From e10050678d0bcd0e4384f2a684daf8c18e30ecb9 Mon Sep 17 00:00:00 2001 From: bibinchundatt Date: Thu, 29 Nov 2018 21:43:34 +0530 Subject: [PATCH] YARN-8948. PlacementRule interface should be for all YarnSchedulers. Contributed by Bibin A Chundatt. (cherry picked from commit a68d766e876631d7ee2e1a6504d4120ba628d178) --- .../placement/AppNameMappingPlacementRule.java | 12 ++++++++++-- .../resourcemanager/placement/PlacementRule.java | 4 ++-- .../placement/UserGroupMappingPlacementRule.java | 11 ++++++++++- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/placement/AppNameMappingPlacementRule.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/placement/AppNameMappingPlacementRule.java index 2debade73b5..7a469627527 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/placement/AppNameMappingPlacementRule.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/placement/AppNameMappingPlacementRule.java @@ -20,11 +20,12 @@ package org.apache.hadoop.yarn.server.resourcemanager.placement; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.hadoop.yarn.api.records.ApplicationId; import org.apache.hadoop.yarn.api.records.ApplicationSubmissionContext; import org.apache.hadoop.yarn.conf.YarnConfiguration; import org.apache.hadoop.yarn.exceptions.YarnException; +import org.apache.hadoop.yarn.server.resourcemanager.scheduler.ResourceScheduler; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CSQueue; +import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacityScheduler; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerContext; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerQueueManager; @@ -61,8 +62,15 @@ public class AppNameMappingPlacementRule extends PlacementRule { } @Override - public boolean initialize(CapacitySchedulerContext schedulerContext) + public boolean initialize(ResourceScheduler scheduler) throws IOException { + if (!(scheduler instanceof CapacityScheduler)) { + throw new IOException( + "AppNameMappingPlacementRule can be configured only for " + + "CapacityScheduler"); + } + CapacitySchedulerContext schedulerContext = + (CapacitySchedulerContext) scheduler; CapacitySchedulerConfiguration conf = schedulerContext.getConfiguration(); boolean overrideWithQueueMappings = conf.getOverrideWithQueueMappings(); LOG.info( diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/placement/PlacementRule.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/placement/PlacementRule.java index 21ab32aeef2..0f3d43c5ad7 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/placement/PlacementRule.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/placement/PlacementRule.java @@ -22,7 +22,7 @@ import java.io.IOException; import org.apache.hadoop.yarn.api.records.ApplicationSubmissionContext; import org.apache.hadoop.yarn.exceptions.YarnException; -import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerContext; +import org.apache.hadoop.yarn.server.resourcemanager.scheduler.ResourceScheduler; public abstract class PlacementRule { @@ -31,7 +31,7 @@ public abstract class PlacementRule { } public abstract boolean initialize( - CapacitySchedulerContext schedulerContext) throws IOException; + ResourceScheduler scheduler) throws IOException; /** * Get queue for a given application diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/placement/UserGroupMappingPlacementRule.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/placement/UserGroupMappingPlacementRule.java index 99f37b1e7a5..a9e823513c8 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/placement/UserGroupMappingPlacementRule.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/placement/UserGroupMappingPlacementRule.java @@ -34,8 +34,10 @@ import org.apache.hadoop.yarn.exceptions.YarnException; import org.apache.hadoop.yarn.server.resourcemanager.placement.UserGroupMappingPlacementRule.QueueMapping.MappingType; import com.google.common.annotations.VisibleForTesting; +import org.apache.hadoop.yarn.server.resourcemanager.scheduler.ResourceScheduler; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.AutoCreatedLeafQueue; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CSQueue; +import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacityScheduler; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerConfiguration; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerContext; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacitySchedulerQueueManager; @@ -230,8 +232,15 @@ public class UserGroupMappingPlacementRule extends PlacementRule { @VisibleForTesting @Override - public boolean initialize(CapacitySchedulerContext schedulerContext) + public boolean initialize(ResourceScheduler scheduler) throws IOException { + if (!(scheduler instanceof CapacityScheduler)) { + throw new IOException( + "UserGroupMappingPlacementRule can be configured only for " + + "CapacityScheduler"); + } + CapacitySchedulerContext schedulerContext = + (CapacitySchedulerContext) scheduler; CapacitySchedulerConfiguration conf = schedulerContext.getConfiguration(); boolean overrideWithQueueMappings = conf.getOverrideWithQueueMappings(); LOG.info(