use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument 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.YangInstanceIdentifier.PathArgument 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.YangInstanceIdentifier.PathArgument in project controller by opendaylight.
the class CandidateListChangeListener method extractEntityPath.
private static YangInstanceIdentifier extractEntityPath(YangInstanceIdentifier candidatePath) {
List<PathArgument> newPathArgs = new ArrayList<>();
for (PathArgument pathArg : candidatePath.getPathArguments()) {
newPathArgs.add(pathArg);
if (pathArg instanceof NodeIdentifierWithPredicates) {
NodeIdentifierWithPredicates nodeKey = (NodeIdentifierWithPredicates) pathArg;
Entry<QName, Object> key = nodeKey.getKeyValues().entrySet().iterator().next();
if (ENTITY_ID_QNAME.equals(key.getKey())) {
break;
}
}
}
return YangInstanceIdentifier.create(newPathArgs);
}
use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument in project controller by opendaylight.
the class DistributedEntityOwnershipService method getOwnershipState.
@Override
public Optional<EntityOwnershipState> getOwnershipState(final DOMEntity forEntity) {
Preconditions.checkNotNull(forEntity, "forEntity cannot be null");
DataTree dataTree = getLocalEntityOwnershipShardDataTree();
if (dataTree == null) {
return Optional.absent();
}
java.util.Optional<NormalizedNode<?, ?>> entityNode = dataTree.takeSnapshot().readNode(entityPath(forEntity.getType(), forEntity.getIdentifier()));
if (!entityNode.isPresent()) {
return Optional.absent();
}
// Check if there are any candidates, if there are none we do not really have ownership state
final MapEntryNode entity = (MapEntryNode) entityNode.get();
final java.util.Optional<DataContainerChild<? extends PathArgument, ?>> optionalCandidates = entity.getChild(CANDIDATE_NODE_ID);
final boolean hasCandidates = optionalCandidates.isPresent() && ((MapNode) optionalCandidates.get()).getValue().size() > 0;
if (!hasCandidates) {
return Optional.absent();
}
MemberName localMemberName = context.getCurrentMemberName();
java.util.Optional<DataContainerChild<? extends PathArgument, ?>> ownerLeaf = entity.getChild(ENTITY_OWNER_NODE_ID);
String owner = ownerLeaf.isPresent() ? ownerLeaf.get().getValue().toString() : null;
boolean hasOwner = !Strings.isNullOrEmpty(owner);
boolean isOwner = hasOwner && localMemberName.getName().equals(owner);
return Optional.of(EntityOwnershipState.from(isOwner, hasOwner));
}
use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument in project controller by opendaylight.
the class EntityOwnersModel method createEntity.
static DOMEntity createEntity(final YangInstanceIdentifier entityPath) {
String entityType = null;
YangInstanceIdentifier entityId = null;
for (PathArgument pathArg : entityPath.getPathArguments()) {
if (pathArg instanceof NodeIdentifierWithPredicates) {
NodeIdentifierWithPredicates nodeKey = (NodeIdentifierWithPredicates) pathArg;
Entry<QName, Object> key = nodeKey.getKeyValues().entrySet().iterator().next();
if (ENTITY_TYPE_QNAME.equals(key.getKey())) {
entityType = key.getValue().toString();
} else if (ENTITY_ID_QNAME.equals(key.getKey())) {
entityId = (YangInstanceIdentifier) key.getValue();
}
}
}
return new DOMEntity(entityType, entityId);
}
Aggregations