Search in sources :

Example 31 with DataObject

use of org.opendaylight.yangtools.yang.binding.DataObject 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)

Example 32 with DataObject

use of org.opendaylight.yangtools.yang.binding.DataObject in project controller by opendaylight.

the class Bug1418AugmentationTest method complexAugmentationCreatedTest.

@Test
public void complexAugmentationCreatedTest() {
    final TestListener listener = createListener(LogicalDatastoreType.CONFIGURATION, COMPLEX_AUGMENT, AsyncDataBroker.DataChangeScope.SUBTREE, false);
    WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
    writeTx.put(LogicalDatastoreType.CONFIGURATION, TOP, top());
    writeTx.put(LogicalDatastoreType.CONFIGURATION, TOP_FOO, topLevelList(new TopLevelListKey(TOP_FOO_KEY)));
    writeTx.put(LogicalDatastoreType.CONFIGURATION, COMPLEX_AUGMENT, complexUsesAugment(LIST_VIA_USES_KEY));
    assertCommit(writeTx.submit());
    AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> event = listener.event();
    assertContains(event.getCreatedData(), COMPLEX_AUGMENT);
    assertContains(event.getCreatedData(), COMPLEX_AUGMENT.child(ListViaUses.class, LIST_VIA_USES_KEY));
    assertEmpty(event.getUpdatedData());
    assertEmpty(event.getOriginalData());
    assertEmpty(event.getRemovedPaths());
}
Also used : WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) ListViaUses(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.augment.rev140709.complex.from.grouping.ListViaUses) DataObject(org.opendaylight.yangtools.yang.binding.DataObject) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) TopLevelListKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelListKey) Test(org.junit.Test) AbstractDataChangeListenerTest(org.opendaylight.controller.md.sal.binding.test.AbstractDataChangeListenerTest)

Example 33 with DataObject

use of org.opendaylight.yangtools.yang.binding.DataObject in project controller by opendaylight.

the class Bug1418AugmentationTest method leafOnlyAugmentationUpdatedTest.

@Test
public void leafOnlyAugmentationUpdatedTest() {
    WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
    writeTx.put(LogicalDatastoreType.CONFIGURATION, TOP, top());
    writeTx.put(LogicalDatastoreType.CONFIGURATION, TOP_FOO, topLevelList(new TopLevelListKey(TOP_FOO_KEY)));
    writeTx.put(LogicalDatastoreType.CONFIGURATION, SIMPLE_AUGMENT, leafOnlyUsesAugment("test leaf"));
    assertCommit(writeTx.submit());
    final TestListener listener = createListener(LogicalDatastoreType.CONFIGURATION, SIMPLE_AUGMENT, AsyncDataBroker.DataChangeScope.SUBTREE);
    writeTx = getDataBroker().newWriteOnlyTransaction();
    writeTx.put(LogicalDatastoreType.CONFIGURATION, SIMPLE_AUGMENT, leafOnlyUsesAugment("test leaf changed"));
    assertCommit(writeTx.submit());
    AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> event = listener.event();
    assertContains(event.getUpdatedData(), SIMPLE_AUGMENT);
    assertContains(event.getOriginalData(), SIMPLE_AUGMENT);
    assertEmpty(event.getCreatedData());
    assertEmpty(event.getRemovedPaths());
}
Also used : WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) DataObject(org.opendaylight.yangtools.yang.binding.DataObject) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) TopLevelListKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelListKey) Test(org.junit.Test) AbstractDataChangeListenerTest(org.opendaylight.controller.md.sal.binding.test.AbstractDataChangeListenerTest)

Example 34 with DataObject

use of org.opendaylight.yangtools.yang.binding.DataObject in project controller by opendaylight.

the class Bug1418AugmentationTest method leafOnlyAugmentationDeletedTest.

@Test
public void leafOnlyAugmentationDeletedTest() {
    WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
    writeTx.put(LogicalDatastoreType.CONFIGURATION, TOP, top());
    writeTx.put(LogicalDatastoreType.CONFIGURATION, TOP_FOO, topLevelList(new TopLevelListKey(TOP_FOO_KEY)));
    writeTx.put(LogicalDatastoreType.CONFIGURATION, SIMPLE_AUGMENT, leafOnlyUsesAugment("test leaf"));
    assertCommit(writeTx.submit());
    final TestListener listener = createListener(LogicalDatastoreType.CONFIGURATION, SIMPLE_AUGMENT, AsyncDataBroker.DataChangeScope.SUBTREE);
    writeTx = getDataBroker().newWriteOnlyTransaction();
    writeTx.delete(LogicalDatastoreType.CONFIGURATION, SIMPLE_AUGMENT);
    assertCommit(writeTx.submit());
    AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> event = listener.event();
    assertContains(event.getRemovedPaths(), SIMPLE_AUGMENT);
    assertContains(event.getOriginalData(), SIMPLE_AUGMENT);
    assertEmpty(event.getCreatedData());
    assertEmpty(event.getUpdatedData());
}
Also used : WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) DataObject(org.opendaylight.yangtools.yang.binding.DataObject) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) TopLevelListKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelListKey) Test(org.junit.Test) AbstractDataChangeListenerTest(org.opendaylight.controller.md.sal.binding.test.AbstractDataChangeListenerTest)

Example 35 with DataObject

use of org.opendaylight.yangtools.yang.binding.DataObject in project bgpcep by opendaylight.

the class AbstractRIBSupportTest method createRoutes.

@SuppressWarnings("checkstyle:OverloadMethodsDeclarationOrder")
protected final Collection<MapEntryNode> createRoutes(final DataObject routes) {
    Preconditions.checkArgument(routes.getImplementedInterface().equals(this.abstractRIBSupport.routesContainerClass()));
    final InstanceIdentifier<DataObject> routesIId = routesIId();
    final Map.Entry<YangInstanceIdentifier, NormalizedNode<?, ?>> normalizedNode = this.mappingService.toNormalizedNode(routesIId, routes);
    final ContainerNode container = (ContainerNode) normalizedNode.getValue();
    final NodeIdentifier routeNid = new NodeIdentifier(getRouteListQname());
    return ((MapNode) container.getChild(routeNid).get()).getValue();
}
Also used : DataObject(org.opendaylight.yangtools.yang.binding.DataObject) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) MapNode(org.opendaylight.yangtools.yang.data.api.schema.MapNode) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) Map(java.util.Map) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)

Aggregations

DataObject (org.opendaylight.yangtools.yang.binding.DataObject)44 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)24 Test (org.junit.Test)14 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)11 DataBroker (org.opendaylight.controller.md.sal.binding.api.DataBroker)10 Optional (com.google.common.base.Optional)8 HashMap (java.util.HashMap)7 Map (java.util.Map)7 LogicalDatastoreType (org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType)7 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)7 Logger (org.slf4j.Logger)7 LoggerFactory (org.slf4j.LoggerFactory)7 ReadOnlyTransaction (org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction)6 AbstractDataChangeListenerTest (org.opendaylight.controller.md.sal.binding.test.AbstractDataChangeListenerTest)6 Node (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node)6 Collection (java.util.Collection)5 Nonnull (javax.annotation.Nonnull)5 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)5 TopLevelListKey (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelListKey)5 DataObjectModification (org.opendaylight.controller.md.sal.binding.api.DataObjectModification)4