ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jonathanhur...@apache.org
Subject ambari git commit: AMBARI-13801 - Upgrade Pre-Req Check Is Confusing When Hosts Are In Maintenance Mode (jonathanhurley)
Date Mon, 09 Nov 2015 22:16:11 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk de5093a5c -> c715189ab


AMBARI-13801 - Upgrade Pre-Req Check Is Confusing When Hosts Are In Maintenance Mode (jonathanhurley)


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

Branch: refs/heads/trunk
Commit: c715189ab50311f5fc2ed0b089e426173b59fd25
Parents: de5093a
Author: Jonathan Hurley <jhurley@hortonworks.com>
Authored: Mon Nov 9 14:24:28 2015 -0500
Committer: Jonathan Hurley <jhurley@hortonworks.com>
Committed: Mon Nov 9 16:55:38 2015 -0500

----------------------------------------------------------------------
 .../ambari/server/checks/CheckDescription.java  | 14 +++-
 .../server/checks/HostMaintenanceModeCheck.java | 76 +++++++++++++++++
 .../server/checks/HostsHeartbeatCheck.java      | 28 ++-----
 .../server/state/stack/PrerequisiteCheck.java   |  5 +-
 .../checks/HostMaintenanceModeCheckTest.java    | 87 ++++++++++++++++++++
 .../server/checks/HostsHeartbeatCheckTest.java  | 23 +++---
 6 files changed, 195 insertions(+), 38 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/c715189a/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 603b279..1908c06 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
@@ -26,6 +26,7 @@ import org.apache.ambari.server.state.stack.PrereqCheckType;
  * Enum that wraps the various type, text and failure messages for the checks
  * done for Rolling Upgrades.
  */
+@SuppressWarnings("serial")
 public enum CheckDescription {
 
   CLIENT_RETRY(PrereqCheckType.SERVICE,
@@ -38,12 +39,17 @@ public enum CheckDescription {
       }}),
 
   HOSTS_HEARTBEAT(PrereqCheckType.HOST,
-      "All hosts must be heartbeating with the Ambari Server unless they are in Maintenance
Mode",
+      "All hosts must be communicating with Ambari. Hosts which are not reachable should
be placed in Maintenance Mode.",
       new HashMap<String, String>() {{
         put(AbstractCheckDescriptor.DEFAULT,
-            "The following hosts must be heartbeating to the Ambari Server or be put into
maintenance mode.");
-        put(HostsHeartbeatCheck.KEY_HOSTS_IN_MM_WARNING,
-            "The following hosts are in maintenance mode and will not be a part of the upgrade.");
+            "There are hosts which are not communicating with Ambari.");
+      }}),
+
+  HOSTS_MAINTENANCE_MODE(PrereqCheckType.HOST,
+      "Hosts in Maintenance Mode will be excluded from the upgrade.",
+      new HashMap<String, String>() {{
+        put(AbstractCheckDescriptor.DEFAULT,
+            "There are hosts in Maintenance Mode which excludes them from being upgraded.");
       }}),
 
   HOSTS_MASTER_MAINTENANCE(PrereqCheckType.HOST,

http://git-wip-us.apache.org/repos/asf/ambari/blob/c715189a/ambari-server/src/main/java/org/apache/ambari/server/checks/HostMaintenanceModeCheck.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/checks/HostMaintenanceModeCheck.java
b/ambari-server/src/main/java/org/apache/ambari/server/checks/HostMaintenanceModeCheck.java
new file mode 100644
index 0000000..8708ef4
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/checks/HostMaintenanceModeCheck.java
@@ -0,0 +1,76 @@
+/*
+ * 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.Collection;
+
+import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.controller.PrereqCheckRequest;
+import org.apache.ambari.server.state.Cluster;
+import org.apache.ambari.server.state.Host;
+import org.apache.ambari.server.state.MaintenanceState;
+import org.apache.ambari.server.state.stack.PrereqCheckStatus;
+import org.apache.ambari.server.state.stack.PrerequisiteCheck;
+
+import com.google.inject.Singleton;
+
+/**
+ * The {@link HostMaintenanceModeCheck} is used to provide a warning if any
+ * hosts are in maintenance mode. Hosts in MM will be exluded from the upgrade.
+ * <p/>
+ * This check will return {@link PrereqCheckStatus#WARNING} for any hosts in
+ * maintenance mode.
+ *
+ * @see HostsHeartbeatCheck
+ */
+@Singleton
+@UpgradeCheck(group = UpgradeCheckGroup.MAINTENANCE_MODE, order = 3.0f, required = true)
+public class HostMaintenanceModeCheck extends AbstractCheckDescriptor {
+
+  /**
+   * Constructor.
+   */
+  public HostMaintenanceModeCheck() {
+    super(CheckDescription.HOSTS_MAINTENANCE_MODE);
+  }
+
+  /**
+   * {@inheritDoc}
+   */
+  @Override
+  public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request)
+      throws AmbariException {
+    final String clusterName = request.getClusterName();
+    final Cluster cluster = clustersProvider.get().getCluster(clusterName);
+    Collection<Host> hosts = cluster.getHosts();
+
+    // see if any hosts in the cluster are in MM
+    for (Host host : hosts) {
+      MaintenanceState maintenanceState = host.getMaintenanceState(cluster.getClusterId());
+      if (maintenanceState != MaintenanceState.OFF) {
+        prerequisiteCheck.getFailedOn().add(host.getHostName());
+      }
+    }
+
+    // for any host in MM, produce a warning
+    if (!prerequisiteCheck.getFailedOn().isEmpty()) {
+      prerequisiteCheck.setStatus(PrereqCheckStatus.WARNING);
+      prerequisiteCheck.setFailReason(getFailReason(prerequisiteCheck, request));
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/c715189a/ambari-server/src/main/java/org/apache/ambari/server/checks/HostsHeartbeatCheck.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/checks/HostsHeartbeatCheck.java
b/ambari-server/src/main/java/org/apache/ambari/server/checks/HostsHeartbeatCheck.java
index a6811cb..1f1980f 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/checks/HostsHeartbeatCheck.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/checks/HostsHeartbeatCheck.java
@@ -35,19 +35,15 @@ import com.google.inject.Singleton;
  * host which is not heartbeating, then it must be in maintenance mode to
  * prevent a failure of this check.
  * <p/>
- * Hosts that are in maintenance mode will be added to a warning that they will
- * not be included in the upgrade.
- * <p/>
  * This check will return {@link PrereqCheckStatus#FAIL} if there are hosts not
- * heartbeating and not in maintenance mode. Otherwise, it will return
- * {@link PrereqCheckStatus#WARNING} for any hosts in maintenance mode.
+ * heartbeating and not in maintenance mode.
+ *
+ * @see HostMaintenanceModeCheck
  */
 @Singleton
 @UpgradeCheck(group = UpgradeCheckGroup.LIVELINESS, order = 1.0f, required = true)
 public class HostsHeartbeatCheck extends AbstractCheckDescriptor {
 
-  static final String KEY_HOSTS_IN_MM_WARNING = "key.hosts.in.mm.warning";
-
   /**
    * Constructor.
    */
@@ -55,6 +51,9 @@ public class HostsHeartbeatCheck extends AbstractCheckDescriptor {
     super(CheckDescription.HOSTS_HEARTBEAT);
   }
 
+  /**
+   * {@inheritDoc}
+   */
   @Override
   public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request)
       throws AmbariException {
@@ -84,20 +83,5 @@ public class HostsHeartbeatCheck extends AbstractCheckDescriptor {
       prerequisiteCheck.setFailReason(getFailReason(prerequisiteCheck, request));
       return;
     }
-
-    // no failues so far, check to see if any hosts are in MM so that this check
-    // will produce a warning
-    for (Host host : hosts) {
-      MaintenanceState maintenanceState = host.getMaintenanceState(cluster.getClusterId());
-      if (maintenanceState != MaintenanceState.OFF) {
-        prerequisiteCheck.getFailedOn().add(host.getHostName());
-      }
-    }
-
-    if (!prerequisiteCheck.getFailedOn().isEmpty()) {
-      prerequisiteCheck.setStatus(PrereqCheckStatus.WARNING);
-      prerequisiteCheck.setFailReason(
-          getFailReason(KEY_HOSTS_IN_MM_WARNING, prerequisiteCheck, request));
-    }
   }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/c715189a/ambari-server/src/main/java/org/apache/ambari/server/state/stack/PrerequisiteCheck.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/stack/PrerequisiteCheck.java
b/ambari-server/src/main/java/org/apache/ambari/server/state/stack/PrerequisiteCheck.java
index f862d09..5822abd 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/stack/PrerequisiteCheck.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/stack/PrerequisiteCheck.java
@@ -24,8 +24,9 @@ import java.util.List;
 import org.apache.ambari.server.checks.CheckDescription;
 
 /**
- * Contains information about performed prerequisite check.
- *
+ * Contains information about performed prerequisite check. Newly initialized
+ * {@link PrerequisiteCheck} instances are always set to
+ * {@link PrereqCheckStatus#PASS}.
  */
 public class PrerequisiteCheck {
   private final CheckDescription m_description;

http://git-wip-us.apache.org/repos/asf/ambari/blob/c715189a/ambari-server/src/test/java/org/apache/ambari/server/checks/HostMaintenanceModeCheckTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/checks/HostMaintenanceModeCheckTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/checks/HostMaintenanceModeCheckTest.java
new file mode 100644
index 0000000..0e14376
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/checks/HostMaintenanceModeCheckTest.java
@@ -0,0 +1,87 @@
+/*
+ * 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.ArrayList;
+import java.util.List;
+
+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.Host;
+import org.apache.ambari.server.state.MaintenanceState;
+import org.apache.ambari.server.state.StackId;
+import org.apache.ambari.server.state.stack.PrereqCheckStatus;
+import org.apache.ambari.server.state.stack.PrerequisiteCheck;
+import org.junit.Assert;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+import com.google.inject.Provider;
+
+/**
+ * Tests {@link HostMaintenanceModeCheck}.
+ */
+public class HostMaintenanceModeCheckTest {
+  private final Clusters clusters = Mockito.mock(Clusters.class);
+
+  /**
+   * @throws Exception
+   */
+  @Test
+  public void testPerform() throws Exception {
+    final HostMaintenanceModeCheck hostMaintenanceModeCheck = new HostMaintenanceModeCheck();
+    hostMaintenanceModeCheck.clustersProvider = new Provider<Clusters>() {
+
+      @Override
+      public Clusters get() {
+        return clusters;
+      }
+    };
+
+    final Cluster cluster = Mockito.mock(Cluster.class);
+    Mockito.when(cluster.getClusterId()).thenReturn(1L);
+    Mockito.when(cluster.getCurrentStackVersion()).thenReturn(new StackId("HDP", "2.2"));
+    Mockito.when(clusters.getCluster("cluster")).thenReturn(cluster);
+
+    final List<Host> hosts = new ArrayList<>();
+    final Host host1 = Mockito.mock(Host.class);
+    final Host host2 = Mockito.mock(Host.class);
+    final Host host3 = Mockito.mock(Host.class);
+
+    Mockito.when(host1.getMaintenanceState(1L)).thenReturn(MaintenanceState.OFF);
+    Mockito.when(host2.getMaintenanceState(1L)).thenReturn(MaintenanceState.OFF);
+    Mockito.when(host3.getMaintenanceState(1L)).thenReturn(MaintenanceState.OFF);
+
+    hosts.add(host1);
+    hosts.add(host2);
+    hosts.add(host3);
+
+    Mockito.when(cluster.getHosts()).thenReturn(hosts);
+
+    PrerequisiteCheck check = new PrerequisiteCheck(null, null);
+    hostMaintenanceModeCheck.perform(check, new PrereqCheckRequest("cluster"));
+    Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus());
+
+    // put a host into MM in order to trigger the warning
+    check = new PrerequisiteCheck(null, null);
+    Mockito.when(host3.getMaintenanceState(1L)).thenReturn(MaintenanceState.ON);
+    hostMaintenanceModeCheck.perform(check, new PrereqCheckRequest("cluster"));
+    Assert.assertEquals(PrereqCheckStatus.WARNING, check.getStatus());
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/c715189a/ambari-server/src/test/java/org/apache/ambari/server/checks/HostsHeartbeatCheckTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/checks/HostsHeartbeatCheckTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/checks/HostsHeartbeatCheckTest.java
index 847027c..4ad2819 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/checks/HostsHeartbeatCheckTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/checks/HostsHeartbeatCheckTest.java
@@ -59,6 +59,9 @@ public class HostsHeartbeatCheckTest {
     Assert.assertTrue(hhc.isApplicable(checkRequest));
   }
 
+  /**
+   * @throws Exception
+   */
   @Test
   public void testPerform() throws Exception {
     final HostsHeartbeatCheck hostHeartbeatCheck = new HostsHeartbeatCheck();
@@ -74,49 +77,49 @@ public class HostsHeartbeatCheckTest {
     Mockito.when(cluster.getClusterId()).thenReturn(1L);
     Mockito.when(cluster.getCurrentStackVersion()).thenReturn(new StackId("HDP", "2.2"));
     Mockito.when(clusters.getCluster("cluster")).thenReturn(cluster);
+
     final List<Host> hosts = new ArrayList<>();
     final Host host1 = Mockito.mock(Host.class);
     final Host host2 = Mockito.mock(Host.class);
     final Host host3 = Mockito.mock(Host.class);
+
     final HostHealthStatus status1 = Mockito.mock(HostHealthStatus.class);
     final HostHealthStatus status2 = Mockito.mock(HostHealthStatus.class);
     final HostHealthStatus status3 = Mockito.mock(HostHealthStatus.class);
+
     Mockito.when(host1.getMaintenanceState(1L)).thenReturn(MaintenanceState.OFF);
     Mockito.when(host2.getMaintenanceState(1L)).thenReturn(MaintenanceState.OFF);
     Mockito.when(host3.getMaintenanceState(1L)).thenReturn(MaintenanceState.OFF);
+
     Mockito.when(host1.getHealthStatus()).thenReturn(status1);
     Mockito.when(host2.getHealthStatus()).thenReturn(status2);
     Mockito.when(host3.getHealthStatus()).thenReturn(status3);
+
     Mockito.when(status1.getHealthStatus()).thenReturn(HealthStatus.HEALTHY);
     Mockito.when(status2.getHealthStatus()).thenReturn(HealthStatus.HEALTHY);
     Mockito.when(status3.getHealthStatus()).thenReturn(HealthStatus.UNKNOWN);
+
     hosts.add(host1);
     hosts.add(host2);
     hosts.add(host3);
+
     Mockito.when(cluster.getHosts()).thenReturn(hosts);
 
     PrerequisiteCheck check = new PrerequisiteCheck(null, null);
     hostHeartbeatCheck.perform(check, new PrereqCheckRequest("cluster"));
     Assert.assertEquals(PrereqCheckStatus.FAIL, check.getStatus());
 
-    // put the unhealthy host into MM to now produce a warning
+    // put the unhealthy host into MM which will allow this check to pass
     check = new PrerequisiteCheck(null, null);
     Mockito.when(host3.getMaintenanceState(1L)).thenReturn(MaintenanceState.ON);
     hostHeartbeatCheck.perform(check, new PrereqCheckRequest("cluster"));
-    Assert.assertEquals(PrereqCheckStatus.WARNING, check.getStatus());
+    Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus());
 
-    // make it's status healthy, but keep in MM to still produce a warning
-    check = new PrerequisiteCheck(null, null);
+    // make the host healthy and take it out of MM to produce a PASS result
     Mockito.when(status3.getHealthStatus()).thenReturn(HealthStatus.HEALTHY);
-    hostHeartbeatCheck.perform(check, new PrereqCheckRequest("cluster"));
-    Assert.assertEquals(PrereqCheckStatus.WARNING, check.getStatus());
-
-    // take it out our MM to allow the check to pass
     check = new PrerequisiteCheck(null, null);
     Mockito.when(host3.getMaintenanceState(1L)).thenReturn(MaintenanceState.OFF);
     hostHeartbeatCheck.perform(check, new PrereqCheckRequest("cluster"));
     Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus());
-
   }
-
 }


Mime
View raw message