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);
}
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());
}
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);
}
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());
}
Aggregations