YARN-7007. NPE in RM while using YarnClient.getApplications(). Contributed by Lingfeng Su.

This commit is contained in:
bibinchundatt 2017-08-18 20:28:50 +05:30
parent c6b4e656b7
commit e05fa3451d
1 changed files with 11 additions and 8 deletions

View File

@ -31,6 +31,7 @@ import org.apache.hadoop.yarn.api.records.ApplicationAttemptId;
import org.apache.hadoop.yarn.api.records.ApplicationResourceUsageReport; import org.apache.hadoop.yarn.api.records.ApplicationResourceUsageReport;
import org.apache.hadoop.yarn.api.records.Resource; import org.apache.hadoop.yarn.api.records.Resource;
import org.apache.hadoop.yarn.server.resourcemanager.RMContext; import org.apache.hadoop.yarn.server.resourcemanager.RMContext;
import org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp;
import org.apache.hadoop.yarn.server.resourcemanager.rmcontainer.RMContainer; import org.apache.hadoop.yarn.server.resourcemanager.rmcontainer.RMContainer;
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.NodeType; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.NodeType;
import org.apache.hadoop.yarn.util.resource.Resources; import org.apache.hadoop.yarn.util.resource.Resources;
@ -125,8 +126,9 @@ public class RMAppAttemptMetrics {
long vcoreSeconds = finishedVcoreSeconds.get(); long vcoreSeconds = finishedVcoreSeconds.get();
// Only add in the running containers if this is the active attempt. // Only add in the running containers if this is the active attempt.
RMAppAttempt currentAttempt = rmContext.getRMApps() RMApp rmApp = rmContext.getRMApps().get(attemptId.getApplicationId());
.get(attemptId.getApplicationId()).getCurrentAppAttempt(); if (null != rmApp) {
RMAppAttempt currentAttempt = rmApp.getCurrentAppAttempt();
if (currentAttempt.getAppAttemptId().equals(attemptId)) { if (currentAttempt.getAppAttemptId().equals(attemptId)) {
ApplicationResourceUsageReport appResUsageReport = rmContext ApplicationResourceUsageReport appResUsageReport = rmContext
.getScheduler().getAppResourceUsageReport(attemptId); .getScheduler().getAppResourceUsageReport(attemptId);
@ -135,6 +137,7 @@ public class RMAppAttemptMetrics {
vcoreSeconds += appResUsageReport.getVcoreSeconds(); vcoreSeconds += appResUsageReport.getVcoreSeconds();
} }
} }
}
return new AggregateAppResourceUsage(memorySeconds, vcoreSeconds); return new AggregateAppResourceUsage(memorySeconds, vcoreSeconds);
} }