Repository: ambari Updated Branches: refs/heads/branch-2.5 661a06e10 -> 05aa34686
AMBARI-20622. yarn resource manager failed to start after upgrade with unable to construct queue exception (ncole) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/05aa3468 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/05aa3468 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/05aa3468 Branch: refs/heads/branch-2.5 Commit: 05aa3468653ce3ee33b4a3dac5f39888d57de5c8 Parents: 661a06e Author: Nate Cole <[email protected]> Authored: Wed Mar 29 16:06:23 2017 -0400 Committer: Nate Cole <[email protected]> Committed: Wed Mar 29 18:34:36 2017 -0400 ---------------------------------------------------------------------- .../FixCapacitySchedulerOrderingPolicy.java | 118 +++++++++++++++++ .../HDP/2.3/upgrades/nonrolling-upgrade-2.6.xml | 6 + .../stacks/HDP/2.3/upgrades/upgrade-2.6.xml | 5 + .../HDP/2.4/upgrades/nonrolling-upgrade-2.6.xml | 8 +- .../stacks/HDP/2.4/upgrades/upgrade-2.6.xml | 5 + .../HDP/2.5/upgrades/nonrolling-upgrade-2.6.xml | 6 + .../stacks/HDP/2.5/upgrades/upgrade-2.6.xml | 5 + .../FixCapacitySchedulerOrderingPolicyTest.java | 128 +++++++++++++++++++ 8 files changed, 280 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/05aa3468/ambari-server/src/main/java/org/apache/ambari/server/serveraction/upgrades/FixCapacitySchedulerOrderingPolicy.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/serveraction/upgrades/FixCapacitySchedulerOrderingPolicy.java b/ambari-server/src/main/java/org/apache/ambari/server/serveraction/upgrades/FixCapacitySchedulerOrderingPolicy.java new file mode 100644 index 0000000..fbb88d8 --- /dev/null +++ b/ambari-server/src/main/java/org/apache/ambari/server/serveraction/upgrades/FixCapacitySchedulerOrderingPolicy.java @@ -0,0 +1,118 @@ +/** + * 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.ambari.server.serveraction.upgrades; + +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ConcurrentMap; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.apache.ambari.server.AmbariException; +import org.apache.ambari.server.actionmanager.HostRoleStatus; +import org.apache.ambari.server.agent.CommandReport; +import org.apache.ambari.server.serveraction.AbstractServerAction; +import org.apache.ambari.server.state.Cluster; +import org.apache.ambari.server.state.Clusters; +import org.apache.ambari.server.state.Config; + +import com.google.inject.Inject; + +/** + * In HDP-2.6, the parent queue's cannot have a ordering-policy other than {@code utilization} or + * {@code priority-utilization}. + * + * This class is used when moving from HDP-2.3/HDP-2.4/HDP-2.5 to HDP2.6 + */ +public class FixCapacitySchedulerOrderingPolicy extends AbstractServerAction { + private static final String SOURCE_CONFIG_TYPE = "capacity-scheduler"; + private static final String ORDERING_POLICY_SUFFIX = "ordering-policy"; + + private static final String CAPACITY_SCHEDULER_PREFIX = "yarn.scheduler.capacity"; + private static final String UTILIZATION = "utilization"; + private static final String PRIORITY_UTILIZATION = "priority-utilization"; + + + // queue names with any letter, ., -, or _ + private static final Pattern ROOT_QUEUE_REGEX = Pattern.compile( + String.format("%s.([.\\-_\\w]+).queues", CAPACITY_SCHEDULER_PREFIX)); + + + @Inject + private Clusters clusters; + + @Override + public CommandReport execute(ConcurrentMap<String, Object> requestSharedDataContext) + throws AmbariException, InterruptedException { + + + String clusterName = getExecutionCommand().getClusterName(); + Cluster cluster = clusters.getCluster(clusterName); + Config config = cluster.getDesiredConfigByType(SOURCE_CONFIG_TYPE); + + Map<String, String> properties = config.getProperties(); + + Set<String> parentQueueNames = new HashSet<>(); + + // first find the parent queue names + for (String key : properties.keySet()) { + Matcher matcher = ROOT_QUEUE_REGEX.matcher(key); + if (matcher.matches() && 1 == matcher.groupCount()) { + parentQueueNames.add(matcher.group(1)); + } + } + + if (parentQueueNames.isEmpty()) { + return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", + String.format("The %s has no root queue names.", SOURCE_CONFIG_TYPE), ""); + } + + boolean changedProperties = false; + StringBuilder stdout = new StringBuilder(); + + + for (String queueName : parentQueueNames) { + String orderingPolicyKey = String.format("%s.%s.%s", CAPACITY_SCHEDULER_PREFIX, queueName, ORDERING_POLICY_SUFFIX); + + String orderingPolicyValue = properties.get(orderingPolicyKey); + if (null == orderingPolicyValue) { + stdout.append("Ordering policy not found for ").append(orderingPolicyKey).append(',') + .append(" value will not be set.").append(System.lineSeparator()); + + } else if (!orderingPolicyValue.equals(UTILIZATION) || !orderingPolicyValue.equals(PRIORITY_UTILIZATION)) { + properties.put(orderingPolicyKey, UTILIZATION); + changedProperties = true; + + stdout.append("Changed ordering policy on ").append(orderingPolicyKey) + .append(" from '").append(orderingPolicyValue).append("' to '").append(UTILIZATION) + .append('\'').append(System.lineSeparator()); + } + } + + if (!changedProperties) { + return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", + String.format("No root queues required updating to %s.", UTILIZATION), ""); + } + + config.setProperties(properties); + config.save(); + + return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", stdout.toString(), ""); + } +} http://git-wip-us.apache.org/repos/asf/ambari/blob/05aa3468/ambari-server/src/main/resources/stacks/HDP/2.3/upgrades/nonrolling-upgrade-2.6.xml ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/resources/stacks/HDP/2.3/upgrades/nonrolling-upgrade-2.6.xml b/ambari-server/src/main/resources/stacks/HDP/2.3/upgrades/nonrolling-upgrade-2.6.xml index c8f93e4..dfcd29f 100644 --- a/ambari-server/src/main/resources/stacks/HDP/2.3/upgrades/nonrolling-upgrade-2.6.xml +++ b/ambari-server/src/main/resources/stacks/HDP/2.3/upgrades/nonrolling-upgrade-2.6.xml @@ -303,6 +303,12 @@ <summary>Calculating Yarn Properties for Spark Shuffle</summary> </task> </execute-stage> + + <execute-stage service="YARN" component="RESOURCEMANAGER" title="Validate Root Queue Ordering Policy"> + <task xsi:type="server_action" class="org.apache.ambari.server.serveraction.upgrades.FixCapacitySchedulerOrderingPolicy"> + <summary>Validate Root Queue Ordering Policy</summary> + </task> + </execute-stage> <execute-stage service="YARN" component="RESOURCEMANAGER" title="Adding YARN Security ACLs"> <task xsi:type="configure" id="yarn_env_security_opts"> http://git-wip-us.apache.org/repos/asf/ambari/blob/05aa3468/ambari-server/src/main/resources/stacks/HDP/2.3/upgrades/upgrade-2.6.xml ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/resources/stacks/HDP/2.3/upgrades/upgrade-2.6.xml b/ambari-server/src/main/resources/stacks/HDP/2.3/upgrades/upgrade-2.6.xml index 3c0769a..27d0059 100644 --- a/ambari-server/src/main/resources/stacks/HDP/2.3/upgrades/upgrade-2.6.xml +++ b/ambari-server/src/main/resources/stacks/HDP/2.3/upgrades/upgrade-2.6.xml @@ -752,6 +752,11 @@ <task xsi:type="server_action" class="org.apache.ambari.server.serveraction.upgrades.SparkShufflePropertyConfig"> <summary>Calculating Yarn Properties for Spark Shuffle</summary> </task> + + <task xsi:type="server_action" class="org.apache.ambari.server.serveraction.upgrades.FixCapacitySchedulerOrderingPolicy"> + <summary>Validate Root Queue Ordering Policy</summary> + </task> + <task xsi:type="configure" id="hdp_2_5_0_0_remove_ranger_yarn_audit_db" /> <task xsi:type="configure" id="yarn_log4j_parameterize" /> <task xsi:type="configure" id="yarn_env_security_opts" /> http://git-wip-us.apache.org/repos/asf/ambari/blob/05aa3468/ambari-server/src/main/resources/stacks/HDP/2.4/upgrades/nonrolling-upgrade-2.6.xml ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/resources/stacks/HDP/2.4/upgrades/nonrolling-upgrade-2.6.xml b/ambari-server/src/main/resources/stacks/HDP/2.4/upgrades/nonrolling-upgrade-2.6.xml index 53caa52..7fda46a 100644 --- a/ambari-server/src/main/resources/stacks/HDP/2.4/upgrades/nonrolling-upgrade-2.6.xml +++ b/ambari-server/src/main/resources/stacks/HDP/2.4/upgrades/nonrolling-upgrade-2.6.xml @@ -317,13 +317,19 @@ <summary>Modifying ATS Scan default</summary> </task> </execute-stage> + + <execute-stage service="YARN" component="RESOURCEMANAGER" title="Validate Root Queue Ordering Policy"> + <task xsi:type="server_action" class="org.apache.ambari.server.serveraction.upgrades.FixCapacitySchedulerOrderingPolicy"> + <summary>Validate Root Queue Ordering Policy</summary> + </task> + </execute-stage> <execute-stage service="MAPREDUCE2" component="MAPREDUCE2_CLIENT" title="Apply config changes for Mapreduce2 client"> <task xsi:type="configure" id="hdp_2_6_0_0_mapreduce_job_queuename"> <summary>Adding queue customization property</summary> </task> </execute-stage> - + <!--TEZ--> <execute-stage service="TEZ" component="TEZ_CLIENT" title="Verify LZO codec path for Tez"> <task xsi:type="server_action" class="org.apache.ambari.server.serveraction.upgrades.FixLzoCodecPath"> http://git-wip-us.apache.org/repos/asf/ambari/blob/05aa3468/ambari-server/src/main/resources/stacks/HDP/2.4/upgrades/upgrade-2.6.xml ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/resources/stacks/HDP/2.4/upgrades/upgrade-2.6.xml b/ambari-server/src/main/resources/stacks/HDP/2.4/upgrades/upgrade-2.6.xml index 66f1a64..40784aa 100644 --- a/ambari-server/src/main/resources/stacks/HDP/2.4/upgrades/upgrade-2.6.xml +++ b/ambari-server/src/main/resources/stacks/HDP/2.4/upgrades/upgrade-2.6.xml @@ -757,6 +757,11 @@ <task xsi:type="server_action" class="org.apache.ambari.server.serveraction.upgrades.SparkShufflePropertyConfig"> <summary>Calculating Yarn Properties for Spark Shuffle</summary> </task> + + <task xsi:type="server_action" class="org.apache.ambari.server.serveraction.upgrades.FixCapacitySchedulerOrderingPolicy"> + <summary>Validate Root Queue Ordering Policy</summary> + </task> + <task xsi:type="configure" id="hdp_2_5_0_0_remove_ranger_yarn_audit_db" /> <task xsi:type="configure" id="yarn_log4j_parameterize" /> <task xsi:type="configure" id="yarn_env_security_opts" /> http://git-wip-us.apache.org/repos/asf/ambari/blob/05aa3468/ambari-server/src/main/resources/stacks/HDP/2.5/upgrades/nonrolling-upgrade-2.6.xml ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/resources/stacks/HDP/2.5/upgrades/nonrolling-upgrade-2.6.xml b/ambari-server/src/main/resources/stacks/HDP/2.5/upgrades/nonrolling-upgrade-2.6.xml index 0d6f51b..9139760 100644 --- a/ambari-server/src/main/resources/stacks/HDP/2.5/upgrades/nonrolling-upgrade-2.6.xml +++ b/ambari-server/src/main/resources/stacks/HDP/2.5/upgrades/nonrolling-upgrade-2.6.xml @@ -334,6 +334,12 @@ </task> </execute-stage> + <execute-stage> + <task xsi:type="server_action" class="org.apache.ambari.server.serveraction.upgrades.FixCapacitySchedulerOrderingPolicy"> + <summary>Validate Root Queue Ordering Policy</summary> + </task> + </execute-stage> + <!--TEZ--> <execute-stage service="TEZ" component="TEZ_CLIENT" title="Verify LZO codec path for Tez"> <task xsi:type="server_action" class="org.apache.ambari.server.serveraction.upgrades.FixLzoCodecPath"> http://git-wip-us.apache.org/repos/asf/ambari/blob/05aa3468/ambari-server/src/main/resources/stacks/HDP/2.5/upgrades/upgrade-2.6.xml ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/resources/stacks/HDP/2.5/upgrades/upgrade-2.6.xml b/ambari-server/src/main/resources/stacks/HDP/2.5/upgrades/upgrade-2.6.xml index 44d0a2a..c226492 100644 --- a/ambari-server/src/main/resources/stacks/HDP/2.5/upgrades/upgrade-2.6.xml +++ b/ambari-server/src/main/resources/stacks/HDP/2.5/upgrades/upgrade-2.6.xml @@ -690,6 +690,11 @@ <task xsi:type="configure" id="yarn_site_retained_log_count" /> <task xsi:type="configure" id="hdp_2_6_0_0_service_check_queue_name"/> <task xsi:type="configure" id="hdp_2_6_0_0_ats_scan_interval_default"/> + + <task xsi:type="server_action" class="org.apache.ambari.server.serveraction.upgrades.FixCapacitySchedulerOrderingPolicy"> + <summary>Validate Root Queue Ordering Policy</summary> + </task> + </pre-upgrade> <pre-downgrade /> <upgrade> http://git-wip-us.apache.org/repos/asf/ambari/blob/05aa3468/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/FixCapacitySchedulerOrderingPolicyTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/FixCapacitySchedulerOrderingPolicyTest.java b/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/FixCapacitySchedulerOrderingPolicyTest.java new file mode 100644 index 0000000..4133d9d --- /dev/null +++ b/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/FixCapacitySchedulerOrderingPolicyTest.java @@ -0,0 +1,128 @@ +/** + * 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.ambari.server.serveraction.upgrades; + +import static org.easymock.EasyMock.anyObject; +import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.replay; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +import java.lang.reflect.Field; +import java.util.HashMap; +import java.util.Map; + +import org.apache.ambari.server.actionmanager.ExecutionCommandWrapper; +import org.apache.ambari.server.actionmanager.HostRoleCommand; +import org.apache.ambari.server.agent.CommandReport; +import org.apache.ambari.server.agent.ExecutionCommand; +import org.apache.ambari.server.state.Cluster; +import org.apache.ambari.server.state.Clusters; +import org.apache.ambari.server.state.Config; +import org.easymock.EasyMock; +import org.junit.Before; +import org.junit.Test; + +import com.google.common.collect.ImmutableMap; +import com.google.inject.Injector; + +/** + * Test FixYarnWebServiceUrl logic + */ +public class FixCapacitySchedulerOrderingPolicyTest { + + private Injector injector; + private Clusters clusters; + private Cluster cluster; + private Field clustersField; + private static final String SOURCE_CONFIG_TYPE = "capacity-scheduler"; + + @Before + public void setup() throws Exception { + injector = EasyMock.createMock(Injector.class); + clusters = EasyMock.createMock(Clusters.class); + cluster = EasyMock.createMock(Cluster.class); + clustersField = FixCapacitySchedulerOrderingPolicy.class.getDeclaredField("clusters"); + clustersField.setAccessible(true); + + expect(clusters.getCluster((String) anyObject())).andReturn(cluster).anyTimes(); + expect(injector.getInstance(Clusters.class)).andReturn(clusters).atLeastOnce(); + replay(injector, clusters); + } + + @Test + public void testRootQueues() throws Exception { + + Map<String, String> mockProperties = new HashMap<>(new ImmutableMap.Builder<String, String>() + .put("yarn.scheduler.capacity.root.hbase.queues", "a") + .put("yarn.scheduler.capacity.someRandom_name.queues", "b") + .put("yarn.scheduler.capacity.a-b-c.queues", "c") + .put("yarn.scheduler.capacity._A.queues", "d") + + .put("yarn.scheduler.capacity.root.hbase.a.ordering-policy", "fifo") + .put("yarn.scheduler.capacity.root.hbase.ordering-policy", "fifo") + .put("yarn.scheduler.capacity.someRandom_name.ordering-policy", "junk") + .put("yarn.scheduler.capacity._A.ordering-policy", "") + .build()); + + Config capacitySchedulerConfig = EasyMock.createNiceMock(Config.class); + expect(capacitySchedulerConfig.getType()).andReturn("capacity-scheduler").anyTimes(); + expect(capacitySchedulerConfig.getProperties()).andReturn(mockProperties).anyTimes(); + + expect(cluster.getDesiredConfigByType(SOURCE_CONFIG_TYPE)).andReturn(capacitySchedulerConfig).atLeastOnce(); + + Map<String, String> commandParams = new HashMap<>(); + commandParams.put("clusterName", "c1"); + + ExecutionCommand executionCommand = new ExecutionCommand(); + executionCommand.setCommandParams(commandParams); + executionCommand.setClusterName("c1"); + + HostRoleCommand hrc = EasyMock.createMock(HostRoleCommand.class); + expect(hrc.getRequestId()).andReturn(1L).anyTimes(); + expect(hrc.getStageId()).andReturn(2L).anyTimes(); + expect(hrc.getExecutionCommandWrapper()).andReturn(new ExecutionCommandWrapper(executionCommand)).anyTimes(); + replay(cluster, hrc, capacitySchedulerConfig); + + + FixCapacitySchedulerOrderingPolicy action = new FixCapacitySchedulerOrderingPolicy(); + clustersField.set(action, clusters); + + action.setExecutionCommand(executionCommand); + action.setHostRoleCommand(hrc); + + CommandReport report = action.execute(null); + assertNotNull(report); + + Cluster c = clusters.getCluster("c1"); + Config capacityConfig = c.getDesiredConfigByType(SOURCE_CONFIG_TYPE); + + Map<String, String> capacityMap = capacityConfig.getProperties(); + + // these roots should be fixed + assertEquals("utilization", capacityMap.get("yarn.scheduler.capacity._A.ordering-policy")); + assertEquals("utilization", capacityMap.get("yarn.scheduler.capacity.root.hbase.ordering-policy")); + assertEquals("utilization", capacityMap.get("yarn.scheduler.capacity.someRandom_name.ordering-policy")); + // make sure a leaf stays as-is + assertEquals("fifo", capacityMap.get("yarn.scheduler.capacity.root.hbase.a.ordering-policy")); + assertNull(capacityMap.get("yarn.scheduler.capacity.a-b-c.ordering-policy")); + + } + +}
