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.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.facade.xml.ConfigSubsystemFacade;
16 import org.opendaylight.controller.config.facade.xml.Datastore;
17 import org.opendaylight.controller.config.util.xml.DocumentedException;
18 import org.opendaylight.controller.config.util.xml.XmlElement;
19 import org.opendaylight.controller.config.util.xml.XmlUtil;
20 import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
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 public Commit(final ConfigSubsystemFacade configSubsystemFacade, final String netconfSessionIdForReporting) {
31 super(configSubsystemFacade, netconfSessionIdForReporting);
34 private static void checkXml(XmlElement xml) throws DocumentedException {
35 xml.checkName(XmlNetconfConstants.COMMIT);
36 xml.checkNamespace(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
40 protected String getOperationName() {
41 return XmlNetconfConstants.COMMIT;
45 protected Element handleWithNoSubsequentOperations(Document document, XmlElement xml) throws DocumentedException {
50 status = getConfigSubsystemFacade().commitTransaction();
51 LOG.trace("Datastore {} committed successfully: {}", Datastore.candidate, status);
52 } catch (ConflictingVersionException | ValidationException e) {
53 throw DocumentedException.wrap(e);
55 LOG.trace("Datastore {} committed successfully: {}", Datastore.candidate, status);
57 return XmlUtil.createElement(document, XmlNetconfConstants.OK, Optional.<String>absent());