Search in sources :

Example 1 with DataTreeCandidate

use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate in project controller by opendaylight.

the class NormalizedNodeAggregator method combine.

private NormalizedNodeAggregator combine() throws DataValidationFailedException {
    final DataTreeModification mod = dataTree.takeSnapshot().newModification();
    for (final Optional<NormalizedNode<?, ?>> node : nodes) {
        if (node.isPresent()) {
            mod.merge(rootIdentifier, node.get());
        }
    }
    mod.ready();
    dataTree.validate(mod);
    final DataTreeCandidate candidate = dataTree.prepare(mod);
    dataTree.commit(candidate);
    return this;
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification) DataTreeCandidate(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)

Example 2 with DataTreeCandidate

use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate in project controller by opendaylight.

the class CandidateListChangeListener method onDataTreeChanged.

@Override
public void onDataTreeChanged(Collection<DataTreeCandidate> changes) {
    for (DataTreeCandidate change : changes) {
        DataTreeCandidateNode changeRoot = change.getRootNode();
        ModificationType type = changeRoot.getModificationType();
        LOG.debug("{}: Candidate node changed: {}, {}", logId, type, change.getRootPath());
        NodeIdentifierWithPredicates candidateKey = (NodeIdentifierWithPredicates) change.getRootPath().getLastPathArgument();
        String candidate = candidateKey.getKeyValues().get(CANDIDATE_NAME_QNAME).toString();
        YangInstanceIdentifier entityId = extractEntityPath(change.getRootPath());
        if (type == ModificationType.WRITE || type == ModificationType.APPEARED) {
            LOG.debug("{}: Candidate {} was added for entity {}", logId, candidate, entityId);
            Collection<String> newCandidates = addToCurrentCandidates(entityId, candidate);
            shard.tell(new CandidateAdded(entityId, candidate, new ArrayList<>(newCandidates)), shard);
        } else if (type == ModificationType.DELETE || type == ModificationType.DISAPPEARED) {
            LOG.debug("{}: Candidate {} was removed for entity {}", logId, candidate, entityId);
            Collection<String> newCandidates = removeFromCurrentCandidates(entityId, candidate);
            shard.tell(new CandidateRemoved(entityId, candidate, new ArrayList<>(newCandidates)), shard);
        }
    }
}
Also used : DataTreeCandidate(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate) ModificationType(org.opendaylight.yangtools.yang.data.api.schema.tree.ModificationType) CandidateAdded(org.opendaylight.controller.cluster.datastore.entityownership.messages.CandidateAdded) DataTreeCandidateNode(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode) ArrayList(java.util.ArrayList) Collection(java.util.Collection) CandidateRemoved(org.opendaylight.controller.cluster.datastore.entityownership.messages.CandidateRemoved) NodeIdentifierWithPredicates(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)

Example 3 with DataTreeCandidate

use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate in project controller by opendaylight.

the class ShardDataTreeTest method testPipelinedTransactionsWithCoordinatedCommits.

@Test
public void testPipelinedTransactionsWithCoordinatedCommits() throws Exception {
    final ShardDataTreeCohort cohort1 = newShardDataTreeCohort(snapshot -> snapshot.write(CarsModel.BASE_PATH, CarsModel.emptyContainer()));
    final ShardDataTreeCohort cohort2 = newShardDataTreeCohort(snapshot -> snapshot.write(CarsModel.CAR_LIST_PATH, CarsModel.newCarMapNode()));
    NormalizedNode<?, ?> peopleNode = PeopleModel.create();
    final ShardDataTreeCohort cohort3 = newShardDataTreeCohort(snapshot -> snapshot.write(PeopleModel.BASE_PATH, peopleNode));
    YangInstanceIdentifier carPath = CarsModel.newCarPath("optima");
    MapEntryNode carNode = CarsModel.newCarEntry("optima", new BigInteger("100"));
    final ShardDataTreeCohort cohort4 = newShardDataTreeCohort(snapshot -> snapshot.write(carPath, carNode));
    immediateCanCommit(cohort1);
    final FutureCallback<Void> canCommitCallback2 = coordinatedCanCommit(cohort2);
    final FutureCallback<Void> canCommitCallback3 = coordinatedCanCommit(cohort3);
    final FutureCallback<Void> canCommitCallback4 = coordinatedCanCommit(cohort4);
    final FutureCallback<DataTreeCandidate> preCommitCallback1 = coordinatedPreCommit(cohort1);
    verify(preCommitCallback1).onSuccess(cohort1.getCandidate());
    verify(canCommitCallback2).onSuccess(null);
    final FutureCallback<DataTreeCandidate> preCommitCallback2 = coordinatedPreCommit(cohort2);
    verify(preCommitCallback2).onSuccess(cohort2.getCandidate());
    verify(canCommitCallback3).onSuccess(null);
    final FutureCallback<DataTreeCandidate> preCommitCallback3 = coordinatedPreCommit(cohort3);
    verify(preCommitCallback3).onSuccess(cohort3.getCandidate());
    verify(canCommitCallback4).onSuccess(null);
    final FutureCallback<DataTreeCandidate> preCommitCallback4 = coordinatedPreCommit(cohort4);
    verify(preCommitCallback4).onSuccess(cohort4.getCandidate());
    final FutureCallback<UnsignedLong> commitCallback2 = coordinatedCommit(cohort2);
    verify(mockShard, never()).persistPayload(eq(cohort1.getIdentifier()), any(CommitTransactionPayload.class), anyBoolean());
    verifyNoMoreInteractions(commitCallback2);
    final FutureCallback<UnsignedLong> commitCallback4 = coordinatedCommit(cohort4);
    verify(mockShard, never()).persistPayload(eq(cohort4.getIdentifier()), any(CommitTransactionPayload.class), anyBoolean());
    verifyNoMoreInteractions(commitCallback4);
    final FutureCallback<UnsignedLong> commitCallback1 = coordinatedCommit(cohort1);
    InOrder inOrder = inOrder(mockShard);
    inOrder.verify(mockShard).persistPayload(eq(cohort1.getIdentifier()), any(CommitTransactionPayload.class), eq(true));
    inOrder.verify(mockShard).persistPayload(eq(cohort2.getIdentifier()), any(CommitTransactionPayload.class), eq(false));
    verifyNoMoreInteractions(commitCallback1);
    verifyNoMoreInteractions(commitCallback2);
    final FutureCallback<UnsignedLong> commitCallback3 = coordinatedCommit(cohort3);
    inOrder = inOrder(mockShard);
    inOrder.verify(mockShard).persistPayload(eq(cohort3.getIdentifier()), any(CommitTransactionPayload.class), eq(true));
    inOrder.verify(mockShard).persistPayload(eq(cohort4.getIdentifier()), any(CommitTransactionPayload.class), eq(false));
    verifyNoMoreInteractions(commitCallback3);
    verifyNoMoreInteractions(commitCallback4);
    final ShardDataTreeCohort cohort5 = newShardDataTreeCohort(snapshot -> snapshot.merge(CarsModel.BASE_PATH, CarsModel.emptyContainer()));
    final FutureCallback<Void> canCommitCallback5 = coordinatedCanCommit(cohort5);
    // The payload instance doesn't matter - it just needs to be of type CommitTransactionPayload.
    CommitTransactionPayload mockPayload = CommitTransactionPayload.create(nextTransactionId(), cohort1.getCandidate());
    shardDataTree.applyReplicatedPayload(cohort1.getIdentifier(), mockPayload);
    shardDataTree.applyReplicatedPayload(cohort2.getIdentifier(), mockPayload);
    shardDataTree.applyReplicatedPayload(cohort3.getIdentifier(), mockPayload);
    shardDataTree.applyReplicatedPayload(cohort4.getIdentifier(), mockPayload);
    inOrder = inOrder(commitCallback1, commitCallback2, commitCallback3, commitCallback4);
    inOrder.verify(commitCallback1).onSuccess(any(UnsignedLong.class));
    inOrder.verify(commitCallback2).onSuccess(any(UnsignedLong.class));
    inOrder.verify(commitCallback3).onSuccess(any(UnsignedLong.class));
    inOrder.verify(commitCallback4).onSuccess(any(UnsignedLong.class));
    verify(canCommitCallback5).onSuccess(null);
    final DataTreeSnapshot snapshot = shardDataTree.newReadOnlyTransaction(nextTransactionId()).getSnapshot();
    Optional<NormalizedNode<?, ?>> optional = snapshot.readNode(carPath);
    assertEquals("Car node present", true, optional.isPresent());
    assertEquals("Car node", carNode, optional.get());
    optional = snapshot.readNode(PeopleModel.BASE_PATH);
    assertEquals("People node present", true, optional.isPresent());
    assertEquals("People node", peopleNode, optional.get());
}
Also used : InOrder(org.mockito.InOrder) UnsignedLong(com.google.common.primitives.UnsignedLong) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) DataTreeCandidate(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate) BigInteger(java.math.BigInteger) CommitTransactionPayload(org.opendaylight.controller.cluster.datastore.persisted.CommitTransactionPayload) DataTreeSnapshot(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) Test(org.junit.Test)

Example 4 with DataTreeCandidate

use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate in project controller by opendaylight.

the class ShardDataTreeTest method testAbortWithFailedRebase.

@SuppressWarnings("unchecked")
@Test
public void testAbortWithFailedRebase() throws Exception {
    immediatePayloadReplication(shardDataTree, mockShard);
    final ShardDataTreeCohort cohort1 = newShardDataTreeCohort(snapshot -> snapshot.write(CarsModel.BASE_PATH, CarsModel.emptyContainer()));
    final ShardDataTreeCohort cohort2 = newShardDataTreeCohort(snapshot -> snapshot.write(CarsModel.CAR_LIST_PATH, CarsModel.newCarMapNode()));
    NormalizedNode<?, ?> peopleNode = PeopleModel.create();
    final ShardDataTreeCohort cohort3 = newShardDataTreeCohort(snapshot -> snapshot.write(PeopleModel.BASE_PATH, peopleNode));
    immediateCanCommit(cohort1);
    FutureCallback<Void> canCommitCallback2 = coordinatedCanCommit(cohort2);
    coordinatedPreCommit(cohort1);
    verify(canCommitCallback2).onSuccess(null);
    FutureCallback<Void> mockAbortCallback = mock(FutureCallback.class);
    doNothing().when(mockAbortCallback).onSuccess(null);
    cohort1.abort(mockAbortCallback);
    verify(mockAbortCallback).onSuccess(null);
    FutureCallback<DataTreeCandidate> preCommitCallback2 = coordinatedPreCommit(cohort2);
    verify(preCommitCallback2).onFailure(any(Throwable.class));
    immediateCanCommit(cohort3);
    immediatePreCommit(cohort3);
    immediateCommit(cohort3);
    final DataTreeSnapshot snapshot = shardDataTree.newReadOnlyTransaction(nextTransactionId()).getSnapshot();
    Optional<NormalizedNode<?, ?>> optional = snapshot.readNode(PeopleModel.BASE_PATH);
    assertEquals("People node present", true, optional.isPresent());
    assertEquals("People node", peopleNode, optional.get());
}
Also used : DataTreeCandidate(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate) DataTreeSnapshot(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) Test(org.junit.Test)

Example 5 with DataTreeCandidate

use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate in project controller by opendaylight.

the class SimpleShardDataTreeCohortTest method preCommitSuccess.

private DataTreeCandidateTip preCommitSuccess() {
    final DataTreeCandidateTip mockCandidate = mock(DataTreeCandidateTip.class);
    doAnswer(invocation -> {
        invocation.getArgumentAt(0, SimpleShardDataTreeCohort.class).successfulPreCommit(mockCandidate);
        return null;
    }).when(mockShardDataTree).startPreCommit(cohort);
    @SuppressWarnings("unchecked") final FutureCallback<DataTreeCandidate> callback = mock(FutureCallback.class);
    cohort.preCommit(callback);
    verify(callback).onSuccess(mockCandidate);
    verifyNoMoreInteractions(callback);
    assertSame("getCandidate", mockCandidate, cohort.getCandidate());
    return mockCandidate;
}
Also used : DataTreeCandidate(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate) DataTreeCandidateTip(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateTip)

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