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