Repository: ambari Updated Branches: refs/heads/trunk 4db43122f -> 9e43840ae
AMBARI-17455: Auto restart flag should be set to 1 for Metrics Collector after upgrade to 2.4.0 Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/9e43840a Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/9e43840a Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/9e43840a Branch: refs/heads/trunk Commit: 9e43840aeff2d0f13e3f61bb8dcb44046dd8877d Parents: 4db4312 Author: Nahappan Somasundaram <[email protected]> Authored: Tue Jun 28 13:06:22 2016 -0700 Committer: Nahappan Somasundaram <[email protected]> Committed: Wed Jun 29 21:27:10 2016 -0700 ---------------------------------------------------------------------- .../server/configuration/Configuration.java | 71 +++++++++++ .../server/upgrade/UpgradeCatalog240.java | 122 +++++++++++++++++++ .../server/upgrade/UpgradeCatalog240Test.java | 3 + 3 files changed, 196 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/9e43840a/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java b/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java index 153289e..399f26c 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java @@ -419,6 +419,17 @@ public class Configuration { public static final String KERBEROS_CHECK_JAAS_CONFIGURATION_DEFAULT = "false"; /** + * Recovery related configuration + */ + public static final String RECOVERY_TYPE_KEY = "recovery.type"; + public static final String RECOVERY_LIFETIME_MAX_COUNT_KEY = "recovery.lifetime_max_count"; + public static final String RECOVERY_MAX_COUNT_KEY = "recovery.max_count"; + public static final String RECOVERY_WINDOW_IN_MIN_KEY = "recovery.window_in_minutes"; + public static final String RECOVERY_RETRY_GAP_KEY = "recovery.retry_interval"; + public static final String RECOVERY_DISABLED_COMPONENTS_KEY = "recovery.disabled_components"; + public static final String RECOVERY_ENABLED_COMPONENTS_KEY = "recovery.enabled_components"; + + /** * Allow proxy calls to these hosts and ports only */ public static final String PROXY_ALLOWED_HOST_PORTS = "proxy.allowed.hostports"; @@ -2635,6 +2646,66 @@ public class Configuration { } /** + * Get the node recovery type DEFAULT|AUTO_START|FULL + * @return + */ + public String getNodeRecoveryType() { + return properties.getProperty(RECOVERY_TYPE_KEY); + } + + /** + * Get configured max count of recovery attempt allowed per host component in a window + * This is reset when agent is restarted. + * @return + */ + public String getNodeRecoveryMaxCount() { + return properties.getProperty(RECOVERY_MAX_COUNT_KEY); + } + + /** + * Get configured max lifetime count of recovery attempt allowed per host component. + * This is reset when agent is restarted. + * @return + */ + public String getNodeRecoveryLifetimeMaxCount() { + return properties.getProperty(RECOVERY_LIFETIME_MAX_COUNT_KEY); + } + + /** + * Get configured window size in minutes + * @return + */ + public String getNodeRecoveryWindowInMin() { + return properties.getProperty(RECOVERY_WINDOW_IN_MIN_KEY); + } + + /** + * Get the components for which recovery is disabled + * @return + */ + public String getRecoveryDisabledComponents() { + return properties.getProperty(RECOVERY_DISABLED_COMPONENTS_KEY); + } + + /** + * Get the components for which recovery is enabled + * @return + */ + public String getRecoveryEnabledComponents() { + return properties.getProperty(RECOVERY_ENABLED_COMPONENTS_KEY); + } + + /** + * Get the configured retry gap between tries per host component + * @return + */ + public String getNodeRecoveryRetryGap() { + return properties.getProperty(RECOVERY_RETRY_GAP_KEY); + } + + /** + + /** * Gets the default KDC port to use when no port is specified in KDC hostname * * @return the default KDC port to use. http://git-wip-us.apache.org/repos/asf/ambari/blob/9e43840a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog240.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog240.java b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog240.java index 18dd877..7ef12a7 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog240.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog240.java @@ -43,7 +43,9 @@ import java.util.UUID; import java.util.concurrent.atomic.AtomicLong; import org.apache.ambari.server.AmbariException; +import org.apache.ambari.server.agent.RecoveryConfigHelper; import org.apache.ambari.server.api.services.AmbariMetaInfo; +import org.apache.ambari.server.configuration.Configuration; import org.apache.ambari.server.controller.AmbariManagementController; import org.apache.ambari.server.orm.DBAccessor.DBColumnInfo; import org.apache.ambari.server.orm.dao.AlertDefinitionDAO; @@ -237,6 +239,9 @@ public class UpgradeCatalog240 extends AbstractUpgradeCatalog { @Inject Users users; + @Inject + Configuration config; + /** * Logger. */ @@ -414,6 +419,7 @@ public class UpgradeCatalog240 extends AbstractUpgradeCatalog { addConnectionTimeoutParamForWebAndMetricAlerts(); addSliderClientConfig(); updateRequestScheduleEntityUserIds(); + updateRecoveryConfigurationDML(); } /** @@ -1652,6 +1658,122 @@ public class UpgradeCatalog240 extends AbstractUpgradeCatalog { } /** + * Puts each item in the specified list inside single quotes and + * returns a comma separated value for use in a SQL query. + * @param list + * @return + */ + private String sqlStringListFromArrayList(List<String> list) { + List sqlList = new ArrayList<String>(list.size()); + + for (String item : list) { + sqlList.add(String.format("'%s'", item.trim())); + } + + return StringUtils.join(sqlList, ','); + } + + /** + * Update clusterconfig table for config type 'cluster-env' with the + * recovery attributes. + * + * @throws AmbariException + */ + private void updateRecoveryClusterEnvConfig() throws AmbariException { + Map<String, String> propertyMap = new HashMap<>(); + + if (StringUtils.isNotEmpty(config.getNodeRecoveryType())) { + propertyMap.put(RecoveryConfigHelper.RECOVERY_ENABLED_KEY, "true"); + propertyMap.put(RecoveryConfigHelper.RECOVERY_TYPE_KEY, config.getNodeRecoveryType()); + } + else { + propertyMap.put(RecoveryConfigHelper.RECOVERY_ENABLED_KEY, "false"); + } + + if (StringUtils.isNotEmpty(config.getNodeRecoveryLifetimeMaxCount())) { + propertyMap.put(RecoveryConfigHelper.RECOVERY_LIFETIME_MAX_COUNT_KEY, config.getNodeRecoveryLifetimeMaxCount()); + } + + if (StringUtils.isNotEmpty(config.getNodeRecoveryMaxCount())) { + propertyMap.put(RecoveryConfigHelper.RECOVERY_MAX_COUNT_KEY, config.getNodeRecoveryMaxCount()); + } + + if (StringUtils.isNotEmpty(config.getNodeRecoveryRetryGap())) { + propertyMap.put(RecoveryConfigHelper.RECOVERY_RETRY_GAP_KEY, config.getNodeRecoveryRetryGap()); + } + + if (StringUtils.isNotEmpty(config.getNodeRecoveryWindowInMin())) { + propertyMap.put(RecoveryConfigHelper.RECOVERY_WINDOW_IN_MIN_KEY, config.getNodeRecoveryWindowInMin()); + } + + AmbariManagementController ambariManagementController = injector.getInstance( + AmbariManagementController.class); + + Clusters clusters = ambariManagementController.getClusters(); + + // for each cluster, update/create the cluster-env config type in clusterconfig + Map<String, Cluster> clusterMap = getCheckedClusterMap(clusters); + for (final Cluster cluster : clusterMap.values()) { + updateConfigurationPropertiesForCluster(cluster, ConfigHelper.CLUSTER_ENV, propertyMap, + true /* update if exists */, true /* create new config type */); + } + } + + /** + * Alter servicecomponentdesiredstate table to update recovery_enabled to 1 + * for the components that have been marked for auto start in ambari.properties + * @throws SQLException + */ + private void updateRecoveryComponents() throws SQLException { + + /* + * Whether specific components are enabled/disabled for recovery. Being enabled takes + * precedence over being disabled. When specific components are enabled then only + * those components are enabled. When specific components are disabled then all of + * the other components are enabled. + */ + String enabledComponents = config.getRecoveryEnabledComponents(); + String disabledComponents = config.getRecoveryDisabledComponents(); + String query; + + if (StringUtils.isEmpty(enabledComponents)) { + if (StringUtils.isEmpty(disabledComponents)) { + // disable all components + query = String.format("UPDATE %s SET recovery_enabled = 0", SERVICE_COMPONENT_DESIRED_STATE_TABLE); + } + else { + // enable (1 - disabledComponents) + List<String> disabledComponentsList = Arrays.asList(disabledComponents.split(",")); + String components = sqlStringListFromArrayList(disabledComponentsList); + query = String.format("UPDATE %s SET recovery_enabled = 1 WHERE component_name NOT IN (%s)", + SERVICE_COMPONENT_DESIRED_STATE_TABLE, components); + } + } + else { + // enable the specified components + List<String> enabledComponentsList = Arrays.asList(enabledComponents.split(",")); + String components = sqlStringListFromArrayList(enabledComponentsList); + query = String.format("UPDATE %s SET recovery_enabled = 1 WHERE component_name IN (%s)", + SERVICE_COMPONENT_DESIRED_STATE_TABLE, components); + } + + dbAccessor.executeQuery(query); + } + + + /** + * Update clusterconfig table and servicecomponentdesiredstate table with the + * recovery attributes and componenents to be recovered. + * + * @throws SQLException + */ + @Transactional + protected void updateRecoveryConfigurationDML() throws SQLException, AmbariException { + updateRecoveryClusterEnvConfig(); + updateRecoveryComponents(); + } + + /** * Update Clusters and Hosts Version State from UPGRADING, UPGRADE_FAILED to INSTALLED * and UPGRADED to CURRENT if repo_version_id from cluster_version equals repo_version_id of Clusters and Hosts Version State * http://git-wip-us.apache.org/repos/asf/ambari/blob/9e43840a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog240Test.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog240Test.java b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog240Test.java index bf681f2..91d84e9 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog240Test.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog240Test.java @@ -584,6 +584,7 @@ public class UpgradeCatalog240Test { Method addConnectionTimeoutParamForWebAndMetricAlerts = AbstractUpgradeCatalog.class.getDeclaredMethod("addConnectionTimeoutParamForWebAndMetricAlerts"); Method addSliderClientConfig = UpgradeCatalog240.class.getDeclaredMethod("addSliderClientConfig"); Method updateRequestScheduleEntityUserIds = UpgradeCatalog240.class.getDeclaredMethod("updateRequestScheduleEntityUserIds"); + Method updateRecoveryConfigurationDML = UpgradeCatalog240.class.getDeclaredMethod("updateRecoveryConfigurationDML"); Capture<String> capturedStatements = newCapture(CaptureType.ALL); @@ -627,6 +628,7 @@ public class UpgradeCatalog240Test { .addMockedMethod(updateHBaseConfigs) .addMockedMethod(addSliderClientConfig) .addMockedMethod(updateRequestScheduleEntityUserIds) + .addMockedMethod(updateRecoveryConfigurationDML) .createMock(); Field field = AbstractUpgradeCatalog.class.getDeclaredField("dbAccessor"); @@ -665,6 +667,7 @@ public class UpgradeCatalog240Test { upgradeCatalog240.updateHBaseConfigs(); upgradeCatalog240.addSliderClientConfig(); upgradeCatalog240.updateRequestScheduleEntityUserIds(); + upgradeCatalog240.updateRecoveryConfigurationDML(); replay(upgradeCatalog240, dbAccessor);
