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 java.util.HashMap;
14 import org.opendaylight.controller.config.api.jmx.CommitStatus;
15 import org.opendaylight.controller.config.util.ConfigRegistryClient;
16 import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
17 import org.opendaylight.controller.netconf.api.NetconfDocumentedException.ErrorSeverity;
18 import org.opendaylight.controller.netconf.api.NetconfDocumentedException.ErrorTag;
19 import org.opendaylight.controller.netconf.api.NetconfDocumentedException.ErrorType;
20 import org.opendaylight.controller.netconf.confignetconfconnector.transactions.TransactionProvider;
21 import org.opendaylight.controller.netconf.util.xml.XmlElement;
22 import org.opendaylight.controller.netconf.util.xml.XmlNetconfConstants;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
25 import org.w3c.dom.Document;
26 import org.w3c.dom.Element;
28 public class Commit extends AbstractConfigNetconfOperation {
30 private static final Logger logger = LoggerFactory.getLogger(Commit.class);
32 private final TransactionProvider transactionProvider;
34 public Commit(TransactionProvider transactionProvider, ConfigRegistryClient configRegistryClient,
35 String netconfSessionIdForReporting) {
36 super(configRegistryClient, netconfSessionIdForReporting);
37 this.transactionProvider = transactionProvider;
40 private static void checkXml(XmlElement xml) {
41 xml.checkName(XmlNetconfConstants.COMMIT);
42 xml.checkNamespace(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
46 protected String getOperationName() {
47 return XmlNetconfConstants.COMMIT;
51 protected Element handle(Document document, XmlElement xml) throws NetconfDocumentedException {
56 status = this.transactionProvider.commitTransaction();
57 } catch (final IllegalStateException e) {
58 logger.warn("Commit failed: ", e);
59 final Map<String, String> errorInfo = new HashMap<>();
60 errorInfo.put(ErrorTag.operation_failed.name(),
61 "Operation failed. Use 'get-config' or 'edit-config' before triggering 'commit' operation");
62 throw new NetconfDocumentedException(e.getMessage(), e, ErrorType.application, ErrorTag.operation_failed,
63 ErrorSeverity.error, errorInfo);
64 } catch (final NetconfDocumentedException e) {
65 throw new NetconfDocumentedException(
66 "Unable to retrieve config snapshot after commit for persister, details: " + e.getMessage(),
67 ErrorType.application, ErrorTag.operation_failed, ErrorSeverity.error, e.getErrorInfo());
69 logger.trace("Datastore {} committed successfully: {}", Datastore.candidate, status);
71 return document.createElement(XmlNetconfConstants.OK);