Search in sources :

Example 6 with DOMRpcResult

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

the class Mdsal500Test method testBindingRegistrationWithDOMInvocation.

@Test
public void testBindingRegistrationWithDOMInvocation() throws Exception {
    switchRpcImpl.registerTo(baRpcProviderService).setSwitchResult(switchResult(true));
    final Mdsal500Service baSwitchService = baRpcConsumerService.getRpcService(Mdsal500Service.class);
    assertNotSame(switchRpcImpl, baSwitchService);
    SwitchInput baSwitchInput = switchBuilder(FOO).build();
    ContainerNode biSwitchInput = toDOMSwitchInput(baSwitchInput);
    DOMRpcResult domResult = biRpcService.invokeRpc(SWITCH_QNAME, biSwitchInput).get(5, TimeUnit.SECONDS);
    assertNotNull(domResult);
    assertNotNull(domResult.getResult());
    assertTrue("Binding KnockKnock service was not invoked", switchRpcImpl.getReceivedSwitch().containsKey(FOO));
    assertEquals(baSwitchInput, switchRpcImpl.getReceivedSwitch().get(FOO).iterator().next());
}
Also used : Mdsal500Service(org.opendaylight.yang.gen.v1.rpc.norev.Mdsal500Service) DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) DOMRpcResult(org.opendaylight.mdsal.dom.api.DOMRpcResult) SwitchInput(org.opendaylight.yang.gen.v1.rpc.norev.SwitchInput) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) Test(org.junit.Test)

Example 7 with DOMRpcResult

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

the class BindingDOMRpcIntegrationTest method testBindingRegistrationWithDOMInvocation.

@Test
public void testBindingRegistrationWithDOMInvocation() throws InterruptedException, ExecutionException, TimeoutException {
    knockRpcImpl.registerTo(baRpcProviderService, BA_NODE_ID).setKnockKnockResult(knockResult(true, "open"));
    final OpendaylightKnockKnockRpcService baKnockService = baRpcConsumerService.getRpcService(OpendaylightKnockKnockRpcService.class);
    assertNotSame(knockRpcImpl, baKnockService);
    KnockKnockInput baKnockKnockInput = knockKnock(BA_NODE_ID).setQuestion("who's there?").build();
    ContainerNode biKnockKnockInput = toDOMKnockKnockInput(baKnockKnockInput);
    DOMRpcResult domResult = biRpcService.invokeRpc(KNOCK_KNOCK_QNAME, biKnockKnockInput).get(5, TimeUnit.SECONDS);
    assertNotNull(domResult);
    assertNotNull(domResult.getResult());
    assertTrue("Binding KnockKnock service was not invoked", knockRpcImpl.getReceivedKnocks().containsKey(BA_NODE_ID));
    assertEquals(baKnockKnockInput, knockRpcImpl.getReceivedKnocks().get(BA_NODE_ID).iterator().next());
}
Also used : OpendaylightKnockKnockRpcService(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.md.sal.knock.knock.rev180723.OpendaylightKnockKnockRpcService) DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) DOMRpcResult(org.opendaylight.mdsal.dom.api.DOMRpcResult) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) KnockKnockInput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.md.sal.knock.knock.rev180723.KnockKnockInput) Test(org.junit.Test)

Example 8 with DOMRpcResult

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

the class LibraryModulesSchemas method create.

public static LibraryModulesSchemas create(final NetconfDeviceRpc deviceRpc, final RemoteDeviceId deviceId) {
    final DOMRpcResult moduleListNodeResult;
    try {
        moduleListNodeResult = deviceRpc.invokeRpc(NETCONF_GET_QNAME, GET_MODULES_STATE_MODULE_LIST_RPC).get();
    } catch (final InterruptedException e) {
        Thread.currentThread().interrupt();
        throw new RuntimeException(deviceId + ": Interrupted while waiting for response to " + MODULES_STATE_MODULE_LIST, e);
    } catch (final ExecutionException e) {
        LOG.warn("{}: Unable to detect available schemas, get to {} failed", deviceId, MODULES_STATE_MODULE_LIST, e);
        return new LibraryModulesSchemas(ImmutableMap.of());
    }
    if (moduleListNodeResult.getErrors().isEmpty() == false) {
        LOG.warn("{}: Unable to detect available schemas, get to {} failed, {}", deviceId, MODULES_STATE_MODULE_LIST, moduleListNodeResult.getErrors());
        return new LibraryModulesSchemas(ImmutableMap.of());
    }
    final Optional<DataContainerChild> modulesStateNode = findModulesStateNode(moduleListNodeResult.getResult());
    if (modulesStateNode.isPresent()) {
        final DataContainerChild node = modulesStateNode.get();
        checkState(node instanceof ContainerNode, "Expecting container containing schemas, but was %s", node);
        return create((ContainerNode) node);
    }
    LOG.warn("{}: Unable to detect available schemas, get to {} was empty", deviceId, MODULES_STATE_NID);
    return new LibraryModulesSchemas(ImmutableMap.of());
}
Also used : DOMRpcResult(org.opendaylight.mdsal.dom.api.DOMRpcResult) DataContainerChild(org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) DataContainerNode(org.opendaylight.yangtools.yang.data.api.schema.DataContainerNode) ExecutionException(java.util.concurrent.ExecutionException)

Example 9 with DOMRpcResult

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

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

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