Search in sources :

Example 31 with DOMRpcResult

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

the class RemoteOpsImplementationTest method testInvokeRpcWithLookupException.

/**
 * This test method invokes remote rpc and lookup failed
 * with runtime exception.
 */
@Test(expected = DOMRpcException.class)
@SuppressWarnings({ "checkstyle:AvoidHidingCauseException", "checkstyle:IllegalThrows" })
public void testInvokeRpcWithLookupException() throws Throwable {
    final NormalizedNode invokeRpcInput = makeRPCInput("foo");
    doThrow(new RuntimeException("test")).when(domRpcService2).invokeRpc(any(QName.class), any(NormalizedNode.class));
    final ListenableFuture<DOMRpcResult> frontEndFuture = remoteRpcImpl1.invokeRpc(TEST_RPC_ID, invokeRpcInput);
    assertTrue(frontEndFuture instanceof RemoteDOMRpcFuture);
    try {
        frontEndFuture.get(5, TimeUnit.SECONDS);
    } catch (ExecutionException e) {
        throw e.getCause();
    }
}
Also used : DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) DOMRpcResult(org.opendaylight.mdsal.dom.api.DOMRpcResult) QName(org.opendaylight.yangtools.yang.common.QName) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 32 with DOMRpcResult

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

the class OpsInvoker method execute.

@SuppressWarnings("checkstyle:IllegalCatch")
private void execute(final ExecuteRpc msg) {
    LOG.debug("Executing RPC {}", msg.getType());
    final ActorRef sender = getSender();
    final ListenableFuture<? extends DOMRpcResult> future;
    try {
        future = rpcService.invokeRpc(msg.getType(), msg.getInput());
    } catch (final RuntimeException e) {
        LOG.debug("Failed to invoke RPC {}", msg.getType(), e);
        sender.tell(new Failure(e), self());
        return;
    }
    Futures.addCallback(future, new AbstractCallback<QName, DOMRpcResult>(getSender(), msg.getType()) {

        @Override
        Object nullResponse(final QName type) {
            LOG.warn("Execution of {} resulted in null result", type);
            return new RpcResponse(null);
        }

        @Override
        Object response(final QName type, final DOMRpcResult result) {
            final Collection<? extends RpcError> errors = result.getErrors();
            return errors.isEmpty() ? new RpcResponse(result.getResult()) : // discarding any output
            new Failure(new RpcErrorsException(String.format("Execution of rpc %s failed", type), errors));
        }
    }, MoreExecutors.directExecutor());
}
Also used : DOMRpcResult(org.opendaylight.mdsal.dom.api.DOMRpcResult) ActorRef(akka.actor.ActorRef) QName(org.opendaylight.yangtools.yang.common.QName) RpcError(org.opendaylight.yangtools.yang.common.RpcError) RpcResponse(org.opendaylight.controller.remote.rpc.messages.RpcResponse) Collection(java.util.Collection) Failure(akka.actor.Status.Failure)

Example 33 with DOMRpcResult

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

the class NetconfDeviceRpcTest method testInvokeRpc.

@Test
public void testInvokeRpc() throws Exception {
    ContainerNode input = createNode("urn:ietf:params:xml:ns:netconf:base:1.0", "2011-06-01", "filter");
    final DOMRpcResult result = rpc.invokeRpc(type, input).get();
    assertEquals(expectedReply.getResult().getIdentifier(), result.getResult().getIdentifier());
    assertEquals(resolveNode(expectedReply), resolveNode(result));
}
Also used : DOMRpcResult(org.opendaylight.mdsal.dom.api.DOMRpcResult) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) AbstractBaseSchemasTest(org.opendaylight.netconf.sal.connect.netconf.AbstractBaseSchemasTest) Test(org.junit.Test)

Example 34 with DOMRpcResult

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

the class KeepaliveSalFacadeResponseWaitingTest method testKeepaliveSalResponseWaiting.

/**
 * Not sending keepalive rpc test while the repsonse is processing.
 */
@Test
public void testKeepaliveSalResponseWaiting() {
    // This settable future object will be never set to any value. The test wants to simulate waiting for the result
    // of the future object.
    final SettableFuture<DOMRpcResult> settableFuture = SettableFuture.create();
    doReturn(settableFuture).when(deviceRpc).invokeRpc(null, null);
    // This settable future will be used to check the invokation of keepalive RPC. Should be never invoked.
    final SettableFuture<DOMRpcResult> keepaliveSettableFuture = SettableFuture.create();
    final DOMRpcResult keepaliveResult = new DefaultDOMRpcResult(Builders.containerBuilder().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(NetconfMessageTransformUtil.NETCONF_RUNNING_QNAME)).build());
    keepaliveSettableFuture.set(keepaliveResult);
    keepaliveSalFacade.onDeviceConnected(null, null, deviceRpc);
    // Invoke general RPC on simulated local facade without args (or with null args). Will be returned
    // settableFuture variable without any set value. WaitingShaduler in keepalive sal facade should wait for any
    // result from the RPC and reset keepalive scheduler.
    underlyingSalFacade.invokeNullRpc();
    // Invoking of general RPC.
    verify(deviceRpc, after(2000).times(1)).invokeRpc(null, null);
    // verify the keepalive RPC invoke. Should be never happen.
    verify(deviceRpc, after(2000).never()).invokeRpc(NETCONF_GET_CONFIG_QNAME, KEEPALIVE_PAYLOAD);
}
Also used : DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) DOMRpcResult(org.opendaylight.mdsal.dom.api.DOMRpcResult) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Test(org.junit.Test)

Example 35 with DOMRpcResult

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

the class KeepaliveSalFacadeTest method testKeepaliveSuccess.

@Test
public void testKeepaliveSuccess() throws Exception {
    final DOMRpcResult result = new DefaultDOMRpcResult(Builders.containerBuilder().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(NetconfMessageTransformUtil.NETCONF_RUNNING_QNAME)).build());
    doReturn(FluentFutures.immediateFluentFuture(result)).when(deviceRpc).invokeRpc(any(QName.class), any(ContainerNode.class));
    keepaliveSalFacade.onDeviceConnected(null, null, deviceRpc);
    verify(underlyingSalFacade).onDeviceConnected(isNull(), isNull(), any(DOMRpcService.class), isNull());
    verify(deviceRpc, timeout(15000).times(5)).invokeRpc(any(QName.class), any(ContainerNode.class));
}
Also used : DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) DOMRpcService(org.opendaylight.mdsal.dom.api.DOMRpcService) DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) DOMRpcResult(org.opendaylight.mdsal.dom.api.DOMRpcResult) QName(org.opendaylight.yangtools.yang.common.QName) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Test(org.junit.Test)

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