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 com.google.common.base.Optional;
12 import org.opendaylight.controller.config.api.ConflictingVersionException;
13 import org.opendaylight.controller.config.api.ValidationException;
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.xml.XmlNetconfConstants;
18 import org.opendaylight.controller.netconf.confignetconfconnector.transactions.TransactionProvider;
19 import org.opendaylight.controller.netconf.util.xml.XmlElement;
20 import org.opendaylight.controller.netconf.util.xml.XmlUtil;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
23 import org.w3c.dom.Document;
24 import org.w3c.dom.Element;
26 public class Commit extends AbstractConfigNetconfOperation {
28 private static final Logger LOG = LoggerFactory.getLogger(Commit.class);
30 private final TransactionProvider transactionProvider;
32 public Commit(TransactionProvider transactionProvider, ConfigRegistryClient configRegistryClient,
33 String netconfSessionIdForReporting) {
34 super(configRegistryClient, netconfSessionIdForReporting);
35 this.transactionProvider = transactionProvider;
38 private static void checkXml(XmlElement xml) throws NetconfDocumentedException {
39 xml.checkName(XmlNetconfConstants.COMMIT);
40 xml.checkNamespace(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
44 protected String getOperationName() {
45 return XmlNetconfConstants.COMMIT;
49 protected Element handleWithNoSubsequentOperations(Document document, XmlElement xml) throws NetconfDocumentedException {
54 status = this.transactionProvider.commitTransaction();
55 LOG.trace("Datastore {} committed successfully: {}", Datastore.candidate, status);
56 } catch (ConflictingVersionException | ValidationException e) {
57 throw NetconfDocumentedException.wrap(e);
59 LOG.trace("Datastore {} committed successfully: {}", Datastore.candidate, status);
61 return XmlUtil.createElement(document, XmlNetconfConstants.OK, Optional.<String>absent());