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,14 +126,16 @@ 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) {
if (currentAttempt.getAppAttemptId().equals(attemptId)) { RMAppAttempt currentAttempt = rmApp.getCurrentAppAttempt();
ApplicationResourceUsageReport appResUsageReport = rmContext if (currentAttempt.getAppAttemptId().equals(attemptId)) {
.getScheduler().getAppResourceUsageReport(attemptId); ApplicationResourceUsageReport appResUsageReport = rmContext
if (appResUsageReport != null) { .getScheduler().getAppResourceUsageReport(attemptId);
memorySeconds += appResUsageReport.getMemorySeconds(); if (appResUsageReport != null) {
vcoreSeconds += appResUsageReport.getVcoreSeconds(); memorySeconds += appResUsageReport.getMemorySeconds();
vcoreSeconds += appResUsageReport.getVcoreSeconds();
}
} }
} }
return new AggregateAppResourceUsage(memorySeconds, vcoreSeconds); return new AggregateAppResourceUsage(memorySeconds, vcoreSeconds);