@Inject StatusResource(EurekaServerContext server) { this.statusUtil = new StatusUtil(server); }
@GET public StatusInfo getStatusInfo() { return statusUtil.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(); }
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(); }
@Test public void testGetStatusInfoHealthy() { StatusUtil statusUtil = getStatusUtil(3, 3, 2); assertTrue(statusUtil.getStatusInfo().isHealthy()); }
return new StatusUtil(mockEurekaServerContext);
@Test public void testGetStatusInfoUnhealthy() { StatusUtil statusUtil = getStatusUtil(5, 3, 4); assertFalse(statusUtil.getStatusInfo().isHealthy()); }
@Inject StatusResource(EurekaServerContext server) { this.statusUtil = new StatusUtil(server); }
@Test public void testGetStatusInfoUnsetHealth() { StatusUtil statusUtil = getStatusUtil(5, 3, -1); StatusInfo statusInfo = statusUtil.getStatusInfo(); try { statusInfo.isHealthy(); } catch (NullPointerException e) { // Expected that the healthy flag is not set when the minimum value is -1 return; } fail("Excpected NPE to be thrown when healthy threshold is not set"); }
@GET public StatusInfo getStatusInfo() { return statusUtil.getStatusInfo(); }