2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.controller.netconf.confignetconfconnector.operations;
11 import org.opendaylight.controller.config.api.ConflictingVersionException;
12 import org.opendaylight.controller.config.api.ValidationException;
13 import org.opendaylight.controller.config.api.jmx.CommitStatus;
14 import org.opendaylight.controller.config.util.ConfigRegistryClient;
15 import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
16 import org.opendaylight.controller.netconf.api.NetconfDocumentedException.ErrorSeverity;
17 import org.opendaylight.controller.netconf.api.NetconfDocumentedException.ErrorTag;
18 import org.opendaylight.controller.netconf.api.NetconfDocumentedException.ErrorType;
19 import org.opendaylight.controller.netconf.confignetconfconnector.transactions.TransactionProvider;
20 import org.opendaylight.controller.netconf.util.xml.XmlElement;
21 import org.opendaylight.controller.netconf.util.xml.XmlNetconfConstants;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
24 import org.w3c.dom.Document;
25 import org.w3c.dom.Element;
27 import java.util.HashMap;
30 public class Commit extends AbstractConfigNetconfOperation {
32 private static final Logger logger = LoggerFactory.getLogger(Commit.class);
34 private final TransactionProvider transactionProvider;
36 public Commit(TransactionProvider transactionProvider, ConfigRegistryClient configRegistryClient,
37 String netconfSessionIdForReporting) {
38 super(configRegistryClient, netconfSessionIdForReporting);
39 this.transactionProvider = transactionProvider;
42 private static void checkXml(XmlElement xml) {
43 xml.checkName(XmlNetconfConstants.COMMIT);
44 xml.checkNamespace(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
48 protected String getOperationName() {
49 return XmlNetconfConstants.COMMIT;
53 protected Element handle(Document document, XmlElement xml) throws NetconfDocumentedException {
58 status = this.transactionProvider.commitTransaction();
59 } catch (final IllegalStateException e) {
60 // FIXME: when can IllegalStateException occur?
61 logger.warn("Commit failed: ", e);
62 final Map<String, String> errorInfo = new HashMap<>();
63 errorInfo.put(ErrorTag.operation_failed.name(),
64 "Operation failed. Use 'get-config' or 'edit-config' before triggering 'commit' operation");
65 throw new NetconfDocumentedException(e.getMessage(), e, ErrorType.application, ErrorTag.operation_failed,
66 ErrorSeverity.error, errorInfo);
67 } catch (ValidationException e) {
68 throw NetconfDocumentedException.wrap(e);
69 } catch (ConflictingVersionException e) {
70 throw NetconfDocumentedException.wrap(e);
73 logger.trace("Datastore {} committed successfully: {}", Datastore.candidate, status);
75 return document.createElement(XmlNetconfConstants.OK);