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%2FValidate.java;h=6fc7165ed7b490861d03f0ffbae0e0aa253486fa;hb=3927509ec3ecfa32a51b725d2b7155d425f5b877;hp=24611c26cd5030637daed3c3a0aa884afa842a4e;hpb=dc43a61816ddd75e3ad3a3a30bf64c60ad8275a2;p=controller.git diff --git a/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/operations/Validate.java b/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/operations/Validate.java index 24611c26cd..6fc7165ed7 100644 --- a/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/operations/Validate.java +++ b/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/operations/Validate.java @@ -8,29 +8,29 @@ package org.opendaylight.controller.netconf.confignetconfconnector.operations; -import com.google.common.base.Preconditions; +import com.google.common.base.Optional; +import java.util.HashMap; +import java.util.Map; import org.opendaylight.controller.config.api.ValidationException; 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; import org.w3c.dom.Element; -import java.util.HashMap; -import java.util.Map; - public class Validate extends AbstractConfigNetconfOperation { public static final String VALIDATE = "validate"; - private static final Logger logger = LoggerFactory.getLogger(Validate.class); + private static final Logger LOG = LoggerFactory.getLogger(Validate.class); private final TransactionProvider transactionProvider; @@ -40,7 +40,7 @@ public class Validate extends AbstractConfigNetconfOperation { this.transactionProvider = transactionProvider; } - private void checkXml(XmlElement xml) { + private void checkXml(XmlElement xml) throws NetconfDocumentedException { xml.checkName(VALIDATE); xml.checkNamespace(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0); @@ -52,8 +52,10 @@ public class Validate extends AbstractConfigNetconfOperation { String datastoreValue = sourceChildNode.getName(); Datastore sourceDatastore = Datastore.valueOf(datastoreValue); - Preconditions.checkState(sourceDatastore == Datastore.candidate, "Only " + Datastore.candidate - + " is supported as source for " + VALIDATE + " but was " + datastoreValue); + if (sourceDatastore != Datastore.candidate){ + throw new NetconfDocumentedException( "Only " + Datastore.candidate + + " is supported as source for " + VALIDATE + " but was " + datastoreValue,ErrorType.application,ErrorTag.data_missing,ErrorSeverity.error); + } } @Override @@ -62,33 +64,15 @@ public class Validate extends AbstractConfigNetconfOperation { } @Override - protected Element handle(Document document, XmlElement xml) throws NetconfDocumentedException { - try { - checkXml(xml); - } catch (IllegalStateException e) { - logger.warn("Rpc error: {}", ErrorTag.missing_attribute, e); - final Map errorInfo = new HashMap<>(); - errorInfo.put(ErrorTag.missing_attribute.name(), "Missing value of datastore attribute"); - throw new NetconfDocumentedException(e.getMessage(), e, ErrorType.rpc, ErrorTag.missing_attribute, - ErrorSeverity.error, errorInfo); - } catch (final IllegalArgumentException e) { - 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 { + checkXml(xml); try { transactionProvider.validateTransaction(); } catch (ValidationException e) { - logger.warn("Validation failed", e); - final Map errorInfo = new HashMap<>(); - errorInfo.put(ErrorTag.operation_failed.name(), "Validation failed"); - throw new NetconfDocumentedException(e.getMessage(), e, ErrorType.application, ErrorTag.operation_failed, - ErrorSeverity.error, errorInfo); + LOG.warn("Validation failed", e); + throw NetconfDocumentedException.wrap(e); } catch (IllegalStateException e) { - logger.warn("Validation failed", e); + LOG.warn("Validation failed", e); final Map errorInfo = new HashMap<>(); errorInfo .put(ErrorTag.operation_failed.name(), @@ -98,8 +82,8 @@ public class Validate extends AbstractConfigNetconfOperation { } - logger.trace("Datastore {} validated successfully", Datastore.candidate); + LOG.trace("Datastore {} validated successfully", Datastore.candidate); - return document.createElement(XmlNetconfConstants.OK); + return XmlUtil.createElement(document, XmlNetconfConstants.OK, Optional.absent()); } }