BUG-2399: take into account new ModificationTypes 10/27110/5
authorRobert Varga <rovarga@cisco.com>
Thu, 17 Sep 2015 03:42:46 +0000 (05:42 +0200)
committerFlavio Fernandes <ffernand@redhat.com>
Thu, 17 Sep 2015 19:55:56 +0000 (15:55 -0400)
When structural containers come and go we can see APPEARED/DISAPPEARED
events.

Patch set 5: fix build

Change-Id: Ic3da43398163a01e21adc013586949026075e3c0
Signed-off-by: Robert Varga <rovarga@cisco.com>
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DataTreeCandidatePayload.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ModifiedDataTreeCandidateNode.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/entityownership/CandidateListChangeListener.java
opendaylight/md-sal/sal-inmemory-datastore/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/ResolveDataChangeEventsTask.java

index c77aef938ec3c60adb3d21f02159cbcc59829a0b..bc3d7b02f8dda76d57f91a57ad7d30b3e98bc671 100644 (file)
@@ -32,6 +32,7 @@ import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNodes;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidates;
+import org.opendaylight.yangtools.yang.data.api.schema.tree.ModificationType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -42,6 +43,8 @@ final class DataTreeCandidatePayload extends Payload implements Externalizable {
     private static final byte SUBTREE_MODIFIED = 1;
     private static final byte UNMODIFIED = 2;
     private static final byte WRITE = 3;
+    private static final byte APPEARED = 4;
+    private static final byte DISAPPEARED = 5;
 
     private transient byte[] serialized;
 
@@ -64,10 +67,20 @@ final class DataTreeCandidatePayload extends Payload implements Externalizable {
     private static void writeNode(final NormalizedNodeOutputStreamWriter writer, final DataOutput out,
             final DataTreeCandidateNode node) throws IOException {
         switch (node.getModificationType()) {
+        case APPEARED:
+            out.writeByte(APPEARED);
+            writer.writePathArgument(node.getIdentifier());
+            writeChildren(writer, out, node.getChildNodes());
+            break;
         case DELETE:
             out.writeByte(DELETE);
             writer.writePathArgument(node.getIdentifier());
             break;
+        case DISAPPEARED:
+            out.writeByte(DISAPPEARED);
+            writer.writePathArgument(node.getIdentifier());
+            writeChildren(writer, out, node.getChildNodes());
+            break;
         case SUBTREE_MODIFIED:
             out.writeByte(SUBTREE_MODIFIED);
             writer.writePathArgument(node.getIdentifier());
@@ -92,9 +105,17 @@ final class DataTreeCandidatePayload extends Payload implements Externalizable {
 
             final DataTreeCandidateNode node = candidate.getRootNode();
             switch (node.getModificationType()) {
+            case APPEARED:
+                out.writeByte(APPEARED);
+                writeChildren(writer, out, node.getChildNodes());
+                break;
             case DELETE:
                 out.writeByte(DELETE);
                 break;
+            case DISAPPEARED:
+                out.writeByte(DISAPPEARED);
+                writeChildren(writer, out, node.getChildNodes());
+                break;
             case SUBTREE_MODIFIED:
                 out.writeByte(SUBTREE_MODIFIED);
                 writeChildren(writer, out, node.getChildNodes());
@@ -135,21 +156,31 @@ final class DataTreeCandidatePayload extends Payload implements Externalizable {
         }
     }
 
+    private static DataTreeCandidateNode readModifiedNode(final ModificationType type,
+            final NormalizedNodeInputStreamReader reader, final DataInput in) throws IOException {
+
+        final PathArgument identifier = reader.readPathArgument();
+        final Collection<DataTreeCandidateNode> children = readChildren(reader, in);
+        if (children.isEmpty()) {
+            LOG.debug("Modified node {} does not have any children, not instantiating it", identifier);
+            return null;
+        } else {
+            return ModifiedDataTreeCandidateNode.create(identifier, type, children);
+        }
+    }
+
     private static DataTreeCandidateNode readNode(final NormalizedNodeInputStreamReader reader,
             final DataInput in) throws IOException {
         final byte type = in.readByte();
         switch (type) {
+        case APPEARED:
+            return readModifiedNode(ModificationType.APPEARED, reader, in);
         case DELETE:
             return DeletedDataTreeCandidateNode.create(reader.readPathArgument());
+        case DISAPPEARED:
+            return readModifiedNode(ModificationType.DISAPPEARED, reader, in);
         case SUBTREE_MODIFIED:
-            final PathArgument identifier = reader.readPathArgument();
-            final Collection<DataTreeCandidateNode> children = readChildren(reader, in);
-            if (children.isEmpty()) {
-                LOG.debug("Modified node {} does not have any children, not instantiating it", identifier);
-                return null;
-            } else {
-                return ModifiedDataTreeCandidateNode.create(identifier, children);
-            }
+            return readModifiedNode(ModificationType.SUBTREE_MODIFIED, reader, in);
         case UNMODIFIED:
             return null;
         case WRITE:
index 208ec33967ffe50c9f5d96d4a643cf74a2f5cb90..44038ecd0ab6df29249ac3e0500ab322d89847fd 100644 (file)
@@ -22,13 +22,13 @@ import org.opendaylight.yangtools.yang.data.api.schema.tree.ModificationType;
 abstract class ModifiedDataTreeCandidateNode extends AbstractDataTreeCandidateNode {
     private final Collection<DataTreeCandidateNode> children;
 
-    private ModifiedDataTreeCandidateNode(final Collection<DataTreeCandidateNode> children) {
-        super(ModificationType.SUBTREE_MODIFIED);
+    private ModifiedDataTreeCandidateNode(final ModificationType type, final Collection<DataTreeCandidateNode> children) {
+        super(type);
         this.children = Preconditions.checkNotNull(children);
     }
 
     static DataTreeCandidateNode create(final Collection<DataTreeCandidateNode> children) {
-        return new ModifiedDataTreeCandidateNode(children) {
+        return new ModifiedDataTreeCandidateNode(ModificationType.SUBTREE_MODIFIED, children) {
             @Override
             public PathArgument getIdentifier() {
                 throw new UnsupportedOperationException("Root node does not have an identifier");
@@ -36,8 +36,8 @@ abstract class ModifiedDataTreeCandidateNode extends AbstractDataTreeCandidateNo
         };
     }
 
-    static DataTreeCandidateNode create(final PathArgument identifier, final Collection<DataTreeCandidateNode> children) {
-        return new ModifiedDataTreeCandidateNode(children) {
+    static DataTreeCandidateNode create(final PathArgument identifier, final ModificationType type, final Collection<DataTreeCandidateNode> children) {
+        return new ModifiedDataTreeCandidateNode(type, children) {
             @Override
             public final PathArgument getIdentifier() {
                 return identifier;
index bd41ebe94292a00d13097fc86251f39edead582e..1ee6b6c47184f4b6c2f517c374f81dbda38f7f16 100644 (file)
@@ -66,8 +66,9 @@ class CandidateListChangeListener implements DOMDataTreeChangeListener {
     public void onDataTreeChanged(Collection<DataTreeCandidate> changes) {
         for(DataTreeCandidate change: changes) {
             DataTreeCandidateNode changeRoot = change.getRootNode();
+            ModificationType type = changeRoot.getModificationType();
 
-            LOG.debug("{}: Candidate node changed: {}, {}", logId, changeRoot.getModificationType(), change.getRootPath());
+            LOG.debug("{}: Candidate node changed: {}, {}", logId, type, change.getRootPath());
 
             NodeIdentifierWithPredicates candidateKey =
                     (NodeIdentifierWithPredicates) change.getRootPath().getLastPathArgument();
@@ -75,12 +76,12 @@ class CandidateListChangeListener implements DOMDataTreeChangeListener {
 
             YangInstanceIdentifier entityId = extractEntityPath(change.getRootPath());
 
-            if(changeRoot.getModificationType() == ModificationType.WRITE) {
+            if(type == ModificationType.WRITE || type == ModificationType.APPEARED) {
                 LOG.debug("{}: Candidate {} was added for entity {}", logId, candidate, entityId);
 
                 Collection<String> currentCandidates = addToCurrentCandidates(entityId, candidate);
                 shard.tell(new CandidateAdded(entityId, candidate, new ArrayList<>(currentCandidates)), shard);
-            } else if(changeRoot.getModificationType() == ModificationType.DELETE) {
+            } else if(type == ModificationType.DELETE || type == ModificationType.DISAPPEARED) {
                 LOG.debug("{}: Candidate {} was removed for entity {}", logId, candidate, entityId);
 
                 Collection<String> currentCandidates = removeFromCurrentCandidates(entityId, candidate);
@@ -126,4 +127,4 @@ class CandidateListChangeListener implements DOMDataTreeChangeListener {
 
         return YangInstanceIdentifier.create(newPathArgs);
     }
-}
\ No newline at end of file
+}
index 5c7ff7df1ee0b6e14abcc2849a112bdb7af304c1..e1eebe65ab5d597d2be9ce9f21816f0cf9de49be 100644 (file)
@@ -118,6 +118,7 @@ public final class ResolveDataChangeEventsTask {
         switch (type) {
         case SUBTREE_MODIFIED:
             return resolveSubtreeChangeEvent(state, node);
+        case APPEARED:
         case WRITE:
             Preconditions.checkArgument(maybeAfter.isPresent(),
                     "Modification at {} has type {} but no after-data", state.getPath(), type);
@@ -129,6 +130,7 @@ public final class ResolveDataChangeEventsTask {
             }
 
             return resolveReplacedEvent(state, maybeBefore.get(), maybeAfter.get());
+        case DISAPPEARED:
         case DELETE:
             Preconditions.checkArgument(maybeBefore.isPresent(),
                     "Modification at {} has type {} but no before-data", state.getPath(), type);
@@ -277,8 +279,10 @@ public final class ResolveDataChangeEventsTask {
             final ResolveDataChangeState childState = state.child(childMod.getIdentifier());
 
             switch (childMod.getModificationType()) {
-            case WRITE:
+            case APPEARED:
             case DELETE:
+            case DISAPPEARED:
+            case WRITE:
                 if (resolveAnyChangeEvent(childState, childMod)) {
                     scope = DataChangeScope.ONE;
                 }