You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by dm...@apache.org on 2014/11/05 11:52:08 UTC

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

Repository: ambari
Updated Branches:
  refs/heads/trunk 6872cbad4 -> 508af3e5b


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


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

Branch: refs/heads/trunk
Commit: 508af3e5bb56598e618b5c16c6c3d25682ef0097
Parents: 6872cba
Author: Lisnichenko Dmitro <dl...@hortonworks.com>
Authored: Wed Nov 5 12:51:27 2014 +0200
Committer: Lisnichenko Dmitro <dl...@hortonworks.com>
Committed: Wed Nov 5 12:51:27 2014 +0200

----------------------------------------------------------------------
 .../AmbariManagementControllerImpl.java         | 32 ++++++++++++++++++--
 .../AmbariManagementControllerTest.java         | 14 +++++++--
 2 files changed, 40 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/508af3e5/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 a409078..4f69dbb 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
@@ -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_URL;
 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.DB_DRIVER_FILENAME;
 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.JAVA_HOME;
 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_VERSION;
 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.IOException;
 import java.net.InetAddress;
 import java.text.MessageFormat;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 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 {
     StackId stackId = cluster.getDesiredStackVersion();
     String serviceName =
@@ -2525,7 +2551,7 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
 
     for (ServiceComponentHostRequest request : expanded) {
 
-      validateServiceComponentHostRequest(request);
+      validateServiceComponentHostRequestDelete(request);
 
       Cluster cluster = clusters.getCluster(request.getClusterName());
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/508af3e5/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 073ffea..b2c023f 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
@@ -8412,7 +8412,9 @@ public class AmbariManagementControllerTest {
 
     schRequests.clear();
     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, mapred, componentName4, host1, null));
     schRequests.add(new ServiceComponentHostRequest(clusterName, mapred, componentName5, host1, null));
@@ -8490,7 +8492,10 @@ public class AmbariManagementControllerTest {
     // delete HC
     schRequests.clear();
     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));
     controller.deleteHostComponents(schRequests);
 
@@ -9132,7 +9137,10 @@ public class AmbariManagementControllerTest {
 
       // confirm delete
       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);
 
       sch = null;