Search in sources :

Example 6 with DOMRpcResult

use of org.opendaylight.controller.md.sal.dom.api.DOMRpcResult in project controller by opendaylight.

the class RpcServiceAdapter method transformFuture.

private static ListenableFuture<RpcResult<?>> transformFuture(final SchemaPath rpc, final ListenableFuture<DOMRpcResult> domFuture, final BindingNormalizedNodeSerializer codec) {
    return Futures.transform(domFuture, input -> {
        final NormalizedNode<?, ?> domData = input.getResult();
        final DataObject bindingResult;
        if (domData != null) {
            final SchemaPath rpcOutput = rpc.createChild(QName.create(rpc.getLastComponent(), "output"));
            bindingResult = codec.fromNormalizedNodeRpcData(rpcOutput, (ContainerNode) domData);
        } else {
            bindingResult = null;
        }
        // DOMRpcResult does not have a notion of success, hence we have to reverse-engineer it by looking
        // at reported errors and checking whether they are just warnings.
        final Collection<RpcError> errors = input.getErrors();
        return RpcResult.class.cast(RpcResultBuilder.status(errors.stream().noneMatch(error -> error.getSeverity() == ErrorSeverity.ERROR)).withResult(bindingResult).withRpcErrors(errors).build());
    }, MoreExecutors.directExecutor());
}
Also used : DOMRpcResult(org.opendaylight.controller.md.sal.dom.api.DOMRpcResult) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) SchemaPath(org.opendaylight.yangtools.yang.model.api.SchemaPath) Proxy(java.lang.reflect.Proxy) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) ErrorSeverity(org.opendaylight.yangtools.yang.common.RpcError.ErrorSeverity) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) DataContainer(org.opendaylight.yangtools.yang.binding.DataContainer) RpcDefinition(org.opendaylight.yangtools.yang.model.api.RpcDefinition) CheckedFuture(com.google.common.util.concurrent.CheckedFuture) BindingReflections(org.opendaylight.yangtools.yang.binding.util.BindingReflections) RpcRoutingStrategy(org.opendaylight.controller.md.sal.dom.broker.spi.rpc.RpcRoutingStrategy) RpcService(org.opendaylight.yangtools.yang.binding.RpcService) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) BindingNormalizedNodeSerializer(org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer) DataObject(org.opendaylight.yangtools.yang.binding.DataObject) Method(java.lang.reflect.Method) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) LeafNode(org.opendaylight.yangtools.yang.data.api.schema.LeafNode) DOMRpcService(org.opendaylight.controller.md.sal.dom.api.DOMRpcService) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) DOMRpcException(org.opendaylight.controller.md.sal.dom.api.DOMRpcException) QName(org.opendaylight.yangtools.yang.common.QName) Futures(com.google.common.util.concurrent.Futures) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) RpcResultBuilder(org.opendaylight.yangtools.yang.common.RpcResultBuilder) ImmutableNodes(org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes) Entry(java.util.Map.Entry) Preconditions(com.google.common.base.Preconditions) InvocationHandler(java.lang.reflect.InvocationHandler) RpcError(org.opendaylight.yangtools.yang.common.RpcError) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) DataObject(org.opendaylight.yangtools.yang.binding.DataObject) SchemaPath(org.opendaylight.yangtools.yang.model.api.SchemaPath) RpcError(org.opendaylight.yangtools.yang.common.RpcError) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)

Example 7 with DOMRpcResult

use of org.opendaylight.controller.md.sal.dom.api.DOMRpcResult in project controller by opendaylight.

the class RoutedDOMRpcRoutingTableEntry method invokeRpc.

@Override
protected CheckedFuture<DOMRpcResult, DOMRpcException> invokeRpc(final NormalizedNode<?, ?> input) {
    final Optional<NormalizedNode<?, ?>> maybeKey = NormalizedNodes.findNode(input, keyId);
    // Routing key is present, attempt to deliver as a routed RPC
    if (maybeKey.isPresent()) {
        final NormalizedNode<?, ?> key = maybeKey.get();
        final Object value = key.getValue();
        if (value instanceof YangInstanceIdentifier) {
            final YangInstanceIdentifier iid = (YangInstanceIdentifier) value;
            // Find a DOMRpcImplementation for a specific iid
            final List<DOMRpcImplementation> specificImpls = getImplementations(iid);
            if (specificImpls != null) {
                return specificImpls.get(0).invokeRpc(DOMRpcIdentifier.create(getSchemaPath(), iid), input);
            }
            LOG.debug("No implementation for context {} found will now look for wildcard id", iid);
            // Find a DOMRpcImplementation for a wild card. Usually remote-rpc-connector would register an
            // implementation this way
            final List<DOMRpcImplementation> mayBeRemoteImpls = getImplementations(YangInstanceIdentifier.EMPTY);
            if (mayBeRemoteImpls != null) {
                return mayBeRemoteImpls.get(0).invokeRpc(DOMRpcIdentifier.create(getSchemaPath(), iid), input);
            }
        } else {
            LOG.warn("Ignoring wrong context value {}", value);
        }
    }
    final List<DOMRpcImplementation> impls = getImplementations(null);
    if (impls != null) {
        return impls.get(0).invokeRpc(globalRpcId, input);
    } else {
        return Futures.<DOMRpcResult, DOMRpcException>immediateFailedCheckedFuture(new DOMRpcImplementationNotAvailableException("No implementation of RPC %s available", getSchemaPath()));
    }
}
Also used : DOMRpcResult(org.opendaylight.controller.md.sal.dom.api.DOMRpcResult) DOMRpcImplementation(org.opendaylight.controller.md.sal.dom.api.DOMRpcImplementation) DOMRpcImplementationNotAvailableException(org.opendaylight.controller.md.sal.dom.api.DOMRpcImplementationNotAvailableException) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) DOMRpcException(org.opendaylight.controller.md.sal.dom.api.DOMRpcException) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)

Example 8 with DOMRpcResult

use of org.opendaylight.controller.md.sal.dom.api.DOMRpcResult in project controller by opendaylight.

the class RemoteRpcImplementationTest method testInvokeRpcWithNullInput.

/**
 * This test method invokes and executes the remote rpc.
 */
@Test
public void testInvokeRpcWithNullInput() throws Exception {
    final ContainerNode rpcOutput = makeRPCOutput("bar");
    final DOMRpcResult rpcResult = new DefaultDOMRpcResult(rpcOutput);
    @SuppressWarnings({ "unchecked", "rawtypes" }) final ArgumentCaptor<NormalizedNode<?, ?>> inputCaptor = (ArgumentCaptor) ArgumentCaptor.forClass(NormalizedNode.class);
    when(domRpcService2.invokeRpc(eq(TEST_RPC_TYPE), inputCaptor.capture())).thenReturn(Futures.<DOMRpcResult, DOMRpcException>immediateCheckedFuture(rpcResult));
    final CheckedFuture<DOMRpcResult, DOMRpcException> frontEndFuture = remoteRpcImpl1.invokeRpc(TEST_RPC_ID, null);
    assertTrue(frontEndFuture instanceof RemoteDOMRpcFuture);
    final DOMRpcResult result = frontEndFuture.checkedGet(5, TimeUnit.SECONDS);
    assertEquals(rpcOutput, result.getResult());
}
Also used : DefaultDOMRpcResult(org.opendaylight.controller.md.sal.dom.spi.DefaultDOMRpcResult) ArgumentCaptor(org.mockito.ArgumentCaptor) DOMRpcResult(org.opendaylight.controller.md.sal.dom.api.DOMRpcResult) DefaultDOMRpcResult(org.opendaylight.controller.md.sal.dom.spi.DefaultDOMRpcResult) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) DOMRpcException(org.opendaylight.controller.md.sal.dom.api.DOMRpcException) Test(org.junit.Test)

Example 9 with DOMRpcResult

use of org.opendaylight.controller.md.sal.dom.api.DOMRpcResult in project controller by opendaylight.

the class RemoteRpcImplementationTest method testInvokeRpcWithNoOutput.

/**
 * This test method invokes and executes the remote rpc.
 */
@Test
public void testInvokeRpcWithNoOutput() throws Exception {
    final ContainerNode rpcOutput = null;
    final DOMRpcResult rpcResult = new DefaultDOMRpcResult(rpcOutput);
    final NormalizedNode<?, ?> invokeRpcInput = makeRPCInput("foo");
    @SuppressWarnings({ "unchecked", "rawtypes" }) final ArgumentCaptor<NormalizedNode<?, ?>> inputCaptor = (ArgumentCaptor) ArgumentCaptor.forClass(NormalizedNode.class);
    when(domRpcService2.invokeRpc(eq(TEST_RPC_TYPE), inputCaptor.capture())).thenReturn(Futures.<DOMRpcResult, DOMRpcException>immediateCheckedFuture(rpcResult));
    final CheckedFuture<DOMRpcResult, DOMRpcException> frontEndFuture = remoteRpcImpl1.invokeRpc(TEST_RPC_ID, invokeRpcInput);
    assertTrue(frontEndFuture instanceof RemoteDOMRpcFuture);
    final DOMRpcResult result = frontEndFuture.checkedGet(5, TimeUnit.SECONDS);
    assertNull(result.getResult());
}
Also used : DefaultDOMRpcResult(org.opendaylight.controller.md.sal.dom.spi.DefaultDOMRpcResult) ArgumentCaptor(org.mockito.ArgumentCaptor) DOMRpcResult(org.opendaylight.controller.md.sal.dom.api.DOMRpcResult) DefaultDOMRpcResult(org.opendaylight.controller.md.sal.dom.spi.DefaultDOMRpcResult) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) DOMRpcException(org.opendaylight.controller.md.sal.dom.api.DOMRpcException) Test(org.junit.Test)

Example 10 with DOMRpcResult

use of org.opendaylight.controller.md.sal.dom.api.DOMRpcResult in project controller by opendaylight.

the class RemoteRpcImplementationTest method testInvokeRpc.

/**
 * This test method invokes and executes the remote rpc.
 */
@Test
public void testInvokeRpc() throws Exception {
    final ContainerNode rpcOutput = makeRPCOutput("bar");
    final DOMRpcResult rpcResult = new DefaultDOMRpcResult(rpcOutput);
    final NormalizedNode<?, ?> invokeRpcInput = makeRPCInput("foo");
    @SuppressWarnings({ "unchecked", "rawtypes" }) final ArgumentCaptor<NormalizedNode<?, ?>> inputCaptor = (ArgumentCaptor) ArgumentCaptor.forClass(NormalizedNode.class);
    when(domRpcService2.invokeRpc(eq(TEST_RPC_TYPE), inputCaptor.capture())).thenReturn(Futures.<DOMRpcResult, DOMRpcException>immediateCheckedFuture(rpcResult));
    final CheckedFuture<DOMRpcResult, DOMRpcException> frontEndFuture = remoteRpcImpl1.invokeRpc(TEST_RPC_ID, invokeRpcInput);
    assertTrue(frontEndFuture instanceof RemoteDOMRpcFuture);
    final DOMRpcResult result = frontEndFuture.checkedGet(5, TimeUnit.SECONDS);
    assertEquals(rpcOutput, result.getResult());
}
Also used : DefaultDOMRpcResult(org.opendaylight.controller.md.sal.dom.spi.DefaultDOMRpcResult) ArgumentCaptor(org.mockito.ArgumentCaptor) DOMRpcResult(org.opendaylight.controller.md.sal.dom.api.DOMRpcResult) DefaultDOMRpcResult(org.opendaylight.controller.md.sal.dom.spi.DefaultDOMRpcResult) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) DOMRpcException(org.opendaylight.controller.md.sal.dom.api.DOMRpcException) Test(org.junit.Test)

Aggregations

DOMRpcResult (org.opendaylight.controller.md.sal.dom.api.DOMRpcResult)10 Test (org.junit.Test)6 DOMRpcException (org.opendaylight.controller.md.sal.dom.api.DOMRpcException)6 DefaultDOMRpcResult (org.opendaylight.controller.md.sal.dom.spi.DefaultDOMRpcResult)6 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)6 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)6 ArgumentCaptor (org.mockito.ArgumentCaptor)3 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)3 SchemaPath (org.opendaylight.yangtools.yang.model.api.SchemaPath)3 DOMRpcService (org.opendaylight.controller.md.sal.dom.api.DOMRpcService)2 RpcResponse (org.opendaylight.controller.remote.rpc.messages.RpcResponse)2 DataObject (org.opendaylight.yangtools.yang.binding.DataObject)2 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)2 ActorRef (akka.actor.ActorRef)1 TestKit (akka.testkit.javadsl.TestKit)1 Preconditions (com.google.common.base.Preconditions)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 CheckedFuture (com.google.common.util.concurrent.CheckedFuture)1 Futures (com.google.common.util.concurrent.Futures)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1