forked from YunaiV/eureka
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fe98f31
commit cc9afc2
Showing
17 changed files
with
194 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
eureka-core/src/main/java/com/netflix/eureka/util/StatusUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package com.netflix.eureka.util; | ||
|
||
import com.netflix.appinfo.InstanceInfo; | ||
import com.netflix.discovery.shared.Application; | ||
import com.netflix.eureka.EurekaServerContext; | ||
import com.netflix.eureka.cluster.PeerEurekaNode; | ||
import com.netflix.eureka.cluster.PeerEurekaNodes; | ||
import com.netflix.eureka.registry.PeerAwareInstanceRegistry; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.net.URI; | ||
|
||
/** | ||
* @author David Liu | ||
*/ | ||
public class StatusUtil { | ||
private static final Logger logger = LoggerFactory.getLogger(StatusUtil.class); | ||
|
||
private final String myAppName; | ||
private final PeerAwareInstanceRegistry registry; | ||
private final PeerEurekaNodes peerEurekaNodes; | ||
|
||
public StatusUtil(EurekaServerContext server) { | ||
this.myAppName = server.getApplicationInfoManager().getInfo().getAppName(); | ||
this.registry = server.getRegistry(); | ||
this.peerEurekaNodes = server.getPeerEurekaNodes(); | ||
} | ||
|
||
public StatusInfo getStatusInfo() { | ||
StatusInfo.Builder builder = StatusInfo.Builder.newBuilder(); | ||
// Add application level status | ||
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(myAppName, node.getServiceUrl())) { | ||
upReplicas.append(node.getServiceUrl()).append(','); | ||
} else { | ||
downReplicas.append(node.getServiceUrl()).append(','); | ||
} | ||
} | ||
|
||
builder.add("registered-replicas", replicaHostNames.toString()); | ||
builder.add("available-replicas", upReplicas.toString()); | ||
builder.add("unavailable-replicas", downReplicas.toString()); | ||
|
||
return builder.build(); | ||
} | ||
|
||
private boolean isReplicaAvailable(String myAppName, String url) { | ||
|
||
try { | ||
String givenHostName = new URI(url).getHost(); | ||
Application app = registry.getApplication(myAppName, false); | ||
for (InstanceInfo info : app.getInstances()) { | ||
if (info.getHostName().equals(givenHostName)) { | ||
return true; | ||
} | ||
} | ||
givenHostName = new URI(url).getHost(); | ||
} catch (Throwable e) { | ||
logger.error("Could not determine if the replica is available ", e); | ||
} | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.