Search in sources :

Example 1 with SimpleDOMActionResult

use of org.opendaylight.mdsal.dom.spi.SimpleDOMActionResult in project controller by opendaylight.

the class RemoteOpsImplementationTest method testInvokeAction.

/**
 * This test method invokes and executes the remote action.
 */
@Test
public void testInvokeAction() throws Exception {
    final ContainerNode actionOutput = makeRPCOutput("bar");
    final DOMActionResult actionResult = new SimpleDOMActionResult(actionOutput, Collections.emptyList());
    final NormalizedNode invokeActionInput = makeRPCInput("foo");
    @SuppressWarnings({ "unchecked", "rawtypes" }) final ArgumentCaptor<ContainerNode> inputCaptor = ArgumentCaptor.forClass(ContainerNode.class);
    doReturn(FluentFutures.immediateFluentFuture(actionResult)).when(domActionService2).invokeAction(eq(TEST_RPC_TYPE), eq(TEST_DATA_TREE_ID), inputCaptor.capture());
    final ListenableFuture<DOMActionResult> frontEndFuture = remoteActionImpl1.invokeAction(TEST_RPC_TYPE, TEST_DATA_TREE_ID, (ContainerNode) invokeActionInput);
    assertTrue(frontEndFuture instanceof RemoteDOMActionFuture);
    final DOMActionResult result = frontEndFuture.get(5, TimeUnit.SECONDS);
    assertEquals(actionOutput, result.getOutput().get());
}
Also used : SimpleDOMActionResult(org.opendaylight.mdsal.dom.spi.SimpleDOMActionResult) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) DOMActionResult(org.opendaylight.mdsal.dom.api.DOMActionResult) SimpleDOMActionResult(org.opendaylight.mdsal.dom.spi.SimpleDOMActionResult) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) Test(org.junit.Test)

Example 2 with SimpleDOMActionResult

use of org.opendaylight.mdsal.dom.spi.SimpleDOMActionResult in project controller by opendaylight.

the class RemoteOpsImplementationTest method testInvokeActionWithNullInput.

/**
 * This test method invokes and executes the remote action.
 */
@Test
public void testInvokeActionWithNullInput() throws Exception {
    final ContainerNode actionOutput = makeRPCOutput("bar");
    final DOMActionResult actionResult = new SimpleDOMActionResult(actionOutput);
    @SuppressWarnings({ "unchecked", "rawtypes" }) final ArgumentCaptor<ContainerNode> inputCaptor = ArgumentCaptor.forClass(ContainerNode.class);
    doReturn(FluentFutures.immediateFluentFuture(actionResult)).when(domActionService2).invokeAction(eq(TEST_RPC_TYPE), eq(TEST_DATA_TREE_ID), inputCaptor.capture());
    ListenableFuture<DOMActionResult> frontEndFuture = remoteActionImpl1.invokeAction(TEST_RPC_TYPE, TEST_DATA_TREE_ID, actionOutput);
    assertTrue(frontEndFuture instanceof RemoteDOMActionFuture);
    final DOMActionResult result = frontEndFuture.get(5, TimeUnit.SECONDS);
    assertEquals(actionOutput, result.getOutput().get());
}
Also used : SimpleDOMActionResult(org.opendaylight.mdsal.dom.spi.SimpleDOMActionResult) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) DOMActionResult(org.opendaylight.mdsal.dom.api.DOMActionResult) SimpleDOMActionResult(org.opendaylight.mdsal.dom.spi.SimpleDOMActionResult) Test(org.junit.Test)

Example 3 with SimpleDOMActionResult

use of org.opendaylight.mdsal.dom.spi.SimpleDOMActionResult in project controller by opendaylight.

the class RemoteDOMActionFuture method processReply.

@Override
DOMActionResult processReply(final Object reply) {
    if (reply instanceof ActionResponse) {
        final ActionResponse actionReply = (ActionResponse) reply;
        final ContainerNode output = actionReply.getOutput();
        return output == null ? new SimpleDOMActionResult(actionReply.getErrors()) : new SimpleDOMActionResult(output, actionReply.getErrors());
    }
    return null;
}
Also used : SimpleDOMActionResult(org.opendaylight.mdsal.dom.spi.SimpleDOMActionResult) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) ActionResponse(org.opendaylight.controller.remote.rpc.messages.ActionResponse)

Example 4 with SimpleDOMActionResult

use of org.opendaylight.mdsal.dom.spi.SimpleDOMActionResult in project netconf by opendaylight.

the class NetconfMessageTransformer method toActionResult.

@Override
public DOMActionResult toActionResult(final Absolute action, final NetconfMessage message) {
    final ActionDefinition actionDefinition = actions.get(action);
    Preconditions.checkArgument(actionDefinition != null, "Action does not exist: %s", action);
    final ContainerNode normalizedNode = (ContainerNode) parseResult(message, actionDefinition);
    if (normalizedNode == null) {
        return new SimpleDOMActionResult(Collections.emptyList());
    } else {
        return new SimpleDOMActionResult(normalizedNode, Collections.emptyList());
    }
}
Also used : SimpleDOMActionResult(org.opendaylight.mdsal.dom.spi.SimpleDOMActionResult) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) ActionDefinition(org.opendaylight.yangtools.yang.model.api.ActionDefinition)

Example 5 with SimpleDOMActionResult

use of org.opendaylight.mdsal.dom.spi.SimpleDOMActionResult 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)

Aggregations

SimpleDOMActionResult (org.opendaylight.mdsal.dom.spi.SimpleDOMActionResult)9 Test (org.junit.Test)5 DOMActionResult (org.opendaylight.mdsal.dom.api.DOMActionResult)5 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)5 ExecutionException (java.util.concurrent.ExecutionException)2 DOMActionService (org.opendaylight.mdsal.dom.api.DOMActionService)2 ClusteringActionException (org.opendaylight.netconf.topology.singleton.impl.utils.ClusteringActionException)2 Collection (java.util.Collection)1 ActionResponse (org.opendaylight.controller.remote.rpc.messages.ActionResponse)1 DOMActionException (org.opendaylight.mdsal.dom.api.DOMActionException)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 ContainerNodeMessage (org.opendaylight.netconf.topology.singleton.messages.ContainerNodeMessage)1 SchemaPathMessage (org.opendaylight.netconf.topology.singleton.messages.SchemaPathMessage)1 InvokeActionMessage (org.opendaylight.netconf.topology.singleton.messages.action.InvokeActionMessage)1 EmptyResultResponse (org.opendaylight.netconf.topology.singleton.messages.transactions.EmptyResultResponse)1 InstanceIdentifierContext (org.opendaylight.restconf.common.context.InstanceIdentifierContext)1 SchemaContextHandler (org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler)1