Bug 2003: CDS serialization improvements 11/11411/4
authortpantelis <tpanteli@brocade.com>
Thu, 18 Sep 2014 21:35:53 +0000 (17:35 -0400)
committertpantelis <tpanteli@brocade.com>
Fri, 19 Sep 2014 16:47:43 +0000 (12:47 -0400)
In NormalizedNodeToNodeCodec#encode, significant time was spent
serializing the YangInstanceIdentifier path via PathUtils even though it
wasn't actually needed - the decode method didn't decode it.

This might have been used by WriteModification and MergeModification
originally however they currently serialized/deserialize their
YangInstanceIdentifier path separately from the NormalizedNode via
InstanceIdentifierUtils. It turns out this takes significant time as
well as it's implemented similarly as PathUtils.

So I ended up using NormalizedNodeToNodeCodec to encode/decode the
YangInstanceIdentifier along with the NormalizedNode but changed
InstanceIdentifierUtils to utilize the new PathArgumentSerializer
and the NormalizedNodeSerializer's special QName encoding.

With serializing a 5K batch of WriteModifications with flow data, the
time went down from ~350 ms to ~150 ms. Deserialization was also
improved.

Other smaller optimizations in NormalizedNodeSerializer,
NormalizedNodeType, PathArgumentSerializer and PathArgumentType chopped
another 20-30 ms off the time.

I also changed InstanceIdentifierUtils to serialize/deserialize via the
new PathArgumentSerializer and the NormalizedNodeSerializer's special QName
encoding by default, even when the ID isn't encoded as part of a
NormalizeNode. This seems reasonable to me as a standalone IID will
likely have repeated namespaces and revisions plus we get savings by not
serializing each path arg class name.

Removed the deprecated InstanceIdentifierUtils class in
sal-distributed-datastore bundle.

Change-Id: Iaa29daeaececf4b93065f4d46d0c2796c4d8188f
Signed-off-by: tpantelis <tpanteli@brocade.com>
40 files changed:
opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/NormalizedNodeToNodeCodec.java
opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/PathUtils.java
opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/serialization/NormalizedNodeSerializationContext.java
opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/serialization/NormalizedNodeSerializer.java
opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/serialization/NormalizedNodeType.java
opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/serialization/PathArgumentSerializer.java
opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/serialization/PathArgumentType.java
opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/serialization/QNameDeSerializationContext.java [new file with mode: 0644]
opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/serialization/QNameDeSerializationContextImpl.java [new file with mode: 0644]
opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/serialization/QNameSerializationContext.java [new file with mode: 0644]
opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/serialization/QNameSerializationContextImpl.java [new file with mode: 0644]
opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/serialization/ValueSerializer.java
opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/util/InstanceIdentifierUtils.java
opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/protobuff/messages/common/NormalizedNodeMessages.java
opendaylight/md-sal/sal-clustering-commons/src/main/resources/Common.proto
opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/datastore/node/NormalizedNodeToNodeCodecTest.java
opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/datastore/node/utils/PathUtilsTest.java
opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/datastore/node/utils/serialization/PathArgumentSerializerTest.java
opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/datastore/node/utils/serialization/ValueSerializerTest.java
opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/datastore/util/InstanceIdentifierUtilsTest.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/Shard.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardRecoveryCoordinator.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/DataChanged.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/DeleteData.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/MergeData.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/ReadData.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/ReadDataReply.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/RegisterChangeListener.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/WriteData.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/modification/AbstractModification.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/modification/DeleteModification.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/modification/MergeModification.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/modification/WriteModification.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/utils/InstanceIdentifierUtils.java [deleted file]
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/messages/MergeDataTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/messages/WriteDataTest.java [new file with mode: 0644]
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/modification/MergeModificationTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/modification/WriteModificationTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/md/cluster/datastore/model/SampleModelsTest.java

index 4e76e37..6669e48 100644 (file)
 
 package org.opendaylight.controller.cluster.datastore.node;
 
-import org.opendaylight.controller.cluster.datastore.node.utils.PathUtils;
 import org.opendaylight.controller.cluster.datastore.node.utils.serialization.NormalizedNodeSerializer;
+import org.opendaylight.controller.cluster.datastore.node.utils.serialization.NormalizedNodeSerializer.DeSerializer;
+import org.opendaylight.controller.cluster.datastore.node.utils.serialization.NormalizedNodeSerializer.Serializer;
 import org.opendaylight.controller.protobuff.messages.common.NormalizedNodeMessages;
+import org.opendaylight.controller.protobuff.messages.common.NormalizedNodeMessages.Container;
+import org.opendaylight.controller.protobuff.messages.common.NormalizedNodeMessages.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 public class NormalizedNodeToNodeCodec {
+    public interface Encoded {
+        NormalizedNodeMessages.Container getEncodedNode();
+
+        NormalizedNodeMessages.InstanceIdentifier getEncodedPath();
+    }
+
+    public interface Decoded {
+        NormalizedNode<?,?> getDecodedNode();
+
+        YangInstanceIdentifier getDecodedPath();
+    }
+
     private final SchemaContext ctx;
-    private static final Logger logger = LoggerFactory.getLogger(NormalizedNodeToNodeCodec.class);
 
     public NormalizedNodeToNodeCodec(final SchemaContext ctx){
         this.ctx = ctx;
+    }
 
+    public NormalizedNodeMessages.Container encode(NormalizedNode<?,?> node){
+        return encode(null, node).getEncodedNode();
     }
 
-    public NormalizedNodeMessages.Container encode(YangInstanceIdentifier id, NormalizedNode node){
+    public Encoded encode(YangInstanceIdentifier path, NormalizedNode<?,?> node) {
+
+        NormalizedNodeMessages.InstanceIdentifier serializedPath = null;
 
         NormalizedNodeMessages.Container.Builder builder = NormalizedNodeMessages.Container.newBuilder();
-        String parentPath = "";
 
-        if(id != null){
-            parentPath = PathUtils.getParentPath(PathUtils.toString(id));
-        }
+        // Note: parent path is no longer used
+        builder.setParentPath("");
 
-        builder.setParentPath(parentPath);
         if(node != null) {
-            builder.setNormalizedNode(NormalizedNodeSerializer.serialize(node));
+            if(path == null) {
+                builder.setNormalizedNode(NormalizedNodeSerializer.serialize(node));
+            } else {
+                Serializer serializer = NormalizedNodeSerializer.newSerializer(node);
+                builder.setNormalizedNode(serializer.serialize(path));
+                serializedPath = serializer.getSerializedPath();
+            }
         }
 
-        return builder.build();
+        return new EncodedImpl(builder.build(), serializedPath);
+    }
+
+
+    public NormalizedNode<?,?> decode(NormalizedNodeMessages.Node node){
+        return decode(null, node).getDecodedNode();
     }
 
-    public NormalizedNode<?,?> decode(YangInstanceIdentifier id, NormalizedNodeMessages.Node node){
+    public Decoded decode(NormalizedNodeMessages.InstanceIdentifier path,
+            NormalizedNodeMessages.Node node) {
         if(node.getIntType() < 0 || node.getSerializedSize() == 0){
-            return null;
+            return new DecodedImpl(null, null);
         }
-        return NormalizedNodeSerializer.deSerialize(node);
+
+        DeSerializer deSerializer = NormalizedNodeSerializer.newDeSerializer(path, node);
+        NormalizedNode<?,?> decodedNode = deSerializer.deSerialize();
+        return new DecodedImpl(decodedNode, deSerializer.getDeserializedPath());
     }
 
+    private static class DecodedImpl implements Decoded {
+
+        private final NormalizedNode<?, ?> decodedNode;
+        private final YangInstanceIdentifier decodedPath;
 
+        public DecodedImpl(NormalizedNode<?, ?> decodedNode, YangInstanceIdentifier decodedPath) {
+            this.decodedNode = decodedNode;
+            this.decodedPath = decodedPath;
+        }
+
+        @Override
+        public NormalizedNode<?, ?> getDecodedNode() {
+            return decodedNode;
+        }
+
+        @Override
+        public YangInstanceIdentifier getDecodedPath() {
+            return decodedPath;
+        }
+    }
+
+    private static class EncodedImpl implements Encoded {
+
+        private final Container encodedNode;
+        private final InstanceIdentifier encodedPath;
+
+        EncodedImpl(Container encodedNode, InstanceIdentifier encodedPath) {
+            this.encodedNode = encodedNode;
+            this.encodedPath = encodedPath;
+        }
+
+        @Override
+        public Container getEncodedNode() {
+            return encodedNode;
+        }
+
+        @Override
+        public InstanceIdentifier getEncodedPath() {
+            return encodedPath;
+        }
+    }
 }
index 25b65f0..6cdddfd 100644 (file)
@@ -20,23 +20,6 @@ import java.util.Set;
 
 public class PathUtils {
 
-    public static String getParentPath(String currentElementPath){
-        StringBuilder parentPath = new StringBuilder();
-
-        if(currentElementPath != null){
-            String[] parentPaths = currentElementPath.split("/");
-            if(parentPaths.length > 2){
-                for(int i=0;i<parentPaths.length-1;i++){
-                    if(parentPaths[i].length() > 0){
-                        parentPath.append("/");
-                        parentPath.append(parentPaths[i]);
-                    }
-                }
-            }
-        }
-        return parentPath.toString();
-    }
-
     /**
      * Given a YangInstanceIdentifier return a serialized version of the same
      * as a String
index 660bc28..1920702 100644 (file)
@@ -8,15 +8,9 @@
 
 package org.opendaylight.controller.cluster.datastore.node.utils.serialization;
 
-import java.net.URI;
-import java.util.Date;
-
 /**
  * NormalizedNodeSerializationContext provides methods which help in encoding
  * certain components of a NormalizedNode properly
  */
 public interface NormalizedNodeSerializationContext {
-    int addNamespace(URI namespace);
-    int addRevision(Date revision);
-    int addLocalName(String localName);
 }
index 44da4a5..15d51e1 100644 (file)
@@ -9,9 +9,9 @@
 package org.opendaylight.controller.cluster.datastore.node.utils.serialization;
 
 import com.google.common.base.Preconditions;
-
+import org.opendaylight.controller.cluster.datastore.util.InstanceIdentifierUtils;
 import org.opendaylight.controller.protobuff.messages.common.NormalizedNodeMessages;
-import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
+import org.opendaylight.controller.protobuff.messages.common.NormalizedNodeMessages.Node.Builder;
 import org.opendaylight.yangtools.yang.data.api.Node;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.AnyXmlNode;
@@ -33,15 +33,8 @@ import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContaine
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.ListNodeBuilder;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeAttrBuilder;
-
-import java.net.URI;
-import java.util.ArrayList;
-import java.util.Date;
 import java.util.EnumMap;
-import java.util.HashMap;
-import java.util.List;
 import java.util.Map;
-
 import static org.opendaylight.controller.cluster.datastore.node.utils.serialization.NormalizedNodeType.ANY_XML_NODE_TYPE;
 import static org.opendaylight.controller.cluster.datastore.node.utils.serialization.NormalizedNodeType.AUGMENTATION_NODE_TYPE;
 import static org.opendaylight.controller.cluster.datastore.node.utils.serialization.NormalizedNodeType.CHOICE_NODE_TYPE;
@@ -93,6 +86,10 @@ public class NormalizedNodeSerializer {
         return new Serializer(node).serialize();
     }
 
+    public static Serializer newSerializer(NormalizedNode node) {
+        Preconditions.checkNotNull(node, "node should not be null");
+        return new Serializer(node);
+    }
 
     /**
      * DeSerialize a protocol buffer message back into a NormalizedNode
@@ -100,8 +97,15 @@ public class NormalizedNodeSerializer {
      * @param node
      * @return
      */
-    public static NormalizedNode deSerialize(NormalizedNodeMessages.Node node){
-        return new DeSerializer(node).deSerialize();
+    public static NormalizedNode deSerialize(NormalizedNodeMessages.Node node) {
+        Preconditions.checkNotNull(node, "node should not be null");
+        return new DeSerializer(null, node).deSerialize();
+    }
+
+    public static DeSerializer newDeSerializer(NormalizedNodeMessages.InstanceIdentifier path,
+            NormalizedNodeMessages.Node node) {
+        Preconditions.checkNotNull(node, "node should not be null");
+        return new DeSerializer(path, node);
     }
 
     /**
@@ -117,25 +121,36 @@ public class NormalizedNodeSerializer {
      * @param pathArgument
      * @return
      */
-    public static YangInstanceIdentifier.PathArgument deSerialize(NormalizedNodeMessages.Node node, NormalizedNodeMessages.PathArgument pathArgument){
+    public static YangInstanceIdentifier.PathArgument deSerialize(NormalizedNodeMessages.Node node,
+            NormalizedNodeMessages.PathArgument pathArgument){
         Preconditions.checkNotNull(node, "node should not be null");
         Preconditions.checkNotNull(pathArgument, "pathArgument should not be null");
-        return new DeSerializer(node).deSerialize(pathArgument);
+        return new DeSerializer(null, node).deSerialize(pathArgument);
     }
 
-    private static class Serializer implements NormalizedNodeSerializationContext {
+    public static class Serializer extends QNameSerializationContextImpl
+                                   implements NormalizedNodeSerializationContext {
 
         private final NormalizedNode node;
 
-        private final Map<Object, Integer> codeMap = new HashMap<>();
-        private final List<String> codes = new ArrayList<>();
+        private NormalizedNodeMessages.InstanceIdentifier serializedPath;
 
         private Serializer(NormalizedNode node) {
             this.node = node;
         }
 
-        private NormalizedNodeMessages.Node serialize() {
-            return this.serialize(node).addAllCode(codes).build();
+        public NormalizedNodeMessages.InstanceIdentifier getSerializedPath() {
+            return serializedPath;
+        }
+
+        public NormalizedNodeMessages.Node serialize() {
+            return this.serialize(node).addAllCode(getCodes()).build();
+        }
+
+        public NormalizedNodeMessages.Node serialize(YangInstanceIdentifier path) {
+            Builder builder = serialize(node);
+            serializedPath = InstanceIdentifierUtils.toSerializable(path, this);
+            return builder.addAllCode(getCodes()).build();
         }
 
         private NormalizedNodeMessages.Node.Builder serialize(
@@ -183,56 +198,10 @@ public class NormalizedNodeSerializer {
 
             return builder;
         }
-
-
-        @Override public int addNamespace(URI namespace) {
-            int namespaceInt = getCode(namespace);
-
-            if(namespaceInt == -1) {
-                namespaceInt = addCode(namespace, namespace.toString());
-            }
-            return namespaceInt;
-        }
-
-        @Override public int addRevision(Date revision) {
-            if(revision == null){
-                return -1;
-            }
-
-            int revisionInt = getCode(revision);
-            if(revisionInt == -1) {
-                String formattedRevision =
-                    SimpleDateFormatUtil.getRevisionFormat().format(revision);
-                revisionInt = addCode(revision, formattedRevision);
-            }
-            return revisionInt;
-        }
-
-        @Override public int addLocalName(String localName) {
-            int localNameInt = getCode(localName);
-            if(localNameInt == -1) {
-                localNameInt = addCode(localName, localName.toString());
-            }
-            return localNameInt;
-
-        }
-
-        public int addCode(Object code, String codeStr){
-            int count = codes.size();
-            codes.add(codeStr);
-            codeMap.put(code, Integer.valueOf(count));
-            return count;
-        }
-
-        public int getCode(Object code){
-            if(codeMap.containsKey(code)){
-                return codeMap.get(code);
-            }
-            return -1;
-        }
     }
 
-    private static class DeSerializer implements NormalizedNodeDeSerializationContext {
+    public static class DeSerializer extends QNameDeSerializationContextImpl
+                                     implements NormalizedNodeDeSerializationContext {
         private static Map<NormalizedNodeType, DeSerializationFunction>
             deSerializationFunctions = new EnumMap<>(NormalizedNodeType.class);
 
@@ -438,13 +407,27 @@ public class NormalizedNodeSerializer {
         }
 
         private final NormalizedNodeMessages.Node node;
+        private final NormalizedNodeMessages.InstanceIdentifier path;
+        private YangInstanceIdentifier deserializedPath;
 
-        public DeSerializer(NormalizedNodeMessages.Node node){
+        public DeSerializer(NormalizedNodeMessages.InstanceIdentifier path,
+                NormalizedNodeMessages.Node node) {
+            super(node.getCodeList());
+            this.path = path;
             this.node = node;
         }
 
-        public NormalizedNode deSerialize(){
-            return deSerialize(node);
+        public YangInstanceIdentifier getDeserializedPath() {
+            return deserializedPath;
+        }
+
+        public NormalizedNode deSerialize() {
+            NormalizedNode deserializedNode = deSerialize(node);
+            if(path != null) {
+                deserializedPath = InstanceIdentifierUtils.fromSerializable(path, this);
+            }
+
+            return deserializedNode;
         }
 
         private NormalizedNode deSerialize(NormalizedNodeMessages.Node node){
@@ -526,18 +509,6 @@ public class NormalizedNodeSerializer {
                 this, path);
         }
 
-        @Override public String getNamespace(int namespace) {
-            return node.getCode(namespace);
-        }
-
-        @Override public String getRevision(int revision) {
-            return node.getCode(revision);
-        }
-
-        @Override public String getLocalName(int localName) {
-            return node.getCode(localName);
-        }
-
         public YangInstanceIdentifier.PathArgument deSerialize(
             NormalizedNodeMessages.PathArgument pathArgument) {
             return PathArgumentSerializer.deSerialize(this, pathArgument);
index eebd580..2d6d738 100644 (file)
@@ -42,20 +42,20 @@ public enum NormalizedNodeType {
     public static NormalizedNodeType getSerializableNodeType(NormalizedNode node){
         Preconditions.checkNotNull(node, "node should not be null");
 
-        if(node instanceof ContainerNode){
-            return CONTAINER_NODE_TYPE;
-        } else if(node instanceof LeafNode){
+        if(node instanceof LeafNode){
             return LEAF_NODE_TYPE;
-        } else if(node instanceof MapNode){
-            return MAP_NODE_TYPE;
+        } else if(node instanceof LeafSetEntryNode){
+            return LEAF_SET_ENTRY_NODE_TYPE;
         } else if(node instanceof MapEntryNode){
             return MAP_ENTRY_NODE_TYPE;
+        } else if(node instanceof ContainerNode){
+            return CONTAINER_NODE_TYPE;
+        } else if(node instanceof MapNode){
+            return MAP_NODE_TYPE;
         } else if(node instanceof AugmentationNode){
             return AUGMENTATION_NODE_TYPE;
         } else if(node instanceof LeafSetNode){
             return LEAF_SET_NODE_TYPE;
-        } else if(node instanceof LeafSetEntryNode){
-            return LEAF_SET_ENTRY_NODE_TYPE;
         } else if(node instanceof ChoiceNode){
             return CHOICE_NODE_TYPE;
         } else if(node instanceof OrderedLeafSetNode){
@@ -69,6 +69,7 @@ public enum NormalizedNodeType {
         } else if(node instanceof AnyXmlNode){
             return ANY_XML_NODE_TYPE;
         }
+
         throw new IllegalArgumentException("Node type unknown : " + node.getClass().getSimpleName());
     }
 
index 4fb676e..bf10316 100644 (file)
@@ -9,28 +9,28 @@
 package org.opendaylight.controller.cluster.datastore.node.utils.serialization;
 
 import com.google.common.base.Preconditions;
-
 import org.opendaylight.controller.cluster.datastore.node.utils.NodeIdentifierFactory;
 import org.opendaylight.controller.cluster.datastore.node.utils.QNameFactory;
 import org.opendaylight.controller.protobuff.messages.common.NormalizedNodeMessages;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Map.Entry;
 import java.util.Set;
-
 import static org.opendaylight.controller.cluster.datastore.node.utils.serialization.PathArgumentType.getSerializablePathArgumentType;
 
 public class PathArgumentSerializer {
     private static final String REVISION_ARG = "?revision=";
-    private static final Map<Class, PathArgumentAttributesGetter> pathArgumentAttributesGetters = new HashMap<>();
+    private static final Map<Class<?>, PathArgumentAttributesGetter> pathArgumentAttributesGetters = new HashMap<>();
 
-    public static NormalizedNodeMessages.PathArgument serialize(NormalizedNodeSerializationContext context, YangInstanceIdentifier.PathArgument pathArgument){
+    public static NormalizedNodeMessages.PathArgument serialize(QNameSerializationContext context,
+            YangInstanceIdentifier.PathArgument pathArgument){
         Preconditions.checkNotNull(context, "context should not be null");
         Preconditions.checkNotNull(pathArgument, "pathArgument should not be null");
 
@@ -53,7 +53,8 @@ public class PathArgumentSerializer {
     }
 
 
-    public static YangInstanceIdentifier.PathArgument deSerialize(NormalizedNodeDeSerializationContext context, NormalizedNodeMessages.PathArgument pathArgument){
+    public static YangInstanceIdentifier.PathArgument deSerialize(QNameDeSerializationContext context,
+            NormalizedNodeMessages.PathArgument pathArgument){
         Preconditions.checkNotNull(context, "context should not be null");
         Preconditions.checkNotNull(pathArgument, "pathArgument should not be null");
 
@@ -62,18 +63,15 @@ public class PathArgumentSerializer {
 
 
     private static interface PathArgumentAttributesGetter {
-        Iterable<? extends NormalizedNodeMessages.PathArgumentAttribute> get(NormalizedNodeSerializationContext context,
-            YangInstanceIdentifier.PathArgument pathArgument);
+        Iterable<? extends NormalizedNodeMessages.PathArgumentAttribute> get(
+                QNameSerializationContext context, YangInstanceIdentifier.PathArgument pathArgument);
     }
 
     static {
         pathArgumentAttributesGetters.put(YangInstanceIdentifier.NodeWithValue.class, new PathArgumentAttributesGetter() {
             @Override
             public Iterable<? extends NormalizedNodeMessages.PathArgumentAttribute> get(
-                NormalizedNodeSerializationContext context,
-                YangInstanceIdentifier.PathArgument pathArgument) {
-                List<NormalizedNodeMessages.PathArgumentAttribute> attributes =
-                    new ArrayList<>();
+                    QNameSerializationContext context, YangInstanceIdentifier.PathArgument pathArgument) {
 
                 YangInstanceIdentifier.NodeWithValue identifier
                     = (YangInstanceIdentifier.NodeWithValue) pathArgument;
@@ -81,62 +79,52 @@ public class PathArgumentSerializer {
                 NormalizedNodeMessages.PathArgumentAttribute attribute =
                     buildAttribute(context, null, identifier.getValue());
 
-                attributes.add(attribute);
-
-                return attributes;
-
+                return Arrays.asList(attribute);
             }
         });
 
         pathArgumentAttributesGetters.put(YangInstanceIdentifier.NodeIdentifierWithPredicates.class, new PathArgumentAttributesGetter() {
             @Override
             public Iterable<? extends NormalizedNodeMessages.PathArgumentAttribute> get(
-                NormalizedNodeSerializationContext context,
-                YangInstanceIdentifier.PathArgument pathArgument) {
-
-                List<NormalizedNodeMessages.PathArgumentAttribute> attributes =
-                    new ArrayList<>();
+                    QNameSerializationContext context, YangInstanceIdentifier.PathArgument pathArgument) {
 
                 YangInstanceIdentifier.NodeIdentifierWithPredicates identifier
                     = (YangInstanceIdentifier.NodeIdentifierWithPredicates) pathArgument;
 
-                for (QName key : identifier.getKeyValues().keySet()) {
-                    Object value = identifier.getKeyValues().get(key);
+                Map<QName, Object> keyValues = identifier.getKeyValues();
+                List<NormalizedNodeMessages.PathArgumentAttribute> attributes =
+                        new ArrayList<>(keyValues.size());
+                for (Entry<QName, Object> e : keyValues.entrySet()) {
                     NormalizedNodeMessages.PathArgumentAttribute attribute =
-                        buildAttribute(context, key, value);
+                        buildAttribute(context, e.getKey(), e.getValue());
 
                     attributes.add(attribute);
-
                 }
 
                 return attributes;
-
             }
         });
 
         pathArgumentAttributesGetters.put(YangInstanceIdentifier.AugmentationIdentifier.class, new PathArgumentAttributesGetter() {
             @Override
             public Iterable<? extends NormalizedNodeMessages.PathArgumentAttribute> get(
-                NormalizedNodeSerializationContext context,
-                YangInstanceIdentifier.PathArgument pathArgument) {
-
-                List<NormalizedNodeMessages.PathArgumentAttribute> attributes =
-                    new ArrayList<>();
+                    QNameSerializationContext context, YangInstanceIdentifier.PathArgument pathArgument) {
 
                 YangInstanceIdentifier.AugmentationIdentifier identifier
                     = (YangInstanceIdentifier.AugmentationIdentifier) pathArgument;
 
-                for (QName key : identifier.getPossibleChildNames()) {
+                Set<QName> possibleChildNames = identifier.getPossibleChildNames();
+                List<NormalizedNodeMessages.PathArgumentAttribute> attributes =
+                        new ArrayList<>(possibleChildNames.size());
+                for (QName key : possibleChildNames) {
                     Object value = key;
                     NormalizedNodeMessages.PathArgumentAttribute attribute =
                         buildAttribute(context, key, value);
 
                     attributes.add(attribute);
-
                 }
 
                 return attributes;
-
             }
         });
 
@@ -144,14 +132,14 @@ public class PathArgumentSerializer {
         pathArgumentAttributesGetters.put(YangInstanceIdentifier.NodeIdentifier.class, new PathArgumentAttributesGetter() {
             @Override
             public Iterable<? extends NormalizedNodeMessages.PathArgumentAttribute> get(
-                NormalizedNodeSerializationContext context,
-                YangInstanceIdentifier.PathArgument pathArgument) {
+                    QNameSerializationContext context, YangInstanceIdentifier.PathArgument pathArgument) {
                 return Collections.emptyList();
             }
         });
     }
 
-    private static NormalizedNodeMessages.PathArgumentAttribute buildAttribute(NormalizedNodeSerializationContext context,QName name, Object value){
+    private static NormalizedNodeMessages.PathArgumentAttribute buildAttribute(
+            QNameSerializationContext context, QName name, Object value) {
         NormalizedNodeMessages.PathArgumentAttribute.Builder builder =
             NormalizedNodeMessages.PathArgumentAttribute.newBuilder();
 
@@ -162,8 +150,9 @@ public class PathArgumentSerializer {
 
     }
 
-    private static NormalizedNodeMessages.QName.Builder encodeQName(NormalizedNodeSerializationContext context, QName qName){
-        if(qName == null){
+    private static NormalizedNodeMessages.QName.Builder encodeQName(QNameSerializationContext context,
+            QName qName) {
+        if(qName == null) {
             return NormalizedNodeMessages.QName.getDefaultInstance().toBuilder();
         }
         NormalizedNodeMessages.QName.Builder qNameBuilder =
@@ -179,15 +168,13 @@ public class PathArgumentSerializer {
     }
 
     private static Iterable<? extends NormalizedNodeMessages.PathArgumentAttribute> getPathArgumentAttributes(
-            NormalizedNodeSerializationContext context,
-            YangInstanceIdentifier.PathArgument pathArgument) {
+            QNameSerializationContext context, YangInstanceIdentifier.PathArgument pathArgument) {
 
         return pathArgumentAttributesGetters.get(pathArgument.getClass()).get(context, pathArgument);
-
     }
 
 
-    private static String qNameToString(NormalizedNodeDeSerializationContext context,
+    private static String qNameToString(QNameDeSerializationContext context,
         NormalizedNodeMessages.QName qName){
         // If this serializer is used qName cannot be null (see encodeQName)
         // adding null check only in case someone tried to deSerialize a protocol buffer node
@@ -219,8 +206,7 @@ public class PathArgumentSerializer {
      * @return MD-SAL PathArgument
      */
     private static YangInstanceIdentifier.PathArgument parsePathArgument(
-        NormalizedNodeDeSerializationContext context,
-        NormalizedNodeMessages.PathArgument pathArgument) {
+            QNameDeSerializationContext context, NormalizedNodeMessages.PathArgument pathArgument) {
 
         switch(PathArgumentType.values()[pathArgument.getIntType()]){
             case NODE_IDENTIFIER_WITH_VALUE : {
@@ -264,8 +250,8 @@ public class PathArgumentSerializer {
     }
 
     private static Map<QName, Object> toAttributesMap(
-        NormalizedNodeDeSerializationContext context,
-        List<NormalizedNodeMessages.PathArgumentAttribute> attributesList) {
+            QNameDeSerializationContext context,
+            List<NormalizedNodeMessages.PathArgumentAttribute> attributesList) {
 
         Map<QName, Object> map;
         if(attributesList.size() == 1) {
@@ -287,7 +273,8 @@ public class PathArgumentSerializer {
         return map;
     }
 
-    private static Object parseAttribute(NormalizedNodeDeSerializationContext context, NormalizedNodeMessages.PathArgumentAttribute attribute){
+    private static Object parseAttribute(QNameDeSerializationContext context,
+            NormalizedNodeMessages.PathArgumentAttribute attribute){
         return ValueSerializer.deSerialize(context, attribute);
     }
 
index 20009d8..58a09ae 100644 (file)
@@ -8,8 +8,9 @@
 
 package org.opendaylight.controller.cluster.datastore.node.utils.serialization;
 
-import com.google.common.base.Preconditions;
+import java.util.Map;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import com.google.common.collect.ImmutableMap;
 
 public enum PathArgumentType {
     AUGMENTATION_IDENTIFIER,
@@ -17,19 +18,21 @@ public enum PathArgumentType {
     NODE_IDENTIFIER_WITH_VALUE,
     NODE_IDENTIFIER_WITH_PREDICATES;
 
+    private static Map<Class<?>, PathArgumentType> CLASS_TO_ENUM_MAP =
+            ImmutableMap.<Class<?>, PathArgumentType>builder().
+                put(YangInstanceIdentifier.AugmentationIdentifier.class, AUGMENTATION_IDENTIFIER).
+                put(YangInstanceIdentifier.NodeIdentifier.class, NODE_IDENTIFIER).
+                put(YangInstanceIdentifier.NodeIdentifierWithPredicates.class, NODE_IDENTIFIER_WITH_PREDICATES).
+                put(YangInstanceIdentifier.NodeWithValue.class, NODE_IDENTIFIER_WITH_VALUE).build();
+
     public static int getSerializablePathArgumentType(YangInstanceIdentifier.PathArgument pathArgument){
-        Preconditions.checkNotNull(pathArgument, "pathArgument should not be null");
-
-        if(pathArgument instanceof YangInstanceIdentifier.AugmentationIdentifier){
-            return AUGMENTATION_IDENTIFIER.ordinal();
-        } else if(pathArgument instanceof YangInstanceIdentifier.NodeIdentifier){
-            return NODE_IDENTIFIER.ordinal();
-        } else if(pathArgument instanceof YangInstanceIdentifier.NodeIdentifierWithPredicates){
-            return NODE_IDENTIFIER_WITH_PREDICATES.ordinal();
-        } else if(pathArgument instanceof YangInstanceIdentifier.NodeWithValue){
-            return NODE_IDENTIFIER_WITH_VALUE.ordinal();
+
+        PathArgumentType type = CLASS_TO_ENUM_MAP.get(pathArgument.getClass());
+        if(type == null) {
+            throw new IllegalArgumentException("Unknown type of PathArgument = " + pathArgument);
         }
-        throw new IllegalArgumentException("Unknown type of PathArgument = " + pathArgument.toString());
+
+        return type.ordinal();
     }
 
 }
diff --git a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/serialization/QNameDeSerializationContext.java b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/serialization/QNameDeSerializationContext.java
new file mode 100644 (file)
index 0000000..ca9ead7
--- /dev/null
@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 2014 Brocade Communications Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * 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.node.utils.serialization;
+
+/**
+ * Interface that provides methods which help in decoding components of a QName.
+ *
+ * @author Thomas Pantelis
+ */
+public interface QNameDeSerializationContext {
+    String getNamespace(int namespace);
+
+    String getRevision(int revision);
+
+    String getLocalName(int localName);
+}
diff --git a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/serialization/QNameDeSerializationContextImpl.java b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/serialization/QNameDeSerializationContextImpl.java
new file mode 100644 (file)
index 0000000..ac3d362
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2014 Brocade Communications Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * 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.node.utils.serialization;
+
+import java.util.List;
+
+/**
+ * Implementation of the QNameDeSerializationContext interface.
+ *
+ * @author Thomas Pantelis
+ */
+public class QNameDeSerializationContextImpl implements QNameDeSerializationContext {
+
+    private final List<String> codeList;
+
+    public QNameDeSerializationContextImpl(List<String> codeList) {
+        this.codeList = codeList;
+    }
+
+    @Override
+    public String getNamespace(int namespace) {
+        return codeList.get(namespace);
+    }
+
+    @Override
+    public String getRevision(int revision) {
+        return codeList.get(revision);
+    }
+
+    @Override
+    public String getLocalName(int localName) {
+        return codeList.get(localName);
+    }
+}
diff --git a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/serialization/QNameSerializationContext.java b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/serialization/QNameSerializationContext.java
new file mode 100644 (file)
index 0000000..9096add
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2014 Brocade Communications Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * 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.node.utils.serialization;
+
+import java.net.URI;
+import java.util.Date;
+
+/**
+ * Interface that provides methods which help in encoding components of a QName.
+ *
+ * @author Thomas Pantelis
+ */
+public interface QNameSerializationContext {
+    int addNamespace(URI namespace);
+
+    int addRevision(Date revision);
+
+    int addLocalName(String localName);
+
+}
diff --git a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/serialization/QNameSerializationContextImpl.java b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/serialization/QNameSerializationContextImpl.java
new file mode 100644 (file)
index 0000000..09fe2ef
--- /dev/null
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2014 Brocade Communications Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * 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.node.utils.serialization;
+
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
+
+/**
+ * Implementation of the QNameSerializationContext interface.
+ *
+ * @author Thomas Pantelis
+ */
+public class QNameSerializationContextImpl implements QNameSerializationContext {
+
+    private final Map<Object, Integer> codeMap = new HashMap<>();
+    private final List<String> codes = new ArrayList<>();
+
+    public List<String> getCodes() {
+        return codes;
+    }
+
+    @Override public int addNamespace(URI namespace) {
+        int namespaceInt = getCode(namespace);
+
+        if(namespaceInt == -1) {
+            namespaceInt = addCode(namespace, namespace.toString());
+        }
+        return namespaceInt;
+    }
+
+    @Override public int addRevision(Date revision) {
+        if(revision == null){
+            return -1;
+        }
+
+        int revisionInt = getCode(revision);
+        if(revisionInt == -1) {
+            String formattedRevision =
+                SimpleDateFormatUtil.getRevisionFormat().format(revision);
+            revisionInt = addCode(revision, formattedRevision);
+        }
+        return revisionInt;
+    }
+
+    @Override public int addLocalName(String localName) {
+        int localNameInt = getCode(localName);
+        if(localNameInt == -1) {
+            localNameInt = addCode(localName, localName);
+        }
+        return localNameInt;
+
+    }
+
+    private int addCode(Object code, String codeStr){
+        int count = codes.size();
+        codes.add(codeStr);
+        codeMap.put(code, Integer.valueOf(count));
+        return count;
+    }
+
+    private int getCode(Object code){
+        Integer value = codeMap.get(code);
+        return value == null ? -1 : value.intValue();
+    }
+}
index 8def754..6a843f5 100644 (file)
@@ -20,12 +20,12 @@ import java.util.Set;
 
 public class ValueSerializer {
     public static void serialize(NormalizedNodeMessages.Node.Builder builder,
-        NormalizedNodeSerializationContext context, Object value){
+            QNameSerializationContext context, Object value) {
         builder.setIntValueType(ValueType.getSerializableType(value).ordinal());
 
         if(value instanceof YangInstanceIdentifier) {
             builder.setInstanceIdentifierValue(
-                InstanceIdentifierUtils.toSerializable((YangInstanceIdentifier) value));
+                InstanceIdentifierUtils.toSerializable((YangInstanceIdentifier) value, context));
         } else if(value instanceof Set) {
             Set set = (Set) value;
             if(!set.isEmpty()){
@@ -44,26 +44,25 @@ public class ValueSerializer {
     }
 
     public static void serialize(NormalizedNodeMessages.PathArgumentAttribute.Builder builder,
-        NormalizedNodeSerializationContext context, Object value){
+            QNameSerializationContext context, Object value){
 
         builder.setType(ValueType.getSerializableType(value).ordinal());
         builder.setValue(value.toString());
     }
 
-    public static Object deSerialize(
-        NormalizedNodeDeSerializationContext context, NormalizedNodeMessages.Node node) {
+    public static Object deSerialize(QNameDeSerializationContext context,
+            NormalizedNodeMessages.Node node) {
         if(node.getIntValueType() == ValueType.YANG_IDENTIFIER_TYPE.ordinal()){
             return InstanceIdentifierUtils.fromSerializable(
-                node.getInstanceIdentifierValue());
+                    node.getInstanceIdentifierValue(), context);
         } else if(node.getIntValueType() == ValueType.BITS_TYPE.ordinal()){
             return new HashSet(node.getBitsValueList());
         }
         return deSerializeBasicTypes(node.getIntValueType(), node.getValue());
     }
 
-    public static Object deSerialize(
-        NormalizedNodeDeSerializationContext context,
-        NormalizedNodeMessages.PathArgumentAttribute attribute) {
+    public static Object deSerialize(QNameDeSerializationContext context,
+            NormalizedNodeMessages.PathArgumentAttribute attribute) {
         return deSerializeBasicTypes(attribute.getType(), attribute.getValue());
     }
 
index 0bb0d4f..64a1e3a 100644 (file)
@@ -12,12 +12,17 @@ package org.opendaylight.controller.cluster.datastore.util;
 
 import org.opendaylight.controller.cluster.datastore.node.utils.NodeIdentifierFactory;
 import org.opendaylight.controller.cluster.datastore.node.utils.QNameFactory;
+import org.opendaylight.controller.cluster.datastore.node.utils.serialization.PathArgumentSerializer;
+import org.opendaylight.controller.cluster.datastore.node.utils.serialization.QNameDeSerializationContext;
+import org.opendaylight.controller.cluster.datastore.node.utils.serialization.QNameDeSerializationContextImpl;
+import org.opendaylight.controller.cluster.datastore.node.utils.serialization.QNameSerializationContext;
+import org.opendaylight.controller.cluster.datastore.node.utils.serialization.QNameSerializationContextImpl;
 import org.opendaylight.controller.protobuff.messages.common.NormalizedNodeMessages;
+import org.opendaylight.controller.protobuff.messages.common.NormalizedNodeMessages.InstanceIdentifier.Builder;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -41,61 +46,54 @@ public class InstanceIdentifierUtils {
     protected static final Logger logger = LoggerFactory
         .getLogger(InstanceIdentifierUtils.class);
 
-    @Deprecated
-    public static YangInstanceIdentifier from(String path) {
-        String[] ids = path.split("/");
-
-        List<YangInstanceIdentifier.PathArgument> pathArguments =
-            new ArrayList<>();
-        for (String nodeId : ids) {
-            if (!"".equals(nodeId)) {
-                pathArguments
-                    .add(NodeIdentifierFactory.getArgument(nodeId));
-            }
-        }
-        final YangInstanceIdentifier instanceIdentifier =
-            YangInstanceIdentifier.create(pathArguments);
-        return instanceIdentifier;
-    }
-
-
     /**
      * Convert an MD-SAL YangInstanceIdentifier into a protocol buffer version of it
      *
      * @param path an MD-SAL YangInstanceIdentifier
      * @return a protocol buffer version of the MD-SAL YangInstanceIdentifier
      */
-    public static NormalizedNodeMessages.InstanceIdentifier toSerializable(YangInstanceIdentifier path){
+    public static NormalizedNodeMessages.InstanceIdentifier toSerializable(YangInstanceIdentifier path) {
+        QNameSerializationContextImpl context = new QNameSerializationContextImpl();
+        Builder builder = toSerializableBuilder(path, context);
+        return builder.addAllCode(context.getCodes()).build();
+    }
+
+    public static NormalizedNodeMessages.InstanceIdentifier toSerializable(
+            YangInstanceIdentifier path, QNameSerializationContext context) {
+        return toSerializableBuilder(path, context).build();
+    }
+
+    private static NormalizedNodeMessages.InstanceIdentifier.Builder toSerializableBuilder(
+            YangInstanceIdentifier path, QNameSerializationContext context) {
         NormalizedNodeMessages.InstanceIdentifier.Builder builder =
             NormalizedNodeMessages.InstanceIdentifier.newBuilder();
 
         try {
-
-            for (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument pathArgument : path
-                .getPathArguments()) {
-
-                String nodeType = "";
-                if(!(pathArgument instanceof YangInstanceIdentifier.AugmentationIdentifier)){
-                    nodeType = pathArgument.getNodeType().toString();
+            for (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.
+                                            PathArgument pathArgument : path.getPathArguments()) {
+                NormalizedNodeMessages.PathArgument serializablePathArgument;
+                if(context == null) {
+                    String nodeType = "";
+                    if(!(pathArgument instanceof YangInstanceIdentifier.AugmentationIdentifier)){
+                        nodeType = pathArgument.getNodeType().toString();
+                    }
+
+                    serializablePathArgument = NormalizedNodeMessages.PathArgument.newBuilder()
+                            .setValue(pathArgument.toString())
+                            .setType(pathArgument.getClass().getSimpleName())
+                            .setNodeType(NormalizedNodeMessages.QName.newBuilder().setValue(nodeType))
+                            .addAllAttributes(getPathArgumentAttributes(pathArgument)).build();
+                } else {
+                    serializablePathArgument = PathArgumentSerializer.serialize(context, pathArgument);
                 }
 
-                NormalizedNodeMessages.PathArgument serializablePathArgument =
-                    NormalizedNodeMessages.PathArgument.newBuilder()
-                        .setValue(pathArgument.toString())
-                        .setType(pathArgument.getClass().getSimpleName())
-                        .setNodeType(NormalizedNodeMessages.QName.newBuilder()
-                            .setValue(nodeType))
-                        .addAllAttributes(getPathArgumentAttributes(
-                            pathArgument))
-                        .build();
-
                 builder.addArguments(serializablePathArgument);
             }
-
         } catch(Exception e){
             logger.error("An exception occurred", e);
         }
-        return builder.build();
+
+        return builder;
     }
 
 
@@ -106,21 +104,24 @@ public class InstanceIdentifierUtils {
      * @param path a protocol buffer version of the MD-SAL YangInstanceIdentifier
      * @return  an MD-SAL YangInstanceIdentifier
      */
-    public static YangInstanceIdentifier fromSerializable(NormalizedNodeMessages.InstanceIdentifier path){
-
-        List<YangInstanceIdentifier.PathArgument> pathArguments =
-            new ArrayList<>();
+    public static YangInstanceIdentifier fromSerializable(NormalizedNodeMessages.InstanceIdentifier path) {
+        return fromSerializable(path, new QNameDeSerializationContextImpl(path.getCodeList()));
+    }
 
-        for(NormalizedNodeMessages.PathArgument pathArgument : path.getArgumentsList()){
+    public static YangInstanceIdentifier fromSerializable(NormalizedNodeMessages.InstanceIdentifier path,
+            QNameDeSerializationContext context) {
 
-            pathArguments
-                .add(parsePathArgument(pathArgument));
+        List<YangInstanceIdentifier.PathArgument> pathArguments = new ArrayList<>();
 
+        for(NormalizedNodeMessages.PathArgument pathArgument : path.getArgumentsList()) {
+            if(context == null || pathArgument.hasType()) {
+                pathArguments.add(parsePathArgument(pathArgument));
+            } else {
+                pathArguments.add(PathArgumentSerializer.deSerialize(context, pathArgument));
+            }
         }
 
-        final YangInstanceIdentifier instanceIdentifier = YangInstanceIdentifier.create(pathArguments);
-
-        return instanceIdentifier;
+        return YangInstanceIdentifier.create(pathArguments);
     }
 
     /**
@@ -218,7 +219,8 @@ public class InstanceIdentifierUtils {
      * @param pathArgument protocol buffer PathArgument
      * @return MD-SAL PathArgument
      */
-    private static YangInstanceIdentifier.PathArgument parsePathArgument(NormalizedNodeMessages.PathArgument pathArgument) {
+    private static YangInstanceIdentifier.PathArgument parsePathArgument(
+            NormalizedNodeMessages.PathArgument pathArgument) {
         if (YangInstanceIdentifier.NodeWithValue.class.getSimpleName().equals(pathArgument.getType())) {
 
             YangInstanceIdentifier.NodeWithValue nodeWithValue =
index 3926bc7..e7f2c36 100644 (file)
@@ -4176,6 +4176,50 @@ public final class NormalizedNodeMessages {
      */
     org.opendaylight.controller.protobuff.messages.common.NormalizedNodeMessages.PathArgumentOrBuilder getArgumentsOrBuilder(
         int index);
+
+    // repeated string code = 2;
+    /**
+     * <code>repeated string code = 2;</code>
+     *
+     * <pre>
+     * A list of string codes which can be used for any repeated strings in the path args. This is
+     * optional - an InstanceIdentifier may be encoded as part of another message, eg NormalizedNode,
+     * that contains the codes.
+     * </pre>
+     */
+    java.util.List<java.lang.String>
+    getCodeList();
+    /**
+     * <code>repeated string code = 2;</code>
+     *
+     * <pre>
+     * A list of string codes which can be used for any repeated strings in the path args. This is
+     * optional - an InstanceIdentifier may be encoded as part of another message, eg NormalizedNode,
+     * that contains the codes.
+     * </pre>
+     */
+    int getCodeCount();
+    /**
+     * <code>repeated string code = 2;</code>
+     *
+     * <pre>
+     * A list of string codes which can be used for any repeated strings in the path args. This is
+     * optional - an InstanceIdentifier may be encoded as part of another message, eg NormalizedNode,
+     * that contains the codes.
+     * </pre>
+     */
+    java.lang.String getCode(int index);
+    /**
+     * <code>repeated string code = 2;</code>
+     *
+     * <pre>
+     * A list of string codes which can be used for any repeated strings in the path args. This is
+     * optional - an InstanceIdentifier may be encoded as part of another message, eg NormalizedNode,
+     * that contains the codes.
+     * </pre>
+     */
+    com.google.protobuf.ByteString
+        getCodeBytes(int index);
   }
   /**
    * Protobuf type {@code org.opendaylight.controller.mdsal.InstanceIdentifier}
@@ -4236,6 +4280,14 @@ public final class NormalizedNodeMessages {
               arguments_.add(input.readMessage(org.opendaylight.controller.protobuff.messages.common.NormalizedNodeMessages.PathArgument.PARSER, extensionRegistry));
               break;
             }
+            case 18: {
+              if (!((mutable_bitField0_ & 0x00000002) == 0x00000002)) {
+                code_ = new com.google.protobuf.LazyStringArrayList();
+                mutable_bitField0_ |= 0x00000002;
+              }
+              code_.add(input.readBytes());
+              break;
+            }
           }
         }
       } catch (com.google.protobuf.InvalidProtocolBufferException e) {
@@ -4247,6 +4299,9 @@ public final class NormalizedNodeMessages {
         if (((mutable_bitField0_ & 0x00000001) == 0x00000001)) {
           arguments_ = java.util.Collections.unmodifiableList(arguments_);
         }
+        if (((mutable_bitField0_ & 0x00000002) == 0x00000002)) {
+          code_ = new com.google.protobuf.UnmodifiableLazyStringList(code_);
+        }
         this.unknownFields = unknownFields.build();
         makeExtensionsImmutable();
       }
@@ -4314,8 +4369,63 @@ public final class NormalizedNodeMessages {
       return arguments_.get(index);
     }
 
+    // repeated string code = 2;
+    public static final int CODE_FIELD_NUMBER = 2;
+    private com.google.protobuf.LazyStringList code_;
+    /**
+     * <code>repeated string code = 2;</code>
+     *
+     * <pre>
+     * A list of string codes which can be used for any repeated strings in the path args. This is
+     * optional - an InstanceIdentifier may be encoded as part of another message, eg NormalizedNode,
+     * that contains the codes.
+     * </pre>
+     */
+    public java.util.List<java.lang.String>
+        getCodeList() {
+      return code_;
+    }
+    /**
+     * <code>repeated string code = 2;</code>
+     *
+     * <pre>
+     * A list of string codes which can be used for any repeated strings in the path args. This is
+     * optional - an InstanceIdentifier may be encoded as part of another message, eg NormalizedNode,
+     * that contains the codes.
+     * </pre>
+     */
+    public int getCodeCount() {
+      return code_.size();
+    }
+    /**
+     * <code>repeated string code = 2;</code>
+     *
+     * <pre>
+     * A list of string codes which can be used for any repeated strings in the path args. This is
+     * optional - an InstanceIdentifier may be encoded as part of another message, eg NormalizedNode,
+     * that contains the codes.
+     * </pre>
+     */
+    public java.lang.String getCode(int index) {
+      return code_.get(index);
+    }
+    /**
+     * <code>repeated string code = 2;</code>
+     *
+     * <pre>
+     * A list of string codes which can be used for any repeated strings in the path args. This is
+     * optional - an InstanceIdentifier may be encoded as part of another message, eg NormalizedNode,
+     * that contains the codes.
+     * </pre>
+     */
+    public com.google.protobuf.ByteString
+        getCodeBytes(int index) {
+      return code_.getByteString(index);
+    }
+
     private void initFields() {
       arguments_ = java.util.Collections.emptyList();
+      code_ = com.google.protobuf.LazyStringArrayList.EMPTY;
     }
     private byte memoizedIsInitialized = -1;
     public final boolean isInitialized() {
@@ -4338,6 +4448,9 @@ public final class NormalizedNodeMessages {
       for (int i = 0; i < arguments_.size(); i++) {
         output.writeMessage(1, arguments_.get(i));
       }
+      for (int i = 0; i < code_.size(); i++) {
+        output.writeBytes(2, code_.getByteString(i));
+      }
       getUnknownFields().writeTo(output);
     }
 
@@ -4351,6 +4464,15 @@ public final class NormalizedNodeMessages {
         size += com.google.protobuf.CodedOutputStream
           .computeMessageSize(1, arguments_.get(i));
       }
+      {
+        int dataSize = 0;
+        for (int i = 0; i < code_.size(); i++) {
+          dataSize += com.google.protobuf.CodedOutputStream
+            .computeBytesSizeNoTag(code_.getByteString(i));
+        }
+        size += dataSize;
+        size += 1 * getCodeList().size();
+      }
       size += getUnknownFields().getSerializedSize();
       memoizedSerializedSize = size;
       return size;
@@ -4474,6 +4596,8 @@ public final class NormalizedNodeMessages {
         } else {
           argumentsBuilder_.clear();
         }
+        code_ = com.google.protobuf.LazyStringArrayList.EMPTY;
+        bitField0_ = (bitField0_ & ~0x00000002);
         return this;
       }
 
@@ -4510,6 +4634,12 @@ public final class NormalizedNodeMessages {
         } else {
           result.arguments_ = argumentsBuilder_.build();
         }
+        if (((bitField0_ & 0x00000002) == 0x00000002)) {
+          code_ = new com.google.protobuf.UnmodifiableLazyStringList(
+              code_);
+          bitField0_ = (bitField0_ & ~0x00000002);
+        }
+        result.code_ = code_;
         onBuilt();
         return result;
       }
@@ -4551,6 +4681,16 @@ public final class NormalizedNodeMessages {
             }
           }
         }
+        if (!other.code_.isEmpty()) {
+          if (code_.isEmpty()) {
+            code_ = other.code_;
+            bitField0_ = (bitField0_ & ~0x00000002);
+          } else {
+            ensureCodeIsMutable();
+            code_.addAll(other.code_);
+          }
+          onChanged();
+        }
         this.mergeUnknownFields(other.getUnknownFields());
         return this;
       }
@@ -4824,6 +4964,153 @@ public final class NormalizedNodeMessages {
         return argumentsBuilder_;
       }
 
+      // repeated string code = 2;
+      private com.google.protobuf.LazyStringList code_ = com.google.protobuf.LazyStringArrayList.EMPTY;
+      private void ensureCodeIsMutable() {
+        if (!((bitField0_ & 0x00000002) == 0x00000002)) {
+          code_ = new com.google.protobuf.LazyStringArrayList(code_);
+          bitField0_ |= 0x00000002;
+         }
+      }
+      /**
+       * <code>repeated string code = 2;</code>
+       *
+       * <pre>
+       * A list of string codes which can be used for any repeated strings in the path args. This is
+       * optional - an InstanceIdentifier may be encoded as part of another message, eg NormalizedNode,
+       * that contains the codes.
+       * </pre>
+       */
+      public java.util.List<java.lang.String>
+          getCodeList() {
+        return java.util.Collections.unmodifiableList(code_);
+      }
+      /**
+       * <code>repeated string code = 2;</code>
+       *
+       * <pre>
+       * A list of string codes which can be used for any repeated strings in the path args. This is
+       * optional - an InstanceIdentifier may be encoded as part of another message, eg NormalizedNode,
+       * that contains the codes.
+       * </pre>
+       */
+      public int getCodeCount() {
+        return code_.size();
+      }
+      /**
+       * <code>repeated string code = 2;</code>
+       *
+       * <pre>
+       * A list of string codes which can be used for any repeated strings in the path args. This is
+       * optional - an InstanceIdentifier may be encoded as part of another message, eg NormalizedNode,
+       * that contains the codes.
+       * </pre>
+       */
+      public java.lang.String getCode(int index) {
+        return code_.get(index);
+      }
+      /**
+       * <code>repeated string code = 2;</code>
+       *
+       * <pre>
+       * A list of string codes which can be used for any repeated strings in the path args. This is
+       * optional - an InstanceIdentifier may be encoded as part of another message, eg NormalizedNode,
+       * that contains the codes.
+       * </pre>
+       */
+      public com.google.protobuf.ByteString
+          getCodeBytes(int index) {
+        return code_.getByteString(index);
+      }
+      /**
+       * <code>repeated string code = 2;</code>
+       *
+       * <pre>
+       * A list of string codes which can be used for any repeated strings in the path args. This is
+       * optional - an InstanceIdentifier may be encoded as part of another message, eg NormalizedNode,
+       * that contains the codes.
+       * </pre>
+       */
+      public Builder setCode(
+          int index, java.lang.String value) {
+        if (value == null) {
+    throw new NullPointerException();
+  }
+  ensureCodeIsMutable();
+        code_.set(index, value);
+        onChanged();
+        return this;
+      }
+      /**
+       * <code>repeated string code = 2;</code>
+       *
+       * <pre>
+       * A list of string codes which can be used for any repeated strings in the path args. This is
+       * optional - an InstanceIdentifier may be encoded as part of another message, eg NormalizedNode,
+       * that contains the codes.
+       * </pre>
+       */
+      public Builder addCode(
+          java.lang.String value) {
+        if (value == null) {
+    throw new NullPointerException();
+  }
+  ensureCodeIsMutable();
+        code_.add(value);
+        onChanged();
+        return this;
+      }
+      /**
+       * <code>repeated string code = 2;</code>
+       *
+       * <pre>
+       * A list of string codes which can be used for any repeated strings in the path args. This is
+       * optional - an InstanceIdentifier may be encoded as part of another message, eg NormalizedNode,
+       * that contains the codes.
+       * </pre>
+       */
+      public Builder addAllCode(
+          java.lang.Iterable<java.lang.String> values) {
+        ensureCodeIsMutable();
+        super.addAll(values, code_);
+        onChanged();
+        return this;
+      }
+      /**
+       * <code>repeated string code = 2;</code>
+       *
+       * <pre>
+       * A list of string codes which can be used for any repeated strings in the path args. This is
+       * optional - an InstanceIdentifier may be encoded as part of another message, eg NormalizedNode,
+       * that contains the codes.
+       * </pre>
+       */
+      public Builder clearCode() {
+        code_ = com.google.protobuf.LazyStringArrayList.EMPTY;
+        bitField0_ = (bitField0_ & ~0x00000002);
+        onChanged();
+        return this;
+      }
+      /**
+       * <code>repeated string code = 2;</code>
+       *
+       * <pre>
+       * A list of string codes which can be used for any repeated strings in the path args. This is
+       * optional - an InstanceIdentifier may be encoded as part of another message, eg NormalizedNode,
+       * that contains the codes.
+       * </pre>
+       */
+      public Builder addCodeBytes(
+          com.google.protobuf.ByteString value) {
+        if (value == null) {
+    throw new NullPointerException();
+  }
+  ensureCodeIsMutable();
+        code_.add(value);
+        onChanged();
+        return this;
+      }
+
       // @@protoc_insertion_point(builder_scope:org.opendaylight.controller.mdsal.InstanceIdentifier)
     }
 
@@ -9998,30 +10285,30 @@ public final class NormalizedNodeMessages {
       "controller.mdsal.PathArgumentAttribute\022@" +
       "\n\nattributes\030\005 \003(\0132,.org.opendaylight.co" +
       "ntroller.mdsal.Attribute\022\017\n\007intType\030\006 \001(" +
-      "\005\"X\n\022InstanceIdentifier\022B\n\targuments\030\001 \003" +
+      "\005\"f\n\022InstanceIdentifier\022B\n\targuments\030\001 \003" +
       "(\0132/.org.opendaylight.controller.mdsal.P" +
-      "athArgument\"\245\003\n\004Node\022\014\n\004path\030\001 \001(\t\022\014\n\004ty" +
-      "pe\030\002 \001(\t\022E\n\014pathArgument\030\003 \001(\0132/.org.ope" +
-      "ndaylight.controller.mdsal.PathArgument\022" +
-      "\017\n\007intType\030\004 \001(\005\022@\n\nattributes\030\005 \003(\0132,.o",
-      "rg.opendaylight.controller.mdsal.Attribu" +
-      "te\0226\n\005child\030\006 \003(\0132\'.org.opendaylight.con" +
-      "troller.mdsal.Node\022\r\n\005value\030\007 \001(\t\022\021\n\tval" +
-      "ueType\030\010 \001(\t\022\024\n\014intValueType\030\t \001(\005\022V\n\027in" +
-      "stanceIdentifierValue\030\n \001(\01325.org.openda" +
-      "ylight.controller.mdsal.InstanceIdentifi" +
-      "er\022\021\n\tbitsValue\030\013 \003(\t\022\014\n\004code\030\014 \003(\t\"`\n\tC" +
-      "ontainer\022\022\n\nparentPath\030\001 \002(\t\022?\n\016normaliz" +
-      "edNode\030\002 \001(\0132\'.org.opendaylight.controll" +
-      "er.mdsal.Node\"\246\001\n\014NodeMapEntry\022U\n\026instan",
-      "ceIdentifierPath\030\001 \002(\01325.org.opendayligh" +
-      "t.controller.mdsal.InstanceIdentifier\022?\n" +
-      "\016normalizedNode\030\002 \001(\0132\'.org.opendaylight" +
-      ".controller.mdsal.Node\"N\n\007NodeMap\022C\n\nmap" +
-      "Entries\030\001 \003(\0132/.org.opendaylight.control" +
-      "ler.mdsal.NodeMapEntryBO\n5org.opendaylig" +
-      "ht.controller.protobuff.messages.commonB" +
-      "\026NormalizedNodeMessages"
+      "athArgument\022\014\n\004code\030\002 \003(\t\"\245\003\n\004Node\022\014\n\004pa" +
+      "th\030\001 \001(\t\022\014\n\004type\030\002 \001(\t\022E\n\014pathArgument\030\003" +
+      " \001(\0132/.org.opendaylight.controller.mdsal" +
+      ".PathArgument\022\017\n\007intType\030\004 \001(\005\022@\n\nattrib",
+      "utes\030\005 \003(\0132,.org.opendaylight.controller" +
+      ".mdsal.Attribute\0226\n\005child\030\006 \003(\0132\'.org.op" +
+      "endaylight.controller.mdsal.Node\022\r\n\005valu" +
+      "e\030\007 \001(\t\022\021\n\tvalueType\030\010 \001(\t\022\024\n\014intValueTy" +
+      "pe\030\t \001(\005\022V\n\027instanceIdentifierValue\030\n \001(" +
+      "\01325.org.opendaylight.controller.mdsal.In" +
+      "stanceIdentifier\022\021\n\tbitsValue\030\013 \003(\t\022\014\n\004c" +
+      "ode\030\014 \003(\t\"`\n\tContainer\022\022\n\nparentPath\030\001 \002" +
+      "(\t\022?\n\016normalizedNode\030\002 \001(\0132\'.org.openday" +
+      "light.controller.mdsal.Node\"\246\001\n\014NodeMapE",
+      "ntry\022U\n\026instanceIdentifierPath\030\001 \002(\01325.o" +
+      "rg.opendaylight.controller.mdsal.Instanc" +
+      "eIdentifier\022?\n\016normalizedNode\030\002 \001(\0132\'.or" +
+      "g.opendaylight.controller.mdsal.Node\"N\n\007" +
+      "NodeMap\022C\n\nmapEntries\030\001 \003(\0132/.org.openda" +
+      "ylight.controller.mdsal.NodeMapEntryBO\n5" +
+      "org.opendaylight.controller.protobuff.me" +
+      "ssages.commonB\026NormalizedNodeMessages"
     };
     com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner =
       new com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner() {
@@ -10057,7 +10344,7 @@ public final class NormalizedNodeMessages {
           internal_static_org_opendaylight_controller_mdsal_InstanceIdentifier_fieldAccessorTable = new
             com.google.protobuf.GeneratedMessage.FieldAccessorTable(
               internal_static_org_opendaylight_controller_mdsal_InstanceIdentifier_descriptor,
-              new java.lang.String[] { "Arguments", });
+              new java.lang.String[] { "Arguments", "Code", });
           internal_static_org_opendaylight_controller_mdsal_Node_descriptor =
             getDescriptor().getMessageTypes().get(5);
           internal_static_org_opendaylight_controller_mdsal_Node_fieldAccessorTable = new
index 0b3ff21..356bfbf 100644 (file)
@@ -37,6 +37,11 @@ message PathArgument {
 
 message InstanceIdentifier {
   repeated PathArgument arguments=1;
+  
+  // A list of string codes which can be used for any repeated strings in the path args. This is
+  // optional - an InstanceIdentifier may be encoded as part of another message, eg NormalizedNode,
+  // that contains the codes. 
+  repeated string code = 2;
 }
 
 message Node{
index a9f9c72..6de1083 100644 (file)
@@ -68,15 +68,12 @@ public class NormalizedNodeToNodeCodecTest {
         new NormalizedNodeToNodeCodec(schemaContext);
     long start = System.currentTimeMillis();
     Container container =
-        codec.encode(instanceIdentifierFromString(id), output);
+        codec.encode(output);
     long end = System.currentTimeMillis();
 
     System.out.println("Timetaken to encode :"+(end-start));
 
     assertNotNull(container);
-    assertEquals(id, container.getParentPath() + "/"
-        + NormalizedNodeSerializer.deSerialize(container.getNormalizedNode(),
-        container.getNormalizedNode().getPathArgument()));
 
     // Decode the normalized node from the ProtocolBuffer form
     // first get the node representation of normalized node
@@ -84,7 +81,7 @@ public class NormalizedNodeToNodeCodecTest {
 
     start = System.currentTimeMillis();
     NormalizedNode<?, ?> normalizedNode =
-        codec.decode(instanceIdentifierFromString(id), node);
+        codec.decode(node);
     end = System.currentTimeMillis();
 
     System.out.println("Timetaken to decode :"+(end-start));
@@ -102,26 +99,18 @@ public class NormalizedNodeToNodeCodecTest {
         new NormalizedNodeToNodeCodec(schemaContext);
 
     Container container =
-        normalizedNodeToNodeCodec.encode(YangInstanceIdentifier.builder()
-            .build(), documentOne);
+        normalizedNodeToNodeCodec.encode(documentOne);
 
 
     final NormalizedNode<?, ?> decode =
         normalizedNodeToNodeCodec
             .decode(
-                instanceIdentifierFromString("/(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)test"),
                 container.getNormalizedNode());
     assertNotNull(decode);
 
     // let us ensure that the return decode normalized node encode returns same container
     Container containerResult =
-        normalizedNodeToNodeCodec.encode(YangInstanceIdentifier.builder()
-            .build(), decode);
-
-    assertEquals(container.getParentPath(), containerResult.getParentPath());
-
-    assertEquals(containerResult.getNormalizedNode().getChildCount(),
-        container.getNormalizedNode().getChildCount());
+        normalizedNodeToNodeCodec.encode(decode);
 
     // check first level children are proper
     List<Node> childrenResult =
@@ -174,11 +163,11 @@ public class NormalizedNodeToNodeCodecTest {
     NormalizedNodeToNodeCodec codec =
         new NormalizedNodeToNodeCodec(schemaContext);
 
-    Container encode = codec.encode(identifier, uno);
+    Container encode = codec.encode(uno);
 
     System.out.println(encode.getNormalizedNode());
 
-    codec.decode(identifier, encode.getNormalizedNode());
+    codec.decode(encode.getNormalizedNode());
   }
 
 }
index ffa8a10..d1e3eb2 100644 (file)
@@ -14,15 +14,6 @@ import static junit.framework.TestCase.assertEquals;
 
 public class PathUtilsTest {
 
-    @Test
-    public void getParentPath(){
-        assertEquals("", PathUtils.getParentPath("foobar"));
-        assertEquals("", PathUtils.getParentPath("/a"));
-        assertEquals("/a", PathUtils.getParentPath("/a/b"));
-        assertEquals("/a/b", PathUtils.getParentPath("/a/b/c"));
-        assertEquals("/a/b", PathUtils.getParentPath("a/b/c"));
-    }
-
     @Test
     public void toStringNodeIdentifier(){
         YangInstanceIdentifier.PathArgument pathArgument = nodeIdentifier();
index d1f21ee..0990cdd 100644 (file)
@@ -40,8 +40,7 @@ public class PathArgumentSerializerTest{
         expectedException.expect(NullPointerException.class);
         expectedException.expectMessage("pathArgument should not be null");
 
-        PathArgumentSerializer.serialize(mock(
-            NormalizedNodeSerializationContext.class), null);
+        PathArgumentSerializer.serialize(mock(QNameSerializationContext.class), null);
 
     }
 
@@ -59,14 +58,13 @@ public class PathArgumentSerializerTest{
         expectedException.expect(NullPointerException.class);
         expectedException.expectMessage("pathArgument should not be null");
 
-        PathArgumentSerializer.deSerialize(mock(NormalizedNodeDeSerializationContext.class), null);
+        PathArgumentSerializer.deSerialize(mock(QNameDeSerializationContext.class), null);
 
     }
 
     @Test
     public void testSerializeNodeIdentifier(){
-        NormalizedNodeSerializationContext serializationContext =
-            mock(NormalizedNodeSerializationContext.class);
+        QNameSerializationContext serializationContext = mock(QNameSerializationContext.class);
 
         when(serializationContext.addLocalName(anyString())).thenReturn(5);
         when(serializationContext.addNamespace(any(URI.class))).thenReturn(10);
@@ -87,8 +85,7 @@ public class PathArgumentSerializerTest{
 
     @Test
     public void testSerializeNodeIdentifierWithValue(){
-        NormalizedNodeSerializationContext serializationContext =
-            mock(NormalizedNodeSerializationContext.class);
+        QNameSerializationContext serializationContext = mock(QNameSerializationContext.class);
 
         when(serializationContext.addLocalName(anyString())).thenReturn(5);
         when(serializationContext.addNamespace(any(URI.class))).thenReturn(10);
@@ -110,9 +107,7 @@ public class PathArgumentSerializerTest{
 
     @Test
     public void testSerializeNodeIdentifierWithPredicates(){
-        NormalizedNodeSerializationContext serializationContext =
-            mock(NormalizedNodeSerializationContext.class);
-
+        QNameSerializationContext serializationContext = mock(QNameSerializationContext.class);
 
         when(serializationContext.addLocalName("test")).thenReturn(5);
         when(serializationContext.addLocalName("child-name")).thenReturn(55);
@@ -150,8 +145,7 @@ public class PathArgumentSerializerTest{
 
     @Test
     public void testSerializeAugmentationIdentifier(){
-        NormalizedNodeSerializationContext serializationContext =
-            mock(NormalizedNodeSerializationContext.class);
+        QNameSerializationContext serializationContext = mock(QNameSerializationContext.class);
 
         when(serializationContext.addLocalName(anyString())).thenReturn(55);
         when(serializationContext.addNamespace(any(URI.class))).thenReturn(66);
index af7a385..88c2695 100644 (file)
@@ -5,15 +5,14 @@ import com.google.common.collect.ImmutableSet;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
+import org.mockito.Mockito;
 import org.opendaylight.controller.cluster.datastore.util.TestModel;
 import org.opendaylight.controller.protobuff.messages.common.NormalizedNodeMessages;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-
 import java.math.BigDecimal;
 import java.math.BigInteger;
 import java.util.Set;
-
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 import static org.mockito.Mockito.mock;
@@ -27,14 +26,15 @@ public class ValueSerializerTest{
     public void testSerializeShort(){
         short v1 = 5;
         NormalizedNodeMessages.Node.Builder builder = NormalizedNodeMessages.Node.newBuilder();
-        ValueSerializer.serialize(builder, mock(NormalizedNodeSerializationContext.class), v1);
+        ValueSerializer.serialize(builder, mock(QNameSerializationContext.class), v1);
 
         assertEquals(ValueType.SHORT_TYPE.ordinal(), builder.getIntValueType());
         assertEquals("5", builder.getValue());
 
-        NormalizedNodeMessages.PathArgumentAttribute.Builder builder1 = NormalizedNodeMessages.PathArgumentAttribute.newBuilder();
+        NormalizedNodeMessages.PathArgumentAttribute.Builder builder1 =
+                NormalizedNodeMessages.PathArgumentAttribute.newBuilder();
 
-        ValueSerializer.serialize(builder1, mock(NormalizedNodeSerializationContext.class), v1);
+        ValueSerializer.serialize(builder1, mock(QNameSerializationContext.class), v1);
 
         assertEquals(ValueType.SHORT_TYPE.ordinal(), builder1.getType());
         assertEquals("5", builder.getValue());
@@ -49,16 +49,15 @@ public class ValueSerializerTest{
 
 
         NormalizedNodeMessages.Node.Builder builder = NormalizedNodeMessages.Node.newBuilder();
-        ValueSerializer.serialize(builder, mock(
-            NormalizedNodeSerializationContext.class), expected);
+        ValueSerializer.serialize(builder, mock(QNameSerializationContext.class), expected);
 
         assertEquals(ValueType.INT_TYPE.ordinal(), builder.getIntValueType());
         assertEquals("243", builder.getValue());
 
-        NormalizedNodeMessages.PathArgumentAttribute.Builder builder1 = NormalizedNodeMessages.PathArgumentAttribute.newBuilder();
+        NormalizedNodeMessages.PathArgumentAttribute.Builder builder1 =
+                NormalizedNodeMessages.PathArgumentAttribute.newBuilder();
 
-        ValueSerializer.serialize(builder1, mock(
-            NormalizedNodeSerializationContext.class), expected);
+        ValueSerializer.serialize(builder1, mock(QNameSerializationContext.class), expected);
 
         assertEquals(ValueType.INT_TYPE.ordinal(), builder1.getType());
         assertEquals("243", builder1.getValue());
@@ -71,16 +70,14 @@ public class ValueSerializerTest{
     public void testSerializeLong(){
         long v1 = 5;
         NormalizedNodeMessages.Node.Builder builder = NormalizedNodeMessages.Node.newBuilder();
-        ValueSerializer.serialize(builder, mock(
-            NormalizedNodeSerializationContext.class), v1);
+        ValueSerializer.serialize(builder, mock(QNameSerializationContext.class), v1);
 
         assertEquals(ValueType.LONG_TYPE.ordinal(), builder.getIntValueType());
         assertEquals("5", builder.getValue());
 
         NormalizedNodeMessages.PathArgumentAttribute.Builder builder1 = NormalizedNodeMessages.PathArgumentAttribute.newBuilder();
 
-        ValueSerializer.serialize(builder1, mock(
-            NormalizedNodeSerializationContext.class), v1);
+        ValueSerializer.serialize(builder1, mock(QNameSerializationContext.class), v1);
 
         assertEquals(ValueType.LONG_TYPE.ordinal(), builder1.getType());
         assertEquals("5", builder1.getValue());
@@ -91,16 +88,14 @@ public class ValueSerializerTest{
     public void testSerializeByte(){
         byte v1 = 5;
         NormalizedNodeMessages.Node.Builder builder = NormalizedNodeMessages.Node.newBuilder();
-        ValueSerializer.serialize(builder, mock(
-            NormalizedNodeSerializationContext.class), v1);
+        ValueSerializer.serialize(builder, mock(QNameSerializationContext.class), v1);
 
         assertEquals(ValueType.BYTE_TYPE.ordinal(), builder.getIntValueType());
         assertEquals("5", builder.getValue());
 
         NormalizedNodeMessages.PathArgumentAttribute.Builder builder1 = NormalizedNodeMessages.PathArgumentAttribute.newBuilder();
 
-        ValueSerializer.serialize(builder1, mock(
-            NormalizedNodeSerializationContext.class), v1);
+        ValueSerializer.serialize(builder1, mock(QNameSerializationContext.class), v1);
 
         assertEquals(ValueType.BYTE_TYPE.ordinal(), builder1.getType());
         assertEquals("5", builder1.getValue());
@@ -110,8 +105,7 @@ public class ValueSerializerTest{
     @Test
     public void testSerializeBits(){
         NormalizedNodeMessages.Node.Builder builder = NormalizedNodeMessages.Node.newBuilder();
-        ValueSerializer.serialize(builder, mock(
-            NormalizedNodeSerializationContext.class),
+        ValueSerializer.serialize(builder, mock(QNameSerializationContext.class),
             ImmutableSet.of("foo", "bar"));
 
         assertEquals(ValueType.BITS_TYPE.ordinal(), builder.getIntValueType());
@@ -120,8 +114,7 @@ public class ValueSerializerTest{
 
         NormalizedNodeMessages.PathArgumentAttribute.Builder builder1 = NormalizedNodeMessages.PathArgumentAttribute.newBuilder();
 
-        ValueSerializer.serialize(builder1, mock(
-            NormalizedNodeSerializationContext.class),
+        ValueSerializer.serialize(builder1, mock(QNameSerializationContext.class),
             ImmutableSet.of("foo", "bar"));
 
         assertEquals(ValueType.BITS_TYPE.ordinal(), builder1.getType());
@@ -134,8 +127,7 @@ public class ValueSerializerTest{
         expectedException.expect(IllegalArgumentException.class);
         expectedException.expectMessage("Expected value type to be Bits but was :");
         NormalizedNodeMessages.Node.Builder builder = NormalizedNodeMessages.Node.newBuilder();
-        ValueSerializer.serialize(builder, mock(
-                NormalizedNodeSerializationContext.class),
+        ValueSerializer.serialize(builder, mock(QNameSerializationContext.class),
             ImmutableSet.of(1, 2));
 
     }
@@ -143,16 +135,14 @@ public class ValueSerializerTest{
     @Test
     public void testSerializeEmptyString(){
         NormalizedNodeMessages.Node.Builder builder = NormalizedNodeMessages.Node.newBuilder();
-        ValueSerializer.serialize(builder, mock(
-            NormalizedNodeSerializationContext.class),"");
+        ValueSerializer.serialize(builder, mock(QNameSerializationContext.class),"");
 
         assertEquals(ValueType.STRING_TYPE.ordinal(), builder.getIntValueType());
         assertEquals("", builder.getValue());
 
         NormalizedNodeMessages.PathArgumentAttribute.Builder builder1 = NormalizedNodeMessages.PathArgumentAttribute.newBuilder();
 
-        ValueSerializer.serialize(builder1, mock(
-            NormalizedNodeSerializationContext.class),"");
+        ValueSerializer.serialize(builder1, mock(QNameSerializationContext.class),"");
 
         assertEquals(ValueType.STRING_TYPE.ordinal(), builder1.getType());
         assertEquals("", builder1.getValue());
@@ -162,16 +152,15 @@ public class ValueSerializerTest{
     @Test
     public void testSerializeString(){
         NormalizedNodeMessages.Node.Builder builder = NormalizedNodeMessages.Node.newBuilder();
-        ValueSerializer.serialize(builder, mock(
-            NormalizedNodeSerializationContext.class),"foo");
+        ValueSerializer.serialize(builder, mock(QNameSerializationContext.class),"foo");
 
         assertEquals(ValueType.STRING_TYPE.ordinal(), builder.getIntValueType());
         assertEquals("foo", builder.getValue());
 
-        NormalizedNodeMessages.PathArgumentAttribute.Builder builder1 = NormalizedNodeMessages.PathArgumentAttribute.newBuilder();
+        NormalizedNodeMessages.PathArgumentAttribute.Builder builder1 =
+                NormalizedNodeMessages.PathArgumentAttribute.newBuilder();
 
-        ValueSerializer.serialize(builder1, mock(
-            NormalizedNodeSerializationContext.class),"foo");
+        ValueSerializer.serialize(builder1, mock(QNameSerializationContext.class),"foo");
 
         assertEquals(ValueType.STRING_TYPE.ordinal(), builder1.getType());
         assertEquals("foo", builder1.getValue());
@@ -183,15 +172,14 @@ public class ValueSerializerTest{
     public void testSerializeBoolean(){
         boolean v1 = true;
         NormalizedNodeMessages.Node.Builder builder = NormalizedNodeMessages.Node.newBuilder();
-        ValueSerializer.serialize(builder, mock(
-            NormalizedNodeSerializationContext.class), v1);
+        ValueSerializer.serialize(builder, mock(QNameSerializationContext.class), v1);
 
         assertEquals(ValueType.BOOL_TYPE.ordinal(), builder.getIntValueType());
         assertEquals("true", builder.getValue());
 
-        NormalizedNodeMessages.PathArgumentAttribute.Builder builder1 = NormalizedNodeMessages.PathArgumentAttribute.newBuilder();
-        ValueSerializer.serialize(builder1, mock(
-            NormalizedNodeSerializationContext.class), v1);
+        NormalizedNodeMessages.PathArgumentAttribute.Builder builder1 =
+                NormalizedNodeMessages.PathArgumentAttribute.newBuilder();
+        ValueSerializer.serialize(builder1, mock(QNameSerializationContext.class), v1);
 
         assertEquals(ValueType.BOOL_TYPE.ordinal(), builder1.getType());
         assertEquals("true", builder1.getValue());
@@ -201,16 +189,14 @@ public class ValueSerializerTest{
     public void testSerializeQName(){
         QName v1 = TestModel.TEST_QNAME;
         NormalizedNodeMessages.Node.Builder builder = NormalizedNodeMessages.Node.newBuilder();
-        ValueSerializer.serialize(builder, mock(
-            NormalizedNodeSerializationContext.class), v1);
+        ValueSerializer.serialize(builder, mock(QNameSerializationContext.class), v1);
 
         assertEquals(ValueType.QNAME_TYPE.ordinal(), builder.getIntValueType());
         assertEquals("(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)test", builder.getValue());
 
         NormalizedNodeMessages.PathArgumentAttribute.Builder builder1 = NormalizedNodeMessages.PathArgumentAttribute.newBuilder();
 
-        ValueSerializer.serialize(builder1, mock(
-            NormalizedNodeSerializationContext.class), v1);
+        ValueSerializer.serialize(builder1, mock(QNameSerializationContext.class), v1);
 
         assertEquals(ValueType.QNAME_TYPE.ordinal(), builder1.getType());
         assertEquals("(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)test", builder1.getValue());
@@ -222,32 +208,30 @@ public class ValueSerializerTest{
         YangInstanceIdentifier v1 = TestModel.TEST_PATH;
 
         NormalizedNodeMessages.Node.Builder builder = NormalizedNodeMessages.Node.newBuilder();
-        ValueSerializer.serialize(builder, mock(
-            NormalizedNodeSerializationContext.class), v1);
-
+        QNameSerializationContext mockContext = mock(QNameSerializationContext.class);
+        ValueSerializer.serialize(builder, mockContext, v1);
 
         assertEquals(ValueType.YANG_IDENTIFIER_TYPE.ordinal(), builder.getIntValueType());
         NormalizedNodeMessages.InstanceIdentifier serializedYangInstanceIdentifier =
             builder.getInstanceIdentifierValue();
 
         assertEquals(1, serializedYangInstanceIdentifier.getArgumentsCount());
-        assertEquals(TestModel.TEST_QNAME.toString(), serializedYangInstanceIdentifier.getArguments(0).getNodeType().getValue());
+        Mockito.verify(mockContext).addLocalName(TestModel.TEST_QNAME.getLocalName());
+        Mockito.verify(mockContext).addNamespace(TestModel.TEST_QNAME.getNamespace());
     }
 
     @Test
     public void testSerializeBigInteger(){
         BigInteger v1 = new BigInteger("1000000000000000000000000");
         NormalizedNodeMessages.Node.Builder builder = NormalizedNodeMessages.Node.newBuilder();
-        ValueSerializer.serialize(builder, mock(
-            NormalizedNodeSerializationContext.class), v1);
+        ValueSerializer.serialize(builder, mock(QNameSerializationContext.class), v1);
 
         assertEquals(ValueType.BIG_INTEGER_TYPE.ordinal(), builder.getIntValueType());
         assertEquals("1000000000000000000000000", builder.getValue());
 
         NormalizedNodeMessages.PathArgumentAttribute.Builder builder1 = NormalizedNodeMessages.PathArgumentAttribute.newBuilder();
 
-        ValueSerializer.serialize(builder1, mock(
-            NormalizedNodeSerializationContext.class), v1);
+        ValueSerializer.serialize(builder1, mock(QNameSerializationContext.class), v1);
 
         assertEquals(ValueType.BIG_INTEGER_TYPE.ordinal(), builder1.getType());
         assertEquals("1000000000000000000000000", builder1.getValue());
@@ -258,15 +242,13 @@ public class ValueSerializerTest{
     public void testSerializeBigDecimal(){
         BigDecimal v1 = new BigDecimal("1000000000000000000000000.51616");
         NormalizedNodeMessages.Node.Builder builder = NormalizedNodeMessages.Node.newBuilder();
-        ValueSerializer.serialize(builder, mock(
-            NormalizedNodeSerializationContext.class), v1);
+        ValueSerializer.serialize(builder, mock(QNameSerializationContext.class), v1);
 
         assertEquals(ValueType.BIG_DECIMAL_TYPE.ordinal(), builder.getIntValueType());
         assertEquals("1000000000000000000000000.51616", builder.getValue());
 
         NormalizedNodeMessages.PathArgumentAttribute.Builder builder1 = NormalizedNodeMessages.PathArgumentAttribute.newBuilder();
-        ValueSerializer.serialize(builder1, mock(
-            NormalizedNodeSerializationContext.class), v1);
+        ValueSerializer.serialize(builder1, mock(QNameSerializationContext.class), v1);
 
         assertEquals(ValueType.BIG_DECIMAL_TYPE.ordinal(), builder1.getType());
         assertEquals("1000000000000000000000000.51616", builder1.getValue());
@@ -280,7 +262,7 @@ public class ValueSerializerTest{
         nodeBuilder.setValue("25");
 
         Object o = ValueSerializer
-            .deSerialize(mock(NormalizedNodeDeSerializationContext.class),
+            .deSerialize(mock(QNameDeSerializationContext.class),
                 nodeBuilder.build());
 
         assertTrue(o instanceof Short);
@@ -294,7 +276,7 @@ public class ValueSerializerTest{
         nodeBuilder.setValue("25");
 
         Object o = ValueSerializer
-            .deSerialize(mock(NormalizedNodeDeSerializationContext.class),
+            .deSerialize(mock(QNameDeSerializationContext.class),
                 nodeBuilder.build());
 
         assertTrue(o instanceof Byte);
@@ -309,7 +291,7 @@ public class ValueSerializerTest{
         nodeBuilder.setValue("25");
 
         Object o = ValueSerializer
-            .deSerialize(mock(NormalizedNodeDeSerializationContext.class),
+            .deSerialize(mock(QNameDeSerializationContext.class),
                 nodeBuilder.build());
 
         assertTrue(o instanceof Integer);
@@ -324,7 +306,7 @@ public class ValueSerializerTest{
         nodeBuilder.setValue("25");
 
         Object o = ValueSerializer
-            .deSerialize(mock(NormalizedNodeDeSerializationContext.class),
+            .deSerialize(mock(QNameDeSerializationContext.class),
                 nodeBuilder.build());
 
         assertTrue(o instanceof Long);
@@ -339,7 +321,7 @@ public class ValueSerializerTest{
         nodeBuilder.setValue("false");
 
         Object o = ValueSerializer
-            .deSerialize(mock(NormalizedNodeDeSerializationContext.class),
+            .deSerialize(mock(QNameDeSerializationContext.class),
                 nodeBuilder.build());
 
         assertTrue(o instanceof Boolean);
@@ -354,7 +336,7 @@ public class ValueSerializerTest{
         nodeBuilder.setValue(TestModel.TEST_QNAME.toString());
 
         Object o = ValueSerializer
-            .deSerialize(mock(NormalizedNodeDeSerializationContext.class),
+            .deSerialize(mock(QNameDeSerializationContext.class),
                 nodeBuilder.build());
 
         assertTrue(o instanceof QName);
@@ -369,7 +351,7 @@ public class ValueSerializerTest{
         nodeBuilder.addAllBitsValue(ImmutableList.of("foo", "bar"));
 
         Object o = ValueSerializer
-            .deSerialize(mock(NormalizedNodeDeSerializationContext.class),
+            .deSerialize(mock(QNameDeSerializationContext.class),
                 nodeBuilder.build());
 
         assertTrue(o instanceof Set);
@@ -384,7 +366,6 @@ public class ValueSerializerTest{
         NormalizedNodeMessages.InstanceIdentifier.Builder idBuilder = NormalizedNodeMessages.InstanceIdentifier.newBuilder();
         NormalizedNodeMessages.PathArgument.Builder pathBuilder = NormalizedNodeMessages.PathArgument.newBuilder();
 
-        pathBuilder.setValue(TestModel.TEST_QNAME.toString());
         pathBuilder.setIntType(PathArgumentType.NODE_IDENTIFIER.ordinal());
 
         idBuilder.addArguments(pathBuilder);
@@ -392,9 +373,15 @@ public class ValueSerializerTest{
         nodeBuilder.setIntValueType(ValueType.YANG_IDENTIFIER_TYPE.ordinal());
         nodeBuilder.setInstanceIdentifierValue(idBuilder);
 
-        Object o = ValueSerializer
-            .deSerialize(mock(NormalizedNodeDeSerializationContext.class),
-                nodeBuilder.build());
+        QNameDeSerializationContext mockContext = mock(QNameDeSerializationContext.class);
+        Mockito.doReturn(TestModel.TEST_QNAME.getNamespace().toString()).when(mockContext).
+                getNamespace(Mockito.anyInt());
+        Mockito.doReturn(TestModel.TEST_QNAME.getLocalName()).when(mockContext).
+                getLocalName(Mockito.anyInt());
+        Mockito.doReturn(TestModel.TEST_QNAME.getFormattedRevision()).when(mockContext).
+                getRevision(Mockito.anyInt());
+
+        Object o = ValueSerializer.deSerialize(mockContext, nodeBuilder.build());
 
         assertTrue(o instanceof YangInstanceIdentifier);
         assertEquals(TestModel.TEST_PATH, o);
@@ -407,8 +394,7 @@ public class ValueSerializerTest{
         nodeBuilder.setIntValueType(ValueType.STRING_TYPE.ordinal());
         nodeBuilder.setValue("25");
 
-        Object o = ValueSerializer
-            .deSerialize(mock(NormalizedNodeDeSerializationContext.class),
+        Object o = ValueSerializer.deSerialize(mock(QNameDeSerializationContext.class),
                 nodeBuilder.build());
 
         assertTrue(o instanceof String);
@@ -423,7 +409,7 @@ public class ValueSerializerTest{
         nodeBuilder.setValue("25");
 
         Object o = ValueSerializer
-            .deSerialize(mock(NormalizedNodeDeSerializationContext.class),
+            .deSerialize(mock(QNameDeSerializationContext.class),
                 nodeBuilder.build());
 
         assertTrue(o instanceof BigInteger);
@@ -438,7 +424,7 @@ public class ValueSerializerTest{
         nodeBuilder.setValue("25");
 
         Object o = ValueSerializer
-            .deSerialize(mock(NormalizedNodeDeSerializationContext.class),
+            .deSerialize(mock(QNameDeSerializationContext.class),
                 nodeBuilder.build());
 
         assertTrue(o instanceof BigDecimal);
index 136748e..6cd06e9 100644 (file)
@@ -12,10 +12,12 @@ package org.opendaylight.controller.cluster.datastore.util;
 
 import org.junit.Assert;
 import org.junit.Test;
+import org.opendaylight.controller.cluster.datastore.node.utils.serialization.QNameDeSerializationContext;
+import org.opendaylight.controller.cluster.datastore.node.utils.serialization.QNameDeSerializationContextImpl;
+import org.opendaylight.controller.cluster.datastore.node.utils.serialization.QNameSerializationContextImpl;
 import org.opendaylight.controller.protobuff.messages.common.NormalizedNodeMessages;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashSet;
@@ -23,139 +25,137 @@ import java.util.List;
 
 public class InstanceIdentifierUtilsTest {
 
-  private static QName TEST_QNAME =
-      QName
-          .create("(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)test");
-  private static QName NODE_WITH_VALUE_QNAME =
-      QName
-          .create("(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)value");
-  private static QName NODE_WITH_PREDICATES_QNAME =
-      QName
-          .create("(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)pred");
-  private static QName NAME_QNAME =
-      QName
-          .create("(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)name");
-
-  @Test
-  public void testSerializationOfNodeIdentifier() {
-    YangInstanceIdentifier.PathArgument p1 =
-        new YangInstanceIdentifier.NodeIdentifier(TEST_QNAME);
-
-    List<YangInstanceIdentifier.PathArgument> arguments = new ArrayList<>();
-
-    arguments.add(p1);
+    private static QName TEST_QNAME = QName
+            .create("(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)test");
+    private static QName NODE_WITH_VALUE_QNAME = QName
+            .create("(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)value");
+    private static QName NODE_WITH_PREDICATES_QNAME = QName
+            .create("(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)pred");
+    private static QName NAME_QNAME = QName
+            .create("(urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test?revision=2014-03-13)name");
 
-    YangInstanceIdentifier expected = YangInstanceIdentifier.create(arguments);
+    @Test
+    public void testSerializationOfNodeIdentifier() {
+        YangInstanceIdentifier.PathArgument p1 = new YangInstanceIdentifier.NodeIdentifier(TEST_QNAME);
 
-    NormalizedNodeMessages.InstanceIdentifier instanceIdentifier =
-        InstanceIdentifierUtils.toSerializable(expected);
+        List<YangInstanceIdentifier.PathArgument> arguments = new ArrayList<>();
 
-    YangInstanceIdentifier actual =
-        InstanceIdentifierUtils.fromSerializable(instanceIdentifier);
+        arguments.add(p1);
 
+        YangInstanceIdentifier expected = YangInstanceIdentifier.create(arguments);
 
-    Assert.assertEquals(expected.getLastPathArgument(),
-        actual.getLastPathArgument());
+        NormalizedNodeMessages.InstanceIdentifier instanceIdentifier =
+                InstanceIdentifierUtils.toSerializable(expected);
 
+        YangInstanceIdentifier actual = InstanceIdentifierUtils.fromSerializable(instanceIdentifier);
 
-  }
+        Assert.assertEquals(expected.getLastPathArgument(), actual.getLastPathArgument());
+    }
 
-  @Test
-  public void testSerializationOfNodeWithValue() {
+    @Test
+    public void testSerializationOfNodeWithValue() {
 
-    withValue((short) 1);
-    withValue((long) 2);
-    withValue(3);
-    withValue(true);
+        withValue((short) 1);
+        withValue((long) 2);
+        withValue(3);
+        withValue(true);
 
-  }
+    }
 
-  private void withValue(Object value) {
-    YangInstanceIdentifier.PathArgument p1 =
-        new YangInstanceIdentifier.NodeIdentifier(TEST_QNAME);
+    private void withValue(Object value) {
+        YangInstanceIdentifier.PathArgument p1 = new YangInstanceIdentifier.NodeIdentifier(TEST_QNAME);
 
-    YangInstanceIdentifier.PathArgument p2 =
-        new YangInstanceIdentifier.NodeWithValue(NODE_WITH_VALUE_QNAME, value);
+        YangInstanceIdentifier.PathArgument p2 =
+                new YangInstanceIdentifier.NodeWithValue(NODE_WITH_VALUE_QNAME, value);
 
+        List<YangInstanceIdentifier.PathArgument> arguments = new ArrayList<>();
 
-    List<YangInstanceIdentifier.PathArgument> arguments = new ArrayList<>();
+        arguments.add(p1);
+        arguments.add(p2);
 
-    arguments.add(p1);
-    arguments.add(p2);
+        YangInstanceIdentifier expected = YangInstanceIdentifier.create(arguments);
 
-    YangInstanceIdentifier expected = YangInstanceIdentifier.create(arguments);
+        NormalizedNodeMessages.InstanceIdentifier instanceIdentifier =
+                InstanceIdentifierUtils.toSerializable(expected);
 
-    NormalizedNodeMessages.InstanceIdentifier instanceIdentifier =
-        InstanceIdentifierUtils.toSerializable(expected);
+        YangInstanceIdentifier actual = InstanceIdentifierUtils.fromSerializable(instanceIdentifier);
 
-    YangInstanceIdentifier actual =
-        InstanceIdentifierUtils.fromSerializable(instanceIdentifier);
+        Assert.assertEquals(expected.getLastPathArgument(), actual.getLastPathArgument());
+    }
 
+    @Test
+    public void testSerializationOfNodeIdentifierWithPredicates() {
 
-    Assert.assertEquals(expected.getLastPathArgument(),
-        actual.getLastPathArgument());
-  }
+        withPredicates((short) 1);
+        withPredicates((long) 2);
+        withPredicates(3);
+        withPredicates(true);
 
+    }
 
-  @Test
-  public void testSerializationOfNodeIdentifierWithPredicates() {
+    private void withPredicates(Object value) {
+        YangInstanceIdentifier.PathArgument p1 = new YangInstanceIdentifier.NodeIdentifier(TEST_QNAME);
 
-    withPredicates((short) 1);
-    withPredicates((long) 2);
-    withPredicates(3);
-    withPredicates(true);
+        YangInstanceIdentifier.PathArgument p2 = new YangInstanceIdentifier.NodeIdentifierWithPredicates(
+                NODE_WITH_PREDICATES_QNAME, NAME_QNAME, value);
 
-  }
+        List<YangInstanceIdentifier.PathArgument> arguments = new ArrayList<>();
 
-  private void withPredicates(Object value) {
-    YangInstanceIdentifier.PathArgument p1 =
-        new YangInstanceIdentifier.NodeIdentifier(TEST_QNAME);
+        arguments.add(p1);
+        arguments.add(p2);
 
-    YangInstanceIdentifier.PathArgument p2 =
-        new YangInstanceIdentifier.NodeIdentifierWithPredicates(
-            NODE_WITH_PREDICATES_QNAME, NAME_QNAME, value);
+        YangInstanceIdentifier expected = YangInstanceIdentifier.create(arguments);
 
+        NormalizedNodeMessages.InstanceIdentifier instanceIdentifier =
+                InstanceIdentifierUtils.toSerializable(expected);
 
-    List<YangInstanceIdentifier.PathArgument> arguments = new ArrayList<>();
+        YangInstanceIdentifier actual = InstanceIdentifierUtils.fromSerializable(instanceIdentifier);
 
-    arguments.add(p1);
-    arguments.add(p2);
+        Assert.assertEquals(expected.getLastPathArgument(), actual.getLastPathArgument());
+    }
 
-    YangInstanceIdentifier expected = YangInstanceIdentifier.create(arguments);
+    @Test
+    public void testAugmentationIdentifier() {
+        YangInstanceIdentifier.PathArgument p1 = new YangInstanceIdentifier.AugmentationIdentifier(new HashSet(
+                Arrays.asList(TEST_QNAME)));
 
-    NormalizedNodeMessages.InstanceIdentifier instanceIdentifier =
-        InstanceIdentifierUtils.toSerializable(expected);
+        List<YangInstanceIdentifier.PathArgument> arguments = new ArrayList<>();
 
-    YangInstanceIdentifier actual =
-        InstanceIdentifierUtils.fromSerializable(instanceIdentifier);
+        arguments.add(p1);
 
+        YangInstanceIdentifier expected = YangInstanceIdentifier.create(arguments);
 
-    Assert.assertEquals(expected.getLastPathArgument(),
-        actual.getLastPathArgument());
-  }
+        NormalizedNodeMessages.InstanceIdentifier instanceIdentifier =
+                InstanceIdentifierUtils.toSerializable(expected);
 
-  @Test
-  public void testAugmentationIdentifier() {
-    YangInstanceIdentifier.PathArgument p1 =
-        new YangInstanceIdentifier.AugmentationIdentifier(new HashSet(
-            Arrays.asList(TEST_QNAME)));
+        YangInstanceIdentifier actual = InstanceIdentifierUtils.fromSerializable(instanceIdentifier);
 
-    List<YangInstanceIdentifier.PathArgument> arguments = new ArrayList<>();
+        Assert.assertEquals(expected.getLastPathArgument(), actual.getLastPathArgument());
 
-    arguments.add(p1);
+    }
 
-    YangInstanceIdentifier expected = YangInstanceIdentifier.create(arguments);
+    @Test
+    public void testSerializationWithContext() {
+        List<YangInstanceIdentifier.PathArgument> arguments =
+                                                Arrays.<YangInstanceIdentifier.PathArgument>asList(
+                new YangInstanceIdentifier.NodeIdentifier(TEST_QNAME),
+                new YangInstanceIdentifier.NodeWithValue(NODE_WITH_VALUE_QNAME, 1),
+                new YangInstanceIdentifier.NodeIdentifierWithPredicates(
+                        NODE_WITH_PREDICATES_QNAME, NAME_QNAME, 2));
 
-    NormalizedNodeMessages.InstanceIdentifier instanceIdentifier =
-        InstanceIdentifierUtils.toSerializable(expected);
+        YangInstanceIdentifier expected = YangInstanceIdentifier.create(arguments);
 
-    YangInstanceIdentifier actual =
-        InstanceIdentifierUtils.fromSerializable(instanceIdentifier);
+        QNameSerializationContextImpl serializationContext = new QNameSerializationContextImpl();
 
+        NormalizedNodeMessages.InstanceIdentifier instanceIdentifier =
+                InstanceIdentifierUtils.toSerializable(expected, serializationContext);
 
-    Assert.assertEquals(expected.getLastPathArgument(),
-        actual.getLastPathArgument());
+        QNameDeSerializationContext deserializationContext = new QNameDeSerializationContextImpl(
+                serializationContext.getCodes());
 
-  }
+        YangInstanceIdentifier actual = InstanceIdentifierUtils.fromSerializable(
+                instanceIdentifier, deserializationContext);
 
+        Assert.assertEquals(expected.getLastPathArgument(), actual.getLastPathArgument());
+    }
 }
index ddb5989..a3109b6 100644 (file)
@@ -588,7 +588,7 @@ public class Shard extends RaftActor {
             DOMStoreWriteTransaction transaction = store.newWriteOnlyTransaction();
             NormalizedNodeMessages.Node serializedNode = NormalizedNodeMessages.Node.parseFrom(snapshot);
             NormalizedNode<?, ?> node = new NormalizedNodeToNodeCodec(schemaContext)
-                .decode(YangInstanceIdentifier.builder().build(), serializedNode);
+                .decode(serializedNode);
 
             // delete everything first
             transaction.delete(YangInstanceIdentifier.builder().build());
index 8afdb4c..94fb584 100644 (file)
@@ -142,7 +142,7 @@ class ShardRecoveryCoordinator {
             try {
                 NormalizedNodeMessages.Node serializedNode = NormalizedNodeMessages.Node.parseFrom(snapshot);
                 NormalizedNode<?, ?> node = new NormalizedNodeToNodeCodec(schemaContext).decode(
-                        YangInstanceIdentifier.builder().build(), serializedNode);
+                        serializedNode);
 
                 // delete everything first
                 resultingTx.delete(YangInstanceIdentifier.builder().build());
index a8827be..5b5f076 100644 (file)
@@ -9,14 +9,13 @@
 package org.opendaylight.controller.cluster.datastore.messages;
 
 import org.opendaylight.controller.cluster.datastore.node.NormalizedNodeToNodeCodec;
-import org.opendaylight.controller.cluster.datastore.utils.InstanceIdentifierUtils;
+import org.opendaylight.controller.cluster.datastore.util.InstanceIdentifierUtils;
 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
 import org.opendaylight.controller.protobuff.messages.common.NormalizedNodeMessages;
 import org.opendaylight.controller.protobuff.messages.datachange.notification.DataChangeListenerMessages;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -26,8 +25,9 @@ import java.util.Map;
 import java.util.Set;
 
 public class DataChanged implements SerializableMessage {
-    public static final Class SERIALIZABLE_CLASS =
+    public static final Class<DataChangeListenerMessages.DataChanged> SERIALIZABLE_CLASS =
         DataChangeListenerMessages.DataChanged.class;
+
     final private SchemaContext schemaContext;
     private final AsyncDataChangeEvent<YangInstanceIdentifier, NormalizedNode<?, ?>>
         change;
@@ -50,7 +50,7 @@ public class DataChanged implements SerializableMessage {
         NormalizedNode<?, ?> normalizedNode) {
 
         return new NormalizedNodeToNodeCodec(schemaContext)
-            .encode(YangInstanceIdentifier.builder().build(), normalizedNode)
+            .encode(normalizedNode)
             .getNormalizedNode();
 
     }
@@ -62,6 +62,7 @@ public class DataChanged implements SerializableMessage {
             removedPathInstanceIds.add(InstanceIdentifierUtils.toSerializable(id));
         }
         return new Iterable<NormalizedNodeMessages.InstanceIdentifier>() {
+            @Override
             public Iterator<NormalizedNodeMessages.InstanceIdentifier> iterator() {
                 return removedPathInstanceIds.iterator();
             }
@@ -86,7 +87,7 @@ public class DataChanged implements SerializableMessage {
 
             builder.setInstanceIdentifierPath(instanceIdentifier)
                 .setNormalizedNode(normalizedNodeToNodeCodec
-                    .encode(entry.getKey(), entry.getValue())
+                    .encode(entry.getValue())
                     .getNormalizedNode());
             nodeMapBuilder.addMapEntries(builder.build());
         }
@@ -146,7 +147,6 @@ public class DataChanged implements SerializableMessage {
 
     static class DataChangedEvent implements
         AsyncDataChangeEvent<YangInstanceIdentifier, NormalizedNode<?, ?>> {
-        private final SchemaContext schemaContext;
         private Map<YangInstanceIdentifier, NormalizedNode<?, ?>> createdData;
         private final NormalizedNodeToNodeCodec nodeCodec;
         private Map<YangInstanceIdentifier, NormalizedNode<?, ?>> updatedData;
@@ -156,7 +156,6 @@ public class DataChanged implements SerializableMessage {
         private Set<YangInstanceIdentifier> removedPathIds;
 
         DataChangedEvent(SchemaContext schemaContext) {
-            this.schemaContext = schemaContext;
             nodeCodec = new NormalizedNodeToNodeCodec(schemaContext);
         }
 
@@ -183,7 +182,7 @@ public class DataChanged implements SerializableMessage {
                 YangInstanceIdentifier id = InstanceIdentifierUtils
                     .fromSerializable(nodeMapEntry.getInstanceIdentifierPath());
                 mapEntries.put(id,
-                    nodeCodec.decode(id, nodeMapEntry.getNormalizedNode()));
+                    nodeCodec.decode(nodeMapEntry.getNormalizedNode()));
             }
             return mapEntries;
         }
@@ -240,7 +239,7 @@ public class DataChanged implements SerializableMessage {
 
         DataChangedEvent setOriginalSubtree(NormalizedNodeMessages.Node node,
             YangInstanceIdentifier instanceIdentifierPath) {
-            originalSubTree = nodeCodec.decode(instanceIdentifierPath, node);
+            originalSubTree = nodeCodec.decode(node);
             return this;
         }
 
@@ -251,7 +250,7 @@ public class DataChanged implements SerializableMessage {
 
         DataChangedEvent setUpdatedSubtree(NormalizedNodeMessages.Node node,
             YangInstanceIdentifier instanceIdentifierPath) {
-            updatedSubTree = nodeCodec.decode(instanceIdentifierPath, node);
+            updatedSubTree = nodeCodec.decode(node);
             return this;
         }
 
index 9ae851e..6d3051c 100644 (file)
@@ -8,7 +8,7 @@
 
 package org.opendaylight.controller.cluster.datastore.messages;
 
-import org.opendaylight.controller.cluster.datastore.utils.InstanceIdentifierUtils;
+import org.opendaylight.controller.cluster.datastore.util.InstanceIdentifierUtils;
 import org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionMessages;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 
index ba79081..eb1f349 100644 (file)
@@ -9,8 +9,8 @@
 package org.opendaylight.controller.cluster.datastore.messages;
 
 import org.opendaylight.controller.cluster.datastore.node.NormalizedNodeToNodeCodec;
-import org.opendaylight.controller.cluster.datastore.utils.InstanceIdentifierUtils;
-import org.opendaylight.controller.protobuff.messages.common.NormalizedNodeMessages;
+import org.opendaylight.controller.cluster.datastore.node.NormalizedNodeToNodeCodec.Decoded;
+import org.opendaylight.controller.cluster.datastore.node.NormalizedNodeToNodeCodec.Encoded;
 import org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionMessages;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
@@ -18,31 +18,26 @@ import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 
 public class MergeData extends ModifyData{
 
-    public static final Class SERIALIZABLE_CLASS = ShardTransactionMessages.MergeData.class;
+    public static final Class<ShardTransactionMessages.MergeData> SERIALIZABLE_CLASS =
+            ShardTransactionMessages.MergeData.class;
 
     public MergeData(YangInstanceIdentifier path, NormalizedNode<?, ?> data,
         SchemaContext context) {
         super(path, data, context);
     }
 
-    @Override public Object toSerializable() {
-
-        NormalizedNodeMessages.Node normalizedNode =
-            new NormalizedNodeToNodeCodec(schemaContext).encode(path, data)
-                .getNormalizedNode();
+    @Override
+    public Object toSerializable() {
+        Encoded encoded = new NormalizedNodeToNodeCodec(schemaContext).encode(path, data);
         return ShardTransactionMessages.MergeData.newBuilder()
-            .setInstanceIdentifierPathArguments(InstanceIdentifierUtils.toSerializable(path))
-            .setNormalizedNode(normalizedNode).build();
+            .setInstanceIdentifierPathArguments(encoded.getEncodedPath())
+            .setNormalizedNode(encoded.getEncodedNode().getNormalizedNode()).build();
     }
 
     public static MergeData fromSerializable(Object serializable, SchemaContext schemaContext){
         ShardTransactionMessages.MergeData o = (ShardTransactionMessages.MergeData) serializable;
-        YangInstanceIdentifier identifier = InstanceIdentifierUtils.fromSerializable(o.getInstanceIdentifierPathArguments());
-
-        NormalizedNode<?, ?> normalizedNode =
-            new NormalizedNodeToNodeCodec(schemaContext)
-                .decode(identifier, o.getNormalizedNode());
-
-        return new MergeData(identifier, normalizedNode, schemaContext);
+        Decoded decoded = new NormalizedNodeToNodeCodec(schemaContext).decode(
+                o.getInstanceIdentifierPathArguments(), o.getNormalizedNode());
+        return new MergeData(decoded.getDecodedPath(), decoded.getDecodedNode(), schemaContext);
     }
 }
index a698f46..d743d99 100644 (file)
@@ -8,7 +8,7 @@
 
 package org.opendaylight.controller.cluster.datastore.messages;
 
-import org.opendaylight.controller.cluster.datastore.utils.InstanceIdentifierUtils;
+import org.opendaylight.controller.cluster.datastore.util.InstanceIdentifierUtils;
 import org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionMessages;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 
index fc6bcff..43dd812 100644 (file)
@@ -15,41 +15,44 @@ import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 
-public class ReadDataReply implements SerializableMessage{
-
-  private final NormalizedNode<?, ?> normalizedNode;
-  private final SchemaContext schemaContext;
-  public static final Class SERIALIZABLE_CLASS = ShardTransactionMessages.ReadDataReply.class;
-  public ReadDataReply(SchemaContext context,NormalizedNode<?, ?> normalizedNode){
-
-    this.normalizedNode = normalizedNode;
-    this.schemaContext = context;
-  }
-
-  public NormalizedNode<?, ?> getNormalizedNode() {
-    return normalizedNode;
-  }
-
-  public Object toSerializable(){
-    if(normalizedNode != null) {
-      return ShardTransactionMessages.ReadDataReply.newBuilder()
-          .setNormalizedNode(new NormalizedNodeToNodeCodec(schemaContext)
-                  .encode(YangInstanceIdentifier.builder().build(), normalizedNode).getNormalizedNode()
-          ).build();
-    }else{
-      return ShardTransactionMessages.ReadDataReply.newBuilder().build();
+public class ReadDataReply implements SerializableMessage {
+    public static final Class<ShardTransactionMessages.ReadDataReply> SERIALIZABLE_CLASS =
+            ShardTransactionMessages.ReadDataReply.class;
 
+    private final NormalizedNode<?, ?> normalizedNode;
+    private final SchemaContext schemaContext;
+
+    public ReadDataReply(SchemaContext context,NormalizedNode<?, ?> normalizedNode){
+
+        this.normalizedNode = normalizedNode;
+        this.schemaContext = context;
+    }
+
+    public NormalizedNode<?, ?> getNormalizedNode() {
+        return normalizedNode;
     }
 
-  }
+    @Override
+    public Object toSerializable(){
+        if(normalizedNode != null) {
+            return ShardTransactionMessages.ReadDataReply.newBuilder()
+                    .setNormalizedNode(new NormalizedNodeToNodeCodec(schemaContext)
+                        .encode(normalizedNode).getNormalizedNode()).build();
+        } else {
+            return ShardTransactionMessages.ReadDataReply.newBuilder().build();
 
-  public static ReadDataReply fromSerializable(SchemaContext schemaContext,YangInstanceIdentifier id,Object serializable){
-    ShardTransactionMessages.ReadDataReply o = (ShardTransactionMessages.ReadDataReply) serializable;
-    return new ReadDataReply(schemaContext,new NormalizedNodeToNodeCodec(schemaContext).decode(id, o.getNormalizedNode()));
-  }
+        }
+    }
+
+    public static ReadDataReply fromSerializable(SchemaContext schemaContext,
+            YangInstanceIdentifier id, Object serializable) {
+        ShardTransactionMessages.ReadDataReply o = (ShardTransactionMessages.ReadDataReply) serializable;
+        return new ReadDataReply(schemaContext, new NormalizedNodeToNodeCodec(schemaContext).decode(
+                o.getNormalizedNode()));
+    }
 
-  public static ByteString getNormalizedNodeByteString(Object serializable){
-      ShardTransactionMessages.ReadDataReply o = (ShardTransactionMessages.ReadDataReply) serializable;
-      return ((ShardTransactionMessages.ReadDataReply) serializable).getNormalizedNode().toByteString();
-  }
+    public static ByteString getNormalizedNodeByteString(Object serializable){
+        ShardTransactionMessages.ReadDataReply o = (ShardTransactionMessages.ReadDataReply) serializable;
+        return ((ShardTransactionMessages.ReadDataReply) serializable).getNormalizedNode().toByteString();
+    }
 }
index c1ec0a8..dea0851 100644 (file)
@@ -10,13 +10,15 @@ package org.opendaylight.controller.cluster.datastore.messages;
 
 import akka.actor.ActorPath;
 import akka.actor.ActorSystem;
-import org.opendaylight.controller.cluster.datastore.utils.InstanceIdentifierUtils;
+import org.opendaylight.controller.cluster.datastore.util.InstanceIdentifierUtils;
 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker;
 import org.opendaylight.controller.protobuff.messages.registration.ListenerRegistrationMessages;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 
 public class RegisterChangeListener implements SerializableMessage {
-  public static final Class SERIALIZABLE_CLASS = ListenerRegistrationMessages.RegisterChangeListener.class;
+    public static final Class<ListenerRegistrationMessages.RegisterChangeListener> SERIALIZABLE_CLASS =
+            ListenerRegistrationMessages.RegisterChangeListener.class;
+
     private final YangInstanceIdentifier path;
     private final ActorPath dataChangeListenerPath;
     private final AsyncDataBroker.DataChangeScope scope;
index 87fa010..8aa63ef 100644 (file)
@@ -9,41 +9,34 @@
 package org.opendaylight.controller.cluster.datastore.messages;
 
 import org.opendaylight.controller.cluster.datastore.node.NormalizedNodeToNodeCodec;
-import org.opendaylight.controller.cluster.datastore.utils.InstanceIdentifierUtils;
-import org.opendaylight.controller.protobuff.messages.common.NormalizedNodeMessages;
+import org.opendaylight.controller.cluster.datastore.node.NormalizedNodeToNodeCodec.Decoded;
+import org.opendaylight.controller.cluster.datastore.node.NormalizedNodeToNodeCodec.Encoded;
 import org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionMessages;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 
-public class WriteData extends ModifyData{
+public class WriteData extends ModifyData {
 
-  public static final Class SERIALIZABLE_CLASS = ShardTransactionMessages.WriteData.class;
+    public static final Class<ShardTransactionMessages.WriteData> SERIALIZABLE_CLASS =
+            ShardTransactionMessages.WriteData.class;
 
-  public WriteData(YangInstanceIdentifier path, NormalizedNode<?, ?> data, SchemaContext schemaContext) {
-    super(path, data, schemaContext);
-  }
-
-    @Override public Object toSerializable() {
+    public WriteData(YangInstanceIdentifier path, NormalizedNode<?, ?> data, SchemaContext schemaContext) {
+        super(path, data, schemaContext);
+    }
 
-        NormalizedNodeMessages.Node normalizedNode =
-            new NormalizedNodeToNodeCodec(schemaContext).encode(path, data)
-                .getNormalizedNode();
+    @Override
+    public Object toSerializable() {
+        Encoded encoded = new NormalizedNodeToNodeCodec(schemaContext).encode(path, data);
         return ShardTransactionMessages.WriteData.newBuilder()
-            .setInstanceIdentifierPathArguments(InstanceIdentifierUtils.toSerializable(path))
-            .setNormalizedNode(normalizedNode).build();
-
+                .setInstanceIdentifierPathArguments(encoded.getEncodedPath())
+                .setNormalizedNode(encoded.getEncodedNode().getNormalizedNode()).build();
     }
 
     public static WriteData fromSerializable(Object serializable, SchemaContext schemaContext){
         ShardTransactionMessages.WriteData o = (ShardTransactionMessages.WriteData) serializable;
-        YangInstanceIdentifier identifier = InstanceIdentifierUtils.fromSerializable(o.getInstanceIdentifierPathArguments());
-
-        NormalizedNode<?, ?> normalizedNode =
-            new NormalizedNodeToNodeCodec(schemaContext)
-                .decode(identifier, o.getNormalizedNode());
-
-        return new WriteData(identifier, normalizedNode, schemaContext);
+        Decoded decoded = new NormalizedNodeToNodeCodec(schemaContext).decode(
+                o.getInstanceIdentifierPathArguments(), o.getNormalizedNode());
+        return new WriteData(decoded.getDecodedPath(), decoded.getDecodedNode(), schemaContext);
     }
-
 }
index 593f458..056fe75 100644 (file)
@@ -8,7 +8,7 @@
 
 package org.opendaylight.controller.cluster.datastore.modification;
 
-import org.opendaylight.controller.cluster.datastore.utils.InstanceIdentifierUtils;
+import org.opendaylight.controller.cluster.datastore.util.InstanceIdentifierUtils;
 import org.opendaylight.controller.protobuff.messages.persistent.PersistentMessages;
 import org.opendaylight.controller.sal.core.spi.data.DOMStoreWriteTransaction;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
@@ -17,23 +17,24 @@ import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
  * DeleteModification store all the parameters required to delete a path from the data tree
  */
 public class DeleteModification extends AbstractModification {
-  public DeleteModification(YangInstanceIdentifier path) {
-    super(path);
-  }
+    private static final long serialVersionUID = 1L;
 
-  @Override
-  public void apply(DOMStoreWriteTransaction transaction) {
-    transaction.delete(path);
-  }
+    public DeleteModification(YangInstanceIdentifier path) {
+        super(path);
+    }
+
+    @Override
+    public void apply(DOMStoreWriteTransaction transaction) {
+        transaction.delete(path);
+    }
 
-    @Override public Object toSerializable() {
-        return PersistentMessages.Modification.newBuilder()
-            .setType(this.getClass().toString())
-            .setPath(InstanceIdentifierUtils.toSerializable(this.path))
-            .build();
+    @Override
+    public Object toSerializable() {
+        return PersistentMessages.Modification.newBuilder().setType(this.getClass().toString())
+                .setPath(InstanceIdentifierUtils.toSerializable(this.path)).build();
     }
 
-    public static DeleteModification fromSerializable(Object serializable){
+    public static DeleteModification fromSerializable(Object serializable) {
         PersistentMessages.Modification o = (PersistentMessages.Modification) serializable;
         return new DeleteModification(InstanceIdentifierUtils.fromSerializable(o.getPath()));
     }
index f06adcf..24c4c6c 100644 (file)
@@ -9,8 +9,7 @@
 package org.opendaylight.controller.cluster.datastore.modification;
 
 import org.opendaylight.controller.cluster.datastore.node.NormalizedNodeToNodeCodec;
-import org.opendaylight.controller.cluster.datastore.utils.InstanceIdentifierUtils;
-import org.opendaylight.controller.protobuff.messages.common.NormalizedNodeMessages;
+import org.opendaylight.controller.cluster.datastore.node.NormalizedNodeToNodeCodec.Decoded;
 import org.opendaylight.controller.protobuff.messages.persistent.PersistentMessages;
 import org.opendaylight.controller.sal.core.spi.data.DOMStoreWriteTransaction;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
@@ -20,16 +19,11 @@ import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 /**
  * MergeModification stores all the parameters required to merge data into the specified path
  */
-public class MergeModification extends AbstractModification {
-    private final NormalizedNode data;
-    private final SchemaContext schemaContext;
-
+public class MergeModification extends WriteModification {
 
     public MergeModification(YangInstanceIdentifier path, NormalizedNode data,
         SchemaContext schemaContext) {
-        super(path);
-        this.data = data;
-        this.schemaContext = schemaContext;
+        super(path, data, schemaContext);
     }
 
     @Override
@@ -37,29 +31,9 @@ public class MergeModification extends AbstractModification {
         transaction.merge(path, data);
     }
 
-    @Override public Object toSerializable() {
-        NormalizedNodeMessages.Container encode =
-            new NormalizedNodeToNodeCodec(schemaContext).encode(
-                path, data);
-
-        return PersistentMessages.Modification.newBuilder()
-            .setType(this.getClass().toString())
-            .setPath(InstanceIdentifierUtils.toSerializable(this.path))
-            .setData(encode.getNormalizedNode())
-            .build();
-
-    }
-
-    public static MergeModification fromSerializable(
-        Object serializable,
-        SchemaContext schemaContext) {
+    public static MergeModification fromSerializable(Object serializable, SchemaContext schemaContext) {
         PersistentMessages.Modification o = (PersistentMessages.Modification) serializable;
-
-        YangInstanceIdentifier path = InstanceIdentifierUtils.fromSerializable(o.getPath());
-        NormalizedNode data = new NormalizedNodeToNodeCodec(schemaContext).decode(
-            path, o.getData());
-
-        return new MergeModification(path, data, schemaContext);
+        Decoded decoded = new NormalizedNodeToNodeCodec(schemaContext).decode(o.getPath(), o.getData());
+        return new MergeModification(decoded.getDecodedPath(), decoded.getDecodedNode(), schemaContext);
     }
-
 }
index b4a7dd6..53cc35a 100644 (file)
@@ -9,8 +9,8 @@
 package org.opendaylight.controller.cluster.datastore.modification;
 
 import org.opendaylight.controller.cluster.datastore.node.NormalizedNodeToNodeCodec;
-import org.opendaylight.controller.cluster.datastore.utils.InstanceIdentifierUtils;
-import org.opendaylight.controller.protobuff.messages.common.NormalizedNodeMessages;
+import org.opendaylight.controller.cluster.datastore.node.NormalizedNodeToNodeCodec.Decoded;
+import org.opendaylight.controller.cluster.datastore.node.NormalizedNodeToNodeCodec.Encoded;
 import org.opendaylight.controller.protobuff.messages.persistent.PersistentMessages;
 import org.opendaylight.controller.sal.core.spi.data.DOMStoreWriteTransaction;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
@@ -22,43 +22,38 @@ import org.opendaylight.yangtools.yang.model.api.SchemaContext;
  */
 public class WriteModification extends AbstractModification {
 
-  private final NormalizedNode data;
+    protected final NormalizedNode data;
     private final SchemaContext schemaContext;
 
     public WriteModification(YangInstanceIdentifier path, NormalizedNode data, SchemaContext schemaContext) {
-    super(path);
-    this.data = data;
+        super(path);
+        this.data = data;
         this.schemaContext = schemaContext;
     }
 
-  @Override
-  public void apply(DOMStoreWriteTransaction transaction) {
-    transaction.write(path, data);
-  }
+    @Override
+    public void apply(DOMStoreWriteTransaction transaction) {
+        transaction.write(path, data);
+    }
 
-    @Override public Object toSerializable() {
-        NormalizedNodeMessages.Container encode =
-            new NormalizedNodeToNodeCodec(schemaContext).encode(
-                path, data);
+    public NormalizedNode getData() {
+        return data;
+    }
 
+    @Override
+    public Object toSerializable() {
+        Encoded encoded = new NormalizedNodeToNodeCodec(schemaContext).encode(path, data);
 
         return PersistentMessages.Modification.newBuilder()
-            .setType(this.getClass().toString())
-            .setPath(InstanceIdentifierUtils.toSerializable(this.path))
-            .setData(encode.getNormalizedNode())
-            .build();
-
+                .setType(this.getClass().toString())
+                .setPath(encoded.getEncodedPath())
+                .setData(encoded.getEncodedNode().getNormalizedNode())
+                .build();
     }
 
-    public static WriteModification fromSerializable(
-        Object serializable,
-        SchemaContext schemaContext) {
+    public static WriteModification fromSerializable(Object serializable, SchemaContext schemaContext) {
         PersistentMessages.Modification o = (PersistentMessages.Modification) serializable;
-
-        YangInstanceIdentifier path = InstanceIdentifierUtils.fromSerializable(o.getPath());
-        NormalizedNode data = new NormalizedNodeToNodeCodec(schemaContext).decode(
-            path, o.getData());
-
-        return new WriteModification(path, data, schemaContext);
+        Decoded decoded = new NormalizedNodeToNodeCodec(schemaContext).decode(o.getPath(), o.getData());
+        return new WriteModification(decoded.getDecodedPath(), decoded.getDecodedNode(), schemaContext);
     }
 }
diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/utils/InstanceIdentifierUtils.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/utils/InstanceIdentifierUtils.java
deleted file mode 100644 (file)
index c154b81..0000000
+++ /dev/null
@@ -1,74 +0,0 @@
-package org.opendaylight.controller.cluster.datastore.utils;
-
-import org.opendaylight.controller.cluster.datastore.node.utils.NodeIdentifierFactory;
-import org.opendaylight.controller.protobuff.messages.common.NormalizedNodeMessages;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * @author: syedbahm
- */
-public class InstanceIdentifierUtils {
-
-    protected static final Logger logger = LoggerFactory
-        .getLogger(InstanceIdentifierUtils.class);
-
-    public static String getParentPath(String currentElementPath) {
-
-        StringBuilder parentPath = new StringBuilder();
-
-        if (currentElementPath != null) {
-            String[] parentPaths = currentElementPath.split("/");
-            if (parentPaths.length > 2) {
-                for (int i = 0; i < parentPaths.length - 1; i++) {
-                    if (parentPaths[i].length() > 0) {
-                        parentPath.append( "/");
-                        parentPath.append( parentPaths[i]);
-                    }
-                }
-            }
-        }
-        return parentPath.toString();
-    }
-
-    @Deprecated
-    public static YangInstanceIdentifier from(String path) {
-        String[] ids = path.split("/");
-
-        List<YangInstanceIdentifier.PathArgument> pathArguments =
-            new ArrayList<>();
-        for (String nodeId : ids) {
-            if (!"".equals(nodeId)) {
-                pathArguments
-                    .add(NodeIdentifierFactory.getArgument(nodeId));
-            }
-        }
-        final YangInstanceIdentifier instanceIdentifier =
-            YangInstanceIdentifier.create(pathArguments);
-        return instanceIdentifier;
-    }
-
-    /**
-     * @deprecated Use {@link org.opendaylight.controller.cluster.datastore.util.InstanceIdentifierUtils} instead
-     * @param path
-     * @return
-     */
-    @Deprecated
-    public static NormalizedNodeMessages.InstanceIdentifier toSerializable(YangInstanceIdentifier path){
-        return org.opendaylight.controller.cluster.datastore.util.InstanceIdentifierUtils.toSerializable(path);
-    }
-
-    /**
-     * @deprecated Use {@link org.opendaylight.controller.cluster.datastore.util.InstanceIdentifierUtils} instead
-     * @param path
-     * @return
-     */
-    @Deprecated
-    public static YangInstanceIdentifier fromSerializable(NormalizedNodeMessages.InstanceIdentifier path){
-        return org.opendaylight.controller.cluster.datastore.util.InstanceIdentifierUtils.fromSerializable(path);
-    }
-}
index a3e0b3a..2051c9d 100644 (file)
@@ -208,7 +208,7 @@ public class ShardTest extends AbstractActorTest {
         YangInstanceIdentifier root = YangInstanceIdentifier.builder().build();
         NormalizedNode<?,?> expected = ref.underlyingActor().readStore(root);
 
-        NormalizedNodeMessages.Container encode = codec.encode(root, expected);
+        NormalizedNodeMessages.Container encode = codec.encode(expected);
 
         ApplySnapshot applySnapshot = new ApplySnapshot(Snapshot.create(
                 encode.getNormalizedNode().toByteString().toByteArray(),
@@ -260,7 +260,7 @@ public class ShardTest extends AbstractActorTest {
 
         InMemorySnapshotStore.addSnapshot(IDENTIFIER.toString(), Snapshot.create(
                 new NormalizedNodeToNodeCodec(SCHEMA_CONTEXT).encode(
-                        YangInstanceIdentifier.builder().build(), root).
+                        root).
                                 getNormalizedNode().toByteString().toByteArray(),
                                 Collections.<ReplicatedLogEntry>emptyList(), 0, 1, -1, -1));
 
index 75128e6..8f3ca9c 100644 (file)
@@ -1,47 +1,21 @@
 package org.opendaylight.controller.cluster.datastore.messages;
 
-import junit.framework.Assert;
+import org.junit.Assert;
 import org.junit.Test;
-import org.opendaylight.controller.cluster.datastore.node.NormalizedNodeToNodeCodec;
 import org.opendaylight.controller.md.cluster.datastore.model.TestModel;
-import org.opendaylight.controller.protobuff.messages.common.NormalizedNodeMessages;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 
 public class MergeDataTest {
 
     @Test
-    public void testBasic(){
-        MergeData mergeData = new MergeData(TestModel.TEST_PATH, ImmutableNodes
-            .containerNode(TestModel.TEST_QNAME),
-            TestModel.createTestContext());
-
-        MergeData output = MergeData
-            .fromSerializable(mergeData.toSerializable(),
-                TestModel.createTestContext());
-
-    }
-
-    @Test
-    public void testNormalizedNodeEncodeDecode(){
-        NormalizedNode<?, ?> expected =
-            ImmutableNodes.containerNode(TestModel.TEST_QNAME);
-
-
-        NormalizedNodeMessages.Container node =
-            new NormalizedNodeToNodeCodec(TestModel.createTestContext())
-                .encode(TestModel.TEST_PATH,
-                    expected);
-
-        String parentPath = node.getParentPath();
-
-        NormalizedNodeMessages.Node normalizedNode =
-            node.getNormalizedNode();
-
-        NormalizedNode<?,?> actual = new NormalizedNodeToNodeCodec(TestModel.createTestContext()).decode(TestModel.TEST_PATH,
-            normalizedNode);
-
-
-        Assert.assertEquals(expected, actual);
+    public void testSerialization() {
+        SchemaContext schemaContext = TestModel.createTestContext();
+        MergeData expected = new MergeData(TestModel.TEST_PATH, ImmutableNodes
+            .containerNode(TestModel.TEST_QNAME), schemaContext);
+
+        MergeData actual = MergeData.fromSerializable(expected.toSerializable(), schemaContext);
+        Assert.assertEquals("getPath", expected.getPath(), actual.getPath());
+        Assert.assertEquals("getData", expected.getData(), actual.getData());
     }
 }
diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/messages/WriteDataTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/messages/WriteDataTest.java
new file mode 100644 (file)
index 0000000..6a5d65f
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2014 Brocade Communications Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * 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.messages;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.opendaylight.controller.md.cluster.datastore.model.TestModel;
+import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+
+/**
+ * Unit tests for WriteData.
+ *
+ * @author Thomas Pantelis
+ */
+public class WriteDataTest {
+
+    @Test
+    public void testSerialization() {
+        SchemaContext schemaContext = TestModel.createTestContext();
+        WriteData expected = new WriteData(TestModel.TEST_PATH, ImmutableNodes
+            .containerNode(TestModel.TEST_QNAME), schemaContext);
+
+        WriteData actual = WriteData.fromSerializable(expected.toSerializable(), schemaContext);
+        Assert.assertEquals("getPath", expected.getPath(), actual.getPath());
+        Assert.assertEquals("getData", expected.getData(), actual.getData());
+    }
+}
index 9af3439..5d20211 100644 (file)
@@ -7,22 +7,38 @@ import org.opendaylight.controller.md.cluster.datastore.model.TestModel;
 import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadWriteTransaction;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 
 public class MergeModificationTest extends AbstractModificationTest{
 
-  @Test
-  public void testApply() throws Exception {
-    //TODO : Need to write a better test for this
+    @Test
+    public void testApply() throws Exception {
+        //TODO : Need to write a better test for this
 
-    //Write something into the datastore
-    DOMStoreReadWriteTransaction writeTransaction = store.newReadWriteTransaction();
-    MergeModification writeModification = new MergeModification(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME), TestModel.createTestContext());
-    writeModification.apply(writeTransaction);
-    commitTransaction(writeTransaction);
+        //Write something into the datastore
+        DOMStoreReadWriteTransaction writeTransaction = store.newReadWriteTransaction();
+        MergeModification writeModification = new MergeModification(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME), TestModel.createTestContext());
+        writeModification.apply(writeTransaction);
+        commitTransaction(writeTransaction);
 
-    //Check if it's in the datastore
-    Optional<NormalizedNode<?,?>> data = readData(TestModel.TEST_PATH);
-    Assert.assertTrue(data.isPresent());
+        //Check if it's in the datastore
+        Optional<NormalizedNode<?,?>> data = readData(TestModel.TEST_PATH);
+        Assert.assertTrue(data.isPresent());
 
-  }
+    }
+
+    @Test
+    public void testSerialization() {
+        SchemaContext schemaContext = TestModel.createTestContext();
+        NormalizedNode<?, ?> node = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
+        MergeModification mergeModification = new MergeModification(TestModel.TEST_PATH,
+                node, schemaContext);
+
+        Object serialized = mergeModification.toSerializable();
+
+        MergeModification newModification = MergeModification.fromSerializable(serialized, schemaContext);
+
+        Assert.assertEquals("getPath", TestModel.TEST_PATH, newModification.getPath());
+        Assert.assertEquals("getData", node, newModification.getData());
+    }
 }
index 75d8c00..3a82fff 100644 (file)
@@ -7,20 +7,36 @@ import org.opendaylight.controller.md.cluster.datastore.model.TestModel;
 import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadWriteTransaction;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 
 public class WriteModificationTest extends AbstractModificationTest{
 
-  @Test
-  public void testApply() throws Exception {
-    //Write something into the datastore
-    DOMStoreReadWriteTransaction writeTransaction = store.newReadWriteTransaction();
-    WriteModification writeModification = new WriteModification(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME), TestModel.createTestContext());
-    writeModification.apply(writeTransaction);
-    commitTransaction(writeTransaction);
+    @Test
+    public void testApply() throws Exception {
+        //Write something into the datastore
+        DOMStoreReadWriteTransaction writeTransaction = store.newReadWriteTransaction();
+        WriteModification writeModification = new WriteModification(TestModel.TEST_PATH,
+                ImmutableNodes.containerNode(TestModel.TEST_QNAME), TestModel.createTestContext());
+        writeModification.apply(writeTransaction);
+        commitTransaction(writeTransaction);
 
-    //Check if it's in the datastore
-    Optional<NormalizedNode<?,?>> data = readData(TestModel.TEST_PATH);
-    Assert.assertTrue(data.isPresent());
+        //Check if it's in the datastore
+        Optional<NormalizedNode<?,?>> data = readData(TestModel.TEST_PATH);
+        Assert.assertTrue(data.isPresent());
+    }
 
-  }
+    @Test
+    public void testSerialization() {
+        SchemaContext schemaContext = TestModel.createTestContext();
+        NormalizedNode<?, ?> node = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
+        WriteModification writeModification = new WriteModification(TestModel.TEST_PATH,
+                node, schemaContext);
+
+        Object serialized = writeModification.toSerializable();
+
+        WriteModification newModification = WriteModification.fromSerializable(serialized, schemaContext);
+
+        Assert.assertEquals("getPath", TestModel.TEST_PATH, newModification.getPath());
+        Assert.assertEquals("getData", node, newModification.getData());
+    }
 }
index be8713c..2300f9d 100644 (file)
@@ -12,7 +12,6 @@ import junit.framework.Assert;
 import org.junit.Test;
 import org.opendaylight.controller.cluster.datastore.node.NormalizedNodeToNodeCodec;
 import org.opendaylight.controller.protobuff.messages.common.NormalizedNodeMessages;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 
 public class SampleModelsTest {
@@ -23,14 +22,12 @@ public class SampleModelsTest {
 
         final NormalizedNodeMessages.Container node =
             new NormalizedNodeToNodeCodec(SchemaContextHelper.full())
-                .encode(YangInstanceIdentifier.of(PeopleModel.BASE_QNAME),
-                    expected);
+                .encode(expected);
 
         final NormalizedNodeMessages.Node normalizedNode =
             node.getNormalizedNode();
 
-        final NormalizedNode<?,?> actual = new NormalizedNodeToNodeCodec(SchemaContextHelper.full()).decode(YangInstanceIdentifier.of(PeopleModel.BASE_QNAME),
-            normalizedNode);
+        final NormalizedNode<?,?> actual = new NormalizedNodeToNodeCodec(SchemaContextHelper.full()).decode(normalizedNode);
 
 
         Assert.assertEquals(expected, actual);
@@ -45,14 +42,12 @@ public class SampleModelsTest {
 
         final NormalizedNodeMessages.Container node =
             new NormalizedNodeToNodeCodec(SchemaContextHelper.full())
-                .encode(YangInstanceIdentifier.of(CarsModel.BASE_QNAME),
-                    expected);
+                .encode(expected);
 
         final NormalizedNodeMessages.Node normalizedNode =
             node.getNormalizedNode();
 
         final NormalizedNode<?,?> actual = new NormalizedNodeToNodeCodec(SchemaContextHelper.full()).decode(
-            YangInstanceIdentifier.of(CarsModel.BASE_QNAME),
             normalizedNode);
 
 

©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.