Revert "Fix nested YANG 1.1 Action invocation" 44/90944/1
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 7 Jul 2020 08:35:18 +0000 (10:35 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 7 Jul 2020 08:39:02 +0000 (10:39 +0200)
This reverts commit 8b9206c7b36b7f7ebfadf23e1be00d43a0bd9573, as
it breaks CSIT.

JIRA: NETCONF-702
Change-Id: I6f65c587f5e9d04e67dcdcaeda12688d206524b5
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfDataServiceImpl.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/RestconfInvokeOperationsUtil.java

index b245738e18f12d86cc9b6892ba9bc3d6db5cfc07..389643b5e77f7c42d7d0c677abb88f3069e96d6f 100644 (file)
@@ -253,7 +253,7 @@ public class RestconfDataServiceImpl implements RestconfDataService {
     public Response postData(final NormalizedNodeContext payload, final UriInfo uriInfo) {
         requireNonNull(payload);
         if (payload.getInstanceIdentifierContext().getSchemaNode() instanceof ActionDefinition) {
-            return invokeAction(payload);
+            return invokeAction(payload, uriInfo);
         }
 
         final QueryParams checkedParms = checkQueryParameters(uriInfo);
@@ -356,9 +356,11 @@ public class RestconfDataServiceImpl implements RestconfDataService {
      *
      * @param payload
      *             {@link NormalizedNodeContext} - the body of the operation
+     * @param uriInfo
+     *             URI info
      * @return {@link NormalizedNodeContext} wrapped in {@link Response}
      */
-    public Response invokeAction(final NormalizedNodeContext payload) {
+    public Response invokeAction(final NormalizedNodeContext payload, final UriInfo uriInfo) {
         final InstanceIdentifierContext<?> context = payload.getInstanceIdentifierContext();
         final DOMMountPoint mountPoint = context.getMountPoint();
         final SchemaPath schemaPath = context.getSchemaNode().getPath();
index e38cf138cbbaef351f1c1e1f7b639d5b90c8c719..0970f014a63d201425d2bf691bc8fbca45a47e62 100644 (file)
@@ -8,6 +8,8 @@
 package org.opendaylight.restconf.nb.rfc8040.rests.utils;
 
 import com.google.common.util.concurrent.ListenableFuture;
+import java.util.ArrayList;
+import java.util.List;
 import java.util.Optional;
 import java.util.concurrent.CancellationException;
 import javax.ws.rs.core.Response.Status;
@@ -26,6 +28,7 @@ import org.opendaylight.restconf.nb.rfc8040.handlers.ActionServiceHandler;
 import org.opendaylight.restconf.nb.rfc8040.handlers.RpcServiceHandler;
 import org.opendaylight.yangtools.yang.common.YangConstants;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
@@ -138,7 +141,9 @@ public final class RestconfInvokeOperationsUtil {
         if (!mountPointService.isPresent()) {
             throw new RestconfDocumentedException("DomAction service is missing.");
         }
-        return prepareActionResult(mountPointService.get().invokeAction(schemaPath, prepareDataTreeId(yangIId), data));
+
+        return prepareActionResult(mountPointService.get().invokeAction(schemaPath,
+            prepareDataTreeId(yangIId, schemaPath), data));
     }
 
     /**
@@ -153,9 +158,9 @@ public final class RestconfInvokeOperationsUtil {
      * @return {@link DOMActionResult}
      */
     public static DOMActionResult invokeAction(final ContainerNode data, final SchemaPath schemaPath,
-        final ActionServiceHandler actionServiceHandler, final YangInstanceIdentifier yangIId) {
-        return prepareActionResult(actionServiceHandler.get().invokeAction(schemaPath, prepareDataTreeId(yangIId),
-            data));
+            final ActionServiceHandler actionServiceHandler, final YangInstanceIdentifier yangIId) {
+        return prepareActionResult(actionServiceHandler.get().invokeAction(schemaPath,
+            prepareDataTreeId(yangIId, schemaPath), data));
     }
 
     /**
@@ -200,9 +205,22 @@ public final class RestconfInvokeOperationsUtil {
      *
      * @param yangIId
      *             {@link YangInstanceIdentifier}
+     * @param schemaPath
+     *              {@link SchemaPath}
      * @return {@link DOMDataTreeIdentifier} domDataTreeIdentifier
      */
-    private static DOMDataTreeIdentifier prepareDataTreeId(final YangInstanceIdentifier yangIId) {
-        return new DOMDataTreeIdentifier(LogicalDatastoreType.OPERATIONAL, yangIId.getParent());
+    private static DOMDataTreeIdentifier prepareDataTreeId(final YangInstanceIdentifier yangIId,
+            final SchemaPath schemaPath) {
+        final List<PathArgument> pathArg = new ArrayList<>();
+        for (PathArgument path : yangIId.getPathArguments()) {
+            if (path.getNodeType().getLocalName().equals(schemaPath.getLastComponent().getLocalName())) {
+                break;
+            }
+            pathArg.add(path);
+        }
+        YangInstanceIdentifier yangInstanceIdentifier = YangInstanceIdentifier.builder().append(pathArg).build();
+        DOMDataTreeIdentifier domDataTreeIdentifier = new DOMDataTreeIdentifier(LogicalDatastoreType.OPERATIONAL,
+            yangInstanceIdentifier);
+        return domDataTreeIdentifier;
     }
 }