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 2013/06/04 00:45:30 UTC

svn commit: r1489217 - in /incubator/ambari/trunk: ./ ambari-server/src/main/java/org/apache/ambari/server/controller/ ambari-server/src/test/java/org/apache/ambari/server/controller/

Author: swagle
Date: Mon Jun  3 22:45:30 2013
New Revision: 1489217

URL: http://svn.apache.org/r1489217
Log:
AMBARI-2266. Clients are not reconfigured on starting a service after each of the service components are stopped individually. (swagle)

Modified:
    incubator/ambari/trunk/CHANGES.txt
    incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
    incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java

Modified: incubator/ambari/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/CHANGES.txt?rev=1489217&r1=1489216&r2=1489217&view=diff
==============================================================================
--- incubator/ambari/trunk/CHANGES.txt (original)
+++ incubator/ambari/trunk/CHANGES.txt Mon Jun  3 22:45:30 2013
@@ -910,6 +910,9 @@ Trunk (unreleased changes):
 
  BUG FIXES
  
+ AMBARI-2266. Clients are not reconfigured on starting a service after each 
+ of the service components are stopped individually. (swagle)
+
  AMBARI-2230. Nagios user is presented in Admin > Misc page when Nagios
  service was not installed. (yusaku)
 

Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java?rev=1489217&r1=1489216&r2=1489217&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java (original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java Mon Jun  3 22:45:30 2013
@@ -1845,39 +1845,31 @@ public class AmbariManagementControllerI
   }
 
   private void addClientSchForReinstall(Cluster cluster,
-            Map<State, List<Service>> changedServices,
             Map<String, Map<State, List<ServiceComponentHost>>> changedScHosts)
             throws AmbariException {
 
     Set<String> services = new HashSet<String>();
-
-    if (changedServices != null) {
-      for (Entry<State, List<Service>> entry : changedServices.entrySet()) {
-        if (State.STARTED != entry.getKey()) {
-          continue;
-        }
-        for (Service s : entry.getValue()) {
-          if (State.INSTALLED == s.getDesiredState()) {
-            services.add(s.getName());
-          }
-        }
-      }
-    }
-
-    if (services == null || services.isEmpty())
-      return;
-
     // Flatten changed Schs that are going to be Started
-    List<ServiceComponentHost> existingSchs = new
+    List<ServiceComponentHost> serviceComponentHosts = new
       ArrayList<ServiceComponentHost>();
     if (changedScHosts != null && !changedScHosts.isEmpty()) {
       for (String sc : changedScHosts.keySet()) {
         for (State s : changedScHosts.get(sc).keySet())
-          if (s == State.STARTED)
-            existingSchs.addAll(changedScHosts.get(sc).get(s));
+          if (s == State.STARTED) {
+            serviceComponentHosts.addAll(changedScHosts.get(sc).get(s));
+          }
+      }
+    }
+
+    if (!serviceComponentHosts.isEmpty()) {
+      for (ServiceComponentHost sch : serviceComponentHosts) {
+        services.add(sch.getServiceName());
       }
     }
 
+    if (services == null || services.isEmpty())
+      return;
+
     Map<String, List<ServiceComponentHost>> clientSchs = new
       HashMap<String, List<ServiceComponentHost>>();
 
@@ -2005,7 +1997,7 @@ public class AmbariManagementControllerI
     if (reconfigureClients) {
       // Re-install client only hosts to reattach changed configs on service
       // restart
-      addClientSchForReinstall(cluster, changedServices, changedScHosts);
+      addClientSchForReinstall(cluster, changedScHosts);
     }
 
     if (!changedScHosts.isEmpty()

Modified: incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java?rev=1489217&r1=1489216&r2=1489217&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java (original)
+++ incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java Mon Jun  3 22:45:30 2013
@@ -211,6 +211,36 @@ public class AmbariManagementControllerT
     return resp.getRequestId();
   }
 
+  private long stopServiceComponentHosts(String clusterName,
+      String serviceName) throws AmbariException {
+    Cluster c = clusters.getCluster(clusterName);
+    Service s = c.getService(serviceName);
+    Set<ServiceComponentHostRequest> requests = new
+      HashSet<ServiceComponentHostRequest>();
+    for (ServiceComponent sc : s.getServiceComponents().values()) {
+      for (ServiceComponentHost sch : sc.getServiceComponentHosts().values()) {
+        ServiceComponentHostRequest schr = new ServiceComponentHostRequest
+          (clusterName, serviceName, sc.getName(),
+            sch.getHostName(), null, State.INSTALLED.name());
+        requests.add(schr);
+      }
+    }
+    Map<String, String> mapRequestProps = new HashMap<String, String>();
+    mapRequestProps.put("context", "Called from a test");
+    RequestStatusResponse resp = controller.updateHostComponents(requests,
+      mapRequestProps, false);
+
+    // manually change live state to started as no running action manager
+    for (ServiceComponent sc :
+      clusters.getCluster(clusterName).getService(serviceName)
+        .getServiceComponents().values()) {
+      for (ServiceComponentHost sch : sc.getServiceComponentHosts().values()) {
+        sch.setState(State.INSTALLED);
+      }
+    }
+    return resp.getRequestId();
+  }
+
   private long startService(String clusterName, String serviceName,
       boolean runSmokeTests, boolean reconfigureClients) throws
     AmbariException {
@@ -4548,6 +4578,107 @@ public class AmbariManagementControllerT
   }
 
   @Test
+  public void testReconfigureClientWithServiceStarted() throws
+    AmbariException {
+    String clusterName = "foo1";
+    createCluster(clusterName);
+    clusters.getCluster(clusterName)
+      .setDesiredStackVersion(new StackId("HDP-0.1"));
+    String serviceName = "HDFS";
+    createService(clusterName, serviceName, null);
+    String componentName1 = "NAMENODE";
+    String componentName2 = "DATANODE";
+    String componentName3 = "HDFS_CLIENT";
+
+    Map<String, String> mapRequestProps = new HashMap<String, String>();
+    mapRequestProps.put("context", "Called from a test");
+
+    createServiceComponent(clusterName, serviceName, componentName1,
+      State.INIT);
+    createServiceComponent(clusterName, serviceName, componentName2,
+      State.INIT);
+    createServiceComponent(clusterName, serviceName, componentName3,
+      State.INIT);
+
+    String host1 = "h1";
+    clusters.addHost(host1);
+    clusters.getHost("h1").setOsType("centos5");
+    clusters.getHost("h1").persist();
+    String host2 = "h2";
+    clusters.addHost(host2);
+    clusters.getHost("h2").setOsType("centos6");
+    clusters.getHost("h2").persist();
+
+    clusters.mapHostToCluster(host1, clusterName);
+    clusters.mapHostToCluster(host2, clusterName);
+
+    createServiceComponentHost(clusterName, serviceName, componentName1,
+      host1, null);
+    createServiceComponentHost(clusterName, serviceName, componentName2,
+      host1, null);
+    createServiceComponentHost(clusterName, serviceName, componentName3,
+      host1, null);
+    createServiceComponentHost(clusterName, serviceName, componentName3,
+      host2, null);
+
+    // Create and attach config
+    Map<String, String> configs = new HashMap<String, String>();
+    configs.put("a", "b");
+
+    ConfigurationRequest cr1,cr2,cr3;
+    cr1 = new ConfigurationRequest(clusterName, "core-site","version1",
+      configs);
+    cr2 = new ConfigurationRequest(clusterName, "hdfs-site","version1",
+      configs);
+
+    ClusterRequest crReq = new ClusterRequest(null, clusterName, null, null);
+    crReq.setDesiredConfig(cr1);
+    controller.updateCluster(crReq, null);
+    crReq = new ClusterRequest(null, clusterName, null, null);
+    crReq.setDesiredConfig(cr2);
+    controller.updateCluster(crReq, null);
+
+    installService(clusterName, serviceName, false, false);
+    startService(clusterName, serviceName, false, false);
+
+    Cluster c = clusters.getCluster(clusterName);
+    Service s = c.getService(serviceName);
+    // Stop Sch only
+    long id = stopServiceComponentHosts(clusterName, serviceName);
+    Assert.assertEquals(State.STARTED, s.getDesiredState());
+    for (ServiceComponent sc : s.getServiceComponents().values()) {
+      for (ServiceComponentHost sch : sc.getServiceComponentHosts().values()) {
+        Assert.assertEquals(State.INSTALLED, sch.getDesiredState());
+      }
+    }
+
+    // Reconfigure
+    configs.clear();
+    configs.put("c", "d");
+    cr3 = new ConfigurationRequest(clusterName, "core-site","version122",
+      configs);
+    crReq = new ClusterRequest(null, clusterName, null, null);
+    crReq.setDesiredConfig(cr3);
+    controller.updateCluster(crReq, null);
+
+    id = startService(clusterName, serviceName, false, true);
+    List<Stage> stages = actionDB.getAllStages(id);
+    HostRoleCommand clientHrc = null;
+    for (Stage stage : stages) {
+      for (HostRoleCommand hrc : stage.getOrderedHostRoleCommands()) {
+        if (hrc.getHostName().equals(host2) && hrc.getRole().toString()
+          .equals("HDFS_CLIENT")) {
+          clientHrc = hrc;
+          Assert.assertEquals("version122", hrc.getExecutionCommandWrapper()
+            .getExecutionCommand().getConfigurationTags().get("core-site")
+            .get("tag"));
+        }
+      }
+    }
+    Assert.assertNotNull(clientHrc);
+  }
+
+  @Test
   public void testClientServiceSmokeTests() throws AmbariException {
     String clusterName = "foo1";
     createCluster(clusterName);