Search in sources :

Example 1 with DOMRpcResult

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

the class BindingDOMRpcImplementationAdapter method invokeRpc.

@Nonnull
@Override
public CheckedFuture<DOMRpcResult, DOMRpcException> invokeRpc(@Nonnull final DOMRpcIdentifier rpc, final NormalizedNode<?, ?> input) {
    final SchemaPath schemaPath = rpc.getType();
    final DataObject bindingInput = input != null ? deserialize(rpc.getType(), input) : null;
    final ListenableFuture<RpcResult<?>> bindingResult = invoke(schemaPath, bindingInput);
    return transformResult(bindingResult);
}
Also used : DataObject(org.opendaylight.yangtools.yang.binding.DataObject) SchemaPath(org.opendaylight.yangtools.yang.model.api.SchemaPath) DOMRpcResult(org.opendaylight.controller.md.sal.dom.api.DOMRpcResult) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) Nonnull(javax.annotation.Nonnull)

Example 2 with DOMRpcResult

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

the class RpcBrokerTest method testExecuteRpc.

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

        {
            final ContainerNode invokeRpcResult = makeRPCOutput("bar");
            final DOMRpcResult rpcResult = new DefaultDOMRpcResult(invokeRpcResult);
            when(domRpcService1.invokeRpc(eq(TEST_RPC_TYPE), Mockito.<NormalizedNode<?, ?>>any())).thenReturn(Futures.<DOMRpcResult, DOMRpcException>immediateCheckedFuture(rpcResult));
            final ExecuteRpc executeMsg = ExecuteRpc.from(TEST_RPC_ID, null);
            rpcInvoker1.tell(executeMsg, getRef());
            final RpcResponse rpcResponse = expectMsgClass(duration("5 seconds"), RpcResponse.class);
            assertEquals(rpcResult.getResult(), rpcResponse.getResultNormalizedNode());
        }
    };
}
Also used : DefaultDOMRpcResult(org.opendaylight.controller.md.sal.dom.spi.DefaultDOMRpcResult) DOMRpcResult(org.opendaylight.controller.md.sal.dom.api.DOMRpcResult) DefaultDOMRpcResult(org.opendaylight.controller.md.sal.dom.spi.DefaultDOMRpcResult) ExecuteRpc(org.opendaylight.controller.remote.rpc.messages.ExecuteRpc) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) TestKit(akka.testkit.javadsl.TestKit) RpcResponse(org.opendaylight.controller.remote.rpc.messages.RpcResponse) Test(org.junit.Test)

Example 3 with DOMRpcResult

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

the class RpcInvoker method executeRpc.

@SuppressWarnings("checkstyle:IllegalCatch")
private void executeRpc(final ExecuteRpc msg) {
    LOG.debug("Executing rpc {}", msg.getRpc());
    final SchemaPath schemaPath = SchemaPath.create(true, msg.getRpc());
    final ActorRef sender = getSender();
    final ActorRef self = self();
    final ListenableFuture<DOMRpcResult> future;
    try {
        future = rpcService.invokeRpc(schemaPath, msg.getInputNormalizedNode());
    } catch (final RuntimeException e) {
        LOG.debug("Failed to invoke RPC {}", msg.getRpc(), e);
        sender.tell(new akka.actor.Status.Failure(e), sender);
        return;
    }
    Futures.addCallback(future, new FutureCallback<DOMRpcResult>() {

        @Override
        public void onSuccess(final DOMRpcResult result) {
            if (result == null) {
                // This shouldn't happen but the FutureCallback annotates the result param with Nullable so
                // handle null here to avoid FindBugs warning.
                LOG.debug("Got null DOMRpcResult - sending null response for execute rpc : {}", msg.getRpc());
                sender.tell(new RpcResponse(null), self);
                return;
            }
            if (!result.getErrors().isEmpty()) {
                final String message = String.format("Execution of RPC %s failed", msg.getRpc());
                sender.tell(new akka.actor.Status.Failure(new RpcErrorsException(message, result.getErrors())), self);
            } else {
                LOG.debug("Sending response for execute rpc : {}", msg.getRpc());
                sender.tell(new RpcResponse(result.getResult()), self);
            }
        }

        @Override
        public void onFailure(final Throwable failure) {
            LOG.debug("Failed to execute RPC {}", msg.getRpc(), failure);
            LOG.error("Failed to execute RPC {} due to {}. More details are available on DEBUG level.", msg.getRpc(), Throwables.getRootCause(failure));
            sender.tell(new akka.actor.Status.Failure(failure), self);
        }
    }, MoreExecutors.directExecutor());
}
Also used : DOMRpcResult(org.opendaylight.controller.md.sal.dom.api.DOMRpcResult) ActorRef(akka.actor.ActorRef) RpcResponse(org.opendaylight.controller.remote.rpc.messages.RpcResponse) SchemaPath(org.opendaylight.yangtools.yang.model.api.SchemaPath)

Example 4 with DOMRpcResult

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

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

the class CrossBrokerRpcTest method bindingRoutedRpcProvider_DomInvokerTest.

@Test
public void bindingRoutedRpcProvider_DomInvokerTest() throws Exception {
    // 
    knockService.registerPath(TestContext.class, // 
    BA_NODE_A_ID).registerPath(TestContext.class, // 
    BA_NODE_B_ID).setKnockKnockResult(knockResult(true, "open"));
    OpendaylightOfMigrationTestModelService baKnockInvoker = providerRegistry.getRpcService(OpendaylightOfMigrationTestModelService.class);
    assertNotSame(knockService, baKnockInvoker);
    KnockKnockInput knockKnockA = // 
    knockKnock(BA_NODE_A_ID).setQuestion("who's there?").build();
    ContainerNode knockKnockDom = toDomRpc(KNOCK_KNOCK_QNAME, knockKnockA);
    assertNotNull(knockKnockDom);
    DOMRpcResult domResult = biRpcInvoker.invokeRpc(KNOCK_KNOCK_PATH, knockKnockDom).get();
    assertNotNull(domResult);
    assertNotNull("DOM result is successful.", domResult.getResult());
    assertTrue("Bidning Add Flow RPC was captured.", knockService.getReceivedKnocks().containsKey(BA_NODE_A_ID));
    assertEquals(knockKnockA, knockService.getReceivedKnocks().get(BA_NODE_A_ID).iterator().next());
}
Also used : DOMRpcResult(org.opendaylight.controller.md.sal.dom.api.DOMRpcResult) DefaultDOMRpcResult(org.opendaylight.controller.md.sal.dom.spi.DefaultDOMRpcResult) BindingTestContext(org.opendaylight.controller.sal.binding.test.util.BindingTestContext) TestContext(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.rpc.routing.rev140701.TestContext) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) OpendaylightOfMigrationTestModelService(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.of.migration.test.model.rev150210.OpendaylightOfMigrationTestModelService) KnockKnockInput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.of.migration.test.model.rev150210.KnockKnockInput) 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