Search in sources :

Example 1 with DataContainerNodeBuilder

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

the class TransactionProxy method mergeAllData.

private void mergeAllData(final ContainerNode rootData) {
    // Populate requests for individual shards that are being touched
    final Map<String, DataContainerNodeBuilder<NodeIdentifier, ContainerNode>> rootBuilders = new HashMap<>();
    for (DataContainerChild child : rootData.body()) {
        final String shardName = shardNameFromRootChild(child);
        rootBuilders.computeIfAbsent(shardName, unused -> Builders.containerBuilder().withNodeIdentifier(rootData.getIdentifier())).addChild(child);
    }
    // Now dispatch all merges
    for (Entry<String, DataContainerNodeBuilder<NodeIdentifier, ContainerNode>> entry : rootBuilders.entrySet()) {
        getContextWrapper(entry.getKey()).maybeExecuteTransactionOperation(new MergeOperation(YangInstanceIdentifier.empty(), entry.getValue().build()));
    }
}
Also used : Verify.verifyNotNull(com.google.common.base.Verify.verifyNotNull) Iterables(com.google.common.collect.Iterables) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) ActorUtils(org.opendaylight.controller.cluster.datastore.utils.ActorUtils) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) SortedSet(java.util.SortedSet) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) LoggerFactory(org.slf4j.LoggerFactory) AbstractDOMStoreTransaction(org.opendaylight.mdsal.dom.spi.store.AbstractDOMStoreTransaction) HashMap(java.util.HashMap) SettableFuture(com.google.common.util.concurrent.SettableFuture) ActorSelection(akka.actor.ActorSelection) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) MergeOperation(org.opendaylight.controller.cluster.datastore.TransactionModificationOperation.MergeOperation) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) DataExists(org.opendaylight.controller.cluster.datastore.messages.DataExists) DOMStoreReadWriteTransaction(org.opendaylight.mdsal.dom.spi.store.DOMStoreReadWriteTransaction) Objects.requireNonNull(java.util.Objects.requireNonNull) Map(java.util.Map) Promise(scala.concurrent.Promise) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) Builders(org.opendaylight.yangtools.yang.data.impl.schema.Builders) Logger(org.slf4j.Logger) DataContainerNodeBuilder(org.opendaylight.yangtools.yang.data.api.schema.builder.DataContainerNodeBuilder) Future(scala.concurrent.Future) Collection(java.util.Collection) Set(java.util.Set) DeleteOperation(org.opendaylight.controller.cluster.datastore.TransactionModificationOperation.DeleteOperation) DataContainerChild(org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild) DataValidationFailedException(org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException) Preconditions.checkState(com.google.common.base.Preconditions.checkState) Futures(com.google.common.util.concurrent.Futures) List(java.util.List) ReadData(org.opendaylight.controller.cluster.datastore.messages.ReadData) TreeMap(java.util.TreeMap) Entry(java.util.Map.Entry) Optional(java.util.Optional) TransactionIdentifier(org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier) VisibleForTesting(com.google.common.annotations.VisibleForTesting) AbstractRead(org.opendaylight.controller.cluster.datastore.messages.AbstractRead) NormalizedNodeAggregator(org.opendaylight.controller.cluster.datastore.utils.NormalizedNodeAggregator) WriteOperation(org.opendaylight.controller.cluster.datastore.TransactionModificationOperation.WriteOperation) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) FluentFuture(com.google.common.util.concurrent.FluentFuture) MergeOperation(org.opendaylight.controller.cluster.datastore.TransactionModificationOperation.MergeOperation) HashMap(java.util.HashMap) DataContainerChild(org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild) DataContainerNodeBuilder(org.opendaylight.yangtools.yang.data.api.schema.builder.DataContainerNodeBuilder)

Example 2 with DataContainerNodeBuilder

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

the class TransactionProxy method writeAllData.

private void writeAllData(final ContainerNode rootData) {
    // Open builders for all shards
    final Map<String, DataContainerNodeBuilder<NodeIdentifier, ContainerNode>> rootBuilders = new HashMap<>();
    for (String shardName : getActorUtils().getConfiguration().getAllShardNames()) {
        rootBuilders.put(shardName, Builders.containerBuilder().withNodeIdentifier(rootData.getIdentifier()));
    }
    // Now distribute children as needed
    for (DataContainerChild child : rootData.body()) {
        final String shardName = shardNameFromRootChild(child);
        verifyNotNull(rootBuilders.get(shardName), "Failed to find builder for %s", shardName).addChild(child);
    }
    // Now dispatch all writes
    for (Entry<String, DataContainerNodeBuilder<NodeIdentifier, ContainerNode>> entry : rootBuilders.entrySet()) {
        getContextWrapper(entry.getKey()).maybeExecuteTransactionOperation(new WriteOperation(YangInstanceIdentifier.empty(), entry.getValue().build()));
    }
}
Also used : WriteOperation(org.opendaylight.controller.cluster.datastore.TransactionModificationOperation.WriteOperation) HashMap(java.util.HashMap) DataContainerChild(org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild) DataContainerNodeBuilder(org.opendaylight.yangtools.yang.data.api.schema.builder.DataContainerNodeBuilder)

Example 3 with DataContainerNodeBuilder

use of org.opendaylight.yangtools.yang.data.api.schema.builder.DataContainerNodeBuilder in project netconf by opendaylight.

the class ReadDataTransactionUtil method prepareData.

/**
 * Prepare and map all data from DS.
 *
 * @param configDataNode data node of config data
 * @param stateDataNode  data node of state data
 * @return {@link NormalizedNode}
 */
@SuppressWarnings("unchecked")
@NonNull
private static NormalizedNode prepareData(@NonNull final NormalizedNode configDataNode, @NonNull final NormalizedNode stateDataNode) {
    if (configDataNode instanceof UserMapNode) {
        final CollectionNodeBuilder<MapEntryNode, UserMapNode> builder = Builders.orderedMapBuilder().withNodeIdentifier(((MapNode) configDataNode).getIdentifier());
        mapValueToBuilder(((UserMapNode) configDataNode).body(), ((UserMapNode) stateDataNode).body(), builder);
        return builder.build();
    } else if (configDataNode instanceof MapNode) {
        final CollectionNodeBuilder<MapEntryNode, SystemMapNode> builder = ImmutableNodes.mapNodeBuilder().withNodeIdentifier(((MapNode) configDataNode).getIdentifier());
        mapValueToBuilder(((MapNode) configDataNode).body(), ((MapNode) stateDataNode).body(), builder);
        return builder.build();
    } else if (configDataNode instanceof MapEntryNode) {
        final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> builder = ImmutableNodes.mapEntryBuilder().withNodeIdentifier(((MapEntryNode) configDataNode).getIdentifier());
        mapValueToBuilder(((MapEntryNode) configDataNode).body(), ((MapEntryNode) stateDataNode).body(), builder);
        return builder.build();
    } else if (configDataNode instanceof ContainerNode) {
        final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> builder = Builders.containerBuilder().withNodeIdentifier(((ContainerNode) configDataNode).getIdentifier());
        mapValueToBuilder(((ContainerNode) configDataNode).body(), ((ContainerNode) stateDataNode).body(), builder);
        return builder.build();
    } else if (configDataNode instanceof AugmentationNode) {
        final DataContainerNodeBuilder<AugmentationIdentifier, AugmentationNode> builder = Builders.augmentationBuilder().withNodeIdentifier(((AugmentationNode) configDataNode).getIdentifier());
        mapValueToBuilder(((AugmentationNode) configDataNode).body(), ((AugmentationNode) stateDataNode).body(), builder);
        return builder.build();
    } else if (configDataNode instanceof ChoiceNode) {
        final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> builder = Builders.choiceBuilder().withNodeIdentifier(((ChoiceNode) configDataNode).getIdentifier());
        mapValueToBuilder(((ChoiceNode) configDataNode).body(), ((ChoiceNode) stateDataNode).body(), builder);
        return builder.build();
    } else if (configDataNode instanceof LeafNode) {
        return ImmutableNodes.leafNode(configDataNode.getIdentifier().getNodeType(), configDataNode.body());
    } else if (configDataNode instanceof UserLeafSetNode) {
        final ListNodeBuilder<Object, UserLeafSetNode<Object>> builder = Builders.orderedLeafSetBuilder().withNodeIdentifier(((UserLeafSetNode<?>) configDataNode).getIdentifier());
        mapValueToBuilder(((UserLeafSetNode<Object>) configDataNode).body(), ((UserLeafSetNode<Object>) stateDataNode).body(), builder);
        return builder.build();
    } else if (configDataNode instanceof LeafSetNode) {
        final ListNodeBuilder<Object, SystemLeafSetNode<Object>> builder = Builders.leafSetBuilder().withNodeIdentifier(((LeafSetNode<?>) configDataNode).getIdentifier());
        mapValueToBuilder(((LeafSetNode<Object>) configDataNode).body(), ((LeafSetNode<Object>) stateDataNode).body(), builder);
        return builder.build();
    } else if (configDataNode instanceof LeafSetEntryNode) {
        return Builders.leafSetEntryBuilder().withNodeIdentifier(((LeafSetEntryNode<?>) configDataNode).getIdentifier()).withValue(configDataNode.body()).build();
    } else if (configDataNode instanceof UnkeyedListNode) {
        final CollectionNodeBuilder<UnkeyedListEntryNode, UnkeyedListNode> builder = Builders.unkeyedListBuilder().withNodeIdentifier(((UnkeyedListNode) configDataNode).getIdentifier());
        mapValueToBuilder(((UnkeyedListNode) configDataNode).body(), ((UnkeyedListNode) stateDataNode).body(), builder);
        return builder.build();
    } else if (configDataNode instanceof UnkeyedListEntryNode) {
        final DataContainerNodeBuilder<NodeIdentifier, UnkeyedListEntryNode> builder = Builders.unkeyedListEntryBuilder().withNodeIdentifier(((UnkeyedListEntryNode) configDataNode).getIdentifier());
        mapValueToBuilder(((UnkeyedListEntryNode) configDataNode).body(), ((UnkeyedListEntryNode) stateDataNode).body(), builder);
        return builder.build();
    } else {
        throw new RestconfDocumentedException("Unexpected node type: " + configDataNode.getClass().getName());
    }
}
Also used : AugmentationIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier) SystemLeafSetNode(org.opendaylight.yangtools.yang.data.api.schema.SystemLeafSetNode) RestconfDocumentedException(org.opendaylight.restconf.common.errors.RestconfDocumentedException) UnkeyedListEntryNode(org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode) MapNode(org.opendaylight.yangtools.yang.data.api.schema.MapNode) SystemMapNode(org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode) UserMapNode(org.opendaylight.yangtools.yang.data.api.schema.UserMapNode) UserLeafSetNode(org.opendaylight.yangtools.yang.data.api.schema.UserLeafSetNode) ListNodeBuilder(org.opendaylight.yangtools.yang.data.api.schema.builder.ListNodeBuilder) LeafNode(org.opendaylight.yangtools.yang.data.api.schema.LeafNode) ChoiceNode(org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) UserMapNode(org.opendaylight.yangtools.yang.data.api.schema.UserMapNode) UnkeyedListNode(org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode) LeafSetEntryNode(org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) NodeIdentifierWithPredicates(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates) SystemLeafSetNode(org.opendaylight.yangtools.yang.data.api.schema.SystemLeafSetNode) LeafSetNode(org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode) UserLeafSetNode(org.opendaylight.yangtools.yang.data.api.schema.UserLeafSetNode) CollectionNodeBuilder(org.opendaylight.yangtools.yang.data.api.schema.builder.CollectionNodeBuilder) DataContainerNodeBuilder(org.opendaylight.yangtools.yang.data.api.schema.builder.DataContainerNodeBuilder) AugmentationNode(org.opendaylight.yangtools.yang.data.api.schema.AugmentationNode) NonNull(org.eclipse.jdt.annotation.NonNull)

Aggregations

DataContainerNodeBuilder (org.opendaylight.yangtools.yang.data.api.schema.builder.DataContainerNodeBuilder)3 HashMap (java.util.HashMap)2 WriteOperation (org.opendaylight.controller.cluster.datastore.TransactionModificationOperation.WriteOperation)2 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)2 DataContainerChild (org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild)2 ActorSelection (akka.actor.ActorSelection)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 Verify.verifyNotNull (com.google.common.base.Verify.verifyNotNull)1 Iterables (com.google.common.collect.Iterables)1 FluentFuture (com.google.common.util.concurrent.FluentFuture)1 Futures (com.google.common.util.concurrent.Futures)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 MoreExecutors (com.google.common.util.concurrent.MoreExecutors)1 SettableFuture (com.google.common.util.concurrent.SettableFuture)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 List (java.util.List)1 Map (java.util.Map)1