From f66ae34ea713e57a7aa2a049f7cf5984bfd8cd39 Mon Sep 17 00:00:00 2001 From: div8cn <35140268+div8cn@users.noreply.github.com> Date: Wed, 28 Oct 2020 18:19:53 +0800 Subject: [PATCH] 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 * Update UsageManagerImpl.java * Update UsageManagerImpl.java * Update UsageManagerImpl.java Co-authored-by: dahn --- .../src/main/java/com/cloud/usage/UsageManagerImpl.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/usage/src/main/java/com/cloud/usage/UsageManagerImpl.java b/usage/src/main/java/com/cloud/usage/UsageManagerImpl.java index b47a9ca986f..1d345885666 100644 --- a/usage/src/main/java/com/cloud/usage/UsageManagerImpl.java +++ b/usage/src/main/java/com/cloud/usage/UsageManagerImpl.java @@ -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; }