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 jb...@apache.org on 2021/03/23 18:36:31 UTC

[hadoop] branch branch-3.3 updated: YARN-10697. Resources are displayed in bytes in UI for schedulers other than capacity. Contributed by Bilwa S T.

This is an automated email from the ASF dual-hosted git repository.

jbrennan pushed a commit to branch branch-3.3
in repository https://gitbox.apache.org/repos/asf/hadoop.git


The following commit(s) were added to refs/heads/branch-3.3 by this push:
     new 78bddd0  YARN-10697. Resources are displayed in bytes in UI for schedulers other than capacity. Contributed by Bilwa S T.
78bddd0 is described below

commit 78bddd0d9fadb5a34e8f41725592c35b5a88f630
Author: Jim Brennan <jb...@apache.org>
AuthorDate: Tue Mar 23 18:21:45 2021 +0000

    YARN-10697. Resources are displayed in bytes in UI for schedulers other than capacity. Contributed by Bilwa S T.
    
    (cherry picked from commit 174f3a96b10a0ab0fd8aed1b0f904ca5f0c3f268)
---
 .../org/apache/hadoop/yarn/api/records/Resource.java     | 16 +++++++++++++++-
 .../resourcemanager/webapp/MetricsOverviewTable.java     | 12 ++++++------
 2 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/Resource.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/Resource.java
index 83e1c5f..b91658f 100644
--- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/Resource.java
+++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/Resource.java
@@ -31,6 +31,7 @@ import org.apache.hadoop.classification.InterfaceStability;
 import org.apache.hadoop.classification.InterfaceStability.Evolving;
 import org.apache.hadoop.classification.InterfaceStability.Stable;
 import org.apache.hadoop.classification.InterfaceStability.Unstable;
+import org.apache.hadoop.util.StringUtils;
 import org.apache.hadoop.yarn.api.ApplicationMasterProtocol;
 import org.apache.hadoop.yarn.api.protocolrecords.ResourceTypes;
 import org.apache.hadoop.yarn.api.records.impl.LightWeightResource;
@@ -465,9 +466,13 @@ public abstract class Resource implements Comparable<Resource> {
 
   @Override
   public String toString() {
+    return getFormattedString(String.valueOf(getMemorySize()));
+  }
+
+  private String getFormattedString(String memory) {
     StringBuilder sb = new StringBuilder();
 
-    sb.append("<memory:").append(getMemorySize()).append(", vCores:")
+    sb.append("<memory:").append(memory).append(", vCores:")
         .append(getVirtualCores());
 
     for (int i = 2; i < resources.length; i++) {
@@ -485,6 +490,15 @@ public abstract class Resource implements Comparable<Resource> {
     return sb.toString();
   }
 
+  /**
+   * This method is to get memory in terms of KB|MB|GB.
+   * @return string containing all resources
+   */
+  public String getFormattedString() {
+    return getFormattedString(
+        StringUtils.byteDesc(getMemorySize() * 1024 * 1024));
+  }
+
   @Override
   public int hashCode() {
     final int prime = 47;
diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/MetricsOverviewTable.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/MetricsOverviewTable.java
index 97e43e6..009a012 100644
--- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/MetricsOverviewTable.java
+++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/MetricsOverviewTable.java
@@ -83,13 +83,13 @@ public class MetricsOverviewTable extends HtmlBlock {
     } else {
       allocatedContainers = clusterMetrics.getContainersAllocated();
       usedResources = Resource.newInstance(
-          clusterMetrics.getAllocatedMB() * BYTES_IN_MB,
+          clusterMetrics.getAllocatedMB(),
           (int) clusterMetrics.getAllocatedVirtualCores());
       totalResources = Resource.newInstance(
-          clusterMetrics.getTotalMB() * BYTES_IN_MB,
+          clusterMetrics.getTotalMB(),
           (int) clusterMetrics.getTotalVirtualCores());
       reservedResources = Resource.newInstance(
-          clusterMetrics.getReservedMB() * BYTES_IN_MB,
+          clusterMetrics.getReservedMB(),
           (int) clusterMetrics.getReservedVirtualCores());
     }
 
@@ -121,9 +121,9 @@ public class MetricsOverviewTable extends HtmlBlock {
                 )
             ).
         td(String.valueOf(allocatedContainers)).
-        td(usedResources.toString()).
-        td(totalResources.toString()).
-        td(reservedResources.toString()).
+        td(usedResources.getFormattedString()).
+        td(totalResources.getFormattedString()).
+        td(reservedResources.getFormattedString()).
         td(String.valueOf(clusterMetrics.getUtilizedMBPercent())).
         td(String.valueOf(clusterMetrics.getUtilizedVirtualCoresPercent())).
         __().

---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org