use of com.netflix.eureka.cluster.PeerEurekaNode in project eureka by Netflix.
the class StatusUtilTest method getMockNodes.
List<PeerEurekaNode> getMockNodes(int size) {
List<PeerEurekaNode> nodes = new ArrayList<>();
for (int i = 0; i < size; i++) {
PeerEurekaNode mockNode = mock(PeerEurekaNode.class);
when(mockNode.getServiceUrl()).thenReturn(String.format("http://%d:8080/v2", i));
nodes.add(mockNode);
}
return nodes;
}
use of com.netflix.eureka.cluster.PeerEurekaNode in project nutzboot by nutzam.
the class EurekaServletStarter method populateNavbar.
private void populateNavbar(NutMap result) {
List<NutMap> replicas = new ArrayList<>();
List<PeerEurekaNode> list = getServerContext().getPeerEurekaNodes().getPeerNodesView();
for (PeerEurekaNode node : list) {
try {
URI uri = new URI(node.getServiceUrl());
String href = scrubBasicAuth(node.getServiceUrl());
replicas.add(NutMap.NEW().setv("key", uri.getHost()).setv("value", href));
} catch (Exception ex) {
}
}
result.put("replicas", replicas);
}
use of com.netflix.eureka.cluster.PeerEurekaNode in project spring-cloud-netflix by spring-cloud.
the class EurekaController method populateNavbar.
private void populateNavbar(HttpServletRequest request, Map<String, Object> model) {
Map<String, String> replicas = new LinkedHashMap<>();
List<PeerEurekaNode> list = getServerContext().getPeerEurekaNodes().getPeerNodesView();
for (PeerEurekaNode node : list) {
try {
URI uri = new URI(node.getServiceUrl());
String href = scrubBasicAuth(node.getServiceUrl());
replicas.put(uri.getHost(), href);
} catch (Exception ex) {
// ignore?
}
}
model.put("replicas", replicas.entrySet());
}
use of com.netflix.eureka.cluster.PeerEurekaNode in project eureka by Netflix.
the class PeerAwareInstanceRegistryImpl method primeAwsReplicas.
/**
* Prime connections for Aws replicas.
* <p>
* Sometimes when the eureka servers comes up, AWS firewall may not allow
* the network connections immediately. This will cause the outbound
* connections to fail, but the inbound connections continue to work. What
* this means is the clients would have switched to this node (after EIP
* binding) and so the other eureka nodes will expire all instances that
* have been switched because of the lack of outgoing heartbeats from this
* instance.
* </p>
* <p>
* The best protection in this scenario is to block and wait until we are
* able to ping all eureka nodes successfully atleast once. Until then we
* won't open up the traffic.
* </p>
*/
private void primeAwsReplicas(ApplicationInfoManager applicationInfoManager) {
boolean areAllPeerNodesPrimed = false;
while (!areAllPeerNodesPrimed) {
String peerHostName = null;
try {
Application eurekaApps = this.getApplication(applicationInfoManager.getInfo().getAppName(), false);
if (eurekaApps == null) {
areAllPeerNodesPrimed = true;
logger.info("No peers needed to prime.");
return;
}
for (PeerEurekaNode node : peerEurekaNodes.getPeerEurekaNodes()) {
for (InstanceInfo peerInstanceInfo : eurekaApps.getInstances()) {
LeaseInfo leaseInfo = peerInstanceInfo.getLeaseInfo();
// If the lease is expired - do not worry about priming
if (System.currentTimeMillis() > (leaseInfo.getRenewalTimestamp() + (leaseInfo.getDurationInSecs() * 1000)) + (2 * 60 * 1000)) {
continue;
}
peerHostName = peerInstanceInfo.getHostName();
logger.info("Trying to send heartbeat for the eureka server at {} to make sure the " + "network channels are open", peerHostName);
// the other instances may be legitimately down
if (peerHostName.equalsIgnoreCase(new URI(node.getServiceUrl()).getHost())) {
node.heartbeat(peerInstanceInfo.getAppName(), peerInstanceInfo.getId(), peerInstanceInfo, null, true);
}
}
}
areAllPeerNodesPrimed = true;
} catch (Throwable e) {
logger.error("Could not contact {}", peerHostName, e);
try {
Thread.sleep(PRIME_PEER_NODES_RETRY_MS);
} catch (InterruptedException e1) {
logger.warn("Interrupted while priming : ", e1);
areAllPeerNodesPrimed = true;
}
}
}
}
use of com.netflix.eureka.cluster.PeerEurekaNode in project eureka by Netflix.
the class StatusUtil method getStatusInfo.
public StatusInfo getStatusInfo() {
StatusInfo.Builder builder = StatusInfo.Builder.newBuilder();
// Add application level status
int upReplicasCount = 0;
StringBuilder upReplicas = new StringBuilder();
StringBuilder downReplicas = new StringBuilder();
StringBuilder replicaHostNames = new StringBuilder();
for (PeerEurekaNode node : peerEurekaNodes.getPeerEurekaNodes()) {
if (replicaHostNames.length() > 0) {
replicaHostNames.append(", ");
}
replicaHostNames.append(node.getServiceUrl());
if (isReplicaAvailable(node.getServiceUrl())) {
upReplicas.append(node.getServiceUrl()).append(',');
upReplicasCount++;
} else {
downReplicas.append(node.getServiceUrl()).append(',');
}
}
builder.add("registered-replicas", replicaHostNames.toString());
builder.add("available-replicas", upReplicas.toString());
builder.add("unavailable-replicas", downReplicas.toString());
// Only set the healthy flag if a threshold has been configured.
if (peerEurekaNodes.getMinNumberOfAvailablePeers() > -1) {
builder.isHealthy(upReplicasCount >= peerEurekaNodes.getMinNumberOfAvailablePeers());
}
builder.withInstanceInfo(this.instanceInfo);
return builder.build();
}
Aggregations