X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fnetconf%2Fconfig-netconf-connector%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Fconfignetconfconnector%2Foperations%2FDiscardChanges.java;h=3cf702ed7f1b8b532d0a6834b787ee6140bc6fc7;hb=daa1d3344b3394accd85152b6f0a2fcda8491759;hp=8965deb6303a716143d7b54a064c58d79758bfbe;hpb=ca923718510fffbf66c2a0c6f41a3638d59495e9;p=controller.git diff --git a/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/operations/DiscardChanges.java b/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/operations/DiscardChanges.java index 8965deb630..3cf702ed7f 100644 --- a/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/operations/DiscardChanges.java +++ b/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/operations/DiscardChanges.java @@ -6,16 +6,19 @@ * and is available at http://www.eclipse.org/legal/epl-v10.html */ -package org.opendaylight.controller.netconf.confignetconfconnector.operations; + package org.opendaylight.controller.netconf.confignetconfconnector.operations; + +import com.google.common.base.Optional; import org.opendaylight.controller.config.util.ConfigRegistryClient; import org.opendaylight.controller.netconf.api.NetconfDocumentedException; import org.opendaylight.controller.netconf.api.NetconfDocumentedException.ErrorSeverity; import org.opendaylight.controller.netconf.api.NetconfDocumentedException.ErrorTag; import org.opendaylight.controller.netconf.api.NetconfDocumentedException.ErrorType; +import org.opendaylight.controller.netconf.api.xml.XmlNetconfConstants; import org.opendaylight.controller.netconf.confignetconfconnector.transactions.TransactionProvider; import org.opendaylight.controller.netconf.util.xml.XmlElement; -import org.opendaylight.controller.netconf.util.xml.XmlNetconfConstants; +import org.opendaylight.controller.netconf.util.xml.XmlUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.w3c.dom.Document; @@ -24,6 +27,7 @@ import org.w3c.dom.Element; import java.util.HashMap; import java.util.Map; + public class DiscardChanges extends AbstractConfigNetconfOperation { public static final String DISCARD = "discard-changes"; @@ -38,7 +42,7 @@ public class DiscardChanges extends AbstractConfigNetconfOperation { this.transactionProvider = transactionProvider; } - private static void fromXml(XmlElement xml) { + private static void fromXml(XmlElement xml) throws NetconfDocumentedException { xml.checkName(DISCARD); xml.checkNamespace(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0); } @@ -49,22 +53,11 @@ public class DiscardChanges extends AbstractConfigNetconfOperation { } @Override - protected Element handle(Document document, XmlElement xml) throws NetconfDocumentedException { - try { - fromXml(xml); - } catch (final IllegalArgumentException e) { - //FIXME where can IllegalStateException be thrown? - logger.warn("Rpc error: {}", ErrorTag.bad_attribute, e); - final Map errorInfo = new HashMap<>(); - errorInfo.put(ErrorTag.bad_attribute.name(), e.getMessage()); - throw new NetconfDocumentedException(e.getMessage(), e, ErrorType.rpc, ErrorTag.bad_attribute, - ErrorSeverity.error, errorInfo); - } - + protected Element handleWithNoSubsequentOperations(Document document, XmlElement xml) throws NetconfDocumentedException { + fromXml(xml); try { this.transactionProvider.abortTransaction(); } catch (final IllegalStateException e) { - //FIXME where can IllegalStateException be thrown? logger.warn("Abort failed: ", e); final Map errorInfo = new HashMap<>(); errorInfo @@ -75,6 +68,7 @@ public class DiscardChanges extends AbstractConfigNetconfOperation { } logger.trace("Changes discarded successfully from datastore {}", Datastore.candidate); - return document.createElement(XmlNetconfConstants.OK); + + return XmlUtil.createElement(document, XmlNetconfConstants.OK, Optional.absent()); } }