use of org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult 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.spi.DefaultDOMRpcResult 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"));
}
use of org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult in project netconf by opendaylight.
the class JSONRestconfServiceImplTest method testInvokeRpcWithNoInput.
@Test
public void testInvokeRpcWithNoInput() throws Exception {
final DOMRpcResult expResult = new DefaultDOMRpcResult((NormalizedNode) null);
doReturn(immediateFluentFuture(expResult)).when(brokerFacade).invokeRpc(any(QName.class), any());
final String uriPath = "toaster:cancel-toast";
final Optional<String> output = this.service.invokeRpc(uriPath, Optional.empty());
assertEquals("Output present", false, output.isPresent());
verify(brokerFacade).invokeRpc(eq(CANCEL_TOAST_QNAME), any());
}
use of org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult in project netconf by opendaylight.
the class NetconfDataTreeServiceActorTest method testLock.
@Test
public void testLock() {
final ListenableFuture<? extends DOMRpcResult> future = Futures.immediateFuture(new DefaultDOMRpcResult());
doReturn(future).when(netconfService).lock();
actorRef.tell(new LockRequest(), probe.ref());
verify(netconfService).lock();
}
use of org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult in project netconf by opendaylight.
the class NetconfDataTreeServiceActorTest method testMerge.
@Test
public void testMerge() {
doReturn(FluentFutures.immediateFluentFuture(new DefaultDOMRpcResult())).when(netconfService).merge(STORE, PATH, NODE, Optional.empty());
final NormalizedNodeMessage node = new NormalizedNodeMessage(PATH, NODE);
actorRef.tell(new MergeEditConfigRequest(STORE, node, null), probe.ref());
verify(netconfService).merge(STORE, PATH, NODE, Optional.empty());
}
Aggregations