use of org.opendaylight.mdsal.dom.api.DOMActionResult 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.api.DOMActionResult in project controller by opendaylight.
the class RemoteOpsImplementationTest method testInvokeActionWithLookupException.
/**
* This test method invokes remote rpc and lookup failed
* with runtime exception.
*/
@Test(expected = DOMActionException.class)
@SuppressWarnings({ "checkstyle:AvoidHidingCauseException", "checkstyle:IllegalThrows" })
public void testInvokeActionWithLookupException() throws Throwable {
final ContainerNode invokeRpcInput = makeRPCInput("foo");
doThrow(new RuntimeException("test")).when(domActionService2).invokeAction(any(Absolute.class), any(DOMDataTreeIdentifier.class), any(ContainerNode.class));
final ListenableFuture<DOMActionResult> frontEndFuture = remoteActionImpl1.invokeAction(TEST_RPC_TYPE, TEST_DATA_TREE_ID, invokeRpcInput);
assertTrue(frontEndFuture instanceof RemoteDOMActionFuture);
try {
frontEndFuture.get(5, TimeUnit.SECONDS);
} catch (ExecutionException e) {
throw e.getCause();
}
}
use of org.opendaylight.mdsal.dom.api.DOMActionResult 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.api.DOMActionResult in project controller by opendaylight.
the class OpsInvoker method execute.
@SuppressWarnings("checkstyle:IllegalCatch")
private void execute(final ExecuteAction msg) {
LOG.debug("Executing Action {}", msg.getType());
final ActorRef sender = getSender();
final ListenableFuture<? extends DOMActionResult> future;
try {
future = actionService.invokeAction(msg.getType(), msg.getPath(), msg.getInput());
} catch (final RuntimeException e) {
LOG.debug("Failed to invoke action {}", msg.getType(), e);
sender.tell(new Failure(e), self());
return;
}
Futures.addCallback(future, new AbstractCallback<Absolute, DOMActionResult>(getSender(), msg.getType()) {
@Override
Object nullResponse(final Absolute type) {
throw new IllegalStateException("Null invocation result of action " + type);
}
@Override
Object response(final Absolute type, final DOMActionResult result) {
final Collection<? extends RpcError> errors = result.getErrors();
return errors.isEmpty() ? new ActionResponse(result.getOutput(), result.getErrors()) : // discarding any output
new Failure(new RpcErrorsException(String.format("Execution of action %s failed", type), errors));
}
}, MoreExecutors.directExecutor());
}
use of org.opendaylight.mdsal.dom.api.DOMActionResult in project mdsal by opendaylight.
the class ActionAdapter method invoke.
@Override
public Object invoke(final Object proxy, final Method method, final Object[] args) throws NoSuchMethodError {
switch(method.getName()) {
case "equals":
if (args.length == 1) {
return proxy == args[0];
}
break;
case "hashCode":
if (args.length == 0) {
return System.identityHashCode(proxy);
}
break;
case "toString":
if (args.length == 0) {
return spec.type().getName() + "$Adapter{delegate=" + getDelegate() + "}";
}
break;
case "invoke":
if (args.length == 2) {
final InstanceIdentifier<?> path = (InstanceIdentifier<?>) requireNonNull(args[0]);
checkArgument(!path.isWildcarded(), "Cannot invoke action on wildcard path %s", path);
final RpcInput input = (RpcInput) requireNonNull(args[1]);
final CurrentAdapterSerializer serializer = currentSerializer();
final ListenableFuture<? extends DOMActionResult> future = getDelegate().invokeAction(actionPath, new DOMDataTreeIdentifier(LogicalDatastoreType.OPERATIONAL, serializer.toYangInstanceIdentifier(path)), serializer.toLazyNormalizedNodeActionInput(spec.type(), inputName, input));
// Invocation returned a future we know about -- return that future instead
if (ENABLE_CODEC_SHORTCUT && future instanceof BindingRpcFutureAware) {
return ((BindingRpcFutureAware) future).getBindingFuture();
}
return Futures.transform(future, dom -> RpcResultUtil.rpcResultFromDOM(dom.getErrors(), dom.getOutput().map(output -> serializer.fromNormalizedNodeActionOutput(spec.type(), output)).orElse(null)), MoreExecutors.directExecutor());
}
break;
default:
break;
}
throw new NoSuchMethodError("Method " + method.toString() + "is unsupported.");
}
Aggregations