*/
package org.opendaylight.controller.cluster.datastore.entityownership;
-import static org.opendaylight.controller.cluster.datastore.entityownership.EntityOwnersModel.CANDIDATE_NAME_NODE_ID;
import static org.opendaylight.controller.cluster.datastore.entityownership.EntityOwnersModel.CANDIDATE_NODE_ID;
import static org.opendaylight.controller.cluster.datastore.entityownership.EntityOwnersModel.ENTITY_ID_NODE_ID;
import static org.opendaylight.controller.cluster.datastore.entityownership.EntityOwnersModel.ENTITY_ID_QNAME;
LOG.debug("{}: oldLeaderMemberName: {}", persistenceId(), oldLeaderMemberName);
if(downPeerMemberNames.contains(oldLeaderMemberName)) {
- selectNewOwnerForEntitiesOwnedBy(oldLeaderMemberName);
+ removeCandidateFromEntities(oldLeaderMemberName);
}
} else {
// The leader changed - notify the coordinator to check if pending modifications need to be sent.
commitCoordinator.onStateChanged(this, isLeader());
}
- private void selectNewOwnerForEntitiesOwnedBy(String owner) {
- final BatchedModifications modifications = commitCoordinator.newBatchedModifications();
- searchForEntitiesOwnedBy(owner, new EntityWalker() {
- @Override
- public void onEntity(MapEntryNode entityTypeNode, MapEntryNode entityNode) {
-
- YangInstanceIdentifier entityPath = YangInstanceIdentifier.builder(ENTITY_TYPES_PATH).
- node(entityTypeNode.getIdentifier()).node(ENTITY_NODE_ID).node(entityNode.getIdentifier()).
- node(ENTITY_OWNER_NODE_ID).build();
-
- String entityType = EntityOwnersModel.entityTypeFromEntityPath(entityPath);
-
- Object newOwner = newOwner(getCandidateNames(entityNode),
- entityOwnershipStatistics.byEntityType(entityType),
- getEntityOwnerElectionStrategy(entityPath));
-
- LOG.debug("{}: Found entity {}, writing new owner {}", persistenceId(), entityPath, newOwner);
-
- modifications.addModification(new WriteModification(entityPath,
- ImmutableNodes.leafNode(ENTITY_OWNER_NODE_ID, newOwner)));
- }
- });
-
- commitCoordinator.commitModifications(modifications, this);
- }
-
private void removeCandidateFromEntities(final String owner) {
final BatchedModifications modifications = commitCoordinator.newBatchedModifications();
searchForEntities(new EntityWalker() {
}
}
- private static Collection<String> getCandidateNames(MapEntryNode entity) {
- Collection<MapEntryNode> candidates = ((MapNode) entity.getChild(CANDIDATE_NODE_ID).get()).getValue();
- Collection<String> candidateNames = new ArrayList<>(candidates.size());
- for(MapEntryNode candidate: candidates) {
- candidateNames.add(candidate.getChild(CANDIDATE_NAME_NODE_ID).get().getValue().toString());
- }
-
- return candidateNames;
- }
-
private void writeNewOwner(YangInstanceIdentifier entityPath, String newOwner) {
LOG.debug("{}: Writing new owner {} for entity {}", persistenceId(), newOwner, entityPath);