diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/attempt/RMAppAttemptMetrics.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/attempt/RMAppAttemptMetrics.java index 0982ef9343..015cff7a96 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/attempt/RMAppAttemptMetrics.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/attempt/RMAppAttemptMetrics.java @@ -135,20 +135,21 @@ public AggregateAppResourceUsage getAggregateAppResourceUsage() { // Only add in the running containers if this is the active attempt. RMApp rmApp = rmContext.getRMApps().get(attemptId.getApplicationId()); if (rmApp != null) { - RMAppAttempt currentAttempt = rmContext.getRMApps().get(attemptId.getApplicationId()).getCurrentAppAttempt(); - if (currentAttempt.getAppAttemptId().equals(attemptId)) { + RMAppAttempt currentAttempt = rmApp.getCurrentAppAttempt(); + if (currentAttempt != null + && currentAttempt.getAppAttemptId().equals(attemptId)) { ApplicationResourceUsageReport appResUsageReport = rmContext.getScheduler().getAppResourceUsageReport(attemptId); if (appResUsageReport != null) { Map tmp = appResUsageReport.getResourceSecondsMap(); for (Map.Entry entry : tmp.entrySet()) { - if (resourcesUsed.containsKey(entry.getKey())) { - Long value = resourcesUsed.get(entry.getKey()); + Long value = resourcesUsed.get(entry.getKey()); + if (value != null) { value += entry.getValue(); - resourcesUsed.put(entry.getKey(), value); - } else{ - resourcesUsed.put(entry.getKey(), entry.getValue()); + } else { + value = entry.getValue(); } + resourcesUsed.put(entry.getKey(), value); } } }