Search in sources :

Example 21 with DataTreeCandidate

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

Example 22 with DataTreeCandidate

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

Example 23 with DataTreeCandidate

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);
}
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 24 with DataTreeCandidate

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);
            }
        }
    }
}
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)

Example 25 with DataTreeCandidate

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);
        }
    }
}
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) DOMEntity(org.opendaylight.mdsal.eos.dom.api.DOMEntity) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)

Aggregations

DataTreeCandidate (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate)41 Test (org.junit.Test)19 DataTreeCandidateNode (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode)13 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)9 DOMDataTreeChangeService (org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeService)7 DOMDataWriteTransaction (org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction)7 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)7 CountDownLatch (java.util.concurrent.CountDownLatch)6 DataTreeModification (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification)6 ActorRef (akka.actor.ActorRef)5 DataTreeChanged (org.opendaylight.controller.cluster.datastore.messages.DataTreeChanged)5 Props (akka.actor.Props)4 TestKit (akka.testkit.javadsl.TestKit)4 DOMDataTreeChangeListener (org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener)4 NodeIdentifierWithPredicates (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates)3 PathArgument (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument)3 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)3 ConflictingModificationAppliedException (org.opendaylight.yangtools.yang.data.api.schema.tree.ConflictingModificationAppliedException)3 DataValidationFailedException (org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException)3 TransactionIdentifier (org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier)2