You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by su...@apache.org on 2012/10/04 04:47:41 UTC

svn commit: r1393886 - in /hadoop/common/branches/branch-1-win: CHANGES.branch-1-win.txt src/core/org/apache/hadoop/util/WindowsResourceCalculatorPlugin.java src/test/org/apache/hadoop/util/TestWindowsResourceCalculatorPlugin.java

Author: suresh
Date: Thu Oct  4 02:47:41 2012
New Revision: 1393886

URL: http://svn.apache.org/viewvc?rev=1393886&view=rev
Log:
MAPREDUCE-4567. WindowsResourceCalculatorPlugin has NPE. Contributed by Bikas Saha.

Modified:
    hadoop/common/branches/branch-1-win/CHANGES.branch-1-win.txt
    hadoop/common/branches/branch-1-win/src/core/org/apache/hadoop/util/WindowsResourceCalculatorPlugin.java
    hadoop/common/branches/branch-1-win/src/test/org/apache/hadoop/util/TestWindowsResourceCalculatorPlugin.java

Modified: hadoop/common/branches/branch-1-win/CHANGES.branch-1-win.txt
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-1-win/CHANGES.branch-1-win.txt?rev=1393886&r1=1393885&r2=1393886&view=diff
==============================================================================
--- hadoop/common/branches/branch-1-win/CHANGES.branch-1-win.txt (original)
+++ hadoop/common/branches/branch-1-win/CHANGES.branch-1-win.txt Thu Oct  4 02:47:41 2012
@@ -143,3 +143,6 @@ BUG FIXES
     
     HADOOP-8836. UGI should throw exception in case winutils.exe cannot be
     loaded. (Bikas Saha via suresh)
+
+    MAPREDUCE-4567. WindowsResourceCalculatorPlugin has NPE.
+    (Bikas Saha via suresh)

Modified: hadoop/common/branches/branch-1-win/src/core/org/apache/hadoop/util/WindowsResourceCalculatorPlugin.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-1-win/src/core/org/apache/hadoop/util/WindowsResourceCalculatorPlugin.java?rev=1393886&r1=1393885&r2=1393886&view=diff
==============================================================================
--- hadoop/common/branches/branch-1-win/src/core/org/apache/hadoop/util/WindowsResourceCalculatorPlugin.java (original)
+++ hadoop/common/branches/branch-1-win/src/core/org/apache/hadoop/util/WindowsResourceCalculatorPlugin.java Thu Oct  4 02:47:41 2012
@@ -79,29 +79,31 @@ public class WindowsResourceCalculatorPl
       long lastCumCpuTimeMs = cumulativeCpuTimeMs;
       reset();
       String sysInfoStr = getSystemInfoInfoFromShell();
-      final int sysInfoSplitCount = 7;
-      String[] sysInfo = sysInfoStr.substring(0, sysInfoStr.indexOf("\r\n"))
-          .split(",");
-      if (sysInfo.length == sysInfoSplitCount) {
-        try {
-          vmemSize = Long.parseLong(sysInfo[0]);
-          memSize = Long.parseLong(sysInfo[1]);
-          vmemAvailable = Long.parseLong(sysInfo[2]);
-          memAvailable = Long.parseLong(sysInfo[3]);
-          numProcessors = Integer.parseInt(sysInfo[4]);
-          cpuFrequencyKhz = Long.parseLong(sysInfo[5]);
-          cumulativeCpuTimeMs = Long.parseLong(sysInfo[6]);
-          if (lastCumCpuTimeMs != -1) {
-            cpuUsage = (cumulativeCpuTimeMs - lastCumCpuTimeMs)
-                / (refreshInterval * 1.0f);
-          }
+      if (sysInfoStr != null) {
+        final int sysInfoSplitCount = 7;
+        String[] sysInfo = sysInfoStr.substring(0, sysInfoStr.indexOf("\r\n"))
+            .split(",");
+        if (sysInfo.length == sysInfoSplitCount) {
+          try {
+            vmemSize = Long.parseLong(sysInfo[0]);
+            memSize = Long.parseLong(sysInfo[1]);
+            vmemAvailable = Long.parseLong(sysInfo[2]);
+            memAvailable = Long.parseLong(sysInfo[3]);
+            numProcessors = Integer.parseInt(sysInfo[4]);
+            cpuFrequencyKhz = Long.parseLong(sysInfo[5]);
+            cumulativeCpuTimeMs = Long.parseLong(sysInfo[6]);
+            if (lastCumCpuTimeMs != -1) {
+              cpuUsage = (cumulativeCpuTimeMs - lastCumCpuTimeMs)
+                  / (refreshInterval * 1.0f);
+            }
 
-        } catch (NumberFormatException nfe) {
-          LOG.debug("Error parsing sysInfo." + nfe);
+          } catch (NumberFormatException nfe) {
+            LOG.warn("Error parsing sysInfo." + nfe);
+          }
+        } else {
+          LOG.warn("Expected split length of sysInfo to be "
+              + sysInfoSplitCount + ". Got " + sysInfo.length);
         }
-      } else {
-        LOG.debug("Expected split length of sysInfo to be " + sysInfoSplitCount
-            + ". Got " + sysInfo.length);
       }
     }
   }

Modified: hadoop/common/branches/branch-1-win/src/test/org/apache/hadoop/util/TestWindowsResourceCalculatorPlugin.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-1-win/src/test/org/apache/hadoop/util/TestWindowsResourceCalculatorPlugin.java?rev=1393886&r1=1393885&r2=1393886&view=diff
==============================================================================
--- hadoop/common/branches/branch-1-win/src/test/org/apache/hadoop/util/TestWindowsResourceCalculatorPlugin.java (original)
+++ hadoop/common/branches/branch-1-win/src/test/org/apache/hadoop/util/TestWindowsResourceCalculatorPlugin.java Thu Oct  4 02:47:41 2012
@@ -70,5 +70,13 @@ public class TestWindowsResourceCalculat
     assertTrue(tester.memAvailable == 5400417792L);
     assertTrue(tester.cpuUsage >= 0.1);
   }
+  
+  public void testErrorInGetSystemInfo() {
+    WindowsResourceCalculatorPluginTester tester = new WindowsResourceCalculatorPluginTester();
+    // info str derived from windows shell command has \r\n termination
+    tester.infoStr = null;
+    // call a method to refresh values
+    tester.getAvailablePhysicalMemorySize();    
+  }
 
 }