Repository: ambari Updated Branches: refs/heads/trunk 915c152b1 -> 31459c7d5
AMBARI-5120. Service Start: Clients are installed on hosts in maintenance mode. (swagle) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/31459c7d Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/31459c7d Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/31459c7d Branch: refs/heads/trunk Commit: 31459c7d54660d310396c8a7630da18543c87d9b Parents: 915c152 Author: Siddharth Wagle <[email protected]> Authored: Mon Mar 17 17:58:18 2014 -0700 Committer: Siddharth Wagle <[email protected]> Committed: Mon Mar 17 18:58:22 2014 -0700 ---------------------------------------------------------------------- .../AmbariManagementControllerImpl.java | 29 +++++------ .../AmbariManagementControllerTest.java | 52 +++++++++++++++++++- 2 files changed, 66 insertions(+), 15 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/31459c7d/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java index ae6621b..9068282 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java @@ -1059,6 +1059,7 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle Set<String> services = new HashSet<String>(); + // This is done to account for services with client only components. if (changedServices != null) { for (Entry<State, List<Service>> entry : changedServices.entrySet()) { if (State.STARTED != entry.getKey()) { @@ -1073,14 +1074,14 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle } // Flatten changed Schs that are going to be Started - List<ServiceComponentHost> serviceComponentHosts = new - ArrayList<ServiceComponentHost>(); + List<ServiceComponentHost> serviceComponentHosts = new ArrayList<ServiceComponentHost>(); if (changedScHosts != null && !changedScHosts.isEmpty()) { for (String sc : changedScHosts.keySet()) { - for (State state : changedScHosts.get(sc).keySet()) + for (State state : changedScHosts.get(sc).keySet()) { if (state == State.STARTED) { serviceComponentHosts.addAll(changedScHosts.get(sc).get(state)); } + } } } @@ -1090,23 +1091,24 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle } } - if (services.isEmpty()) + if (services.isEmpty()) { return; + } - Map<String, List<ServiceComponentHost>> clientSchs = new - HashMap<String, List<ServiceComponentHost>>(); + Map<String, List<ServiceComponentHost>> clientSchs = new HashMap<String, List<ServiceComponentHost>>(); for (String serviceName : services) { Service s = cluster.getService(serviceName); for (String component : s.getServiceComponents().keySet()) { - List<ServiceComponentHost> potentialHosts = new - ArrayList<ServiceComponentHost>(); + List<ServiceComponentHost> potentialHosts = new ArrayList<ServiceComponentHost>(); ServiceComponent sc = s.getServiceComponents().get(component); if (sc.isClientComponent()) { - for (ServiceComponentHost potentialSch : sc - .getServiceComponentHosts().values()) { - if (!potentialSch.getHostState().equals(HostState - .HEARTBEAT_LOST)) { + for (ServiceComponentHost potentialSch : sc.getServiceComponentHosts().values()) { + Host host = clusters.getHost(potentialSch.getHostName()); + // Host is alive and neither host nor SCH is in Maintenance State + if (!potentialSch.getHostState().equals(HostState.HEARTBEAT_LOST) + && potentialSch.getMaintenanceState() != MaintenanceState.ON + && host.getMaintenanceState(cluster.getClusterId()) == MaintenanceState.OFF) { potentialHosts.add(potentialSch); } } @@ -1120,8 +1122,7 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle if (changedScHosts != null) { for (String sc : clientSchs.keySet()) { - Map<State, List<ServiceComponentHost>> schMap = new - HashMap<State, List<ServiceComponentHost>>(); + Map<State, List<ServiceComponentHost>> schMap = new HashMap<State, List<ServiceComponentHost>>(); schMap.put(State.INSTALLED, clientSchs.get(sc)); changedScHosts.put(sc, schMap); } http://git-wip-us.apache.org/repos/asf/ambari/blob/31459c7d/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java index 7c58a69..b3e7c8d 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java @@ -259,7 +259,6 @@ public class AmbariManagementControllerTest { controller.createHostComponents(requests); } - @Transactional private Long createConfigGroup(Cluster cluster, String name, String tag, List<String> hosts, List<Config> configs) throws AmbariException { @@ -9568,6 +9567,57 @@ public class AmbariManagementControllerTest { } @Test + public void testReinstallClientSchSkippedInMaintenance() throws Exception { + Cluster c1 = setupClusterWithHosts("c1", "HDP-1.2.0", + new ArrayList<String>() {{ + add("h1"); + add("h2"); + add("h3"); + }}, + "centos5"); + + Service hdfs = c1.addService("HDFS"); + hdfs.persist(); + createServiceComponent("c1", "HDFS", "NAMENODE", State.INIT); + createServiceComponent("c1", "HDFS", "DATANODE", State.INIT); + createServiceComponent("c1", "HDFS", "HDFS_CLIENT", State.INIT); + + createServiceComponentHost("c1", "HDFS", "NAMENODE", "h1", State.INIT); + createServiceComponentHost("c1", "HDFS", "DATANODE", "h1", State.INIT); + createServiceComponentHost("c1", "HDFS", "HDFS_CLIENT", "h1", State.INIT); + createServiceComponentHost("c1", "HDFS", "HDFS_CLIENT", "h2", State.INIT); + createServiceComponentHost("c1", "HDFS", "HDFS_CLIENT", "h3", State.INIT); + + installService("c1", "HDFS", false, false); + + clusters.getHost("h3").setMaintenanceState(c1.getClusterId(), MaintenanceState.ON); + + Long id = startService("c1", "HDFS", false ,true); + + Assert.assertNotNull(id); + List<Stage> stages = actionDB.getAllStages(id); + Assert.assertNotNull(stages); + HostRoleCommand hrc1 = null; + HostRoleCommand hrc2 = null; + HostRoleCommand hrc3 = null; + for (Stage s : stages) { + for (HostRoleCommand hrc : s.getOrderedHostRoleCommands()) { + if (hrc.getRole().equals(Role.HDFS_CLIENT) && hrc.getHostName().equals("h1")) { + hrc1 = hrc; + } else if (hrc.getRole().equals(Role.HDFS_CLIENT) && hrc.getHostName().equals("h2")) { + hrc2 = hrc; + } else if (hrc.getRole().equals(Role.HDFS_CLIENT) && hrc.getHostName().equals("h3")) { + hrc3 = hrc; + } + } + } + + Assert.assertNotNull(hrc1); + Assert.assertNotNull(hrc2); + Assert.assertNull(hrc3); + } + + @Test public void testMaintenanceState() throws Exception { String clusterName = "c1"; createCluster(clusterName);
