Преглед изворни кода

AMBARI-6039. ZK should not be required to be restarted after adding a host. (Florian Barca via mahadev)

Mahadev Konar пре 11 година
родитељ
комит
35583abd8d

+ 15 - 10
ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java

@@ -396,7 +396,8 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
                 new HashSet<String>());
                 new HashSet<String>());
       }
       }
       if (hostComponentNames.get(request.getClusterName())
       if (hostComponentNames.get(request.getClusterName())
-          .get(request.getServiceName()).get(request.getComponentName())
+          .get(request.getServiceName())
+          .get(request.getComponentName())
           .contains(request.getHostname())) {
           .contains(request.getHostname())) {
         duplicates.add("[clusterName=" + request.getClusterName() + ", hostName=" + request.getHostname() +
         duplicates.add("[clusterName=" + request.getClusterName() + ", hostName=" + request.getHostname() +
             ", componentName=" +request.getComponentName() +']');
             ", componentName=" +request.getComponentName() +']');
@@ -427,8 +428,8 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
       }
       }
       ServiceComponent sc = s.getServiceComponent(
       ServiceComponent sc = s.getServiceComponent(
           request.getComponentName());
           request.getComponentName());
-     
-      setRestartRequiredServices(s);
+
+      setRestartRequiredServices(s, request.getHostname());
 
 
       Host host;
       Host host;
       try {
       try {
@@ -566,21 +567,25 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
   } 
   } 
   
   
   private void setRestartRequiredServices(
   private void setRestartRequiredServices(
-          Service service) throws AmbariException {
+          Service service, String hostName) throws AmbariException {
 
 
     Cluster cluster = service.getCluster();
     Cluster cluster = service.getCluster();
     StackId stackId = cluster.getCurrentStackVersion();
     StackId stackId = cluster.getCurrentStackVersion();
     Set<String> needRestartServices = ambariMetaInfo.getRestartRequiredServicesNames(
     Set<String> needRestartServices = ambariMetaInfo.getRestartRequiredServicesNames(
-            stackId.getStackName(), stackId.getStackVersion());
-    if (needRestartServices.contains(service.getName())) {
+        stackId.getStackName(), stackId.getStackVersion());
+
+    if(needRestartServices.contains(service.getName())) {
       Map<String, ServiceComponent> m = service.getServiceComponents();
       Map<String, ServiceComponent> m = service.getServiceComponents();
       for (Entry<String, ServiceComponent> entry : m.entrySet()) {
       for (Entry<String, ServiceComponent> entry : m.entrySet()) {
         ServiceComponent serviceComponent = entry.getValue();
         ServiceComponent serviceComponent = entry.getValue();
         if (serviceComponent.isMasterComponent()) {
         if (serviceComponent.isMasterComponent()) {
           Map<String, ServiceComponentHost> schMap = serviceComponent.getServiceComponentHosts();
           Map<String, ServiceComponentHost> schMap = serviceComponent.getServiceComponentHosts();
-          for (Entry<String, ServiceComponentHost> sch : schMap.entrySet()) {
-            ServiceComponentHost serviceComponentHost = sch.getValue();
-            serviceComponentHost.setRestartRequired(true);
+          //schMap will only contain hostName when deleting a host; when adding a host the test skips the loop
+          if(schMap.containsKey(hostName)) {
+            for (Entry<String, ServiceComponentHost> sch : schMap.entrySet()) {
+              ServiceComponentHost serviceComponentHost = sch.getValue();
+              serviceComponentHost.setRestartRequired(true);
+            }
           }
           }
         }
         }
       }
       }
@@ -2240,7 +2245,7 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
             "DISABLED/INIT/INSTALLED/INSTALL_FAILED/UNKNOWN state. Current=" + componentHost.getState() + ".");
             "DISABLED/INIT/INSTALLED/INSTALL_FAILED/UNKNOWN state. Current=" + componentHost.getState() + ".");
       }
       }
 
 
-      setRestartRequiredServices(service);
+      setRestartRequiredServices(service, request.getHostname());
               
               
       if (!safeToRemoveSCHs.containsKey(component)) {
       if (!safeToRemoveSCHs.containsKey(component)) {
         safeToRemoveSCHs.put(component, new HashSet<ServiceComponentHost>());
         safeToRemoveSCHs.put(component, new HashSet<ServiceComponentHost>());

+ 28 - 4
ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java

@@ -222,7 +222,7 @@ public class AmbariManagementControllerTest {
   private void addHost(String hostname) throws AmbariException {
   private void addHost(String hostname) throws AmbariException {
     addHost(hostname, null);
     addHost(hostname, null);
   }
   }
-  
+
   private void addHost(String hostname, String clusterName) throws AmbariException {
   private void addHost(String hostname, String clusterName) throws AmbariException {
     clusters.addHost(hostname);
     clusters.addHost(hostname);
     setOsFamily(clusters.getHost(hostname), "redhat", "6.3");
     setOsFamily(clusters.getHost(hostname), "redhat", "6.3");
@@ -232,6 +232,10 @@ public class AmbariManagementControllerTest {
       clusters.mapHostToCluster(hostname, clusterName);
       clusters.mapHostToCluster(hostname, clusterName);
   }
   }
 
 
+  private void deleteHost(String hostname) throws AmbariException {
+    clusters.deleteHost(hostname);
+  }
+
   private void createCluster(String clusterName) throws AmbariException {
   private void createCluster(String clusterName) throws AmbariException {
     ClusterRequest r = new ClusterRequest(null, clusterName, State.INSTALLED.name(), "HDP-0.1", null);
     ClusterRequest r = new ClusterRequest(null, clusterName, State.INSTALLED.name(), "HDP-0.1", null);
     controller.createCluster(r);
     controller.createCluster(r);
@@ -280,6 +284,21 @@ public class AmbariManagementControllerTest {
     controller.createHostComponents(requests);
     controller.createHostComponents(requests);
   }
   }
 
 
+  private void deleteServiceComponentHost(String clusterName,
+                                          String serviceName, String componentName, String hostname,
+                                          State desiredState) throws AmbariException {
+    String dStateStr = null;
+    if (desiredState != null) {
+      dStateStr = desiredState.toString();
+    }
+    ServiceComponentHostRequest r = new ServiceComponentHostRequest(clusterName,
+        serviceName, componentName, hostname, dStateStr);
+    Set<ServiceComponentHostRequest> requests =
+        new HashSet<ServiceComponentHostRequest>();
+    requests.add(r);
+    controller.deleteHostComponents(requests);
+  }
+
   private Long createConfigGroup(Cluster cluster, String name, String tag,
   private Long createConfigGroup(Cluster cluster, String name, String tag,
                               List<String> hosts, List<Config> configs)
                               List<String> hosts, List<Config> configs)
                               throws AmbariException {
                               throws AmbariException {
@@ -9446,7 +9465,7 @@ public class AmbariManagementControllerTest {
   }
   }
 
 
   @Test
   @Test
-  public void setRestartRequieredAfterChangeService() throws Exception {
+  public void setRestartRequiredAfterChangeService() throws Exception {
     String clusterName = "c1";
     String clusterName = "c1";
     createCluster(clusterName);
     createCluster(clusterName);
     Cluster cluster = clusters.getCluster(clusterName);
     Cluster cluster = clusters.getCluster(clusterName);
@@ -9490,8 +9509,13 @@ public class AmbariManagementControllerTest {
     addHost(host2, clusterName);
     addHost(host2, clusterName);
     createServiceComponentHost(clusterName, zookeeperService, zookeeperServer, host2, null);
     createServiceComponentHost(clusterName, zookeeperService, zookeeperServer, host2, null);
 
 
-    assertTrue(zookeeperSch.isRestartRequired());
-  }  
+    assertFalse(zookeeperSch.isRestartRequired());  //No restart required if adding host
+
+    deleteServiceComponentHost(clusterName, zookeeperService, zookeeperServer, host2, null);
+    deleteHost(host2);
+
+    assertTrue(zookeeperSch.isRestartRequired());   //Restart if removing host!
+  }
   
   
   @Test
   @Test
   public void testMaintenanceState() throws Exception {
   public void testMaintenanceState() throws Exception {