From 33c4d4570d1e729e551a1cad551b9685d103a8c1 Mon Sep 17 00:00:00 2001 From: Jim Brennan Date: Tue, 23 Mar 2021 18:57:23 +0000 Subject: [PATCH] YARN-10697. Resources are displayed in bytes in UI for schedulers other than capacity. Contributed by Bilwa S T. (cherry picked from commit 34e507cb8c11d3b6ee561fd4aabde6dadadcee00) --- .../apache/hadoop/yarn/api/records/Resource.java | 16 +++++++++++++++- .../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 bd6b31572cb..977b28633cd 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 @@ -29,6 +29,7 @@ import org.apache.hadoop.classification.InterfaceAudience.Public; import org.apache.hadoop.classification.InterfaceStability; import org.apache.hadoop.classification.InterfaceStability.Evolving; import org.apache.hadoop.classification.InterfaceStability.Stable; +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; @@ -472,9 +473,13 @@ public abstract class Resource implements Comparable { @Override public String toString() { + return getFormattedString(String.valueOf(getMemorySize())); + } + + private String getFormattedString(String memory) { StringBuilder sb = new StringBuilder(); - sb.append(" { 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 f98fc01b100..0fc98df7865 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())). _().