mirror of https://github.com/grpc/grpc-java.git
alts: remove confusing constant name in InternalCheckGcpEnvironment.java (#7954)
This commit is contained in:
parent
c8d3cf23e6
commit
bb737a2e31
|
|
@ -30,25 +30,22 @@ import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class for checking if the system is running on Google Cloud Platform (GCP).
|
* Class for checking if the system is running on Google Cloud Platform (GCP). This is intended for
|
||||||
* This is intended for usage internal to the gRPC team. If you *really* think you need
|
* usage internal to the gRPC team. If you *really* think you need to use this, contact the gRPC
|
||||||
* to use this, contact the gRPC team first.
|
* team first.
|
||||||
*/
|
*/
|
||||||
@Internal
|
@Internal
|
||||||
public final class InternalCheckGcpEnvironment {
|
public final class InternalCheckGcpEnvironment {
|
||||||
|
|
||||||
private static final Logger logger =
|
private static final Logger logger =
|
||||||
Logger.getLogger(InternalCheckGcpEnvironment.class.getName());
|
Logger.getLogger(InternalCheckGcpEnvironment.class.getName());
|
||||||
private static final String DMI_PRODUCT_NAME = "/sys/class/dmi/id/product_name";
|
|
||||||
private static final String WINDOWS_COMMAND = "powershell.exe";
|
private static final String WINDOWS_COMMAND = "powershell.exe";
|
||||||
private static Boolean cachedResult = null;
|
private static Boolean cachedResult = null;
|
||||||
|
|
||||||
// Construct me not!
|
// Construct me not!
|
||||||
private InternalCheckGcpEnvironment() {}
|
private InternalCheckGcpEnvironment() {}
|
||||||
|
|
||||||
/**
|
/** Returns {@code true} if currently running on Google Cloud Platform (GCP). */
|
||||||
* Returns {@code true} if currently running on Google Cloud Platform (GCP).
|
|
||||||
*/
|
|
||||||
public static synchronized boolean isOnGcp() {
|
public static synchronized boolean isOnGcp() {
|
||||||
if (cachedResult == null) {
|
if (cachedResult == null) {
|
||||||
cachedResult = isRunningOnGcp();
|
cachedResult = isRunningOnGcp();
|
||||||
|
|
@ -73,13 +70,14 @@ public final class InternalCheckGcpEnvironment {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isRunningOnGcp() {
|
private static boolean isRunningOnGcp() {
|
||||||
String osName = System.getProperty("os.name").toLowerCase(Locale.ENGLISH);
|
String osName = System.getProperty("os.name").toLowerCase(Locale.ENGLISH);
|
||||||
try {
|
try {
|
||||||
if (osName.startsWith("linux")) {
|
if (osName.startsWith("linux")) {
|
||||||
// Checks GCE residency on Linux platform.
|
// Checks GCE residency on Linux platform.
|
||||||
return checkProductNameOnLinux(Files.newBufferedReader(Paths.get(DMI_PRODUCT_NAME), UTF_8));
|
return checkProductNameOnLinux(
|
||||||
|
Files.newBufferedReader(Paths.get("/sys/class/dmi/id/product_name"), UTF_8));
|
||||||
} else if (osName.startsWith("windows")) {
|
} else if (osName.startsWith("windows")) {
|
||||||
// Checks GCE residency on Windows platform.
|
// Checks GCE residency on Windows platform.
|
||||||
Process p =
|
Process p =
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue