Przeglądaj źródła

HADOOP-1882. Remove spurious asterisks from decimal number displays. Contributed by Raghu.

git-svn-id: https://svn.apache.org/repos/asf/lucene/hadoop/trunk@577860 13f79535-47bb-0310-9956-ffa450edef68
Doug Cutting 18 lat temu
rodzic
commit
2d08923f8a

+ 3 - 0
CHANGES.txt

@@ -167,6 +167,9 @@ Trunk (unreleased changes)
     HADOOP-1907.  Fix null pointer exception when getting task diagnostics
     in JobClient. (Christian Kunz via omalley)
 
+    HADOOP-1882.  Remove spurious asterisks from decimal number displays.
+    (Raghu Angadi via cutting)
+
   IMPROVEMENTS
 
     HADOOP-1266. Remove dependency of package org.apache.hadoop.net on 

+ 1 - 1
src/java/org/apache/hadoop/dfs/DFSAdmin.java

@@ -75,7 +75,7 @@ public class DFSAdmin extends FsShell {
       System.out.println("Used raw bytes: " + rawUsed
                          + " (" + byteDesc(rawUsed) + ")");
       System.out.println("% used: "
-                         + limitDecimal(((1.0 * rawUsed) / raw) * 100, 2)
+                         + limitDecimalTo2(((1.0 * rawUsed) / raw) * 100)
                          + "%");
       System.out.println();
       System.out.println("Total effective bytes: " + used

+ 2 - 2
src/java/org/apache/hadoop/dfs/DatanodeInfo.java

@@ -160,7 +160,7 @@ public class DatanodeInfo extends DatanodeID implements Node {
     buffer.append("Total raw bytes: "+c+" ("+FsShell.byteDesc(c)+")"+"\n");
     buffer.append("Remaining raw bytes: " +r+ "("+FsShell.byteDesc(r)+")"+"\n");
     buffer.append("Used raw bytes: "+u+" ("+FsShell.byteDesc(u)+")"+"\n");
-    buffer.append("% used: "+FsShell.limitDecimal(((1.0*u)/c)*100, 2)+"%"+"\n");
+    buffer.append("% used: "+FsShell.limitDecimalTo2(((1.0*u)/c)*100)+"%"+"\n");
     buffer.append("Last contact: "+new Date(lastUpdate)+"\n");
     return buffer.toString();
   }
@@ -184,7 +184,7 @@ public class DatanodeInfo extends DatanodeID implements Node {
     }
     buffer.append(" " + c + "(" + FsShell.byteDesc(c)+")");
     buffer.append(" " + u + "(" + FsShell.byteDesc(u)+")");
-    buffer.append(" " + FsShell.limitDecimal(((1.0*u)/c)*100, 2)+"%");
+    buffer.append(" " + FsShell.limitDecimalTo2(((1.0*u)/c)*100)+"%");
     buffer.append(" " + r + "(" + FsShell.byteDesc(r)+")");
     buffer.append(" " + new Date(lastUpdate));
     return buffer.toString();

+ 4 - 10
src/java/org/apache/hadoop/fs/FsShell.java

@@ -45,8 +45,7 @@ public class FsShell extends Configured implements Tool {
   }
   static final String SETREP_SHORT_USAGE="-setrep [-R] [-w] <rep> <path/file>";
   static final String TAIL_USAGE="-tail [-f] <file>";
-  private static final DecimalFormat decimalFormat = 
-    new DecimalFormat("#*0.0#*");
+  private static final DecimalFormat decimalFormat = new DecimalFormat("#.##");
 
   /**
    */
@@ -951,16 +950,11 @@ public class FsShell extends Configured implements Tool {
       val = (1.0 * len) / (1024L * 1024 * 1024 * 1024 * 1024);
       ending = " PB";
     }
-    return limitDecimal(val, 2) + ending;
+    return limitDecimalTo2(val) + ending;
   }
 
-  public static String limitDecimal(double d, int placesAfterDecimal) {
-    String strVal = decimalFormat.format(d);
-    int decpt = strVal.indexOf(".");
-    if (decpt >= 0) {
-      strVal = strVal.substring(0, Math.min(strVal.length(), decpt + 1 + placesAfterDecimal));
-    }
-    return strVal;
+  public static synchronized String limitDecimalTo2(double d) {
+    return decimalFormat.format(d);
   }
 
   private void printHelp(String cmd) {

+ 5 - 5
src/webapps/dfs/dfshealth.jsp

@@ -87,7 +87,7 @@
     
     String percentUsed;
     if (c > 0) 
-      percentUsed = FsShell.limitDecimal(((1.0 * u)/c)*100, 2);
+      percentUsed = FsShell.limitDecimalTo2(((1.0 * u)/c)*100);
     else
       percentUsed = "100";
 
@@ -102,10 +102,10 @@
 	      "<td class=\"adminstate\">" +
               adminState +
 	      "<td class=\"size\">" +
-              FsShell.limitDecimal(c*1.0/diskBytes, 2) +
+              FsShell.limitDecimalTo2(c*1.0/diskBytes) +
 	      "<td class=\"pcused\">" + percentUsed +
 	      "<td class=\"size\">" +
-              FsShell.limitDecimal(d.getRemaining()*1.0/diskBytes, 2) +
+              FsShell.limitDecimalTo2(d.getRemaining()*1.0/diskBytes) +
           "<td class=\"blocks\">" + d.numBlocks() + "\n");
   }
 
@@ -153,8 +153,8 @@
 	       rowTxt() + colTxt() + "DFS Used" + colTxt() + ":" + colTxt() +
 	       FsShell.byteDesc( fsn.totalDfsUsed() ) +
 	       rowTxt() + colTxt() + "DFS Used%" + colTxt() + ":" + colTxt() +
-	       FsShell.limitDecimal((fsn.totalDfsUsed())*100.0/
-				     (fsn.totalCapacity() + 1e-10), 2) + " %" +
+	       FsShell.limitDecimalTo2((fsn.totalDfsUsed())*100.0/
+				       (fsn.totalCapacity() + 1e-10)) + " %" +
 	       rowTxt() + colTxt() +
                "<a href=\"#LiveNodes\">Live Nodes</a> " +
                colTxt() + ":" + colTxt() + live.size() +