use of org.opendaylight.controller.remote.rpc.messages.RpcResponse 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.remote.rpc.messages.RpcResponse 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());
}
Aggregations