From efe209e4ffdd06a0697c879d6468182a45b0c2e2 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Thu, 17 Sep 2015 05:42:46 +0200 Subject: [PATCH] BUG-2399: take into account new ModificationTypes 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 --- .../datastore/DataTreeCandidatePayload.java | 47 +++++++++++++++---- .../ModifiedDataTreeCandidateNode.java | 10 ++-- .../CandidateListChangeListener.java | 9 ++-- .../impl/ResolveDataChangeEventsTask.java | 6 ++- 4 files changed, 54 insertions(+), 18 deletions(-) diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DataTreeCandidatePayload.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DataTreeCandidatePayload.java index c77aef938e..bc3d7b02f8 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DataTreeCandidatePayload.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DataTreeCandidatePayload.java @@ -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 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 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: diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ModifiedDataTreeCandidateNode.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ModifiedDataTreeCandidateNode.java index 208ec33967..44038ecd0a 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ModifiedDataTreeCandidateNode.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ModifiedDataTreeCandidateNode.java @@ -22,13 +22,13 @@ import org.opendaylight.yangtools.yang.data.api.schema.tree.ModificationType; abstract class ModifiedDataTreeCandidateNode extends AbstractDataTreeCandidateNode { private final Collection children; - private ModifiedDataTreeCandidateNode(final Collection children) { - super(ModificationType.SUBTREE_MODIFIED); + private ModifiedDataTreeCandidateNode(final ModificationType type, final Collection children) { + super(type); this.children = Preconditions.checkNotNull(children); } static DataTreeCandidateNode create(final Collection 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 children) { - return new ModifiedDataTreeCandidateNode(children) { + static DataTreeCandidateNode create(final PathArgument identifier, final ModificationType type, final Collection children) { + return new ModifiedDataTreeCandidateNode(type, children) { @Override public final PathArgument getIdentifier() { return identifier; diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/entityownership/CandidateListChangeListener.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/entityownership/CandidateListChangeListener.java index bd41ebe942..1ee6b6c471 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/entityownership/CandidateListChangeListener.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/entityownership/CandidateListChangeListener.java @@ -66,8 +66,9 @@ class CandidateListChangeListener implements DOMDataTreeChangeListener { public void onDataTreeChanged(Collection 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 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 currentCandidates = removeFromCurrentCandidates(entityId, candidate); @@ -126,4 +127,4 @@ class CandidateListChangeListener implements DOMDataTreeChangeListener { return YangInstanceIdentifier.create(newPathArgs); } -} \ No newline at end of file +} diff --git a/opendaylight/md-sal/sal-inmemory-datastore/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/ResolveDataChangeEventsTask.java b/opendaylight/md-sal/sal-inmemory-datastore/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/ResolveDataChangeEventsTask.java index 5c7ff7df1e..e1eebe65ab 100644 --- a/opendaylight/md-sal/sal-inmemory-datastore/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/ResolveDataChangeEventsTask.java +++ b/opendaylight/md-sal/sal-inmemory-datastore/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/ResolveDataChangeEventsTask.java @@ -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; } -- 2.36.6