Search in sources :

Example 41 with DOMRpcResult

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

the class NetconfRemoteSchemaYangSourceProviderTest method setUp.

@Before
public void setUp() throws Exception {
    final DOMRpcResult value = new DefaultDOMRpcResult(getNode(), Set.of());
    final FluentFuture<DOMRpcResult> response = FluentFutures.immediateFluentFuture(value);
    doReturn(response).when(service).invokeRpc(any(QName.class), any(ContainerNode.class));
    provider = new NetconfRemoteSchemaYangSourceProvider(new RemoteDeviceId("device1", InetSocketAddress.createUnresolved("localhost", 17830)), service);
}
Also used : RemoteDeviceId(org.opendaylight.netconf.sal.connect.util.RemoteDeviceId) 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) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) Before(org.junit.Before)

Example 42 with DOMRpcResult

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

the class MountPointEndToEndTest method testRpc.

private void testRpc(final DOMRpcService domRpcService, final QName qname, final NormalizedNode input, final DOMRpcResult result) throws InterruptedException, ExecutionException, TimeoutException {
    final FluentFuture<DOMRpcResult> future = result == null ? FluentFutures.immediateNullFluentFuture() : FluentFutures.immediateFluentFuture(result);
    final DOMRpcResult actual = invokeRpc(domRpcService, qname, input, future);
    if (result == null) {
        assertNull(actual);
        return;
    }
    assertNotNull(actual);
    assertEquals(result.getResult(), actual.getResult());
    assertEquals(result.getErrors().size(), actual.getErrors().size());
    Iterator<? extends RpcError> iter1 = result.getErrors().iterator();
    Iterator<? extends RpcError> iter2 = actual.getErrors().iterator();
    while (iter1.hasNext() && iter2.hasNext()) {
        RpcError err1 = iter1.next();
        RpcError err2 = iter2.next();
        assertEquals(err1.getErrorType(), err2.getErrorType());
        assertEquals(err1.getTag(), err2.getTag());
        assertEquals(err1.getMessage(), err2.getMessage());
        assertEquals(err1.getSeverity(), err2.getSeverity());
        assertEquals(err1.getApplicationTag(), err2.getApplicationTag());
        assertEquals(err1.getInfo(), err2.getInfo());
    }
}
Also used : DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) DOMRpcResult(org.opendaylight.mdsal.dom.api.DOMRpcResult) RpcError(org.opendaylight.yangtools.yang.common.RpcError)

Example 43 with DOMRpcResult

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

the class NetconfNodeActorTest method testSlaveInvokeRpc.

@Test
public void testSlaveInvokeRpc() throws Exception {
    final List<SourceIdentifier> sourceIdentifiers = Lists.newArrayList(RevisionSourceIdentifier.create("testID"));
    initializeMaster(sourceIdentifiers);
    registerSlaveMountPoint();
    ArgumentCaptor<DOMRpcService> domRPCServiceCaptor = ArgumentCaptor.forClass(DOMRpcService.class);
    verify(mockMountPointBuilder).addService(eq(DOMRpcService.class), domRPCServiceCaptor.capture());
    final DOMRpcService slaveDomRPCService = domRPCServiceCaptor.getValue();
    assertTrue(slaveDomRPCService instanceof ProxyDOMRpcService);
    final QName testQName = QName.create("", "TestQname");
    final NormalizedNode outputNode = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(testQName)).withChild(ImmutableNodes.leafNode(testQName, "foo")).build();
    final RpcError rpcError = RpcResultBuilder.newError(RpcError.ErrorType.RPC, null, "Rpc invocation failed.");
    // RPC with no response output.
    doReturn(FluentFutures.immediateNullFluentFuture()).when(mockDOMRpcService).invokeRpc(any(), any());
    DOMRpcResult result = slaveDomRPCService.invokeRpc(testQName, outputNode).get(2, TimeUnit.SECONDS);
    assertEquals(null, result);
    // RPC with response output.
    doReturn(FluentFutures.immediateFluentFuture(new DefaultDOMRpcResult(outputNode))).when(mockDOMRpcService).invokeRpc(any(), any());
    result = slaveDomRPCService.invokeRpc(testQName, outputNode).get(2, TimeUnit.SECONDS);
    assertEquals(outputNode, result.getResult());
    assertTrue(result.getErrors().isEmpty());
    // RPC with response error.
    doReturn(FluentFutures.immediateFluentFuture(new DefaultDOMRpcResult(rpcError))).when(mockDOMRpcService).invokeRpc(any(), any());
    result = slaveDomRPCService.invokeRpc(testQName, outputNode).get(2, TimeUnit.SECONDS);
    assertNull(result.getResult());
    assertEquals(rpcError, result.getErrors().iterator().next());
    // RPC with response output and error.
    doReturn(FluentFutures.immediateFluentFuture(new DefaultDOMRpcResult(outputNode, rpcError))).when(mockDOMRpcService).invokeRpc(any(), any());
    final DOMRpcResult resultOutputError = slaveDomRPCService.invokeRpc(testQName, outputNode).get(2, TimeUnit.SECONDS);
    assertEquals(outputNode, resultOutputError.getResult());
    assertEquals(rpcError, resultOutputError.getErrors().iterator().next());
    // RPC failure.
    doReturn(FluentFutures.immediateFailedFluentFuture(new ClusteringRpcException("mock"))).when(mockDOMRpcService).invokeRpc(any(), any());
    final ListenableFuture<? extends DOMRpcResult> future = slaveDomRPCService.invokeRpc(testQName, outputNode);
    final ExecutionException e = assertThrows(ExecutionException.class, () -> future.get(2, TimeUnit.SECONDS));
    final Throwable cause = e.getCause();
    assertThat(cause, instanceOf(DOMRpcException.class));
    assertEquals("mock", cause.getMessage());
}
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) SourceIdentifier(org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier) RevisionSourceIdentifier(org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier) RpcError(org.opendaylight.yangtools.yang.common.RpcError) DOMRpcException(org.opendaylight.mdsal.dom.api.DOMRpcException) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) ClusteringRpcException(org.opendaylight.netconf.topology.singleton.impl.utils.ClusteringRpcException) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 44 with DOMRpcResult

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

the class ActorProxyNetconfServiceFacade method commit.

@Override
public ListenableFuture<? extends DOMRpcResult> commit() {
    LOG.debug("{}: Commit via actor {}", id, masterActor);
    final Future<Object> future = Patterns.ask(masterActor, new CommitRequest(), askTimeout);
    final SettableFuture<DOMRpcResult> settableFuture = SettableFuture.create();
    future.onComplete(new OnComplete<>() {

        @Override
        public void onComplete(final Throwable failure, final Object response) {
            if (failure != null) {
                LOG.debug("{}: Commit failed", id, failure);
                settableFuture.setException(newNetconfServiceFailedException(processFailure(failure)));
            } else if (response instanceof InvokeRpcMessageReply) {
                LOG.debug("{}: Commit succeeded", id);
                settableFuture.set(mapInvokeRpcMessageReplyToDOMRpcResult((InvokeRpcMessageReply) response));
            } else {
                settableFuture.setException(new ClusteringRpcException("Commit operation returned unexpected type"));
                LOG.error("{}: Commit via actor {} returned unexpected type", id, masterActor);
            }
        }

        private NetconfServiceFailedException newNetconfServiceFailedException(final Throwable failure) {
            return new NetconfServiceFailedException(String.format("%s: Commit of operation failed", getDeviceId()), failure);
        }
    }, executionContext);
    return settableFuture;
}
Also used : CommitRequest(org.opendaylight.netconf.topology.singleton.messages.netconf.CommitRequest) DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) DOMRpcResult(org.opendaylight.mdsal.dom.api.DOMRpcResult) ClusteringRpcException(org.opendaylight.netconf.topology.singleton.impl.utils.ClusteringRpcException) InvokeRpcMessageReply(org.opendaylight.netconf.topology.singleton.messages.rpc.InvokeRpcMessageReply)

Example 45 with DOMRpcResult

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

the class ProxyDOMRpcService method invokeRpc.

@Override
public FluentFuture<DOMRpcResult> invokeRpc(final QName type, final NormalizedNode input) {
    LOG.trace("{}: Rpc operation invoked with schema type: {} and node: {}.", id, type, input);
    final NormalizedNodeMessage normalizedNodeMessage = input != null ? new NormalizedNodeMessage(YangInstanceIdentifier.empty(), input) : null;
    final Future<Object> scalaFuture = Patterns.ask(masterActorRef, new InvokeRpcMessage(new SchemaPathMessage(type), normalizedNodeMessage), actorResponseWaitTime);
    final SettableFuture<DOMRpcResult> settableFuture = SettableFuture.create();
    scalaFuture.onComplete(new OnComplete<>() {

        @Override
        public void onComplete(final Throwable failure, final Object response) {
            if (failure != null) {
                if (failure instanceof ClusteringRpcException) {
                    settableFuture.setException(failure);
                } else {
                    settableFuture.setException(new ClusteringRpcException(id + ": Exception during remote rpc invocation.", failure));
                }
                return;
            }
            if (response instanceof EmptyResultResponse) {
                settableFuture.set(null);
                return;
            }
            final Collection<? extends RpcError> errors = ((InvokeRpcMessageReply) response).getRpcErrors();
            final NormalizedNodeMessage normalizedNodeMessageResult = ((InvokeRpcMessageReply) response).getNormalizedNodeMessage();
            final DOMRpcResult result;
            if (normalizedNodeMessageResult == null) {
                result = new DefaultDOMRpcResult(ImmutableList.copyOf(errors));
            } else {
                result = new DefaultDOMRpcResult(normalizedNodeMessageResult.getNode(), errors);
            }
            settableFuture.set(result);
        }
    }, actorSystem.dispatcher());
    return FluentFuture.from(settableFuture);
}
Also used : DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) NormalizedNodeMessage(org.opendaylight.netconf.topology.singleton.messages.NormalizedNodeMessage) DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) DOMRpcResult(org.opendaylight.mdsal.dom.api.DOMRpcResult) SchemaPathMessage(org.opendaylight.netconf.topology.singleton.messages.SchemaPathMessage) RpcError(org.opendaylight.yangtools.yang.common.RpcError) EmptyResultResponse(org.opendaylight.netconf.topology.singleton.messages.transactions.EmptyResultResponse) InvokeRpcMessage(org.opendaylight.netconf.topology.singleton.messages.rpc.InvokeRpcMessage) ClusteringRpcException(org.opendaylight.netconf.topology.singleton.impl.utils.ClusteringRpcException) Collection(java.util.Collection)

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