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);
}
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());
}
};
}
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());
}
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!");
}
}
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());
}
Aggregations