Search in sources :

Example 11 with DOMRpcResult

use of org.opendaylight.mdsal.dom.api.DOMRpcResult in project netconf by opendaylight.

the class InvokeRpcMethodTest method testInvokeRpcMethodWithInput.

@Test
@Ignore
public void testInvokeRpcMethodWithInput() {
    final DOMRpcResult expResult = mock(DOMRpcResult.class);
    final QName path = QName.create("(http://netconfcentral.org/ns/toaster?revision=2009-11-20)make-toast");
    final Module rpcModule = schemaContext.findModules("toaster").iterator().next();
    assertNotNull(rpcModule);
    final QName rpcQName = QName.create(rpcModule.getQNameModule(), "make-toast");
    RpcDefinition rpcDef = null;
    ContainerLike rpcInputSchemaNode = null;
    for (final RpcDefinition rpc : rpcModule.getRpcs()) {
        if (rpcQName.isEqualWithoutRevision(rpc.getQName())) {
            rpcInputSchemaNode = rpc.getInput();
            rpcDef = rpc;
            break;
        }
    }
    assertNotNull(rpcDef);
    assertNotNull(rpcInputSchemaNode);
    final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> containerBuilder = SchemaAwareBuilders.containerBuilder(rpcInputSchemaNode);
    final NormalizedNodeContext payload = new NormalizedNodeContext(new InstanceIdentifierContext<>(null, rpcInputSchemaNode, null, schemaContext), containerBuilder.build());
    doReturn(immediateFluentFuture(expResult)).when(brokerFacade).invokeRpc(eq(path), any(NormalizedNode.class));
    final NormalizedNodeContext output = this.restconfImpl.invokeRpc("toaster:make-toast", payload, uriInfo);
    assertNotNull(output);
    assertEquals(null, output.getData());
// additional validation in the fact that the restconfImpl does not
// throw an exception.
}
Also used : ContainerLike(org.opendaylight.yangtools.yang.model.api.ContainerLike) DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) DOMRpcResult(org.opendaylight.mdsal.dom.api.DOMRpcResult) RpcDefinition(org.opendaylight.yangtools.yang.model.api.RpcDefinition) QName(org.opendaylight.yangtools.yang.common.QName) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) Module(org.opendaylight.yangtools.yang.model.api.Module) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) NormalizedNodeContext(org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 12 with DOMRpcResult

use of org.opendaylight.mdsal.dom.api.DOMRpcResult 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 13 with DOMRpcResult

use of org.opendaylight.mdsal.dom.api.DOMRpcResult in project netconf by opendaylight.

the class ProxyNetconfDataTreeServiceTest method lock.

private void lock() {
    final ListenableFuture<DOMRpcResult> lock = proxy.lock();
    masterActor.expectMsgClass(NetconfDataTreeServiceRequest.class);
    masterActor.reply(new Status.Success(masterActor.ref()));
    masterActor.expectMsgClass(LockRequest.class);
    masterActor.reply(new InvokeRpcMessageReply(null, Collections.emptyList()));
    Futures.whenAllComplete(lock).run(() -> {
        assertTrue(lock.isDone());
        assertNotNull(Futures.getUnchecked(lock));
    }, MoreExecutors.directExecutor());
}
Also used : Status(akka.actor.Status) DOMRpcResult(org.opendaylight.mdsal.dom.api.DOMRpcResult) InvokeRpcMessageReply(org.opendaylight.netconf.topology.singleton.messages.rpc.InvokeRpcMessageReply)

Example 14 with DOMRpcResult

use of org.opendaylight.mdsal.dom.api.DOMRpcResult in project netconf by opendaylight.

the class ActorProxyNetconfServiceFacade method discardChanges.

@Override
public ListenableFuture<DOMRpcResult> discardChanges() {
    LOG.debug("{}: Discard changes via actor {}", id, masterActor);
    final SettableFuture<DOMRpcResult> discardChangesResult = SettableFuture.create();
    final Future<Object> future = Patterns.ask(masterActor, new DiscardChangesRequest(), askTimeout);
    future.onComplete(new OnComplete<>() {

        @Override
        public void onComplete(final Throwable failure, final Object response) {
            if (failure != null) {
                discardChangesResult.setException(failure);
            } else if (response instanceof InvokeRpcMessageReply) {
                discardChangesResult.set(mapInvokeRpcMessageReplyToDOMRpcResult((InvokeRpcMessageReply) response));
            } else {
                discardChangesResult.setException(new ClusteringRpcException("Discard changes operation returned unexpected type"));
                LOG.error("{}: Discard changes  via actor {} returned unexpected type", id, masterActor);
            }
        }
    }, executionContext);
    return discardChangesResult;
}
Also used : DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) DOMRpcResult(org.opendaylight.mdsal.dom.api.DOMRpcResult) DiscardChangesRequest(org.opendaylight.netconf.topology.singleton.messages.netconf.DiscardChangesRequest) ClusteringRpcException(org.opendaylight.netconf.topology.singleton.impl.utils.ClusteringRpcException) InvokeRpcMessageReply(org.opendaylight.netconf.topology.singleton.messages.rpc.InvokeRpcMessageReply)

Example 15 with DOMRpcResult

use of org.opendaylight.mdsal.dom.api.DOMRpcResult in project netconf by opendaylight.

the class ActorProxyNetconfServiceFacade method createResult.

private ListenableFuture<? extends DOMRpcResult> createResult() {
    final SettableFuture<DOMRpcResult> settableFuture = SettableFuture.create();
    settableFuture.set(new DefaultDOMRpcResult());
    return settableFuture;
}
Also used : DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) DOMRpcResult(org.opendaylight.mdsal.dom.api.DOMRpcResult)

Aggregations

DOMRpcResult (org.opendaylight.mdsal.dom.api.DOMRpcResult)61 DefaultDOMRpcResult (org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult)39 Test (org.junit.Test)38 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)21 QName (org.opendaylight.yangtools.yang.common.QName)18 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)16 NetconfMessage (org.opendaylight.netconf.api.NetconfMessage)10 RpcError (org.opendaylight.yangtools.yang.common.RpcError)8 ExecutionException (java.util.concurrent.ExecutionException)7 AbstractBaseSchemasTest (org.opendaylight.netconf.sal.connect.netconf.AbstractBaseSchemasTest)7 RpcDefinition (org.opendaylight.yangtools.yang.model.api.RpcDefinition)7 ClusteringRpcException (org.opendaylight.netconf.topology.singleton.impl.utils.ClusteringRpcException)6 DOMRpcService (org.opendaylight.mdsal.dom.api.DOMRpcService)5 InvokeRpcMessageReply (org.opendaylight.netconf.topology.singleton.messages.rpc.InvokeRpcMessageReply)5 DOMRpcImplementationNotAvailableException (org.opendaylight.mdsal.dom.api.DOMRpcImplementationNotAvailableException)4 NormalizedNodeContext (org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext)4 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)4 WebApplicationException (javax.ws.rs.WebApplicationException)3 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)3 ArgumentCaptor (org.mockito.ArgumentCaptor)3