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