use of org.opendaylight.mdsal.dom.api.DOMRpcResult in project mdsal by opendaylight.
the class Mdsal500Test method testBindingRegistrationWithDOMInvocation.
@Test
public void testBindingRegistrationWithDOMInvocation() throws Exception {
switchRpcImpl.registerTo(baRpcProviderService).setSwitchResult(switchResult(true));
final Mdsal500Service baSwitchService = baRpcConsumerService.getRpcService(Mdsal500Service.class);
assertNotSame(switchRpcImpl, baSwitchService);
SwitchInput baSwitchInput = switchBuilder(FOO).build();
ContainerNode biSwitchInput = toDOMSwitchInput(baSwitchInput);
DOMRpcResult domResult = biRpcService.invokeRpc(SWITCH_QNAME, biSwitchInput).get(5, TimeUnit.SECONDS);
assertNotNull(domResult);
assertNotNull(domResult.getResult());
assertTrue("Binding KnockKnock service was not invoked", switchRpcImpl.getReceivedSwitch().containsKey(FOO));
assertEquals(baSwitchInput, switchRpcImpl.getReceivedSwitch().get(FOO).iterator().next());
}
use of org.opendaylight.mdsal.dom.api.DOMRpcResult in project mdsal by opendaylight.
the class BindingDOMRpcIntegrationTest method testBindingRegistrationWithDOMInvocation.
@Test
public void testBindingRegistrationWithDOMInvocation() throws InterruptedException, ExecutionException, TimeoutException {
knockRpcImpl.registerTo(baRpcProviderService, BA_NODE_ID).setKnockKnockResult(knockResult(true, "open"));
final OpendaylightKnockKnockRpcService baKnockService = baRpcConsumerService.getRpcService(OpendaylightKnockKnockRpcService.class);
assertNotSame(knockRpcImpl, baKnockService);
KnockKnockInput baKnockKnockInput = knockKnock(BA_NODE_ID).setQuestion("who's there?").build();
ContainerNode biKnockKnockInput = toDOMKnockKnockInput(baKnockKnockInput);
DOMRpcResult domResult = biRpcService.invokeRpc(KNOCK_KNOCK_QNAME, biKnockKnockInput).get(5, TimeUnit.SECONDS);
assertNotNull(domResult);
assertNotNull(domResult.getResult());
assertTrue("Binding KnockKnock service was not invoked", knockRpcImpl.getReceivedKnocks().containsKey(BA_NODE_ID));
assertEquals(baKnockKnockInput, knockRpcImpl.getReceivedKnocks().get(BA_NODE_ID).iterator().next());
}
use of org.opendaylight.mdsal.dom.api.DOMRpcResult in project netconf by opendaylight.
the class LibraryModulesSchemas method create.
public static LibraryModulesSchemas create(final NetconfDeviceRpc deviceRpc, final RemoteDeviceId deviceId) {
final DOMRpcResult moduleListNodeResult;
try {
moduleListNodeResult = deviceRpc.invokeRpc(NETCONF_GET_QNAME, GET_MODULES_STATE_MODULE_LIST_RPC).get();
} catch (final InterruptedException e) {
Thread.currentThread().interrupt();
throw new RuntimeException(deviceId + ": Interrupted while waiting for response to " + MODULES_STATE_MODULE_LIST, e);
} catch (final ExecutionException e) {
LOG.warn("{}: Unable to detect available schemas, get to {} failed", deviceId, MODULES_STATE_MODULE_LIST, e);
return new LibraryModulesSchemas(ImmutableMap.of());
}
if (moduleListNodeResult.getErrors().isEmpty() == false) {
LOG.warn("{}: Unable to detect available schemas, get to {} failed, {}", deviceId, MODULES_STATE_MODULE_LIST, moduleListNodeResult.getErrors());
return new LibraryModulesSchemas(ImmutableMap.of());
}
final Optional<DataContainerChild> modulesStateNode = findModulesStateNode(moduleListNodeResult.getResult());
if (modulesStateNode.isPresent()) {
final DataContainerChild node = modulesStateNode.get();
checkState(node instanceof ContainerNode, "Expecting container containing schemas, but was %s", node);
return create((ContainerNode) node);
}
LOG.warn("{}: Unable to detect available schemas, get to {} was empty", deviceId, MODULES_STATE_NID);
return new LibraryModulesSchemas(ImmutableMap.of());
}
use of org.opendaylight.mdsal.dom.api.DOMRpcResult in project netconf by opendaylight.
the class NetconfDeviceRpc method invokeRpc.
@Override
@SuppressWarnings("checkstyle:IllegalCatch")
public ListenableFuture<DOMRpcResult> invokeRpc(final QName type, final NormalizedNode input) {
final ListenableFuture<RpcResult<NetconfMessage>> delegateFuture = communicator.sendRequest(transformer.toRpcRequest(type, input), type);
final SettableFuture<DOMRpcResult> ret = SettableFuture.create();
Futures.addCallback(delegateFuture, new FutureCallback<RpcResult<NetconfMessage>>() {
@Override
public void onSuccess(final RpcResult<NetconfMessage> result) {
try {
ret.set(result.isSuccessful() ? transformer.toRpcResult(result.getResult(), type) : new DefaultDOMRpcResult(result.getErrors()));
} catch (Exception cause) {
ret.setException(new DefaultDOMRpcException("Unable to parse rpc reply. type: " + type + " input: " + input, cause));
}
}
@Override
public void onFailure(final Throwable cause) {
ret.setException(new DOMRpcImplementationNotAvailableException(cause, "Unable to invoke rpc %s", type));
}
}, MoreExecutors.directExecutor());
return ret;
}
use of org.opendaylight.mdsal.dom.api.DOMRpcResult in project netconf by opendaylight.
the class InvokeRpcMethodTest method testInvokeRpcWithNoPayloadRpc_FailWithRpcError.
@Test
public void testInvokeRpcWithNoPayloadRpc_FailWithRpcError() {
final List<RpcError> rpcErrors = Arrays.asList(RpcResultBuilder.newError(RpcError.ErrorType.TRANSPORT, "bogusTag", "foo"), RpcResultBuilder.newWarning(RpcError.ErrorType.RPC, "in-use", "bar", "app-tag", null, null));
final DOMRpcResult result = new DefaultDOMRpcResult(rpcErrors);
final QName path = QName.create("(http://netconfcentral.org/ns/toaster?revision=2009-11-20)cancel-toast");
doReturn(immediateFluentFuture(result)).when(brokerFacade).invokeRpc(eq(path), any());
final RestconfDocumentedException ex = assertThrows(RestconfDocumentedException.class, () -> this.restconfImpl.invokeRpc("toaster:cancel-toast", null, uriInfo));
// We are performing pass-through here of error-tag, hence the tag remains as specified, but we want to make
// sure the HTTP status remains the same as
final ErrorTag bogus = new ErrorTag("bogusTag");
verifyRestconfDocumentedException(ex, 0, ErrorType.TRANSPORT, bogus, Optional.of("foo"), Optional.empty());
assertEquals(ErrorTags.statusOf(ErrorTag.OPERATION_FAILED), ErrorTags.statusOf(bogus));
verifyRestconfDocumentedException(ex, 1, ErrorType.RPC, ErrorTag.IN_USE, Optional.of("bar"), Optional.of("app-tag"));
}
Aggregations