You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by sw...@apache.org on 2017/09/18 18:58:53 UTC

ambari git commit: Add Druid High Availability Check for Rolling Upgrades. (Nishant Bangarwa via Swapan Shridhar).

Repository: ambari
Updated Branches:
  refs/heads/trunk c2f676c63 -> 4c858d018


Add Druid High Availability Check for Rolling Upgrades. (Nishant Bangarwa via Swapan Shridhar).


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/4c858d01
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/4c858d01
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/4c858d01

Branch: refs/heads/trunk
Commit: 4c858d018765ac78fff9d395271ad470a96936da
Parents: c2f676c
Author: Nishant <ni...@gmail.com>
Authored: Sat Sep 16 03:27:37 2017 +0530
Committer: Swapan Shridhar <ss...@hortonworks.com>
Committed: Mon Sep 18 11:58:14 2017 -0700

----------------------------------------------------------------------
 .../ambari/server/checks/CheckDescription.java  |  12 ++
 .../checks/DruidHighAvailabilityCheck.java      | 121 +++++++++++++
 .../stacks/HDP/2.5/upgrades/upgrade-2.6.xml     |   1 +
 .../stacks/HDP/2.6/upgrades/upgrade-2.6.xml     |   1 +
 .../checks/DruidHighAvailabilityCheckTest.java  | 176 +++++++++++++++++++
 5 files changed, 311 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/4c858d01/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 4fd37dc..c4d0820 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
@@ -341,6 +341,18 @@ public class CheckDescription {
         .put(AbstractCheckDescriptor.DEFAULT, "The following components do not exist in the target repository's stack. They must be removed from the cluster before upgrading.")
           .build());
 
+  public static CheckDescription DRUID_HA_WARNING = new CheckDescription(
+      "DRUID_HA",
+      PrereqCheckType.SERVICE,
+      "Druid Downtime During Upgrade",
+      new ImmutableMap.Builder<String, String>()
+          .put(
+              AbstractCheckDescriptor.DEFAULT,
+              "High Availability is not enabled for Druid. Druid Service may have some downtime during upgrade. Deploy multiple instances of %s in the Cluster to avoid any downtime."
+          )
+          .build()
+  );
+
   private String m_name;
   private PrereqCheckType m_type;
   private String m_description;

http://git-wip-us.apache.org/repos/asf/ambari/blob/4c858d01/ambari-server/src/main/java/org/apache/ambari/server/checks/DruidHighAvailabilityCheck.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/checks/DruidHighAvailabilityCheck.java b/ambari-server/src/main/java/org/apache/ambari/server/checks/DruidHighAvailabilityCheck.java
new file mode 100644
index 0000000..28a3f29
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/checks/DruidHighAvailabilityCheck.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 java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+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.ServiceComponent;
+import org.apache.ambari.server.state.stack.PrereqCheckStatus;
+import org.apache.ambari.server.state.stack.PrerequisiteCheck;
+import org.apache.commons.lang.StringUtils;
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.Sets;
+import com.google.inject.Singleton;
+
+/**
+ * Checks that namenode high availability is enabled.
+ */
+@Singleton
+@UpgradeCheck(group = UpgradeCheckGroup.MULTIPLE_COMPONENT_WARNING, order = 16.0f)
+public class DruidHighAvailabilityCheck extends AbstractCheckDescriptor
+{
+
+  public static final String DRUID_SERVICE_NAME = "DRUID";
+  public static final String[] DRUID_COMPONENT_NAMES = new String[]{
+      "DRUID_BROKER",
+      "DRUID_COORDINATOR",
+      "DRUID_HISTORICAL",
+      "DRUID_OVERLORD",
+      "DRUID_MIDDLEMANAGER",
+      "DRUID_ROUTER"
+  };
+
+  /**
+   * Constructor.
+   */
+  public DruidHighAvailabilityCheck()
+  {
+    super(CheckDescription.DRUID_HA_WARNING);
+  }
+
+  /**
+   * {@inheritDoc}
+   */
+  @Override
+  public Set<String> getApplicableServices()
+  {
+    return Sets.newHashSet(DRUID_SERVICE_NAME);
+  }
+
+  /**
+   * {@inheritDoc}
+   */
+  @Override
+  public List<CheckQualification> getQualifications()
+  {
+    return Arrays.asList(
+        new PriorCheckQualification(CheckDescription.DRUID_HA_WARNING));
+  }
+
+  @Override
+  public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException
+  {
+    List<String> haNotEnabledComponents = Lists.newArrayList();
+    for (String component : DRUID_COMPONENT_NAMES) {
+      Set<String> hosts = getHostsForComponent(request, component);
+      if (hosts.size() == 1) {
+        // This component is installed on only 1 host, HA is not enabled for it.
+        haNotEnabledComponents.add(component);
+      }
+    }
+    if (!haNotEnabledComponents.isEmpty()) {
+      prerequisiteCheck.getFailedOn().add(DRUID_SERVICE_NAME);
+      prerequisiteCheck.setStatus(PrereqCheckStatus.WARNING);
+      String failReason = getFailReason(prerequisiteCheck, request);
+      prerequisiteCheck.setFailReason(String.format(failReason, StringUtils.join(haNotEnabledComponents.toArray(), ", ")));
+    }
+
+  }
+
+  private Set<String> getHostsForComponent(PrereqCheckRequest request, String componentName)
+      throws AmbariException
+  {
+    Set<String> hosts = new HashSet<>();
+    final String clusterName = request.getClusterName();
+    final Cluster cluster = clustersProvider.get().getCluster(clusterName);
+    try {
+      ServiceComponent serviceComponent = cluster.getService(DRUID_SERVICE_NAME).getServiceComponent(componentName);
+      if (serviceComponent != null) {
+        hosts = serviceComponent.getServiceComponentHosts().keySet();
+      }
+    }
+    catch (ServiceComponentNotFoundException err) {
+      // This exception can be ignored if the component doesn't exist because it is a best-attempt at finding it.
+    }
+
+    return hosts;
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/4c858d01/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 4654e6f..0a01a04 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
@@ -34,6 +34,7 @@
     <check>org.apache.ambari.server.checks.YarnRMHighAvailabilityCheck</check>
     <check>org.apache.ambari.server.checks.YarnTimelineServerStatePreservingCheck</check>
     <check>org.apache.ambari.server.checks.RangerSSLConfigCheck</check>
+    <check>org.apache.ambari.server.checks.DruidHighAvailabilityCheck</check>
 
     <configuration>
       <!-- Configuration properties for all pre-reqs including required pre-reqs -->

http://git-wip-us.apache.org/repos/asf/ambari/blob/4c858d01/ambari-server/src/main/resources/stacks/HDP/2.6/upgrades/upgrade-2.6.xml
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.6/upgrades/upgrade-2.6.xml b/ambari-server/src/main/resources/stacks/HDP/2.6/upgrades/upgrade-2.6.xml
index 1aabd90..f7baf81 100644
--- a/ambari-server/src/main/resources/stacks/HDP/2.6/upgrades/upgrade-2.6.xml
+++ b/ambari-server/src/main/resources/stacks/HDP/2.6/upgrades/upgrade-2.6.xml
@@ -33,6 +33,7 @@
     <check>org.apache.ambari.server.checks.ServicesYarnWorkPreservingCheck</check>
     <check>org.apache.ambari.server.checks.YarnRMHighAvailabilityCheck</check>
     <check>org.apache.ambari.server.checks.YarnTimelineServerStatePreservingCheck</check>
+    <check>org.apache.ambari.server.checks.DruidHighAvailabilityCheck</check>
 
     <configuration>
       <!-- Configuration properties for all pre-reqs including required pre-reqs -->

http://git-wip-us.apache.org/repos/asf/ambari/blob/4c858d01/ambari-server/src/test/java/org/apache/ambari/server/checks/DruidHighAvailabilityCheckTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/checks/DruidHighAvailabilityCheckTest.java b/ambari-server/src/test/java/org/apache/ambari/server/checks/DruidHighAvailabilityCheckTest.java
new file mode 100644
index 0000000..dfb18ed
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/checks/DruidHighAvailabilityCheckTest.java
@@ -0,0 +1,176 @@
+/*
+ * 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.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.ambari.server.api.services.AmbariMetaInfo;
+import org.apache.ambari.server.configuration.Configuration;
+import org.apache.ambari.server.controller.PrereqCheckRequest;
+import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
+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.repository.ClusterVersionSummary;
+import org.apache.ambari.server.state.repository.VersionDefinitionXml;
+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.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.inject.Provider;
+
+/**
+ * Unit tests for SecondaryNamenodeDeletedCheck
+ *
+ */
+@RunWith(MockitoJUnitRunner.class)
+public class DruidHighAvailabilityCheckTest
+{
+  private final Clusters clusters = Mockito.mock(Clusters.class);
+
+  private final DruidHighAvailabilityCheck druidHighAvailabilityCheck = new DruidHighAvailabilityCheck();
+
+  @Mock
+  private ClusterVersionSummary m_clusterVersionSummary;
+
+  @Mock
+  private VersionDefinitionXml m_vdfXml;
+
+  @Mock
+  private RepositoryVersionEntity m_repositoryVersion;
+
+  final Map<String, Service> m_services = new HashMap<>();
+
+  @Before
+  public void setup() throws Exception {
+    druidHighAvailabilityCheck.clustersProvider = new Provider<Clusters>() {
+      @Override
+      public Clusters get() {
+        return clusters;
+      }
+    };
+
+    druidHighAvailabilityCheck.ambariMetaInfo = new Provider<AmbariMetaInfo>() {
+      @Override
+      public AmbariMetaInfo get() {
+        return Mockito.mock(AmbariMetaInfo.class);
+      }
+    };
+
+    Configuration config = Mockito.mock(Configuration.class);
+    druidHighAvailabilityCheck.config = config;
+
+    m_services.clear();
+    Mockito.when(m_repositoryVersion.getRepositoryXml()).thenReturn(m_vdfXml);
+    Mockito.when(m_vdfXml.getClusterSummary(Mockito.any(Cluster.class))).thenReturn(m_clusterVersionSummary);
+    Mockito.when(m_clusterVersionSummary.getAvailableServiceNames()).thenReturn(m_services.keySet());
+  }
+
+  @Test
+  public void testIsApplicable() throws Exception {
+    final Cluster cluster = Mockito.mock(Cluster.class);
+    final Service service = Mockito.mock(Service.class);
+
+    m_services.put("DRUID", service);
+
+    Mockito.when(cluster.getClusterId()).thenReturn(1L);
+    Mockito.when(cluster.getServices()).thenReturn(m_services);
+    Mockito.when(clusters.getCluster("cluster")).thenReturn(cluster);
+
+    PrereqCheckRequest request = new PrereqCheckRequest("cluster");
+    request.setTargetRepositoryVersion(m_repositoryVersion);
+
+    Assert.assertTrue(druidHighAvailabilityCheck.isApplicable(request));
+
+    request = new PrereqCheckRequest("cluster");
+    request.setTargetRepositoryVersion(m_repositoryVersion);
+
+    request.addResult(CheckDescription.DRUID_HA_WARNING, PrereqCheckStatus.PASS);
+    Assert.assertTrue(druidHighAvailabilityCheck.isApplicable(request));
+
+    m_services.remove("DRUID");
+    Assert.assertFalse(druidHighAvailabilityCheck.isApplicable(request));
+  }
+
+  @Test
+  public void testPerform() throws Exception {
+    final ServiceComponentHost serviceComponentHost= Mockito.mock(ServiceComponentHost.class);
+    final Cluster cluster = Mockito.mock(Cluster.class);
+    Mockito.when(cluster.getClusterId()).thenReturn(1L);
+    Mockito.when(clusters.getCluster("cluster")).thenReturn(cluster);
+
+    final Service service = Mockito.mock(Service.class);
+    final ServiceComponent serviceComponent = Mockito.mock(ServiceComponent.class);
+    final ServiceComponent haComponent = Mockito.mock(ServiceComponent.class);
+    Mockito.when(serviceComponent.getServiceComponentHosts()).thenReturn(Collections.singletonMap("host", null));
+    Mockito.when(haComponent.getServiceComponentHosts()).thenReturn(ImmutableMap.<String,ServiceComponentHost>of("host1", serviceComponentHost, "host2", serviceComponentHost));
+
+    // All Components Not HA
+    Mockito.when(cluster.getService("DRUID")).thenReturn(service);
+    Mockito.when(service.getServiceComponent("DRUID_COORDINATOR")).thenReturn(serviceComponent);
+    Mockito.when(service.getServiceComponent("DRUID_BROKER")).thenReturn(serviceComponent);
+    Mockito.when(service.getServiceComponent("DRUID_MIDDLEMANAGER")).thenReturn(serviceComponent);
+    Mockito.when(service.getServiceComponent("DRUID_HISTORICAL")).thenReturn(serviceComponent);
+    Mockito.when(service.getServiceComponent("DRUID_OVERLORD")).thenReturn(serviceComponent);
+    Mockito.when(service.getServiceComponent("DRUID_ROUTER")).thenReturn(serviceComponent);
+    PrerequisiteCheck check = new PrerequisiteCheck(null, null);
+    druidHighAvailabilityCheck.perform(check, new PrereqCheckRequest("cluster"));
+    Assert.assertEquals(PrereqCheckStatus.WARNING, check.getStatus());
+    Assert.assertEquals("DRUID", check.getFailedOn().toArray(new String[1])[0]);
+    Assert.assertEquals("High Availability is not enabled for Druid. Druid Service may have some downtime during upgrade. Deploy multiple instances of DRUID_BROKER, DRUID_COORDINATOR, DRUID_HISTORICAL, DRUID_OVERLORD, DRUID_MIDDLEMANAGER, DRUID_ROUTER in the Cluster to avoid any downtime.", check.getFailReason());
+
+    // Some Components have HA
+    Mockito.when(cluster.getService("DRUID")).thenReturn(service);
+    Mockito.when(service.getServiceComponent("DRUID_COORDINATOR")).thenReturn(serviceComponent);
+    Mockito.when(service.getServiceComponent("DRUID_BROKER")).thenReturn(haComponent);
+    Mockito.when(service.getServiceComponent("DRUID_MIDDLEMANAGER")).thenReturn(serviceComponent);
+    Mockito.when(service.getServiceComponent("DRUID_HISTORICAL")).thenReturn(haComponent);
+    Mockito.when(service.getServiceComponent("DRUID_OVERLORD")).thenReturn(serviceComponent);
+    Mockito.when(service.getServiceComponent("DRUID_ROUTER")).thenReturn(haComponent);
+    check = new PrerequisiteCheck(null, null);
+    druidHighAvailabilityCheck.perform(check, new PrereqCheckRequest("cluster"));
+    Assert.assertEquals(PrereqCheckStatus.WARNING, check.getStatus());
+    Assert.assertEquals("DRUID", check.getFailedOn().toArray(new String[1])[0]);
+    Assert.assertEquals("High Availability is not enabled for Druid. Druid Service may have some downtime during upgrade. Deploy multiple instances of DRUID_COORDINATOR, DRUID_OVERLORD, DRUID_MIDDLEMANAGER in the Cluster to avoid any downtime.", check.getFailReason());
+
+    // All components have HA
+    Mockito.when(cluster.getService("DRUID")).thenReturn(service);
+    Mockito.when(service.getServiceComponent("DRUID_COORDINATOR")).thenReturn(haComponent);
+    Mockito.when(service.getServiceComponent("DRUID_BROKER")).thenReturn(haComponent);
+    Mockito.when(service.getServiceComponent("DRUID_MIDDLEMANAGER")).thenReturn(haComponent);
+    Mockito.when(service.getServiceComponent("DRUID_HISTORICAL")).thenReturn(haComponent);
+    Mockito.when(service.getServiceComponent("DRUID_OVERLORD")).thenReturn(haComponent);
+    Mockito.when(service.getServiceComponent("DRUID_ROUTER")).thenReturn(haComponent);
+
+
+    check = new PrerequisiteCheck(null, null);
+    druidHighAvailabilityCheck.perform(check, new PrereqCheckRequest("cluster"));
+    Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus());
+  }
+}