use of org.opendaylight.controller.cluster.access.concepts.MemberName in project controller by opendaylight.
the class ShardedDataTreeActor method memberReachable.
private void memberReachable(final ReachableMember message) {
final MemberName memberName = memberToName(message.member());
LOG.debug("Received ReachableMember: memberName {}, address: {}", memberName, message.member().address());
resolver.addPeerAddress(memberName, message.member().address());
}
use of org.opendaylight.controller.cluster.access.concepts.MemberName in project controller by opendaylight.
the class EntityOwnershipShard method onLeaderChanged.
@Override
protected void onLeaderChanged(final String oldLeader, final String newLeader) {
boolean isLeader = isLeader();
LOG.debug("{}: onLeaderChanged: oldLeader: {}, newLeader: {}, isLeader: {}", persistenceId(), oldLeader, newLeader, isLeader);
if (isLeader) {
// Re-initialize the downPeerMemberNames from the current akka Cluster state. The previous leader, if any,
// is most likely down however it's possible we haven't received the PeerDown message yet.
initializeDownPeerMemberNamesFromClusterState();
// Clear all existing strategies so that they get re-created when we call createStrategy again
// This allows the strategies to be re-initialized with existing statistics maintained by
// EntityOwnershipStatistics
strategyConfig.clearStrategies();
// Re-assign owners for all members that are known to be down. In a cluster which has greater than
// 3 nodes it is possible for some node beside the leader being down when the leadership transitions
// it makes sense to use this event to re-assign owners for those downed nodes.
Set<String> ownedBy = new HashSet<>(downPeerMemberNames.size() + 1);
for (MemberName downPeerName : downPeerMemberNames) {
ownedBy.add(downPeerName.getName());
}
// Also try to assign owners for entities that have no current owner. See explanation in onPeerUp.
ownedBy.add("");
selectNewOwnerForEntitiesOwnedBy(ownedBy);
} else {
// The leader changed - notify the coordinator to check if pending modifications need to be sent.
// While onStateChanged also does this, this method handles the case where the shard hears from a
// leader and stays in the follower state. In that case no behavior state change occurs.
commitCoordinator.onStateChanged(this, isLeader);
}
super.onLeaderChanged(oldLeader, newLeader);
}
use of org.opendaylight.controller.cluster.access.concepts.MemberName in project controller by opendaylight.
the class EntityOwnershipShard method getViableCandidates.
private Collection<String> getViableCandidates(final Collection<String> candidates) {
Map<MemberName, VotingState> memberToVotingState = new HashMap<>();
getRaftActorContext().getPeers().forEach(peerInfo -> memberToVotingState.put(ShardIdentifier.fromShardIdString(peerInfo.getId()).getMemberName(), peerInfo.getVotingState()));
Collection<String> viableCandidates = new ArrayList<>();
for (String candidate : candidates) {
MemberName memberName = MemberName.forName(candidate);
if (memberToVotingState.get(memberName) != VotingState.NON_VOTING && !downPeerMemberNames.contains(memberName)) {
viableCandidates.add(candidate);
}
}
return viableCandidates;
}
use of org.opendaylight.controller.cluster.access.concepts.MemberName in project controller by opendaylight.
the class DistributedEntityOwnershipService method start.
public static DistributedEntityOwnershipService start(final ActorContext context, final EntityOwnerSelectionStrategyConfig strategyConfig) {
ActorRef shardManagerActor = context.getShardManager();
Configuration configuration = context.getConfiguration();
Collection<MemberName> entityOwnersMemberNames = configuration.getUniqueMemberNamesForAllShards();
CreateShard createShard = new CreateShard(new ModuleShardConfiguration(EntityOwners.QNAME.getNamespace(), "entity-owners", ENTITY_OWNERSHIP_SHARD_NAME, ModuleShardStrategy.NAME, entityOwnersMemberNames), newShardBuilder(context, strategyConfig), null);
Future<Object> createFuture = context.executeOperationAsync(shardManagerActor, createShard, MESSAGE_TIMEOUT);
createFuture.onComplete(new OnComplete<Object>() {
@Override
public void onComplete(final Throwable failure, final Object response) {
if (failure != null) {
LOG.error("Failed to create {} shard", ENTITY_OWNERSHIP_SHARD_NAME, failure);
} else {
LOG.info("Successfully created {} shard", ENTITY_OWNERSHIP_SHARD_NAME);
}
}
}, context.getClientDispatcher());
return new DistributedEntityOwnershipService(context);
}
use of org.opendaylight.controller.cluster.access.concepts.MemberName in project controller by opendaylight.
the class DistributedEntityOwnershipService method getOwnershipState.
@Override
public Optional<EntityOwnershipState> getOwnershipState(final DOMEntity forEntity) {
Preconditions.checkNotNull(forEntity, "forEntity cannot be null");
DataTree dataTree = getLocalEntityOwnershipShardDataTree();
if (dataTree == null) {
return Optional.absent();
}
java.util.Optional<NormalizedNode<?, ?>> entityNode = dataTree.takeSnapshot().readNode(entityPath(forEntity.getType(), forEntity.getIdentifier()));
if (!entityNode.isPresent()) {
return Optional.absent();
}
// Check if there are any candidates, if there are none we do not really have ownership state
final MapEntryNode entity = (MapEntryNode) entityNode.get();
final java.util.Optional<DataContainerChild<? extends PathArgument, ?>> optionalCandidates = entity.getChild(CANDIDATE_NODE_ID);
final boolean hasCandidates = optionalCandidates.isPresent() && ((MapNode) optionalCandidates.get()).getValue().size() > 0;
if (!hasCandidates) {
return Optional.absent();
}
MemberName localMemberName = context.getCurrentMemberName();
java.util.Optional<DataContainerChild<? extends PathArgument, ?>> ownerLeaf = entity.getChild(ENTITY_OWNER_NODE_ID);
String owner = ownerLeaf.isPresent() ? ownerLeaf.get().getValue().toString() : null;
boolean hasOwner = !Strings.isNullOrEmpty(owner);
boolean isOwner = hasOwner && localMemberName.getName().equals(owner);
return Optional.of(EntityOwnershipState.from(isOwner, hasOwner));
}
Aggregations