Improve action lookup 60/84960/1
authorRobert Varga <robert.varga@pantheon.tech>
Fri, 23 Aug 2019 15:55:06 +0000 (17:55 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 7 Oct 2019 06:29:45 +0000 (08:29 +0200)
The code here is extremely twisty, but at the end of the day it
ends up creating the path to an action's input -- which we can
readily get from schema. Simplify the logic, speeding it up
significantly.

Change-Id: Ic29689bd03b99b5a2095efa4e3fb3866afc08526
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit c566755c9040b150261b989800331b12d52137da)

netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/schema/mapping/NetconfMessageTransformer.java

index 2523f2e40912c1f192e1463f6462ace25f9f09cf..1eae8a0dfec58cc30f6c78117c82c36850ca1d75 100644 (file)
@@ -215,23 +215,21 @@ public class NetconfMessageTransformer implements MessageTransformer<NetconfMess
     }
 
     @Override
-    public NetconfMessage toActionRequest(SchemaPath action, final DOMDataTreeIdentifier domDataTreeIdentifier,
+    public NetconfMessage toActionRequest(final SchemaPath action, final DOMDataTreeIdentifier domDataTreeIdentifier,
             final NormalizedNode<?, ?> payload) {
         ActionDefinition actionDefinition = null;
-        SchemaPath schemaPath = action;
         for (ActionDefinition actionDef : actions) {
             if (actionDef.getPath().getLastComponent().equals(action.getLastComponent())) {
                 actionDefinition = actionDef;
-                schemaPath = actionDef.getPath();
             }
         }
         Preconditions.checkNotNull(actionDefinition, "Action does not exist: %s", action.getLastComponent());
 
-        if (actionDefinition.getInput().getChildNodes().isEmpty()) {
+        final ContainerSchemaNode inputDef = actionDefinition.getInput();
+        if (inputDef.getChildNodes().isEmpty()) {
             return new NetconfMessage(NetconfMessageTransformUtil.prepareDomResultForActionRequest(
                     DataSchemaContextTree.from(schemaContext), domDataTreeIdentifier, action, counter,
-                    actionDefinition.getQName().getLocalName())
-                    .getNode().getOwnerDocument());
+                    actionDefinition.getQName().getLocalName()).getNode().getOwnerDocument());
         }
 
         Preconditions.checkNotNull(payload, "Transforming an action with input: %s, payload cannot be null",
@@ -239,15 +237,15 @@ public class NetconfMessageTransformer implements MessageTransformer<NetconfMess
         Preconditions.checkArgument(payload instanceof ContainerNode,
                 "Transforming an rpc with input: %s, payload has to be a container, but was: %s",
                 action.getLastComponent(), payload);
-        // Set the path to the input of rpc for the node stream writer
-        action = action.createChild(QName.create(action.getLastComponent(), "input").intern());
+
+        // Set the path to the input of action for the node stream writer
         final DOMResult result = NetconfMessageTransformUtil.prepareDomResultForActionRequest(
-                DataSchemaContextTree.from(schemaContext), domDataTreeIdentifier, action, counter,
+                DataSchemaContextTree.from(schemaContext), domDataTreeIdentifier, inputDef.getPath(), counter,
                 actionDefinition.getQName().getLocalName());
 
         try {
-            NetconfMessageTransformUtil.writeNormalizedRpc((ContainerNode) payload, result,
-                    schemaPath.createChild(QName.create(action.getLastComponent(), "input").intern()), schemaContext);
+            NetconfMessageTransformUtil.writeNormalizedRpc((ContainerNode) payload, result, inputDef.getPath(),
+                schemaContext);
         } catch (final XMLStreamException | IOException | IllegalStateException e) {
             throw new IllegalStateException("Unable to serialize " + action, e);
         }