Просмотр исходного кода

AMBARI-8140. Ambari allows to delete a host without decommissioning datanode/nodemanager (dlysnichenko)

Lisnichenko Dmitro 10 лет назад
Родитель
Сommit
508af3e5bb

+ 29 - 3
ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java

@@ -22,9 +22,11 @@ import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.AMBARI_DB
 import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.AMBARI_DB_RCA_PASSWORD;
 import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.AMBARI_DB_RCA_PASSWORD;
 import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.AMBARI_DB_RCA_URL;
 import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.AMBARI_DB_RCA_URL;
 import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.AMBARI_DB_RCA_USERNAME;
 import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.AMBARI_DB_RCA_USERNAME;
+import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.CLIENTS_TO_UPDATE_CONFIGS;
 import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.COMMAND_TIMEOUT;
 import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.COMMAND_TIMEOUT;
 import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.DB_DRIVER_FILENAME;
 import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.DB_DRIVER_FILENAME;
 import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.DB_NAME;
 import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.DB_NAME;
+import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.GROUP_LIST;
 import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.HOOKS_FOLDER;
 import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.HOOKS_FOLDER;
 import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.JAVA_HOME;
 import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.JAVA_HOME;
 import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.JCE_NAME;
 import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.JCE_NAME;
@@ -41,14 +43,13 @@ import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.SERVICE_R
 import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.STACK_NAME;
 import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.STACK_NAME;
 import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.STACK_VERSION;
 import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.STACK_VERSION;
 import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.USER_LIST;
 import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.USER_LIST;
-import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.GROUP_LIST;
-import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.CLIENTS_TO_UPDATE_CONFIGS;
 
 
 import java.io.File;
 import java.io.File;
 import java.io.IOException;
 import java.io.IOException;
 import java.net.InetAddress;
 import java.net.InetAddress;
 import java.text.MessageFormat;
 import java.text.MessageFormat;
 import java.util.ArrayList;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Collections;
 import java.util.EnumMap;
 import java.util.EnumMap;
@@ -2403,6 +2404,31 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
     }
     }
   }
   }
 
 
+  private void validateServiceComponentHostRequestDelete(
+      ServiceComponentHostRequest request) {
+    Set<String> componentsDecommissioned = new HashSet<String>(
+        Arrays.asList(new String[] { "DATANODE", "NODEMANAGER" }));
+
+    if (request.getClusterName() == null
+        || request.getClusterName().isEmpty()
+        || request.getComponentName() == null
+        || request.getComponentName().isEmpty()
+        || request.getHostname() == null
+        || request.getHostname().isEmpty()) {
+      throw new IllegalArgumentException("Invalid arguments"
+          + ", cluster name, component name and host name should be"
+          + " provided");
+    }
+
+    if (componentsDecommissioned.contains(request.getComponentName())
+        && request.getAdminState() != null
+        && !request.getAdminState().equals("DECOMMISSIONED")) {
+      throw new IllegalArgumentException(
+          "Invalid arguments, component=" + request.getComponentName()
+              + " must be in DECOMMISSIONED state.");
+    }
+  }
+
   public String findServiceName(Cluster cluster, String componentName) throws AmbariException {
   public String findServiceName(Cluster cluster, String componentName) throws AmbariException {
     StackId stackId = cluster.getDesiredStackVersion();
     StackId stackId = cluster.getDesiredStackVersion();
     String serviceName =
     String serviceName =
@@ -2525,7 +2551,7 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
 
 
     for (ServiceComponentHostRequest request : expanded) {
     for (ServiceComponentHostRequest request : expanded) {
 
 
-      validateServiceComponentHostRequest(request);
+      validateServiceComponentHostRequestDelete(request);
 
 
       Cluster cluster = clusters.getCluster(request.getClusterName());
       Cluster cluster = clusters.getCluster(request.getClusterName());
 
 

+ 11 - 3
ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java

@@ -8412,7 +8412,9 @@ public class AmbariManagementControllerTest {
 
 
     schRequests.clear();
     schRequests.clear();
     schRequests.add(new ServiceComponentHostRequest(clusterName, serviceName, componentName1, host1, null));
     schRequests.add(new ServiceComponentHostRequest(clusterName, serviceName, componentName1, host1, null));
-    schRequests.add(new ServiceComponentHostRequest(clusterName, serviceName, componentName2, host1, null));
+    ServiceComponentHostRequest schr2 = new ServiceComponentHostRequest(clusterName, serviceName, componentName2, host1, null);
+    schr2.setAdminState("DECOMMISSIONED");
+    schRequests.add(schr2);
     schRequests.add(new ServiceComponentHostRequest(clusterName, serviceName, componentName3, host1, null));
     schRequests.add(new ServiceComponentHostRequest(clusterName, serviceName, componentName3, host1, null));
     schRequests.add(new ServiceComponentHostRequest(clusterName, mapred, componentName4, host1, null));
     schRequests.add(new ServiceComponentHostRequest(clusterName, mapred, componentName4, host1, null));
     schRequests.add(new ServiceComponentHostRequest(clusterName, mapred, componentName5, host1, null));
     schRequests.add(new ServiceComponentHostRequest(clusterName, mapred, componentName5, host1, null));
@@ -8490,7 +8492,10 @@ public class AmbariManagementControllerTest {
     // delete HC
     // delete HC
     schRequests.clear();
     schRequests.clear();
     schRequests.add(new ServiceComponentHostRequest(clusterName, serviceName, componentName1, host1, null));
     schRequests.add(new ServiceComponentHostRequest(clusterName, serviceName, componentName1, host1, null));
-    schRequests.add(new ServiceComponentHostRequest(clusterName, serviceName, componentName2, host1, null));
+    // DataNode must be in "DECOMMISSIONED" state.
+    ServiceComponentHostRequest schr = new ServiceComponentHostRequest(clusterName, serviceName, componentName2, host1, null);
+    schr.setAdminState("DECOMMISSIONED");
+    schRequests.add(schr);
     schRequests.add(new ServiceComponentHostRequest(clusterName, serviceName, componentName3, host1, null));
     schRequests.add(new ServiceComponentHostRequest(clusterName, serviceName, componentName3, host1, null));
     controller.deleteHostComponents(schRequests);
     controller.deleteHostComponents(schRequests);
 
 
@@ -9132,7 +9137,10 @@ public class AmbariManagementControllerTest {
 
 
       // confirm delete
       // confirm delete
       componentHostRequests.clear();
       componentHostRequests.clear();
-      componentHostRequests.add(new ServiceComponentHostRequest("c1", null, "DATANODE", "host2", null));
+      // DataNode must be in "DECOMMISSIONED" state.
+      ServiceComponentHostRequest schr = new ServiceComponentHostRequest("c1", null, "DATANODE", "host2", null);
+      schr.setAdminState("DECOMMISSIONED");
+      componentHostRequests.add(schr);
       amc.deleteHostComponents(componentHostRequests);
       amc.deleteHostComponents(componentHostRequests);
 
 
       sch = null;
       sch = null;