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;
|
||||
|
||||
/**
|
||||
* Class for checking if the system is running on Google Cloud Platform (GCP).
|
||||
* This is intended for usage internal to the gRPC team. If you *really* think you need
|
||||
* to use this, contact the gRPC team first.
|
||||
* Class for checking if the system is running on Google Cloud Platform (GCP). This is intended for
|
||||
* usage internal to the gRPC team. If you *really* think you need to use this, contact the gRPC
|
||||
* team first.
|
||||
*/
|
||||
@Internal
|
||||
public final class InternalCheckGcpEnvironment {
|
||||
|
||||
private static final Logger logger =
|
||||
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 Boolean cachedResult = null;
|
||||
|
||||
// Construct me not!
|
||||
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() {
|
||||
if (cachedResult == null) {
|
||||
cachedResult = isRunningOnGcp();
|
||||
|
|
@ -73,13 +70,14 @@ public final class InternalCheckGcpEnvironment {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private static boolean isRunningOnGcp() {
|
||||
String osName = System.getProperty("os.name").toLowerCase(Locale.ENGLISH);
|
||||
try {
|
||||
if (osName.startsWith("linux")) {
|
||||
// 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")) {
|
||||
// Checks GCE residency on Windows platform.
|
||||
Process p =
|
||||
|
|
|
|||
Loading…
Reference in New Issue