Repository: ambari Updated Branches: refs/heads/branch-2.5 fab367491 -> edcc6c6e8
AMBARI-21129. Nimbus fails to start when Ambari is upgraded to 2.5.1, EU to HDP 2.6.1, and cluster is then Kerberized (alejandro) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/edcc6c6e Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/edcc6c6e Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/edcc6c6e Branch: refs/heads/branch-2.5 Commit: edcc6c6e89407c51d9be6d67640de38722657d0b Parents: fab3674 Author: Alejandro Fernandez <afernan...@hortonworks.com> Authored: Fri Jun 2 15:44:34 2017 -0700 Committer: Alejandro Fernandez <afernan...@hortonworks.com> Committed: Fri Jun 2 15:44:34 2017 -0700 ---------------------------------------------------------------------- .../server/upgrade/UpgradeCatalog251.java | 50 ++++++++++++++++++++ .../server/upgrade/UpgradeCatalog251Test.java | 6 +++ 2 files changed, 56 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/edcc6c6e/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog251.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog251.java b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog251.java index 40fafb2..f4f69f7 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog251.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog251.java @@ -18,12 +18,20 @@ package org.apache.ambari.server.upgrade; import java.sql.SQLException; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; import org.apache.ambari.server.AmbariException; +import org.apache.ambari.server.controller.AmbariManagementController; import org.apache.ambari.server.orm.DBAccessor.DBColumnInfo; import com.google.inject.Inject; import com.google.inject.Injector; +import org.apache.ambari.server.state.Cluster; +import org.apache.ambari.server.state.Clusters; +import org.apache.ambari.server.state.Config; +import org.apache.ambari.server.state.SecurityType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -39,6 +47,7 @@ public class UpgradeCatalog251 extends AbstractUpgradeCatalog { private static final String REQUEST_TABLE = "request"; private static final String CLUSTER_HOST_INFO_COLUMN = "cluster_host_info"; private static final String REQUEST_ID_COLUMN = "request_id"; + protected static final String STORM_ENV_CONFIG = "storm-env"; /** @@ -94,6 +103,7 @@ public class UpgradeCatalog251 extends AbstractUpgradeCatalog { @Override protected void executeDMLUpdates() throws AmbariException, SQLException { addNewConfigurationsFromXml(); + updateSTORMConfigs(); } /** @@ -121,4 +131,44 @@ public class UpgradeCatalog251 extends AbstractUpgradeCatalog { dbAccessor.moveColumnToAnotherTable(STAGE_TABLE, sourceColumn, REQUEST_ID_COLUMN, REQUEST_TABLE, targetColumn, REQUEST_ID_COLUMN, false); } + + /** + * Make sure storm-env changes are applied to anyone upgrading to HDP-2.6.1 Storm + * If the base version was before Ambari 2.5.0, this method should wind up doing nothing. + * @throws AmbariException + */ + protected void updateSTORMConfigs() throws AmbariException { + AmbariManagementController ambariManagementController = injector.getInstance(AmbariManagementController.class); + Clusters clusters = ambariManagementController.getClusters(); + if (clusters != null) { + Map<String, Cluster> clusterMap = getCheckedClusterMap(clusters); + if (clusterMap != null && !clusterMap.isEmpty()) { + for (final Cluster cluster : clusterMap.values()) { + Set<String> installedServices = cluster.getServices().keySet(); + + // Technically, this should be added when the cluster is Kerberized on HDP 2.6.1, but is safe to add even + // without security or on an older stack version (such as HDP 2.5) + // The problem is that Kerberizing a cluster does not invoke Stack Advisor and has no easy way of setting + // these configs, so instead, add them as long as Storm is present. + if (installedServices.contains("STORM")) { + Config stormEnv = cluster.getDesiredConfigByType(STORM_ENV_CONFIG); + String content = stormEnv.getProperties().get("content"); + if (content != null && !content.contains("STORM_AUTOCREDS_LIB_DIR")) { + Map<String, String> newProperties = new HashMap<>(); + String stormEnvConfigs = "\n# set storm-auto creds\n" + + "# check if storm_jaas.conf in config, only enable storm_auto_creds in secure mode.\n" + + "STORM_JAAS_CONF=$STORM_HOME/conf/storm_jaas.conf\n" + + "STORM_AUTOCREDS_LIB_DIR=$STORM_HOME/external/storm-autocreds\n" + + "if [ -f $STORM_JAAS_CONF ] && [ -d $STORM_AUTOCREDS_LIB_DIR ]; then\n" + + " export STORM_EXT_CLASSPATH=$STORM_AUTOCREDS_LIB_DIR\n" + + "fi\n"; + content += stormEnvConfigs; + newProperties.put("content", content); + updateConfigurationPropertiesForCluster(cluster, "storm-env", newProperties, true, false); + } + } + } + } + } + } } http://git-wip-us.apache.org/repos/asf/ambari/blob/edcc6c6e/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog251Test.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog251Test.java b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog251Test.java index 862ab6e..2ac9d46 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog251Test.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog251Test.java @@ -170,13 +170,19 @@ public class UpgradeCatalog251Test { @Test public void testExecuteDMLUpdates() throws Exception { Method addNewConfigurationsFromXml = AbstractUpgradeCatalog.class.getDeclaredMethod("addNewConfigurationsFromXml"); + Method updateSTORMConfigs = UpgradeCatalog251.class.getDeclaredMethod("updateSTORMConfigs"); + UpgradeCatalog251 upgradeCatalog251 = createMockBuilder(UpgradeCatalog251.class) .addMockedMethod(addNewConfigurationsFromXml) + .addMockedMethod(updateSTORMConfigs) .createMock(); upgradeCatalog251.addNewConfigurationsFromXml(); expectLastCall().once(); + upgradeCatalog251.updateSTORMConfigs(); + expectLastCall().once(); + replay(upgradeCatalog251); upgradeCatalog251.executeDMLUpdates();