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/07/29 07:32:24 UTC

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

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



##########
File path: usage/src/main/java/com/cloud/usage/UsageManagerImpl.java
##########
@@ -275,7 +277,14 @@ 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"));
+
+        try {
+            String processName = ManagementFactory.getRuntimeMXBean().getName();
+            _pid = Integer.parseInt(processName.split("@")[0]);
+        } catch (Exception e) {
+            s_logger.error("Unable to get process pid ", e);
+            throw new ConfigurationException("Unable to get process pid " + e.toString());
+        }

Review comment:
       1. twice the same message should be in a string constand
   1. rethrown should not abandon the stack trace for the original problem
   ```suggestion
           String processName;
           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.error(msg);
               throw new ConfigurationException(msg, e);
           }
   ```
   or
   ```suggestion
           String processName;
           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);
           }
   ```




----------------------------------------------------------------
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