http://git-wip-us.apache.org/repos/asf/ambari/blob/56362fd6/ambari-server/src/test/java/org/apache/ambari/server/serveraction/kerberos/UpdateKerberosConfigsServerActionTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/serveraction/kerberos/UpdateKerberosConfigsServerActionTest.java b/ambari-server/src/test/java/org/apache/ambari/server/serveraction/kerberos/UpdateKerberosConfigsServerActionTest.java index 733d815..021186b 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/serveraction/kerberos/UpdateKerberosConfigsServerActionTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/serveraction/kerberos/UpdateKerberosConfigsServerActionTest.java @@ -35,14 +35,17 @@ import org.apache.ambari.server.controller.AmbariManagementController; import org.apache.ambari.server.state.Cluster; import org.apache.ambari.server.state.Clusters; import org.apache.ambari.server.state.ConfigHelper; +import org.apache.ambari.server.state.StackId; import org.apache.ambari.server.state.stack.OsFamily; import org.easymock.Capture; import org.easymock.CaptureType; +import org.easymock.EasyMock; import org.easymock.EasyMockSupport; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; + import com.google.inject.AbstractModule; import com.google.inject.Guice; import com.google.inject.Injector; @@ -95,15 +98,15 @@ public class UpdateKerberosConfigsServerActionTest extends EasyMockSupport{ @Test public void testUpdateConfig() throws Exception { - Map<String, String> commandParams = new HashMap<String, String>(); + Map<String, String> commandParams = new HashMap<>(); commandParams.put(KerberosServerAction.DATA_DIRECTORY, dataDir); ExecutionCommand executionCommand = new ExecutionCommand(); executionCommand.setCommandParams(commandParams); ConfigHelper configHelper = injector.getInstance(ConfigHelper.class); - configHelper.updateConfigType(anyObject(Cluster.class), anyObject(AmbariManagementController.class), - anyObject(String.class), anyObject(Map.class), anyObject(Collection.class), anyObject(String.class), anyObject(String.class)); + configHelper.updateConfigType(anyObject(Cluster.class), anyObject(StackId.class), anyObject(AmbariManagementController.class), + anyObject(String.class), EasyMock.<Map<String, String>>anyObject(), EasyMock.<Collection<String>>anyObject(), anyObject(String.class), anyObject(String.class)); expectLastCall().atLeastOnce(); replayAll(); @@ -117,7 +120,7 @@ public class UpdateKerberosConfigsServerActionTest extends EasyMockSupport{ @Test public void testUpdateConfigMissingDataDirectory() throws Exception { ExecutionCommand executionCommand = new ExecutionCommand(); - Map<String, String> commandParams = new HashMap<String, String>(); + Map<String, String> commandParams = new HashMap<>(); executionCommand.setCommandParams(commandParams); replayAll(); @@ -131,7 +134,7 @@ public class UpdateKerberosConfigsServerActionTest extends EasyMockSupport{ @Test public void testUpdateConfigEmptyDataDirectory() throws Exception { ExecutionCommand executionCommand = new ExecutionCommand(); - Map<String, String> commandParams = new HashMap<String, String>(); + Map<String, String> commandParams = new HashMap<>(); commandParams.put(KerberosServerAction.DATA_DIRECTORY, testFolder.newFolder().getAbsolutePath()); executionCommand.setCommandParams(commandParams); @@ -145,7 +148,7 @@ public class UpdateKerberosConfigsServerActionTest extends EasyMockSupport{ @Test public void testUpdateConfigForceSecurityEnabled() throws Exception { - Map<String, String> commandParams = new HashMap<String, String>(); + Map<String, String> commandParams = new HashMap<>(); commandParams.put(KerberosServerAction.DATA_DIRECTORY, dataDir); ExecutionCommand executionCommand = new ExecutionCommand(); @@ -155,7 +158,7 @@ public class UpdateKerberosConfigsServerActionTest extends EasyMockSupport{ Capture<String> configTypes = Capture.newInstance(CaptureType.ALL); Capture<Map<String, String>> configUpdates = Capture.newInstance(CaptureType.ALL); - configHelper.updateConfigType(anyObject(Cluster.class), anyObject(AmbariManagementController.class), + configHelper.updateConfigType(anyObject(Cluster.class), anyObject(StackId.class), anyObject(AmbariManagementController.class), capture(configTypes), capture(configUpdates), anyObject(Collection.class), anyObject(String.class), anyObject(String.class)); expectLastCall().atLeastOnce(); @@ -177,4 +180,4 @@ public class UpdateKerberosConfigsServerActionTest extends EasyMockSupport{ } -} +} \ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ambari/blob/56362fd6/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/ConfigureActionTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/ConfigureActionTest.java b/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/ConfigureActionTest.java index 976dea4..731e100 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/ConfigureActionTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/ConfigureActionTest.java @@ -1,4 +1,4 @@ -/** +/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -32,6 +32,7 @@ import javax.persistence.EntityManager; import org.apache.ambari.server.AmbariException; import org.apache.ambari.server.H2DatabaseCleaner; +import org.apache.ambari.server.ServiceComponentNotFoundException; import org.apache.ambari.server.ServiceNotFoundException; import org.apache.ambari.server.actionmanager.ExecutionCommandWrapper; import org.apache.ambari.server.actionmanager.HostRoleCommand; @@ -41,12 +42,12 @@ import org.apache.ambari.server.agent.ExecutionCommand; import org.apache.ambari.server.orm.GuiceJpaInitializer; import org.apache.ambari.server.orm.InMemoryDefaultTestModule; import org.apache.ambari.server.orm.OrmTestHelper; -import org.apache.ambari.server.orm.dao.HostDAO; -import org.apache.ambari.server.orm.dao.HostVersionDAO; -import org.apache.ambari.server.orm.dao.RepositoryVersionDAO; -import org.apache.ambari.server.orm.dao.StackDAO; -import org.apache.ambari.server.orm.entities.HostVersionEntity; -import org.apache.ambari.server.orm.entities.StackEntity; +import org.apache.ambari.server.orm.dao.RequestDAO; +import org.apache.ambari.server.orm.dao.UpgradeDAO; +import org.apache.ambari.server.orm.entities.RepositoryVersionEntity; +import org.apache.ambari.server.orm.entities.RequestEntity; +import org.apache.ambari.server.orm.entities.UpgradeEntity; +import org.apache.ambari.server.orm.entities.UpgradeHistoryEntity; import org.apache.ambari.server.serveraction.ServerAction; import org.apache.ambari.server.state.Cluster; import org.apache.ambari.server.state.Clusters; @@ -54,10 +55,14 @@ 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.Host; -import org.apache.ambari.server.state.RepositoryVersionState; import org.apache.ambari.server.state.Service; +import org.apache.ambari.server.state.ServiceComponent; +import org.apache.ambari.server.state.ServiceComponentFactory; +import org.apache.ambari.server.state.ServiceComponentHost; +import org.apache.ambari.server.state.ServiceComponentHostFactory; import org.apache.ambari.server.state.ServiceFactory; import org.apache.ambari.server.state.StackId; +import org.apache.ambari.server.state.State; import org.apache.ambari.server.state.stack.upgrade.ConfigUpgradeChangeDefinition.ConfigurationKeyValue; import org.apache.ambari.server.state.stack.upgrade.ConfigUpgradeChangeDefinition.Insert; import org.apache.ambari.server.state.stack.upgrade.ConfigUpgradeChangeDefinition.InsertType; @@ -67,7 +72,10 @@ import org.apache.ambari.server.state.stack.upgrade.ConfigureTask; import org.apache.ambari.server.state.stack.upgrade.PropertyKeyState; import org.apache.ambari.server.state.stack.upgrade.TransferCoercionType; import org.apache.ambari.server.state.stack.upgrade.TransferOperation; +import org.apache.ambari.server.state.stack.upgrade.UpgradeType; +import org.apache.commons.lang.StringUtils; import org.junit.After; +import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -81,41 +89,62 @@ import com.google.inject.Injector; */ public class ConfigureActionTest { - private static final String HDP_2_2_0_0 = "2.2.0.0-2041"; - private static final String HDP_2_2_0_1 = "2.2.0.1-2270"; - private static final StackId HDP_211_STACK = new StackId("HDP-2.1.1"); - private static final StackId HDP_220_STACK = new StackId("HDP-2.2.0"); - @Inject private Injector m_injector; + @Inject private OrmTestHelper m_helper; - @Inject - private RepositoryVersionDAO repoVersionDAO; - @Inject - private HostVersionDAO hostVersionDAO; + @Inject private HostRoleCommandFactory hostRoleCommandFactory; + @Inject private ServiceFactory serviceFactory; + @Inject private ConfigHelper m_configHelper; + @Inject private Clusters clusters; + @Inject - private ConfigFactory cf; + private ConfigFactory configFactory; + @Inject private ConfigureAction action; + @Inject - private HostDAO hostDAO; + private RequestDAO requestDAO; + + @Inject + private UpgradeDAO upgradeDAO; + @Inject - private StackDAO stackDAO; + private ServiceComponentFactory serviceComponentFactory; + + @Inject + private ServiceComponentHostFactory serviceComponentHostFactory; + + private RepositoryVersionEntity repoVersion2110; + private RepositoryVersionEntity repoVersion2111; + private RepositoryVersionEntity repoVersion2200; + + private final Map<String, Map<String, String>> NO_ATTRIBUTES = new HashMap<>(); @Before public void setup() throws Exception { m_injector = Guice.createInjector(new InMemoryDefaultTestModule()); m_injector.getInstance(GuiceJpaInitializer.class); m_injector.injectMembers(this); + + repoVersion2110 = m_helper.getOrCreateRepositoryVersion(new StackId("HDP-2.1.1"), + "2.1.1.0-1234"); + repoVersion2111 = m_helper.getOrCreateRepositoryVersion(new StackId("HDP-2.1.1"), + "2.1.1.1-5678"); + repoVersion2200 = m_helper.getOrCreateRepositoryVersion(new StackId("HDP-2.2.0"), + "2.2.0.0-1234"); + + makeUpgradeCluster(); } @After @@ -124,18 +153,24 @@ public class ConfigureActionTest { } + /** + * Tests that a new configuration is created when upgrading across stack when + * there is no existing configuration with the correct target stack. + * + * @throws Exception + */ @Test - public void testConfigActionUpgradeAcrossStack() throws Exception { - makeUpgradeCluster(); - + public void testNewConfigCreatedWhenUpgradingAcrossStacks() throws Exception { Cluster c = clusters.getCluster("c1"); assertEquals(1, c.getConfigsByType("zoo.cfg").size()); - c.setCurrentStackVersion(HDP_211_STACK); - c.setDesiredStackVersion(HDP_220_STACK); - Config config = cf.createNew(c, "zoo.cfg", "version2", new HashMap<String, String>() {{ - put("initLimit", "10"); - }}, new HashMap<String, Map<String,String>>()); + Map<String, String> properties = new HashMap<String, String>() { + { + put("initLimit", "10"); + } + }; + + Config config = createConfig(c, repoVersion2110, "zoo.cfg", "version2", properties); c.addDesiredConfig("user", Collections.singleton(config)); assertEquals(2, c.getConfigsByType("zoo.cfg").size()); @@ -146,23 +181,73 @@ public class ConfigureActionTest { keyValue.key = "initLimit"; keyValue.value = "11"; + createUpgrade(c, repoVersion2200); + Map<String, String> commandParams = new HashMap<>(); - commandParams.put("upgrade_direction", "upgrade"); - commandParams.put("version", HDP_2_2_0_1); commandParams.put("clusterName", "c1"); commandParams.put(ConfigureTask.PARAMETER_CONFIG_TYPE, "zoo.cfg"); commandParams.put(ConfigureTask.PARAMETER_KEY_VALUE_PAIRS, new Gson().toJson(configurations)); - ExecutionCommand executionCommand = new ExecutionCommand(); - executionCommand.setCommandParams(commandParams); - executionCommand.setClusterName("c1"); - + ExecutionCommand executionCommand = getExecutionCommand(commandParams); HostRoleCommand hostRoleCommand = hostRoleCommandFactory.create(null, null, null, null); hostRoleCommand.setExecutionCommandWrapper(new ExecutionCommandWrapper( executionCommand)); + action.setExecutionCommand(executionCommand); + action.setHostRoleCommand(hostRoleCommand); + + CommandReport report = action.execute(null); + assertNotNull(report); + + assertEquals(3, c.getConfigsByType("zoo.cfg").size()); + + config = c.getDesiredConfigByType("zoo.cfg"); + assertNotNull(config); + assertFalse(StringUtils.equals("version2", config.getTag())); + assertEquals("11", config.getProperties().get("initLimit")); + } + + /** + * Tests that if a configuration with the target stack already exists, then it + * will be re-used instead of a new one created. + * + * @throws Exception + */ + @Test + public void testConfigurationWithTargetStackUsed() throws Exception { + Cluster c = clusters.getCluster("c1"); + assertEquals(1, c.getConfigsByType("zoo.cfg").size()); + + Map<String, String> properties = new HashMap<String, String>() { + { + put("initLimit", "10"); + } + }; + + Config config = createConfig(c, repoVersion2200, "zoo.cfg", "version2", properties); + + c.addDesiredConfig("user", Collections.singleton(config)); + assertEquals(2, c.getConfigsByType("zoo.cfg").size()); + + List<ConfigurationKeyValue> configurations = new ArrayList<>(); + ConfigurationKeyValue keyValue = new ConfigurationKeyValue(); + configurations.add(keyValue); + keyValue.key = "initLimit"; + keyValue.value = "11"; + + createUpgrade(c, repoVersion2200); + + Map<String, String> commandParams = new HashMap<>(); + commandParams.put("clusterName", "c1"); + commandParams.put(ConfigureTask.PARAMETER_CONFIG_TYPE, "zoo.cfg"); + commandParams.put(ConfigureTask.PARAMETER_KEY_VALUE_PAIRS, new Gson().toJson(configurations)); + + ExecutionCommand executionCommand = getExecutionCommand(commandParams); + HostRoleCommand hostRoleCommand = hostRoleCommandFactory.create(null, null, null, null); + + hostRoleCommand.setExecutionCommandWrapper(new ExecutionCommandWrapper(executionCommand)); action.setExecutionCommand(executionCommand); action.setHostRoleCommand(hostRoleCommand); @@ -185,31 +270,29 @@ public class ConfigureActionTest { */ @Test public void testDeletePreserveChanges() throws Exception { - makeUpgradeCluster(); - Cluster c = clusters.getCluster("c1"); assertEquals(1, c.getConfigsByType("zoo.cfg").size()); - c.setDesiredStackVersion(HDP_220_STACK); - // create a config for zoo.cfg with two values; one is a stack value and the // other is custom - Config config = cf.createNew(c, "zoo.cfg", "version2", new HashMap<String, String>() { + Map<String, String> properties = new HashMap<String, String>() { { put("tickTime", "2000"); put("foo", "bar"); } - }, new HashMap<String, Map<String, String>>()); + }; + + Config config = createConfig(c, repoVersion2110, "zoo.cfg", "version2", properties); c.addDesiredConfig("user", Collections.singleton(config)); assertEquals(2, c.getConfigsByType("zoo.cfg").size()); Map<String, String> commandParams = new HashMap<>(); - commandParams.put("upgrade_direction", "upgrade"); - commandParams.put("version", HDP_2_2_0_1); commandParams.put("clusterName", "c1"); commandParams.put(ConfigureTask.PARAMETER_CONFIG_TYPE, "zoo.cfg"); + createUpgrade(c, repoVersion2111); + // delete all keys, preserving edits or additions List<Transfer> transfers = new ArrayList<>(); Transfer transfer = new Transfer(); @@ -220,16 +303,10 @@ public class ConfigureActionTest { commandParams.put(ConfigureTask.PARAMETER_TRANSFERS, new Gson().toJson(transfers)); - ExecutionCommand executionCommand = new ExecutionCommand(); - executionCommand.setCommandParams(commandParams); - executionCommand.setClusterName("c1"); - executionCommand.setRoleParams(new HashMap<String, String>()); - executionCommand.getRoleParams().put(ServerAction.ACTION_USER_NAME, "username"); - + ExecutionCommand executionCommand = getExecutionCommand(commandParams); HostRoleCommand hostRoleCommand = hostRoleCommandFactory.create(null, null, null, null); hostRoleCommand.setExecutionCommandWrapper(new ExecutionCommandWrapper(executionCommand)); - action.setExecutionCommand(executionCommand); action.setHostRoleCommand(hostRoleCommand); @@ -251,18 +328,19 @@ public class ConfigureActionTest { @Test public void testConfigTransferCopy() throws Exception { - makeUpgradeCluster(); - Cluster c = clusters.getCluster("c1"); assertEquals(1, c.getConfigsByType("zoo.cfg").size()); - c.setDesiredStackVersion(HDP_220_STACK); - Config config = cf.createNew(c, "zoo.cfg", "version2", new HashMap<String, String>() {{ - put("initLimit", "10"); - put("copyIt", "10"); - put("moveIt", "10"); - put("deleteIt", "10"); - }}, new HashMap<String, Map<String,String>>()); + Map<String, String> properties = new HashMap<String, String>() { + { + put("initLimit", "10"); + put("copyIt", "10"); + put("moveIt", "10"); + put("deleteIt", "10"); + } + }; + + Config config = createConfig(c, repoVersion2110, "zoo.cfg", "version2", properties); c.addDesiredConfig("user", Collections.singleton(config)); assertEquals(2, c.getConfigsByType("zoo.cfg").size()); @@ -273,9 +351,9 @@ public class ConfigureActionTest { keyValue.key = "initLimit"; keyValue.value = "11"; + createUpgrade(c, repoVersion2111); + Map<String, String> commandParams = new HashMap<>(); - commandParams.put("upgrade_direction", "upgrade"); - commandParams.put("version", HDP_2_2_0_1); commandParams.put("clusterName", "c1"); commandParams.put(ConfigureTask.PARAMETER_CONFIG_TYPE, "zoo.cfg"); commandParams.put(ConfigureTask.PARAMETER_KEY_VALUE_PAIRS, new Gson().toJson(configurations)); @@ -319,12 +397,7 @@ public class ConfigureActionTest { commandParams.put(ConfigureTask.PARAMETER_TRANSFERS, new Gson().toJson(transfers)); - ExecutionCommand executionCommand = new ExecutionCommand(); - executionCommand.setCommandParams(commandParams); - executionCommand.setClusterName("c1"); - executionCommand.setRoleParams(new HashMap<String, String>()); - executionCommand.getRoleParams().put(ServerAction.ACTION_USER_NAME, "username"); - + ExecutionCommand executionCommand = getExecutionCommand(commandParams); HostRoleCommand hostRoleCommand = hostRoleCommandFactory.create(null, null, null, null); @@ -388,24 +461,23 @@ public class ConfigureActionTest { @Test public void testCoerceValueOnCopy() throws Exception { - makeUpgradeCluster(); - Cluster c = clusters.getCluster("c1"); assertEquals(1, c.getConfigsByType("zoo.cfg").size()); - c.setDesiredStackVersion(HDP_220_STACK); - Config config = cf.createNew(c, "zoo.cfg", "version2", new HashMap<String, String>() { + Map<String, String> properties = new HashMap<String, String>() { { put("zoo.server.csv", "c6401,c6402, c6403"); } - }, new HashMap<String, Map<String, String>>()); + }; + + Config config = createConfig(c, repoVersion2110, "zoo.cfg", "version2", properties); c.addDesiredConfig("user", Collections.singleton(config)); assertEquals(2, c.getConfigsByType("zoo.cfg").size()); + createUpgrade(c, repoVersion2111); + Map<String, String> commandParams = new HashMap<>(); - commandParams.put("upgrade_direction", "upgrade"); - commandParams.put("version", HDP_2_2_0_1); commandParams.put("clusterName", "c1"); commandParams.put(ConfigureTask.PARAMETER_CONFIG_TYPE, "zoo.cfg"); @@ -421,12 +493,7 @@ public class ConfigureActionTest { commandParams.put(ConfigureTask.PARAMETER_TRANSFERS, new Gson().toJson(transfers)); - ExecutionCommand executionCommand = new ExecutionCommand(); - executionCommand.setCommandParams(commandParams); - executionCommand.setClusterName("c1"); - executionCommand.setRoleParams(new HashMap<String, String>()); - executionCommand.getRoleParams().put(ServerAction.ACTION_USER_NAME, "username"); - + ExecutionCommand executionCommand = getExecutionCommand(commandParams); HostRoleCommand hostRoleCommand = hostRoleCommandFactory.create(null, null, null, null); hostRoleCommand.setExecutionCommandWrapper(new ExecutionCommandWrapper(executionCommand)); @@ -451,25 +518,24 @@ public class ConfigureActionTest { @Test public void testValueReplacement() throws Exception { - makeUpgradeCluster(); - Cluster c = clusters.getCluster("c1"); assertEquals(1, c.getConfigsByType("zoo.cfg").size()); - c.setDesiredStackVersion(HDP_220_STACK); - Config config = cf.createNew(c, "zoo.cfg", "version2", new HashMap<String, String>() { + Map<String, String> properties = new HashMap<String, String>() { { put("key_to_replace", "My New Cat"); put("key_with_no_match", "WxyAndZ"); } - }, new HashMap<String, Map<String, String>>()); + }; + + Config config = createConfig(c, repoVersion2110, "zoo.cfg", "version2", properties); c.addDesiredConfig("user", Collections.singleton(config)); assertEquals(2, c.getConfigsByType("zoo.cfg").size()); + createUpgrade(c, repoVersion2111); + Map<String, String> commandParams = new HashMap<>(); - commandParams.put("upgrade_direction", "upgrade"); - commandParams.put("version", HDP_2_2_0_1); commandParams.put("clusterName", "c1"); commandParams.put(ConfigureTask.PARAMETER_CONFIG_TYPE, "zoo.cfg"); @@ -489,12 +555,7 @@ public class ConfigureActionTest { commandParams.put(ConfigureTask.PARAMETER_REPLACEMENTS, new Gson().toJson(replacements)); - ExecutionCommand executionCommand = new ExecutionCommand(); - executionCommand.setCommandParams(commandParams); - executionCommand.setClusterName("c1"); - executionCommand.setRoleParams(new HashMap<String, String>()); - executionCommand.getRoleParams().put(ServerAction.ACTION_USER_NAME, "username"); - + ExecutionCommand executionCommand = getExecutionCommand(commandParams); HostRoleCommand hostRoleCommand = hostRoleCommandFactory.create(null, null, null, null); hostRoleCommand.setExecutionCommandWrapper(new ExecutionCommandWrapper(executionCommand)); @@ -523,25 +584,24 @@ public class ConfigureActionTest { */ @Test public void testValueReplacementWithMissingConfigurations() throws Exception { - makeUpgradeCluster(); - Cluster c = clusters.getCluster("c1"); assertEquals(1, c.getConfigsByType("zoo.cfg").size()); - c.setDesiredStackVersion(HDP_220_STACK); - Config config = cf.createNew(c, "zoo.cfg", "version2", new HashMap<String, String>() { + Map<String, String> properties = new HashMap<String, String>() { { put("existing", "This exists!"); put("missing", null); } - }, new HashMap<String, Map<String, String>>()); + }; + + Config config = createConfig(c, repoVersion2110, "zoo.cfg", "version2", properties); c.addDesiredConfig("user", Collections.singleton(config)); assertEquals(2, c.getConfigsByType("zoo.cfg").size()); + createUpgrade(c, repoVersion2111); + Map<String, String> commandParams = new HashMap<>(); - commandParams.put("upgrade_direction", "upgrade"); - commandParams.put("version", HDP_2_2_0_1); commandParams.put("clusterName", "c1"); commandParams.put(ConfigureTask.PARAMETER_CONFIG_TYPE, "zoo.cfg"); @@ -580,18 +640,16 @@ public class ConfigureActionTest { @Test public void testMultipleKeyValuesPerTask() throws Exception { - makeUpgradeCluster(); - Cluster c = clusters.getCluster("c1"); assertEquals(1, c.getConfigsByType("zoo.cfg").size()); - c.setCurrentStackVersion(HDP_211_STACK); - c.setDesiredStackVersion(HDP_220_STACK); - Config config = cf.createNew(c, "zoo.cfg", "version2", new HashMap<String, String>() { + Map<String, String> properties = new HashMap<String, String>() { { put("fooKey", "barValue"); } - }, new HashMap<String, Map<String, String>>()); + }; + + Config config = createConfig(c, repoVersion2200, "zoo.cfg", "version2", properties); c.addDesiredConfig("user", Collections.singleton(config)); assertEquals(2, c.getConfigsByType("zoo.cfg").size()); @@ -609,17 +667,14 @@ public class ConfigureActionTest { fooKey3.value = "barValue3"; fooKey3.mask = true; + createUpgrade(c, repoVersion2200); + Map<String, String> commandParams = new HashMap<>(); - commandParams.put("upgrade_direction", "upgrade"); - commandParams.put("version", HDP_2_2_0_1); commandParams.put("clusterName", "c1"); commandParams.put(ConfigureTask.PARAMETER_CONFIG_TYPE, "zoo.cfg"); commandParams.put(ConfigureTask.PARAMETER_KEY_VALUE_PAIRS, new Gson().toJson(configurations)); - ExecutionCommand executionCommand = new ExecutionCommand(); - executionCommand.setCommandParams(commandParams); - executionCommand.setClusterName("c1"); - + ExecutionCommand executionCommand = getExecutionCommand(commandParams); HostRoleCommand hostRoleCommand = hostRoleCommandFactory.create(null, null, null, null); hostRoleCommand.setExecutionCommandWrapper(new ExecutionCommandWrapper(executionCommand)); @@ -643,21 +698,19 @@ public class ConfigureActionTest { @Test public void testAllowedSet() throws Exception { - makeUpgradeCluster(); - Cluster c = clusters.getCluster("c1"); assertEquals(1, c.getConfigsByType("zoo.cfg").size()); - c.setCurrentStackVersion(HDP_211_STACK); - c.setDesiredStackVersion(HDP_220_STACK); - Config config = cf.createNew(c, "zoo.cfg", "version2", new HashMap<String, String>() { + Map<String, String> properties = new HashMap<String, String>() { { put("set.key.1", "s1"); put("set.key.2", "s2"); put("set.key.3", "s3"); put("set.key.4", "s4"); } - }, new HashMap<String, Map<String, String>>()); + }; + + Config config = createConfig(c, repoVersion2200, "zoo.cfg", "version2", properties); c.addDesiredConfig("user", Collections.singleton(config)); assertEquals(2, c.getConfigsByType("zoo.cfg").size()); @@ -698,18 +751,14 @@ public class ConfigureActionTest { fooKey5.ifType = "zoo.cfg"; fooKey5.ifKeyState= PropertyKeyState.ABSENT; + createUpgrade(c, repoVersion2200); Map<String, String> commandParams = new HashMap<>(); - commandParams.put("upgrade_direction", "upgrade"); - commandParams.put("version", HDP_2_2_0_1); commandParams.put("clusterName", "c1"); commandParams.put(ConfigureTask.PARAMETER_CONFIG_TYPE, "zoo.cfg"); commandParams.put(ConfigureTask.PARAMETER_KEY_VALUE_PAIRS, new Gson().toJson(configurations)); - ExecutionCommand executionCommand = new ExecutionCommand(); - executionCommand.setCommandParams(commandParams); - executionCommand.setClusterName("c1"); - + ExecutionCommand executionCommand = getExecutionCommand(commandParams); HostRoleCommand hostRoleCommand = hostRoleCommandFactory.create(null, null, null, null); hostRoleCommand.setExecutionCommandWrapper(new ExecutionCommandWrapper(executionCommand)); @@ -737,21 +786,19 @@ public class ConfigureActionTest { @Test public void testDisallowedSet() throws Exception { - makeUpgradeCluster(); - Cluster c = clusters.getCluster("c1"); assertEquals(1, c.getConfigsByType("zoo.cfg").size()); - c.setCurrentStackVersion(HDP_211_STACK); - c.setDesiredStackVersion(HDP_220_STACK); - Config config = cf.createNew(c, "zoo.cfg", "version2", new HashMap<String, String>() { + Map<String, String> properties = new HashMap<String, String>() { { put("set.key.1", "s1"); put("set.key.2", "s2"); put("set.key.3", "s3"); put("set.key.4", "s4"); } - }, new HashMap<String, Map<String, String>>()); + }; + + Config config = createConfig(c, repoVersion2200, "zoo.cfg", "version2", properties); c.addDesiredConfig("user", Collections.singleton(config)); assertEquals(2, c.getConfigsByType("zoo.cfg").size()); @@ -782,18 +829,14 @@ public class ConfigureActionTest { fooKey5.ifType = "zoo.cfg"; fooKey5.ifKeyState= PropertyKeyState.PRESENT; + createUpgrade(c, repoVersion2200); Map<String, String> commandParams = new HashMap<>(); - commandParams.put("upgrade_direction", "upgrade"); - commandParams.put("version", HDP_2_2_0_1); commandParams.put("clusterName", "c1"); commandParams.put(ConfigureTask.PARAMETER_CONFIG_TYPE, "zoo.cfg"); commandParams.put(ConfigureTask.PARAMETER_KEY_VALUE_PAIRS, new Gson().toJson(configurations)); - ExecutionCommand executionCommand = new ExecutionCommand(); - executionCommand.setCommandParams(commandParams); - executionCommand.setClusterName("c1"); - + ExecutionCommand executionCommand = getExecutionCommand(commandParams); HostRoleCommand hostRoleCommand = hostRoleCommandFactory.create(null, null, null, null); hostRoleCommand.setExecutionCommandWrapper(new ExecutionCommandWrapper(executionCommand)); @@ -819,14 +862,12 @@ public class ConfigureActionTest { @Test public void testAllowedReplacment() throws Exception { - makeUpgradeCluster(); + Cluster c = clusters.getCluster("c1"); assertEquals(1, c.getConfigsByType("zoo.cfg").size()); - c.setCurrentStackVersion(HDP_211_STACK); - c.setDesiredStackVersion(HDP_220_STACK); - Config config = cf.createNew(c, "zoo.cfg", "version2", new HashMap<String, String>() { + Map<String, String> properties = new HashMap<String, String>() { { put("replace.key.1", "r1"); put("replace.key.2", "r2"); @@ -834,7 +875,9 @@ public class ConfigureActionTest { put("replace.key.4", "r4"); put("replace.key.5", "r5"); } - }, new HashMap<String, Map<String, String>>()); + }; + + Config config = createConfig(c, repoVersion2200, "zoo.cfg", "version2", properties); c.addDesiredConfig("user", Collections.singleton(config)); assertEquals(2, c.getConfigsByType("zoo.cfg").size()); @@ -877,17 +920,14 @@ public class ConfigureActionTest { replace4.ifKeyState = PropertyKeyState.ABSENT; replacements.add(replace4); + createUpgrade(c, repoVersion2200); + Map<String, String> commandParams = new HashMap<>(); - commandParams.put("upgrade_direction", "upgrade"); - commandParams.put("version", HDP_2_2_0_1); commandParams.put("clusterName", "c1"); commandParams.put(ConfigureTask.PARAMETER_CONFIG_TYPE, "zoo.cfg"); commandParams.put(ConfigureTask.PARAMETER_REPLACEMENTS, new Gson().toJson(replacements)); - ExecutionCommand executionCommand = new ExecutionCommand(); - executionCommand.setCommandParams(commandParams); - executionCommand.setClusterName("c1"); - + ExecutionCommand executionCommand = getExecutionCommand(commandParams); HostRoleCommand hostRoleCommand = hostRoleCommandFactory.create(null, null, null, null); hostRoleCommand.setExecutionCommandWrapper(new ExecutionCommandWrapper(executionCommand)); @@ -911,14 +951,10 @@ public class ConfigureActionTest { @Test public void testDisallowedReplacment() throws Exception { - makeUpgradeCluster(); - Cluster c = clusters.getCluster("c1"); assertEquals(1, c.getConfigsByType("zoo.cfg").size()); - c.setCurrentStackVersion(HDP_211_STACK); - c.setDesiredStackVersion(HDP_220_STACK); - Config config = cf.createNew(c, "zoo.cfg", "version2", new HashMap<String, String>() { + Map<String, String> properties = new HashMap<String, String>() { { put("replace.key.1", "r1"); put("replace.key.2", "r2"); @@ -926,7 +962,9 @@ public class ConfigureActionTest { put("replace.key.4", "r4"); put("replace.key.5", "r5"); } - }, new HashMap<String, Map<String, String>>()); + }; + + Config config = createConfig(c, repoVersion2110, "zoo.cfg", "version2", properties); c.addDesiredConfig("user", Collections.singleton(config)); assertEquals(2, c.getConfigsByType("zoo.cfg").size()); @@ -964,17 +1002,14 @@ public class ConfigureActionTest { replace4.ifKeyState = PropertyKeyState.PRESENT; replacements.add(replace4); + createUpgrade(c, repoVersion2200); + Map<String, String> commandParams = new HashMap<>(); - commandParams.put("upgrade_direction", "upgrade"); - commandParams.put("version", HDP_2_2_0_1); commandParams.put("clusterName", "c1"); commandParams.put(ConfigureTask.PARAMETER_CONFIG_TYPE, "zoo.cfg"); commandParams.put(ConfigureTask.PARAMETER_REPLACEMENTS, new Gson().toJson(replacements)); - ExecutionCommand executionCommand = new ExecutionCommand(); - executionCommand.setCommandParams(commandParams); - executionCommand.setClusterName("c1"); - + ExecutionCommand executionCommand = getExecutionCommand(commandParams); HostRoleCommand hostRoleCommand = hostRoleCommandFactory.create(null, null, null, null); hostRoleCommand.setExecutionCommandWrapper(new ExecutionCommandWrapper(executionCommand)); @@ -998,17 +1033,18 @@ public class ConfigureActionTest { @Test public void testAllowedTransferCopy() throws Exception { - makeUpgradeCluster(); - Cluster c = clusters.getCluster("c1"); assertEquals(1, c.getConfigsByType("zoo.cfg").size()); - c.setDesiredStackVersion(HDP_220_STACK); - Config config = cf.createNew(c, "zoo.cfg", "version2", new HashMap<String, String>() {{ - put("initLimit", "10"); - put("copy.key.1", "c1"); - put("copy.key.2", "c2"); - }}, new HashMap<String, Map<String,String>>()); + Map<String, String> properties = new HashMap<String, String>() { + { + put("initLimit", "10"); + put("copy.key.1", "c1"); + put("copy.key.2", "c2"); + } + }; + + Config config = createConfig(c, repoVersion2110, "zoo.cfg", "version2", properties); c.addDesiredConfig("user", Collections.singleton(config)); assertEquals(2, c.getConfigsByType("zoo.cfg").size()); @@ -1019,9 +1055,9 @@ public class ConfigureActionTest { keyValue.key = "initLimit"; keyValue.value = "11"; + createUpgrade(c, repoVersion2200); + Map<String, String> commandParams = new HashMap<>(); - commandParams.put("upgrade_direction", "upgrade"); - commandParams.put("version", HDP_2_2_0_1); commandParams.put("clusterName", "c1"); commandParams.put(ConfigureTask.PARAMETER_CONFIG_TYPE, "zoo.cfg"); commandParams.put(ConfigureTask.PARAMETER_KEY_VALUE_PAIRS, new Gson().toJson(configurations)); @@ -1072,12 +1108,7 @@ public class ConfigureActionTest { commandParams.put(ConfigureTask.PARAMETER_TRANSFERS, new Gson().toJson(transfers)); - ExecutionCommand executionCommand = new ExecutionCommand(); - executionCommand.setCommandParams(commandParams); - executionCommand.setClusterName("c1"); - executionCommand.setRoleParams(new HashMap<String, String>()); - executionCommand.getRoleParams().put(ServerAction.ACTION_USER_NAME, "username"); - + ExecutionCommand executionCommand = getExecutionCommand(commandParams); HostRoleCommand hostRoleCommand = hostRoleCommandFactory.create(null, null, null, null); @@ -1111,17 +1142,18 @@ public class ConfigureActionTest { @Test public void testDisallowedTransferCopy() throws Exception { - makeUpgradeCluster(); - Cluster c = clusters.getCluster("c1"); assertEquals(1, c.getConfigsByType("zoo.cfg").size()); - c.setDesiredStackVersion(HDP_220_STACK); - Config config = cf.createNew(c, "zoo.cfg", "version2", new HashMap<String, String>() {{ - put("initLimit", "10"); - put("copy.key.1", "c1"); - put("copy.key.2", "c2"); - }}, new HashMap<String, Map<String,String>>()); + Map<String, String> properties = new HashMap<String, String>() { + { + put("initLimit", "10"); + put("copy.key.1", "c1"); + put("copy.key.2", "c2"); + } + }; + + Config config = createConfig(c, repoVersion2110, "zoo.cfg", "version2", properties); c.addDesiredConfig("user", Collections.singleton(config)); assertEquals(2, c.getConfigsByType("zoo.cfg").size()); @@ -1132,9 +1164,9 @@ public class ConfigureActionTest { keyValue.key = "initLimit"; keyValue.value = "11"; + createUpgrade(c, repoVersion2111); + Map<String, String> commandParams = new HashMap<>(); - commandParams.put("upgrade_direction", "upgrade"); - commandParams.put("version", HDP_2_2_0_1); commandParams.put("clusterName", "c1"); commandParams.put(ConfigureTask.PARAMETER_CONFIG_TYPE, "zoo.cfg"); commandParams.put(ConfigureTask.PARAMETER_KEY_VALUE_PAIRS, new Gson().toJson(configurations)); @@ -1204,19 +1236,20 @@ public class ConfigureActionTest { @Test public void testAllowedTransferMove() throws Exception { - makeUpgradeCluster(); - Cluster c = clusters.getCluster("c1"); assertEquals(1, c.getConfigsByType("zoo.cfg").size()); - c.setDesiredStackVersion(HDP_220_STACK); - Config config = cf.createNew(c, "zoo.cfg", "version2", new HashMap<String, String>() {{ - put("initLimit", "10"); - put("move.key.1", "m1"); - put("move.key.2", "m2"); - put("move.key.3", "m3"); - put("move.key.4", "m4"); - }}, new HashMap<String, Map<String,String>>()); + Map<String, String> properties = new HashMap<String, String>() { + { + put("initLimit", "10"); + put("move.key.1", "m1"); + put("move.key.2", "m2"); + put("move.key.3", "m3"); + put("move.key.4", "m4"); + } + }; + + Config config = createConfig(c, repoVersion2110, "zoo.cfg", "version2", properties); c.addDesiredConfig("user", Collections.singleton(config)); assertEquals(2, c.getConfigsByType("zoo.cfg").size()); @@ -1227,9 +1260,9 @@ public class ConfigureActionTest { keyValue.key = "initLimit"; keyValue.value = "11"; + createUpgrade(c, repoVersion2111); + Map<String, String> commandParams = new HashMap<>(); - commandParams.put("upgrade_direction", "upgrade"); - commandParams.put("version", HDP_2_2_0_1); commandParams.put("clusterName", "c1"); commandParams.put(ConfigureTask.PARAMETER_CONFIG_TYPE, "zoo.cfg"); commandParams.put(ConfigureTask.PARAMETER_KEY_VALUE_PAIRS, new Gson().toJson(configurations)); @@ -1270,12 +1303,7 @@ public class ConfigureActionTest { commandParams.put(ConfigureTask.PARAMETER_TRANSFERS, new Gson().toJson(transfers)); - ExecutionCommand executionCommand = new ExecutionCommand(); - executionCommand.setCommandParams(commandParams); - executionCommand.setClusterName("c1"); - executionCommand.setRoleParams(new HashMap<String, String>()); - executionCommand.getRoleParams().put(ServerAction.ACTION_USER_NAME, "username"); - + ExecutionCommand executionCommand = getExecutionCommand(commandParams); HostRoleCommand hostRoleCommand = hostRoleCommandFactory.create(null, null, null, null); @@ -1310,20 +1338,20 @@ public class ConfigureActionTest { @Test public void testDisallowedTransferMove() throws Exception { - makeUpgradeCluster(); - Cluster c = clusters.getCluster("c1"); assertEquals(1, c.getConfigsByType("zoo.cfg").size()); - c.setDesiredStackVersion(HDP_220_STACK); - Config config = cf.createNew(c, "zoo.cfg", "version2", - new HashMap<String, String>() {{ - put("initLimit", "10"); - put("move.key.1", "m1"); - put("move.key.2", "m2"); - put("move.key.3", "m3"); - put("move.key.4", "m4"); - }}, new HashMap<String, Map<String,String>>()); + Map<String, String> properties = new HashMap<String, String>() { + { + put("initLimit", "10"); + put("move.key.1", "m1"); + put("move.key.2", "m2"); + put("move.key.3", "m3"); + put("move.key.4", "m4"); + } + }; + + Config config = createConfig(c, repoVersion2110, "zoo.cfg", "version2", properties); c.addDesiredConfig("user", Collections.singleton(config)); assertEquals(2, c.getConfigsByType("zoo.cfg").size()); @@ -1334,9 +1362,9 @@ public class ConfigureActionTest { keyValue.key = "initLimit"; keyValue.value = "11"; + createUpgrade(c, repoVersion2111); + Map<String, String> commandParams = new HashMap<>(); - commandParams.put("upgrade_direction", "upgrade"); - commandParams.put("version", HDP_2_2_0_1); commandParams.put("clusterName", "c1"); commandParams.put(ConfigureTask.PARAMETER_CONFIG_TYPE, "zoo.cfg"); commandParams.put(ConfigureTask.PARAMETER_KEY_VALUE_PAIRS, new Gson().toJson(configurations)); @@ -1371,12 +1399,7 @@ public class ConfigureActionTest { commandParams.put(ConfigureTask.PARAMETER_TRANSFERS, new Gson().toJson(transfers)); - ExecutionCommand executionCommand = new ExecutionCommand(); - executionCommand.setCommandParams(commandParams); - executionCommand.setClusterName("c1"); - executionCommand.setRoleParams(new HashMap<String, String>()); - executionCommand.getRoleParams().put(ServerAction.ACTION_USER_NAME, "username"); - + ExecutionCommand executionCommand = getExecutionCommand(commandParams); HostRoleCommand hostRoleCommand = hostRoleCommandFactory.create(null, null, null, null); @@ -1412,19 +1435,20 @@ public class ConfigureActionTest { @Test public void testAllowedTransferDelete() throws Exception { - makeUpgradeCluster(); - Cluster c = clusters.getCluster("c1"); assertEquals(1, c.getConfigsByType("zoo.cfg").size()); - c.setDesiredStackVersion(HDP_220_STACK); - Config config = cf.createNew(c, "zoo.cfg", "version2", new HashMap<String, String>() {{ - put("initLimit", "10"); - put("delete.key.1", "d1"); - put("delete.key.2", "d2"); - put("delete.key.3", "d3"); - put("delete.key.4", "d4"); - }}, new HashMap<String, Map<String,String>>()); + Map<String, String> properties = new HashMap<String, String>() { + { + put("initLimit", "10"); + put("delete.key.1", "d1"); + put("delete.key.2", "d2"); + put("delete.key.3", "d3"); + put("delete.key.4", "d4"); + } + }; + + Config config = createConfig(c, repoVersion2110, "zoo.cfg", "version2", properties); c.addDesiredConfig("user", Collections.singleton(config)); assertEquals(2, c.getConfigsByType("zoo.cfg").size()); @@ -1435,9 +1459,9 @@ public class ConfigureActionTest { keyValue.key = "initLimit"; keyValue.value = "11"; + createUpgrade(c, repoVersion2111); + Map<String, String> commandParams = new HashMap<>(); - commandParams.put("upgrade_direction", "upgrade"); - commandParams.put("version", HDP_2_2_0_1); commandParams.put("clusterName", "c1"); commandParams.put(ConfigureTask.PARAMETER_CONFIG_TYPE, "zoo.cfg"); commandParams.put(ConfigureTask.PARAMETER_KEY_VALUE_PAIRS, new Gson().toJson(configurations)); @@ -1474,12 +1498,7 @@ public class ConfigureActionTest { commandParams.put(ConfigureTask.PARAMETER_TRANSFERS, new Gson().toJson(transfers)); - ExecutionCommand executionCommand = new ExecutionCommand(); - executionCommand.setCommandParams(commandParams); - executionCommand.setClusterName("c1"); - executionCommand.setRoleParams(new HashMap<String, String>()); - executionCommand.getRoleParams().put(ServerAction.ACTION_USER_NAME, "username"); - + ExecutionCommand executionCommand = getExecutionCommand(commandParams); HostRoleCommand hostRoleCommand = hostRoleCommandFactory.create(null, null, null, null); @@ -1510,19 +1529,20 @@ public class ConfigureActionTest { @Test public void testDisallowedTransferDelete() throws Exception { - makeUpgradeCluster(); - Cluster c = clusters.getCluster("c1"); assertEquals(1, c.getConfigsByType("zoo.cfg").size()); - c.setDesiredStackVersion(HDP_220_STACK); - Config config = cf.createNew(c, "zoo.cfg", "version2", new HashMap<String, String>() {{ - put("initLimit", "10"); - put("delete.key.1", "d1"); - put("delete.key.2", "d2"); - put("delete.key.3", "d3"); - put("delete.key.4", "d4"); - }}, new HashMap<String, Map<String,String>>()); + Map<String, String> properties = new HashMap<String, String>() { + { + put("initLimit", "10"); + put("delete.key.1", "d1"); + put("delete.key.2", "d2"); + put("delete.key.3", "d3"); + put("delete.key.4", "d4"); + } + }; + + Config config = createConfig(c, repoVersion2110, "zoo.cfg", "version2", properties); c.addDesiredConfig("user", Collections.singleton(config)); assertEquals(2, c.getConfigsByType("zoo.cfg").size()); @@ -1533,9 +1553,9 @@ public class ConfigureActionTest { keyValue.key = "initLimit"; keyValue.value = "11"; + createUpgrade(c, repoVersion2111); + Map<String, String> commandParams = new HashMap<>(); - commandParams.put("upgrade_direction", "upgrade"); - commandParams.put("version", HDP_2_2_0_1); commandParams.put("clusterName", "c1"); commandParams.put(ConfigureTask.PARAMETER_CONFIG_TYPE, "zoo.cfg"); commandParams.put(ConfigureTask.PARAMETER_KEY_VALUE_PAIRS, new Gson().toJson(configurations)); @@ -1567,12 +1587,7 @@ public class ConfigureActionTest { commandParams.put(ConfigureTask.PARAMETER_TRANSFERS, new Gson().toJson(transfers)); - ExecutionCommand executionCommand = new ExecutionCommand(); - executionCommand.setCommandParams(commandParams); - executionCommand.setClusterName("c1"); - executionCommand.setRoleParams(new HashMap<String, String>()); - executionCommand.getRoleParams().put(ServerAction.ACTION_USER_NAME, "username"); - + ExecutionCommand executionCommand = getExecutionCommand(commandParams); HostRoleCommand hostRoleCommand = hostRoleCommandFactory.create(null, null, null, null); @@ -1608,25 +1623,24 @@ public class ConfigureActionTest { */ @Test public void testInsert() throws Exception { - makeUpgradeCluster(); - Cluster c = clusters.getCluster("c1"); assertEquals(1, c.getConfigsByType("zoo.cfg").size()); - c.setDesiredStackVersion(HDP_220_STACK); - Config config = cf.createNew(c, "zoo.cfg", "version2", new HashMap<String, String>() { + Map<String, String> properties = new HashMap<String, String>() { { put("key_to_append", "append"); put("key_to_prepend", "prepend"); } - }, new HashMap<String, Map<String, String>>()); + }; + + Config config = createConfig(c, repoVersion2110, "zoo.cfg", "version2", properties); c.addDesiredConfig("user", Collections.singleton(config)); assertEquals(2, c.getConfigsByType("zoo.cfg").size()); + createUpgrade(c, repoVersion2111); + Map<String, String> commandParams = new HashMap<>(); - commandParams.put("upgrade_direction", "upgrade"); - commandParams.put("version", HDP_2_2_0_1); commandParams.put("clusterName", "c1"); commandParams.put(ConfigureTask.PARAMETER_CONFIG_TYPE, "zoo.cfg"); @@ -1661,12 +1675,7 @@ public class ConfigureActionTest { commandParams.put(ConfigureTask.PARAMETER_INSERTIONS, new Gson().toJson(insertions)); - ExecutionCommand executionCommand = new ExecutionCommand(); - executionCommand.setCommandParams(commandParams); - executionCommand.setClusterName("c1"); - executionCommand.setRoleParams(new HashMap<String, String>()); - executionCommand.getRoleParams().put(ServerAction.ACTION_USER_NAME, "username"); - + ExecutionCommand executionCommand = getExecutionCommand(commandParams); HostRoleCommand hostRoleCommand = hostRoleCommandFactory.create(null, null, null, null); hostRoleCommand.setExecutionCommandWrapper(new ExecutionCommandWrapper(executionCommand)); action.setExecutionCommand(executionCommand); @@ -1689,67 +1698,46 @@ public class ConfigureActionTest { assertEquals(expectedAppend, config.getProperties().get("key_to_append")); } + /** + * Creates a cluster using {@link #repoVersion2110} with ZooKeeper installed. + * + * @throws Exception + */ private void makeUpgradeCluster() throws Exception { String clusterName = "c1"; String hostName = "h1"; - clusters.addCluster(clusterName, HDP_220_STACK); - - - StackEntity stackEntity = stackDAO.find(HDP_220_STACK.getStackName(), - HDP_220_STACK.getStackVersion()); - - assertNotNull(stackEntity); + clusters.addCluster(clusterName, repoVersion2110.getStackId()); Cluster c = clusters.getCluster(clusterName); - c.setDesiredStackVersion(HDP_220_STACK); - - // !!! very important, otherwise the loops that walk the list of installed - // service properties will not run! - installService(c, "ZOOKEEPER"); - - Config config = cf.createNew(c, "zoo.cfg", "version1", new HashMap<String, String>() { - { - put("initLimit", "10"); - } - }, new HashMap<String, Map<String, String>>()); - - c.addDesiredConfig("user", Collections.singleton(config)); // add a host component clusters.addHost(hostName); - Host host = clusters.getHost(hostName); - Map<String, String> hostAttributes = new HashMap<>(); hostAttributes.put("os_family", "redhat"); hostAttributes.put("os_release_version", "6"); host.setHostAttributes(hostAttributes); - // Creating starting repo - m_helper.getOrCreateRepositoryVersion(HDP_220_STACK, HDP_2_2_0_0); - c.createClusterVersion(HDP_220_STACK, HDP_2_2_0_0, "admin", RepositoryVersionState.INSTALLING); - c.transitionClusterVersion(HDP_220_STACK, HDP_2_2_0_0, RepositoryVersionState.CURRENT); - - String urlInfo = "[{'repositories':[" - + "{'Repositories/base_url':'http://foo1','Repositories/repo_name':'HDP','Repositories/repo_id':'HDP-2.2.0'}" - + "], 'OperatingSystems/os_type':'redhat6'}]"; - repoVersionDAO.create(stackEntity, HDP_2_2_0_1, String.valueOf(System.currentTimeMillis()), urlInfo); - + clusters.mapHostToCluster(hostName, clusterName); - c.createClusterVersion(HDP_220_STACK, HDP_2_2_0_1, "admin", RepositoryVersionState.INSTALLING); - c.transitionClusterVersion(HDP_220_STACK, HDP_2_2_0_1, RepositoryVersionState.INSTALLED); - c.setCurrentStackVersion(HDP_220_STACK); + // !!! very important, otherwise the loops that walk the list of installed + // service properties will not run! + Service zk = installService(c, "ZOOKEEPER", repoVersion2110); + addServiceComponent(c, zk, "ZOOKEEPER_SERVER"); + addServiceComponent(c, zk, "ZOOKEEPER_CLIENT"); + createNewServiceComponentHost(c, "ZOOKEEPER", "ZOOKEEPER_SERVER", hostName); + createNewServiceComponentHost(c, "ZOOKEEPER", "ZOOKEEPER_CLIENT", hostName); - c.mapHostVersions(Collections.singleton(hostName), c.getCurrentClusterVersion(), - RepositoryVersionState.CURRENT); + Map<String, String> properties = new HashMap<String, String>() { + { + put("initLimit", "10"); + } + }; + Config config = createConfig(c, repoVersion2110, "zoo.cfg", "version1", properties); - HostVersionEntity entity = new HostVersionEntity(); - entity.setHostEntity(hostDAO.findByName(hostName)); - entity.setRepositoryVersion(repoVersionDAO.findByStackAndVersion(HDP_220_STACK, HDP_2_2_0_1)); - entity.setState(RepositoryVersionState.INSTALLED); - hostVersionDAO.create(entity); + c.addDesiredConfig("user", Collections.singleton(config)); // verify that our configs are there String tickTime = m_configHelper.getPropertyValueFromStackDefinitions(c, "zoo.cfg", "tickTime"); @@ -1764,16 +1752,104 @@ public class ConfigureActionTest { * @return * @throws AmbariException */ - private Service installService(Cluster cluster, String serviceName) throws AmbariException { + private Service installService(Cluster cluster, String serviceName, + RepositoryVersionEntity repositoryVersion) throws AmbariException { Service service = null; try { service = cluster.getService(serviceName); } catch (ServiceNotFoundException e) { - service = serviceFactory.createNew(cluster, serviceName); + service = serviceFactory.createNew(cluster, serviceName, repositoryVersion); cluster.addService(service); } return service; } -} + + private ServiceComponent addServiceComponent(Cluster cluster, Service service, + String componentName) throws AmbariException { + ServiceComponent serviceComponent = null; + try { + serviceComponent = service.getServiceComponent(componentName); + } catch (ServiceComponentNotFoundException e) { + serviceComponent = serviceComponentFactory.createNew(service, componentName); + service.addServiceComponent(serviceComponent); + serviceComponent.setDesiredState(State.INSTALLED); + } + + return serviceComponent; + } + + private ServiceComponentHost createNewServiceComponentHost(Cluster cluster, String serviceName, + String svcComponent, String hostName) throws AmbariException { + Assert.assertNotNull(cluster.getConfigGroups()); + Service s = cluster.getService(serviceName); + ServiceComponent sc = addServiceComponent(cluster, s, svcComponent); + + ServiceComponentHost sch = serviceComponentHostFactory.createNew(sc, hostName); + + sc.addServiceComponentHost(sch); + sch.setDesiredState(State.INSTALLED); + sch.setState(State.INSTALLED); + return sch; + } + + /** + * Creates an upgrade and associates it with the cluster. + */ + private UpgradeEntity createUpgrade(Cluster cluster, RepositoryVersionEntity repositoryVersion) + throws Exception { + + // create some entities for the finalize action to work with for patch + // history + RequestEntity requestEntity = new RequestEntity(); + requestEntity.setClusterId(cluster.getClusterId()); + requestEntity.setRequestId(1L); + requestEntity.setStartTime(System.currentTimeMillis()); + requestEntity.setCreateTime(System.currentTimeMillis()); + requestDAO.create(requestEntity); + + UpgradeEntity upgradeEntity = new UpgradeEntity(); + upgradeEntity.setId(1L); + upgradeEntity.setClusterId(cluster.getClusterId()); + upgradeEntity.setRequestEntity(requestEntity); + upgradeEntity.setUpgradePackage(""); + upgradeEntity.setRepositoryVersion(repositoryVersion); + upgradeEntity.setUpgradeType(UpgradeType.NON_ROLLING); + + Map<String, Service> services = cluster.getServices(); + for (String serviceName : services.keySet()) { + Service service = services.get(serviceName); + Map<String, ServiceComponent> components = service.getServiceComponents(); + for (String componentName : components.keySet()) { + UpgradeHistoryEntity history = new UpgradeHistoryEntity(); + history.setUpgrade(upgradeEntity); + history.setServiceName(serviceName); + history.setComponentName(componentName); + history.setFromRepositoryVersion(service.getDesiredRepositoryVersion()); + history.setTargetRepositoryVersion(repositoryVersion); + upgradeEntity.addHistory(history); + } + } + + upgradeDAO.create(upgradeEntity); + cluster.setUpgradeEntity(upgradeEntity); + return upgradeEntity; + } + + private ExecutionCommand getExecutionCommand(Map<String, String> commandParams) { + ExecutionCommand executionCommand = new ExecutionCommand(); + executionCommand.setClusterName("c1"); + executionCommand.setCommandParams(commandParams); + executionCommand.setRoleParams(new HashMap<String, String>()); + executionCommand.getRoleParams().put(ServerAction.ACTION_USER_NAME, "username"); + + return executionCommand; + } + + private Config createConfig(Cluster cluster, RepositoryVersionEntity repoVersion, String type, + String tag, Map<String, String> properties) { + return configFactory.createNew(cluster, type, tag, properties, + NO_ATTRIBUTES); + } +} \ No newline at end of file
