diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/AbstractYarnScheduler.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/AbstractYarnScheduler.java index a798b97af5f..e04e5b942a9 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/AbstractYarnScheduler.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/scheduler/AbstractYarnScheduler.java @@ -34,6 +34,7 @@ import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; +import org.apache.commons.collections.CollectionUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.classification.InterfaceAudience.Private; @@ -289,13 +290,8 @@ public SchedulingMonitorManager getSchedulingMonitorManager() { * @param app application attempt. */ public List getBlacklistedNodes(final SchedulerApplicationAttempt app) { - - NodeFilter nodeFilter = new NodeFilter() { - @Override - public boolean accept(SchedulerNode node) { - return SchedulerAppUtils.isPlaceBlacklisted(app, node, LOG); - } - }; + NodeFilter nodeFilter = + node -> SchedulerAppUtils.isPlaceBlacklisted(app, node, LOG); return nodeTracker.getNodes(nodeFilter); } @@ -490,8 +486,7 @@ public void recoverContainersOnNode(List containerReports, try { writeLock.lock(); if (!rmContext.isWorkPreservingRecoveryEnabled() - || containerReports == null || (containerReports != null - && containerReports.isEmpty())) { + || CollectionUtils.isEmpty(containerReports)) { return; } @@ -778,16 +773,9 @@ public void moveAllApps(String sourceQueue, String destQueue) LOG.warn(e); throw new YarnException(e); } - // check if source queue is a valid - List apps = getAppsInQueue(sourceQueue); - if (apps == null) { - String errMsg = - "The specified Queue: " + sourceQueue + " doesn't exist"; - LOG.warn(errMsg); - throw new YarnException(errMsg); - } + // generate move events for each pending/running app - for (ApplicationAttemptId appAttemptId : apps) { + for (ApplicationAttemptId appAttemptId : getValidQueues(sourceQueue)) { this.rmContext.getDispatcher().getEventHandler() .handle(new RMAppManagerEvent(appAttemptId.getApplicationId(), destQueue, RMAppManagerEventType.APP_MOVE)); @@ -802,15 +790,8 @@ public void killAllAppsInQueue(String queueName) throws YarnException { try { writeLock.lock(); - // check if queue is a valid - List apps = getAppsInQueue(queueName); - if (apps == null) { - String errMsg = "The specified Queue: " + queueName + " doesn't exist"; - LOG.warn(errMsg); - throw new YarnException(errMsg); - } // generate kill events for each pending/running app - for (ApplicationAttemptId app : apps) { + for (ApplicationAttemptId app : getValidQueues(queueName)) { this.rmContext.getDispatcher().getEventHandler().handle( new RMAppEvent(app.getApplicationId(), RMAppEventType.KILL, "Application killed due to expiry of reservation queue " @@ -1538,4 +1519,24 @@ public boolean attemptAllocationOnNode(SchedulerApplicationAttempt appAttempt, public void resetSchedulerMetrics() { // reset scheduler metrics } + + /** + * Get valid queues. Always need to check if queue is a valid, regardless + * of scheduler. So that it guarantee valid queues. + * @param queueName queue name + * @return apps which in specified queue, it maybe empty. + * @throws YarnException if {@link YarnScheduler#getAppsInQueue(String)} + * return null, will throw this exception. + */ + private List getValidQueues(String queueName) + throws YarnException { + List apps = getAppsInQueue(queueName); + if (apps == null) { + String errMsg = "The specified Queue: " + queueName + " doesn't exist"; + LOG.warn(errMsg); + throw new YarnException(errMsg); + } + return apps; + } + }