import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.function.BiPredicate;
import java.util.stream.Collectors;
import org.opendaylight.controller.eos.akka.owner.supervisor.command.CandidatesChanged;
import org.opendaylight.controller.eos.akka.owner.supervisor.command.DataCenterDeactivated;
// reverse lookup of owner to entity
private final Multimap<String, DOMEntity> ownerToEntity = HashMultimap.create();
+ // only reassign owner for those entities that lost this candidate or is not reachable
+ private final BiPredicate<DOMEntity, String> reassignPredicate = (entity, candidate) ->
+ !isActiveCandidate(candidate) || !isCandidateFor(entity, candidate);
+
private OwnerSupervisor(final ActorContext<OwnerSupervisorCommand> context,
final Map<DOMEntity, Set<String>> currentCandidates,
final Map<DOMEntity, String> currentOwners) {
return newReceiveBuilder()
.onMessage(CandidatesChanged.class, this::onCandidatesChanged)
.onMessage(DeactivateDataCenter.class, this::onDeactivateDatacenter)
+ .onMessage(OwnerChanged.class, this::onOwnerChanged)
.onMessage(MemberUpEvent.class, this::onPeerUp)
.onMessage(MemberDownEvent.class, this::onPeerDown)
.onMessage(MemberReachableEvent.class, this::onPeerReachable)
return IdleSupervisor.create();
}
+ private Behavior<OwnerSupervisorCommand> onOwnerChanged(final OwnerChanged command) {
+ LOG.debug("Owner has changed for {}", command.getResponse().key());
+ return this;
+ }
+
private void reassignUnreachableOwners() {
final Set<String> ownersToReassign = new HashSet<>();
for (final String owner : ownerToEntity.keys()) {
}
for (final String owner : ownersToReassign) {
- reassignCandidatesFor(owner, ImmutableList.copyOf(ownerToEntity.get(owner)));
+ reassignCandidatesFor(owner, ImmutableList.copyOf(ownerToEntity.get(owner)), reassignPredicate);
}
}
// then reassign those that need new owners
for (final String toReassign : ownersToReassign) {
- reassignCandidatesFor(toReassign, ImmutableList.copyOf(ownerToEntity.get(toReassign)));
+ reassignCandidatesFor(toReassign, ImmutableList.copyOf(ownerToEntity.get(toReassign)),
+ reassignPredicate);
}
if (currentCandidates.get(entity) == null) {
}
}
- private void reassignCandidatesFor(final String oldOwner, final Collection<DOMEntity> entities) {
+ private void reassignCandidatesFor(final String oldOwner, final Collection<DOMEntity> entities,
+ final BiPredicate<DOMEntity, String> predicate) {
LOG.debug("Reassigning owners for {}", entities);
for (final DOMEntity entity : entities) {
- // only reassign owner for those entities that lost this candidate or is not reachable
- if (!activeMembers.contains(oldOwner)
- || !currentCandidates.getOrDefault(entity, Collections.emptySet()).contains(oldOwner)) {
+
+ if (predicate.test(entity, oldOwner)) {
ownerToEntity.remove(oldOwner, entity);
assignOwnerFor(entity);
}
}
}
+ private boolean isActiveCandidate(final String candidate) {
+ return activeMembers.contains(candidate);
+ }
+
+ private boolean isCandidateFor(final DOMEntity entity, final String candidate) {
+ return currentCandidates.getOrDefault(entity, Collections.emptySet()).contains(candidate);
+ }
+
private void assignOwnerFor(final DOMEntity entity) {
final Set<String> candidatesForEntity = currentCandidates.get(entity);
if (candidatesForEntity.isEmpty()) {