Search in sources :

Example 21 with DOMRpcResult

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

the class NetconfMessageTransformerTest method testGetSchemaResponse.

@Test
public void testGetSchemaResponse() throws Exception {
    final NetconfMessageTransformer transformer = getTransformer(SCHEMA);
    final NetconfMessage response = new NetconfMessage(XmlUtil.readXmlToDocument("<rpc-reply message-id=\"101\"\n" + "xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" + "<data\n" + "xmlns=\"urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring\">\n" + "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">\n" + "Random YANG SCHEMA\n" + "</xs:schema>\n" + "</data>\n" + "</rpc-reply>"));
    final DOMRpcResult compositeNodeRpcResult = transformer.toRpcResult(response, GET_SCHEMA_QNAME);
    assertTrue(compositeNodeRpcResult.getErrors().isEmpty());
    assertNotNull(compositeNodeRpcResult.getResult());
    final DOMSource schemaContent = ((DOMSourceAnyxmlNode) ((ContainerNode) compositeNodeRpcResult.getResult()).body().iterator().next()).body();
    assertThat(schemaContent.getNode().getTextContent(), CoreMatchers.containsString("Random YANG SCHEMA"));
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) DOMRpcResult(org.opendaylight.mdsal.dom.api.DOMRpcResult) DOMSourceAnyxmlNode(org.opendaylight.yangtools.yang.data.api.schema.DOMSourceAnyxmlNode) NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) AbstractBaseSchemasTest(org.opendaylight.netconf.sal.connect.netconf.AbstractBaseSchemasTest) Test(org.junit.Test)

Example 22 with DOMRpcResult

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

the class NetconfMessageTransformerTest method testRpcEmptyBodyWithoutOutputDefinedSchemaResult.

@Test
public void testRpcEmptyBodyWithoutOutputDefinedSchemaResult() throws Exception {
    final String result = "<rpc-reply xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"><ok/></rpc-reply>";
    DOMRpcResult domRpcResult = actionNetconfMessageTransformer.toRpcResult(new NetconfMessage(XmlUtil.readXmlToDocument(result)), RPC_WITHOUT_OUTPUT_QNAME);
    assertNotNull(domRpcResult);
}
Also used : DOMRpcResult(org.opendaylight.mdsal.dom.api.DOMRpcResult) NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) AbstractBaseSchemasTest(org.opendaylight.netconf.sal.connect.netconf.AbstractBaseSchemasTest) Test(org.junit.Test)

Example 23 with DOMRpcResult

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

the class SchemalessNetconfDeviceRpc method handleRpc.

private ListenableFuture<DOMRpcResult> handleRpc(@NonNull final QName type, @NonNull final NormalizedNode input, final MessageTransformer<NetconfMessage> transformer) {
    final ListenableFuture<RpcResult<NetconfMessage>> delegateFuture = listener.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) {
            ret.set(result.isSuccessful() ? transformer.toRpcResult(result.getResult(), type) : new DefaultDOMRpcResult(result.getErrors()));
        }

        @Override
        public void onFailure(final Throwable cause) {
            ret.setException(new DOMRpcImplementationNotAvailableException(cause, "Unable to invoke rpc %s on device %s", type, deviceId));
        }
    }, 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) NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) 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)

Example 24 with DOMRpcResult

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

the class AbstractWriteTx method resultsToTxStatus.

protected ListenableFuture<RpcResult<Void>> resultsToTxStatus() {
    final SettableFuture<RpcResult<Void>> transformed = SettableFuture.create();
    Futures.addCallback(Futures.allAsList(resultsFutures), new FutureCallback<List<DOMRpcResult>>() {

        @Override
        public void onSuccess(final List<DOMRpcResult> domRpcResults) {
            if (!transformed.isDone()) {
                extractResult(domRpcResults, transformed);
            }
        }

        @Override
        public void onFailure(final Throwable throwable) {
            final NetconfDocumentedException exception = new NetconfDocumentedException(id + ":RPC during tx returned an exception" + throwable.getMessage(), // FIXME: add proper unmask/wrap to ExecutionException
            new Exception(throwable), ErrorType.APPLICATION, ErrorTag.OPERATION_FAILED, ErrorSeverity.ERROR);
            transformed.setException(exception);
        }
    }, MoreExecutors.directExecutor());
    return transformed;
}
Also used : DOMRpcResult(org.opendaylight.mdsal.dom.api.DOMRpcResult) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) DOMRpcResult(org.opendaylight.mdsal.dom.api.DOMRpcResult) NetconfDocumentedException(org.opendaylight.netconf.api.NetconfDocumentedException) ArrayList(java.util.ArrayList) List(java.util.List) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) NetconfDocumentedException(org.opendaylight.netconf.api.NetconfDocumentedException) TransactionCommitFailedException(org.opendaylight.mdsal.common.api.TransactionCommitFailedException)

Example 25 with DOMRpcResult

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

the class KeepaliveSalFacadeTest method testKeepaliveSuccessWithRpcError.

@Test
public void testKeepaliveSuccessWithRpcError() {
    final DOMRpcResult rpcSuccessWithError = new DefaultDOMRpcResult(mock(RpcError.class));
    doReturn(FluentFutures.immediateFluentFuture(rpcSuccessWithError)).when(deviceRpc).invokeRpc(any(QName.class), any(ContainerNode.class));
    keepaliveSalFacade.onDeviceConnected(null, null, deviceRpc);
    verify(underlyingSalFacade).onDeviceConnected(isNull(), isNull(), any(DOMRpcService.class), isNull());
    // Shouldn't disconnect the session
    verify(listener, times(0)).disconnect();
    verify(deviceRpc, timeout(15000).times(1)).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) RpcError(org.opendaylight.yangtools.yang.common.RpcError) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) 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