You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by jo...@apache.org on 2017/07/25 14:35:19 UTC
[15/19] ambari git commit: AMBARI-21345 Add host doesn't fully add a
node when include/exclude files are used (additional patch) (dsen)
AMBARI-21345 Add host doesn't fully add a node when include/exclude files are used (additional patch) (dsen)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/b56446af
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/b56446af
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/b56446af
Branch: refs/heads/branch-feature-AMBARI-21450
Commit: b56446af660e1bb1e1a61db70a04ac0396bd6851
Parents: fe761ef
Author: Dmytro Sen <ds...@apache.org>
Authored: Mon Jul 24 19:58:29 2017 +0300
Committer: Dmytro Sen <ds...@apache.org>
Committed: Mon Jul 24 19:58:29 2017 +0300
----------------------------------------------------------------------
.../AmbariCustomCommandExecutionHelper.java | 5 +++
.../AmbariManagementControllerImpl.java | 43 ++++++++++++++++----
2 files changed, 39 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/b56446af/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelper.java
----------------------------------------------------------------------
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 723a10d..9bd38fc 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
@@ -139,6 +139,7 @@ public class AmbariCustomCommandExecutionHelper {
public final static String DECOM_SLAVE_COMPONENT = "slave_type";
public final static String HBASE_MARK_DRAINING_ONLY = "mark_draining_only";
public final static String UPDATE_FILES_ONLY = "update_files_only";
+ public final static String MULTI_SERVICES_DECOM_REQUEST = "multi_services_decom_request";
private final static String ALIGN_MAINTENANCE_STATE = "align_maintenance_state";
@@ -814,6 +815,10 @@ public class AmbariCustomCommandExecutionHelper {
Set<String> includedHosts = getHostList(actionExecutionContext.getParameters(),
DECOM_INCLUDED_HOSTS);
+ if (actionExecutionContext.getParameters().get(MULTI_SERVICES_DECOM_REQUEST) != null &&
+ actionExecutionContext.getParameters().get(MULTI_SERVICES_DECOM_REQUEST).equalsIgnoreCase("true")) {
+ includedHosts = getHostList(actionExecutionContext.getParameters(), masterCompType + "_" + DECOM_INCLUDED_HOSTS);
+ }
Set<String> cloneSet = new HashSet<>(excludedHosts);
cloneSet.retainAll(includedHosts);
http://git-wip-us.apache.org/repos/asf/ambari/blob/b56446af/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 850838d..13526c4 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
@@ -3335,7 +3335,7 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
if (changedComps != null) {
for (Entry<State, List<ServiceComponent>> entry :
- changedComps.entrySet()) {
+ changedComps.entrySet()) {
State newState = entry.getKey();
for (ServiceComponent sc : entry.getValue()) {
sc.setDesiredState(newState);
@@ -3343,7 +3343,9 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
}
}
+ //keep 2 maps for simpler maintenance
Map<String, String> serviceMasterForDecommissionMap = new HashMap<>();
+ Map<String, Set<String>> masterSlaveHostsMap = new HashMap<>();
for (Map<State, List<ServiceComponentHost>> stateScHostMap :
changedScHosts.values()) {
for (Entry<State, List<ServiceComponentHost>> entry :
@@ -3365,6 +3367,10 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
//Filter services whose masters are not started
if (isServiceComponentStartedOnAnyHost(cluster, serviceName, masterComponentName)) {
serviceMasterForDecommissionMap.put(serviceName, masterComponentName);
+ if (!masterSlaveHostsMap.containsKey(masterComponentName)) {
+ masterSlaveHostsMap.put(masterComponentName, new HashSet<String>());
+ }
+ masterSlaveHostsMap.get(masterComponentName).add(sch.getHostName());
} else {
LOG.info(String.format("Not adding %s service from include/exclude files refresh map because it's master is not started", serviceName));
}
@@ -3380,7 +3386,7 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
}
try {
- createAndExecuteRefreshIncludeExcludeFilesActionForMasters(serviceMasterForDecommissionMap, cluster.getClusterName());
+ createAndExecuteRefreshIncludeExcludeFilesActionForMasters(serviceMasterForDecommissionMap, masterSlaveHostsMap, cluster.getClusterName(), false);
} catch (AmbariException e) {
LOG.error("Exception during refresh include exclude files action : ", e);
}
@@ -3651,7 +3657,9 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
}
}
+ //keep 2 maps for simpler maintenance
Map<String, Map<String, String>> clusterServiceMasterForDecommissionMap = new HashMap<>();
+ Map<String, Map<String, Set<String>>> clusterMasterSlaveHostsMap = new HashMap<>();
for (Entry<ServiceComponent, Set<ServiceComponentHost>> entry : safeToRemoveSCHs.entrySet()) {
for (ServiceComponentHost componentHost : entry.getValue()) {
@@ -3669,10 +3677,19 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
}
if (clusterServiceMasterForDecommissionMap.containsKey(componentHost.getClusterName())) {
clusterServiceMasterForDecommissionMap.get(componentHost.getClusterName()).put(componentHost.getServiceName(), masterComponentName);
+ Map<String, Set<String>> masterSlaveMap = clusterMasterSlaveHostsMap.get(componentHost.getClusterName());
+ if (!masterSlaveMap.containsKey(masterComponentName)) {
+ masterSlaveMap.put(masterComponentName, new HashSet<String>());
+ }
+ masterSlaveMap.get(masterComponentName).add(componentHost.getHostName());
} else {
- Map<String, String> tempMap = new HashMap<>();
- tempMap.put(componentHost.getServiceName(), masterComponentName);
- clusterServiceMasterForDecommissionMap.put(componentHost.getClusterName(), tempMap);
+ Map<String, String> serviceMasterMap = new HashMap<>();
+ serviceMasterMap.put(componentHost.getServiceName(), masterComponentName);
+ clusterServiceMasterForDecommissionMap.put(componentHost.getClusterName(), serviceMasterMap);
+
+ Map<String, Set<String>> masterSlaveHostsMap = new HashMap<>();
+ masterSlaveHostsMap.put(masterComponentName, new HashSet<String>(Collections.singletonList(componentHost.getHostName())));
+ clusterMasterSlaveHostsMap.put(componentHost.getClusterName(), masterSlaveHostsMap);
}
}
} catch (Exception ex) {
@@ -3682,7 +3699,7 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
}
for (String cluster : clusterServiceMasterForDecommissionMap.keySet()) {
- createAndExecuteRefreshIncludeExcludeFilesActionForMasters(clusterServiceMasterForDecommissionMap.get(cluster), cluster);
+ createAndExecuteRefreshIncludeExcludeFilesActionForMasters(clusterServiceMasterForDecommissionMap.get(cluster), clusterMasterSlaveHostsMap.get(cluster), cluster, true);
}
//Do not break behavior for existing clients where delete request contains only 1 host component.
@@ -3740,10 +3757,10 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
/**
* Creates and triggers an action to update include and exclude files for the master components depending on current cluster topology and components state
* @param serviceMasterMap
- * @param clusterName
- * @throws AmbariException
+ * @param masterSlaveHostsMap
+ *@param clusterName @throws AmbariException
*/
- private void createAndExecuteRefreshIncludeExcludeFilesActionForMasters(Map<String, String> serviceMasterMap, String clusterName) throws AmbariException {
+ private void createAndExecuteRefreshIncludeExcludeFilesActionForMasters(Map<String, String> serviceMasterMap, Map<String, Set<String>> masterSlaveHostsMap, String clusterName, boolean isDecommission) throws AmbariException {
//Clear include/exclude files or draining list except HBASE
serviceMasterMap.remove(Service.Type.HBASE.toString());
//exit if empty
@@ -3757,6 +3774,14 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle
HashMap<String, String> params = new HashMap<>();
params.put(AmbariCustomCommandExecutionHelper.UPDATE_FILES_ONLY, "false");
+ for (String masterName : masterSlaveHostsMap.keySet()) {
+ if (!isDecommission) {
+ params.put(masterName + "_" + AmbariCustomCommandExecutionHelper.DECOM_INCLUDED_HOSTS, StringUtils.join(masterSlaveHostsMap.get(masterName).toArray(), ","));
+ }
+ }
+
+ params.put(AmbariCustomCommandExecutionHelper.MULTI_SERVICES_DECOM_REQUEST, "true");
+
//Create filter for command
List<RequestResourceFilter> resourceFilters = new ArrayList<>(serviceMasterMap.size());
for (String serviceName : serviceMasterMap.keySet()) {