Search in sources :

Example 1 with DOMActionService

use of org.opendaylight.mdsal.dom.api.DOMActionService in project mdsal by opendaylight.

the class DOMRpcRouterTest method testActionInstanceRouting.

@Test
public void testActionInstanceRouting() throws ExecutionException {
    try (DOMRpcRouter rpcRouter = actionsRouter()) {
        final DOMActionProviderService actionProvider = rpcRouter.getActionProviderService();
        assertNotNull(actionProvider);
        final DOMActionService actionConsumer = rpcRouter.getActionService();
        assertNotNull(actionConsumer);
        try (ObjectRegistration<?> reg = actionProvider.registerActionImplementation(IMPL, DOMActionInstance.of(Actions.BAZ_TYPE, LogicalDatastoreType.OPERATIONAL, BAZ_PATH_GOOD))) {
            assertAvailable(actionConsumer, BAZ_PATH_GOOD);
            assertUnavailable(actionConsumer, BAZ_PATH_BAD);
        }
        assertUnavailable(actionConsumer, BAZ_PATH_BAD);
        assertUnavailable(actionConsumer, BAZ_PATH_GOOD);
    }
}
Also used : DOMActionService(org.opendaylight.mdsal.dom.api.DOMActionService) DOMActionProviderService(org.opendaylight.mdsal.dom.api.DOMActionProviderService) Test(org.junit.Test)

Example 2 with DOMActionService

use of org.opendaylight.mdsal.dom.api.DOMActionService in project mdsal by opendaylight.

the class DOMRpcRouterTest method testActionDatastoreRouting.

@Test
public void testActionDatastoreRouting() throws ExecutionException {
    try (DOMRpcRouter rpcRouter = actionsRouter()) {
        final DOMActionProviderService actionProvider = rpcRouter.getActionProviderService();
        assertNotNull(actionProvider);
        final DOMActionService actionConsumer = rpcRouter.getActionService();
        assertNotNull(actionConsumer);
        try (ObjectRegistration<?> reg = actionProvider.registerActionImplementation(IMPL, DOMActionInstance.of(Actions.BAZ_TYPE, LogicalDatastoreType.OPERATIONAL, YangInstanceIdentifier.empty()))) {
            assertAvailable(actionConsumer, BAZ_PATH_GOOD);
            assertAvailable(actionConsumer, BAZ_PATH_BAD);
        }
        assertUnavailable(actionConsumer, BAZ_PATH_BAD);
        assertUnavailable(actionConsumer, BAZ_PATH_GOOD);
    }
}
Also used : DOMActionService(org.opendaylight.mdsal.dom.api.DOMActionService) DOMActionProviderService(org.opendaylight.mdsal.dom.api.DOMActionProviderService) Test(org.junit.Test)

Example 3 with DOMActionService

use of org.opendaylight.mdsal.dom.api.DOMActionService in project netconf by opendaylight.

the class NetconfNodeActorTest method testSlaveInvokeAction.

@Test
public void testSlaveInvokeAction() throws Exception {
    final List<SourceIdentifier> sourceIdentifiers = Lists.newArrayList(RevisionSourceIdentifier.create("testActionID"));
    initializeMaster(sourceIdentifiers);
    registerSlaveMountPoint();
    ArgumentCaptor<DOMActionService> domActionServiceCaptor = ArgumentCaptor.forClass(DOMActionService.class);
    verify(mockMountPointBuilder).addService(eq(DOMActionService.class), domActionServiceCaptor.capture());
    final DOMActionService slaveDomActionService = domActionServiceCaptor.getValue();
    assertTrue(slaveDomActionService instanceof ProxyDOMActionService);
    final QName testQName = QName.create("test", "2019-08-16", "TestActionQname");
    final Absolute schemaPath = Absolute.of(testQName);
    final YangInstanceIdentifier yangIIdPath = YangInstanceIdentifier.create(new YangInstanceIdentifier.NodeIdentifier(testQName));
    final DOMDataTreeIdentifier domDataTreeIdentifier = new DOMDataTreeIdentifier(LogicalDatastoreType.OPERATIONAL, yangIIdPath);
    final ContainerNode outputNode = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(testQName)).withChild(ImmutableNodes.leafNode(testQName, "foo")).build();
    // Action with no response output.
    doReturn(FluentFutures.immediateNullFluentFuture()).when(mockDOMActionService).invokeAction(any(), any(), any());
    DOMActionResult result = slaveDomActionService.invokeAction(schemaPath, domDataTreeIdentifier, outputNode).get(2, TimeUnit.SECONDS);
    assertEquals(null, result);
    // Action with response output.
    doReturn(FluentFutures.immediateFluentFuture(new SimpleDOMActionResult(outputNode))).when(mockDOMActionService).invokeAction(any(), any(), any());
    result = slaveDomActionService.invokeAction(schemaPath, domDataTreeIdentifier, outputNode).get(2, TimeUnit.SECONDS);
    assertEquals(outputNode, result.getOutput().get());
    assertTrue(result.getErrors().isEmpty());
    // Action failure.
    doReturn(FluentFutures.immediateFailedFluentFuture(new ClusteringActionException("mock"))).when(mockDOMActionService).invokeAction(any(), any(), any());
    final ListenableFuture<? extends DOMActionResult> future = slaveDomActionService.invokeAction(schemaPath, domDataTreeIdentifier, outputNode);
    final ExecutionException e = assertThrows(ExecutionException.class, () -> future.get(2, TimeUnit.SECONDS));
    final Throwable cause = e.getCause();
    assertThat(cause, instanceOf(DOMActionException.class));
    assertEquals("mock", cause.getMessage());
}
Also used : QName(org.opendaylight.yangtools.yang.common.QName) DOMDataTreeIdentifier(org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier) SourceIdentifier(org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier) RevisionSourceIdentifier(org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier) DOMActionException(org.opendaylight.mdsal.dom.api.DOMActionException) Absolute(org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) DOMActionService(org.opendaylight.mdsal.dom.api.DOMActionService) SimpleDOMActionResult(org.opendaylight.mdsal.dom.spi.SimpleDOMActionResult) ClusteringActionException(org.opendaylight.netconf.topology.singleton.impl.utils.ClusteringActionException) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) DOMActionResult(org.opendaylight.mdsal.dom.api.DOMActionResult) SimpleDOMActionResult(org.opendaylight.mdsal.dom.spi.SimpleDOMActionResult) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 4 with DOMActionService

use of org.opendaylight.mdsal.dom.api.DOMActionService in project netconf by opendaylight.

the class Netconf799Test method testInvokeAction.

@Test
public void testInvokeAction() throws FileNotFoundException {
    final EffectiveModelContext contextRef = YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles("/instanceidentifier/yang"));
    final DOMDataBroker mockDataBroker = mock(DOMDataBroker.class);
    final SchemaContextHandler schemaContextHandler = new SchemaContextHandler(mockDataBroker, mock(DOMSchemaService.class));
    schemaContextHandler.onModelContextUpdated(contextRef);
    final DOMActionService actionService = mock(DOMActionService.class);
    doReturn(Futures.immediateFuture(new SimpleDOMActionResult(Builders.containerBuilder().withNodeIdentifier(NodeIdentifier.create(OUTPUT_QNAME)).build()))).when(actionService).invokeAction(eq(Absolute.of(CONT_QNAME, CONT1_QNAME, RESET_QNAME)), any(), any());
    final RestconfDataServiceImpl dataService = new RestconfDataServiceImpl(schemaContextHandler, mockDataBroker, mock(DOMMountPointService.class), mock(RestconfStreamsSubscriptionService.class), actionService, mock(Configuration.class));
    final var schemaNode = loadAction(contextRef, RESET_QNAME, ACTION_YII).orElseThrow();
    final var response = dataService.invokeAction(NormalizedNodePayload.of(new InstanceIdentifierContext<>(ACTION_YII, schemaNode, null, contextRef), Builders.containerBuilder().withNodeIdentifier(NodeIdentifier.create(INPUT_QNAME)).withChild(ImmutableNodes.leafNode(DELAY_QNAME, Uint32.TEN)).build()));
    assertEquals(204, response.getStatus());
    assertNull(response.getEntity());
}
Also used : DOMActionService(org.opendaylight.mdsal.dom.api.DOMActionService) SchemaContextHandler(org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler) SimpleDOMActionResult(org.opendaylight.mdsal.dom.spi.SimpleDOMActionResult) Configuration(org.opendaylight.restconf.nb.rfc8040.streams.Configuration) RestconfStreamsSubscriptionService(org.opendaylight.restconf.nb.rfc8040.rests.services.api.RestconfStreamsSubscriptionService) DOMMountPointService(org.opendaylight.mdsal.dom.api.DOMMountPointService) InstanceIdentifierContext(org.opendaylight.restconf.common.context.InstanceIdentifierContext) DOMDataBroker(org.opendaylight.mdsal.dom.api.DOMDataBroker) DOMSchemaService(org.opendaylight.mdsal.dom.api.DOMSchemaService) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext) Test(org.junit.Test)

Example 5 with DOMActionService

use of org.opendaylight.mdsal.dom.api.DOMActionService in project mdsal by opendaylight.

the class OSGiRpcRouterTest method testAction.

@Test
public void testAction() {
    final DOMActionService delegate = mock(DOMActionService.class);
    doReturn(delegate).when(router).getActionService();
    new OSGiDOMActionService(router);
// FIXME: invoke something to test delegate()
}
Also used : DOMActionService(org.opendaylight.mdsal.dom.api.DOMActionService) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)5 DOMActionService (org.opendaylight.mdsal.dom.api.DOMActionService)5 DOMActionProviderService (org.opendaylight.mdsal.dom.api.DOMActionProviderService)2 SimpleDOMActionResult (org.opendaylight.mdsal.dom.spi.SimpleDOMActionResult)2 ExecutionException (java.util.concurrent.ExecutionException)1 DOMActionException (org.opendaylight.mdsal.dom.api.DOMActionException)1 DOMActionResult (org.opendaylight.mdsal.dom.api.DOMActionResult)1 DOMDataBroker (org.opendaylight.mdsal.dom.api.DOMDataBroker)1 DOMDataTreeIdentifier (org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier)1 DOMMountPointService (org.opendaylight.mdsal.dom.api.DOMMountPointService)1 DOMSchemaService (org.opendaylight.mdsal.dom.api.DOMSchemaService)1 ClusteringActionException (org.opendaylight.netconf.topology.singleton.impl.utils.ClusteringActionException)1 InstanceIdentifierContext (org.opendaylight.restconf.common.context.InstanceIdentifierContext)1 SchemaContextHandler (org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler)1 RestconfStreamsSubscriptionService (org.opendaylight.restconf.nb.rfc8040.rests.services.api.RestconfStreamsSubscriptionService)1 Configuration (org.opendaylight.restconf.nb.rfc8040.streams.Configuration)1 QName (org.opendaylight.yangtools.yang.common.QName)1 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)1 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)1 EffectiveModelContext (org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)1