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