X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-netconf-connector%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Fconnect%2Fnetconf%2Futil%2FNetconfMessageTransformUtil.java;h=e3a7441caf746fdb56cc8d0a4cc87287908c41b9;hp=1e3cf4b6fce9f30917ef4c3bc3c19a61bf9b7d64;hb=61486fc82a2f4b3dc49ea49102e08680f8f059a6;hpb=c74d5c2399e500fe3e690edc8cee497b1cb6f867 diff --git a/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/util/NetconfMessageTransformUtil.java b/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/util/NetconfMessageTransformUtil.java index 1e3cf4b6fc..e3a7441caf 100644 --- a/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/util/NetconfMessageTransformUtil.java +++ b/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/util/NetconfMessageTransformUtil.java @@ -7,6 +7,7 @@ */ package org.opendaylight.controller.sal.connect.netconf.util; +import com.google.common.base.Optional; import com.google.common.base.Preconditions; import com.google.common.base.Predicate; import com.google.common.collect.Collections2; @@ -14,16 +15,13 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Iterables; import com.google.common.collect.Sets; - import java.net.URI; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Map.Entry; - import javax.annotation.Nullable; - import org.opendaylight.controller.netconf.api.NetconfDocumentedException; import org.opendaylight.controller.netconf.api.NetconfMessage; import org.opendaylight.controller.netconf.util.messages.NetconfMessageUtil; @@ -33,9 +31,9 @@ import org.opendaylight.yangtools.yang.common.RpcError; import org.opendaylight.yangtools.yang.common.RpcError.ErrorSeverity; import org.opendaylight.yangtools.yang.common.RpcResultBuilder; import org.opendaylight.yangtools.yang.data.api.CompositeNode; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.Node; import org.opendaylight.yangtools.yang.data.api.SimpleNode; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.impl.CompositeNodeTOImpl; import org.opendaylight.yangtools.yang.data.impl.ImmutableCompositeNode; import org.opendaylight.yangtools.yang.data.impl.NodeFactory; @@ -43,12 +41,15 @@ import org.opendaylight.yangtools.yang.data.impl.SimpleNodeTOImpl; import org.opendaylight.yangtools.yang.data.impl.util.CompositeNodeBuilder; import org.opendaylight.yangtools.yang.model.api.DataNodeContainer; import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; +import org.opendaylight.yangtools.yang.model.api.RpcDefinition; import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.w3c.dom.Document; import org.w3c.dom.Element; public class NetconfMessageTransformUtil { + public static final String MESSAGE_ID_ATTR = "message-id"; + private NetconfMessageTransformUtil() {} public static final QName IETF_NETCONF_MONITORING = QName.create(NetconfState.QNAME, "ietf-netconf-monitoring"); @@ -58,34 +59,34 @@ public class NetconfMessageTransformUtil { public static final QName IETF_NETCONF_MONITORING_SCHEMA_VERSION = QName.create(IETF_NETCONF_MONITORING, "version"); public static final QName IETF_NETCONF_MONITORING_SCHEMA_NAMESPACE = QName.create(IETF_NETCONF_MONITORING, "namespace"); - public static URI NETCONF_URI = URI.create("urn:ietf:params:xml:ns:netconf:base:1.0"); - public static QName NETCONF_QNAME = QName.create(NETCONF_URI, null, "netconf"); - public static QName NETCONF_DATA_QNAME = QName.create(NETCONF_QNAME, "data"); - public static QName NETCONF_RPC_REPLY_QNAME = QName.create(NETCONF_QNAME, "rpc-reply"); - public static QName NETCONF_ERROR_OPTION_QNAME = QName.create(NETCONF_QNAME, "error-option"); - public static QName NETCONF_RUNNING_QNAME = QName.create(NETCONF_QNAME, "running"); - static List> RUNNING = Collections.> singletonList(new SimpleNodeTOImpl<>(NETCONF_RUNNING_QNAME, null, null)); - public static QName NETCONF_SOURCE_QNAME = QName.create(NETCONF_QNAME, "source"); - public static CompositeNode CONFIG_SOURCE_RUNNING = new CompositeNodeTOImpl(NETCONF_SOURCE_QNAME, null, RUNNING); - public static QName NETCONF_CANDIDATE_QNAME = QName.create(NETCONF_QNAME, "candidate"); - public static QName NETCONF_TARGET_QNAME = QName.create(NETCONF_QNAME, "target"); - public static QName NETCONF_CONFIG_QNAME = QName.create(NETCONF_QNAME, "config"); - public static QName NETCONF_COMMIT_QNAME = QName.create(NETCONF_QNAME, "commit"); - public static QName NETCONF_OPERATION_QNAME = QName.create(NETCONF_QNAME, "operation"); - public static QName NETCONF_DEFAULT_OPERATION_QNAME = QName.create(NETCONF_OPERATION_QNAME, "default-operation"); - public static QName NETCONF_EDIT_CONFIG_QNAME = QName.create(NETCONF_QNAME, "edit-config"); - public static QName NETCONF_GET_CONFIG_QNAME = QName.create(NETCONF_QNAME, "get-config"); - public static QName NETCONF_DISCARD_CHANGES_QNAME = QName.create(NETCONF_QNAME, "discard-changes"); - public static QName NETCONF_TYPE_QNAME = QName.create(NETCONF_QNAME, "type"); - public static QName NETCONF_FILTER_QNAME = QName.create(NETCONF_QNAME, "filter"); - public static QName NETCONF_GET_QNAME = QName.create(NETCONF_QNAME, "get"); - public static QName NETCONF_RPC_QNAME = QName.create(NETCONF_QNAME, "rpc"); - - public static URI NETCONF_ROLLBACK_ON_ERROR_URI = URI + public static final URI NETCONF_URI = URI.create("urn:ietf:params:xml:ns:netconf:base:1.0"); + public static final QName NETCONF_QNAME = QName.create(NETCONF_URI, null, "netconf"); + public static final QName NETCONF_DATA_QNAME = QName.create(NETCONF_QNAME, "data"); + public static final QName NETCONF_RPC_REPLY_QNAME = QName.create(NETCONF_QNAME, "rpc-reply"); + public static final QName NETCONF_ERROR_OPTION_QNAME = QName.create(NETCONF_QNAME, "error-option"); + public static final QName NETCONF_RUNNING_QNAME = QName.create(NETCONF_QNAME, "running"); + static final List> RUNNING = Collections.> singletonList(new SimpleNodeTOImpl<>(NETCONF_RUNNING_QNAME, null, null)); + public static final QName NETCONF_SOURCE_QNAME = QName.create(NETCONF_QNAME, "source"); + public static final CompositeNode CONFIG_SOURCE_RUNNING = new CompositeNodeTOImpl(NETCONF_SOURCE_QNAME, null, RUNNING); + public static final QName NETCONF_CANDIDATE_QNAME = QName.create(NETCONF_QNAME, "candidate"); + public static final QName NETCONF_TARGET_QNAME = QName.create(NETCONF_QNAME, "target"); + public static final QName NETCONF_CONFIG_QNAME = QName.create(NETCONF_QNAME, "config"); + public static final QName NETCONF_COMMIT_QNAME = QName.create(NETCONF_QNAME, "commit"); + public static final QName NETCONF_OPERATION_QNAME = QName.create(NETCONF_QNAME, "operation"); + public static final QName NETCONF_DEFAULT_OPERATION_QNAME = QName.create(NETCONF_OPERATION_QNAME, "default-operation"); + public static final QName NETCONF_EDIT_CONFIG_QNAME = QName.create(NETCONF_QNAME, "edit-config"); + public static final QName NETCONF_GET_CONFIG_QNAME = QName.create(NETCONF_QNAME, "get-config"); + public static final QName NETCONF_DISCARD_CHANGES_QNAME = QName.create(NETCONF_QNAME, "discard-changes"); + public static final QName NETCONF_TYPE_QNAME = QName.create(NETCONF_QNAME, "type"); + public static final QName NETCONF_FILTER_QNAME = QName.create(NETCONF_QNAME, "filter"); + public static final QName NETCONF_GET_QNAME = QName.create(NETCONF_QNAME, "get"); + public static final QName NETCONF_RPC_QNAME = QName.create(NETCONF_QNAME, "rpc"); + + public static final URI NETCONF_ROLLBACK_ON_ERROR_URI = URI .create("urn:ietf:params:netconf:capability:rollback-on-error:1.0"); - public static String ROLLBACK_ON_ERROR_OPTION = "rollback-on-error"; + public static final String ROLLBACK_ON_ERROR_OPTION = "rollback-on-error"; - public static URI NETCONF_CANDIDATE_URI = URI + public static final URI NETCONF_CANDIDATE_URI = URI .create("urn:ietf:params:netconf:capability:candidate:1.0"); // Discard changes message @@ -115,7 +116,7 @@ public class NetconfMessageTransformUtil { static Node toNode(final YangInstanceIdentifier.NodeIdentifierWithPredicates argument, final Node node) { final List> list = new ArrayList<>(); for (final Map.Entry arg : argument.getKeyValues().entrySet()) { - list.add(new SimpleNodeTOImpl(arg.getKey(), null, arg.getValue())); + list.add(new SimpleNodeTOImpl<>(arg.getKey(), null, arg.getValue())); } if (node != null) { list.add(node); @@ -125,8 +126,8 @@ public class NetconfMessageTransformUtil { public static void checkValidReply(final NetconfMessage input, final NetconfMessage output) throws NetconfDocumentedException { - final String inputMsgId = input.getDocument().getDocumentElement().getAttribute("message-id"); - final String outputMsgId = output.getDocument().getDocumentElement().getAttribute("message-id"); + final String inputMsgId = input.getDocument().getDocumentElement().getAttribute(MESSAGE_ID_ATTR); + final String outputMsgId = output.getDocument().getDocumentElement().getAttribute(MESSAGE_ID_ATTR); if(inputMsgId.equals(outputMsgId) == false) { Map errorInfo = ImmutableMap.builder() @@ -323,6 +324,20 @@ public class NetconfMessageTransformUtil { return new NodeContainerProxy(NETCONF_RPC_QNAME, Sets.newHashSet(editConfigProxy)); } + + public static Optional findSchemaForRpc(final QName rpcName, final SchemaContext schemaContext) { + Preconditions.checkNotNull(rpcName); + Preconditions.checkNotNull(schemaContext); + + for (final RpcDefinition rpcDefinition : schemaContext.getOperations()) { + if(rpcDefinition.getQName().equals(rpcName)) { + return Optional.of(rpcDefinition); + } + } + + return Optional.absent(); + } + /** * Creates artificial schema node for schema defined rpc. This artificial schema looks like: *
@@ -338,13 +353,9 @@ public class NetconfMessageTransformUtil {
      * This makes the translation of schema defined rpc request
      * to xml use schema which is crucial for some types of nodes e.g. identity-ref.
      */
-    public static DataNodeContainer createSchemaForRpc(final QName rpcName, final SchemaContext schemaContext) {
-        Preconditions.checkNotNull(rpcName);
-        Preconditions.checkNotNull(schemaContext);
-
-        final NodeContainerProxy rpcBodyProxy = new NodeContainerProxy(rpcName, schemaContext.getChildNodes());
+    public static DataNodeContainer createSchemaForRpc(final RpcDefinition rpcDefinition) {
+        final NodeContainerProxy rpcBodyProxy = new NodeContainerProxy(rpcDefinition.getQName(), rpcDefinition.getInput().getChildNodes());
         return new NodeContainerProxy(NETCONF_RPC_QNAME, Sets.newHashSet(rpcBodyProxy));
-
     }
 
     public static CompositeNodeTOImpl wrap(final QName name, final Node node) {