diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/logaggregation/AggregatedLogFormat.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/logaggregation/AggregatedLogFormat.java index 0aa318c8ce..0f729ccad4 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/logaggregation/AggregatedLogFormat.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/logaggregation/AggregatedLogFormat.java @@ -310,31 +310,37 @@ public String getUser() { } private Set getPendingLogFilesToUpload(File containerLogDir) { - Set candidates = - new HashSet(Arrays.asList(containerLogDir.listFiles())); - for (File logFile : candidates) { - this.allExistingFileMeta.add(getLogFileMetaData(logFile)); - } + File[] containerLogs = containerLogDir.listFiles(); + Set candidates = new HashSet(); + if(containerLogs != null) { + candidates.addAll(Arrays.asList(containerLogs)); + for (File logFile : candidates) { + this.allExistingFileMeta.add(getLogFileMetaData(logFile)); + } - // if log files are older than retention policy, do not upload them. - // but schedule them for deletion. - if(logRetentionContext != null && !logRetentionContext.shouldRetainLog()){ - obseleteRetentionLogFiles.addAll(candidates); - candidates.clear(); - return candidates; - } + // if log files are older than retention policy, do not upload them. + // but schedule them for deletion. + if (logRetentionContext != null && !logRetentionContext + .shouldRetainLog()) { + obseleteRetentionLogFiles.addAll(candidates); + candidates.clear(); + return candidates; + } - Set fileCandidates = new HashSet(candidates); - if (this.logAggregationContext != null && candidates.size() > 0) { - fileCandidates = getFileCandidates(fileCandidates, this.appFinished); - if (!this.appFinished && this.containerFinished) { - Set addition = new HashSet(candidates); - addition = getFileCandidates(addition, true); - fileCandidates.addAll(addition); + Set fileCandidates = new HashSet(candidates); + if (this.logAggregationContext != null && candidates.size() > 0) { + fileCandidates = getFileCandidates(fileCandidates, this.appFinished); + if (!this.appFinished && this.containerFinished) { + Set addition = new HashSet(candidates); + addition = getFileCandidates(addition, true); + fileCandidates.addAll(addition); + } } - } - return fileCandidates; + return fileCandidates; + } + // If there is no available logs, return an empty set. + return candidates; } private Set getFileCandidates(Set candidates, diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/util/ProcfsBasedProcessTree.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/util/ProcfsBasedProcessTree.java index a08b90e608..904f377df9 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/util/ProcfsBasedProcessTree.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/util/ProcfsBasedProcessTree.java @@ -481,18 +481,23 @@ private static String getValidPID(String pid) { * Get the list of all processes in the system. */ private List getProcessList() { - String[] processDirs = (new File(procfsDir)).list(); List processList = new ArrayList(); - - for (String dir : processDirs) { - Matcher m = numberPattern.matcher(dir); - if (!m.matches()) continue; - try { - if ((new File(procfsDir, dir)).isDirectory()) { - processList.add(dir); + if (procfsDir != null) { + String[] processDirs = (new File(procfsDir)).list(); + if (processDirs != null) { + for (String dir : processDirs) { + Matcher m = numberPattern.matcher(dir); + if (!m.matches()) { + continue; + } + try { + if ((new File(procfsDir, dir)).isDirectory()) { + processList.add(dir); + } + } catch (SecurityException s) { + // skip this process + } } - } catch (SecurityException s) { - // skip this process } } return processList;