Repository: ambari Updated Branches: refs/heads/trunk 78b4450e3 -> b8eccc7e8
AMBARI-11288 - During Upgrade Warn If Multiple Metastores Are Not Present (jonathanhurley) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/b8eccc7e Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/b8eccc7e Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/b8eccc7e Branch: refs/heads/trunk Commit: b8eccc7e8d18a4e6591ad0fb7e81f2bb85956a95 Parents: 78b4450 Author: Jonathan Hurley <[email protected]> Authored: Wed May 20 18:45:09 2015 -0400 Committer: Jonathan Hurley <[email protected]> Committed: Thu May 21 09:48:53 2015 -0400 ---------------------------------------------------------------------- .../ambari/server/checks/CheckDescription.java | 11 +- .../checks/HiveMultipleMetastoreCheck.java | 89 +++++++++++++ .../ambari/server/checks/UpgradeCheckGroup.java | 6 + .../checks/YarnRMHighAvailabilityCheck.java | 2 +- .../checks/TestHiveMultipleMetastoreCheck.java | 124 +++++++++++++++++++ 5 files changed, 229 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/b8eccc7e/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 8e92cfe..23a575a 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 @@ -72,6 +72,13 @@ public enum CheckDescription { put(AbstractCheckDescriptor.DEFAULT, "The SNameNode component must be deleted from host: {{fails}}."); }}), + SERVICES_HIVE_MULTIPLE_METASTORES(PrereqCheckType.SERVICE, + "Hive Metastore Availability", + new HashMap<String, String>() {{ + put(AbstractCheckDescriptor.DEFAULT, + "Multiple Hive Metastore instances are recommended for Rolling Upgrade. This ensures that there is at least one Metastore running during the upgrade process."); + }}), + SERVICES_MAINTENANCE_MODE(PrereqCheckType.SERVICE, "No services can be in Maintenance Mode", new HashMap<String, String>() {{ @@ -134,10 +141,10 @@ public enum CheckDescription { }}), SERVICES_YARN_RM_HA(PrereqCheckType.SERVICE, - "YARN ResourceManager HA should be enabled to prevent a disruption in service during the upgrade", + "YARN ResourceManager High Availability is not enabled.", new HashMap<String, String>() {{ put(AbstractCheckDescriptor.DEFAULT, - "YARN ResourceManager High Availability is not enabled. Verify that dfs.nameservices property is present in hdfs-site.xml."); + "YARN ResourceManager HA should be enabled to prevent a disruption in service during the upgrade"); }}), SERVICES_YARN_TIMELINE_ST(PrereqCheckType.SERVICE, http://git-wip-us.apache.org/repos/asf/ambari/blob/b8eccc7e/ambari-server/src/main/java/org/apache/ambari/server/checks/HiveMultipleMetastoreCheck.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/checks/HiveMultipleMetastoreCheck.java b/ambari-server/src/main/java/org/apache/ambari/server/checks/HiveMultipleMetastoreCheck.java new file mode 100644 index 0000000..5b3e2a0 --- /dev/null +++ b/ambari-server/src/main/java/org/apache/ambari/server/checks/HiveMultipleMetastoreCheck.java @@ -0,0 +1,89 @@ +/* + * 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 java.util.Map; + +import org.apache.ambari.server.AmbariException; +import org.apache.ambari.server.ServiceComponentNotFoundException; +import org.apache.ambari.server.controller.PrereqCheckRequest; +import org.apache.ambari.server.state.Cluster; +import org.apache.ambari.server.state.Service; +import org.apache.ambari.server.state.ServiceComponent; +import org.apache.ambari.server.state.ServiceComponentHost; +import org.apache.ambari.server.state.stack.PrereqCheckStatus; +import org.apache.ambari.server.state.stack.PrerequisiteCheck; + +import com.google.inject.Singleton; + +/** + * The {@link HiveMultipleMetastoreCheck} checks that there are at least 2 Hive + * Metastore instances in the cluster. + */ +@Singleton +@UpgradeCheck(group = UpgradeCheckGroup.MULTIPLE_COMPONENT_WARNING, order = 1.0f) +public class HiveMultipleMetastoreCheck extends AbstractCheckDescriptor { + + /** + * Constructor. + */ + public HiveMultipleMetastoreCheck() { + super(CheckDescription.SERVICES_HIVE_MULTIPLE_METASTORES); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean isApplicable(PrereqCheckRequest request) throws AmbariException { + if (!super.isApplicable(request)) { + return false; + } + + final Cluster cluster = clustersProvider.get().getCluster(request.getClusterName()); + Map<String, Service> services = cluster.getServices(); + if (!services.containsKey("HIVE")) { + return false; + } + + return true; + } + + /** + * {@inheritDoc} + */ + @Override + public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException { + final String clusterName = request.getClusterName(); + final Cluster cluster = clustersProvider.get().getCluster(clusterName); + + try { + Service hive = cluster.getService("HIVE"); + ServiceComponent metastore = hive.getServiceComponent("HIVE_METASTORE"); + Map<String, ServiceComponentHost> metastores = metastore.getServiceComponentHosts(); + + if (metastores.size() < 2) { + prerequisiteCheck.setStatus(PrereqCheckStatus.WARNING); + prerequisiteCheck.setFailReason(getFailReason(prerequisiteCheck, request)); + } + } catch (ServiceComponentNotFoundException scnfe) { + prerequisiteCheck.setStatus(PrereqCheckStatus.WARNING); + prerequisiteCheck.setFailReason(getFailReason(prerequisiteCheck, request)); + } + } +} http://git-wip-us.apache.org/repos/asf/ambari/blob/b8eccc7e/ambari-server/src/main/java/org/apache/ambari/server/checks/UpgradeCheckGroup.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/checks/UpgradeCheckGroup.java b/ambari-server/src/main/java/org/apache/ambari/server/checks/UpgradeCheckGroup.java index 16e56f3..d46bed7 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/checks/UpgradeCheckGroup.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/checks/UpgradeCheckGroup.java @@ -54,6 +54,12 @@ public enum UpgradeCheckGroup { CLIENT_RETRY_PROPERTY(5.0f), /** + * Checks for various HA components, such as multiple metastores, are + * available. + */ + MULTIPLE_COMPONENT_WARNING(6.0f), + + /** * All other checks. */ DEFAULT(Float.MAX_VALUE); http://git-wip-us.apache.org/repos/asf/ambari/blob/b8eccc7e/ambari-server/src/main/java/org/apache/ambari/server/checks/YarnRMHighAvailabilityCheck.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/checks/YarnRMHighAvailabilityCheck.java b/ambari-server/src/main/java/org/apache/ambari/server/checks/YarnRMHighAvailabilityCheck.java index db8af29..bf25f9f 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/checks/YarnRMHighAvailabilityCheck.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/checks/YarnRMHighAvailabilityCheck.java @@ -34,7 +34,7 @@ import com.google.inject.Singleton; * for ResourceManager.. */ @Singleton -@UpgradeCheck(group = UpgradeCheckGroup.DEFAULT, order = 1.0f) +@UpgradeCheck(group = UpgradeCheckGroup.MULTIPLE_COMPONENT_WARNING, order = 2.0f) public class YarnRMHighAvailabilityCheck extends AbstractCheckDescriptor { /** http://git-wip-us.apache.org/repos/asf/ambari/blob/b8eccc7e/ambari-server/src/test/java/org/apache/ambari/server/checks/TestHiveMultipleMetastoreCheck.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/checks/TestHiveMultipleMetastoreCheck.java b/ambari-server/src/test/java/org/apache/ambari/server/checks/TestHiveMultipleMetastoreCheck.java new file mode 100644 index 0000000..ab8e5bd --- /dev/null +++ b/ambari-server/src/test/java/org/apache/ambari/server/checks/TestHiveMultipleMetastoreCheck.java @@ -0,0 +1,124 @@ +/** + * 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 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.Service; +import org.apache.ambari.server.state.ServiceComponent; +import org.apache.ambari.server.state.ServiceComponentHost; +import org.apache.ambari.server.state.stack.PrereqCheckStatus; +import org.apache.ambari.server.state.stack.PrerequisiteCheck; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; + +import com.google.inject.Provider; + +/** + * Tests {@link HiveMultipleMetastoreCheck} + */ +public class TestHiveMultipleMetastoreCheck { + private final Clusters m_clusters = Mockito.mock(Clusters.class); + private final HiveMultipleMetastoreCheck m_check = new HiveMultipleMetastoreCheck(); + + /** + * + */ + @Before + public void setup() { + m_check.clustersProvider = new Provider<Clusters>() { + + @Override + public Clusters get() { + return m_clusters; + } + }; + } + + /** + * Tests that the check is applicable when hive is installed. + * + * @throws Exception + */ + @Test + public void testIsApplicable() throws Exception { + final Cluster cluster = Mockito.mock(Cluster.class); + + Mockito.when(cluster.getClusterId()).thenReturn(1L); + Mockito.when(m_clusters.getCluster("cluster")).thenReturn(cluster); + Map<String, Service> services = new HashMap<String, Service>(); + Mockito.when(cluster.getServices()).thenReturn(services); + + services.put("HDFS", Mockito.mock(Service.class)); + + PrereqCheckRequest request = new PrereqCheckRequest("cluster"); + request.setRepositoryVersion("2.3.0.0"); + + // HIVE not installed + Assert.assertFalse(m_check.isApplicable(request)); + + // install HIVE + services.put("HIVE", Mockito.mock(Service.class)); + + // HIVE installed + Assert.assertTrue(m_check.isApplicable(request)); + } + + /** + * Tests that the warning is correctly tripped when there are not enough + * metastores. + * + * @throws Exception + */ + @Test + public void testPerform() throws Exception { + final Cluster cluster = Mockito.mock(Cluster.class); + Service hive = Mockito.mock(Service.class); + ServiceComponent metastore = Mockito.mock(ServiceComponent.class); + + Mockito.when(cluster.getClusterId()).thenReturn(1L); + Mockito.when(m_clusters.getCluster("cluster")).thenReturn(cluster); + Mockito.when(cluster.getService("HIVE")).thenReturn(hive); + + Mockito.when(hive.getServiceComponent("HIVE_METASTORE")).thenReturn(metastore); + + Map<String, ServiceComponentHost> metastores = new HashMap<String, ServiceComponentHost>(); + Mockito.when(metastore.getServiceComponentHosts()).thenReturn(metastores); + + PrerequisiteCheck check = new PrerequisiteCheck(null, null); + PrereqCheckRequest request = new PrereqCheckRequest("cluster"); + request.setRepositoryVersion("2.3.0.0"); + m_check.perform(check, request); + + Assert.assertEquals(PrereqCheckStatus.WARNING, check.getStatus()); + + metastores.put("c6401", Mockito.mock(ServiceComponentHost.class)); + metastores.put("c6402", Mockito.mock(ServiceComponentHost.class)); + + check = new PrerequisiteCheck(null, null); + m_check.perform(check, request); + + Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus()); + } +}
