use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode in project controller by opendaylight.
the class CommitTransactionPayloadTest method assertChildrenEquals.
private static void assertChildrenEquals(final Collection<DataTreeCandidateNode> expected, final Collection<DataTreeCandidateNode> actual) {
// Make sure all expected nodes are there
for (DataTreeCandidateNode exp : expected) {
final DataTreeCandidateNode act = findNode(actual, exp.getIdentifier());
assertNotNull("missing expected child", act);
assertCandidateNodeEquals(exp, act);
}
// Make sure no nodes are present which are not in the expected set
for (DataTreeCandidateNode act : actual) {
final DataTreeCandidateNode exp = findNode(expected, act.getIdentifier());
assertNull("unexpected child", exp);
}
}
use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode 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.DataTreeCandidateNode in project controller by opendaylight.
the class DataTreeCandidateInputOutput method readDataTreeCandidate.
public static DataTreeCandidate readDataTreeCandidate(final DataInput in) throws IOException {
final NormalizedNodeDataInput reader = NormalizedNodeInputOutput.newDataInput(in);
final YangInstanceIdentifier rootPath = reader.readYangInstanceIdentifier();
final byte type = reader.readByte();
final DataTreeCandidateNode rootNode;
switch(type) {
case APPEARED:
rootNode = ModifiedDataTreeCandidateNode.create(ModificationType.APPEARED, readChildren(reader));
break;
case DELETE:
rootNode = DeletedDataTreeCandidateNode.create();
break;
case DISAPPEARED:
rootNode = ModifiedDataTreeCandidateNode.create(ModificationType.DISAPPEARED, readChildren(reader));
break;
case SUBTREE_MODIFIED:
rootNode = ModifiedDataTreeCandidateNode.create(ModificationType.SUBTREE_MODIFIED, readChildren(reader));
break;
case WRITE:
rootNode = DataTreeCandidateNodes.fromNormalizedNode(reader.readNormalizedNode());
break;
case UNMODIFIED:
rootNode = AbstractDataTreeCandidateNode.createUnmodified();
break;
default:
throw new IllegalArgumentException("Unhandled node type " + type);
}
return DataTreeCandidates.newDataTreeCandidate(rootPath, rootNode);
}
use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode in project controller by opendaylight.
the class DataTreeCandidateInputOutput method readModifiedNode.
private static DataTreeCandidateNode readModifiedNode(final ModificationType type, final NormalizedNodeDataInput in) throws IOException {
final PathArgument identifier = in.readPathArgument();
final Collection<DataTreeCandidateNode> children = readChildren(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);
}
}
use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode 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);
}
}
}
}
Aggregations