Search in sources :

Example 26 with PathArgument

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);
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification) DataTreeCandidate(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate) DataTreeCandidateNode(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode) PathArgument(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument) SchemaValidationFailedException(org.opendaylight.yangtools.yang.data.impl.schema.tree.SchemaValidationFailedException)

Example 27 with PathArgument

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);
    }
}
Also used : DataTreeCandidateNode(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode) PathArgument(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument)

Example 28 with PathArgument

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);
}
Also used : QName(org.opendaylight.yangtools.yang.common.QName) ArrayList(java.util.ArrayList) PathArgument(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument) NodeIdentifierWithPredicates(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates)

Example 29 with PathArgument

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));
}
Also used : DataTree(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree) GetShardDataTree(org.opendaylight.controller.cluster.datastore.messages.GetShardDataTree) DataContainerChild(org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild) PathArgument(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument) MemberName(org.opendaylight.controller.cluster.access.concepts.MemberName) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)

Example 30 with PathArgument

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);
}
Also used : QName(org.opendaylight.yangtools.yang.common.QName) DOMEntity(org.opendaylight.mdsal.eos.dom.api.DOMEntity) PathArgument(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument) NodeIdentifierWithPredicates(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)

Aggregations

PathArgument (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument)55 DataContainerChild (org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild)31 UnkeyedListEntryNode (org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode)18 ArrayList (java.util.ArrayList)17 Set (java.util.Set)12 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)11 NodeIdentifierWithPredicates (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates)11 UnkeyedListNode (org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode)6 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)5 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)4 Test (org.junit.Test)3 AbstractDataTreeModificationCursor (org.opendaylight.controller.cluster.datastore.util.AbstractDataTreeModificationCursor)3 DataNormalizationException (org.opendaylight.controller.md.sal.common.impl.util.compat.DataNormalizationException)3 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)3 DataTreeCandidate (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate)3 DataTreeCandidateNode (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode)3 DataTreeModification (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification)3 ImmutableList (com.google.common.collect.ImmutableList)2 TransactionDelete (org.opendaylight.controller.cluster.access.commands.TransactionDelete)2 TransactionMerge (org.opendaylight.controller.cluster.access.commands.TransactionMerge)2