Search in sources :

Example 6 with SimpleDOMActionResult

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

Example 7 with SimpleDOMActionResult

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

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

the class BindingOperationFluentFuture method userFutureCompleted.

@SuppressWarnings("checkstyle:illegalCatch")
private void userFutureCompleted() {
    final DOMActionResult domResult;
    try {
        final RpcResult<O> bindingResult = Futures.getDone(userFuture);
        if (bindingResult.getResult() != null) {
            domResult = new SimpleDOMActionResult(adapterContext.currentSerializer().toLazyNormalizedNodeActionOutput(action, identifier, bindingResult.getResult()), bindingResult.getErrors());
        } else {
            domResult = new SimpleDOMActionResult(bindingResult.getErrors());
        }
    } catch (ExecutionException e) {
        adapterContext = null;
        setException(e.getCause());
        return;
    } catch (RuntimeException | Error e) {
        adapterContext = null;
        setException(e);
        return;
    }
    adapterContext = null;
    set(domResult);
}
Also used : SimpleDOMActionResult(org.opendaylight.mdsal.dom.spi.SimpleDOMActionResult) DOMActionResult(org.opendaylight.mdsal.dom.api.DOMActionResult) SimpleDOMActionResult(org.opendaylight.mdsal.dom.spi.SimpleDOMActionResult) ExecutionException(java.util.concurrent.ExecutionException)

Example 9 with SimpleDOMActionResult

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

the class ActionServiceAdapterTest method testInvocation.

@Test
public void testInvocation() throws ExecutionException {
    final Foo handle = service.getActionHandle(ActionSpec.builder(Cont.class).build(Foo.class));
    final ListenableFuture<RpcResult<Output>> future = handle.invoke(InstanceIdentifier.create(Cont.class), BINDING_FOO_INPUT);
    assertNotNull(future);
    assertFalse(future.isDone());
    domResult.set(new SimpleDOMActionResult(DOM_FOO_OUTPUT, List.of()));
    final RpcResult<Output> bindingResult = Futures.getDone(future);
    assertEquals(List.of(), bindingResult.getErrors());
    assertEquals(BINDING_FOO_OUTPUT, bindingResult.getResult());
}
Also used : Cont(org.opendaylight.yang.gen.v1.urn.odl.actions.norev.Cont) SimpleDOMActionResult(org.opendaylight.mdsal.dom.spi.SimpleDOMActionResult) Foo(org.opendaylight.yang.gen.v1.urn.odl.actions.norev.cont.Foo) Output(org.opendaylight.yang.gen.v1.urn.odl.actions.norev.cont.foo.Output) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) 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