Search in sources :

Example 6 with DefaultDOMRpcResult

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;
}
Also used : DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) DOMRpcResult(org.opendaylight.mdsal.dom.api.DOMRpcResult) DOMRpcImplementationNotAvailableException(org.opendaylight.mdsal.dom.api.DOMRpcImplementationNotAvailableException) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) DOMRpcResult(org.opendaylight.mdsal.dom.api.DOMRpcResult) DOMRpcImplementationNotAvailableException(org.opendaylight.mdsal.dom.api.DOMRpcImplementationNotAvailableException) DefaultDOMRpcException(org.opendaylight.mdsal.dom.api.DefaultDOMRpcException) NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) DefaultDOMRpcException(org.opendaylight.mdsal.dom.api.DefaultDOMRpcException)

Example 7 with DefaultDOMRpcResult

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"));
}
Also used : DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) RestconfDocumentedException(org.opendaylight.restconf.common.errors.RestconfDocumentedException) ErrorTag(org.opendaylight.yangtools.yang.common.ErrorTag) DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) DOMRpcResult(org.opendaylight.mdsal.dom.api.DOMRpcResult) QName(org.opendaylight.yangtools.yang.common.QName) RpcError(org.opendaylight.yangtools.yang.common.RpcError) Test(org.junit.Test)

Example 8 with DefaultDOMRpcResult

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());
}
Also used : DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) DOMRpcResult(org.opendaylight.mdsal.dom.api.DOMRpcResult) QName(org.opendaylight.yangtools.yang.common.QName) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 9 with DefaultDOMRpcResult

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();
}
Also used : DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) LockRequest(org.opendaylight.netconf.topology.singleton.messages.netconf.LockRequest) Test(org.junit.Test)

Example 10 with DefaultDOMRpcResult

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());
}
Also used : MergeEditConfigRequest(org.opendaylight.netconf.topology.singleton.messages.netconf.MergeEditConfigRequest) DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) NormalizedNodeMessage(org.opendaylight.netconf.topology.singleton.messages.NormalizedNodeMessage) Test(org.junit.Test)

Aggregations

DefaultDOMRpcResult (org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult)72 Test (org.junit.Test)51 QName (org.opendaylight.yangtools.yang.common.QName)27 DOMRpcResult (org.opendaylight.mdsal.dom.api.DOMRpcResult)25 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)25 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)16 InstanceIdentifierContext (org.opendaylight.restconf.common.context.InstanceIdentifierContext)15 NetconfRestconfStrategy (org.opendaylight.restconf.nb.rfc8040.rests.transactions.NetconfRestconfStrategy)15 NormalizedNodePayload (org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload)12 Before (org.junit.Before)10 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)10 DataSchemaNode (org.opendaylight.yangtools.yang.model.api.DataSchemaNode)10 NetconfBaseOps (org.opendaylight.netconf.sal.connect.netconf.util.NetconfBaseOps)9 MdsalRestconfStrategy (org.opendaylight.restconf.nb.rfc8040.rests.transactions.MdsalRestconfStrategy)9 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)9 AbstractBaseSchemasTest (org.opendaylight.netconf.sal.connect.netconf.AbstractBaseSchemasTest)5 RemoteDeviceId (org.opendaylight.netconf.sal.connect.util.RemoteDeviceId)5 RpcError (org.opendaylight.yangtools.yang.common.RpcError)5 ArrayList (java.util.ArrayList)4 NormalizedNodeMessage (org.opendaylight.netconf.topology.singleton.messages.NormalizedNodeMessage)4