http://git-wip-us.apache.org/repos/asf/ambari/blob/4278c4a4/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterTest.java index 90a3d02..daa3abc 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterTest.java @@ -87,7 +87,6 @@ import org.apache.ambari.server.state.ComponentInfo; import org.apache.ambari.server.state.Config; import org.apache.ambari.server.state.ConfigFactory; import org.apache.ambari.server.state.ConfigHelper; -import org.apache.ambari.server.state.ConfigImpl; import org.apache.ambari.server.state.DesiredConfig; import org.apache.ambari.server.state.Host; import org.apache.ambari.server.state.HostHealthStatus; @@ -964,21 +963,14 @@ public class ClusterTest { Map<String, Map<String, String>> c2PropAttributes = new HashMap<String, Map<String,String>>(); c2PropAttributes.put("final", new HashMap<String, String>()); c2PropAttributes.get("final").put("x", "true"); - Config config1 = configFactory.createNew(c1, "global", + Config config1 = configFactory.createNew(c1, "global", "version1", new HashMap<String, String>() {{ put("a", "b"); }}, c1PropAttributes); - config1.setTag("version1"); - Config config2 = configFactory.createNew(c1, "global", + Config config2 = configFactory.createNew(c1, "global", "version2", new HashMap<String, String>() {{ put("x", "y"); }}, c2PropAttributes); - config2.setTag("version2"); - Config config3 = configFactory.createNew(c1, "core-site", + Config config3 = configFactory.createNew(c1, "core-site", "version2", new HashMap<String, String>() {{ put("x", "y"); }}, new HashMap<String, Map<String,String>>()); - config3.setTag("version2"); - - c1.addConfig(config1); - c1.addConfig(config2); - c1.addConfig(config3); c1.addDesiredConfig("_test", Collections.singleton(config1)); Config res = c1.getDesiredConfigByType("global"); @@ -998,21 +990,14 @@ public class ClusterTest { public void testDesiredConfigs() throws Exception { createDefaultCluster(); - Config config1 = configFactory.createNew(c1, "global", + Config config1 = configFactory.createNew(c1, "global", "version1", new HashMap<String, String>() {{ put("a", "b"); }}, new HashMap<String, Map<String,String>>()); - config1.setTag("version1"); - Config config2 = configFactory.createNew(c1, "global", + Config config2 = configFactory.createNew(c1, "global", "version2", new HashMap<String, String>() {{ put("x", "y"); }}, new HashMap<String, Map<String,String>>()); - config2.setTag("version2"); - Config config3 = configFactory.createNew(c1, "core-site", + Config config3 = configFactory.createNew(c1, "core-site", "version2", new HashMap<String, String>() {{ put("x", "y"); }}, new HashMap<String, Map<String,String>>()); - config3.setTag("version2"); - - c1.addConfig(config1); - c1.addConfig(config2); - c1.addConfig(config3); try { c1.addDesiredConfig(null, Collections.singleton(config1)); @@ -1132,18 +1117,11 @@ public class ClusterTest { c1.addService("HDFS"); - Config config1 = configFactory.createNew(c1, "hdfs-site", + Config config1 = configFactory.createNew(c1, "hdfs-site", "version1", new HashMap<String, String>() {{ put("a", "b"); }}, new HashMap<String, Map<String,String>>()); - config1.setTag("version1"); - Config config2 = configFactory.createNew(c1, "core-site", + Config config2 = configFactory.createNew(c1, "core-site", "version2", new HashMap<String, String>() {{ put("x", "y"); }}, new HashMap<String, Map<String,String>>()); - config2.setTag("version2"); - - config1.persist(); - c1.addConfig(config1); - config2.persist(); - c1.addConfig(config2); Set<Config> configs = new HashSet<Config>(); configs.add(config1); @@ -1209,10 +1187,9 @@ public class ClusterTest { Map<String, Map<String, String>> propAttributes = new HashMap<String, Map<String,String>>(); propAttributes.put("final", new HashMap<String, String>()); propAttributes.get("final").put("test", "true"); - Config config = configFactory.createNew(c1, "hdfs-site", new HashMap<String, String>(){{ + Config config = configFactory.createNew(c1, "hdfs-site", "1", new HashMap<String, String>(){{ put("test", "test"); }}, propAttributes); - config.setTag("1"); host1.addDesiredConfig(c1.getClusterId(), true, "test", config); @@ -1247,16 +1224,11 @@ public class ClusterTest { public void testServiceConfigVersions() throws Exception { createDefaultCluster(); - Config config1 = configFactory.createNew(c1, "hdfs-site", + Config config1 = configFactory.createNew(c1, "hdfs-site", "version1", new HashMap<String, String>() {{ put("a", "b"); }}, new HashMap<String, Map<String,String>>()); - config1.setTag("version1"); - Config config2 = configFactory.createNew(c1, "hdfs-site", + Config config2 = configFactory.createNew(c1, "hdfs-site", "version2", new HashMap<String, String>() {{ put("x", "y"); }}, new HashMap<String, Map<String,String>>()); - config2.setTag("version2"); - - c1.addConfig(config1); - c1.addConfig(config2); c1.addDesiredConfig("admin", Collections.singleton(config1)); List<ServiceConfigVersionResponse> serviceConfigVersions = @@ -1310,16 +1282,11 @@ public class ClusterTest { public void testSingleServiceVersionForMultipleConfigs() throws Exception { createDefaultCluster(); - Config config1 = configFactory.createNew(c1, "hdfs-site", + Config config1 = configFactory.createNew(c1, "hdfs-site", "version1", new HashMap<String, String>() {{ put("a", "b"); }}, new HashMap<String, Map<String,String>>()); - config1.setTag("version1"); - Config config2 = configFactory.createNew(c1, "core-site", + Config config2 = configFactory.createNew(c1, "core-site", "version2", new HashMap<String, String>() {{ put("x", "y"); }}, new HashMap<String, Map<String,String>>()); - config2.setTag("version2"); - - c1.addConfig(config1); - c1.addConfig(config2); Set<Config> configs = new HashSet<Config>(); configs.add(config1); @@ -1345,11 +1312,8 @@ public class ClusterTest { public void testServiceConfigVersionsForGroups() throws Exception { createDefaultCluster(); - Config config1 = configFactory.createNew(c1, "hdfs-site", + Config config1 = configFactory.createNew(c1, "hdfs-site", "version1", new HashMap<String, String>() {{ put("a", "b"); }}, new HashMap<String, Map<String,String>>()); - config1.setTag("version1"); - - c1.addConfig(config1); ServiceConfigVersionResponse scvResponse = c1.addDesiredConfig("admin", Collections.singleton(config1)); @@ -1361,16 +1325,13 @@ public class ClusterTest { Assert.assertEquals("Only one scv should be active", 1, activeServiceConfigVersions.get("HDFS").size()); //create config group - Config config2 = configFactory.createNew(c1, "hdfs-site", + Config config2 = configFactory.createNew(c1, "hdfs-site", "version2", new HashMap<String, String>() {{ put("a", "c"); }}, new HashMap<String, Map<String,String>>()); - config2.setTag("version2"); ConfigGroup configGroup = configGroupFactory.createNew(c1, "test group", "HDFS", "descr", Collections.singletonMap("hdfs-site", config2), Collections.<Long, Host>emptyMap()); - configGroup.persist(); - c1.addConfigGroup(configGroup); scvResponse = c1.createServiceConfigVersion("HDFS", "admin", "test note", configGroup); @@ -1381,12 +1342,11 @@ public class ClusterTest { Assert.assertEquals("Two service config versions should be active, for default and test groups", 2, activeServiceConfigVersions.get("HDFS").size()); - Config config3 = configFactory.createNew(c1, "hdfs-site", + Config config3 = configFactory.createNew(c1, "hdfs-site", "version3", new HashMap<String, String>() {{ put("a", "d"); }}, new HashMap<String, Map<String,String>>()); configGroup.setConfigurations(Collections.singletonMap("hdfs-site", config3)); - configGroup.persist(); scvResponse = c1.createServiceConfigVersion("HDFS", "admin", "test note", configGroup); assertEquals("SCV 3 should be created", Long.valueOf(3), scvResponse.getVersion()); @@ -1417,16 +1377,14 @@ public class ClusterTest { //check config with empty cluster - Config config4 = new ConfigImpl("hdfs-site"); - config4.setProperties(new HashMap<String, String>() {{ - put("a", "b"); - }}); + Config config4 = configFactory.createReadOnly("hdfs-site", "version4", + Collections.singletonMap("a", "b"), null); ConfigGroup configGroup2 = - configGroupFactory.createNew(c1, "test group 2", "HDFS", "descr", Collections.singletonMap("hdfs-site", config4), + configGroupFactory.createNew(c1, "test group 2", "HDFS", "descr", + new HashMap<>(Collections.singletonMap("hdfs-site", config4)), Collections.<Long, Host>emptyMap()); - configGroup2.persist(); c1.addConfigGroup(configGroup2); scvResponse = c1.createServiceConfigVersion("HDFS", "admin", "test note", configGroup2); @@ -1443,12 +1401,8 @@ public class ClusterTest { // Given createDefaultCluster(); - Config hdfsSiteConfigV1 = configFactory.createNew(c1, "hdfs-site", ImmutableMap.of("p1", "v1"), ImmutableMap.<String, Map<String,String>>of()); - hdfsSiteConfigV1.setTag("version1"); - hdfsSiteConfigV1.persist(); - - c1.addConfig(hdfsSiteConfigV1); - + Config hdfsSiteConfigV1 = configFactory.createNew(c1, "hdfs-site", "version1", + ImmutableMap.of("p1", "v1"), ImmutableMap.<String, Map<String,String>>of()); ServiceConfigVersionResponse hdfsSiteConfigResponseV1 = c1.addDesiredConfig("admin", Collections.singleton(hdfsSiteConfigV1)); List<ConfigurationResponse> configResponsesDefaultGroup = Collections.singletonList( @@ -1459,11 +1413,10 @@ public class ClusterTest { hdfsSiteConfigResponseV1.setConfigurations(configResponsesDefaultGroup); - Config hdfsSiteConfigV2 = configFactory.createNew(c1, "hdfs-site", ImmutableMap.of("p1", "v2"), ImmutableMap.<String, Map<String,String>>of()); - hdfsSiteConfigV2.setTag("version2"); + Config hdfsSiteConfigV2 = configFactory.createNew(c1, "hdfs-site", "version2", + ImmutableMap.of("p1", "v2"), ImmutableMap.<String, Map<String,String>>of()); ConfigGroup configGroup = configGroupFactory.createNew(c1, "configGroup1", "version1", "test description", ImmutableMap.of(hdfsSiteConfigV2.getType(), hdfsSiteConfigV2), ImmutableMap.<Long, Host>of()); - configGroup.persist(); c1.addConfigGroup(configGroup); ServiceConfigVersionResponse hdfsSiteConfigResponseV2 = c1.createServiceConfigVersion("HDFS", "admin", "test note", configGroup); @@ -1507,12 +1460,8 @@ public class ClusterTest { // Given createDefaultCluster(); - Config hdfsSiteConfigV1 = configFactory.createNew(c1, "hdfs-site", ImmutableMap.of("p1", "v1"), ImmutableMap.<String, Map<String,String>>of()); - hdfsSiteConfigV1.setTag("version1"); - hdfsSiteConfigV1.persist(); - - c1.addConfig(hdfsSiteConfigV1); - + Config hdfsSiteConfigV1 = configFactory.createNew(c1, "hdfs-site", "version1", + ImmutableMap.of("p1", "v1"), ImmutableMap.<String, Map<String,String>>of()); ServiceConfigVersionResponse hdfsSiteConfigResponseV1 = c1.addDesiredConfig("admin", Collections.singleton(hdfsSiteConfigV1)); List<ConfigurationResponse> configResponsesDefaultGroup = Collections.singletonList( @@ -1523,11 +1472,10 @@ public class ClusterTest { hdfsSiteConfigResponseV1.setConfigurations(configResponsesDefaultGroup); - Config hdfsSiteConfigV2 = configFactory.createNew(c1, "hdfs-site", ImmutableMap.of("p1", "v2"), ImmutableMap.<String, Map<String,String>>of()); - hdfsSiteConfigV2.setTag("version2"); + Config hdfsSiteConfigV2 = configFactory.createNew(c1, "hdfs-site", "version2", + ImmutableMap.of("p1", "v2"), ImmutableMap.<String, Map<String,String>>of()); ConfigGroup configGroup = configGroupFactory.createNew(c1, "configGroup1", "version1", "test description", ImmutableMap.of(hdfsSiteConfigV2.getType(), hdfsSiteConfigV2), ImmutableMap.<Long, Host>of()); - configGroup.persist(); c1.addConfigGroup(configGroup); ServiceConfigVersionResponse hdfsSiteConfigResponseV2 = c1.createServiceConfigVersion("HDFS", "admin", "test note", configGroup); @@ -2373,17 +2321,13 @@ public class ClusterTest { ClusterEntity clusterEntity = clusterDAO.findByName("c1"); assertEquals(0, clusterEntity.getClusterConfigEntities().size()); - final Config originalConfig = configFactory.createNew(cluster, "foo-site", + final Config originalConfig = configFactory.createNew(cluster, "foo-site", "version3", new HashMap<String, String>() { { put("one", "two"); } }, new HashMap<String, Map<String, String>>()); - originalConfig.setTag("version3"); - originalConfig.persist(); - cluster.addConfig(originalConfig); - ConfigGroup configGroup = configGroupFactory.createNew(cluster, "g1", "t1", "", new HashMap<String, Config>() { { @@ -2391,7 +2335,6 @@ public class ClusterTest { } }, Collections.<Long, Host> emptyMap()); - configGroup.persist(); cluster.addConfigGroup(configGroup); clusterEntity = clusterDAO.findByName("c1"); @@ -2403,8 +2346,7 @@ public class ClusterTest { Map<String, String> properties = config.getProperties(); properties.put("three", "four"); config.setProperties(properties); - - config.persist(false); + config.save(); clusterEntity = clusterDAO.findByName("c1"); assertEquals(1, clusterEntity.getClusterConfigEntities().size()); @@ -2525,6 +2467,101 @@ public class ClusterTest { } /** + * Tests that {@link Cluster#applyLatestConfigurations(StackId)} sets the + * right configs to enabled when there are duplicate mappings for type/tag. + * Only the most recent should be enabled. + * + * @throws Exception + */ + @Test + public void testApplyLatestConfigurationsWithMultipleMappings() throws Exception { + createDefaultCluster(); + Cluster cluster = clusters.getCluster("c1"); + ClusterEntity clusterEntity = clusterDAO.findByName("c1"); + StackId stackId = cluster.getCurrentStackVersion(); + + StackEntity currentStack = stackDAO.find(stackId.getStackName(), stackId.getStackVersion()); + + String configType = "foo-type"; + String configTag = "version-1"; + + // create the config for the mappings + ClusterConfigEntity clusterConfig = new ClusterConfigEntity(); + clusterConfig.setClusterEntity(clusterEntity); + clusterConfig.setConfigId(1L); + clusterConfig.setStack(currentStack); + clusterConfig.setTag(configTag); + clusterConfig.setData("{}"); + clusterConfig.setType(configType); + clusterConfig.setTimestamp(1L); + clusterConfig.setVersion(1L); + + clusterDAO.createConfig(clusterConfig); + clusterEntity.getClusterConfigEntities().add(clusterConfig); + clusterEntity = clusterDAO.merge(clusterEntity); + + // create 3 mappings for the same type/tag, each with a different time + + // config mapping 1 + ClusterConfigMappingEntity configMapping = new ClusterConfigMappingEntity(); + configMapping.setClusterEntity(clusterEntity); + configMapping.setCreateTimestamp(1L); + configMapping.setSelected(0); + configMapping.setTag(configTag); + configMapping.setType(configType); + configMapping.setUser("admin"); + clusterDAO.persistConfigMapping(configMapping); + clusterEntity.getConfigMappingEntities().add(configMapping); + + // config mapping 2 + configMapping = new ClusterConfigMappingEntity(); + configMapping.setClusterEntity(clusterEntity); + configMapping.setCreateTimestamp(2L); + configMapping.setSelected(0); + configMapping.setTag(configTag); + configMapping.setType(configType); + configMapping.setUser("admin"); + clusterDAO.persistConfigMapping(configMapping); + clusterEntity.getConfigMappingEntities().add(configMapping); + + // config mapping 3 + configMapping = new ClusterConfigMappingEntity(); + configMapping.setClusterEntity(clusterEntity); + configMapping.setCreateTimestamp(3L); + configMapping.setSelected(0); + configMapping.setTag(configTag); + configMapping.setType(configType); + configMapping.setUser("admin"); + clusterDAO.persistConfigMapping(configMapping); + clusterEntity.getConfigMappingEntities().add(configMapping); + + clusterEntity = clusterDAO.merge(clusterEntity); + + // check all 3 mappings are disabled + Collection<ClusterConfigMappingEntity> clusterConfigMappings = clusterEntity.getConfigMappingEntities(); + Assert.assertEquals(3, clusterConfigMappings.size()); + for (ClusterConfigMappingEntity clusterConfigMapping : clusterConfigMappings) { + Assert.assertEquals(0, clusterConfigMapping.isSelected()); + } + + // apply configurations and check to see we've set the one with the latest + // timestamp ONLY + cluster.applyLatestConfigurations(cluster.getCurrentStackVersion()); + clusterEntity = clusterDAO.findByName("c1"); + + // now check that the new config mapping is enabled + clusterConfigMappings = clusterEntity.getConfigMappingEntities(); + Assert.assertEquals(3, clusterConfigMappings.size()); + for (ClusterConfigMappingEntity clusterConfigMapping : clusterConfigMappings) { + if (clusterConfigMapping.getCreateTimestamp() < 3) { + Assert.assertEquals(0, clusterConfigMapping.isSelected()); + } else { + Assert.assertEquals(1, clusterConfigMapping.isSelected()); + } + } + } + + /** * Tests that applying configurations for a given stack correctly sets * {@link DesiredConfig}s. */ @@ -2545,13 +2582,7 @@ public class ClusterTest { // foo-type for v1 on current stack properties.put("foo-property-1", "foo-value-1"); - Config c1 = new ConfigImpl(cluster, "foo-type", properties, propertiesAttributes, injector); - c1.setTag("version-1"); - c1.setStackId(stackId); - c1.setVersion(1L); - - cluster.addConfig(c1); - c1.persist(); + Config c1 = configFactory.createNew(cluster, "foo-type", "version-1", properties, propertiesAttributes); // make v1 "current" cluster.addDesiredConfig("admin", Sets.newHashSet(c1), "note-1"); @@ -2562,12 +2593,7 @@ public class ClusterTest { // save v2 // foo-type for v2 on new stack properties.put("foo-property-2", "foo-value-2"); - Config c2 = new ConfigImpl(cluster, "foo-type", properties, propertiesAttributes, injector); - c2.setTag("version-2"); - c2.setStackId(newStackId); - c2.setVersion(2L); - cluster.addConfig(c2); - c2.persist(); + Config c2 = configFactory.createNew(cluster, "foo-type", "version-2", properties, propertiesAttributes); // make v2 "current" cluster.addDesiredConfig("admin", Sets.newHashSet(c2), "note-2");
http://git-wip-us.apache.org/repos/asf/ambari/blob/4278c4a4/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersTest.java index 5886234..d75d9d0 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersTest.java @@ -405,19 +405,15 @@ public class ClustersTest { cluster.transitionClusterVersion(stackId, stackId.getStackVersion(), RepositoryVersionState.CURRENT); - final Config config1 = injector.getInstance(ConfigFactory.class).createNew(cluster, "t1", + final Config config1 = injector.getInstance(ConfigFactory.class).createNew(cluster, "t1", "1", new HashMap<String, String>() {{ put("prop1", "val1"); }}, new HashMap<String, Map<String,String>>()); - config1.setTag("1"); - config1.persist(); - Config config2 = injector.getInstance(ConfigFactory.class).createNew(cluster, "t1", + Config config2 = injector.getInstance(ConfigFactory.class).createNew(cluster, "t1", "2", new HashMap<String, String>() {{ put("prop2", "val2"); }}, new HashMap<String, Map<String,String>>()); - config2.setTag("2"); - config2.persist(); // cluster desired config cluster.addDesiredConfig("_test", Collections.singleton(config1)); http://git-wip-us.apache.org/repos/asf/ambari/blob/4278c4a4/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ServiceComponentHostConcurrentWriteDeadlockTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ServiceComponentHostConcurrentWriteDeadlockTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ServiceComponentHostConcurrentWriteDeadlockTest.java index 1f09002..96dbf26 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ServiceComponentHostConcurrentWriteDeadlockTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ServiceComponentHostConcurrentWriteDeadlockTest.java @@ -114,17 +114,12 @@ public class ServiceComponentHostConcurrentWriteDeadlockTest { cluster.createClusterVersion(stackId, stackId.getStackVersion(), "admin", RepositoryVersionState.INSTALLING); - Config config1 = configFactory.createNew(cluster, "test-type1", new HashMap<String, String>(), new HashMap<String, + Config config1 = configFactory.createNew(cluster, "test-type1", null, new HashMap<String, String>(), new HashMap<String, Map<String, String>>()); - Config config2 = configFactory.createNew(cluster, "test-type2", new HashMap<String, String>(), new HashMap<String, + Config config2 = configFactory.createNew(cluster, "test-type2", null, new HashMap<String, String>(), new HashMap<String, Map<String, String>>()); - config1.persist(); - config2.persist(); - - cluster.addConfig(config1); - cluster.addConfig(config2); cluster.addDesiredConfig("test user", new HashSet<Config>(Arrays.asList(config1, config2))); String hostName = "c6401"; http://git-wip-us.apache.org/repos/asf/ambari/blob/4278c4a4/ambari-server/src/test/java/org/apache/ambari/server/state/host/HostTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/host/HostTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/host/HostTest.java index 596f381..5c8d174 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/state/host/HostTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/state/host/HostTest.java @@ -384,7 +384,7 @@ public class HostTest { clusters.mapHostToCluster("h1", "c1"); ConfigFactory configFactory = injector.getInstance(ConfigFactory.class); - Config config = configFactory.createNew(c1, "global", + Config config = configFactory.createNew(c1, "global", "v1", new HashMap<String,String>() {{ put("a", "b"); put("x", "y"); }}, new HashMap<String, Map<String,String>>()); try { @@ -396,16 +396,14 @@ public class HostTest { } - config.setTag("v1"); host.addDesiredConfig(c1.getClusterId(), true, "_test", config); Map<String, DesiredConfig> map = host.getDesiredConfigs(c1.getClusterId()); Assert.assertTrue("Expect desired config to contain global", map.containsKey("global")); Assert.assertEquals("Expect global user to be '_test'", "_test", map.get("global").getUser()); - config = configFactory.createNew(c1, "global", + config = configFactory.createNew(c1, "global", "v2", new HashMap<String,String>() {{ put("c", "d"); }}, new HashMap<String, Map<String,String>>()); - config.setTag("v2"); host.addDesiredConfig(c1.getClusterId(), true, "_test1", config); map = host.getDesiredConfigs(c1.getClusterId()); http://git-wip-us.apache.org/repos/asf/ambari/blob/4278c4a4/ambari-server/src/test/java/org/apache/ambari/server/state/stack/UpgradePackTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/stack/UpgradePackTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/stack/UpgradePackTest.java index dde7ffa..8f9f791 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/state/stack/UpgradePackTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/state/stack/UpgradePackTest.java @@ -18,6 +18,7 @@ package org.apache.ambari.server.state.stack; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; @@ -570,6 +571,27 @@ public class UpgradePackTest { Map<String, Map<String, ProcessingComponent>> tasks = upgradePack.getTasks(); assertTrue(tasks.containsKey("HBASE")); + + // !!! generalized upgrade pack shouldn't be in this + boolean found = false; + for (Grouping grouping : upgradePack.getAllGroups()) { + if (grouping.name.equals("GANGLIA_UPGRADE")) { + found = true; + break; + } + } + assertFalse(found); + + // !!! test merge of a generalized upgrade pack + upgradePack = upgrades.get("upgrade_test_conditions"); + assertNotNull(upgradePack); + for (Grouping grouping : upgradePack.getAllGroups()) { + if (grouping.name.equals("GANGLIA_UPGRADE")) { + found = true; + break; + } + } + assertTrue(found); } http://git-wip-us.apache.org/repos/asf/ambari/blob/4278c4a4/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostTest.java index 77e5142..5987af3 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostTest.java @@ -221,11 +221,8 @@ public class ServiceComponentHostTest { Cluster c = clusters.getCluster(clusterName); if (c.getConfig("time", String.valueOf(timestamp)) == null) { - Config config = configFactory.createNew (c, "time", + Config config = configFactory.createNew (c, "time", String.valueOf(timestamp), new HashMap<String, String>(), new HashMap<String, Map<String,String>>()); - config.setTag(String.valueOf(timestamp)); - c.addConfig(config); - config.persist(); } switch (eventType) { @@ -564,7 +561,6 @@ public class ServiceComponentHostTest { final ConfigGroup configGroup = configGroupFactory.createNew(cluster, "cg1", "t1", "", new HashMap<String, Config>(), new HashMap<Long, Host>()); - configGroup.persist(); cluster.addConfigGroup(configGroup); Map<String, Map<String,String>> actual = @@ -815,17 +811,14 @@ public class ServiceComponentHostTest { final Host host = clusters.getHostsForCluster(clusterName).get(hostName); Assert.assertNotNull(host); - final Config c = configFactory.createNew(cluster, "hdfs-site", + final Config c = configFactory.createNew(cluster, "hdfs-site", "version3", new HashMap<String, String>() {{ put("dfs.journalnode.http-address", "http://goo"); }}, new HashMap<String, Map<String,String>>()); - c.setTag("version3"); - c.persist(); - cluster.addConfig(c); + host.addDesiredConfig(cluster.getClusterId(), true, "user", c); ConfigGroup configGroup = configGroupFactory.createNew(cluster, "g1", "t1", "", new HashMap<String, Config>() {{ put("hdfs-site", c); }}, new HashMap<Long, Host>() {{ put(hostEntity.getHostId(), host); }}); - configGroup.persist(); cluster.addConfigGroup(configGroup); // HDP-x/HDFS/hdfs-site updated host to changed property @@ -876,16 +869,12 @@ public class ServiceComponentHostTest { sch1.updateActualConfigs(actual); - final Config c1 = configFactory.createNew(cluster, "core-site", + final Config c1 = configFactory.createNew(cluster, "core-site", "version2", new HashMap<String, String>() {{ put("fs.trash.interval", "400"); }}, new HashMap<String, Map<String,String>>()); - c1.setTag("version2"); - c1.persist(); - cluster.addConfig(c1); configGroup = configGroupFactory.createNew(cluster, "g2", "t2", "", new HashMap<String, Config>() {{ put("core-site", c1); }}, new HashMap<Long, Host>() {{ put(hostEntity.getHostId(), host); }}); - configGroup.persist(); cluster.addConfigGroup(configGroup); Assert.assertTrue(sch1.convertToResponse(null).isStaleConfig()); @@ -1039,10 +1028,7 @@ public class ServiceComponentHostTest { * @param values the values for the config */ private void makeConfig(Cluster cluster, String type, String tag, Map<String, String> values, Map<String, Map<String, String>> attributes) { - Config config = configFactory.createNew(cluster, type, values, attributes); - config.setTag(tag); - config.persist(); - cluster.addConfig(config); + Config config = configFactory.createNew(cluster, type, tag, values, attributes); cluster.addDesiredConfig("user", Collections.singleton(config)); } http://git-wip-us.apache.org/repos/asf/ambari/blob/4278c4a4/ambari-server/src/test/java/org/apache/ambari/server/topology/AmbariContextTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/topology/AmbariContextTest.java b/ambari-server/src/test/java/org/apache/ambari/server/topology/AmbariContextTest.java index 82526e7..fac5185 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/topology/AmbariContextTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/topology/AmbariContextTest.java @@ -59,6 +59,7 @@ import org.apache.ambari.server.controller.spi.Resource; 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.ConfigFactory; import org.apache.ambari.server.state.ConfigHelper; import org.apache.ambari.server.state.DesiredConfig; import org.apache.ambari.server.state.Host; @@ -66,13 +67,14 @@ import org.apache.ambari.server.state.Service; import org.apache.ambari.server.state.StackId; import org.apache.ambari.server.state.configgroup.ConfigGroup; import org.easymock.Capture; +import org.easymock.EasyMock; import org.junit.After; import org.junit.Before; import org.junit.Test; +import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; -import com.google.common.collect.ImmutableList; /** * AmbariContext unit tests @@ -110,6 +112,7 @@ public class AmbariContextTest { private static final ConfigGroup configGroup2 = createMock(ConfigGroup.class); private static final Host host1 = createNiceMock(Host.class); private static final Host host2 = createNiceMock(Host.class); + private static final ConfigFactory configFactory = createNiceMock(ConfigFactory.class); private static final Collection<String> blueprintServices = new HashSet<String>(); private static final Map<String, Service> clusterServices = new HashMap<String, Service>(); @@ -164,6 +167,9 @@ public class AmbariContextTest { type1Props.put("prop3", "val3"); group1Configuration = new Configuration(group1Properties, null, bpConfiguration); + Map<String, String> group1ResolvedProperties = new HashMap<String, String>(bpType1Props); + group1ResolvedProperties.putAll(type1Props); + // config type -> service mapping Map<String, String> configTypeServiceMapping = new HashMap<String, String>(); configTypeServiceMapping.put("type1", "service1"); @@ -172,6 +178,28 @@ public class AmbariContextTest { configGroups.put(1L, configGroup1); configGroups.put(2L, configGroup2); + // config factory mock + Config type1Group1 = createNiceMock(Config.class); + expect(type1Group1.getType()).andReturn("type1").anyTimes(); + expect(type1Group1.getTag()).andReturn("group1").anyTimes(); + expect(type1Group1.getProperties()).andReturn(group1ResolvedProperties).anyTimes(); + expect(configFactory.createReadOnly(EasyMock.eq("type1"), EasyMock.eq("group1"), + EasyMock.<Map<String, String>> anyObject(), + EasyMock.<Map<String, Map<String, String>>> anyObject())).andReturn(type1Group1).anyTimes(); + replay(type1Group1); + + Config type1Service1 = createNiceMock(Config.class); + expect(type1Service1.getType()).andReturn("type1").anyTimes(); + expect(type1Service1.getTag()).andReturn("service1").anyTimes(); + expect(type1Service1.getProperties()).andReturn(type1Props).anyTimes(); + expect(configFactory.createReadOnly(EasyMock.eq("type1"), EasyMock.eq("service1"), + EasyMock.<Map<String, String>> anyObject(), + EasyMock.<Map<String, Map<String, String>>> anyObject())).andReturn( + type1Service1).anyTimes(); + replay(type1Service1); + + context.configFactory = configFactory; + blueprintServices.add("service1"); blueprintServices.add("service2"); @@ -222,17 +250,17 @@ public class AmbariContextTest { public void tearDown() throws Exception { verify(controller, clusterController, hostResourceProvider, serviceResourceProvider, componentResourceProvider, hostComponentResourceProvider, configGroupResourceProvider, topology, blueprint, stack, clusters, - cluster, group1Info, configHelper, configGroup1, configGroup2, host1, host2); + cluster, group1Info, configHelper, configGroup1, configGroup2, host1, host2, configFactory); reset(controller, clusterController, hostResourceProvider, serviceResourceProvider, componentResourceProvider, hostComponentResourceProvider, configGroupResourceProvider, topology, blueprint, stack, clusters, - cluster, group1Info, configHelper, configGroup1, configGroup2, host1, host2); + cluster, group1Info, configHelper, configGroup1, configGroup2, host1, host2, configFactory); } private void replayAll() { replay(controller, clusterController, hostResourceProvider, serviceResourceProvider, componentResourceProvider, hostComponentResourceProvider, configGroupResourceProvider, topology, blueprint, stack, clusters, - cluster, group1Info, configHelper, configGroup1, configGroup2, host1, host2); + cluster, group1Info, configHelper, configGroup1, configGroup2, host1, host2, configFactory); } @Test @@ -330,6 +358,7 @@ public class AmbariContextTest { expect(clusterController.ensureResourceProvider(Resource.Type.ConfigGroup)).andReturn(configGroupResourceProvider).once(); //todo: for now not using return value so just returning null expect(configGroupResourceProvider.createResources(capture(configGroupRequestCapture))).andReturn(null).once(); + // replay all mocks replayAll(); @@ -416,7 +445,6 @@ public class AmbariContextTest { expect(configGroup1.getHosts()).andReturn(Collections.singletonMap(2L, host2)).once(); configGroup1.addHost(host1); - configGroup1.persistHostMapping(); // replay all mocks replayAll(); http://git-wip-us.apache.org/repos/asf/ambari/blob/4278c4a4/ambari-server/src/test/java/org/apache/ambari/server/update/HostUpdateHelperTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/update/HostUpdateHelperTest.java b/ambari-server/src/test/java/org/apache/ambari/server/update/HostUpdateHelperTest.java index f9dd5d1..3bb6c0a 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/update/HostUpdateHelperTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/update/HostUpdateHelperTest.java @@ -49,6 +49,8 @@ import org.apache.ambari.server.orm.entities.StackEntity; 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.ConfigFactory; +import org.apache.ambari.server.state.ConfigImpl; import org.apache.ambari.server.state.Host; import org.apache.ambari.server.state.stack.OsFamily; import org.apache.ambari.server.utils.CollectionPresentationUtils; @@ -62,6 +64,7 @@ import com.google.gson.JsonPrimitive; import com.google.inject.AbstractModule; import com.google.inject.Guice; import com.google.inject.Injector; +import com.google.inject.assistedinject.FactoryModuleBuilder; import junit.framework.Assert; @@ -212,16 +215,12 @@ public class HostUpdateHelperTest { Clusters mockClusters = easyMockSupport.createStrictMock(Clusters.class); Cluster mockCluster = easyMockSupport.createNiceMock(Cluster.class); ClusterEntity mockClusterEntity1 = easyMockSupport.createNiceMock(ClusterEntity.class); - ClusterEntity mockClusterEntity2 = easyMockSupport.createNiceMock(ClusterEntity.class); ClusterConfigEntity mockClusterConfigEntity1 = easyMockSupport.createNiceMock(ClusterConfigEntity.class); ClusterConfigEntity mockClusterConfigEntity2 = easyMockSupport.createNiceMock(ClusterConfigEntity.class); - ClusterConfigEntity mockClusterConfigEntity3 = easyMockSupport.createNiceMock(ClusterConfigEntity.class); - ClusterConfigEntity mockClusterConfigEntity4 = easyMockSupport.createNiceMock(ClusterConfigEntity.class); StackEntity mockStackEntity = easyMockSupport.createNiceMock(StackEntity.class); Map<String, Map<String, String>> clusterHostsToChange = new HashMap<>(); Map<String, String> hosts = new HashMap<>(); List<ClusterConfigEntity> clusterConfigEntities1 = new ArrayList<>(); - List<ClusterConfigEntity> clusterConfigEntities2 = new ArrayList<>(); final Injector mockInjector = Guice.createInjector(new AbstractModule() { @Override @@ -231,6 +230,8 @@ public class HostUpdateHelperTest { bind(EntityManager.class).toInstance(entityManager); bind(OsFamily.class).toInstance(createNiceMock(OsFamily.class)); bind(ClusterDAO.class).toInstance(mockClusterDAO); + + install(new FactoryModuleBuilder().implement(Config.class, ConfigImpl.class).build(ConfigFactory.class)); } }); @@ -242,49 +243,42 @@ public class HostUpdateHelperTest { clusterConfigEntities1.add(mockClusterConfigEntity1); clusterConfigEntities1.add(mockClusterConfigEntity2); - clusterConfigEntities2.add(mockClusterConfigEntity3); - clusterConfigEntities2.add(mockClusterConfigEntity4); - clusterHostsToChange.put("cl1", hosts); - expect(mockClusterDAO.findByName("cl1")).andReturn(mockClusterEntity1).once(); - expect(mockClusterDAO.findById(1L)).andReturn(mockClusterEntity2).atLeastOnce(); + expect(mockClusterDAO.findByName("cl1")).andReturn(mockClusterEntity1).atLeastOnce(); expect(mockAmbariManagementController.getClusters()).andReturn(mockClusters).once(); expect(mockClusters.getCluster("cl1")).andReturn(mockCluster).once(); - expect(mockCluster.getClusterId()).andReturn(1L).atLeastOnce(); + expect(mockCluster.getClusterId()).andReturn(1L).anyTimes(); expect(mockClusterEntity1.getClusterConfigEntities()).andReturn(clusterConfigEntities1).atLeastOnce(); - expect(mockClusterEntity2.getClusterConfigEntities()).andReturn(clusterConfigEntities2).atLeastOnce(); - expect(mockClusterConfigEntity1.getStack()).andReturn(mockStackEntity).once(); + expect(mockClusterConfigEntity1.getClusterId()).andReturn(1L).atLeastOnce(); + expect(mockClusterConfigEntity1.getConfigId()).andReturn(1L).atLeastOnce(); + expect(mockClusterConfigEntity1.getStack()).andReturn(mockStackEntity).atLeastOnce(); expect(mockClusterConfigEntity1.getData()).andReturn("{\"testProperty1\" : \"testValue_host1\", " + "\"testProperty2\" : \"testValue_host5\", \"testProperty3\" : \"testValue_host11\", " + "\"testProperty4\" : \"testValue_host55\"}").atLeastOnce(); expect(mockClusterConfigEntity1.getTag()).andReturn("testTag1").atLeastOnce(); expect(mockClusterConfigEntity1.getType()).andReturn("testType1").atLeastOnce(); expect(mockClusterConfigEntity1.getVersion()).andReturn(1L).atLeastOnce(); + expect(mockClusterDAO.findConfig(1L)).andReturn(mockClusterConfigEntity1).atLeastOnce(); - expect(mockClusterConfigEntity2.getStack()).andReturn(mockStackEntity).once(); + expect(mockClusterConfigEntity2.getClusterId()).andReturn(1L).atLeastOnce(); + expect(mockClusterConfigEntity2.getConfigId()).andReturn(2L).anyTimes(); + expect(mockClusterConfigEntity2.getStack()).andReturn(mockStackEntity).atLeastOnce(); expect(mockClusterConfigEntity2.getData()).andReturn("{\"testProperty5\" : \"test_host1_test_host5_test_host11_test_host55\"}").atLeastOnce(); expect(mockClusterConfigEntity2.getTag()).andReturn("testTag2").atLeastOnce(); expect(mockClusterConfigEntity2.getType()).andReturn("testType2").atLeastOnce(); expect(mockClusterConfigEntity2.getVersion()).andReturn(2L).atLeastOnce(); - - expect(mockClusterConfigEntity3.getTag()).andReturn("testTag1").atLeastOnce(); - expect(mockClusterConfigEntity3.getType()).andReturn("testType1").atLeastOnce(); - expect(mockClusterConfigEntity3.getVersion()).andReturn(1L).atLeastOnce(); - - expect(mockClusterConfigEntity4.getTag()).andReturn("testTag2").atLeastOnce(); - expect(mockClusterConfigEntity4.getType()).andReturn("testType2").atLeastOnce(); - expect(mockClusterConfigEntity4.getVersion()).andReturn(2L).atLeastOnce(); + expect(mockClusterDAO.findConfig(2L)).andReturn(mockClusterConfigEntity2).atLeastOnce(); Capture<String> dataCapture = EasyMock.newCapture(); - mockClusterConfigEntity3.setData(EasyMock.capture(dataCapture)); + mockClusterConfigEntity1.setData(EasyMock.capture(dataCapture)); expectLastCall(); - mockClusterConfigEntity4.setData("{\"testProperty5\":\"test_host5_test_host1_test_host55_test_host11\"}"); + mockClusterConfigEntity2.setData("{\"testProperty5\":\"test_host5_test_host1_test_host55_test_host11\"}"); expectLastCall(); HostUpdateHelper hostUpdateHelper = new HostUpdateHelper(null, null, mockInjector); http://git-wip-us.apache.org/repos/asf/ambari/blob/4278c4a4/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog210Test.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog210Test.java b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog210Test.java index e8ed042..f19288f 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog210Test.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog210Test.java @@ -876,6 +876,8 @@ public class UpgradeCatalog210Test { final Map<String, String> propertiesExpectedHdfs = new HashMap<String, String>(); final Map<String, String> propertiesExpectedCoreSite = new HashMap<String, String>(); + propertiesExpectedHdfs.put("dfs.nameservices", "nncl1,nncl2"); + propertiesExpectedHdfs.put("dfs.ha.namenodes.nncl2", "nn1,nn2"); propertiesExpectedCoreSite.put("fs.defaultFS", "hdfs://EXAMPLE.COM:8020"); final Injector mockInjector = Guice.createInjector(new AbstractModule() { @Override http://git-wip-us.apache.org/repos/asf/ambari/blob/4278c4a4/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 dc8a7e5..6da2cf1 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 @@ -36,6 +36,7 @@ import org.apache.ambari.server.orm.DBAccessor; 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.stack.OsFamily; import org.easymock.Capture; import org.easymock.EasyMock; @@ -211,6 +212,8 @@ public class UpgradeCatalog250Test { Method updateAmsConfigs = UpgradeCatalog250.class.getDeclaredMethod("updateAMSConfigs"); Method updateKafkaConfigs = UpgradeCatalog250.class.getDeclaredMethod("updateKafkaConfigs"); Method updateHiveLlapConfigs = UpgradeCatalog250.class.getDeclaredMethod("updateHiveLlapConfigs"); + Method updateTablesForZeppelinViewRemoval = UpgradeCatalog250.class.getDeclaredMethod("updateTablesForZeppelinViewRemoval"); + Method updateAtlasConfigs = UpgradeCatalog250.class.getDeclaredMethod("updateAtlasConfigs"); Method addNewConfigurationsFromXml = AbstractUpgradeCatalog.class.getDeclaredMethod("addNewConfigurationsFromXml"); Method updateHIVEInteractiveConfigs = UpgradeCatalog250.class.getDeclaredMethod("updateHIVEInteractiveConfigs"); Method updateTEZInteractiveConfigs = UpgradeCatalog250.class.getDeclaredMethod("updateTEZInteractiveConfigs"); @@ -221,6 +224,8 @@ public class UpgradeCatalog250Test { .addMockedMethod(updateHIVEInteractiveConfigs) .addMockedMethod(updateTEZInteractiveConfigs) .addMockedMethod(updateHiveLlapConfigs) + .addMockedMethod(updateTablesForZeppelinViewRemoval) + .addMockedMethod(updateAtlasConfigs) .addMockedMethod(addNewConfigurationsFromXml) .createMock(); @@ -243,6 +248,12 @@ public class UpgradeCatalog250Test { upgradeCatalog250.updateHiveLlapConfigs(); expectLastCall().once(); + upgradeCatalog250.updateTablesForZeppelinViewRemoval(); + expectLastCall().once(); + + upgradeCatalog250.updateAtlasConfigs(); + expectLastCall().once(); + replay(upgradeCatalog250); upgradeCatalog250.executeDMLUpdates(); @@ -592,4 +603,91 @@ public class UpgradeCatalog250Test { Map<String, String> updatedProperties = propertiesCapture.getValue(); assertTrue(Maps.difference(newProperties, updatedProperties).areEqual()); } + + @Test + public void testUpdateAtlasConfigs() throws Exception { + + Map<String, String> oldHiveProperties = new HashMap<String, String>(); + Map<String, String> newHiveProperties = new HashMap<String, String>(); + + 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>(); + 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>(); + 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>(); + oldSqoopProperties.put("sqoop.atlas.hook", "false"); + newSqoopProperties.put("sqoop.atlas.hook", "true"); + testUpdateAtlasHookConfig(oldSqoopProperties, newSqoopProperties, "sqoop-env"); + } + + public void testUpdateAtlasHookConfig(Map<String, String> oldProperties, Map<String, String> newProperties, String configType) throws Exception { + + Map<String, Service> installedServices = new HashMap<String, Service>() { + { + put("ATLAS", null); + put("HIVE", null); + put("STORM", null); + put("FALCON", null); + put("SQOOP", null); + } + }; + + EasyMockSupport easyMockSupport = new EasyMockSupport(); + + Clusters clusters = easyMockSupport.createNiceMock(Clusters.class); + final Cluster cluster = easyMockSupport.createNiceMock(Cluster.class); + final Service service = createStrictMock(Service.class); + + expect(clusters.getClusters()).andReturn(new HashMap<String, Cluster>() {{ + put("normal", cluster); + }}).once(); + expect(cluster.getClusterName()).andReturn("cl1").once(); + expect(cluster.getServices()).andReturn(installedServices).atLeastOnce(); + + Config mockAtlasConfig = easyMockSupport.createNiceMock(Config.class); + expect(cluster.getDesiredConfigByType(configType)).andReturn(mockAtlasConfig).atLeastOnce(); + expect(mockAtlasConfig.getProperties()).andReturn(oldProperties).anyTimes(); + + Injector injector = easyMockSupport.createNiceMock(Injector.class); + expect(injector.getInstance(Gson.class)).andReturn(null).anyTimes(); + expect(injector.getInstance(MaintenanceStateHelper.class)).andReturn(null).anyTimes(); + expect(injector.getInstance(KerberosHelper.class)).andReturn(createNiceMock(KerberosHelper.class)).anyTimes(); + + replay(injector, clusters, mockAtlasConfig, cluster); + + AmbariManagementControllerImpl controller = createMockBuilder(AmbariManagementControllerImpl.class) + .addMockedMethod("createConfiguration") + .addMockedMethod("getClusters", new Class[] { }) + .addMockedMethod("createConfig") + .withConstructor(createNiceMock(ActionManager.class), clusters, injector) + .createNiceMock(); + + Injector injector2 = easyMockSupport.createNiceMock(Injector.class); + Capture<Map> propertiesCapture = EasyMock.newCapture(); + + expect(injector2.getInstance(AmbariManagementController.class)).andReturn(controller).anyTimes(); + expect(controller.getClusters()).andReturn(clusters).anyTimes(); + expect(controller.createConfig(anyObject(Cluster.class), anyString(), capture(propertiesCapture), anyString(), + anyObject(Map.class))).andReturn(createNiceMock(Config.class)).once(); + + replay(controller, injector2); + new UpgradeCatalog250(injector2).updateAtlasConfigs(); + easyMockSupport.verifyAll(); + + Map<String, String> updatedProperties = propertiesCapture.getValue(); + assertTrue(Maps.difference(newProperties, updatedProperties).areEqual()); + } } http://git-wip-us.apache.org/repos/asf/ambari/blob/4278c4a4/ambari-server/src/test/java/org/apache/ambari/server/utils/RequestUtilsTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/utils/RequestUtilsTest.java b/ambari-server/src/test/java/org/apache/ambari/server/utils/RequestUtilsTest.java index 595127e..f36858e 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/utils/RequestUtilsTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/utils/RequestUtilsTest.java @@ -30,6 +30,7 @@ import org.junit.Test; public class RequestUtilsTest { public static final String REMOTE_ADDRESS = "12.13.14.15"; + public static final String REMOTE_ADDRESS_MULTIPLE = "12.13.14.15,12.13.14.16"; @Test public void testGetRemoteAddress() { @@ -49,6 +50,23 @@ public class RequestUtilsTest { } @Test + public void testGetMultipleRemoteAddress() { + // GIVEN + HttpServletRequest mockedRequest = createMock(HttpServletRequest.class); + expect(mockedRequest.getHeader("X-Forwarded-For")).andReturn(null); + expect(mockedRequest.getHeader("Proxy-Client-IP")).andReturn("unknown"); + expect(mockedRequest.getHeader("WL-Proxy-Client-IP")).andReturn(""); + expect(mockedRequest.getHeader("HTTP_CLIENT_IP")).andReturn("unknown"); + expect(mockedRequest.getHeader("HTTP_X_FORWARDED_FOR")).andReturn(REMOTE_ADDRESS_MULTIPLE); + replay(mockedRequest); + // WHEN + String remoteAddress = RequestUtils.getRemoteAddress(mockedRequest); + // THEN + assertEquals(REMOTE_ADDRESS, remoteAddress); + verify(mockedRequest); + } + + @Test public void testGetRemoteAddressFoundFirstHeader() { // GIVEN HttpServletRequest mockedRequest = createMock(HttpServletRequest.class); http://git-wip-us.apache.org/repos/asf/ambari/blob/4278c4a4/ambari-server/src/test/java/org/apache/ambari/server/utils/StageUtilsTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/utils/StageUtilsTest.java b/ambari-server/src/test/java/org/apache/ambari/server/utils/StageUtilsTest.java index 29f40fb..5c77831 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/utils/StageUtilsTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/utils/StageUtilsTest.java @@ -65,6 +65,9 @@ import org.apache.ambari.server.security.encryption.CredentialStoreService; import org.apache.ambari.server.stack.StackManagerFactory; 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.ConfigFactory; +import org.apache.ambari.server.state.ConfigImpl; import org.apache.ambari.server.state.Host; import org.apache.ambari.server.state.HostComponentAdminState; import org.apache.ambari.server.state.Service; @@ -126,6 +129,7 @@ public class StageUtilsTest extends EasyMockSupport { bind(HostRoleCommandDAO.class).toInstance(createNiceMock(HostRoleCommandDAO.class)); install(new FactoryModuleBuilder().build(ExecutionCommandWrapperFactory.class)); + install(new FactoryModuleBuilder().implement(Config.class, ConfigImpl.class).build(ConfigFactory.class)); } }); http://git-wip-us.apache.org/repos/asf/ambari/blob/4278c4a4/ambari-server/src/test/python/TestMpacks.py ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/python/TestMpacks.py b/ambari-server/src/test/python/TestMpacks.py index 4b54415..ef81945 100644 --- a/ambari-server/src/test/python/TestMpacks.py +++ b/ambari-server/src/test/python/TestMpacks.py @@ -64,7 +64,7 @@ def get_configs(): serverConfiguration.STACK_LOCATION_KEY : "/var/lib/ambari-server/resources/stacks", serverConfiguration.COMMON_SERVICES_PATH_PROPERTY : "/var/lib/ambari-server/resources/common-services", serverConfiguration.EXTENSION_PATH_PROPERTY : "/var/lib/ambari-server/resources/extensions", - serverConfiguration.DASHBOARD_PATH_PROPERTY : "/var/lib/ambari-server/resources/dashboards", + serverConfiguration.RESOURCES_DIR_PROPERTY : "/var/lib/ambari-server/resources", serverConfiguration.MPACKS_STAGING_PATH_PROPERTY : mpacks_directory, serverConfiguration.SERVER_TMP_DIR_PROPERTY : "/tmp", serverConfiguration.JDBC_DATABASE_PROPERTY: "postgres" @@ -100,9 +100,11 @@ class TestMpacks(TestCase): fail = True self.assertTrue(fail) + @patch("os.path.exists") @patch("ambari_server.setupMpacks.get_YN_input") @patch("ambari_server.setupMpacks.run_mpack_install_checker") - def test_validate_purge(self, run_mpack_install_checker_mock, get_YN_input_mock): + @patch("ambari_server.setupMpacks.get_ambari_properties") + def test_validate_purge(self, get_ambari_properties_mock, run_mpack_install_checker_mock, get_YN_input_mock, os_path_exists_mock): options = self._create_empty_options_mock() options.purge = True purge_list = options.purge_list.split(',') @@ -112,6 +114,7 @@ class TestMpacks(TestCase): replay_mode = False run_mpack_install_checker_mock.return_value = (0, "No errors found", "") get_YN_input_mock.return_value = True + os_path_exists_mock.return_value = True fail = False try: @@ -160,22 +163,28 @@ class TestMpacks(TestCase): extensions_directory = configs[serverConfiguration.EXTENSION_PATH_PROPERTY] common_services_directory = configs[serverConfiguration.COMMON_SERVICES_PATH_PROPERTY] mpacks_directory = configs[serverConfiguration.MPACKS_STAGING_PATH_PROPERTY] - os_path_exists_mock.return_value = False + os_path_exists_mock.side_effect = [True] purge_stacks_and_mpacks(None) - os_path_exists_calls = [] + os_path_exists_calls = [ + call('/var/lib/ambari-server/resources'), + ] os_path_exists_mock.assert_has_calls(os_path_exists_calls) + os_path_exists_mock.side_effect = [True, False, False] purge_stacks_and_mpacks(options.purge_list.split(",")) os_path_exists_calls = [ + call('/var/lib/ambari-server/resources'), call(stacks_directory), call(mpacks_directory) ] os_path_exists_mock.assert_has_calls(os_path_exists_calls) options.purge_list = ",".join([STACK_DEFINITIONS_RESOURCE_NAME, SERVICE_DEFINITIONS_RESOURCE_NAME, MPACKS_RESOURCE_NAME]) + os_path_exists_mock.side_effect = [True, False, False, False] purge_stacks_and_mpacks(options.purge_list.split(",")) os_path_exists_calls = [ + call('/var/lib/ambari-server/resources'), call(stacks_directory), call(common_services_directory), call(mpacks_directory) @@ -183,8 +192,10 @@ class TestMpacks(TestCase): os_path_exists_mock.assert_has_calls(os_path_exists_calls) options.purge_list = ",".join([STACK_DEFINITIONS_RESOURCE_NAME, EXTENSION_DEFINITIONS_RESOURCE_NAME, MPACKS_RESOURCE_NAME]) + os_path_exists_mock.side_effect = [True, False, False, False] purge_stacks_and_mpacks(options.purge_list.split(",")) os_path_exists_calls = [ + call('/var/lib/ambari-server/resources'), call(stacks_directory), call(extensions_directory), call(mpacks_directory) @@ -193,10 +204,13 @@ class TestMpacks(TestCase): options.purge_list = ",".join([STACK_DEFINITIONS_RESOURCE_NAME, SERVICE_DEFINITIONS_RESOURCE_NAME, MPACKS_RESOURCE_NAME]) options.replay_mode = True + os_path_exists_mock.side_effect = [True, False, False, False] purge_stacks_and_mpacks(options.purge_list.split(",")) os_path_exists_calls = [ + call('/var/lib/ambari-server/resources'), call(stacks_directory), - call(common_services_directory) + call(common_services_directory), + call(mpacks_directory) ] os_path_exists_mock.assert_has_calls(os_path_exists_calls) @@ -266,10 +280,11 @@ class TestMpacks(TestCase): get_ambari_version_mock.return_value = "2.4.0.0" run_os_command_mock.return_value = (0, "", "") mpacks_directory = configs[serverConfiguration.MPACKS_STAGING_PATH_PROPERTY] - """ + os_path_exists_calls = [call('/tmp/mystack.tar.gz'), call('mpacks/mystack-ambari-mpack-1.0.0.0/mpack.json'), call('mpacks/mystack-ambari-mpack-1.0.0.0/hooks/before_install.py'), + call('/var/lib/ambari-server/resources'), call('/var/lib/ambari-server/resources/stacks'), call('/var/lib/ambari-server/resources/extensions'), call('/var/lib/ambari-server/resources/common-services'), @@ -277,12 +292,14 @@ class TestMpacks(TestCase): call(mpacks_directory + '/cache'), call('/var/lib/ambari-server/resources/dashboards'), call(mpacks_directory + '/mystack-ambari-mpack-1.0.0.0'), + call('/var/lib/ambari-server/resources'), call('/var/lib/ambari-server/resources/common-services/SERVICEA'), call(mpacks_directory + '/mystack-ambari-mpack-1.0.0.0/common-services/SERVICEA/1.0/dashboards'), call(mpacks_directory + '/mystack-ambari-mpack-1.0.0.0/common-services/SERVICEA/2.0/dashboards'), call('/var/lib/ambari-server/resources/common-services/SERVICEB'), call(mpacks_directory + '/mystack-ambari-mpack-1.0.0.0/common-services/SERVICEB/1.0.0/dashboards'), call(mpacks_directory + '/mystack-ambari-mpack-1.0.0.0/common-services/SERVICEB/2.0.0/dashboards'), + call('/var/lib/ambari-server/resources'), call('/var/lib/ambari-server/resources/stacks/MYSTACK'), call('/var/lib/ambari-server/resources/stacks/MYSTACK/1.0'), call('/var/lib/ambari-server/resources/stacks/MYSTACK/1.0/services'), @@ -295,22 +312,26 @@ class TestMpacks(TestCase): call(mpacks_directory + '/mystack-ambari-mpack-1.0.0.0/stacks/MYSTACK/2.0/services/SERVICEA/dashboards'), call(mpacks_directory + '/mystack-ambari-mpack-1.0.0.0/stacks/MYSTACK/2.0/services/SERVICEB/dashboards'), call(mpacks_directory + '/mystack-ambari-mpack-1.0.0.0/hooks/after_install.py')] - """ - os_path_exists_mock.side_effect = [True, True, True, False, True, False, False, False, False, - False, False, False, False, False, False, - False, False, False, False, False, False, False, False, - False, False, False, False, True] + + os_path_exists_mock.side_effect = [True, True, True, True, False, True, False, False, False, False, + False, True, False, False, False, False, False, False, True, False, + False, False, False, False, False, False, False, False, False, False, + True] get_ambari_properties_mock.return_value = configs shutil_move_mock.return_value = True - install_mpack(options) + try: + install_mpack(options) + except Exception as e: + print e stacks_directory = configs[serverConfiguration.STACK_LOCATION_KEY] common_services_directory = configs[serverConfiguration.COMMON_SERVICES_PATH_PROPERTY] extensions_directory = configs[serverConfiguration.EXTENSION_PATH_PROPERTY] mpacks_directory = configs[serverConfiguration.MPACKS_STAGING_PATH_PROPERTY] - dashboards_directory = serverConfiguration.get_dashboard_location(configs) mpacks_staging_directory = os.path.join(mpacks_directory, "mystack-ambari-mpack-1.0.0.0") + resources_directory = configs[serverConfiguration.RESOURCES_DIR_PROPERTY] + dashboards_directory = os.path.join(resources_directory, "dashboards") run_os_command_calls = [ call([ @@ -377,6 +398,7 @@ class TestMpacks(TestCase): "SERVICEB", None) ] + os_path_exists_mock.assert_has_calls(os_path_exists_calls) self.assertTrue(purge_stacks_and_mpacks_mock.called) run_os_command_mock.assert_has_calls(run_os_command_calls) os_mkdir_mock.assert_has_calls(os_mkdir_calls) @@ -403,8 +425,8 @@ class TestMpacks(TestCase): expand_mpack_mock.return_value = "mpacks/myextension-ambari-mpack-1.0.0.0" get_ambari_version_mock.return_value = "2.4.0.0" - os_path_exists_mock.side_effect = [True, True, True, False, True, False, False, False, - False, True, False, False, False] + os_path_exists_mock.side_effect = [True, True, True, True, False, True, False, False, False, + False, True, True, False, False, False] get_ambari_properties_mock.return_value = configs shutil_move_mock.return_value = True @@ -413,10 +435,12 @@ class TestMpacks(TestCase): extensions_directory = configs[serverConfiguration.EXTENSION_PATH_PROPERTY] mpacks_directory = configs[serverConfiguration.MPACKS_STAGING_PATH_PROPERTY] mpacks_staging_directory = os.path.join(mpacks_directory, "myextension-ambari-mpack-1.0.0.0") - dashboards_directory = serverConfiguration.get_dashboard_location(configs) + resources_directory = configs[serverConfiguration.RESOURCES_DIR_PROPERTY] + dashboards_directory = os.path.join(resources_directory, "dashboards") os_path_exists_calls = [call('/tmp/myextension.tar.gz'), call('mpacks/myextension-ambari-mpack-1.0.0.0/mpack.json'), + call('/var/lib/ambari-server/resources'), call('/var/lib/ambari-server/resources/stacks'), call('/var/lib/ambari-server/resources/extensions'), call('/var/lib/ambari-server/resources/common-services'), @@ -424,6 +448,7 @@ class TestMpacks(TestCase): call(mpacks_directory + '/cache'), call('/var/lib/ambari-server/resources/dashboards'), call(mpacks_directory + '/myextension-ambari-mpack-1.0.0.0'), + call('/var/lib/ambari-server/resources'), call('/var/lib/ambari-server/resources/extensions'), call('/var/lib/ambari-server/resources/extensions/MYEXTENSION'), call(mpacks_directory + '/myextension-ambari-mpack-1.0.0.0/extensions/MYEXTENSION/1.0/services'), @@ -476,9 +501,9 @@ class TestMpacks(TestCase): expand_mpack_mock.return_value = "mpacks/myservice-ambari-mpack-1.0.0.0" get_ambari_version_mock.return_value = "2.4.0.0" - os_path_exists_mock.side_effect = [True, True, True, True, True, True, - True, True, False, False, False, False, - True, True, True, False, True, True, + os_path_exists_mock.side_effect = [True, True, True, True, True, True, True, + True, True, False, False, True, False, False, + True, True, True, True, False, True, True, True, False] get_ambari_properties_mock.return_value = configs @@ -491,11 +516,13 @@ class TestMpacks(TestCase): common_services_directory = configs[serverConfiguration.COMMON_SERVICES_PATH_PROPERTY] mpacks_directory = configs[serverConfiguration.MPACKS_STAGING_PATH_PROPERTY] mpacks_staging_directory = os.path.join(mpacks_directory, "myservice-ambari-mpack-1.0.0.0") - dashboards_directory = serverConfiguration.get_dashboard_location(configs) + resources_directory = configs[serverConfiguration.RESOURCES_DIR_PROPERTY] + dashboards_directory = os.path.join(resources_directory, "dashboards") os_path_exists_calls = [call('/tmp/myservice.tar.gz'), call('mpacks/myservice-ambari-mpack-1.0.0.0/mpack.json'), call('/var/lib/ambari-server/resources/stacks/MYSTACK/1.0'), + call('/var/lib/ambari-server/resources'), call('/var/lib/ambari-server/resources/stacks'), call('/var/lib/ambari-server/resources/extensions'), call('/var/lib/ambari-server/resources/common-services'), @@ -503,8 +530,10 @@ class TestMpacks(TestCase): call(mpacks_directory + '/cache'), call('/var/lib/ambari-server/resources/dashboards'), call(mpacks_directory + '/myservice-ambari-mpack-1.0.0.0'), + call('/var/lib/ambari-server/resources'), call('/var/lib/ambari-server/resources/common-services/MYSERVICE'), call(mpacks_directory + '/myservice-ambari-mpack-1.0.0.0/common-services/MYSERVICE/1.0.0/dashboards'), + call('/var/lib/ambari-server/resources'), call('/var/lib/ambari-server/resources/stacks/MYSTACK'), call('/var/lib/ambari-server/resources/stacks/MYSTACK/1.0'), call('/var/lib/ambari-server/resources/stacks/MYSTACK/1.0/services'), @@ -562,14 +591,14 @@ class TestMpacks(TestCase): get_ambari_version_mock.return_value = "2.4.0.0" run_os_command_mock.return_value = (0, "", "") mpacks_directory = configs[serverConfiguration.MPACKS_STAGING_PATH_PROPERTY] - os_path_exists_mock.side_effect = [True, True, True, True, True, True, True, True, - True, True, True, True, True, True, True, False, - False, True, False, False, True, False, False, - False, False, False, True, True, True, False, - True, True, False, True, True, False, False, - False, False, False, True, True, True, True, - True, True, True, False, True, False, True, True, - True, True, True, True] + os_path_exists_mock.side_effect = [True, True, True, True, True, True, True, True, True, True, + True, True, True, True, True, True, True, False, False, True, + True, False, False, True, False, False, False, False, False, True, + True, True, True, False, True, True, False, True, True, False, + False, False, False, False, True, True, True, True, True, True, + True, False, True, False, True, True, True, True, True, True, + True] + get_ambari_properties_mock.return_value = configs shutil_move_mock.return_value = True @@ -579,10 +608,12 @@ class TestMpacks(TestCase): common_services_directory = configs[serverConfiguration.COMMON_SERVICES_PATH_PROPERTY] mpacks_directory = configs[serverConfiguration.MPACKS_STAGING_PATH_PROPERTY] mpacks_staging_directory = os.path.join(mpacks_directory, "mystack-ambari-mpack-1.0.0.1") - dashboards_directory = serverConfiguration.get_dashboard_location(configs) + resources_directory = configs[serverConfiguration.RESOURCES_DIR_PROPERTY] + dashboards_directory = os.path.join(resources_directory, "dashboards") os_path_exists_calls = [call('/tmp/mystack-1.0.0.1.tar.gz'), call('mpacks/mystack-ambari-mpack-1.0.0.1/mpack.json'), + call('/var/lib/ambari-server/resources'), call(mpacks_directory), call(mpacks_directory + '/myextension-ambari-mpack-1.0.0.0/mpack.json'), call(mpacks_directory + '/myservice-ambari-mpack-1.0.0.0/mpack.json'), @@ -591,6 +622,7 @@ class TestMpacks(TestCase): call('/tmp/mystack-1.0.0.1.tar.gz'), call('mpacks/mystack-ambari-mpack-1.0.0.1/mpack.json'), call('mpacks/mystack-ambari-mpack-1.0.0.1/hooks/before_upgrade.py'), + call('/var/lib/ambari-server/resources'), call('/var/lib/ambari-server/resources/stacks'), call('/var/lib/ambari-server/resources/extensions'), call('/var/lib/ambari-server/resources/common-services'), @@ -598,6 +630,7 @@ class TestMpacks(TestCase): call(mpacks_directory + '/cache'), call('/var/lib/ambari-server/resources/dashboards'), call(mpacks_directory + '/mystack-ambari-mpack-1.0.0.1'), + call('/var/lib/ambari-server/resources'), call('/var/lib/ambari-server/resources/common-services/SERVICEA'), call(mpacks_directory + '/mystack-ambari-mpack-1.0.0.1/common-services/SERVICEA/1.0/dashboards'), call(mpacks_directory + '/mystack-ambari-mpack-1.0.0.1/common-services/SERVICEA/2.0/dashboards'), @@ -607,6 +640,7 @@ class TestMpacks(TestCase): call('/var/lib/ambari-server/resources/common-services/SERVICEC'), call(mpacks_directory + '/mystack-ambari-mpack-1.0.0.1/common-services/SERVICEC/1.0.0/dashboards'), call(mpacks_directory + '/mystack-ambari-mpack-1.0.0.1/common-services/SERVICEC/2.0.0/dashboards'), + call('/var/lib/ambari-server/resources'), call('/var/lib/ambari-server/resources/stacks/MYSTACK'), call('/var/lib/ambari-server/resources/stacks/MYSTACK/1.0'), call('/var/lib/ambari-server/resources/stacks/MYSTACK/1.0/services'), @@ -631,6 +665,7 @@ class TestMpacks(TestCase): call('/var/lib/ambari-server/resources/dashboards/grafana-dashboards/SERVICEC'), call(mpacks_directory + '/mystack-ambari-mpack-1.0.0.1/stacks/MYSTACK/3.0/services/SERVICEC/dashboards/service-metrics/SERVICEC.txt'), call('/var/lib/ambari-server/resources/dashboards/service-metrics/SERVICEC.txt'), + call('/var/lib/ambari-server/resources'), call(mpacks_directory), call(mpacks_directory + '/myextension-ambari-mpack-1.0.0.0/mpack.json'), call(mpacks_directory + '/myservice-ambari-mpack-1.0.0.0/mpack.json'), @@ -775,7 +810,7 @@ class TestMpacks(TestCase): serverConfiguration.COMMON_SERVICES_PATH_PROPERTY : os.path.join(uninstall_directory, "common-services"), serverConfiguration.EXTENSION_PATH_PROPERTY : os.path.join(uninstall_directory, "extensions"), serverConfiguration.MPACKS_STAGING_PATH_PROPERTY : mpacks_directory, - serverConfiguration.DASHBOARD_PATH_PROPERTY : os.path.join(uninstall_directory, "dashboards"), + serverConfiguration.RESOURCES_DIR_PROPERTY : uninstall_directory, serverConfiguration.SERVER_TMP_DIR_PROPERTY : "/tmp" } @@ -784,7 +819,8 @@ class TestMpacks(TestCase): stacks_directory = fake_configs[serverConfiguration.STACK_LOCATION_KEY] extension_directory = fake_configs[serverConfiguration.EXTENSION_PATH_PROPERTY] common_services_directory = fake_configs[serverConfiguration.COMMON_SERVICES_PATH_PROPERTY] - dashboard_directory = fake_configs[serverConfiguration.DASHBOARD_PATH_PROPERTY] + resources_directory = fake_configs[serverConfiguration.RESOURCES_DIR_PROPERTY] + dashboards_directory = os.path.join(resources_directory, "dashboards") _uninstall_mpack("mystack-ambari-mpack", "1.0.0.1") @@ -794,8 +830,8 @@ class TestMpacks(TestCase): call(os.path.join(stacks_directory, "2.0/files/metainfo2.xml")), call(os.path.join(extension_directory, "SERVICEB")), call(os.path.join(common_services_directory, "SERVICEB")), - call(os.path.join(dashboard_directory, "SERVICEB")), - call(os.path.join(dashboard_directory, "files/STORM.txt"))] + call(os.path.join(dashboards_directory, "SERVICEB")), + call(os.path.join(dashboards_directory, "files/STORM.txt"))] def _create_empty_options_mock(self): options = MagicMock() http://git-wip-us.apache.org/repos/asf/ambari/blob/4278c4a4/ambari-server/src/test/python/stacks/2.0.6/YARN/test_yarn_service_check.py ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/python/stacks/2.0.6/YARN/test_yarn_service_check.py b/ambari-server/src/test/python/stacks/2.0.6/YARN/test_yarn_service_check.py index bb671aa..fe7456d 100644 --- a/ambari-server/src/test/python/stacks/2.0.6/YARN/test_yarn_service_check.py +++ b/ambari-server/src/test/python/stacks/2.0.6/YARN/test_yarn_service_check.py @@ -22,11 +22,11 @@ import re from mock.mock import MagicMock, call, patch from stacks.utils.RMFTestCase import * -curl_call = MagicMock(return_value=(0, "{ \"app\": {\"state\": \"FINISHED\",\"finalStatus\": \"SUCCEEDED\"}}",'')) +curl_returns = [(0, "{\"clusterInfo\":{\"id\": \"1471586271500\",\"haState\": \"ACTIVE\"}}",''), + (0, "{\"app\":{\"state\": \"FINISHED\",\"finalStatus\":\"SUCCEEDED\"}}",'')] @patch("platform.linux_distribution", new = MagicMock(return_value="Linux")) @patch("sys.executable", new = '/usr/bin/python2.6') -@patch("resource_management.libraries.functions.get_user_call_output.get_user_call_output", new = curl_call) class TestServiceCheck(RMFTestCase): COMMON_SERVICES_PACKAGE_DIR = "YARN/2.1.0.2.0/package" STACK_VERSION = "2.0.6" @@ -38,32 +38,32 @@ class TestServiceCheck(RMFTestCase): re_search_mock.return_value = m m.group.return_value = "http://c6402.ambari.apache.org:8088/proxy/application_1429699682952_0010/" - self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/service_check.py", - classname="ServiceCheck", - command="service_check", - config_file="default.json", - stack_version = self.STACK_VERSION, - target = RMFTestCase.TARGET_COMMON_SERVICES, - checked_call_mocks = [(0, "some test text, appTrackingUrl=http:" - "//c6402.ambari.apache.org:8088/proxy/application_1429885383763_0001/, some test text")] - ) - self.assertResourceCalled('HdfsResource', '/user/ambari-qa', - immutable_paths = self.DEFAULT_IMMUTABLE_PATHS, - security_enabled = False, - hadoop_bin_dir = '/usr/bin', - keytab = UnknownConfigurationMock(), - kinit_path_local = '/usr/bin/kinit', - user = 'hdfs', - dfs_type = '', - mode = 0770, - owner = 'ambari-qa', - action = ['create_on_execute'], hdfs_resource_ignore_file='/var/lib/ambari-agent/data/.hdfs_resource_ignore', hdfs_site=self.getConfig()['configurations']['hdfs-site'], principal_name=UnknownConfigurationMock(), default_fs='hdfs://c6401.ambari.apache.org:8020', - hadoop_conf_dir = '/etc/hadoop/conf', - type = 'directory', - ) - self.assertCurlCallForwardsCredentialsOnRedirect() - self.assertNoMoreResources() - + with patch("resource_management.libraries.functions.get_user_call_output.get_user_call_output", side_effect = curl_returns) as mock_curl: + self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/service_check.py", + classname="ServiceCheck", + command="service_check", + config_file="default.json", + stack_version = self.STACK_VERSION, + target = RMFTestCase.TARGET_COMMON_SERVICES, + checked_call_mocks = [(0, "some test text, appTrackingUrl=http:" + "//c6402.ambari.apache.org:8088/proxy/application_1429885383763_0001/, some test text")] + ) + self.assertResourceCalled('HdfsResource', '/user/ambari-qa', + immutable_paths = self.DEFAULT_IMMUTABLE_PATHS, + security_enabled = False, + hadoop_bin_dir = '/usr/bin', + keytab = UnknownConfigurationMock(), + kinit_path_local = '/usr/bin/kinit', + user = 'hdfs', + dfs_type = '', + mode = 0770, + owner = 'ambari-qa', + action = ['create_on_execute'], hdfs_resource_ignore_file='/var/lib/ambari-agent/data/.hdfs_resource_ignore', hdfs_site=self.getConfig()['configurations']['hdfs-site'], principal_name=UnknownConfigurationMock(), default_fs='hdfs://c6401.ambari.apache.org:8020', + hadoop_conf_dir = '/etc/hadoop/conf', + type = 'directory', + ) + self.assertCurlCallForwardsCredentialsOnRedirect(mock_curl_call = mock_curl) + self.assertNoMoreResources() @patch("re.search") def test_service_check_secured(self, re_search_mock): @@ -71,31 +71,32 @@ class TestServiceCheck(RMFTestCase): re_search_mock.return_value = m m.group.return_value = "http://c6402.ambari.apache.org:8088/proxy/application_1429699682952_0010/" - self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/service_check.py", - classname="ServiceCheck", - command="service_check", - config_file="secured.json", - stack_version = self.STACK_VERSION, - target = RMFTestCase.TARGET_COMMON_SERVICES, - checked_call_mocks = [(0, "some test text, appTrackingUrl=http:" - "//c6402.ambari.apache.org:8088/proxy/application_1429885383763_0001/, some test text")] - ) - self.assertResourceCalled('HdfsResource', '/user/ambari-qa', - immutable_paths = self.DEFAULT_IMMUTABLE_PATHS, - security_enabled = True, - hadoop_bin_dir = '/usr/bin', - keytab = '/etc/security/keytabs/hdfs.headless.keytab', - kinit_path_local = '/usr/bin/kinit', - user = 'hdfs', - dfs_type = '', - mode = 0770, - owner = 'ambari-qa', - action = ['create_on_execute'], hdfs_resource_ignore_file='/var/lib/ambari-agent/data/.hdfs_resource_ignore', hdfs_site=self.getConfig()['configurations']['hdfs-site'], principal_name='hdfs', default_fs='hdfs://c6401.ambari.apache.org:8020', - hadoop_conf_dir = '/etc/hadoop/conf', - type = 'directory', - ) - self.assertCurlCallForwardsCredentialsOnRedirect() - self.assertNoMoreResources() + with patch("resource_management.libraries.functions.get_user_call_output.get_user_call_output", side_effect = curl_returns) as mock_curl: + self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/service_check.py", + classname="ServiceCheck", + command="service_check", + config_file="secured.json", + stack_version = self.STACK_VERSION, + target = RMFTestCase.TARGET_COMMON_SERVICES, + checked_call_mocks = [(0, "some test text, appTrackingUrl=http:" + "//c6402.ambari.apache.org:8088/proxy/application_1429885383763_0001/, some test text")] + ) + self.assertResourceCalled('HdfsResource', '/user/ambari-qa', + immutable_paths = self.DEFAULT_IMMUTABLE_PATHS, + security_enabled = True, + hadoop_bin_dir = '/usr/bin', + keytab = '/etc/security/keytabs/hdfs.headless.keytab', + kinit_path_local = '/usr/bin/kinit', + user = 'hdfs', + dfs_type = '', + mode = 0770, + owner = 'ambari-qa', + action = ['create_on_execute'], hdfs_resource_ignore_file='/var/lib/ambari-agent/data/.hdfs_resource_ignore', hdfs_site=self.getConfig()['configurations']['hdfs-site'], principal_name='hdfs', default_fs='hdfs://c6401.ambari.apache.org:8020', + hadoop_conf_dir = '/etc/hadoop/conf', + type = 'directory', + ) + self.assertCurlCallForwardsCredentialsOnRedirect(mock_curl_call = mock_curl) + self.assertNoMoreResources() - def assertCurlCallForwardsCredentialsOnRedirect(self): - self.assertIn('--location-trusted', curl_call.call_args[0][0]) \ No newline at end of file + def assertCurlCallForwardsCredentialsOnRedirect(self, mock_curl_call): + self.assertIn('--location-trusted', mock_curl_call.call_args[0][0]) http://git-wip-us.apache.org/repos/asf/ambari/blob/4278c4a4/ambari-server/src/test/python/stacks/2.0.6/common/test_stack_advisor.py ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/python/stacks/2.0.6/common/test_stack_advisor.py b/ambari-server/src/test/python/stacks/2.0.6/common/test_stack_advisor.py index 4c6c2a3..4fa9e02 100644 --- a/ambari-server/src/test/python/stacks/2.0.6/common/test_stack_advisor.py +++ b/ambari-server/src/test/python/stacks/2.0.6/common/test_stack_advisor.py @@ -1195,8 +1195,10 @@ class TestHDP206StackAdvisor(TestCase): {'properties': {'falcon_user': 'falcon'}}, 'hdfs-site': - {'properties': + {'properties': {'dfs.datanode.data.dir': '/hadoop/hdfs/data', + 'dfs.namenode.name.dir': '/hadoop/hdfs/namenode', + 'dfs.namenode.checkpoint.dir': '/hadoop/hdfs/namesecondary', 'dfs.datanode.du.reserved': '10240000000'}}, 'hive-env': {'properties': @@ -1330,6 +1332,8 @@ class TestHDP206StackAdvisor(TestCase): 'hdfs-site': {'properties': {'dfs.datanode.data.dir': '/hadoop/hdfs/data', + 'dfs.namenode.name.dir': '/hadoop/hdfs/namenode', + 'dfs.namenode.checkpoint.dir': '/hadoop/hdfs/namesecondary', 'dfs.datanode.du.reserved': '10240000000'}}, 'hive-env': {'properties': @@ -1463,8 +1467,10 @@ class TestHDP206StackAdvisor(TestCase): {'hive_user': 'hive', 'webhcat_user': 'webhcat'}}, 'hdfs-site': - {'properties': + {'properties': {'dfs.datanode.data.dir': '/hadoop/hdfs/data', + 'dfs.namenode.name.dir': '/hadoop/hdfs/namenode', + 'dfs.namenode.checkpoint.dir': '/hadoop/hdfs/namesecondary', 'dfs.datanode.du.reserved': '10240000000'}}, 'hadoop-env': {'properties': @@ -1484,10 +1490,12 @@ class TestHDP206StackAdvisor(TestCase): expected["hdfs-site"] = { 'properties': { - 'dfs.datanode.data.dir': '/hadoop/hdfs/data', 'dfs.datanode.du.reserved': '10240000000', 'dfs.internal.nameservices': 'mycluster', - 'dfs.ha.namenodes.mycluster': 'nn1,nn2' + 'dfs.ha.namenodes.mycluster': 'nn1,nn2', + 'dfs.datanode.data.dir': '/hadoop/hdfs/data', + 'dfs.namenode.name.dir': '/hadoop/hdfs/namenode', + 'dfs.namenode.checkpoint.dir': '/hadoop/hdfs/namesecondary', }, 'property_attributes': { 'dfs.namenode.rpc-address': {