Search in sources :

Example 1 with DOMRpcException

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

the class RpcBrokerTest method testExecuteRpcFailureWithException.

@Test
public void testExecuteRpcFailureWithException() {
    new TestKit(node1) {

        {
            when(domRpcService1.invokeRpc(eq(TEST_RPC_TYPE), Mockito.<NormalizedNode<?, ?>>any())).thenReturn(Futures.<DOMRpcResult, DOMRpcException>immediateFailedCheckedFuture(new DOMRpcImplementationNotAvailableException("NOT FOUND")));
            final ExecuteRpc executeMsg = ExecuteRpc.from(TEST_RPC_ID, null);
            rpcInvoker1.tell(executeMsg, getRef());
            final Failure rpcResponse = expectMsgClass(duration("5 seconds"), akka.actor.Status.Failure.class);
            Assert.assertTrue(rpcResponse.cause() instanceof DOMRpcException);
        }
    };
}
Also used : DOMRpcImplementationNotAvailableException(org.opendaylight.controller.md.sal.dom.api.DOMRpcImplementationNotAvailableException) ExecuteRpc(org.opendaylight.controller.remote.rpc.messages.ExecuteRpc) TestKit(akka.testkit.javadsl.TestKit) DOMRpcException(org.opendaylight.controller.md.sal.dom.api.DOMRpcException) Failure(akka.actor.Status.Failure) Test(org.junit.Test)

Example 2 with DOMRpcException

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

the class DOMRpcServiceTestBugfix560 method test.

@Test
public void test() throws ExecutionException, InterruptedException {
    // FIXME: This is made to only make sure instance identifier codec for path is instantiated.
    domMountPointService.createMountPoint(BI_MOUNT_ID).addService(DOMRpcService.class, new DOMRpcService() {

        @Override
        public <T extends DOMRpcAvailabilityListener> ListenerRegistration<T> registerRpcListener(final T arg0) {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public CheckedFuture<DOMRpcResult, DOMRpcException> invokeRpc(final SchemaPath arg0, final NormalizedNode<?, ?> arg1) {
            final DOMRpcResult result = new DefaultDOMRpcResult((NormalizedNode<?, ?>) null);
            return Futures.immediateCheckedFuture(result);
        }
    }).register();
    final Optional<MountPoint> mountInstance = bindingMountPointService.getMountPoint(BA_MOUNT_ID);
    assertTrue(mountInstance.isPresent());
    final Optional<RpcConsumerRegistry> rpcRegistry = mountInstance.get().getService(RpcConsumerRegistry.class);
    assertTrue(rpcRegistry.isPresent());
    final OpendaylightTestRpcServiceService rpcService = rpcRegistry.get().getRpcService(OpendaylightTestRpcServiceService.class);
    assertNotNull(rpcService);
    try {
        final Future<RpcResult<Void>> result = rpcService.rockTheHouse(new RockTheHouseInputBuilder().build());
        assertTrue(result.get().isSuccessful());
    } catch (final IllegalStateException ex) {
        fail("OpendaylightTestRpcServiceService class doesn't contain rockTheHouse method!");
    }
}
Also used : DefaultDOMRpcResult(org.opendaylight.controller.md.sal.dom.spi.DefaultDOMRpcResult) DOMRpcService(org.opendaylight.controller.md.sal.dom.api.DOMRpcService) DOMRpcResult(org.opendaylight.controller.md.sal.dom.api.DOMRpcResult) DefaultDOMRpcResult(org.opendaylight.controller.md.sal.dom.spi.DefaultDOMRpcResult) RockTheHouseInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.bi.ba.rpcservice.rev140701.RockTheHouseInputBuilder) DOMRpcResult(org.opendaylight.controller.md.sal.dom.api.DOMRpcResult) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) DefaultDOMRpcResult(org.opendaylight.controller.md.sal.dom.spi.DefaultDOMRpcResult) DOMRpcException(org.opendaylight.controller.md.sal.dom.api.DOMRpcException) MountPoint(org.opendaylight.controller.md.sal.binding.api.MountPoint) DOMRpcAvailabilityListener(org.opendaylight.controller.md.sal.dom.api.DOMRpcAvailabilityListener) RpcConsumerRegistry(org.opendaylight.controller.sal.binding.api.RpcConsumerRegistry) OpendaylightTestRpcServiceService(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.bi.ba.rpcservice.rev140701.OpendaylightTestRpcServiceService) SchemaPath(org.opendaylight.yangtools.yang.model.api.SchemaPath) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) Test(org.junit.Test)

Example 3 with DOMRpcException

use of org.opendaylight.controller.md.sal.dom.api.DOMRpcException 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 4 with DOMRpcException

use of org.opendaylight.controller.md.sal.dom.api.DOMRpcException 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 5 with DOMRpcException

use of org.opendaylight.controller.md.sal.dom.api.DOMRpcException 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)

Aggregations

DOMRpcException (org.opendaylight.controller.md.sal.dom.api.DOMRpcException)6 Test (org.junit.Test)5 DOMRpcResult (org.opendaylight.controller.md.sal.dom.api.DOMRpcResult)5 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)5 DefaultDOMRpcResult (org.opendaylight.controller.md.sal.dom.spi.DefaultDOMRpcResult)4 ArgumentCaptor (org.mockito.ArgumentCaptor)3 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)3 DOMRpcImplementationNotAvailableException (org.opendaylight.controller.md.sal.dom.api.DOMRpcImplementationNotAvailableException)2 Failure (akka.actor.Status.Failure)1 TestKit (akka.testkit.javadsl.TestKit)1 MountPoint (org.opendaylight.controller.md.sal.binding.api.MountPoint)1 DOMRpcAvailabilityListener (org.opendaylight.controller.md.sal.dom.api.DOMRpcAvailabilityListener)1 DOMRpcImplementation (org.opendaylight.controller.md.sal.dom.api.DOMRpcImplementation)1 DOMRpcService (org.opendaylight.controller.md.sal.dom.api.DOMRpcService)1 ExecuteRpc (org.opendaylight.controller.remote.rpc.messages.ExecuteRpc)1 RpcConsumerRegistry (org.opendaylight.controller.sal.binding.api.RpcConsumerRegistry)1 OpendaylightTestRpcServiceService (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.bi.ba.rpcservice.rev140701.OpendaylightTestRpcServiceService)1 RockTheHouseInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.bi.ba.rpcservice.rev140701.RockTheHouseInputBuilder)1 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)1 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)1