From f2202f799090b729a90b244200c4fe5d081ab919 Mon Sep 17 00:00:00 2001 From: Ahmed Hussein Date: Wed, 29 May 2019 11:24:08 -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 abf76ac371e4611c8eb371736b433e3d89c9d2ae) --- .../scheduler/SchedulerApplicationAttempt.java | 7 ++++--- .../scheduler/TestSchedulerApplicationAttempt.java | 2 +- .../scheduler/capacity/TestLeafQueue.java | 10 ++++++++++ 3 files changed, 15 insertions(+), 4 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 767df6d0ad4..3e78220c810 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 @@ -1124,9 +1124,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, - Resources.multiply(cluster, queueCapacityPerc)) * 100; + 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/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/TestSchedulerApplicationAttempt.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/TestSchedulerApplicationAttempt.java index c110b1c3d5d..0d6ff160e55 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/TestSchedulerApplicationAttempt.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/TestSchedulerApplicationAttempt.java @@ -271,7 +271,7 @@ public class TestSchedulerApplicationAttempt { assertEquals(60.0f, app.getResourceUsageReport().getClusterUsagePercentage(), 0.01f); - queue = createQueue("test3", null, 0.0f); + queue = createQueue("test3", null, Float.MIN_VALUE); app = new SchedulerApplicationAttempt(appAttId, user, queue, queue.getAbstractUsersManager(), rmContext); 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 04bb7912d1c..15a5eb2e92d 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 @@ -4037,6 +4037,16 @@ 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, + Resources.multiply(res, Float.MIN_VALUE)); + app = new FiCaSchedulerApp(appAttId, user, zeroQueue, + qChild.getAbstractUsersManager(), rmContext); + app.getAppAttemptResourceUsage().incUsed(requestedResource); + assertEquals(0.0f, app.getResourceUsageReport().getQueueUsagePercentage(), + 0.01f); } @Test