BUG-1092: adjust to YangInstanceIdentifier
[controller.git] / opendaylight / md-sal / sal-protocolbuffer-encoding / src / main / java / org / opendaylight / controller / cluster / datastore / node / NormalizedNodeToProtocolBufferNode.java
index 6b2f1bd187c1f8f9e5854ec2cb93c7d052a39444..f8ec57be8fd553fb240846628c513ff3061846a1 100644 (file)
@@ -1,9 +1,9 @@
 package org.opendaylight.controller.cluster.datastore.node;
-import com.google.common.base.Preconditions;
+
 import org.opendaylight.controller.protobuff.messages.common.NormalizedNodeMessages;
 import org.opendaylight.controller.protobuff.messages.common.NormalizedNodeMessages.Node;
 import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.AugmentationNode;
 import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
@@ -46,15 +46,21 @@ public class NormalizedNodeToProtocolBufferNode {
       parentPath = "";
     }
 
-    Preconditions.checkArgument(normalizedNode!=null);
-
-    navigateNormalizedNode(0, parentPath,normalizedNode, builderRoot);
-    // here we need to put back the Node Tree in Container
     NormalizedNodeMessages.Container.Builder containerBuilder =
         NormalizedNodeMessages.Container.newBuilder();
-    containerBuilder.setParentPath(parentPath).setNormalizedNode(
-        builderRoot.build());
-    container = containerBuilder.build();
+
+    if(normalizedNode != null) {
+
+      navigateNormalizedNode(0, parentPath, normalizedNode, builderRoot);
+      // here we need to put back the Node Tree in Container
+
+      container= containerBuilder.setParentPath(parentPath).setNormalizedNode(
+          builderRoot.build()).build();
+    }else {
+      //this can happen when an attempt was made to read from datastore and normalized node was null.
+      container = containerBuilder.setParentPath(parentPath).build();
+
+    }
 
   }
 
@@ -67,7 +73,7 @@ public class NormalizedNodeToProtocolBufferNode {
     builderParent.setPath(dataContainerNode.getIdentifier().toString())
         .setType(type);
 
-    final Iterable<DataContainerChild<? extends InstanceIdentifier.PathArgument, ?>> value =
+    final Iterable<DataContainerChild<? extends YangInstanceIdentifier.PathArgument, ?>> value =
         dataContainerNode.getValue();
     for (NormalizedNode<?, ?> node : value) {
       Node.Builder builderChild = Node.newBuilder();