diff --git a/hadoop-yarn-project/CHANGES.txt b/hadoop-yarn-project/CHANGES.txt index dbb1e7c9a8..dd760fd69f 100644 --- a/hadoop-yarn-project/CHANGES.txt +++ b/hadoop-yarn-project/CHANGES.txt @@ -109,6 +109,9 @@ Release 2.3.0 - UNRELEASED YARN-1305. RMHAProtocolService#serviceInit should handle HAUtil's IllegalArgumentException (Tsuyoshi Ozawa via bikas) + YARN-1374. Changed ResourceManager to start the preemption policy monitors + as active services. (Karthik Kambatla via vinodkv) + Release 2.2.1 - UNRELEASED INCOMPATIBLE CHANGES diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/ResourceManager.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/ResourceManager.java index f9ee0974a8..41b119e851 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/ResourceManager.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/ResourceManager.java @@ -501,6 +501,36 @@ protected void serviceStop() throws Exception { super.serviceStop(); } + + protected void createPolicyMonitors() { + if (scheduler instanceof PreemptableResourceScheduler + && conf.getBoolean(YarnConfiguration.RM_SCHEDULER_ENABLE_MONITORS, + YarnConfiguration.DEFAULT_RM_SCHEDULER_ENABLE_MONITORS)) { + LOG.info("Loading policy monitors"); + List policies = conf.getInstances( + YarnConfiguration.RM_SCHEDULER_MONITOR_POLICIES, + SchedulingEditPolicy.class); + if (policies.size() > 0) { + rmDispatcher.register(ContainerPreemptEventType.class, + new RMContainerPreemptEventDispatcher( + (PreemptableResourceScheduler) scheduler)); + for (SchedulingEditPolicy policy : policies) { + LOG.info("LOADING SchedulingEditPolicy:" + policy.getPolicyName()); + policy.init(conf, rmContext.getDispatcher().getEventHandler(), + (PreemptableResourceScheduler) scheduler); + // periodically check whether we need to take action to guarantee + // constraints + SchedulingMonitor mon = new SchedulingMonitor(policy); + addService(mon); + } + } else { + LOG.warn("Policy monitors configured (" + + YarnConfiguration.RM_SCHEDULER_ENABLE_MONITORS + + ") but none specified (" + + YarnConfiguration.RM_SCHEDULER_MONITOR_POLICIES + ")"); + } + } + } } @Private @@ -829,37 +859,6 @@ protected ApplicationMasterService createApplicationMasterService() { return new ApplicationMasterService(this.rmContext, scheduler); } - protected void createPolicyMonitors() { - if (scheduler instanceof PreemptableResourceScheduler - && conf.getBoolean(YarnConfiguration.RM_SCHEDULER_ENABLE_MONITORS, - YarnConfiguration.DEFAULT_RM_SCHEDULER_ENABLE_MONITORS)) { - LOG.info("Loading policy monitors"); - List policies = conf.getInstances( - YarnConfiguration.RM_SCHEDULER_MONITOR_POLICIES, - SchedulingEditPolicy.class); - if (policies.size() > 0) { - this.rmDispatcher.register(ContainerPreemptEventType.class, - new RMContainerPreemptEventDispatcher( - (PreemptableResourceScheduler) scheduler)); - for (SchedulingEditPolicy policy : policies) { - LOG.info("LOADING SchedulingEditPolicy:" + policy.getPolicyName()); - policy.init(conf, this.rmContext.getDispatcher().getEventHandler(), - (PreemptableResourceScheduler) scheduler); - // periodically check whether we need to take action to guarantee - // constraints - SchedulingMonitor mon = new SchedulingMonitor(policy); - addService(mon); - - } - } else { - LOG.warn("Policy monitors configured (" + - YarnConfiguration.RM_SCHEDULER_ENABLE_MONITORS + - ") but none specified (" + - YarnConfiguration.RM_SCHEDULER_MONITOR_POLICIES + ")"); - } - } - } - protected AdminService createAdminService( ClientRMService clientRMService, ApplicationMasterService applicationMasterService, diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/TestSchedulingMonitor.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/TestSchedulingMonitor.java new file mode 100644 index 0000000000..5bf61e347d --- /dev/null +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/monitor/TestSchedulingMonitor.java @@ -0,0 +1,46 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.yarn.server.resourcemanager.monitor; + +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.yarn.conf.YarnConfiguration; +import org.apache.hadoop.yarn.server.resourcemanager.ResourceManager; +import org.apache.hadoop.yarn.server.resourcemanager.monitor.capacity.ProportionalCapacityPreemptionPolicy; +import org.junit.Test; + +import static org.junit.Assert.fail; + +public class TestSchedulingMonitor { + + @Test(timeout = 10000) + public void testRMStarts() { + Configuration conf = new YarnConfiguration(); + conf.setBoolean(YarnConfiguration.RM_SCHEDULER_ENABLE_MONITORS, true); + conf.set(YarnConfiguration.RM_SCHEDULER_MONITOR_POLICIES, + ProportionalCapacityPreemptionPolicy.class.getCanonicalName()); + + ResourceManager rm = new ResourceManager(); + try { + rm.init(conf); + } catch (Exception e) { + fail("ResourceManager does not start when " + + YarnConfiguration.RM_SCHEDULER_ENABLE_MONITORS + " is set to true"); + } + } +}