use of com.netflix.titus.api.clustermembership.model.ClusterMemberAddress in project titus-control-plane by Netflix.
the class GrpcClusterMembershipLeaderNameResolver method refresh.
private void refresh(ClusterMembershipSnapshot snapshot) {
try {
Optional<ClusterMembershipRevision<ClusterMember>> leaderOpt = snapshot.getLeaderRevision().flatMap(l -> Optional.ofNullable(snapshot.getMemberRevisions().get(l.getCurrent().getMemberId())));
if (leaderOpt.isPresent()) {
ClusterMembershipRevision<ClusterMember> memberRevision = leaderOpt.get();
ClusterMemberAddress address = addressSelector.apply(memberRevision.getCurrent());
if (lastLeader == null || !lastLeader.getCurrent().getMemberId().equals(memberRevision.getCurrent().getMemberId())) {
logger.info("New leader: {}", memberRevision);
Evaluators.acceptNotNull(leaderMetrics, LeaderMetrics::close);
lastLeader = memberRevision;
leaderMetrics = new LeaderMetrics(lastLeader, titusRuntime);
} else {
logger.debug("Refreshing: {}", lastLeader);
}
EquivalentAddressGroup server = new EquivalentAddressGroup(new InetSocketAddress(address.getIpAddress(), address.getPortNumber()));
List<EquivalentAddressGroup> servers = Collections.singletonList(server);
listener.onAddresses(servers, Attributes.EMPTY);
} else {
if (lastLeader != null) {
leaderMetrics.close();
lastLeader = null;
leaderMetrics = null;
logger.warn("No leader");
}
listener.onError(Status.UNAVAILABLE.withDescription("Unable to resolve leader server"));
}
} catch (Exception e) {
logger.error("Unable to create server with error: ", e);
listener.onError(Status.UNAVAILABLE.withCause(e));
}
}
Aggregations