You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by GitBox <gi...@apache.org> on 2020/08/05 02:51:06 UTC

[GitHub] [cloudstack] GabrielBrascher commented on a change in pull request #4144: Fix Usage failed to get pid

GabrielBrascher commented on a change in pull request #4144:
URL: https://github.com/apache/cloudstack/pull/4144#discussion_r465441006



##########
File path: usage/src/main/java/com/cloud/usage/UsageManagerImpl.java
##########
@@ -275,7 +277,16 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
             s_logger.error("Unhandled exception configuring UsageManger", e);
             throw new ConfigurationException("Unhandled exception configuring UsageManager " + e.toString());
         }
-        _pid = Integer.parseInt(System.getProperty("pid"));
+
+        String processName = null;
+        try {
+            processName = ManagementFactory.getRuntimeMXBean().getName();
+            _pid = Integer.parseInt(processName.split("@")[0]);
+        } catch (Exception e) {
+            String msg = String.format("Unable to get process Id for %s!", processName);
+            s_logger.debug(msg , e);
+            throw new ConfigurationException(msg + " " + e.toString());

Review comment:
       @DaanHoogland @div8cn What do you think of using `e.printStackTrace()` to add the stack on the log/ConfigurationException?
   
   With `toString` (or simply s_logger.debug(msg , e)) it logs only the exception name and the error message (if there is any message). On the other hand, `printStackTrace()` presents the whole stack trace of an exception, which is very helpful for debugging.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org