use of org.opendaylight.yangtools.yang.data.api.schema.tree.ModificationType in project controller by opendaylight.
the class CandidateListChangeListener method onDataTreeChanged.
@Override
public void onDataTreeChanged(Collection<DataTreeCandidate> changes) {
for (DataTreeCandidate change : changes) {
DataTreeCandidateNode changeRoot = change.getRootNode();
ModificationType type = changeRoot.getModificationType();
LOG.debug("{}: Candidate node changed: {}, {}", logId, type, change.getRootPath());
NodeIdentifierWithPredicates candidateKey = (NodeIdentifierWithPredicates) change.getRootPath().getLastPathArgument();
String candidate = candidateKey.getKeyValues().get(CANDIDATE_NAME_QNAME).toString();
YangInstanceIdentifier entityId = extractEntityPath(change.getRootPath());
if (type == ModificationType.WRITE || type == ModificationType.APPEARED) {
LOG.debug("{}: Candidate {} was added for entity {}", logId, candidate, entityId);
Collection<String> newCandidates = addToCurrentCandidates(entityId, candidate);
shard.tell(new CandidateAdded(entityId, candidate, new ArrayList<>(newCandidates)), shard);
} else if (type == ModificationType.DELETE || type == ModificationType.DISAPPEARED) {
LOG.debug("{}: Candidate {} was removed for entity {}", logId, candidate, entityId);
Collection<String> newCandidates = removeFromCurrentCandidates(entityId, candidate);
shard.tell(new CandidateRemoved(entityId, candidate, new ArrayList<>(newCandidates)), shard);
}
}
}
use of org.opendaylight.yangtools.yang.data.api.schema.tree.ModificationType in project controller by opendaylight.
the class ShardDataTreeTest method testListenerNotifiedOnApplySnapshot.
@Test
public void testListenerNotifiedOnApplySnapshot() throws Exception {
immediatePayloadReplication(shardDataTree, mockShard);
DOMDataTreeChangeListener listener = mock(DOMDataTreeChangeListener.class);
shardDataTree.registerTreeChangeListener(CarsModel.CAR_LIST_PATH.node(CarsModel.CAR_QNAME), listener, com.google.common.base.Optional.absent(), noop -> {
});
addCar(shardDataTree, "optima");
verifyOnDataTreeChanged(listener, dtc -> {
assertEquals("getModificationType", ModificationType.WRITE, dtc.getRootNode().getModificationType());
assertEquals("getRootPath", CarsModel.newCarPath("optima"), dtc.getRootPath());
});
addCar(shardDataTree, "sportage");
verifyOnDataTreeChanged(listener, dtc -> {
assertEquals("getModificationType", ModificationType.WRITE, dtc.getRootNode().getModificationType());
assertEquals("getRootPath", CarsModel.newCarPath("sportage"), dtc.getRootPath());
});
ShardDataTree newDataTree = new ShardDataTree(mockShard, fullSchema, TreeType.OPERATIONAL);
immediatePayloadReplication(newDataTree, mockShard);
addCar(newDataTree, "optima");
addCar(newDataTree, "murano");
shardDataTree.applySnapshot(newDataTree.takeStateSnapshot());
Map<YangInstanceIdentifier, ModificationType> expChanges = Maps.newHashMap();
expChanges.put(CarsModel.newCarPath("optima"), ModificationType.WRITE);
expChanges.put(CarsModel.newCarPath("murano"), ModificationType.WRITE);
expChanges.put(CarsModel.newCarPath("sportage"), ModificationType.DELETE);
verifyOnDataTreeChanged(listener, dtc -> {
ModificationType expType = expChanges.remove(dtc.getRootPath());
assertNotNull("Got unexpected change for " + dtc.getRootPath(), expType);
assertEquals("getModificationType", expType, dtc.getRootNode().getModificationType());
});
if (!expChanges.isEmpty()) {
fail("Missing change notifications: " + expChanges);
}
}
use of org.opendaylight.yangtools.yang.data.api.schema.tree.ModificationType in project controller by opendaylight.
the class ResolveDataChangeEventsTask method resolveAnyChangeEvent.
/**
* Resolves data change event for supplied node.
*
* @param path
* Path to current node in tree
* @param listeners
* Collection of Listener registration nodes interested in
* subtree
* @param modification
* Modification of current node
* @param before
* - Original (before) state of current node
* @param after
* - After state of current node
* @return True if the subtree changed, false otherwise
*/
private boolean resolveAnyChangeEvent(final ResolveDataChangeState state, final DataTreeCandidateNode node) {
final Optional<NormalizedNode<?, ?>> maybeBefore = node.getDataBefore();
final Optional<NormalizedNode<?, ?>> maybeAfter = node.getDataAfter();
final ModificationType type = node.getModificationType();
if (type != ModificationType.UNMODIFIED && !maybeAfter.isPresent() && !maybeBefore.isPresent()) {
LOG.debug("Modification at {} has type {}, but no before- and after-data. Assuming unchanged.", state.getPath(), type);
return false;
}
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);
if (!maybeBefore.isPresent()) {
@SuppressWarnings({ "unchecked", "rawtypes" }) final NormalizedNode<PathArgument, ?> afterNode = (NormalizedNode) maybeAfter.get();
resolveSameEventRecursivelly(state, afterNode, DOMImmutableDataChangeEvent.getCreateEventFactory());
return true;
}
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);
@SuppressWarnings({ "unchecked", "rawtypes" }) final NormalizedNode<PathArgument, ?> beforeNode = (NormalizedNode) maybeBefore.get();
resolveSameEventRecursivelly(state, beforeNode, DOMImmutableDataChangeEvent.getRemoveEventFactory());
return true;
case UNMODIFIED:
return false;
default:
break;
}
throw new IllegalStateException(String.format("Unhandled node state %s at %s", type, state.getPath()));
}
Aggregations