Search in sources :

Example 41 with ContainerNode

use of org.opendaylight.yangtools.yang.data.api.schema.ContainerNode 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 42 with ContainerNode

use of org.opendaylight.yangtools.yang.data.api.schema.ContainerNode in project controller by opendaylight.

the class PruningDataTreeModificationTest method testMergeWithInvalidChildNodeNames.

@Test
public void testMergeWithInvalidChildNodeNames() throws DataValidationFailedException {
    ContainerNode augContainer = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(AUG_CONTAINER)).withChild(ImmutableNodes.containerNode(AUG_INNER_CONTAINER)).build();
    DataContainerChild<?, ?> outerNode = outerNode(outerNodeEntry(1, innerNode("one", "two")));
    ContainerNode normalizedNode = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TEST_QNAME)).withChild(outerNode).withChild(augContainer).withChild(ImmutableNodes.leafNode(AUG_QNAME, "aug")).build();
    YangInstanceIdentifier path = TestModel.TEST_PATH;
    pruningDataTreeModification.merge(path, normalizedNode);
    dataTree.commit(getCandidate());
    ContainerNode prunedNode = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TEST_QNAME)).withChild(outerNode).build();
    Optional<NormalizedNode<?, ?>> actual = dataTree.takeSnapshot().readNode(path);
    assertTrue("After pruning present", actual.isPresent());
    assertEquals("After pruning", prunedNode, actual.get());
}
Also used : ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Test(org.junit.Test)

Example 43 with ContainerNode

use of org.opendaylight.yangtools.yang.data.api.schema.ContainerNode in project controller by opendaylight.

the class DistributedShardFrontendTest method createCrossShardContainer.

private static ContainerNode createCrossShardContainer() {
    final MapEntryNode outerListEntry1 = ImmutableNodes.mapEntryBuilder(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1).withChild(createInnerMapNode(1)).build();
    final MapEntryNode outerListEntry2 = ImmutableNodes.mapEntryBuilder(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 2).withChild(createInnerMapNode(2)).build();
    final MapNode outerList = ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).withChild(outerListEntry1).withChild(outerListEntry2).build();
    final ContainerNode testContainer = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME)).withChild(outerList).build();
    return testContainer;
}
Also used : 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) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)

Example 44 with ContainerNode

use of org.opendaylight.yangtools.yang.data.api.schema.ContainerNode in project controller by opendaylight.

the class ReadyLocalTransactionSerializerTest method testToAndFromBinary.

@Test
public void testToAndFromBinary() throws NotSerializableException {
    DataTree dataTree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL, TestModel.createTestContext());
    DataTreeModification modification = dataTree.takeSnapshot().newModification();
    ContainerNode writeData = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
    new WriteModification(TestModel.TEST_PATH, writeData).apply(modification);
    MapNode mergeData = ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build();
    new MergeModification(TestModel.OUTER_LIST_PATH, mergeData).apply(modification);
    TransactionIdentifier txId = nextTransactionId();
    ReadyLocalTransaction readyMessage = new ReadyLocalTransaction(txId, modification, true);
    final ExtendedActorSystem system = (ExtendedActorSystem) ExtendedActorSystem.create("test");
    final Object deserialized;
    try {
        final ReadyLocalTransactionSerializer serializer = new ReadyLocalTransactionSerializer(system);
        final byte[] bytes = serializer.toBinary(readyMessage);
        deserialized = serializer.fromBinary(bytes, ReadyLocalTransaction.class);
    } finally {
        JavaTestKit.shutdownActorSystem(system);
    }
    assertNotNull("fromBinary returned null", deserialized);
    assertEquals("fromBinary return type", BatchedModifications.class, deserialized.getClass());
    BatchedModifications batched = (BatchedModifications) deserialized;
    assertEquals("getTransactionID", txId, batched.getTransactionId());
    assertEquals("getVersion", DataStoreVersions.CURRENT_VERSION, batched.getVersion());
    List<Modification> batchedMods = batched.getModifications();
    assertEquals("getModifications size", 2, batchedMods.size());
    Modification mod = batchedMods.get(0);
    assertEquals("Modification type", WriteModification.class, mod.getClass());
    assertEquals("Modification getPath", TestModel.TEST_PATH, ((WriteModification) mod).getPath());
    assertEquals("Modification getData", writeData, ((WriteModification) mod).getData());
    mod = batchedMods.get(1);
    assertEquals("Modification type", MergeModification.class, mod.getClass());
    assertEquals("Modification getPath", TestModel.OUTER_LIST_PATH, ((MergeModification) mod).getPath());
    assertEquals("Modification getData", mergeData, ((MergeModification) mod).getData());
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification) WriteModification(org.opendaylight.controller.cluster.datastore.modification.WriteModification) DataTreeModification(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification) WriteModification(org.opendaylight.controller.cluster.datastore.modification.WriteModification) Modification(org.opendaylight.controller.cluster.datastore.modification.Modification) MergeModification(org.opendaylight.controller.cluster.datastore.modification.MergeModification) MapNode(org.opendaylight.yangtools.yang.data.api.schema.MapNode) InMemoryDataTreeFactory(org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory) MergeModification(org.opendaylight.controller.cluster.datastore.modification.MergeModification) ExtendedActorSystem(akka.actor.ExtendedActorSystem) DataTree(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree) TransactionIdentifier(org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) Test(org.junit.Test) AbstractTest(org.opendaylight.controller.cluster.datastore.AbstractTest)

Example 45 with ContainerNode

use of org.opendaylight.yangtools.yang.data.api.schema.ContainerNode in project controller by opendaylight.

the class ClientTransactionCursorTest method testMerge.

@Test
public void testMerge() throws Exception {
    final YangInstanceIdentifier.NodeIdentifier path = YangInstanceIdentifier.NodeIdentifier.create(NODE_1);
    final ContainerNode data = createData(path.getNodeType());
    cursor.merge(path, data);
    final YangInstanceIdentifier expected = createId(NODE_1);
    verify(transaction).merge(expected, data);
}
Also used : ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Test(org.junit.Test)

Aggregations

ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)81 Test (org.junit.Test)46 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)32 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)28 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)18 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)12 MapNode (org.opendaylight.yangtools.yang.data.api.schema.MapNode)12 ChoiceNode (org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode)9 DefaultDOMRpcResult (org.opendaylight.controller.md.sal.dom.spi.DefaultDOMRpcResult)8 ByteBuf (io.netty.buffer.ByteBuf)7 TransactionIdentifier (org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier)7 Map (java.util.Map)6 DOMRpcResult (org.opendaylight.controller.md.sal.dom.api.DOMRpcResult)6 Collection (java.util.Collection)4 ExecutionException (java.util.concurrent.ExecutionException)4 ConcurrentDOMDataBroker (org.opendaylight.controller.cluster.databroker.ConcurrentDOMDataBroker)4 MergeModification (org.opendaylight.controller.cluster.datastore.modification.MergeModification)4 WriteModification (org.opendaylight.controller.cluster.datastore.modification.WriteModification)4 DOMDataWriteTransaction (org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction)4 DOMRpcException (org.opendaylight.controller.md.sal.dom.api.DOMRpcException)4