Search in sources :

Example 21 with DataTreeCandidateNode

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

Example 22 with DataTreeCandidateNode

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);
}
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 23 with DataTreeCandidateNode

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);
}
Also used : DataTreeCandidateNode(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode) NormalizedNodeDataInput(org.opendaylight.controller.cluster.datastore.node.utils.stream.NormalizedNodeDataInput) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)

Example 24 with DataTreeCandidateNode

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

Example 25 with DataTreeCandidateNode

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

Aggregations

DataTreeCandidateNode (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode)38 Test (org.junit.Test)18 DataTreeCandidate (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate)13 AbstractRIBSupportTest (org.opendaylight.protocol.bgp.rib.spi.AbstractRIBSupportTest)12 Routes (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.rib.tables.Routes)12 DOMDataWriteTransaction (org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction)8 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)7 CountDownLatch (java.util.concurrent.CountDownLatch)6 DOMDataTreeChangeService (org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeService)6 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)5 PathArgument (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 NodeIdentifierWithPredicates (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates)2 LeafNode (org.opendaylight.yangtools.yang.data.api.schema.LeafNode)2 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)2 DataTreeCandidateTip (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateTip)2 Collection (java.util.Collection)1 Before (org.junit.Before)1 CandidateAdded (org.opendaylight.controller.cluster.datastore.entityownership.messages.CandidateAdded)1