Fix Usage failed to get pid (#4144)

* Update UsageManagerImpl.java

When System.getProperty Failure to get the PID will cause the service to stay in the config phase. The startup cannot continue and there will be no log output
Use managementfactory to get the PID and throw an exception when the PID cannot be obtained.

* Update usage/src/main/java/com/cloud/usage/UsageManagerImpl.java

Co-authored-by: dahn <daan.hoogland@gmail.com>

* Update UsageManagerImpl.java

* Update UsageManagerImpl.java

* Update UsageManagerImpl.java

Co-authored-by: dahn <daan.hoogland@gmail.com>
This commit is contained in:
div8cn 2020-10-28 18:19:53 +08:00 committed by GitHub
parent c1fb6b4cb9
commit f66ae34ea7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -278,7 +278,14 @@ public class UsageManagerImpl extends ManagerBase implements UsageManager, Runna
s_logger.error("Unhandled exception configuring UsageManger", e);
throw new ConfigurationException("Unhandled exception configuring UsageManager " + e.toString());
}
_pid = Integer.parseInt(System.getProperty("pid"));
try {
_pid = (int) ProcessHandle.current().pid();
} catch (Exception e) {
String msg = String.format("Unable to get process Id for %s!", e.toString());
s_logger.debug(msg);
throw new ConfigurationException(msg);
}
return true;
}