diff --git a/hadoop-tools/hadoop-sls/src/main/java/org/apache/hadoop/yarn/sls/AMRunner.java b/hadoop-tools/hadoop-sls/src/main/java/org/apache/hadoop/yarn/sls/AMRunner.java index 8ce8d29a01a..2dc09de6653 100644 --- a/hadoop-tools/hadoop-sls/src/main/java/org/apache/hadoop/yarn/sls/AMRunner.java +++ b/hadoop-tools/hadoop-sls/src/main/java/org/apache/hadoop/yarn/sls/AMRunner.java @@ -44,8 +44,11 @@ import java.io.IOException; import java.io.InputStreamReader; import java.io.Reader; import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.Iterator; +import java.util.List; import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; @@ -53,7 +56,7 @@ import java.util.concurrent.ConcurrentHashMap; public class AMRunner { private static final Logger LOG = LoggerFactory.getLogger(AMRunner.class); - static int remainingApps = 0; + int remainingApps = 0; private final Configuration conf; private int AM_ID; @@ -263,7 +266,7 @@ public class AMRunner { } public void setInputTraces(String[] inputTraces) { - this.inputTraces = inputTraces; + this.inputTraces = inputTraces.clone(); } public void setResourceManager(ResourceManager rm) { diff --git a/hadoop-tools/hadoop-sls/src/main/java/org/apache/hadoop/yarn/sls/NMRunner.java b/hadoop-tools/hadoop-sls/src/main/java/org/apache/hadoop/yarn/sls/NMRunner.java index 224e1e373ff..14524a4e04a 100644 --- a/hadoop-tools/hadoop-sls/src/main/java/org/apache/hadoop/yarn/sls/NMRunner.java +++ b/hadoop-tools/hadoop-sls/src/main/java/org/apache/hadoop/yarn/sls/NMRunner.java @@ -205,7 +205,7 @@ public class NMRunner { } public void setInputTraces(String[] inputTraces) { - this.inputTraces = inputTraces; + this.inputTraces = inputTraces.clone(); } public int getNumNMs() { diff --git a/hadoop-tools/hadoop-sls/src/main/java/org/apache/hadoop/yarn/sls/SLSRunner.java b/hadoop-tools/hadoop-sls/src/main/java/org/apache/hadoop/yarn/sls/SLSRunner.java index 0909a45cc47..c14d5685b7d 100644 --- a/hadoop-tools/hadoop-sls/src/main/java/org/apache/hadoop/yarn/sls/SLSRunner.java +++ b/hadoop-tools/hadoop-sls/src/main/java/org/apache/hadoop/yarn/sls/SLSRunner.java @@ -98,8 +98,8 @@ public class SLSRunner extends Configured implements Tool { public static final String NETWORK_NEGATIVE_CACHE_TTL = "networkaddress.cache.negative.ttl"; - public static int getRemainingApps() { - return AMRunner.remainingApps; + public int getRemainingApps() { + return amRunner.remainingApps; } public SLSRunner() throws ClassNotFoundException, YarnException { @@ -204,6 +204,7 @@ public class SLSRunner extends Configured implements Tool { // set queue & tracked apps information SchedulerWrapper resourceScheduler = (SchedulerWrapper) rmRunner.getRm().getResourceScheduler(); + resourceScheduler.setSLSRunner(this); Tracker tracker = resourceScheduler.getTracker(); tracker.setQueueSet(rmRunner.getQueueAppNumMap().keySet()); tracker.setTrackedAppSet(amRunner.getTrackedApps()); @@ -301,9 +302,9 @@ public class SLSRunner extends Configured implements Tool { return nmRunner.getNmMap(); } - public static void decreaseRemainingApps() { - AMRunner.remainingApps--; - if (AMRunner.remainingApps == 0) { + public void decreaseRemainingApps() { + amRunner.remainingApps--; + if (amRunner.remainingApps == 0) { exitSLSRunner(); } } diff --git a/hadoop-tools/hadoop-sls/src/main/java/org/apache/hadoop/yarn/sls/scheduler/SLSCapacityScheduler.java b/hadoop-tools/hadoop-sls/src/main/java/org/apache/hadoop/yarn/sls/scheduler/SLSCapacityScheduler.java index 39170b18727..18e12cca05f 100644 --- a/hadoop-tools/hadoop-sls/src/main/java/org/apache/hadoop/yarn/sls/scheduler/SLSCapacityScheduler.java +++ b/hadoop-tools/hadoop-sls/src/main/java/org/apache/hadoop/yarn/sls/scheduler/SLSCapacityScheduler.java @@ -35,6 +35,7 @@ import org.apache.hadoop.yarn.server.resourcemanager.scheduler.ContainerUpdates; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacityScheduler; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.common.ResourceCommitRequest; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.event.SchedulerEvent; +import org.apache.hadoop.yarn.sls.SLSRunner; @Private @Unstable @@ -43,6 +44,7 @@ public class SLSCapacityScheduler extends CapacityScheduler implements private final SLSSchedulerCommons schedulerCommons; private Configuration conf; + private SLSRunner runner; public SLSCapacityScheduler() { schedulerCommons = new SLSSchedulerCommons(this); @@ -138,5 +140,15 @@ public class SLSCapacityScheduler extends CapacityScheduler implements public Tracker getTracker() { return schedulerCommons.getTracker(); } + + @Override + public void setSLSRunner(SLSRunner runner) { + this.runner = runner; + } + + @Override + public SLSRunner getSLSRunner() { + return this.runner; + } } diff --git a/hadoop-tools/hadoop-sls/src/main/java/org/apache/hadoop/yarn/sls/scheduler/SLSFairScheduler.java b/hadoop-tools/hadoop-sls/src/main/java/org/apache/hadoop/yarn/sls/scheduler/SLSFairScheduler.java index 2835b413cab..1b4d5ced69b 100644 --- a/hadoop-tools/hadoop-sls/src/main/java/org/apache/hadoop/yarn/sls/scheduler/SLSFairScheduler.java +++ b/hadoop-tools/hadoop-sls/src/main/java/org/apache/hadoop/yarn/sls/scheduler/SLSFairScheduler.java @@ -30,6 +30,8 @@ import org.apache.hadoop.yarn.server.resourcemanager.scheduler.Allocation; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.ContainerUpdates; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.event.SchedulerEvent; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.FairScheduler; +import org.apache.hadoop.yarn.sls.SLSRunner; + import java.util.List; @Private @@ -37,6 +39,7 @@ import java.util.List; public class SLSFairScheduler extends FairScheduler implements SchedulerWrapper, Configurable { private final SLSSchedulerCommons schedulerCommons; + private SLSRunner runner; public SLSFairScheduler() { schedulerCommons = new SLSSchedulerCommons(this); @@ -99,4 +102,14 @@ public class SLSFairScheduler extends FairScheduler public Tracker getTracker() { return schedulerCommons.getTracker(); } + + @Override + public void setSLSRunner(SLSRunner runner) { + this.runner = runner; + } + + @Override + public SLSRunner getSLSRunner() { + return this.runner; + } } \ No newline at end of file diff --git a/hadoop-tools/hadoop-sls/src/main/java/org/apache/hadoop/yarn/sls/scheduler/SLSSchedulerCommons.java b/hadoop-tools/hadoop-sls/src/main/java/org/apache/hadoop/yarn/sls/scheduler/SLSSchedulerCommons.java index ee70dfbe3e9..a99fe53eff9 100644 --- a/hadoop-tools/hadoop-sls/src/main/java/org/apache/hadoop/yarn/sls/scheduler/SLSSchedulerCommons.java +++ b/hadoop-tools/hadoop-sls/src/main/java/org/apache/hadoop/yarn/sls/scheduler/SLSSchedulerCommons.java @@ -205,6 +205,7 @@ public class SLSSchedulerCommons { } public void handle(SchedulerEvent schedulerEvent) { + SchedulerWrapper wrapper = (SchedulerWrapper) scheduler; if (!metricsON) { ((SchedulerWrapper)scheduler).propagatedHandle(schedulerEvent); return; @@ -259,11 +260,11 @@ public class SLSSchedulerCommons { if (schedulerEvent.getType() == SchedulerEventType.APP_ATTEMPT_REMOVED && schedulerEvent instanceof AppAttemptRemovedSchedulerEvent) { - SLSRunner.decreaseRemainingApps(); + wrapper.getSLSRunner().decreaseRemainingApps(); AppAttemptRemovedSchedulerEvent appRemoveEvent = (AppAttemptRemovedSchedulerEvent) schedulerEvent; appQueueMap.remove(appRemoveEvent.getApplicationAttemptID()); - if (SLSRunner.getRemainingApps() == 0) { + if (wrapper.getSLSRunner().getRemainingApps() == 0) { try { schedulerMetrics.tearDown(); SLSRunner.exitSLSRunner(); diff --git a/hadoop-tools/hadoop-sls/src/main/java/org/apache/hadoop/yarn/sls/scheduler/SchedulerWrapper.java b/hadoop-tools/hadoop-sls/src/main/java/org/apache/hadoop/yarn/sls/scheduler/SchedulerWrapper.java index 5ee088d792a..cc9844a8f2a 100644 --- a/hadoop-tools/hadoop-sls/src/main/java/org/apache/hadoop/yarn/sls/scheduler/SchedulerWrapper.java +++ b/hadoop-tools/hadoop-sls/src/main/java/org/apache/hadoop/yarn/sls/scheduler/SchedulerWrapper.java @@ -27,6 +27,7 @@ import org.apache.hadoop.yarn.exceptions.YarnException; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.Allocation; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.ContainerUpdates; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.event.SchedulerEvent; +import org.apache.hadoop.yarn.sls.SLSRunner; import java.util.List; @@ -48,4 +49,8 @@ public interface SchedulerWrapper { List blacklistAdditions, List blacklistRemovals, ContainerUpdates updateRequests); + + void setSLSRunner(SLSRunner runner); + + SLSRunner getSLSRunner(); }