YARN-7454. RMAppAttemptMetrics#getAggregateResourceUsage can NPE due to double lookup. Contributed by Jason Lowe.

This commit is contained in:
bibinchundatt 2017-11-09 21:01:19 +05:30
parent 3a3566e1d1
commit 0a72c2f56c
1 changed files with 8 additions and 7 deletions

View File

@ -135,20 +135,21 @@ public class RMAppAttemptMetrics {
// Only add in the running containers if this is the active attempt. // Only add in the running containers if this is the active attempt.
RMApp rmApp = rmContext.getRMApps().get(attemptId.getApplicationId()); RMApp rmApp = rmContext.getRMApps().get(attemptId.getApplicationId());
if (rmApp != null) { if (rmApp != null) {
RMAppAttempt currentAttempt = rmContext.getRMApps().get(attemptId.getApplicationId()).getCurrentAppAttempt(); RMAppAttempt currentAttempt = rmApp.getCurrentAppAttempt();
if (currentAttempt.getAppAttemptId().equals(attemptId)) { if (currentAttempt != null
&& currentAttempt.getAppAttemptId().equals(attemptId)) {
ApplicationResourceUsageReport appResUsageReport = ApplicationResourceUsageReport appResUsageReport =
rmContext.getScheduler().getAppResourceUsageReport(attemptId); rmContext.getScheduler().getAppResourceUsageReport(attemptId);
if (appResUsageReport != null) { if (appResUsageReport != null) {
Map<String, Long> tmp = appResUsageReport.getResourceSecondsMap(); Map<String, Long> tmp = appResUsageReport.getResourceSecondsMap();
for (Map.Entry<String, Long> entry : tmp.entrySet()) { for (Map.Entry<String, Long> 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(); value += entry.getValue();
resourcesUsed.put(entry.getKey(), value); } else {
} else{ value = entry.getValue();
resourcesUsed.put(entry.getKey(), entry.getValue());
} }
resourcesUsed.put(entry.getKey(), value);
} }
} }
} }