Search in sources :

Example 1 with ClusteringActionException

use of org.opendaylight.netconf.topology.singleton.impl.utils.ClusteringActionException 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 2 with ClusteringActionException

use of org.opendaylight.netconf.topology.singleton.impl.utils.ClusteringActionException in project netconf by opendaylight.

the class ProxyDOMActionService method invokeAction.

@Override
public FluentFuture<DOMActionResult> invokeAction(final Absolute type, final DOMDataTreeIdentifier domDataTreeIdentifier, final ContainerNode input) {
    requireNonNull(type);
    requireNonNull(input);
    requireNonNull(domDataTreeIdentifier);
    LOG.info("{}: Action Operation invoked with schema type: {} and node: {}.", id, type, input);
    final ContainerNodeMessage containerNodeMessage = new ContainerNodeMessage(input);
    final Future<Object> scalaFuture = Patterns.ask(masterActorRef, new InvokeActionMessage(new SchemaPathMessage(type), containerNodeMessage, domDataTreeIdentifier), actorResponseWaitTime);
    final SettableFuture<DOMActionResult> settableFuture = SettableFuture.create();
    scalaFuture.onComplete(new OnComplete<>() {

        @Override
        public void onComplete(final Throwable failure, final Object response) {
            if (failure != null) {
                if (failure instanceof ClusteringActionException) {
                    settableFuture.setException(failure);
                } else {
                    settableFuture.setException(new ClusteringActionException(id + ": Exception during remote Action invocation.", failure));
                }
                return;
            }
            if (response instanceof EmptyResultResponse) {
                settableFuture.set(null);
                return;
            }
            final Collection<? extends RpcError> errors = ((InvokeActionMessageReply) response).getRpcErrors();
            final ContainerNodeMessage containerNodeMessage = ((InvokeActionMessageReply) response).getContainerNodeMessage();
            final DOMActionResult result;
            if (containerNodeMessage == null) {
                result = new SimpleDOMActionResult(ImmutableList.copyOf(errors));
            } else {
                result = new SimpleDOMActionResult(containerNodeMessage.getNode(), ImmutableList.copyOf(errors));
            }
            settableFuture.set(result);
        }
    }, actorSystem.dispatcher());
    return FluentFuture.from(settableFuture);
}
Also used : SchemaPathMessage(org.opendaylight.netconf.topology.singleton.messages.SchemaPathMessage) RpcError(org.opendaylight.yangtools.yang.common.RpcError) EmptyResultResponse(org.opendaylight.netconf.topology.singleton.messages.transactions.EmptyResultResponse) SimpleDOMActionResult(org.opendaylight.mdsal.dom.spi.SimpleDOMActionResult) InvokeActionMessage(org.opendaylight.netconf.topology.singleton.messages.action.InvokeActionMessage) ClusteringActionException(org.opendaylight.netconf.topology.singleton.impl.utils.ClusteringActionException) ContainerNodeMessage(org.opendaylight.netconf.topology.singleton.messages.ContainerNodeMessage) Collection(java.util.Collection) DOMActionResult(org.opendaylight.mdsal.dom.api.DOMActionResult) SimpleDOMActionResult(org.opendaylight.mdsal.dom.spi.SimpleDOMActionResult)

Aggregations

DOMActionResult (org.opendaylight.mdsal.dom.api.DOMActionResult)2 SimpleDOMActionResult (org.opendaylight.mdsal.dom.spi.SimpleDOMActionResult)2 ClusteringActionException (org.opendaylight.netconf.topology.singleton.impl.utils.ClusteringActionException)2 Collection (java.util.Collection)1 ExecutionException (java.util.concurrent.ExecutionException)1 Test (org.junit.Test)1 DOMActionException (org.opendaylight.mdsal.dom.api.DOMActionException)1 DOMActionService (org.opendaylight.mdsal.dom.api.DOMActionService)1 DOMDataTreeIdentifier (org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier)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 QName (org.opendaylight.yangtools.yang.common.QName)1 RpcError (org.opendaylight.yangtools.yang.common.RpcError)1 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)1 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)1 Absolute (org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute)1 RevisionSourceIdentifier (org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier)1 SourceIdentifier (org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier)1