Fix nested YANG 1.1 Action invocation 61/90261/1
authorajay_dp001 <ajay.deep.singh@est.tech>
Wed, 3 Jun 2020 04:27:28 +0000 (09:57 +0530)
committerRobert Varga <nite@hq.sk>
Tue, 9 Jun 2020 08:36:41 +0000 (08:36 +0000)
Invocation of action fails if the action is defined as an augmentation.
As it turns out the logic can be very much simplified by just cutting
the last item from YangInstanceIdentifier, as that points to the parent
(and hence context) of the action.

JIRA: NETCONF-696
Change-Id: I7b03b2b1ebdd7bffbfab5291552c430700ff2850
Signed-off-by: ajay_dp001 <ajay.deep.singh@est.tech>
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 c6a9efbf09d4436560a38ba27d29718bed868f7e..e4c24dd8441a70ce063b1a1b4ccecd655837d065 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, uriInfo);
+            return invokeAction(payload);
         }
 
         final QueryParams checkedParms = checkQueryParameters(uriInfo);
@@ -356,11 +356,9 @@ 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, final UriInfo uriInfo) {
+    public Response invokeAction(final NormalizedNodeContext payload) {
         final InstanceIdentifierContext<?> context = payload.getInstanceIdentifierContext();
         final DOMMountPoint mountPoint = context.getMountPoint();
         final SchemaPath schemaPath = context.getSchemaNode().getPath();
index 8e1304ea5bfb8682b4683746c4dcd2da6f3d4959..a5f684dd60b4344196aa2d7634abe2f108dcc8ad 100644 (file)
@@ -8,8 +8,6 @@
 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,7 +24,6 @@ import org.opendaylight.restconf.common.errors.RestconfError.ErrorType;
 import org.opendaylight.restconf.nb.rfc8040.handlers.ActionServiceHandler;
 import org.opendaylight.restconf.nb.rfc8040.handlers.RpcServiceHandler;
 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.model.api.SchemaPath;
@@ -137,9 +134,7 @@ public final class RestconfInvokeOperationsUtil {
         if (!mountPointService.isPresent()) {
             throw new RestconfDocumentedException("DomAction service is missing.");
         }
-
-        return prepareActionResult(mountPointService.get().invokeAction(schemaPath,
-            prepareDataTreeId(yangIId, schemaPath), data));
+        return prepareActionResult(mountPointService.get().invokeAction(schemaPath, prepareDataTreeId(yangIId), data));
     }
 
     /**
@@ -154,9 +149,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, schemaPath), data));
+        final ActionServiceHandler actionServiceHandler, final YangInstanceIdentifier yangIId) {
+        return prepareActionResult(actionServiceHandler.get().invokeAction(schemaPath, prepareDataTreeId(yangIId),
+            data));
     }
 
     /**
@@ -201,22 +196,9 @@ public final class RestconfInvokeOperationsUtil {
      *
      * @param yangIId
      *             {@link YangInstanceIdentifier}
-     * @param schemaPath
-     *              {@link SchemaPath}
      * @return {@link DOMDataTreeIdentifier} domDataTreeIdentifier
      */
-    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;
+    private static DOMDataTreeIdentifier prepareDataTreeId(final YangInstanceIdentifier yangIId) {
+        return new DOMDataTreeIdentifier(LogicalDatastoreType.OPERATIONAL, yangIId.getParent());
     }
 }