From 0101267d9d801eab4cb3b4df289c402ecb591685 Mon Sep 17 00:00:00 2001 From: Rohith Sharma K S Date: Tue, 24 Jan 2017 10:59:55 +0530 Subject: [PATCH] YARN-6082. Invalid REST api response for getApps since queueUsagePercentage is coming as INF. Contributed by Sunil G. --- .../scheduler/SchedulerApplicationAttempt.java | 9 ++++++--- .../scheduler/TestSchedulerApplicationAttempt.java | 12 ++++++++++++ 2 files changed, 18 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 7558eac9b8..3e41cb439f 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,12 @@ public ApplicationResourceUsageReport getResourceUsageReport() { float queueUsagePerc = 0.0f; float clusterUsagePerc = 0.0f; if (!calc.isInvalidDivisor(cluster)) { - queueUsagePerc = calc.divide(cluster, usedResourceClone, Resources - .multiply(cluster, queue.getQueueInfo(false, false).getCapacity())) - * 100; + float queueCapacityPerc = queue.getQueueInfo(false, false) + .getCapacity(); + if (queueCapacityPerc != 0) { + queueUsagePerc = calc.divide(cluster, usedResourceClone, + Resources.multiply(cluster, queueCapacityPerc)) * 100; + } 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 9a6c8d4e8a..c5e5183625 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 @@ -227,6 +227,18 @@ public void testAppPercentages() throws Exception { 0.01f); assertEquals(60.0f, app.getResourceUsageReport().getClusterUsagePercentage(), 0.01f); + + queue = createQueue("test3", null, 0.0f); + app = new SchedulerApplicationAttempt(appAttId, user, queue, + queue.getActiveUsersManager(), rmContext); + + // Resource request + app.attemptResourceUsage.incUsed(requestedResource); + + assertEquals(0.0f, app.getResourceUsageReport().getQueueUsagePercentage(), + 0.01f); + assertEquals(15.0f, + app.getResourceUsageReport().getClusterUsagePercentage(), 0.01f); } @Test