use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier in project controller by opendaylight.
the class EntityOwnershipShard method removeCandidateFromEntities.
private void removeCandidateFromEntities(final MemberName member) {
final List<Modification> modifications = new ArrayList<>();
searchForEntities((entityTypeNode, entityNode) -> {
if (hasCandidate(entityNode, member)) {
YangInstanceIdentifier entityId = (YangInstanceIdentifier) entityNode.getIdentifier().getKeyValues().get(ENTITY_ID_QNAME);
YangInstanceIdentifier candidatePath = candidatePath(entityTypeNode.getIdentifier().getKeyValues().get(ENTITY_TYPE_QNAME).toString(), entityId, member.getName());
LOG.info("{}: Found entity {}, removing candidate {}, path {}", persistenceId(), entityId, member, candidatePath);
modifications.add(new DeleteModification(candidatePath));
}
});
commitCoordinator.commitModifications(modifications, this);
}
use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier 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.YangInstanceIdentifier in project controller by opendaylight.
the class DataChanged method readExternal.
@Override
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
// Read the version
in.readShort();
NormalizedNodeDataInput streamReader = NormalizedNodeInputOutput.newDataInputWithoutValidation(in);
// Note: the scope passed to builder is not actually used.
Builder builder = DOMImmutableDataChangeEvent.builder(DataChangeScope.SUBTREE);
// Read created data
int size = in.readInt();
for (int i = 0; i < size; i++) {
YangInstanceIdentifier path = streamReader.readYangInstanceIdentifier();
NormalizedNode<?, ?> node = streamReader.readNormalizedNode();
builder.addCreated(path, node);
}
// Read updated data
size = in.readInt();
for (int i = 0; i < size; i++) {
YangInstanceIdentifier path = streamReader.readYangInstanceIdentifier();
NormalizedNode<?, ?> before = streamReader.readNormalizedNode();
NormalizedNode<?, ?> after = streamReader.readNormalizedNode();
builder.addUpdated(path, before, after);
}
// Read removed data
size = in.readInt();
for (int i = 0; i < size; i++) {
YangInstanceIdentifier path = streamReader.readYangInstanceIdentifier();
NormalizedNode<?, ?> node = streamReader.readNormalizedNode();
builder.addRemoved(path, node);
}
// Read original subtree
boolean present = in.readBoolean();
if (present) {
builder.setBefore(streamReader.readNormalizedNode());
}
// Read updated subtree
present = in.readBoolean();
if (present) {
builder.setAfter(streamReader.readNormalizedNode());
}
change = builder.build();
}
use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier in project controller by opendaylight.
the class DataChanged method writeExternal.
@Override
public void writeExternal(ObjectOutput out) throws IOException {
out.writeShort(DataStoreVersions.CURRENT_VERSION);
NormalizedNodeDataOutput streamWriter = NormalizedNodeInputOutput.newDataOutput(out);
// Write created data
Map<YangInstanceIdentifier, NormalizedNode<?, ?>> createdData = change.getCreatedData();
out.writeInt(createdData.size());
for (Map.Entry<YangInstanceIdentifier, NormalizedNode<?, ?>> e : createdData.entrySet()) {
streamWriter.writeYangInstanceIdentifier(e.getKey());
streamWriter.writeNormalizedNode(e.getValue());
}
// Write updated data
Map<YangInstanceIdentifier, NormalizedNode<?, ?>> originalData = change.getOriginalData();
Map<YangInstanceIdentifier, NormalizedNode<?, ?>> updatedData = change.getUpdatedData();
out.writeInt(updatedData.size());
for (Map.Entry<YangInstanceIdentifier, NormalizedNode<?, ?>> e : updatedData.entrySet()) {
streamWriter.writeYangInstanceIdentifier(e.getKey());
streamWriter.writeNormalizedNode(originalData.get(e.getKey()));
streamWriter.writeNormalizedNode(e.getValue());
}
// Write removed data
Set<YangInstanceIdentifier> removed = change.getRemovedPaths();
out.writeInt(removed.size());
for (YangInstanceIdentifier path : removed) {
streamWriter.writeYangInstanceIdentifier(path);
streamWriter.writeNormalizedNode(originalData.get(path));
}
// Write original subtree
NormalizedNode<?, ?> originalSubtree = change.getOriginalSubtree();
out.writeBoolean(originalSubtree != null);
if (originalSubtree != null) {
streamWriter.writeNormalizedNode(originalSubtree);
}
// Write original subtree
NormalizedNode<?, ?> updatedSubtree = change.getUpdatedSubtree();
out.writeBoolean(updatedSubtree != null);
if (updatedSubtree != null) {
streamWriter.writeNormalizedNode(updatedSubtree);
}
}
use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier 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());
}
Aggregations