Repository: ambari Updated Branches: refs/heads/branch-2.6 e99bfd023 -> efe88a49e
AMBARI-22240. Restart of random service could fail during express downgrade (ncole) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/efe88a49 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/efe88a49 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/efe88a49 Branch: refs/heads/branch-2.6 Commit: efe88a49ee2db242860141469723be93a5896bd0 Parents: e99bfd0 Author: Nate Cole <[email protected]> Authored: Fri Oct 13 21:38:42 2017 -0400 Committer: Nate Cole <[email protected]> Committed: Mon Oct 16 09:01:17 2017 -0400 ---------------------------------------------------------------------- .../controller/AmbariManagementController.java | 3 +- .../AmbariManagementControllerImpl.java | 14 +- .../ambari/server/state/ConfigFactory.java | 12 +- .../ambari/server/state/ConfigHelper.java | 2 +- .../apache/ambari/server/state/ConfigImpl.java | 27 ++- .../ambari/server/state/UpgradeHelper.java | 19 +- .../server/state/cluster/ClusterImpl.java | 8 +- .../state/configgroup/ConfigGroupImpl.java | 22 ++- .../server/upgrade/AbstractUpgradeCatalog.java | 2 +- .../ExecutionCommandWrapperTest.java | 11 +- .../server/agent/HeartbeatTestHelper.java | 2 +- .../server/agent/TestHeartbeatMonitor.java | 6 +- .../upgrade/AbstractUpgradeCatalogTest.java | 8 +- .../server/upgrade/UpgradeCatalog250Test.java | 174 +++++++++---------- .../server/upgrade/UpgradeCatalog252Test.java | 8 +- .../server/upgrade/UpgradeCatalog260Test.java | 12 +- 16 files changed, 190 insertions(+), 140 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/efe88a49/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementController.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementController.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementController.java index 91bfe09..54c0848 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementController.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementController.java @@ -57,6 +57,7 @@ import org.apache.ambari.server.state.ServiceComponentFactory; import org.apache.ambari.server.state.ServiceComponentHost; import org.apache.ambari.server.state.ServiceInfo; import org.apache.ambari.server.state.ServiceOsSpecific; +import org.apache.ambari.server.state.StackId; import org.apache.ambari.server.state.State; import org.apache.ambari.server.state.configgroup.ConfigGroupFactory; import org.apache.ambari.server.state.quicklinksprofile.QuickLinkVisibilityController; @@ -114,7 +115,7 @@ public interface AmbariManagementController { * TODO move this method to Cluster? doesn't seem to be on its place * @return config created */ - Config createConfig(Cluster cluster, String type, Map<String, String> properties, + Config createConfig(Cluster cluster, StackId stackId, String type, Map<String, String> properties, String versionTag, Map<String, Map<String, String>> propertiesAttributes); /** http://git-wip-us.apache.org/repos/asf/ambari/blob/efe88a49/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 18659d4..83521c6 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 @@ -904,7 +904,15 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle request.getType())); } - Config config = createConfig(cluster, request.getType(), requestProperties, + StackId stackId = null; + if (null != service) { + Service svc = cluster.getService(service); + stackId = svc.getDesiredStackId(); + } else { + stackId = cluster.getDesiredStackVersion(); + } + + Config config = createConfig(cluster, stackId, request.getType(), requestProperties, request.getVersionTag(), propertiesAttributes); LOG.info(MessageFormat.format("Creating configuration with tag ''{0}'' to cluster ''{1}'' for configuration type {2}", @@ -916,10 +924,10 @@ public class AmbariManagementControllerImpl implements AmbariManagementControlle } @Override - public Config createConfig(Cluster cluster, String type, Map<String, String> properties, + public Config createConfig(Cluster cluster, StackId stackId, String type, Map<String, String> properties, String versionTag, Map<String, Map<String, String>> propertiesAttributes) { - Config config = configFactory.createNew(cluster, type, versionTag, properties, + Config config = configFactory.createNew(stackId, cluster, type, versionTag, properties, propertiesAttributes); cluster.addConfig(config); http://git-wip-us.apache.org/repos/asf/ambari/blob/efe88a49/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigFactory.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigFactory.java b/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigFactory.java index d6cd997..6307f18 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigFactory.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigFactory.java @@ -19,6 +19,8 @@ package org.apache.ambari.server.state; import java.util.Map; +import org.apache.ambari.annotations.Experimental; +import org.apache.ambari.annotations.ExperimentalFeature; import org.apache.ambari.server.orm.entities.ClusterConfigEntity; import com.google.inject.assistedinject.Assisted; @@ -30,6 +32,14 @@ public interface ConfigFactory { /** * Creates a new {@link Config} object using provided values. + */ + @Experimental(feature = ExperimentalFeature.PATCH_UPGRADES, + comment = "This constructor is only used for test compatibility and should be removed") + Config createNew(Cluster cluster, @Assisted("type") String type, @Assisted("tag") String tag, + Map<String, String> map, Map<String, Map<String, String>> mapAttributes); + + /** + * Creates a new {@link Config} object using provided values. * * @param cluster * @param type @@ -38,7 +48,7 @@ public interface ConfigFactory { * @param mapAttributes * @return */ - Config createNew(Cluster cluster, @Assisted("type") String type, @Assisted("tag") String tag, + Config createNew(StackId stackId, Cluster cluster, @Assisted("type") String type, @Assisted("tag") String tag, Map<String, String> map, Map<String, Map<String, String>> mapAttributes); /** http://git-wip-us.apache.org/repos/asf/ambari/blob/efe88a49/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigHelper.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigHelper.java b/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigHelper.java index 987ff38..0738897 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigHelper.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigHelper.java @@ -1176,7 +1176,7 @@ public class ConfigHelper { } } - return controller.createConfig(cluster, type, properties, tag, propertyAttributes); + return controller.createConfig(cluster, stackId, type, properties, tag, propertyAttributes); } /** http://git-wip-us.apache.org/repos/asf/ambari/blob/efe88a49/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigImpl.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigImpl.java index 0a861d8..abe2e8b 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigImpl.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/state/ConfigImpl.java @@ -32,8 +32,10 @@ import org.apache.ambari.server.events.publishers.AmbariEventPublisher; import org.apache.ambari.server.logging.LockFactory; import org.apache.ambari.server.orm.dao.ClusterDAO; import org.apache.ambari.server.orm.dao.ServiceConfigDAO; +import org.apache.ambari.server.orm.dao.StackDAO; import org.apache.ambari.server.orm.entities.ClusterConfigEntity; import org.apache.ambari.server.orm.entities.ClusterEntity; +import org.apache.ambari.server.orm.entities.StackEntity; import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -95,11 +97,27 @@ public class ConfigImpl implements Config { private final AmbariEventPublisher eventPublisher; + /** + * Temporary constructor to used for testing purposes + */ @AssistedInject ConfigImpl(@Assisted Cluster cluster, @Assisted("type") String type, @Assisted("tag") @Nullable String tag, @Assisted Map<String, String> properties, - @Assisted @Nullable Map<String, Map<String, String>> propertiesAttributes, ClusterDAO clusterDAO, + @Assisted @Nullable Map<String, Map<String, String>> propertiesAttributes, + ClusterDAO clusterDAO, StackDAO stackDAO, + Gson gson, AmbariEventPublisher eventPublisher, LockFactory lockFactory) { + this(cluster.getDesiredStackVersion(), cluster, type, tag, properties, propertiesAttributes, + clusterDAO, stackDAO, gson, eventPublisher, lockFactory); + } + + + @AssistedInject + ConfigImpl(@Assisted StackId stackId, @Assisted Cluster cluster, @Assisted("type") String type, + @Assisted("tag") @Nullable String tag, + @Assisted Map<String, String> properties, + @Assisted @Nullable Map<String, Map<String, String>> propertiesAttributes, + ClusterDAO clusterDAO, StackDAO stackDAO, Gson gson, AmbariEventPublisher eventPublisher, LockFactory lockFactory) { propertyLock = lockFactory.newReadWriteLock(PROPERTY_LOCK_LABEL); @@ -122,6 +140,7 @@ public class ConfigImpl implements Config { this.tag = tag; ClusterEntity clusterEntity = clusterDAO.findById(cluster.getClusterId()); + StackEntity stackEntity = stackDAO.find(stackId); ClusterConfigEntity entity = new ClusterConfigEntity(); entity.setClusterEntity(clusterEntity); @@ -130,7 +149,7 @@ public class ConfigImpl implements Config { entity.setVersion(version); entity.setTag(this.tag); entity.setTimestamp(System.currentTimeMillis()); - entity.setStack(clusterEntity.getDesiredStack()); + entity.setStack(stackEntity); entity.setData(gson.toJson(properties)); if (null != propertiesAttributes) { @@ -139,7 +158,7 @@ public class ConfigImpl implements Config { // when creating a brand new config without a backing entity, use the // cluster's desired stack as the config's stack - stackId = cluster.getDesiredStackVersion(); + this.stackId = stackId; propertiesTypes = cluster.getConfigPropertiesTypes(type); persist(entity); @@ -278,7 +297,7 @@ public class ConfigImpl implements Config { @Override public Map<String, Map<String, String>> getPropertiesAttributes() { return null == propertiesAttributes ? null - : new HashMap<String, Map<String, String>>(propertiesAttributes); + : new HashMap<>(propertiesAttributes); } @Override http://git-wip-us.apache.org/repos/asf/ambari/blob/efe88a49/ambari-server/src/main/java/org/apache/ambari/server/state/UpgradeHelper.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/UpgradeHelper.java b/ambari-server/src/main/java/org/apache/ambari/server/state/UpgradeHelper.java index 77e2d47..9bb8262 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/state/UpgradeHelper.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/state/UpgradeHelper.java @@ -951,20 +951,6 @@ public class UpgradeHelper { Set<String> clusterConfigTypes = new HashSet<>(); Set<String> processedClusterConfigTypes = new HashSet<>(); - // downgrades are easy - either do nothing or simply apply configurations - // from the target stack - if (direction == Direction.DOWNGRADE) { - StackId currentStackId = cluster.getCurrentStackVersion(); - StackId desiredStackId = cluster.getDesiredStackVersion(); - - if (!currentStackId.equals(desiredStackId)) { - cluster.applyLatestConfigurations(currentStackId); - } - - return; - } - - // upgrade is a bit harder - we have to merge new stack configurations in // merge or revert configurations for any service that needs it for (String serviceName : servicesInUpgrade) { RepositoryVersionEntity sourceRepositoryVersion = upgradeContext.getSourceRepositoryVersion(serviceName); @@ -985,6 +971,11 @@ public class UpgradeHelper { ConfigHelper configHelper = m_configHelperProvider.get(); + if (direction == Direction.DOWNGRADE) { + cluster.applyLatestConfigurations(targetStackId, serviceName); + continue; + } + // the auto-merge must take read-only properties even if they have changed // - if the properties was read-only in the source stack, then we must // take the new stack's value http://git-wip-us.apache.org/repos/asf/ambari/blob/efe88a49/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java index 6bde42c..ce328f9 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClusterImpl.java @@ -560,6 +560,7 @@ public class ClusterImpl implements Cluster { return serviceComponentHosts.get(serviceName).get(serviceComponentName).get(hostname); } + @Override public List<ServiceComponentHost> getServiceComponentHosts() { List<ServiceComponentHost> serviceComponentHosts = new ArrayList<>(); if (!serviceComponentHostsByHost.isEmpty()) { @@ -1825,7 +1826,7 @@ public class ClusterImpl implements Cluster { Collection<String> configTypes = serviceConfigTypes.get(serviceName); List<ClusterConfigEntity> enabledConfigs = clusterDAO.getEnabledConfigsByTypes(clusterId, configTypes); List<ClusterConfigEntity> serviceConfigEntities = serviceConfigEntity.getClusterConfigEntities(); - ArrayList<ClusterConfigEntity> duplicatevalues = new ArrayList<ClusterConfigEntity>(serviceConfigEntities); + ArrayList<ClusterConfigEntity> duplicatevalues = new ArrayList<>(serviceConfigEntities); duplicatevalues.retainAll(enabledConfigs); for (ClusterConfigEntity enabledConfig : enabledConfigs) { @@ -2413,7 +2414,10 @@ public class ClusterImpl implements Cluster { // since the entities which were modified came from the cluster entity's // list to begin with, we can just save them right back - no need for a // new collection since the entity instances were modified directly - clusterEntity = clusterDAO.merge(clusterEntity); + + // !!! without providing the flush here, when this transaction completes it + // looks like the database has all unselected configs for some types + clusterEntity = clusterDAO.merge(clusterEntity, true); cacheConfigurations(); http://git-wip-us.apache.org/repos/asf/ambari/blob/efe88a49/ambari-server/src/main/java/org/apache/ambari/server/state/configgroup/ConfigGroupImpl.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/configgroup/ConfigGroupImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/state/configgroup/ConfigGroupImpl.java index 1a8b5b6..3cc1856 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/state/configgroup/ConfigGroupImpl.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/state/configgroup/ConfigGroupImpl.java @@ -51,6 +51,8 @@ import org.apache.ambari.server.state.Clusters; import org.apache.ambari.server.state.Config; import org.apache.ambari.server.state.ConfigFactory; import org.apache.ambari.server.state.Host; +import org.apache.ambari.server.state.Service; +import org.apache.ambari.server.state.StackId; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -150,8 +152,8 @@ public class ConfigGroupImpl implements ConfigGroup { configGroupId = configGroupEntity.getGroupId(); configGroupName = configGroupEntity.getGroupName(); - m_configurations = new ConcurrentHashMap<String, Config>(); - m_hosts = new ConcurrentHashMap<Long, Host>(); + m_configurations = new ConcurrentHashMap<>(); + m_hosts = new ConcurrentHashMap<>(); // Populate configs for (ConfigGroupConfigMappingEntity configMappingEntity : configGroupEntity.getConfigGroupConfigMappingEntities()) { @@ -423,8 +425,12 @@ public class ConfigGroupImpl implements ConfigGroup { (cluster.getClusterId(), config.getType(), config.getTag()); if (clusterConfigEntity == null) { - config = configFactory.createNew(cluster, config.getType(), config.getTag(), - config.getProperties(), config.getPropertiesAttributes()); + String serviceName = getServiceName(); + Service service = cluster.getServices().get(serviceName); + StackId stackId = (null == service) ? cluster.getDesiredStackVersion() : service.getDesiredStackId(); + + config = configFactory.createNew(stackId, cluster, config.getType(), + config.getTag(), config.getProperties(), config.getPropertiesAttributes()); entry.setValue(config); @@ -484,17 +490,17 @@ public class ConfigGroupImpl implements ConfigGroup { @Override public ConfigGroupResponse convertToResponse() throws AmbariException { - Set<Map<String, Object>> hostnames = new HashSet<Map<String, Object>>(); + Set<Map<String, Object>> hostnames = new HashSet<>(); for (Host host : m_hosts.values()) { - Map<String, Object> hostMap = new HashMap<String, Object>(); + Map<String, Object> hostMap = new HashMap<>(); hostMap.put("host_name", host.getHostName()); hostnames.add(hostMap); } - Set<Map<String, Object>> configObjMap = new HashSet<Map<String, Object>>(); + Set<Map<String, Object>> configObjMap = new HashSet<>(); for (Config config : m_configurations.values()) { - Map<String, Object> configMap = new HashMap<String, Object>(); + Map<String, Object> configMap = new HashMap<>(); configMap.put(ConfigurationResourceProvider.CONFIGURATION_CONFIG_TYPE_PROPERTY_ID, config.getType()); configMap.put(ConfigurationResourceProvider.CONFIGURATION_CONFIG_TAG_PROPERTY_ID, http://git-wip-us.apache.org/repos/asf/ambari/blob/efe88a49/ambari-server/src/main/java/org/apache/ambari/server/upgrade/AbstractUpgradeCatalog.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/AbstractUpgradeCatalog.java b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/AbstractUpgradeCatalog.java index d7cd087..dac871e 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/AbstractUpgradeCatalog.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/AbstractUpgradeCatalog.java @@ -584,7 +584,7 @@ public abstract class AbstractUpgradeCatalog implements UpgradeCatalog { propertiesAttributes = Collections.emptyMap(); } - controller.createConfig(cluster, configType, mergedProperties, newTag, propertiesAttributes); + controller.createConfig(cluster, cluster.getDesiredStackVersion(), configType, mergedProperties, newTag, propertiesAttributes); Config baseConfig = cluster.getConfig(configType, newTag); if (baseConfig != null) { http://git-wip-us.apache.org/repos/asf/ambari/blob/efe88a49/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/ExecutionCommandWrapperTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/ExecutionCommandWrapperTest.java b/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/ExecutionCommandWrapperTest.java index 87721e4..7630c55 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/ExecutionCommandWrapperTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/ExecutionCommandWrapperTest.java @@ -110,7 +110,8 @@ public class ExecutionCommandWrapperTest { clusters = injector.getInstance(Clusters.class); clusters.addHost(HOST1); - clusters.addCluster(CLUSTER1, new StackId("HDP-0.1")); + StackId stackId = new StackId("HDP-0.1"); + clusters.addCluster(CLUSTER1, stackId); Cluster cluster1 = clusters.getCluster(CLUSTER1); @@ -139,19 +140,19 @@ public class ExecutionCommandWrapperTest { CONFIG_ATTRIBUTES = new HashMap<>(); //Cluster level global config - configFactory.createNew(cluster1, GLOBAL_CONFIG, CLUSTER_VERSION_TAG, GLOBAL_CLUSTER, + configFactory.createNew(stackId, cluster1, GLOBAL_CONFIG, CLUSTER_VERSION_TAG, GLOBAL_CLUSTER, CONFIG_ATTRIBUTES); //Cluster level service config - configFactory.createNew(cluster1, SERVICE_SITE_CONFIG, CLUSTER_VERSION_TAG, + configFactory.createNew(stackId, cluster1, SERVICE_SITE_CONFIG, CLUSTER_VERSION_TAG, SERVICE_SITE_CLUSTER, CONFIG_ATTRIBUTES); //Service level service config - configFactory.createNew(cluster1, SERVICE_SITE_CONFIG, SERVICE_VERSION_TAG, + configFactory.createNew(stackId, cluster1, SERVICE_SITE_CONFIG, SERVICE_VERSION_TAG, SERVICE_SITE_SERVICE, CONFIG_ATTRIBUTES); //Host level service config - configFactory.createNew(cluster1, SERVICE_SITE_CONFIG, HOST_VERSION_TAG, SERVICE_SITE_HOST, + configFactory.createNew(stackId, cluster1, SERVICE_SITE_CONFIG, HOST_VERSION_TAG, SERVICE_SITE_HOST, CONFIG_ATTRIBUTES); ActionDBAccessor db = injector.getInstance(ActionDBAccessorImpl.class); http://git-wip-us.apache.org/repos/asf/ambari/blob/efe88a49/ambari-server/src/test/java/org/apache/ambari/server/agent/HeartbeatTestHelper.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/agent/HeartbeatTestHelper.java b/ambari-server/src/test/java/org/apache/ambari/server/agent/HeartbeatTestHelper.java index 76f4bb3..c1b6c14 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/agent/HeartbeatTestHelper.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/agent/HeartbeatTestHelper.java @@ -192,7 +192,7 @@ public class HeartbeatTestHelper { cluster.setCurrentStackVersion(stackId); ConfigFactory cf = injector.getInstance(ConfigFactory.class); - Config config = cf.createNew(cluster, "cluster-env", "version1", configProperties, new HashMap<String, Map<String, String>>()); + Config config = cf.createNew(stackId, cluster, "cluster-env", "version1", configProperties, new HashMap<String, Map<String, String>>()); cluster.addDesiredConfig("user", Collections.singleton(config)); http://git-wip-us.apache.org/repos/asf/ambari/blob/efe88a49/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatMonitor.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatMonitor.java b/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatMonitor.java index 088ec8d..28d51d3 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatMonitor.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatMonitor.java @@ -167,7 +167,7 @@ public class TestHeartbeatMonitor { }}; ConfigFactory configFactory = injector.getInstance(ConfigFactory.class); - Config config = configFactory.createNew(cluster, "hadoop-env", "version1", + Config config = configFactory.createNew(stackId, cluster, "hadoop-env", "version1", new HashMap<String,String>() {{ put("a", "b"); }}, new HashMap<String, Map<String,String>>()); cluster.addDesiredConfig("_test", Collections.singleton(config)); @@ -260,13 +260,13 @@ public class TestHeartbeatMonitor { }}; ConfigFactory configFactory = injector.getInstance(ConfigFactory.class); - Config hadoopEnvConfig = configFactory.createNew(cluster, "hadoop-env", "version1", + Config hadoopEnvConfig = configFactory.createNew(stackId, cluster, "hadoop-env", "version1", new HashMap<String, String>() {{ put("a", "b"); }}, new HashMap<String, Map<String,String>>()); - Config hbaseEnvConfig = configFactory.createNew(cluster, "hbase-env", "version1", + Config hbaseEnvConfig = configFactory.createNew(stackId, cluster, "hbase-env", "version1", new HashMap<String, String>() {{ put("a", "b"); }}, new HashMap<String, Map<String,String>>()); http://git-wip-us.apache.org/repos/asf/ambari/blob/efe88a49/ambari-server/src/test/java/org/apache/ambari/server/upgrade/AbstractUpgradeCatalogTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/AbstractUpgradeCatalogTest.java b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/AbstractUpgradeCatalogTest.java index 96ccc57..eaa7522 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/AbstractUpgradeCatalogTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/AbstractUpgradeCatalogTest.java @@ -17,6 +17,7 @@ */ package org.apache.ambari.server.upgrade; +import static org.easymock.EasyMock.anyObject; import static org.easymock.EasyMock.anyString; import static org.easymock.EasyMock.createNiceMock; import static org.easymock.EasyMock.createStrictMock; @@ -41,6 +42,7 @@ import org.apache.ambari.server.state.PropertyInfo; import org.apache.ambari.server.state.PropertyUpgradeBehavior; import org.apache.ambari.server.state.Service; import org.apache.ambari.server.state.ServiceInfo; +import org.apache.ambari.server.state.StackId; import org.junit.Before; import org.junit.Test; @@ -129,7 +131,7 @@ public class AbstractUpgradeCatalogTest { mergedProperties.put("prop1", "v1-old"); mergedProperties.put("prop4", "v4"); - expect(amc.createConfig(eq(cluster), eq("hdfs-site"), eq(mergedProperties), anyString(), eq(tags))).andReturn(null); + expect(amc.createConfig(eq(cluster), anyObject(StackId.class), eq("hdfs-site"), eq(mergedProperties), anyString(), eq(tags))).andReturn(null); replay(injector, configHelper, amc, cluster, clusters, serviceInfo, oldConfig); @@ -151,7 +153,7 @@ public class AbstractUpgradeCatalogTest { mergedProperties.put("prop2", "v2"); mergedProperties.put("prop3", "v3-old"); - expect(amc.createConfig(eq(cluster), eq("hdfs-site"), eq(mergedProperties), anyString(), eq(tags))).andReturn(null); + expect(amc.createConfig(eq(cluster), anyObject(StackId.class), eq("hdfs-site"), eq(mergedProperties), anyString(), eq(tags))).andReturn(null); replay(injector, configHelper, amc, cluster, clusters, serviceInfo, oldConfig); @@ -170,7 +172,7 @@ public class AbstractUpgradeCatalogTest { Map<String, String> mergedProperties = new HashMap<>(); mergedProperties.put("prop1", "v1-old"); - expect(amc.createConfig(eq(cluster), eq("hdfs-site"), eq(mergedProperties), anyString(), eq(tags))).andReturn(null); + expect(amc.createConfig(eq(cluster), anyObject(StackId.class), eq("hdfs-site"), eq(mergedProperties), anyString(), eq(tags))).andReturn(null); replay(injector, configHelper, amc, cluster, clusters, serviceInfo, oldConfig); http://git-wip-us.apache.org/repos/asf/ambari/blob/efe88a49/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog250Test.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog250Test.java b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog250Test.java index 2590d1c..1a3a0d1 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog250Test.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog250Test.java @@ -18,21 +18,35 @@ package org.apache.ambari.server.upgrade; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Maps; -import com.google.gson.Gson; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; -import com.google.gson.JsonPrimitive; -import com.google.inject.AbstractModule; -import com.google.inject.Binder; -import com.google.inject.Guice; -import com.google.inject.Injector; -import com.google.inject.Module; -import com.google.inject.Provider; +import static org.easymock.EasyMock.anyObject; +import static org.easymock.EasyMock.anyString; +import static org.easymock.EasyMock.capture; +import static org.easymock.EasyMock.createMockBuilder; +import static org.easymock.EasyMock.createNiceMock; +import static org.easymock.EasyMock.eq; +import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.expectLastCall; +import static org.easymock.EasyMock.newCapture; +import static org.easymock.EasyMock.replay; +import static org.easymock.EasyMock.reset; +import static org.easymock.EasyMock.verify; +import static org.junit.Assert.assertTrue; -import junit.framework.Assert; -import junit.framework.AssertionFailedError; +import java.io.File; +import java.lang.reflect.Method; +import java.net.URL; +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import javax.persistence.EntityManager; import org.apache.ambari.server.AmbariException; import org.apache.ambari.server.actionmanager.ActionManager; @@ -56,6 +70,7 @@ 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.Service; +import org.apache.ambari.server.state.StackId; import org.apache.ambari.server.state.kerberos.AbstractKerberosDescriptorContainer; import org.apache.ambari.server.state.kerberos.KerberosComponentDescriptor; import org.apache.ambari.server.state.kerberos.KerberosDescriptor; @@ -77,36 +92,21 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import javax.persistence.EntityManager; - -import java.io.File; -import java.lang.reflect.Method; -import java.net.URL; -import java.sql.Connection; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Statement; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Maps; +import com.google.gson.Gson; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import com.google.gson.JsonPrimitive; +import com.google.inject.AbstractModule; +import com.google.inject.Binder; +import com.google.inject.Guice; +import com.google.inject.Injector; +import com.google.inject.Module; +import com.google.inject.Provider; -import static org.easymock.EasyMock.anyObject; -import static org.easymock.EasyMock.anyString; -import static org.easymock.EasyMock.capture; -import static org.easymock.EasyMock.createMockBuilder; -import static org.easymock.EasyMock.createNiceMock; -import static org.easymock.EasyMock.eq; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.expectLastCall; -import static org.easymock.EasyMock.newCapture; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.reset; -import static org.easymock.EasyMock.verify; -import static org.junit.Assert.assertTrue; +import junit.framework.Assert; +import junit.framework.AssertionFailedError; /** * {@link UpgradeCatalog250} unit tests. @@ -737,7 +737,7 @@ public class UpgradeCatalog250Test { expect(injector2.getInstance(AmbariManagementController.class)).andReturn(controller).anyTimes(); expect(controller.getClusters()).andReturn(clusters).anyTimes(); - expect(controller.createConfig(anyObject(Cluster.class), anyString(), capture(propertiesCapture), anyString(), + expect(controller.createConfig(anyObject(Cluster.class), anyObject(StackId.class), anyString(), capture(propertiesCapture), anyString(), EasyMock.<Map<String, Map<String, String>>>anyObject())).andReturn(config).once(); replay(controller, injector2); @@ -824,7 +824,7 @@ public class UpgradeCatalog250Test { expect(injector2.getInstance(AmbariManagementController.class)).andReturn(controller).anyTimes(); expect(controller.getClusters()).andReturn(clusters).anyTimes(); - expect(controller.createConfig(anyObject(Cluster.class), anyString(), capture(propertiesCapture), anyString(), + expect(controller.createConfig(anyObject(Cluster.class), anyObject(StackId.class), anyString(), capture(propertiesCapture), anyString(), EasyMock.<Map<String, Map<String, String>>>anyObject())).andReturn(config).once(); replay(controller, injector2); @@ -905,7 +905,7 @@ public class UpgradeCatalog250Test { expect(injector2.getInstance(AmbariManagementController.class)).andReturn(controller).anyTimes(); expect(controller.getClusters()).andReturn(clusters).anyTimes(); - expect(controller.createConfig(anyObject(Cluster.class), anyString(), capture(propertiesCapture), anyString(), + expect(controller.createConfig(anyObject(Cluster.class), anyObject(StackId.class), anyString(), capture(propertiesCapture), anyString(), EasyMock.<Map<String, Map<String, String>>>anyObject())).andReturn(config).times(2); replay(controller, injector2); @@ -959,7 +959,7 @@ public class UpgradeCatalog250Test { expect(injector2.getInstance(AmbariManagementController.class)).andReturn(controller).anyTimes(); expect(controller.getClusters()).andReturn(clusters).anyTimes(); - expect(controller.createConfig(anyObject(Cluster.class), anyString(), capture(propertiesCapture), anyString(), + expect(controller.createConfig(anyObject(Cluster.class), anyObject(StackId.class), anyString(), capture(propertiesCapture), anyString(), EasyMock.<Map<String, Map<String, String>>>anyObject())).andReturn(config).once(); replay(controller, injector2); @@ -1064,7 +1064,7 @@ public class UpgradeCatalog250Test { expect(cluster.getDesiredConfigByType("ams-log4j")).andReturn(mockAmsLog4j).atLeastOnce(); expect(mockAmsLog4j.getProperties()).andReturn(oldAmsLog4j).anyTimes(); Capture<Map<String, String>> AmsLog4jCapture = EasyMock.newCapture(); - expect(controller.createConfig(anyObject(Cluster.class), anyString(), capture(AmsLog4jCapture), anyString(), + expect(controller.createConfig(anyObject(Cluster.class), anyObject(StackId.class), anyString(), capture(AmsLog4jCapture), anyString(), anyObject(Map.class))).andReturn(config).once(); Map<String, String> oldAmsHbaseLog4j = ImmutableMap.of( @@ -1179,7 +1179,7 @@ public class UpgradeCatalog250Test { "# log4j.logger.org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation=INFO\n" + "# log4j.logger.org.apache.hadoop.hbase.client.MetaScanner=INFO\n"); - Map<String, String> expectedAmsHbaseLog4j = new HashMap<String, String>(); + Map<String, String> expectedAmsHbaseLog4j = new HashMap<>(); expectedAmsHbaseLog4j.put("content", "# Licensed to the Apache Software Foundation (ASF) under one\n" + "# or more contributor license agreements. See the NOTICE file\n" + "# distributed with this work for additional information\n" + @@ -1299,7 +1299,7 @@ public class UpgradeCatalog250Test { expect(cluster.getDesiredConfigByType("ams-hbase-log4j")).andReturn(mockAmsHbaseLog4j).atLeastOnce(); expect(mockAmsHbaseLog4j.getProperties()).andReturn(oldAmsHbaseLog4j).anyTimes(); Capture<Map<String, String>> AmsHbaseLog4jCapture = EasyMock.newCapture(); - expect(controller.createConfig(anyObject(Cluster.class), anyString(), capture(AmsHbaseLog4jCapture), anyString(), + expect(controller.createConfig(anyObject(Cluster.class), anyObject(StackId.class), anyString(), capture(AmsHbaseLog4jCapture), anyString(), anyObject(Map.class))).andReturn(config).once(); replay(clusters, cluster); @@ -1348,7 +1348,7 @@ public class UpgradeCatalog250Test { expect(cluster.getDesiredConfigByType("logsearch-properties")).andReturn(mockLogSearchProperties).atLeastOnce(); expect(mockLogSearchProperties.getProperties()).andReturn(oldLogSearchProperties).anyTimes(); Capture<Map<String, String>> logSearchPropertiesCapture = EasyMock.newCapture(); - expect(controller.createConfig(anyObject(Cluster.class), anyString(), capture(logSearchPropertiesCapture), anyString(), + expect(controller.createConfig(anyObject(Cluster.class), anyObject(StackId.class), anyString(), capture(logSearchPropertiesCapture), anyString(), EasyMock.<Map<String, Map<String, String>>>anyObject())).andReturn(config).once(); Map<String, String> oldLogFeederEnv = ImmutableMap.of( @@ -1361,7 +1361,7 @@ public class UpgradeCatalog250Test { expect(cluster.getDesiredConfigByType("logfeeder-env")).andReturn(mockLogFeederEnv).atLeastOnce(); expect(mockLogFeederEnv.getProperties()).andReturn(oldLogFeederEnv).anyTimes(); Capture<Map<String, String>> logFeederEnvCapture = EasyMock.newCapture(); - expect(controller.createConfig(anyObject(Cluster.class), anyString(), capture(logFeederEnvCapture), anyString(), + expect(controller.createConfig(anyObject(Cluster.class), anyObject(StackId.class), anyString(), capture(logFeederEnvCapture), anyString(), EasyMock.<Map<String, Map<String, String>>>anyObject())).andReturn(config).once(); Map<String, String> oldLogSearchEnv = new HashMap<>(); @@ -1383,7 +1383,7 @@ public class UpgradeCatalog250Test { expect(cluster.getDesiredConfigByType("logsearch-env")).andReturn(mockLogSearchEnv).atLeastOnce(); expect(mockLogSearchEnv.getProperties()).andReturn(oldLogSearchEnv).anyTimes(); Capture<Map<String, String>> logSearchEnvCapture = EasyMock.newCapture(); - expect(controller.createConfig(anyObject(Cluster.class), anyString(), capture(logSearchEnvCapture), anyString(), + expect(controller.createConfig(anyObject(Cluster.class), anyObject(StackId.class), anyString(), capture(logSearchEnvCapture), anyString(), EasyMock.<Map<String, Map<String, String>>>anyObject())).andReturn(config).once(); Map<String, String> oldLogFeederLog4j = ImmutableMap.of( @@ -1436,7 +1436,7 @@ public class UpgradeCatalog250Test { expect(cluster.getDesiredConfigByType("logfeeder-log4j")).andReturn(mockLogFeederLog4j).atLeastOnce(); expect(mockLogFeederLog4j.getProperties()).andReturn(oldLogFeederLog4j).anyTimes(); Capture<Map<String, String>> logFeederLog4jCapture = EasyMock.newCapture(); - expect(controller.createConfig(anyObject(Cluster.class), anyString(), capture(logFeederLog4jCapture), anyString(), + expect(controller.createConfig(anyObject(Cluster.class), anyObject(StackId.class), anyString(), capture(logFeederLog4jCapture), anyString(), EasyMock.<Map<String, Map<String, String>>>anyObject())).andReturn(config).once(); Map<String, String> oldLogSearchLog4j = ImmutableMap.of( @@ -1554,7 +1554,7 @@ public class UpgradeCatalog250Test { expect(cluster.getDesiredConfigByType("logsearch-log4j")).andReturn(mockLogSearchLog4j).atLeastOnce(); expect(mockLogSearchLog4j.getProperties()).andReturn(oldLogSearchLog4j).anyTimes(); Capture<Map<String, String>> logSearchLog4jCapture = EasyMock.newCapture(); - expect(controller.createConfig(anyObject(Cluster.class), anyString(), capture(logSearchLog4jCapture), anyString(), + expect(controller.createConfig(anyObject(Cluster.class), anyObject(StackId.class), anyString(), capture(logSearchLog4jCapture), anyString(), EasyMock.<Map<String, Map<String, String>>>anyObject())).andReturn(config).once(); replay(clusters, cluster); @@ -1613,7 +1613,7 @@ public class UpgradeCatalog250Test { expect(cluster.getDesiredConfigByType("infra-solr-env")).andReturn(mockInfraSolrEnv).atLeastOnce(); expect(mockInfraSolrEnv.getProperties()).andReturn(oldInfraSolrEnv).anyTimes(); Capture<Map<String, String>> infraSolrEnvCapture = EasyMock.newCapture(); - expect(controller.createConfig(anyObject(Cluster.class), anyString(), capture(infraSolrEnvCapture), anyString(), + expect(controller.createConfig(anyObject(Cluster.class), anyObject(StackId.class), anyString(), capture(infraSolrEnvCapture), anyString(), EasyMock.<Map<String, Map<String, String>>>anyObject())).andReturn(config).once(); Map<String, String> oldInfraSolrLog4j = ImmutableMap.of( @@ -1630,7 +1630,7 @@ public class UpgradeCatalog250Test { expect(cluster.getDesiredConfigByType("infra-solr-log4j")).andReturn(mockInfraSolrLog4j).atLeastOnce(); expect(mockInfraSolrLog4j.getProperties()).andReturn(oldInfraSolrLog4j).anyTimes(); Capture<Map<String, String>> infraSolrLog4jCapture = EasyMock.newCapture(); - expect(controller.createConfig(anyObject(Cluster.class), anyString(), capture(infraSolrLog4jCapture), anyString(), + expect(controller.createConfig(anyObject(Cluster.class), anyObject(StackId.class), anyString(), capture(infraSolrLog4jCapture), anyString(), EasyMock.<Map<String, Map<String, String>>>anyObject())).andReturn(config).once(); Map<String, String> oldInfraSolrClientLog4j = ImmutableMap.of( @@ -1649,7 +1649,7 @@ public class UpgradeCatalog250Test { expect(cluster.getDesiredConfigByType("infra-solr-client-log4j")).andReturn(mockInfraSolrClientLog4j).atLeastOnce(); expect(mockInfraSolrClientLog4j.getProperties()).andReturn(oldInfraSolrClientLog4j).anyTimes(); Capture<Map<String, String>> infraSolrClientLog4jCapture = EasyMock.newCapture(); - expect(controller.createConfig(anyObject(Cluster.class), anyString(), capture(infraSolrClientLog4jCapture), anyString(), + expect(controller.createConfig(anyObject(Cluster.class), anyObject(StackId.class), anyString(), capture(infraSolrClientLog4jCapture), anyString(), EasyMock.<Map<String, Map<String, String>>>anyObject())).andReturn(config).once(); replay(clusters, cluster); @@ -1708,7 +1708,7 @@ public class UpgradeCatalog250Test { expect(cluster.getDesiredConfigByType("hive-interactive-env")).andReturn(mockHsiEnv).atLeastOnce(); expect(mockHsiEnv.getProperties()).andReturn(oldHsiEnv).anyTimes(); Capture<Map<String, String>> hsiEnvCapture = EasyMock.newCapture(); - expect(controller.createConfig(anyObject(Cluster.class), anyString(), capture(hsiEnvCapture), anyString(), + expect(controller.createConfig(anyObject(Cluster.class), anyObject(StackId.class), anyString(), capture(hsiEnvCapture), anyString(), EasyMock.<Map<String, Map<String, String>>>anyObject())).andReturn(config).once(); replay(clusters, cluster); @@ -1724,27 +1724,27 @@ public class UpgradeCatalog250Test { @Test public void testUpdateAtlasConfigs() throws Exception { - Map<String, String> oldHiveProperties = new HashMap<String, String>(); - Map<String, String> newHiveProperties = new HashMap<String, String>(); + Map<String, String> oldHiveProperties = new HashMap<>(); + Map<String, String> newHiveProperties = new HashMap<>(); oldHiveProperties.put("hive.atlas.hook", "false"); newHiveProperties.put("hive.atlas.hook", "true"); testUpdateAtlasHookConfig(oldHiveProperties, newHiveProperties, "hive-env"); - Map<String, String> oldStormProperties = new HashMap<String, String>(); - Map<String, String> newStormProperties = new HashMap<String, String>(); + Map<String, String> oldStormProperties = new HashMap<>(); + Map<String, String> newStormProperties = new HashMap<>(); oldStormProperties.put("storm.atlas.hook", "false"); newStormProperties.put("storm.atlas.hook", "true"); testUpdateAtlasHookConfig(oldStormProperties, newStormProperties, "storm-env"); - Map<String, String> oldFalconProperties = new HashMap<String, String>(); - Map<String, String> newFalconProperties = new HashMap<String, String>(); + Map<String, String> oldFalconProperties = new HashMap<>(); + Map<String, String> newFalconProperties = new HashMap<>(); oldFalconProperties.put("falcon.atlas.hook", "false"); newFalconProperties.put("falcon.atlas.hook", "true"); testUpdateAtlasHookConfig(oldFalconProperties, newFalconProperties, "falcon-env"); - Map<String, String> oldSqoopProperties = new HashMap<String, String>(); - Map<String, String> newSqoopProperties = new HashMap<String, String>(); + Map<String, String> oldSqoopProperties = new HashMap<>(); + Map<String, String> newSqoopProperties = new HashMap<>(); oldSqoopProperties.put("sqoop.atlas.hook", "false"); newSqoopProperties.put("sqoop.atlas.hook", "true"); testUpdateAtlasHookConfig(oldSqoopProperties, newSqoopProperties, "sqoop-env"); @@ -1789,7 +1789,7 @@ public class UpgradeCatalog250Test { expect(injector2.getInstance(AmbariManagementController.class)).andReturn(controller).anyTimes(); expect(controller.getClusters()).andReturn(clusters).anyTimes(); - expect(controller.createConfig(anyObject(Cluster.class), anyString(), capture(propertiesCapture), anyString(), + expect(controller.createConfig(anyObject(Cluster.class), anyObject(StackId.class), anyString(), capture(propertiesCapture), anyString(), EasyMock.<Map<String, Map<String, String>>>anyObject())).andReturn(config).once(); replay(controller, injector2); @@ -1985,56 +1985,56 @@ public class UpgradeCatalog250Test { @Test public void testUpdateRangerUrlConfigs() throws Exception { - Map<String, String> oldHdfsProperties = new HashMap<String, String>(); - Map<String, String> newHdfsProperties = new HashMap<String, String>(); + Map<String, String> oldHdfsProperties = new HashMap<>(); + Map<String, String> newHdfsProperties = new HashMap<>(); oldHdfsProperties.put("ranger.plugin.hdfs.policy.rest.url", "{{policymgr_mgr_url}}"); newHdfsProperties.put("ranger.plugin.hdfs.policy.rest.url", "http://localhost:6080"); testUpdateRangerUrl(oldHdfsProperties, newHdfsProperties, "ranger-hdfs-security"); - Map<String, String> oldHiveProperties = new HashMap<String, String>(); - Map<String, String> newHiveProperties = new HashMap<String, String>(); + Map<String, String> oldHiveProperties = new HashMap<>(); + Map<String, String> newHiveProperties = new HashMap<>(); oldHiveProperties.put("ranger.plugin.hive.policy.rest.url", "{{policymgr_mgr_url}}"); newHiveProperties.put("ranger.plugin.hive.policy.rest.url", "http://localhost:6080"); testUpdateRangerUrl(oldHiveProperties, newHiveProperties, "ranger-hive-security"); - Map<String, String> oldHbaseProperties = new HashMap<String, String>(); - Map<String, String> newHbaseProperties = new HashMap<String, String>(); + Map<String, String> oldHbaseProperties = new HashMap<>(); + Map<String, String> newHbaseProperties = new HashMap<>(); oldHbaseProperties.put("ranger.plugin.hbase.policy.rest.url", "{{policymgr_mgr_url}}"); newHbaseProperties.put("ranger.plugin.hbase.policy.rest.url", "http://localhost:6080"); testUpdateRangerUrl(oldHbaseProperties, newHbaseProperties, "ranger-hbase-security"); - Map<String, String> oldKnoxProperties = new HashMap<String, String>(); - Map<String, String> newKnoxProperties = new HashMap<String, String>(); + Map<String, String> oldKnoxProperties = new HashMap<>(); + Map<String, String> newKnoxProperties = new HashMap<>(); oldKnoxProperties.put("ranger.plugin.knox.policy.rest.url", "{{policymgr_mgr_url}}"); newKnoxProperties.put("ranger.plugin.knox.policy.rest.url", "http://localhost:6080"); testUpdateRangerUrl(oldKnoxProperties, newKnoxProperties, "ranger-knox-security"); - Map<String, String> oldStormProperties = new HashMap<String, String>(); - Map<String, String> newStormProperties = new HashMap<String, String>(); + Map<String, String> oldStormProperties = new HashMap<>(); + Map<String, String> newStormProperties = new HashMap<>(); oldStormProperties.put("ranger.plugin.storm.policy.rest.url", "{{policymgr_mgr_url}}"); newStormProperties.put("ranger.plugin.storm.policy.rest.url", "http://localhost:6080"); testUpdateRangerUrl(oldStormProperties, newStormProperties, "ranger-storm-security"); - Map<String, String> oldYarnProperties = new HashMap<String, String>(); - Map<String, String> newYarnProperties = new HashMap<String, String>(); + Map<String, String> oldYarnProperties = new HashMap<>(); + Map<String, String> newYarnProperties = new HashMap<>(); oldYarnProperties.put("ranger.plugin.yarn.policy.rest.url", "{{policymgr_mgr_url}}"); newYarnProperties.put("ranger.plugin.yarn.policy.rest.url", "http://localhost:6080"); testUpdateRangerUrl(oldYarnProperties, newYarnProperties, "ranger-yarn-security"); - Map<String, String> oldKafkaProperties = new HashMap<String, String>(); - Map<String, String> newKafkaProperties = new HashMap<String, String>(); + Map<String, String> oldKafkaProperties = new HashMap<>(); + Map<String, String> newKafkaProperties = new HashMap<>(); oldKafkaProperties.put("ranger.plugin.kafka.policy.rest.url", "{{policymgr_mgr_url}}"); newKafkaProperties.put("ranger.plugin.kafka.policy.rest.url", "http://localhost:6080"); testUpdateRangerUrl(oldKafkaProperties, newKafkaProperties, "ranger-kafka-security"); - Map<String, String> oldAtlasProperties = new HashMap<String, String>(); - Map<String, String> newAtlasProperties = new HashMap<String, String>(); + Map<String, String> oldAtlasProperties = new HashMap<>(); + Map<String, String> newAtlasProperties = new HashMap<>(); oldAtlasProperties.put("ranger.plugin.atlas.policy.rest.url", "{{policymgr_mgr_url}}"); newAtlasProperties.put("ranger.plugin.atlas.policy.rest.url", "http://localhost:6080"); testUpdateRangerUrl(oldAtlasProperties, newAtlasProperties, "ranger-atlas-security"); - Map<String, String> oldKmsProperties = new HashMap<String, String>(); - Map<String, String> newKmsProperties = new HashMap<String, String>(); + Map<String, String> oldKmsProperties = new HashMap<>(); + Map<String, String> newKmsProperties = new HashMap<>(); oldKmsProperties.put("ranger.plugin.kms.policy.rest.url", "{{policymgr_mgr_url}}"); newKmsProperties.put("ranger.plugin.kms.policy.rest.url", "http://localhost:6080"); testUpdateRangerUrl(oldKmsProperties, newKmsProperties, "ranger-kms-security"); @@ -2078,7 +2078,7 @@ public class UpgradeCatalog250Test { expect(injector2.getInstance(AmbariManagementController.class)).andReturn(controller).anyTimes(); expect(controller.getClusters()).andReturn(clusters).anyTimes(); - expect(controller.createConfig(anyObject(Cluster.class), anyString(), capture(propertiesCapture), anyString(), + expect(controller.createConfig(anyObject(Cluster.class), anyObject(StackId.class), anyString(), capture(propertiesCapture), anyString(), EasyMock.<Map<String, Map<String, String>>>anyObject())).andReturn(config).once(); replay(controller, injector2); http://git-wip-us.apache.org/repos/asf/ambari/blob/efe88a49/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog252Test.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog252Test.java b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog252Test.java index e6dbb7c..ddc8782 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog252Test.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog252Test.java @@ -54,6 +54,7 @@ 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.Service; +import org.apache.ambari.server.state.StackId; import org.apache.ambari.server.state.kerberos.KerberosComponentDescriptor; import org.apache.ambari.server.state.kerberos.KerberosDescriptor; import org.apache.ambari.server.state.kerberos.KerberosDescriptorFactory; @@ -191,6 +192,8 @@ public class UpgradeCatalog252Test { final Config livy2ConfNew = createMock(Config.class); final AmbariManagementController controller = createMock(AmbariManagementController.class); + StackId stackId = new StackId("HDP", "2.2"); + Capture<? extends Map<String, String>> captureLivyConfProperties = newCapture(); Capture<? extends Map<String, String>> captureLivy2ConfProperties = newCapture(); @@ -209,6 +212,7 @@ public class UpgradeCatalog252Test { expect(clusters.getClusters()).andReturn(Collections.singletonMap("c1", cluster)).once(); expect(cluster.getClusterName()).andReturn("c1").atLeastOnce(); + expect(cluster.getDesiredStackVersion()).andReturn(stackId).atLeastOnce(); expect(cluster.getDesiredConfigByType("zeppelin-env")).andReturn(zeppelinEnv).atLeastOnce(); expect(cluster.getServiceByConfigType("livy-conf")).andReturn("SPARK").atLeastOnce(); expect(cluster.getDesiredConfigByType("livy-conf")).andReturn(livyConf).atLeastOnce(); @@ -227,10 +231,10 @@ public class UpgradeCatalog252Test { expect(livy2Conf.getProperties()).andReturn(Collections.<String, String>emptyMap()).atLeastOnce(); expect(livy2Conf.getPropertiesAttributes()).andReturn(Collections.<String, Map<String, String>>emptyMap()).atLeastOnce(); - expect(controller.createConfig(eq(cluster), eq("livy-conf"), capture(captureLivyConfProperties), anyString(), anyObject(Map.class))) + expect(controller.createConfig(eq(cluster), eq(stackId), eq("livy-conf"), capture(captureLivyConfProperties), anyString(), anyObject(Map.class))) .andReturn(livyConfNew) .once(); - expect(controller.createConfig(eq(cluster), eq("livy2-conf"), capture(captureLivy2ConfProperties), anyString(), anyObject(Map.class))) + expect(controller.createConfig(eq(cluster), eq(stackId), eq("livy2-conf"), capture(captureLivy2ConfProperties), anyString(), anyObject(Map.class))) .andReturn(livy2ConfNew) .once(); http://git-wip-us.apache.org/repos/asf/ambari/blob/efe88a49/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog260Test.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog260Test.java b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog260Test.java index 23962b7..be04cd5 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog260Test.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog260Test.java @@ -202,7 +202,7 @@ public class UpgradeCatalog260Test { expectAddViewUrlPKConstraint(); expectRemoveStaleConstraints(); - + replay(dbAccessor, configuration, connection, statement, resultSet); Injector injector = getInjector(); @@ -588,6 +588,7 @@ public class UpgradeCatalog260Test { expect(clusters.getClusters()).andReturn(Collections.singletonMap("c1", cluster)).once(); expect(cluster.getClusterName()).andReturn("c1").atLeastOnce(); + expect(cluster.getDesiredStackVersion()).andReturn(new StackId("HDP-2.6")).atLeastOnce(); expect(cluster.getDesiredConfigByType("zeppelin-env")).andReturn(zeppelinEnvConf).atLeastOnce(); expect(cluster.getDesiredConfigByType("core-site")).andReturn(coreSiteConf).atLeastOnce(); expect(cluster.getConfigsByType("core-site")).andReturn(Collections.singletonMap("tag1", coreSiteConf)).atLeastOnce(); @@ -600,7 +601,7 @@ public class UpgradeCatalog260Test { expect(coreSiteConf.getProperties()).andReturn(Collections.singletonMap("hadoop.proxyuser.zeppelin_user.hosts", "existing_value")).atLeastOnce(); expect(coreSiteConf.getPropertiesAttributes()).andReturn(Collections.<String, Map<String, String>>emptyMap()).atLeastOnce(); - expect(controller.createConfig(eq(cluster), eq("core-site"), capture(captureCoreSiteConfProperties), anyString(), anyObject(Map.class))) + expect(controller.createConfig(eq(cluster), anyObject(StackId.class), eq("core-site"), capture(captureCoreSiteConfProperties), anyString(), anyObject(Map.class))) .andReturn(coreSiteConfNew) .once(); @@ -669,7 +670,10 @@ public class UpgradeCatalog260Test { ServiceConfigVersionResponse response = createMock(ServiceConfigVersionResponse.class); + StackId stackId = createMock(StackId.class); + Cluster cluster = createMock(Cluster.class); + expect(cluster.getDesiredStackVersion()).andReturn(stackId).atLeastOnce(); expect(cluster.getDesiredConfigByType("dbks-site")).andReturn(config).anyTimes(); expect(cluster.getDesiredConfigByType("ranger-kms-audit")).andReturn(config).anyTimes(); expect(cluster.getConfigsByType("ranger-kms-audit")).andReturn(Collections.singletonMap("version1", config)).anyTimes(); @@ -684,7 +688,7 @@ public class UpgradeCatalog260Test { Capture<? extends Map<String, String>> captureProperties = newCapture(); AmbariManagementController controller = injector.getInstance(AmbariManagementController.class); - expect(controller.createConfig(eq(cluster), eq("ranger-kms-audit"), capture(captureProperties), anyString(), anyObject(Map.class))) + expect(controller.createConfig(eq(cluster), eq(stackId), eq("ranger-kms-audit"), capture(captureProperties), anyString(), anyObject(Map.class))) .andReturn(null) .once(); @@ -764,7 +768,7 @@ public class UpgradeCatalog260Test { expect(injector2.getInstance(AmbariManagementController.class)).andReturn(controller).anyTimes(); expect(controller.getClusters()).andReturn(clusters).anyTimes(); - expect(controller.createConfig(anyObject(Cluster.class), anyString(), capture(propertiesCapture), anyString(), + expect(controller.createConfig(anyObject(Cluster.class), anyObject(StackId.class), anyString(), capture(propertiesCapture), anyString(), anyObject(Map.class))).andReturn(createNiceMock(Config.class)).once(); replay(controller, injector2);
