Merge "Add message to update the schema context of the InMemoryDOMDataStore"
[controller.git] / opendaylight / netconf / config-netconf-connector / src / main / java / org / opendaylight / controller / netconf / confignetconfconnector / operations / Commit.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.controller.netconf.confignetconfconnector.operations;
10
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;
24
25 import com.google.common.base.Optional;
26
27 public class Commit extends AbstractConfigNetconfOperation {
28
29     private static final Logger logger = LoggerFactory.getLogger(Commit.class);
30
31     private final TransactionProvider transactionProvider;
32
33     public Commit(TransactionProvider transactionProvider, ConfigRegistryClient configRegistryClient,
34             String netconfSessionIdForReporting) {
35         super(configRegistryClient, netconfSessionIdForReporting);
36         this.transactionProvider = transactionProvider;
37     }
38
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);
42     }
43
44     @Override
45     protected String getOperationName() {
46         return XmlNetconfConstants.COMMIT;
47     }
48
49     @Override
50     protected Element handleWithNoSubsequentOperations(Document document, XmlElement xml) throws NetconfDocumentedException {
51
52         checkXml(xml);
53         CommitStatus status;
54         try {
55             status = this.transactionProvider.commitTransaction();
56             logger.trace("Datastore {} committed successfully: {}", Datastore.candidate, status);
57         } catch (ConflictingVersionException | ValidationException e) {
58             throw NetconfDocumentedException.wrap(e);
59         }
60         logger.trace("Datastore {} committed successfully: {}", Datastore.candidate, status);
61
62         return XmlUtil.createElement(document, XmlNetconfConstants.OK, Optional.<String>absent());
63     }
64
65 }