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 java.util.HashMap;
14 import org.opendaylight.controller.config.facade.xml.ConfigSubsystemFacade;
15 import org.opendaylight.controller.config.facade.xml.Datastore;
16 import org.opendaylight.controller.config.util.xml.DocumentedException;
17 import org.opendaylight.controller.config.util.xml.DocumentedException.ErrorSeverity;
18 import org.opendaylight.controller.config.util.xml.DocumentedException.ErrorTag;
19 import org.opendaylight.controller.config.util.xml.DocumentedException.ErrorType;
20 import org.opendaylight.controller.config.util.xml.XmlElement;
21 import org.opendaylight.controller.config.util.xml.XmlUtil;
22 import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
25 import org.w3c.dom.Document;
26 import org.w3c.dom.Element;
29 public class DiscardChanges extends AbstractConfigNetconfOperation {
31 public static final String DISCARD = "discard-changes";
33 private static final Logger LOG = LoggerFactory.getLogger(DiscardChanges.class);
35 public DiscardChanges(final ConfigSubsystemFacade configSubsystemFacade,
36 final String netconfSessionIdForReporting) {
37 super(configSubsystemFacade, netconfSessionIdForReporting);
40 private static void fromXml(final XmlElement xml) throws DocumentedException {
41 xml.checkName(DISCARD);
42 xml.checkNamespace(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
46 protected String getOperationName() {
50 @SuppressWarnings("checkstyle:IllegalCatch")
52 protected Element handleWithNoSubsequentOperations(final Document document,
53 final XmlElement xml) throws DocumentedException {
56 getConfigSubsystemFacade().abortConfiguration();
57 } catch (final RuntimeException e) {
58 LOG.warn("Abort failed: ", e);
59 final Map<String, String> errorInfo = new HashMap<>();
61 .put(ErrorTag.OPERATION_FAILED.name(),
63 throw new DocumentedException(e.getMessage(), e, ErrorType.APPLICATION, ErrorTag.OPERATION_FAILED,
64 ErrorSeverity.ERROR, errorInfo);
66 LOG.trace("Changes discarded successfully from datastore {}", Datastore.candidate);
69 return XmlUtil.createElement(document, XmlNetconfConstants.OK, Optional.absent());