From: Robert Varga Date: Fri, 25 Mar 2022 23:44:17 +0000 (+0100) Subject: Do not re-acquire global schema context X-Git-Tag: v3.0.0~6 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F76%2F100276%2F4;p=netconf.git Do not re-acquire global schema context The context is bound at NormalizedNodeContext creation time, let's make sure we do not change that. JIRA: NETCONF-818 Change-Id: I7ec6296c2703b3689aa0c464874ede37695d9065 Signed-off-by: Robert Varga --- diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfInvokeOperationsServiceImpl.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfInvokeOperationsServiceImpl.java index b340007aed..c8affc6873 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfInvokeOperationsServiceImpl.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfInvokeOperationsServiceImpl.java @@ -16,7 +16,6 @@ import com.google.common.util.concurrent.FutureCallback; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.MoreExecutors; -import java.util.Optional; import java.util.concurrent.ExecutionException; import javax.ws.rs.Path; import javax.ws.rs.WebApplicationException; @@ -28,7 +27,6 @@ import org.opendaylight.mdsal.dom.api.DOMMountPoint; import org.opendaylight.mdsal.dom.api.DOMRpcException; import org.opendaylight.mdsal.dom.api.DOMRpcResult; import org.opendaylight.mdsal.dom.api.DOMRpcService; -import org.opendaylight.mdsal.dom.api.DOMSchemaService; import org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult; import org.opendaylight.restconf.common.context.InstanceIdentifierContext; import org.opendaylight.restconf.common.errors.RestconfDocumentedException; @@ -74,20 +72,19 @@ public class RestconfInvokeOperationsServiceImpl implements RestconfInvokeOperat @Override public void invokeRpc(final String identifier, final NormalizedNodePayload payload, final UriInfo uriInfo, final AsyncResponse ar) { - final SchemaNode schema = payload.getInstanceIdentifierContext().getSchemaNode(); + final InstanceIdentifierContext context = payload.getInstanceIdentifierContext(); + final EffectiveModelContext schemaContext = context.getSchemaContext(); + final DOMMountPoint mountPoint = context.getMountPoint(); + final SchemaNode schema = context.getSchemaNode(); final QName rpcName = schema.getQName(); - final DOMMountPoint mountPoint = payload.getInstanceIdentifierContext().getMountPoint(); final ListenableFuture future; - final EffectiveModelContext schemaContextRef; if (mountPoint == null) { - schemaContextRef = schemaContextHandler.get(); - // FIXME: this really should be a normal RPC invocation service which has its own interface with JAX-RS if (SAL_REMOTE_NAMESPACE.equals(rpcName.getNamespace())) { if (identifier.contains("create-data-change-event-subscription")) { future = Futures.immediateFuture( - CreateStreamUtil.createDataChangeNotifiStream(payload, schemaContextRef)); + CreateStreamUtil.createDataChangeNotifiStream(payload, schemaContext)); } else { future = Futures.immediateFailedFuture(new RestconfDocumentedException("Unsupported operation", ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED)); @@ -96,7 +93,6 @@ public class RestconfInvokeOperationsServiceImpl implements RestconfInvokeOperat future = invokeRpc(payload.getData(), rpcName, rpcService); } } else { - schemaContextRef = modelContext(mountPoint); future = invokeRpc(payload.getData(), rpcName, mountPoint); } @@ -114,8 +110,7 @@ public class RestconfInvokeOperationsServiceImpl implements RestconfInvokeOperat if (resultData == null || ((ContainerNode) resultData).isEmpty()) { ar.resume(new WebApplicationException(Status.NO_CONTENT)); } else { - ar.resume(NormalizedNodePayload.of(new InstanceIdentifierContext(null, schema, - mountPoint, schemaContextRef), resultData)); + ar.resume(NormalizedNodePayload.of(context, resultData)); } } @@ -178,10 +173,4 @@ public class RestconfInvokeOperationsServiceImpl implements RestconfInvokeOperat throw new RestconfDocumentedException("Invocation failed", e); } } - - private static EffectiveModelContext modelContext(final DOMMountPoint mountPoint) { - return mountPoint.getService(DOMSchemaService.class) - .flatMap(svc -> Optional.ofNullable(svc.getGlobalContext())) - .orElse(null); - } } diff --git a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfInvokeOperationsServiceImplTest.java b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfInvokeOperationsServiceImplTest.java index 229b4f79ff..33d1a85d7e 100644 --- a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfInvokeOperationsServiceImplTest.java +++ b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfInvokeOperationsServiceImplTest.java @@ -29,6 +29,7 @@ import javax.ws.rs.container.AsyncResponse; import javax.ws.rs.core.Response.Status; import javax.ws.rs.core.UriInfo; import org.junit.Before; +import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; @@ -42,8 +43,8 @@ import org.opendaylight.mdsal.dom.api.DOMRpcException; import org.opendaylight.mdsal.dom.api.DOMRpcImplementationNotAvailableException; import org.opendaylight.mdsal.dom.api.DOMRpcResult; import org.opendaylight.mdsal.dom.api.DOMRpcService; -import org.opendaylight.mdsal.dom.api.DOMSchemaService; import org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult; +import org.opendaylight.mdsal.dom.spi.FixedDOMSchemaService; import org.opendaylight.restconf.common.context.InstanceIdentifierContext; import org.opendaylight.restconf.common.errors.RestconfDocumentedException; import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils; @@ -62,8 +63,6 @@ import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; @RunWith(MockitoJUnitRunner.StrictStubs.class) public class RestconfInvokeOperationsServiceImplTest { - private static final String PATH_FOR_NEW_SCHEMA_CONTEXT = "/invoke-rpc"; - private static final QName RPC = QName.create("ns", "2015-02-28", "test-rpc"); private static final ContainerNode INPUT = Builders.containerBuilder() .withNodeIdentifier(new NodeIdentifier(QName.create(RPC, "input"))) @@ -74,23 +73,28 @@ public class RestconfInvokeOperationsServiceImplTest { .withChild(ImmutableNodes.leafNode(QName.create(RPC, "content"), "operation result")) .build(); + private static EffectiveModelContext CONTEXT; + @Mock private DOMRpcService rpcService; @Mock private DOMMountPoint mountPoint; private RestconfInvokeOperationsServiceImpl invokeOperationsService; + @BeforeClass + public static void beforeClass() throws Exception { + CONTEXT = YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles("/invoke-rpc")); + } + @Before - public void setup() throws Exception { - final EffectiveModelContext contextRef = - YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles(PATH_FOR_NEW_SCHEMA_CONTEXT)); + public void setup() { final DOMDataBroker dataBroker = mock(DOMDataBroker.class); final DOMDataTreeWriteTransaction wTx = mock(DOMDataTreeWriteTransaction.class); doReturn(wTx).when(dataBroker).newWriteOnlyTransaction(); doReturn(CommitInfo.emptyFluentFuture()).when(wTx).commit(); final SchemaContextHandler schemaContextHandler = new SchemaContextHandler(dataBroker, - mock(DOMSchemaService.class)); - schemaContextHandler.onModelContextUpdated(contextRef); + FixedDOMSchemaService.of(CONTEXT)); + schemaContextHandler.init(); invokeOperationsService = new RestconfInvokeOperationsServiceImpl(rpcService, schemaContextHandler); } @@ -183,6 +187,6 @@ public class RestconfInvokeOperationsServiceImplTest { doReturn(immediateFluentFuture(domRpcResult)).when(rpcService).invokeRpc(qname, data); doReturn(result).when(domRpcResult).getResult(); return NormalizedNodePayload.of( - InstanceIdentifierContext.ofLocalRpc(mock(EffectiveModelContext.class), schemaNode), data); + InstanceIdentifierContext.ofLocalRpc(CONTEXT, schemaNode), data); } }