use of org.opendaylight.controller.cluster.datastore.modification.Modification in project controller by opendaylight.
the class EntityOwnershipShard method onVotingStateChangeComplete.
@Override
protected void onVotingStateChangeComplete() {
// Re-evaluate ownership for all entities - if a member changed from voting to non-voting it should lose
// ownership and vice versa it now is a candidate to become owner.
final List<Modification> modifications = new ArrayList<>();
searchForEntities((entityTypeNode, entityNode) -> {
YangInstanceIdentifier entityPath = YangInstanceIdentifier.builder(ENTITY_TYPES_PATH).node(entityTypeNode.getIdentifier()).node(ENTITY_NODE_ID).node(entityNode.getIdentifier()).node(ENTITY_OWNER_NODE_ID).build();
java.util.Optional<String> possibleOwner = entityNode.getChild(ENTITY_OWNER_NODE_ID).map(node -> node.getValue().toString());
String newOwner = newOwner(possibleOwner.orElse(null), getCandidateNames(entityNode), getEntityOwnerElectionStrategy(entityPath));
if (!newOwner.equals(possibleOwner.orElse(""))) {
modifications.add(new WriteModification(entityPath, ImmutableNodes.leafNode(ENTITY_OWNER_NODE_ID, newOwner)));
}
});
commitCoordinator.commitModifications(modifications, this);
}
use of org.opendaylight.controller.cluster.datastore.modification.Modification in project controller by opendaylight.
the class EntityOwnershipShardCommitCoordinator method pruneModifications.
@Nullable
private BatchedModifications pruneModifications(BatchedModifications toPrune) {
BatchedModifications prunedModifications = new BatchedModifications(toPrune.getTransactionId(), toPrune.getVersion());
prunedModifications.setDoCommitOnReady(toPrune.isDoCommitOnReady());
prunedModifications.setReady(toPrune.isReady());
prunedModifications.setTotalMessagesSent(toPrune.getTotalMessagesSent());
for (Modification mod : toPrune.getModifications()) {
if (canForwardModificationToNewLeader(mod)) {
prunedModifications.addModification(mod);
}
}
return !prunedModifications.getModifications().isEmpty() ? prunedModifications : null;
}
Aggregations