Skip to content

Commit

Permalink
Check for existence of ConfigurationManager (#1288)
Browse files Browse the repository at this point in the history
This is useful if a project has excluded Archaius 1 such as spring-cloud-netflix. This is a simple workaround.
  • Loading branch information
spencergibb committed Apr 30, 2020
1 parent bf424b7 commit 80bf99f
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions eureka-core/src/main/java/com/netflix/eureka/util/StatusInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import java.util.HashMap;
import java.util.Map;

import com.netflix.appinfo.ApplicationInfoManager;
import com.netflix.appinfo.InstanceInfo;
import com.netflix.config.ConfigurationManager;
import com.netflix.discovery.provider.Serializer;
Expand All @@ -23,6 +22,7 @@
@XStreamAlias("status")
public class StatusInfo {
private static final String DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss Z";
private static final boolean ARCHAIUS_EXISTS = classExists("com.netflix.config.ConfigurationManager");

public static final class Builder {

Expand Down Expand Up @@ -68,8 +68,10 @@ public StatusInfo build() {
}

result.generalStats.put("server-uptime", getUpTime());
result.generalStats.put("environment", ConfigurationManager
.getDeploymentContext().getDeploymentEnvironment());
if (ARCHAIUS_EXISTS) {
result.generalStats.put("environment", ConfigurationManager
.getDeploymentContext().getDeploymentEnvironment());
}

Runtime runtime = Runtime.getRuntime();
int totalMem = (int) (runtime.totalMemory() / 1048576);
Expand Down Expand Up @@ -143,4 +145,14 @@ public static String getCurrentTimeAsString() {
SimpleDateFormat format = new SimpleDateFormat(DATE_FORMAT);
return format.format(new Date());
}

private static boolean classExists(String className) {
try {
Class.forName(className);
return true;
} catch (ClassNotFoundException e) {
return false;
}
}

}

0 comments on commit 80bf99f

Please sign in to comment.