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