X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fnetconf%2Fconfig-netconf-connector%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Fconfignetconfconnector%2Foperations%2Fruntimerpc%2FRuntimeRpc.java;h=98eb17699973cc1e2448c5072421a0e29b205280;hp=e7f9772c011dbf7979463146f6aafe1e2526940e;hb=8720a3f3498bbc6fab675431f4200d26641a8ec8;hpb=9390dd5bea2420cdbb1e4f6c2029091811c4df5a diff --git a/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/operations/runtimerpc/RuntimeRpc.java b/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/operations/runtimerpc/RuntimeRpc.java index e7f9772c01..98eb176999 100644 --- a/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/operations/runtimerpc/RuntimeRpc.java +++ b/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/operations/runtimerpc/RuntimeRpc.java @@ -12,7 +12,6 @@ import com.google.common.base.Optional; import com.google.common.base.Preconditions; import com.google.common.collect.Maps; import org.opendaylight.controller.config.util.ConfigRegistryClient; -import org.opendaylight.controller.config.yang.store.api.YangStoreSnapshot; import org.opendaylight.controller.config.yangjmxgenerator.ModuleMXBeanEntry; import org.opendaylight.controller.config.yangjmxgenerator.RuntimeBeanEntry; import org.opendaylight.controller.config.yangjmxgenerator.RuntimeBeanEntry.Rpc; @@ -28,9 +27,12 @@ import org.opendaylight.controller.netconf.confignetconfconnector.mapping.rpc.Mo import org.opendaylight.controller.netconf.confignetconfconnector.mapping.rpc.Rpcs; import org.opendaylight.controller.netconf.confignetconfconnector.operations.AbstractConfigNetconfOperation; import org.opendaylight.controller.netconf.confignetconfconnector.operations.Commit; +import org.opendaylight.controller.netconf.confignetconfconnector.osgi.YangStoreSnapshot; import org.opendaylight.controller.netconf.mapping.api.HandlingPriority; +import org.opendaylight.controller.netconf.util.exception.MissingNameSpaceException; 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; @@ -53,8 +55,8 @@ public class RuntimeRpc extends AbstractConfigNetconfOperation { this.yangStoreSnapshot = yangStoreSnapshot; } - private Element toXml(Document doc, Object result, AttributeIfc returnType, String namespace, String elementName) { - AttributeMappingStrategy> mappingStrategy = new ObjectMapper(null).prepareStrategy(returnType); + private Element toXml(Document doc, Object result, AttributeIfc returnType, String namespace, String elementName) throws NetconfDocumentedException { + AttributeMappingStrategy> mappingStrategy = new ObjectMapper().prepareStrategy(returnType); Optional mappedAttributeOpt = mappingStrategy.mapAttribute(result); Preconditions.checkState(mappedAttributeOpt.isPresent(), "Unable to map return value %s as %s", result, returnType.getOpenType()); @@ -64,7 +66,7 @@ public class RuntimeRpc extends AbstractConfigNetconfOperation { // Either allow List of Elements to be returned from NetconfOperation or // pass reference to parent output xml element for netconf operations to // append result(s) on their own - Element tempParent = doc.createElementNS(XmlNetconfConstants.RFC4741_TARGET_NAMESPACE, "output"); + Element tempParent = XmlUtil.createElement(doc, "output", Optional.of(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0)); new ObjectXmlWriter().prepareWritingStrategy(elementName, returnType, doc).writeElement(tempParent, namespace, mappedAttributeOpt.get()); XmlElement xmlElement = XmlElement.fromDomElement(tempParent); @@ -91,7 +93,13 @@ public class RuntimeRpc extends AbstractConfigNetconfOperation { } public NetconfOperationExecution fromXml(final XmlElement xml) throws NetconfDocumentedException { - final String namespace = xml.getNamespace(); + final String namespace; + try { + namespace = xml.getNamespace(); + } catch (MissingNameSpaceException e) { + logger.trace("Can't get namespace from xml element due to {}",e); + throw NetconfDocumentedException.wrap(e); + } final XmlElement contextInstanceElement = xml.getOnlyChildElement(CONTEXT_INSTANCE); final String operationName = xml.getName(); @@ -114,18 +122,26 @@ public class RuntimeRpc extends AbstractConfigNetconfOperation { } @Override - public HandlingPriority canHandle(Document message) { - XmlElement requestElement = getRequestElementWithCheck(message); + public HandlingPriority canHandle(Document message) throws NetconfDocumentedException { + XmlElement requestElement = null; + requestElement = getRequestElementWithCheck(message); XmlElement operationElement = requestElement.getOnlyChildElement(); final String netconfOperationName = operationElement.getName(); - final String netconfOperationNamespace = operationElement.getNamespace(); + final String netconfOperationNamespace; + try { + netconfOperationNamespace = operationElement.getNamespace(); + } catch (MissingNameSpaceException e) { + logger.debug("Cannot retrieve netconf operation namespace from message due to {}", e); + return HandlingPriority.CANNOT_HANDLE; + } final Optional contextInstanceElement = operationElement .getOnlyChildElementOptionally(CONTEXT_INSTANCE); - if (contextInstanceElement.isPresent() == false) + if (!contextInstanceElement.isPresent()){ return HandlingPriority.CANNOT_HANDLE; + } final RuntimeRpcElementResolved id = RuntimeRpcElementResolved.fromXpath(contextInstanceElement.get() .getTextContent(), netconfOperationName, netconfOperationNamespace); @@ -161,23 +177,20 @@ public class RuntimeRpc extends AbstractConfigNetconfOperation { } @Override - protected Element handle(Document document, XmlElement xml) throws NetconfDocumentedException { - - // TODO exception handling + protected Element handleWithNoSubsequentOperations(Document document, XmlElement xml) throws NetconfDocumentedException { // TODO check for namespaces and unknown elements - final NetconfOperationExecution execution = fromXml(xml); logger.debug("Invoking operation {} on {} with arguments {}", execution.operationName, execution.on, execution.attributes); - final Object result = executeOperation(configRegistryClient, execution.on, execution.operationName, + final Object result = executeOperation(getConfigRegistryClient(), execution.on, execution.operationName, execution.attributes); logger.trace("Operation {} called successfully on {} with arguments {} with result {}", execution.operationName, execution.on, execution.attributes, result); if (execution.isVoid()) { - return document.createElement("ok"); + return XmlUtil.createElement(document, XmlNetconfConstants.OK, Optional.absent()); } else { return toXml(document, result, execution.returnType, execution.namespace, execution.returnType.getAttributeYangName()); @@ -213,7 +226,7 @@ public class RuntimeRpc extends AbstractConfigNetconfOperation { for (XmlElement xmlElement : xml.getChildElements()) { final String name = xmlElement.getName(); - if (CONTEXT_INSTANCE.equals(name) == false) { // skip context + if (!CONTEXT_INSTANCE.equals(name)) { // skip context // instance child node // because it // specifies