Search in sources :

Example 1 with DOMActionResult

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());
}
Also used : SimpleDOMActionResult(org.opendaylight.mdsal.dom.spi.SimpleDOMActionResult) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) DOMActionResult(org.opendaylight.mdsal.dom.api.DOMActionResult) SimpleDOMActionResult(org.opendaylight.mdsal.dom.spi.SimpleDOMActionResult) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) Test(org.junit.Test)

Example 2 with DOMActionResult

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();
    }
}
Also used : DOMDataTreeIdentifier(org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) Absolute(org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute) DOMActionResult(org.opendaylight.mdsal.dom.api.DOMActionResult) SimpleDOMActionResult(org.opendaylight.mdsal.dom.spi.SimpleDOMActionResult) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 3 with DOMActionResult

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());
}
Also used : SimpleDOMActionResult(org.opendaylight.mdsal.dom.spi.SimpleDOMActionResult) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) DOMActionResult(org.opendaylight.mdsal.dom.api.DOMActionResult) SimpleDOMActionResult(org.opendaylight.mdsal.dom.spi.SimpleDOMActionResult) Test(org.junit.Test)

Example 4 with DOMActionResult

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());
}
Also used : ActorRef(akka.actor.ActorRef) RpcError(org.opendaylight.yangtools.yang.common.RpcError) Absolute(org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute) ActionResponse(org.opendaylight.controller.remote.rpc.messages.ActionResponse) Collection(java.util.Collection) DOMActionResult(org.opendaylight.mdsal.dom.api.DOMActionResult) Failure(akka.actor.Status.Failure)

Example 5 with DOMActionResult

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.");
}
Also used : DOMDataTreeIdentifier(org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier) DOMActionResult(org.opendaylight.mdsal.dom.api.DOMActionResult) DOMActionService(org.opendaylight.mdsal.dom.api.DOMActionService) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) YangConstants.operationInputQName(org.opendaylight.yangtools.yang.common.YangConstants.operationInputQName) ActionSpec(org.opendaylight.mdsal.binding.api.ActionSpec) Absolute(org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Futures(com.google.common.util.concurrent.Futures) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) Objects.requireNonNull(java.util.Objects.requireNonNull) LogicalDatastoreType(org.opendaylight.mdsal.common.api.LogicalDatastoreType) InvocationHandler(java.lang.reflect.InvocationHandler) RpcInput(org.opendaylight.yangtools.yang.binding.RpcInput) ENABLE_CODEC_SHORTCUT(org.opendaylight.mdsal.binding.dom.adapter.StaticConfiguration.ENABLE_CODEC_SHORTCUT) Method(java.lang.reflect.Method) NonNull(org.eclipse.jdt.annotation.NonNull) DOMDataTreeIdentifier(org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier) RpcInput(org.opendaylight.yangtools.yang.binding.RpcInput) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier)

Aggregations

DOMActionResult (org.opendaylight.mdsal.dom.api.DOMActionResult)14 SimpleDOMActionResult (org.opendaylight.mdsal.dom.spi.SimpleDOMActionResult)9 Test (org.junit.Test)8 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)7 ExecutionException (java.util.concurrent.ExecutionException)6 Absolute (org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute)5 DOMDataTreeIdentifier (org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier)4 DOMActionService (org.opendaylight.mdsal.dom.api.DOMActionService)3 NetconfMessage (org.opendaylight.netconf.api.NetconfMessage)3 AbstractBaseSchemasTest (org.opendaylight.netconf.sal.connect.netconf.AbstractBaseSchemasTest)3 RpcError (org.opendaylight.yangtools.yang.common.RpcError)3 Futures (com.google.common.util.concurrent.Futures)2 MoreExecutors (com.google.common.util.concurrent.MoreExecutors)2 Collection (java.util.Collection)2 Objects.requireNonNull (java.util.Objects.requireNonNull)2 LogicalDatastoreType (org.opendaylight.mdsal.common.api.LogicalDatastoreType)2 DOMActionException (org.opendaylight.mdsal.dom.api.DOMActionException)2 ClusteringActionException (org.opendaylight.netconf.topology.singleton.impl.utils.ClusteringActionException)2 QName (org.opendaylight.yangtools.yang.common.QName)2 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)2