From dc4d7f69cec3f47af5be6f24cee1439081a4845c Mon Sep 17 00:00:00 2001 From: Ahmed Hussein Date: Wed, 29 May 2019 14:19:20 -0500 Subject: [PATCH] YARN-9563. Resource report REST API could return NaN or Inf (Ahmed Hussein via jeagles) Signed-off-by: Jonathan Eagles (cherry picked from commit 9d63fc7ed61ca6c3d901fe9984a7cca98ce07ea9) --- .../scheduler/SchedulerApplicationAttempt.java | 5 +++-- .../scheduler/common/fica/FiCaSchedulerApp.java | 4 +++- .../scheduler/capacity/TestLeafQueue.java | 9 +++++++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/SchedulerApplicationAttempt.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/SchedulerApplicationAttempt.java index 05dc8343c4b..71abdf00af5 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/SchedulerApplicationAttempt.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/SchedulerApplicationAttempt.java @@ -1037,9 +1037,10 @@ public class SchedulerApplicationAttempt implements SchedulableEntity { if (!calc.isInvalidDivisor(cluster)) { float queueCapacityPerc = queue.getQueueInfo(false, false) .getCapacity(); - if (queueCapacityPerc != 0) { - queueUsagePerc = calc.divide(cluster, usedResourceClone, + queueUsagePerc = calc.divide(cluster, usedResourceClone, Resources.multiply(cluster, queueCapacityPerc)) * 100; + if (Float.isNaN(queueUsagePerc) || Float.isInfinite(queueUsagePerc)) { + queueUsagePerc = 0.0f; } clusterUsagePerc = calc.divide(cluster, usedResourceClone, cluster) * 100; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/common/fica/FiCaSchedulerApp.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/common/fica/FiCaSchedulerApp.java index e7bb0273f39..6f3762335e3 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/common/fica/FiCaSchedulerApp.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/common/fica/FiCaSchedulerApp.java @@ -1031,7 +1031,9 @@ public class FiCaSchedulerApp extends SchedulerApplicationAttempt { Resources.multiply(totalPartitionRes, queueAbsMaxCapPerPartition)) * 100; } - report.setQueueUsagePercentage(queueUsagePerc); + if (!(Float.isNaN(queueUsagePerc) || Float.isInfinite(queueUsagePerc))) { + report.setQueueUsagePercentage(queueUsagePerc); + } } return report; } finally { diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestLeafQueue.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestLeafQueue.java index 115373b3671..3b76fb27967 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestLeafQueue.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/capacity/TestLeafQueue.java @@ -3967,6 +3967,15 @@ public class TestLeafQueue { 0.01f); assertEquals(15.0f, app.getResourceUsageReport().getClusterUsagePercentage(), 0.01f); + + // test that queueUsagePercentage returns neither NaN nor Infinite + AbstractCSQueue zeroQueue = createQueue("test2.2", null, + Float.MIN_VALUE, Float.MIN_VALUE); + app = new FiCaSchedulerApp(appAttId, user, zeroQueue, + qChild.getAbstractUsersManager(), rmContext); + app.getAppAttemptResourceUsage().incUsed(requestedResource); + assertEquals(0.0f, app.getResourceUsageReport().getQueueUsagePercentage(), + 0.01f); } private ApplicationAttemptId createAppAttemptId(int appId, int attemptId) {