Search in sources :

Example 1 with Absolute

use of org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute in project controller by opendaylight.

the class OpsInvoker method execute.

@SuppressWarnings("checkstyle:IllegalCatch")
private void execute(final ExecuteAction msg) {
    LOG.debug("Executing Action {}", msg.getType());
    final ActorRef sender = getSender();
    final ListenableFuture<? extends DOMActionResult> future;
    try {
        future = actionService.invokeAction(msg.getType(), msg.getPath(), msg.getInput());
    } catch (final RuntimeException e) {
        LOG.debug("Failed to invoke action {}", msg.getType(), e);
        sender.tell(new Failure(e), self());
        return;
    }
    Futures.addCallback(future, new AbstractCallback<Absolute, DOMActionResult>(getSender(), msg.getType()) {

        @Override
        Object nullResponse(final Absolute type) {
            throw new IllegalStateException("Null invocation result of action " + type);
        }

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

Example 2 with Absolute

use of org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute in project mdsal by opendaylight.

the class DOMNotificationRouter method registerNotificationListener.

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

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

Example 3 with Absolute

use of org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute in project mdsal by opendaylight.

the class ActionProviderServiceAdapter method registerImplementation.

@Override
public <P extends DataObject, A extends Action<? extends InstanceIdentifier<P>, ?, ?>, S extends A> ObjectRegistration<S> registerImplementation(final ActionSpec<A, P> spec, final S implementation, final LogicalDatastoreType datastore, final Set<? extends InstanceIdentifier<P>> validNodes) {
    final CurrentAdapterSerializer serializer = currentSerializer();
    final Absolute actionPath = serializer.getActionPath(spec);
    final Impl impl = new Impl(adapterContext(), actionPath, spec.type(), implementation);
    final DOMActionInstance instance = validNodes.isEmpty() ? // Register on the entire datastore
    DOMActionInstance.of(actionPath, new DOMDataTreeIdentifier(datastore, YangInstanceIdentifier.empty())) : // Register on specific instances
    DOMActionInstance.of(actionPath, validNodes.stream().map(node -> serializer.toDOMDataTreeIdentifier(DataTreeIdentifier.create(datastore, node))).collect(Collectors.toUnmodifiableSet()));
    final ObjectRegistration<?> reg = getDelegate().registerActionImplementation(impl, instance);
    return new AbstractObjectRegistration<>(implementation) {

        @Override
        protected void removeRegistration() {
            reg.close();
        }
    };
}
Also used : DOMActionResult(org.opendaylight.mdsal.dom.api.DOMActionResult) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) ActionProviderService(org.opendaylight.mdsal.binding.api.ActionProviderService) LoggerFactory(org.slf4j.LoggerFactory) DOMActionInstance(org.opendaylight.mdsal.dom.api.DOMActionInstance) DataTreeIdentifier(org.opendaylight.mdsal.binding.api.DataTreeIdentifier) Factory(org.opendaylight.mdsal.binding.dom.adapter.BindingDOMAdapterBuilder.Factory) ErrorType(org.opendaylight.yangtools.yang.common.ErrorType) ClassToInstanceMap(com.google.common.collect.ClassToInstanceMap) Absolute(org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute) ObjectRegistration(org.opendaylight.yangtools.concepts.ObjectRegistration) Objects.requireNonNull(java.util.Objects.requireNonNull) DOMActionProviderService(org.opendaylight.mdsal.dom.api.DOMActionProviderService) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) DataObject(org.opendaylight.yangtools.yang.binding.DataObject) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) DOMDataTreeIdentifier(org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier) ImmutableSet(com.google.common.collect.ImmutableSet) NonNullByDefault(org.eclipse.jdt.annotation.NonNullByDefault) Logger(org.slf4j.Logger) ErrorTag(org.opendaylight.yangtools.yang.common.ErrorTag) Set(java.util.Set) ActionSpec(org.opendaylight.mdsal.binding.api.ActionSpec) Collectors(java.util.stream.Collectors) Futures(com.google.common.util.concurrent.Futures) List(java.util.List) AbstractObjectRegistration(org.opendaylight.yangtools.concepts.AbstractObjectRegistration) Action(org.opendaylight.yangtools.yang.binding.Action) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) RpcResultBuilder(org.opendaylight.yangtools.yang.common.RpcResultBuilder) LogicalDatastoreType(org.opendaylight.mdsal.common.api.LogicalDatastoreType) YangConstants(org.opendaylight.yangtools.yang.common.YangConstants) DOMActionImplementation(org.opendaylight.mdsal.dom.api.DOMActionImplementation) DOMService(org.opendaylight.mdsal.dom.api.DOMService) SimpleDOMActionResult(org.opendaylight.mdsal.dom.spi.SimpleDOMActionResult) AbstractObjectRegistration(org.opendaylight.yangtools.concepts.AbstractObjectRegistration) DOMDataTreeIdentifier(org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier) DOMActionInstance(org.opendaylight.mdsal.dom.api.DOMActionInstance) Absolute(org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute)

Example 4 with Absolute

use of org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute in project mdsal by opendaylight.

the class BindingDOMNotificationListenerAdapter method getNotificationTypes.

private static Set<Absolute> getNotificationTypes(final Class<? extends NotificationListener> type) {
    // TODO: Investigate possibility and performance impact if we cache this or expose
    // it from NotificationListenerInvoker
    final Set<Absolute> ret = new HashSet<>();
    for (final Method method : type.getMethods()) {
        if (BindingReflections.isNotificationCallback(method)) {
            final Class<?> notification = method.getParameterTypes()[0];
            ret.add(Absolute.of(BindingReflections.findQName(notification)));
        }
    }
    return ret;
}
Also used : Method(java.lang.reflect.Method) Absolute(org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute) HashSet(java.util.HashSet)

Example 5 with Absolute

use of org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute in project yangtools by opendaylight.

the class LeafRefContextTreeBuilderTest method leafRefContextUtilsTest2.

@Test
public void leafRefContextUtilsTest2() {
    final QName q1 = QName.create(tst, "odl-project");
    final QName q2 = QName.create(tst, "project");
    final QName q3 = QName.create(tst, "name");
    final Absolute node = Absolute.of(q1, q2, q3);
    LeafRefContext found = rootLeafRefContext.getLeafRefReferencingContext(node);
    assertNull(found);
    found = rootLeafRefContext.getLeafRefReferencedByContext(node);
    assertNotNull(found);
    assertTrue(found.isReferenced());
    assertFalse(found.getAllReferencedByLeafRefCtxs().isEmpty());
    assertEquals(6, found.getAllReferencedByLeafRefCtxs().size());
    assertEquals(rootLeafRefContext.getReferencedChildByName(q1).getReferencedChildByName(q2).getReferencedChildByName(q3), found);
}
Also used : QName(org.opendaylight.yangtools.yang.common.QName) Absolute(org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute) Test(org.junit.Test)

Aggregations

Absolute (org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute)31 Test (org.junit.Test)22 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)18 DOMNotification (org.opendaylight.mdsal.dom.api.DOMNotification)16 QName (org.opendaylight.yangtools.yang.common.QName)5 DOMActionResult (org.opendaylight.mdsal.dom.api.DOMActionResult)4 HashSet (java.util.HashSet)3 DOMDataTreeIdentifier (org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier)3 SimpleDOMActionResult (org.opendaylight.mdsal.dom.spi.SimpleDOMActionResult)3 AugmentationNode (org.opendaylight.yangtools.yang.data.api.schema.AugmentationNode)3 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)3 Futures (com.google.common.util.concurrent.Futures)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Objects.requireNonNull (java.util.Objects.requireNonNull)2 ExecutionException (java.util.concurrent.ExecutionException)2 Collectors (java.util.stream.Collectors)2 LogicalDatastoreType (org.opendaylight.mdsal.common.api.LogicalDatastoreType)2 DOMActionException (org.opendaylight.mdsal.dom.api.DOMActionException)2 DOMActionService (org.opendaylight.mdsal.dom.api.DOMActionService)2