Search in sources :

Example 6 with SchemaPath

use of org.opendaylight.yangtools.yang.model.api.SchemaPath in project controller by opendaylight.

the class BindingDOMRpcImplementationAdapter method invokeRpc.

@Nonnull
@Override
public CheckedFuture<DOMRpcResult, DOMRpcException> invokeRpc(@Nonnull final DOMRpcIdentifier rpc, final NormalizedNode<?, ?> input) {
    final SchemaPath schemaPath = rpc.getType();
    final DataObject bindingInput = input != null ? deserialize(rpc.getType(), input) : null;
    final ListenableFuture<RpcResult<?>> bindingResult = invoke(schemaPath, bindingInput);
    return transformResult(bindingResult);
}
Also used : DataObject(org.opendaylight.yangtools.yang.binding.DataObject) SchemaPath(org.opendaylight.yangtools.yang.model.api.SchemaPath) DOMRpcResult(org.opendaylight.controller.md.sal.dom.api.DOMRpcResult) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) Nonnull(javax.annotation.Nonnull)

Example 7 with SchemaPath

use of org.opendaylight.yangtools.yang.model.api.SchemaPath in project controller by opendaylight.

the class DOMNotificationRouter method registerNotificationListener.

@Override
public synchronized <T extends DOMNotificationListener> ListenerRegistration<T> registerNotificationListener(final T listener, final Collection<SchemaPath> types) {
    final ListenerRegistration<T> reg = new AbstractListenerRegistration<T>(listener) {

        @Override
        protected void removeRegistration() {
            final ListenerRegistration<T> me = this;
            synchronized (DOMNotificationRouter.this) {
                replaceListeners(ImmutableMultimap.copyOf(Multimaps.filterValues(listeners, input -> input != me)));
            }
        }
    };
    if (!types.isEmpty()) {
        final Builder<SchemaPath, ListenerRegistration<? extends DOMNotificationListener>> b = ImmutableMultimap.builder();
        b.putAll(listeners);
        for (final SchemaPath t : types) {
            b.put(t, reg);
        }
        replaceListeners(b.build());
    }
    return reg;
}
Also used : AbstractListenerRegistration(org.opendaylight.yangtools.concepts.AbstractListenerRegistration) DOMNotificationListener(org.opendaylight.controller.md.sal.dom.api.DOMNotificationListener) SchemaPath(org.opendaylight.yangtools.yang.model.api.SchemaPath) ListenerRegistration(org.opendaylight.yangtools.concepts.ListenerRegistration) AbstractListenerRegistration(org.opendaylight.yangtools.concepts.AbstractListenerRegistration)

Example 8 with SchemaPath

use of org.opendaylight.yangtools.yang.model.api.SchemaPath in project controller by opendaylight.

the class RpcInvoker method executeRpc.

@SuppressWarnings("checkstyle:IllegalCatch")
private void executeRpc(final ExecuteRpc msg) {
    LOG.debug("Executing rpc {}", msg.getRpc());
    final SchemaPath schemaPath = SchemaPath.create(true, msg.getRpc());
    final ActorRef sender = getSender();
    final ActorRef self = self();
    final ListenableFuture<DOMRpcResult> future;
    try {
        future = rpcService.invokeRpc(schemaPath, msg.getInputNormalizedNode());
    } catch (final RuntimeException e) {
        LOG.debug("Failed to invoke RPC {}", msg.getRpc(), e);
        sender.tell(new akka.actor.Status.Failure(e), sender);
        return;
    }
    Futures.addCallback(future, new FutureCallback<DOMRpcResult>() {

        @Override
        public void onSuccess(final DOMRpcResult result) {
            if (result == null) {
                // This shouldn't happen but the FutureCallback annotates the result param with Nullable so
                // handle null here to avoid FindBugs warning.
                LOG.debug("Got null DOMRpcResult - sending null response for execute rpc : {}", msg.getRpc());
                sender.tell(new RpcResponse(null), self);
                return;
            }
            if (!result.getErrors().isEmpty()) {
                final String message = String.format("Execution of RPC %s failed", msg.getRpc());
                sender.tell(new akka.actor.Status.Failure(new RpcErrorsException(message, result.getErrors())), self);
            } else {
                LOG.debug("Sending response for execute rpc : {}", msg.getRpc());
                sender.tell(new RpcResponse(result.getResult()), self);
            }
        }

        @Override
        public void onFailure(final Throwable failure) {
            LOG.debug("Failed to execute RPC {}", msg.getRpc(), failure);
            LOG.error("Failed to execute RPC {} due to {}. More details are available on DEBUG level.", msg.getRpc(), Throwables.getRootCause(failure));
            sender.tell(new akka.actor.Status.Failure(failure), self);
        }
    }, MoreExecutors.directExecutor());
}
Also used : DOMRpcResult(org.opendaylight.controller.md.sal.dom.api.DOMRpcResult) ActorRef(akka.actor.ActorRef) RpcResponse(org.opendaylight.controller.remote.rpc.messages.RpcResponse) SchemaPath(org.opendaylight.yangtools.yang.model.api.SchemaPath)

Example 9 with SchemaPath

use of org.opendaylight.yangtools.yang.model.api.SchemaPath in project controller by opendaylight.

the class DOMRpcServiceTestBugfix560 method test.

@Test
public void test() throws ExecutionException, InterruptedException {
    // FIXME: This is made to only make sure instance identifier codec for path is instantiated.
    domMountPointService.createMountPoint(BI_MOUNT_ID).addService(DOMRpcService.class, new DOMRpcService() {

        @Override
        public <T extends DOMRpcAvailabilityListener> ListenerRegistration<T> registerRpcListener(final T arg0) {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public CheckedFuture<DOMRpcResult, DOMRpcException> invokeRpc(final SchemaPath arg0, final NormalizedNode<?, ?> arg1) {
            final DOMRpcResult result = new DefaultDOMRpcResult((NormalizedNode<?, ?>) null);
            return Futures.immediateCheckedFuture(result);
        }
    }).register();
    final Optional<MountPoint> mountInstance = bindingMountPointService.getMountPoint(BA_MOUNT_ID);
    assertTrue(mountInstance.isPresent());
    final Optional<RpcConsumerRegistry> rpcRegistry = mountInstance.get().getService(RpcConsumerRegistry.class);
    assertTrue(rpcRegistry.isPresent());
    final OpendaylightTestRpcServiceService rpcService = rpcRegistry.get().getRpcService(OpendaylightTestRpcServiceService.class);
    assertNotNull(rpcService);
    try {
        final Future<RpcResult<Void>> result = rpcService.rockTheHouse(new RockTheHouseInputBuilder().build());
        assertTrue(result.get().isSuccessful());
    } catch (final IllegalStateException ex) {
        fail("OpendaylightTestRpcServiceService class doesn't contain rockTheHouse method!");
    }
}
Also used : DefaultDOMRpcResult(org.opendaylight.controller.md.sal.dom.spi.DefaultDOMRpcResult) DOMRpcService(org.opendaylight.controller.md.sal.dom.api.DOMRpcService) DOMRpcResult(org.opendaylight.controller.md.sal.dom.api.DOMRpcResult) DefaultDOMRpcResult(org.opendaylight.controller.md.sal.dom.spi.DefaultDOMRpcResult) RockTheHouseInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.bi.ba.rpcservice.rev140701.RockTheHouseInputBuilder) DOMRpcResult(org.opendaylight.controller.md.sal.dom.api.DOMRpcResult) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) DefaultDOMRpcResult(org.opendaylight.controller.md.sal.dom.spi.DefaultDOMRpcResult) DOMRpcException(org.opendaylight.controller.md.sal.dom.api.DOMRpcException) MountPoint(org.opendaylight.controller.md.sal.binding.api.MountPoint) DOMRpcAvailabilityListener(org.opendaylight.controller.md.sal.dom.api.DOMRpcAvailabilityListener) RpcConsumerRegistry(org.opendaylight.controller.sal.binding.api.RpcConsumerRegistry) OpendaylightTestRpcServiceService(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.bi.ba.rpcservice.rev140701.OpendaylightTestRpcServiceService) SchemaPath(org.opendaylight.yangtools.yang.model.api.SchemaPath) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) Test(org.junit.Test)

Example 10 with SchemaPath

use of org.opendaylight.yangtools.yang.model.api.SchemaPath in project controller by opendaylight.

the class RpcServiceAdapter method transformFuture.

private static ListenableFuture<RpcResult<?>> transformFuture(final SchemaPath rpc, final ListenableFuture<DOMRpcResult> domFuture, final BindingNormalizedNodeSerializer codec) {
    return Futures.transform(domFuture, input -> {
        final NormalizedNode<?, ?> domData = input.getResult();
        final DataObject bindingResult;
        if (domData != null) {
            final SchemaPath rpcOutput = rpc.createChild(QName.create(rpc.getLastComponent(), "output"));
            bindingResult = codec.fromNormalizedNodeRpcData(rpcOutput, (ContainerNode) domData);
        } else {
            bindingResult = null;
        }
        // DOMRpcResult does not have a notion of success, hence we have to reverse-engineer it by looking
        // at reported errors and checking whether they are just warnings.
        final Collection<RpcError> errors = input.getErrors();
        return RpcResult.class.cast(RpcResultBuilder.status(errors.stream().noneMatch(error -> error.getSeverity() == ErrorSeverity.ERROR)).withResult(bindingResult).withRpcErrors(errors).build());
    }, MoreExecutors.directExecutor());
}
Also used : DOMRpcResult(org.opendaylight.controller.md.sal.dom.api.DOMRpcResult) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) SchemaPath(org.opendaylight.yangtools.yang.model.api.SchemaPath) Proxy(java.lang.reflect.Proxy) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) ErrorSeverity(org.opendaylight.yangtools.yang.common.RpcError.ErrorSeverity) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) DataContainer(org.opendaylight.yangtools.yang.binding.DataContainer) RpcDefinition(org.opendaylight.yangtools.yang.model.api.RpcDefinition) CheckedFuture(com.google.common.util.concurrent.CheckedFuture) BindingReflections(org.opendaylight.yangtools.yang.binding.util.BindingReflections) RpcRoutingStrategy(org.opendaylight.controller.md.sal.dom.broker.spi.rpc.RpcRoutingStrategy) RpcService(org.opendaylight.yangtools.yang.binding.RpcService) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) BindingNormalizedNodeSerializer(org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer) DataObject(org.opendaylight.yangtools.yang.binding.DataObject) Method(java.lang.reflect.Method) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) LeafNode(org.opendaylight.yangtools.yang.data.api.schema.LeafNode) DOMRpcService(org.opendaylight.controller.md.sal.dom.api.DOMRpcService) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) DOMRpcException(org.opendaylight.controller.md.sal.dom.api.DOMRpcException) QName(org.opendaylight.yangtools.yang.common.QName) Futures(com.google.common.util.concurrent.Futures) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) RpcResultBuilder(org.opendaylight.yangtools.yang.common.RpcResultBuilder) ImmutableNodes(org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes) Entry(java.util.Map.Entry) Preconditions(com.google.common.base.Preconditions) InvocationHandler(java.lang.reflect.InvocationHandler) RpcError(org.opendaylight.yangtools.yang.common.RpcError) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) DataObject(org.opendaylight.yangtools.yang.binding.DataObject) SchemaPath(org.opendaylight.yangtools.yang.model.api.SchemaPath) RpcError(org.opendaylight.yangtools.yang.common.RpcError) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)

Aggregations

SchemaPath (org.opendaylight.yangtools.yang.model.api.SchemaPath)15 DOMRpcResult (org.opendaylight.controller.md.sal.dom.api.DOMRpcResult)4 Method (java.lang.reflect.Method)3 Test (org.junit.Test)3 QName (org.opendaylight.yangtools.yang.common.QName)3 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)3 RpcDefinition (org.opendaylight.yangtools.yang.model.api.RpcDefinition)3 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 DOMNotificationListener (org.opendaylight.controller.md.sal.dom.api.DOMNotificationListener)2 DOMRpcException (org.opendaylight.controller.md.sal.dom.api.DOMRpcException)2 DOMRpcService (org.opendaylight.controller.md.sal.dom.api.DOMRpcService)2 RpcRoutingStrategy (org.opendaylight.controller.md.sal.dom.broker.spi.rpc.RpcRoutingStrategy)2 AbstractListenerRegistration (org.opendaylight.yangtools.concepts.AbstractListenerRegistration)2 DataObject (org.opendaylight.yangtools.yang.binding.DataObject)2 QNameModule (org.opendaylight.yangtools.yang.common.QNameModule)2 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)2 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)2 ActorRef (akka.actor.ActorRef)1 Preconditions (com.google.common.base.Preconditions)1