Migrate NodeIdentifierWithPredicates.getKeyValues() 29/83829/3
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 20 Aug 2019 19:17:57 +0000 (21:17 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 20 Aug 2019 22:59:18 +0000 (00:59 +0200)
Change-Id: Iea47db72483111eea40374c23d7be0da33f67728
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/AbstractNormalizedNodeDataOutput.java
opendaylight/md-sal/sal-common-impl/src/main/java/org/opendaylight/controller/md/sal/common/impl/util/compat/DataNormalizationOperation.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/entityownership/CandidateListChangeListener.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/entityownership/EntityOwnersModel.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/entityownership/EntityOwnershipShard.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/utils/ClusterUtils.java

index 447a588..161a450 100755 (executable)
@@ -15,7 +15,7 @@ import java.io.OutputStream;
 import java.io.StringWriter;
 import java.nio.charset.StandardCharsets;
 import java.util.Collection;
-import java.util.Map;
+import java.util.Map.Entry;
 import java.util.Set;
 import javax.xml.transform.TransformerException;
 import javax.xml.transform.TransformerFactory;
@@ -249,7 +249,7 @@ abstract class AbstractNormalizedNodeDataOutput implements NormalizedNodeDataOut
         LOG.trace("Starting a new map entry node");
         startNode(identifier.getNodeType(), NodeTypes.MAP_ENTRY_NODE);
 
-        writeKeyValueMap(identifier.getKeyValues());
+        writeKeyValueMap(identifier.entrySet());
     }
 
     @Override
@@ -395,7 +395,7 @@ abstract class AbstractNormalizedNodeDataOutput implements NormalizedNodeDataOut
                     (NodeIdentifierWithPredicates) pathArgument;
                 writeQName(nodeIdentifierWithPredicates.getNodeType());
 
-                writeKeyValueMap(nodeIdentifierWithPredicates.getKeyValues());
+                writeKeyValueMap(nodeIdentifierWithPredicates.entrySet());
                 break;
 
             case PathArgumentTypes.NODE_IDENTIFIER_WITH_VALUE :
@@ -417,11 +417,10 @@ abstract class AbstractNormalizedNodeDataOutput implements NormalizedNodeDataOut
         }
     }
 
-    private void writeKeyValueMap(final Map<QName, Object> keyValueMap) throws IOException {
-        if (keyValueMap != null && !keyValueMap.isEmpty()) {
-            output.writeInt(keyValueMap.size());
-
-            for (Map.Entry<QName, Object> entry : keyValueMap.entrySet()) {
+    private void writeKeyValueMap(final Set<Entry<QName, Object>> entrySet) throws IOException {
+        if (!entrySet.isEmpty()) {
+            output.writeInt(entrySet.size());
+            for (Entry<QName, Object> entry : entrySet) {
                 writeQName(entry.getKey());
                 writeObject(entry.getValue());
             }
index 84705e7..87e97d4 100644 (file)
@@ -82,7 +82,6 @@ public abstract class DataNormalizationOperation<T extends PathArgument> impleme
 
     public abstract DataNormalizationOperation<?> getChild(QName child) throws DataNormalizationException;
 
-
     public abstract boolean isLeaf();
 
     public Optional<DataSchemaNode> getDataSchemaNode() {
@@ -92,8 +91,7 @@ public abstract class DataNormalizationOperation<T extends PathArgument> impleme
 
     private abstract static class SimpleTypeNormalization<T extends PathArgument>
             extends DataNormalizationOperation<T> {
-
-        protected SimpleTypeNormalization(final T identifier, final DataSchemaNode potential) {
+        SimpleTypeNormalization(final T identifier, final DataSchemaNode potential) {
             super(identifier,potential);
         }
 
@@ -119,15 +117,12 @@ public abstract class DataNormalizationOperation<T extends PathArgument> impleme
     }
 
     private static final class LeafNormalization extends SimpleTypeNormalization<NodeIdentifier> {
-
-        protected LeafNormalization(final LeafSchemaNode potential) {
+        LeafNormalization(final LeafSchemaNode potential) {
             super(new NodeIdentifier(potential.getQName()),potential);
         }
-
     }
 
     private static final class LeafListEntryNormalization extends SimpleTypeNormalization<NodeWithValue> {
-
         LeafListEntryNormalization(final LeafListSchemaNode potential) {
             super(new NodeWithValue(potential.getQName(), null),potential);
         }
@@ -140,8 +135,7 @@ public abstract class DataNormalizationOperation<T extends PathArgument> impleme
 
     private abstract static class CompositeNodeNormalizationOperation<T extends PathArgument>
             extends DataNormalizationOperation<T> {
-
-        protected CompositeNodeNormalizationOperation(final T identifier, final DataSchemaNode schema) {
+        CompositeNodeNormalizationOperation(final T identifier, final DataSchemaNode schema) {
             super(identifier,schema);
         }
 
@@ -149,18 +143,15 @@ public abstract class DataNormalizationOperation<T extends PathArgument> impleme
         public boolean isLeaf() {
             return false;
         }
-
-
     }
 
     private abstract static class DataContainerNormalizationOperation<T extends PathArgument>
             extends CompositeNodeNormalizationOperation<T> {
-
         private final DataNodeContainer schema;
         private final Map<QName, DataNormalizationOperation<?>> byQName;
         private final Map<PathArgument, DataNormalizationOperation<?>> byArg;
 
-        protected DataContainerNormalizationOperation(final T identifier, final DataNodeContainer schema,
+        DataContainerNormalizationOperation(final T identifier, final DataNodeContainer schema,
                 final DataSchemaNode node) {
             super(identifier,node);
             this.schema = schema;
@@ -211,13 +202,11 @@ public abstract class DataNormalizationOperation<T extends PathArgument> impleme
             }
             return potential;
         }
-
     }
 
     private static final class ListItemNormalization extends
             DataContainerNormalizationOperation<NodeIdentifierWithPredicates> {
-
-        protected ListItemNormalization(final NodeIdentifierWithPredicates identifier, final ListSchemaNode schema) {
+        ListItemNormalization(final NodeIdentifierWithPredicates identifier, final ListSchemaNode schema) {
             super(identifier, schema, schema);
         }
 
@@ -226,8 +215,7 @@ public abstract class DataNormalizationOperation<T extends PathArgument> impleme
         public NormalizedNode<?, ?> createDefault(final PathArgument currentArg) {
             final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> builder = Builders
                     .mapEntryBuilder().withNodeIdentifier((NodeIdentifierWithPredicates) currentArg);
-            for (final Entry<QName, Object> keyValue :
-                    ((NodeIdentifierWithPredicates) currentArg).getKeyValues().entrySet()) {
+            for (final Entry<QName, Object> keyValue : ((NodeIdentifierWithPredicates) currentArg).entrySet()) {
                 builder.addChild(Builders.leafBuilder()
                         //
                         .withNodeIdentifier(new NodeIdentifier(keyValue.getKey())).withValue(keyValue.getValue())
@@ -236,7 +224,6 @@ public abstract class DataNormalizationOperation<T extends PathArgument> impleme
             return builder.build();
         }
 
-
         @Override
         public boolean isKeyedEntry() {
             return true;
@@ -245,8 +232,7 @@ public abstract class DataNormalizationOperation<T extends PathArgument> impleme
 
     private static final class UnkeyedListItemNormalization
             extends DataContainerNormalizationOperation<NodeIdentifier> {
-
-        protected UnkeyedListItemNormalization(final ListSchemaNode schema) {
+        UnkeyedListItemNormalization(final ListSchemaNode schema) {
             super(new NodeIdentifier(schema.getQName()), schema,schema);
         }
 
@@ -255,12 +241,10 @@ public abstract class DataNormalizationOperation<T extends PathArgument> impleme
         public NormalizedNode<?, ?> createDefault(final PathArgument currentArg) {
             return Builders.unkeyedListEntryBuilder().withNodeIdentifier((NodeIdentifier) currentArg).build();
         }
-
     }
 
     private static final class ContainerNormalization extends DataContainerNormalizationOperation<NodeIdentifier> {
-
-        protected ContainerNormalization(final ContainerSchemaNode schema) {
+        ContainerNormalization(final ContainerSchemaNode schema) {
             super(new NodeIdentifier(schema.getQName()),schema, schema);
         }
 
@@ -269,13 +253,12 @@ public abstract class DataNormalizationOperation<T extends PathArgument> impleme
         public NormalizedNode<?, ?> createDefault(final PathArgument currentArg) {
             return Builders.containerBuilder().withNodeIdentifier((NodeIdentifier) currentArg).build();
         }
-
     }
 
     private abstract static class MixinNormalizationOp<T extends PathArgument>
             extends CompositeNodeNormalizationOperation<T> {
 
-        protected MixinNormalizationOp(final T identifier, final DataSchemaNode schema) {
+        MixinNormalizationOp(final T identifier, final DataSchemaNode schema) {
             super(identifier,schema);
         }
 
@@ -283,10 +266,8 @@ public abstract class DataNormalizationOperation<T extends PathArgument> impleme
         public final boolean isMixin() {
             return true;
         }
-
     }
 
-
     private static final class OrderedLeafListMixinNormalization extends UnorderedLeafListMixinNormalization {
         OrderedLeafListMixinNormalization(final LeafListSchemaNode potential) {
             super(potential);
@@ -341,8 +322,6 @@ public abstract class DataNormalizationOperation<T extends PathArgument> impleme
             return true;
         }
 
-
-
         @Override
         protected DataNormalizationOperation<?> fromLocalSchemaAndQName(final DataNodeContainer schema,
                 final QName child) {
@@ -372,7 +351,6 @@ public abstract class DataNormalizationOperation<T extends PathArgument> impleme
     }
 
     private static class UnorderedMapMixinNormalization extends MixinNormalizationOp<NodeIdentifier> {
-
         private final ListItemNormalization innerNode;
 
         UnorderedMapMixinNormalization(final ListSchemaNode list) {
@@ -401,12 +379,9 @@ public abstract class DataNormalizationOperation<T extends PathArgument> impleme
             }
             return null;
         }
-
     }
 
-
     private static class UnkeyedListMixinNormalization extends MixinNormalizationOp<NodeIdentifier> {
-
         private final UnkeyedListItemNormalization innerNode;
 
         UnkeyedListMixinNormalization(final ListSchemaNode list) {
@@ -434,11 +409,9 @@ public abstract class DataNormalizationOperation<T extends PathArgument> impleme
             }
             return null;
         }
-
     }
 
     private static final class OrderedMapMixinNormalization extends UnorderedMapMixinNormalization {
-
         OrderedMapMixinNormalization(final ListSchemaNode list) {
             super(list);
         }
@@ -447,15 +420,13 @@ public abstract class DataNormalizationOperation<T extends PathArgument> impleme
         public NormalizedNode<?, ?> createDefault(final PathArgument currentArg) {
             return Builders.orderedMapBuilder().withNodeIdentifier(getIdentifier()).build();
         }
-
     }
 
     private static class ChoiceNodeNormalization extends MixinNormalizationOp<NodeIdentifier> {
-
         private final ImmutableMap<QName, DataNormalizationOperation<?>> byQName;
         private final ImmutableMap<PathArgument, DataNormalizationOperation<?>> byArg;
 
-        protected ChoiceNodeNormalization(final ChoiceSchemaNode schema) {
+        ChoiceNodeNormalization(final ChoiceSchemaNode schema) {
             super(new NodeIdentifier(schema.getQName()),schema);
             final ImmutableMap.Builder<QName, DataNormalizationOperation<?>> byQNameBuilder = ImmutableMap.builder();
             final ImmutableMap.Builder<PathArgument, DataNormalizationOperation<?>> byArgBuilder =
@@ -491,8 +462,7 @@ public abstract class DataNormalizationOperation<T extends PathArgument> impleme
     }
 
     private static class AnyXmlNormalization extends DataNormalizationOperation<NodeIdentifier> {
-
-        protected AnyXmlNormalization(final AnyXmlSchemaNode schema) {
+        AnyXmlNormalization(final AnyXmlSchemaNode schema) {
             super(new NodeIdentifier(schema.getQName()), schema);
         }
 
index 35ef06b..f96d155 100644 (file)
@@ -21,7 +21,6 @@ import java.util.HashMap;
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
-import java.util.Map.Entry;
 import java.util.Optional;
 import org.opendaylight.controller.cluster.datastore.ShardDataTree;
 import org.opendaylight.controller.cluster.datastore.entityownership.messages.CandidateAdded;
@@ -29,7 +28,6 @@ import org.opendaylight.controller.cluster.datastore.entityownership.messages.Ca
 import org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.clustering.entity.owners.rev150804.entity.owners.EntityType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.clustering.entity.owners.rev150804.entity.owners.entity.type.entity.Candidate;
-import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
@@ -73,7 +71,7 @@ class CandidateListChangeListener implements DOMDataTreeChangeListener {
 
             NodeIdentifierWithPredicates candidateKey =
                     (NodeIdentifierWithPredicates) change.getRootPath().getLastPathArgument();
-            String candidate = candidateKey.getKeyValues().get(CANDIDATE_NAME_QNAME).toString();
+            String candidate = candidateKey.getValue(CANDIDATE_NAME_QNAME).toString();
 
             YangInstanceIdentifier entityId = extractEntityPath(change.getRootPath());
 
@@ -114,12 +112,9 @@ class CandidateListChangeListener implements DOMDataTreeChangeListener {
         List<PathArgument> newPathArgs = new ArrayList<>();
         for (PathArgument pathArg: candidatePath.getPathArguments()) {
             newPathArgs.add(pathArg);
-            if (pathArg instanceof NodeIdentifierWithPredicates) {
-                NodeIdentifierWithPredicates nodeKey = (NodeIdentifierWithPredicates) pathArg;
-                Entry<QName, Object> key = nodeKey.getKeyValues().entrySet().iterator().next();
-                if (ENTITY_ID_QNAME.equals(key.getKey())) {
-                    break;
-                }
+            if (pathArg instanceof NodeIdentifierWithPredicates
+                    && ENTITY_ID_QNAME.equals(((NodeIdentifierWithPredicates) pathArg).keySet().iterator().next())) {
+                break;
             }
         }
 
index b69c9b3..a32c8b5 100644 (file)
@@ -34,21 +34,20 @@ import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableOr
  */
 public final class EntityOwnersModel {
     static final QName ENTITY_QNAME = Entity.QNAME;
-    static final QName CANDIDATE_NAME_QNAME = QName.create(Candidate.QNAME, "name");
-    static final QName ENTITY_ID_QNAME = QName.create(ENTITY_QNAME, "id");
-    static final QName ENTITY_OWNER_QNAME = QName.create(ENTITY_QNAME, "owner");
-    static final QName ENTITY_TYPE_QNAME = QName.create(EntityType.QNAME, "type");
-
-    static final NodeIdentifier ENTITY_OWNERS_NODE_ID = new NodeIdentifier(EntityOwners.QNAME);
-    static final NodeIdentifier ENTITY_OWNER_NODE_ID = new NodeIdentifier(ENTITY_OWNER_QNAME);
-    static final NodeIdentifier ENTITY_NODE_ID = new NodeIdentifier(ENTITY_QNAME);
-    static final NodeIdentifier ENTITY_ID_NODE_ID = new NodeIdentifier(ENTITY_ID_QNAME);
-    static final NodeIdentifier ENTITY_TYPE_NODE_ID = new NodeIdentifier(ENTITY_TYPE_QNAME);
-    static final NodeIdentifier CANDIDATE_NODE_ID = new NodeIdentifier(Candidate.QNAME);
-    static final NodeIdentifier CANDIDATE_NAME_NODE_ID = new NodeIdentifier(CANDIDATE_NAME_QNAME);
-    static final YangInstanceIdentifier ENTITY_OWNERS_PATH = YangInstanceIdentifier.of(EntityOwners.QNAME);
-    static final YangInstanceIdentifier ENTITY_TYPES_PATH =
-            YangInstanceIdentifier.of(EntityOwners.QNAME).node(EntityType.QNAME);
+    static final QName CANDIDATE_NAME_QNAME = QName.create(Candidate.QNAME, "name").intern();
+    static final QName ENTITY_ID_QNAME = QName.create(ENTITY_QNAME, "id").intern();
+    static final QName ENTITY_OWNER_QNAME = QName.create(ENTITY_QNAME, "owner").intern();
+    static final QName ENTITY_TYPE_QNAME = QName.create(EntityType.QNAME, "type").intern();
+
+    static final NodeIdentifier ENTITY_OWNERS_NODE_ID = NodeIdentifier.create(EntityOwners.QNAME);
+    static final NodeIdentifier ENTITY_OWNER_NODE_ID = NodeIdentifier.create(ENTITY_OWNER_QNAME);
+    static final NodeIdentifier ENTITY_NODE_ID = NodeIdentifier.create(ENTITY_QNAME);
+    static final NodeIdentifier ENTITY_ID_NODE_ID = NodeIdentifier.create(ENTITY_ID_QNAME);
+    static final NodeIdentifier ENTITY_TYPE_NODE_ID = NodeIdentifier.create(ENTITY_TYPE_QNAME);
+    static final NodeIdentifier CANDIDATE_NODE_ID = NodeIdentifier.create(Candidate.QNAME);
+    static final NodeIdentifier CANDIDATE_NAME_NODE_ID = NodeIdentifier.create(CANDIDATE_NAME_QNAME);
+    static final YangInstanceIdentifier ENTITY_OWNERS_PATH = YangInstanceIdentifier.create(ENTITY_OWNERS_NODE_ID);
+    static final YangInstanceIdentifier ENTITY_TYPES_PATH = ENTITY_OWNERS_PATH.node(EntityType.QNAME).toOptimized();
 
     private static final SharedSingletonMapTemplate<QName> NODE_KEY_TEMPLATE = SharedSingletonMapTemplate.ordered(
         CANDIDATE_NAME_QNAME);
@@ -125,7 +124,7 @@ public final class EntityOwnersModel {
             if (EntityType.QNAME.equals(parent.getLastPathArgument().getNodeType())) {
                 YangInstanceIdentifier.NodeIdentifierWithPredicates entityTypeLastPathArgument =
                         (YangInstanceIdentifier.NodeIdentifierWithPredicates) parent.getLastPathArgument();
-                return (String) entityTypeLastPathArgument.getKeyValues().get(ENTITY_TYPE_QNAME);
+                return (String) entityTypeLastPathArgument.getValue(ENTITY_TYPE_QNAME);
             }
             parent = parent.getParent();
         }
@@ -138,7 +137,7 @@ public final class EntityOwnersModel {
         for (PathArgument pathArg: entityPath.getPathArguments()) {
             if (pathArg instanceof NodeIdentifierWithPredicates) {
                 NodeIdentifierWithPredicates nodeKey = (NodeIdentifierWithPredicates) pathArg;
-                Entry<QName, Object> key = nodeKey.getKeyValues().entrySet().iterator().next();
+                Entry<QName, Object> key = nodeKey.entrySet().iterator().next();
                 if (ENTITY_TYPE_QNAME.equals(key.getKey())) {
                     entityType = key.getValue().toString();
                 } else if (ENTITY_ID_QNAME.equals(key.getKey())) {
index 4fbd951..6e1d1a8 100644 (file)
@@ -571,11 +571,10 @@ class EntityOwnershipShard extends Shard {
         final List<Modification> modifications = new ArrayList<>();
         searchForEntities((entityTypeNode, entityNode) -> {
             if (hasCandidate(entityNode, member)) {
-                YangInstanceIdentifier entityId =
-                        (YangInstanceIdentifier) entityNode.getIdentifier().getKeyValues().get(ENTITY_ID_QNAME);
-                YangInstanceIdentifier candidatePath = candidatePath(
-                        entityTypeNode.getIdentifier().getKeyValues().get(ENTITY_TYPE_QNAME).toString(),
-                        entityId, member.getName());
+                YangInstanceIdentifier entityId = (YangInstanceIdentifier) entityNode.getIdentifier()
+                        .getValue(ENTITY_ID_QNAME);
+                YangInstanceIdentifier candidatePath = candidatePath(entityTypeNode.getIdentifier()
+                    .getValue(ENTITY_TYPE_QNAME).toString(), entityId, member.getName());
 
                 LOG.info("{}: Found entity {}, removing candidate {}, path {}", persistenceId(), entityId,
                         member, candidatePath);
index dea8320..927dca4 100644 (file)
@@ -5,7 +5,6 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.controller.cluster.datastore.utils;
 
 import org.opendaylight.controller.cluster.access.concepts.MemberName;
@@ -82,14 +81,12 @@ public final class ClusterUtils {
             builder.append(p.getNodeType().getLocalName());
             if (p instanceof NodeIdentifierWithPredicates) {
                 builder.append("-key_");
-                ((NodeIdentifierWithPredicates) p).getKeyValues().forEach((key, value) -> {
-                    builder.append(key.getLocalName());
-                    builder.append(value);
-                    builder.append("-");
+                ((NodeIdentifierWithPredicates) p).entrySet().forEach(entry -> {
+                    builder.append(entry.getKey().getLocalName()).append(entry.getValue()).append('-');
                 });
-                builder.append("_");
+                builder.append('_');
             }
-            builder.append("!");
+            builder.append('!');
         });
         return builder.toString();
     }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.