Repository: ambari Updated Branches: refs/heads/branch-2.5 83bdf4b3b -> 1b1c08088
AMBARI-19800. Add precheck for Auto-Start being disabled (ncole) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/1b1c0808 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/1b1c0808 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/1b1c0808 Branch: refs/heads/branch-2.5 Commit: 1b1c08088052530f7f79c67ea231b7ab3e1a0aa0 Parents: 83bdf4b Author: Nate Cole <nc...@hortonworks.com> Authored: Wed Feb 1 16:31:01 2017 -0500 Committer: Nate Cole <nc...@hortonworks.com> Committed: Thu Feb 2 09:26:13 2017 -0500 ---------------------------------------------------------------------- .../server/checks/AutoStartDisabledCheck.java | 74 ++++++++++++ .../ambari/server/checks/CheckDescription.java | 7 ++ .../checks/AutoStartDisabledCheckTest.java | 121 +++++++++++++++++++ 3 files changed, 202 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/1b1c0808/ambari-server/src/main/java/org/apache/ambari/server/checks/AutoStartDisabledCheck.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/checks/AutoStartDisabledCheck.java b/ambari-server/src/main/java/org/apache/ambari/server/checks/AutoStartDisabledCheck.java new file mode 100644 index 0000000..c41ad20 --- /dev/null +++ b/ambari-server/src/main/java/org/apache/ambari/server/checks/AutoStartDisabledCheck.java @@ -0,0 +1,74 @@ +/* + * 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.checks; + +import org.apache.ambari.server.AmbariException; +import org.apache.ambari.server.controller.PrereqCheckRequest; +import org.apache.ambari.server.state.stack.PrereqCheckStatus; +import org.apache.ambari.server.state.stack.PrerequisiteCheck; +import org.apache.ambari.server.state.stack.upgrade.UpgradeType; +import org.apache.commons.lang.StringUtils; + +import com.google.inject.Singleton; + +/** + * The {@link AutoStartDisabledCheck} class is used to check that the cluster does + * not have auto-restart enabled. + */ +@Singleton +@UpgradeCheck( + group = UpgradeCheckGroup.CONFIGURATION_WARNING, + required = { UpgradeType.ROLLING, UpgradeType.NON_ROLLING, UpgradeType.HOST_ORDERED }) +public class AutoStartDisabledCheck extends AbstractCheckDescriptor { + + static final String CLUSTER_ENV_TYPE = "cluster-env"; + static final String RECOVERY_ENABLED_KEY = "recovery_enabled"; + static final String RECOVERY_TYPE_KEY = "recovery_type"; + static final String RECOVERY_AUTO_START = "AUTO_START"; + + /** + * Constructor. + */ + public AutoStartDisabledCheck() { + super(CheckDescription.AUTO_START_DISABLED); + } + + /** + * {@inheritDoc} + */ + @Override + public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException { + + String autoStartEnabled = getProperty(request, CLUSTER_ENV_TYPE, RECOVERY_ENABLED_KEY); + + // !!! auto-start is already disabled + if (!Boolean.valueOf(autoStartEnabled)) { + return; + } + + // !!! double check the value is AUTO_START. it's the only supported value (and there's no enum for it) + String recoveryType = getProperty(request, CLUSTER_ENV_TYPE, RECOVERY_TYPE_KEY); + if (StringUtils.equals(recoveryType, RECOVERY_AUTO_START)) { + + prerequisiteCheck.setFailReason(getFailReason(prerequisiteCheck, request)); + prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL); + prerequisiteCheck.getFailedOn().add(request.getClusterName()); + + } + } +} http://git-wip-us.apache.org/repos/asf/ambari/blob/1b1c0808/ambari-server/src/main/java/org/apache/ambari/server/checks/CheckDescription.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/checks/CheckDescription.java b/ambari-server/src/main/java/org/apache/ambari/server/checks/CheckDescription.java index a204ada..8d8f540 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/checks/CheckDescription.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/checks/CheckDescription.java @@ -313,6 +313,13 @@ public class CheckDescription { .put(AbstractCheckDescriptor.DEFAULT, "Storm does not support rolling upgrades on this version of the stack. If you proceed, you will be required to stop all running topologies before Storm is restarted.").build()); + public static CheckDescription AUTO_START_DISABLED = new CheckDescription("AUTO_START_DISABLED", + PrereqCheckType.CLUSTER, + "Auto-Start Disabled Check", + new ImmutableMap.Builder<String, String>() + .put(AbstractCheckDescriptor.DEFAULT, + "Auto-Start must be disabled before performing an Upgrade").build()); + private String m_name; private PrereqCheckType m_type; http://git-wip-us.apache.org/repos/asf/ambari/blob/1b1c0808/ambari-server/src/test/java/org/apache/ambari/server/checks/AutoStartDisabledCheckTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/checks/AutoStartDisabledCheckTest.java b/ambari-server/src/test/java/org/apache/ambari/server/checks/AutoStartDisabledCheckTest.java new file mode 100644 index 0000000..c1e2ce7 --- /dev/null +++ b/ambari-server/src/test/java/org/apache/ambari/server/checks/AutoStartDisabledCheckTest.java @@ -0,0 +1,121 @@ +/** + * 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.checks; + +import static org.easymock.EasyMock.anyObject; +import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.replay; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.ambari.server.controller.PrereqCheckRequest; +import org.apache.ambari.server.state.Cluster; +import org.apache.ambari.server.state.Clusters; +import org.apache.ambari.server.state.Config; +import org.apache.ambari.server.state.DesiredConfig; +import org.apache.ambari.server.state.stack.PrereqCheckStatus; +import org.apache.ambari.server.state.stack.PrerequisiteCheck; +import org.easymock.EasyMock; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import com.google.inject.Provider; + +/** + * Tests for {@link AutoStartDisabledCheck} + */ +public class AutoStartDisabledCheckTest { + + private final AutoStartDisabledCheck m_check = new AutoStartDisabledCheck(); + private final Clusters m_clusters = EasyMock.createMock(Clusters.class); + private Map<String, String> m_configMap = new HashMap<>(); + + @Before + public void before() throws Exception { + + m_check.clustersProvider = new Provider<Clusters>() { + @Override + public Clusters get() { + return m_clusters; + } + }; + + Cluster cluster = EasyMock.createMock(Cluster.class); + + Map<String, DesiredConfig> map = new HashMap<>(); + map.put(AutoStartDisabledCheck.CLUSTER_ENV_TYPE, new DesiredConfig()); + + expect(cluster.getDesiredConfigs()).andReturn(map).anyTimes(); + + Config config = EasyMock.createMock(Config.class); + expect(config.getProperties()).andReturn(m_configMap).anyTimes(); + + expect(cluster.getConfig(EasyMock.eq(AutoStartDisabledCheck.CLUSTER_ENV_TYPE), EasyMock.anyString())) + .andReturn(config).anyTimes(); + + expect(m_clusters.getCluster((String) anyObject())).andReturn(cluster).anyTimes(); + + replay(m_clusters, cluster, config); + + m_configMap.clear(); + } + + @Test + public void testNoAutoStart() throws Exception { + PrerequisiteCheck check = new PrerequisiteCheck(CheckDescription.AUTO_START_DISABLED, "foo"); + PrereqCheckRequest request = new PrereqCheckRequest("cluster"); + + Assert.assertTrue(m_check.isApplicable(request)); + + m_check.perform(check, request); + + Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus()); + } + + @Test + public void testAutoStartFalse() throws Exception { + PrerequisiteCheck check = new PrerequisiteCheck(CheckDescription.AUTO_START_DISABLED, "foo"); + PrereqCheckRequest request = new PrereqCheckRequest("cluster"); + + Assert.assertTrue(m_check.isApplicable(request)); + + m_configMap.put(AutoStartDisabledCheck.RECOVERY_ENABLED_KEY, "false"); + + m_check.perform(check, request); + + Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus()); + } + + @Test + public void testAutoStartTrue() throws Exception { + PrerequisiteCheck check = new PrerequisiteCheck(CheckDescription.AUTO_START_DISABLED, "foo"); + PrereqCheckRequest request = new PrereqCheckRequest("cluster"); + + Assert.assertTrue(m_check.isApplicable(request)); + + m_configMap.put(AutoStartDisabledCheck.RECOVERY_ENABLED_KEY, "true"); + m_configMap.put(AutoStartDisabledCheck.RECOVERY_TYPE_KEY, AutoStartDisabledCheck.RECOVERY_AUTO_START); + + m_check.perform(check, request); + + Assert.assertEquals(PrereqCheckStatus.FAIL, check.getStatus()); + } + +}