This is an automated email from the ASF dual-hosted git repository.

vjasani pushed a commit to branch branch-2.7
in repository https://gitbox.apache.org/repos/asf/ambari.git


The following commit(s) were added to refs/heads/branch-2.7 by this push:
     new c1226eb025 AMBARI-25950: Exclude hosts getting erased when RM, NN are 
restarted (#3711)
c1226eb025 is described below

commit c1226eb0255d575705266a06df91a8afb4aa4b42
Author: Murali Krishna <muralikrishna.dm...@gmail.com>
AuthorDate: Mon Aug 21 23:15:44 2023 +0530

    AMBARI-25950: Exclude hosts getting erased when RM, NN are restarted (#3711)
---
 .../controller/AmbariCustomCommandExecutionHelper.java     | 11 ++++++++++-
 .../server/controller/AmbariManagementControllerImpl.java  | 11 +++++++++++
 .../server/controller/AmbariManagementControllerTest.java  | 14 +++++++++++++-
 .../controller/BackgroundCustomCommandExecutionTest.java   |  2 ++
 4 files changed, 36 insertions(+), 2 deletions(-)

diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelper.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelper.java
index 347b5e9167..92e8b05f6d 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelper.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelper.java
@@ -1040,7 +1040,7 @@ public class AmbariCustomCommandExecutionHelper {
     }
   }
 
-  private Set<String> calculateDecommissionedNodes(Service service, String 
slaveCompType) throws AmbariException {
+  Set<String> calculateDecommissionedNodes(Service service, String 
slaveCompType) throws AmbariException {
     Set<String> decommissionedHostsSet = new HashSet<>();
     ServiceComponent serviceComponent = 
service.getServiceComponent(slaveCompType);
     for (ServiceComponentHost serviceComponentHost : 
serviceComponent.getServiceComponentHosts().values()) {
@@ -1151,6 +1151,15 @@ public class AmbariCustomCommandExecutionHelper {
           extraParams.put(componentName, requestParams.get(componentName));
         }
 
+        if 
(resourceFilter.getComponentName().equals(Role.RESOURCEMANAGER.name())){
+          extraParams.putIfAbsent(ALL_DECOMMISSIONED_HOSTS, 
StringUtils.join(calculateDecommissionedNodes(
+            
clusters.getCluster(actionExecutionContext.getClusterName()).getService(Service.Type.YARN.name()),
+              Role.NODEMANAGER.name()), ','));
+        } else if 
(resourceFilter.getComponentName().equals(Role.NAMENODE.name())){
+          extraParams.putIfAbsent(ALL_DECOMMISSIONED_HOSTS, 
StringUtils.join(calculateDecommissionedNodes(
+            
clusters.getCluster(actionExecutionContext.getClusterName()).getService(Service.Type.HDFS.name()),
+              Role.DATANODE.name()), ','));
+        }
         // If command should be retried upon failure then add the option and 
also the default duration for retry
         if (requestParams.containsKey(KeyNames.COMMAND_RETRY_ENABLED)) {
           extraParams.put(KeyNames.COMMAND_RETRY_ENABLED, 
requestParams.get(KeyNames.COMMAND_RETRY_ENABLED));
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 d3e4364ea6..5156746c1f 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
@@ -2615,6 +2615,17 @@ public class AmbariManagementControllerImpl implements 
AmbariManagementControlle
     execCmd.setRoleParams(roleParams);
     execCmd.setCommandParams(commandParams);
 
+    String role = execCmd.getRole();
+    if (role.equals(Role.RESOURCEMANAGER.name())) {
+      
commandParams.putIfAbsent(AmbariCustomCommandExecutionHelper.ALL_DECOMMISSIONED_HOSTS,
+        
StringUtils.join(customCommandExecutionHelper.calculateDecommissionedNodes(
+          clusterService, Role.NODEMANAGER.name()), ','));
+    } else if (role.equals(Role.NAMENODE.name())) {
+      
commandParams.putIfAbsent(AmbariCustomCommandExecutionHelper.ALL_DECOMMISSIONED_HOSTS,
+        
StringUtils.join(customCommandExecutionHelper.calculateDecommissionedNodes(
+          clusterService, Role.DATANODE.name()), ','));
+    }
+
     CommandRepository commandRepository;
     try {
       commandRepository = repoVersionHelper.getCommandRepository(cluster, 
component, host);
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 2ee98af0e4..118ce7d7aa 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
@@ -2087,7 +2087,11 @@ public class AmbariManagementControllerTest {
 
       for (String host : stage.getHosts()) {
         for (ExecutionCommandWrapper ecw : stage.getExecutionCommands(host)) {
-          Assert.assertNotNull(ecw.getExecutionCommand().getRepositoryFile());
+          ExecutionCommand execCmd = ecw.getExecutionCommand();
+         if (execCmd.getRole().equals(Role.NAMENODE)) {
+            
Assert.assertTrue(execCmd.getCommandParams().containsKey("all_decommissioned_hosts"));
+         }
+          Assert.assertNotNull(execCmd.getRepositoryFile());
         }
       }
     }
@@ -6173,6 +6177,7 @@ public class AmbariManagementControllerTest {
     hdfs.addServiceComponent(Role.DATANODE.name());
 
     mapred.addServiceComponent(Role.RESOURCEMANAGER.name());
+    mapred.addServiceComponent(Role.NODEMANAGER.name());
 
     
hdfs.getServiceComponent(Role.HDFS_CLIENT.name()).addServiceComponentHost(host1);
     
hdfs.getServiceComponent(Role.NAMENODE.name()).addServiceComponentHost(host1);
@@ -6180,6 +6185,7 @@ public class AmbariManagementControllerTest {
     
hdfs.getServiceComponent(Role.DATANODE.name()).addServiceComponentHost(host2);
 
     
mapred.getServiceComponent(Role.RESOURCEMANAGER.name()).addServiceComponentHost(host2);
+    
mapred.getServiceComponent(Role.NODEMANAGER.name()).addServiceComponentHost(host2);
 
     Map<String, String> params = new HashMap<String, String>() {{
       put("test", "test");
@@ -6211,6 +6217,9 @@ public class AmbariManagementControllerTest {
       Assert.assertEquals("RESTART", hrc.getCustomCommandName());
 
       Map<String, String> cParams = 
hrc.getExecutionCommandWrapper().getExecutionCommand().getCommandParams();
+      if (hrc.getRole().equals(Role.RESOURCEMANAGER)) {
+        Assert.assertTrue(cParams.containsKey("all_decommissioned_hosts"));
+      }
       Assert.assertEquals("Expect retry to be set", true, 
cParams.containsKey("command_retry_enabled"));
       Assert.assertEquals("Expect max duration to be set", true, 
cParams.containsKey("max_duration_for_retries"));
       Assert.assertEquals("Expect max duration to be 600", "600", 
cParams.get("max_duration_for_retries"));
@@ -10208,10 +10217,13 @@ public class AmbariManagementControllerTest {
     String serviceName = "HDFS";
     createService(cluster1, serviceName, null);
     String componentName1 = "NAMENODE";
+    String componentName2 = "DATANODE";
 
     createServiceComponent(cluster1, serviceName, componentName1, State.INIT);
+    createServiceComponent(cluster1, serviceName, componentName2, State.INIT);
 
     createServiceComponentHost(cluster1, serviceName, componentName1, host1, 
null);
+    createServiceComponentHost(cluster1, serviceName, componentName2, host1, 
null);
 
     // Install
     installService(cluster1, serviceName, false, false);
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/controller/BackgroundCustomCommandExecutionTest.java
 
b/ambari-server/src/test/java/org/apache/ambari/server/controller/BackgroundCustomCommandExecutionTest.java
index c2a4b8e0d2..bf89053c18 100644
--- 
a/ambari-server/src/test/java/org/apache/ambari/server/controller/BackgroundCustomCommandExecutionTest.java
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/controller/BackgroundCustomCommandExecutionTest.java
@@ -196,8 +196,10 @@ public class BackgroundCustomCommandExecutionTest {
     createService("c1", "HDFS", null);
     createService("c1", "HBASE", null);
     createServiceComponent("c1", "HDFS", "NAMENODE", State.INIT);
+    createServiceComponent("c1", "HDFS", "DATANODE", State.INIT);
     createServiceComponent("c1", "HBASE", "HBASE_MASTER", State.INIT);
     createServiceComponentHost("c1", "HDFS", "NAMENODE", "c6401", null);
+    createServiceComponentHost("c1", "HDFS", "DATANODE", "c6401", null);
     createServiceComponentHost("c1", "HBASE", "HBASE_MASTER", "c7007", null);
   }
   private void addHost(String hostname, String clusterName) throws 
AmbariException {


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@ambari.apache.org
For additional commands, e-mail: commits-h...@ambari.apache.org

Reply via email to