From 40fcd10098a68ea8a8acf1b020252ccb2e0b9f9c Mon Sep 17 00:00:00 2001 From: ajay_dp001 Date: Sun, 12 Jul 2020 12:51:17 +0530 Subject: [PATCH] Fix Nested YANG 1.1 Action invocation 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 Signed-off-by: ajay_dp001 Change-Id: I1d5cd6f65ae4d040d36de5f24f6d76fe5076991f --- .../JsonNormalizedNodeBodyReader.java | 5 ++- .../impl/RestconfDataServiceImpl.java | 9 ++---- .../utils/RestconfInvokeOperationsUtil.java | 31 ++++--------------- 3 files changed, 13 insertions(+), 32 deletions(-) diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/JsonNormalizedNodeBodyReader.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/JsonNormalizedNodeBodyReader.java index a8c79f3560..c3c82df756 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/JsonNormalizedNodeBodyReader.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/JsonNormalizedNodeBodyReader.java @@ -41,6 +41,7 @@ import org.opendaylight.yangtools.yang.data.codec.gson.JsonParserStream; import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNormalizedNodeStreamWriter; import org.opendaylight.yangtools.yang.data.impl.schema.NormalizedNodeResult; import org.opendaylight.yangtools.yang.data.impl.schema.ResultAlreadySetException; +import org.opendaylight.yangtools.yang.model.api.OperationDefinition; import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang.model.api.SchemaNode; import org.opendaylight.yangtools.yang.model.api.SchemaPath; @@ -112,7 +113,9 @@ public class JsonNormalizedNodeBodyReader extends AbstractNormalizedNodeBodyRead iiToDataList.add(new YangInstanceIdentifier.NodeIdentifier(result.getNodeType())); iiToDataList.add(result.getIdentifier()); } else { - iiToDataList.add(result.getIdentifier()); + if (!(parentSchema instanceof OperationDefinition)) { + iiToDataList.add(result.getIdentifier()); + } } } else { if (result instanceof MapNode) { diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfDataServiceImpl.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfDataServiceImpl.java index 6e7c0d5d04..ea4bc46ed4 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfDataServiceImpl.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfDataServiceImpl.java @@ -292,7 +292,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); @@ -405,13 +405,10 @@ public class RestconfDataServiceImpl implements RestconfDataService { /** * Invoke Action operation. * - * @param payload - * {@link NormalizedNodeContext} - the body of the operation - * @param uriInfo - * URI info + * @param payload {@link NormalizedNodeContext} - the body of the operation * @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(); diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/RestconfInvokeOperationsUtil.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/RestconfInvokeOperationsUtil.java index 8e1304ea5b..417b9781d3 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/RestconfInvokeOperationsUtil.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/RestconfInvokeOperationsUtil.java @@ -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)); } /** @@ -155,8 +150,8 @@ public final class RestconfInvokeOperationsUtil { */ 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)); + return prepareActionResult( + actionServiceHandler.get().invokeAction(schemaPath, prepareDataTreeId(yangIId), data)); } /** @@ -199,24 +194,10 @@ public final class RestconfInvokeOperationsUtil { /** * Prepare DOMDataTree Identifier. * - * @param yangIId - * {@link YangInstanceIdentifier} - * @param schemaPath - * {@link SchemaPath} + * @param yangIId {@link YangInstanceIdentifier} * @return {@link DOMDataTreeIdentifier} domDataTreeIdentifier */ - private static DOMDataTreeIdentifier prepareDataTreeId(final YangInstanceIdentifier yangIId, - final SchemaPath schemaPath) { - final List 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()); } } -- 2.36.6