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.xml.XmlNetconfConstants;
17 import org.opendaylight.controller.netconf.confignetconfconnector.transactions.TransactionProvider;
18 import org.opendaylight.controller.netconf.util.xml.XmlElement;
19 import org.opendaylight.controller.netconf.util.xml.XmlUtil;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
22 import org.w3c.dom.Document;
23 import org.w3c.dom.Element;
25 import com.google.common.base.Optional;
27 public class Commit extends AbstractConfigNetconfOperation {
29 private static final Logger logger = LoggerFactory.getLogger(Commit.class);
31 private final TransactionProvider transactionProvider;
33 public Commit(TransactionProvider transactionProvider, ConfigRegistryClient configRegistryClient,
34 String netconfSessionIdForReporting) {
35 super(configRegistryClient, netconfSessionIdForReporting);
36 this.transactionProvider = transactionProvider;
39 private static void checkXml(XmlElement xml) throws NetconfDocumentedException {
40 xml.checkName(XmlNetconfConstants.COMMIT);
41 xml.checkNamespace(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
45 protected String getOperationName() {
46 return XmlNetconfConstants.COMMIT;
50 protected Element handleWithNoSubsequentOperations(Document document, XmlElement xml) throws NetconfDocumentedException {
55 status = this.transactionProvider.commitTransaction();
56 logger.trace("Datastore {} committed successfully: {}", Datastore.candidate, status);
57 } catch (ConflictingVersionException | ValidationException e) {
58 throw NetconfDocumentedException.wrap(e);
60 logger.trace("Datastore {} committed successfully: {}", Datastore.candidate, status);
62 return XmlUtil.createElement(document, XmlNetconfConstants.OK, Optional.<String>absent());