use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate in project controller by opendaylight.
the class PruningDataTreeModificationTest method testMergeWithValidNamespaceAndInvalidNodeName.
@Test
public void testMergeWithValidNamespaceAndInvalidNodeName() throws DataValidationFailedException {
NormalizedNode<?, ?> normalizedNode = ImmutableNodes.containerNode(INVALID_TEST_QNAME);
YangInstanceIdentifier path = INVALID_TEST_PATH;
pruningDataTreeModification.merge(path, normalizedNode);
verify(mockModification, times(1)).merge(path, normalizedNode);
DataTreeCandidate candidate = getCandidate();
assertEquals("getModificationType", ModificationType.UNMODIFIED, candidate.getRootNode().getModificationType());
}
use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate in project controller by opendaylight.
the class MockDataTreeChangeListener method waitForChangeEvents.
@SuppressWarnings({ "unchecked", "rawtypes" })
public void waitForChangeEvents(final YangInstanceIdentifier... expPaths) {
boolean done = Uninterruptibles.awaitUninterruptibly(changeLatch, 5, TimeUnit.SECONDS);
if (!done) {
fail(String.format("Missing change notifications. Expected: %d. Actual: %d", expChangeEventCount, expChangeEventCount - changeLatch.getCount()));
}
for (int i = 0; i < expPaths.length; i++) {
final DataTreeCandidate candidate = changeList.get(i);
final Optional<NormalizedNode<?, ?>> maybeDataAfter = candidate.getRootNode().getDataAfter();
if (!maybeDataAfter.isPresent()) {
fail(String.format("Change %d does not contain data after. Actual: %s", i + 1, candidate.getRootNode()));
}
final NormalizedNode<?, ?> dataAfter = maybeDataAfter.get();
final Optional<YangInstanceIdentifier> relativePath = expPaths[i].relativeTo(candidate.getRootPath());
if (!relativePath.isPresent()) {
assertEquals(String.format("Change %d does not contain %s. Actual: %s", i + 1, expPaths[i], dataAfter), expPaths[i].getLastPathArgument(), dataAfter.getIdentifier());
} else {
NormalizedNode<?, ?> nextChild = dataAfter;
for (PathArgument pathArg : relativePath.get().getPathArguments()) {
boolean found = false;
if (nextChild instanceof NormalizedNodeContainer) {
Optional<NormalizedNode<?, ?>> maybeChild = ((NormalizedNodeContainer) nextChild).getChild(pathArg);
if (maybeChild.isPresent()) {
found = true;
nextChild = maybeChild.get();
}
}
if (!found) {
fail(String.format("Change %d does not contain %s. Actual: %s", i + 1, expPaths[i], dataAfter));
}
}
}
}
}
use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate in project controller by opendaylight.
the class DistributedShardChangePublisher method applyChanges.
synchronized DataTreeCandidate applyChanges(final YangInstanceIdentifier listenerPath, final Collection<DataTreeCandidate> changes) throws DataValidationFailedException {
final DataTreeModification modification = dataTree.takeSnapshot().newModification();
for (final DataTreeCandidate change : changes) {
try {
DataTreeCandidates.applyToModification(modification, change);
} catch (SchemaValidationFailedException e) {
LOG.error("Validation failed {}", e);
}
}
modification.ready();
final DataTreeCandidate candidate;
dataTree.validate(modification);
// strip nodes we dont need since this listener doesn't have to be registered at the root of the DataTree
candidate = dataTree.prepare(modification);
dataTree.commit(candidate);
DataTreeCandidateNode modifiedChild = candidate.getRootNode();
for (final PathArgument pathArgument : listenerPath.getPathArguments()) {
modifiedChild = modifiedChild.getModifiedChild(pathArgument);
}
if (modifiedChild == null) {
modifiedChild = new EmptyDataTreeCandidateNode(dataTree.getRootPath().getLastPathArgument());
}
return DataTreeCandidates.newDataTreeCandidate(dataTree.getRootPath(), modifiedChild);
}
use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate in project controller by opendaylight.
the class EntityOwnershipStatistics method onDataTreeChanged.
@Override
public void onDataTreeChanged(@Nonnull final Collection<DataTreeCandidate> changes) {
for (DataTreeCandidate change : changes) {
DataTreeCandidateNode changeRoot = change.getRootNode();
LeafNode<?> ownerLeaf = (LeafNode<?>) changeRoot.getDataAfter().get();
String entityType = entityTypeFromEntityPath(change.getRootPath());
String newOwner = extractOwner(ownerLeaf);
if (!Strings.isNullOrEmpty(newOwner)) {
updateStatistics(entityType, newOwner, 1);
}
Optional<NormalizedNode<?, ?>> dataBefore = changeRoot.getDataBefore();
if (dataBefore.isPresent()) {
String origOwner = extractOwner((LeafNode<?>) changeRoot.getDataBefore().get());
if (!Strings.isNullOrEmpty(origOwner)) {
updateStatistics(entityType, origOwner, -1);
}
}
}
}
use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate in project controller by opendaylight.
the class EntityOwnerChangeListener method onDataTreeChanged.
@Override
public void onDataTreeChanged(final Collection<DataTreeCandidate> changes) {
for (DataTreeCandidate change : changes) {
DataTreeCandidateNode changeRoot = change.getRootNode();
LeafNode<?> ownerLeaf = (LeafNode<?>) changeRoot.getDataAfter().get();
LOG.debug("{}: Entity node changed: {}, {}", logId(), changeRoot.getModificationType(), change.getRootPath());
String newOwner = extractOwner(ownerLeaf);
String origOwner = null;
Optional<NormalizedNode<?, ?>> dataBefore = changeRoot.getDataBefore();
if (dataBefore.isPresent()) {
origOwner = extractOwner((LeafNode<?>) changeRoot.getDataBefore().get());
}
LOG.debug("{}: New owner: {}, Original owner: {}", logId(), newOwner, origOwner);
if (!Objects.equals(origOwner, newOwner)) {
boolean isOwner = localMemberName.equals(newOwner);
boolean wasOwner = localMemberName.equals(origOwner);
boolean hasOwner = !Strings.isNullOrEmpty(newOwner);
DOMEntity entity = createEntity(change.getRootPath());
LOG.debug("{}: Calling notifyEntityOwnershipListeners: entity: {}, wasOwner: {}, isOwner: {}, hasOwner: {}", logId(), entity, wasOwner, isOwner, hasOwner);
publisher.notifyEntityOwnershipListeners(entity, wasOwner, isOwner, hasOwner);
}
}
}
Aggregations