http://git-wip-us.apache.org/repos/asf/ambari/blob/ee79dd21/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql index 252feea..9ade56f 100644 --- a/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql +++ b/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql @@ -168,8 +168,7 @@ CREATE TABLE hoststate ( CREATE TABLE host_version ( id BIGINT NOT NULL, repo_version_id BIGINT NOT NULL, - host_name VARCHAR(255) NOT NULL, - --host_id BIGINT NOT NULL, + host_id BIGINT NOT NULL, state VARCHAR(32) NOT NULL, PRIMARY KEY (id)); @@ -231,8 +230,7 @@ CREATE TABLE host_role_command ( retry_allowed SMALLINT DEFAULT 0 NOT NULL, event VARCHAR(32000) NOT NULL, exitcode INTEGER NOT NULL, - host_name VARCHAR(255) NOT NULL, - --host_id BIGINT NOT NULL, + host_id BIGINT NOT NULL, last_attempt_time BIGINT NOT NULL, request_id BIGINT NOT NULL, role VARCHAR(255), @@ -599,6 +597,7 @@ ALTER TABLE repo_version ADD CONSTRAINT UQ_repo_version_display_name UNIQUE (dis ALTER TABLE repo_version ADD CONSTRAINT UQ_repo_version_stack_version UNIQUE (stack_id, version); --------altering tables by creating foreign keys---------- +-- Note, Oracle has a limitation of 32 chars in the FK name, and we should use the same FK name in all DB types. ALTER TABLE members ADD CONSTRAINT FK_members_group_id FOREIGN KEY (group_id) REFERENCES groups (group_id); ALTER TABLE members ADD CONSTRAINT FK_members_user_id FOREIGN KEY (user_id) REFERENCES users (user_id); ALTER TABLE clusterconfig ADD CONSTRAINT FK_clusterconfig_cluster_id FOREIGN KEY (cluster_id) REFERENCES clusters (cluster_id); @@ -612,15 +611,13 @@ ALTER TABLE hostcomponentdesiredstate ADD CONSTRAINT hstcmpnntdesiredstatecmpnnt ALTER TABLE hostcomponentstate ADD CONSTRAINT hstcomponentstatecomponentname FOREIGN KEY (component_name, cluster_id, service_name) REFERENCES servicecomponentdesiredstate (component_name, cluster_id, service_name); ALTER TABLE hostcomponentstate ADD CONSTRAINT FK_hostcomponentstate_host_id FOREIGN KEY (host_id) REFERENCES hosts (host_id); ALTER TABLE hoststate ADD CONSTRAINT FK_hoststate_host_id FOREIGN KEY (host_id) REFERENCES hosts (host_id); -ALTER TABLE host_version ADD CONSTRAINT FK_host_version_host_name FOREIGN KEY (host_name) REFERENCES hosts (host_name); ---ALTER TABLE host_version ADD CONSTRAINT FK_host_version_host_id FOREIGN KEY (host_id) REFERENCES hosts (host_id); +ALTER TABLE host_version ADD CONSTRAINT FK_host_version_host_id FOREIGN KEY (host_id) REFERENCES hosts (host_id); ALTER TABLE host_version ADD CONSTRAINT FK_host_version_repovers_id FOREIGN KEY (repo_version_id) REFERENCES repo_version (repo_version_id); ALTER TABLE servicecomponentdesiredstate ADD CONSTRAINT srvccmponentdesiredstatesrvcnm FOREIGN KEY (service_name, cluster_id) REFERENCES clusterservices (service_name, cluster_id); ALTER TABLE servicedesiredstate ADD CONSTRAINT servicedesiredstateservicename FOREIGN KEY (service_name, cluster_id) REFERENCES clusterservices (service_name, cluster_id); ALTER TABLE execution_command ADD CONSTRAINT FK_execution_command_task_id FOREIGN KEY (task_id) REFERENCES host_role_command (task_id); ALTER TABLE host_role_command ADD CONSTRAINT FK_host_role_command_stage_id FOREIGN KEY (stage_id, request_id) REFERENCES stage (stage_id, request_id); -ALTER TABLE host_role_command ADD CONSTRAINT FK_host_role_command_host_name FOREIGN KEY (host_name) REFERENCES hosts (host_name); ---ALTER TABLE host_role_command ADD CONSTRAINT FK_host_role_command_host_id FOREIGN KEY (host_id) REFERENCES hosts (host_id); +ALTER TABLE host_role_command ADD CONSTRAINT FK_host_role_command_host_id FOREIGN KEY (host_id) REFERENCES hosts (host_id); ALTER TABLE role_success_criteria ADD CONSTRAINT role_success_criteria_stage_id FOREIGN KEY (stage_id, request_id) REFERENCES stage (stage_id, request_id); ALTER TABLE stage ADD CONSTRAINT FK_stage_request_id FOREIGN KEY (request_id) REFERENCES request (request_id); ALTER TABLE request ADD CONSTRAINT FK_request_schedule_id FOREIGN KEY (request_schedule_id) REFERENCES requestschedule (schedule_id);
http://git-wip-us.apache.org/repos/asf/ambari/blob/ee79dd21/ambari-server/src/main/resources/Ambari-DDL-Postgres-EMBEDDED-CREATE.sql ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/resources/Ambari-DDL-Postgres-EMBEDDED-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-Postgres-EMBEDDED-CREATE.sql index d2edab0..feaeae9 100644 --- a/ambari-server/src/main/resources/Ambari-DDL-Postgres-EMBEDDED-CREATE.sql +++ b/ambari-server/src/main/resources/Ambari-DDL-Postgres-EMBEDDED-CREATE.sql @@ -193,8 +193,7 @@ GRANT ALL PRIVILEGES ON TABLE ambari.hoststate TO :username; CREATE TABLE ambari.host_version ( id BIGINT NOT NULL, repo_version_id BIGINT NOT NULL, - host_name VARCHAR(255) NOT NULL, - --host_id BIGINT NOT NULL, + host_id BIGINT NOT NULL, state VARCHAR(32) NOT NULL, PRIMARY KEY (id)); GRANT ALL PRIVILEGES ON TABLE ambari.host_version TO :username; @@ -263,8 +262,7 @@ CREATE TABLE ambari.host_role_command ( retry_allowed SMALLINT DEFAULT 0 NOT NULL, event VARCHAR(32000) NOT NULL, exitcode INTEGER NOT NULL, - host_name VARCHAR(255) NOT NULL, - --host_id BIGINT NOT NULL, + host_id BIGINT NOT NULL, last_attempt_time BIGINT NOT NULL, request_id BIGINT NOT NULL, role VARCHAR(255), @@ -672,6 +670,7 @@ ALTER TABLE ambari.repo_version ADD CONSTRAINT UQ_repo_version_display_name UNIQ ALTER TABLE ambari.repo_version ADD CONSTRAINT UQ_repo_version_stack_version UNIQUE (stack_id, version); --------altering tables by creating foreign keys---------- +-- Note, Oracle has a limitation of 32 chars in the FK name, and we should use the same FK name in all DB types. ALTER TABLE ambari.members ADD CONSTRAINT FK_members_group_id FOREIGN KEY (group_id) REFERENCES ambari.groups (group_id); ALTER TABLE ambari.members ADD CONSTRAINT FK_members_user_id FOREIGN KEY (user_id) REFERENCES ambari.users (user_id); ALTER TABLE ambari.clusterconfig ADD CONSTRAINT FK_clusterconfig_cluster_id FOREIGN KEY (cluster_id) REFERENCES ambari.clusters (cluster_id); @@ -685,15 +684,13 @@ ALTER TABLE ambari.hostcomponentdesiredstate ADD CONSTRAINT hstcmpnntdesiredstat ALTER TABLE ambari.hostcomponentstate ADD CONSTRAINT hstcomponentstatecomponentname FOREIGN KEY (component_name, cluster_id, service_name) REFERENCES ambari.servicecomponentdesiredstate (component_name, cluster_id, service_name); ALTER TABLE ambari.hostcomponentstate ADD CONSTRAINT FK_hostcomponentstate_host_id FOREIGN KEY (host_id) REFERENCES ambari.hosts (host_id); ALTER TABLE ambari.hoststate ADD CONSTRAINT FK_hoststate_host_id FOREIGN KEY (host_id) REFERENCES ambari.hosts (host_id); -ALTER TABLE ambari.host_version ADD CONSTRAINT FK_host_version_host_name FOREIGN KEY (host_name) REFERENCES ambari.hosts (host_name); ---ALTER TABLE ambari.host_version ADD CONSTRAINT FK_host_version_host_id FOREIGN KEY (host_id) REFERENCES ambari.hosts (host_id); +ALTER TABLE ambari.host_version ADD CONSTRAINT FK_host_version_host_id FOREIGN KEY (host_id) REFERENCES ambari.hosts (host_id); ALTER TABLE ambari.host_version ADD CONSTRAINT FK_host_version_repovers_id FOREIGN KEY (repo_version_id) REFERENCES ambari.repo_version (repo_version_id); ALTER TABLE ambari.servicecomponentdesiredstate ADD CONSTRAINT srvccmponentdesiredstatesrvcnm FOREIGN KEY (service_name, cluster_id) REFERENCES ambari.clusterservices (service_name, cluster_id); ALTER TABLE ambari.servicedesiredstate ADD CONSTRAINT servicedesiredstateservicename FOREIGN KEY (service_name, cluster_id) REFERENCES ambari.clusterservices (service_name, cluster_id); ALTER TABLE ambari.execution_command ADD CONSTRAINT FK_execution_command_task_id FOREIGN KEY (task_id) REFERENCES ambari.host_role_command (task_id); ALTER TABLE ambari.host_role_command ADD CONSTRAINT FK_host_role_command_stage_id FOREIGN KEY (stage_id, request_id) REFERENCES ambari.stage (stage_id, request_id); -ALTER TABLE ambari.host_role_command ADD CONSTRAINT FK_host_role_command_host_name FOREIGN KEY (host_name) REFERENCES ambari.hosts (host_name); ---ALTER TABLE ambari.host_role_command ADD CONSTRAINT FK_host_role_command_host_id FOREIGN KEY (host_id) REFERENCES ambari.hosts (host_id); +ALTER TABLE ambari.host_role_command ADD CONSTRAINT FK_host_role_command_host_id FOREIGN KEY (host_id) REFERENCES ambari.hosts (host_id); ALTER TABLE ambari.role_success_criteria ADD CONSTRAINT role_success_criteria_stage_id FOREIGN KEY (stage_id, request_id) REFERENCES ambari.stage (stage_id, request_id); ALTER TABLE ambari.stage ADD CONSTRAINT FK_stage_request_id FOREIGN KEY (request_id) REFERENCES ambari.request (request_id); ALTER TABLE ambari.request ADD CONSTRAINT FK_request_schedule_id FOREIGN KEY (request_schedule_id) REFERENCES ambari.requestschedule (schedule_id); http://git-wip-us.apache.org/repos/asf/ambari/blob/ee79dd21/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql index 835c23f..1567bf1 100644 --- a/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql +++ b/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql @@ -249,10 +249,10 @@ CREATE TABLE host_role_command ( retry_allowed SMALLINT DEFAULT 0 NOT NULL, event VARCHAR(MAX) NOT NULL, exitcode INTEGER NOT NULL, - host_name VARCHAR(255) NOT NULL, + host_id BIGINT NOT NULL, last_attempt_time BIGINT NOT NULL, request_id BIGINT NOT NULL, - ROLE VARCHAR(255), + role VARCHAR(255), stage_id BIGINT NOT NULL, start_time BIGINT NOT NULL, end_time BIGINT, @@ -710,6 +710,7 @@ ALTER TABLE repo_version ADD CONSTRAINT UQ_repo_version_display_name UNIQUE (dis ALTER TABLE repo_version ADD CONSTRAINT UQ_repo_version_stack_version UNIQUE (stack_id, version); -- altering tables by creating foreign keys---------- +-- Note, Oracle has a limitation of 32 chars in the FK name, and we should use the same FK name in all DB types. ALTER TABLE members ADD CONSTRAINT FK_members_group_id FOREIGN KEY (group_id) REFERENCES groups (group_id); ALTER TABLE members ADD CONSTRAINT FK_members_user_id FOREIGN KEY (user_id) REFERENCES users (user_id); ALTER TABLE clusterconfig ADD CONSTRAINT FK_clusterconfig_cluster_id FOREIGN KEY (cluster_id) REFERENCES clusters (cluster_id); @@ -723,15 +724,13 @@ ALTER TABLE hostcomponentdesiredstate ADD CONSTRAINT hstcmpnntdesiredstatecmpnnt ALTER TABLE hostcomponentstate ADD CONSTRAINT hstcomponentstatecomponentname FOREIGN KEY (component_name, cluster_id, service_name) REFERENCES servicecomponentdesiredstate (component_name, cluster_id, service_name); ALTER TABLE hostcomponentstate ADD CONSTRAINT FK_hostcomponentstate_host_id FOREIGN KEY (host_id) REFERENCES hosts (host_id); ALTER TABLE hoststate ADD CONSTRAINT FK_hoststate_host_id FOREIGN KEY (host_id) REFERENCES hosts (host_id); -ALTER TABLE host_version ADD CONSTRAINT FK_host_version_host_name FOREIGN KEY (host_name) REFERENCES hosts (host_name); ---ALTER TABLE host_version ADD CONSTRAINT FK_host_version_host_id FOREIGN KEY (host_id) REFERENCES hosts (host_id); +ALTER TABLE host_version ADD CONSTRAINT FK_host_version_host_id FOREIGN KEY (host_id) REFERENCES hosts (host_id); ALTER TABLE host_version ADD CONSTRAINT FK_host_version_repovers_id FOREIGN KEY (repo_version_id) REFERENCES repo_version (repo_version_id); ALTER TABLE servicecomponentdesiredstate ADD CONSTRAINT srvccmponentdesiredstatesrvcnm FOREIGN KEY (service_name, cluster_id) REFERENCES clusterservices (service_name, cluster_id); ALTER TABLE servicedesiredstate ADD CONSTRAINT servicedesiredstateservicename FOREIGN KEY (service_name, cluster_id) REFERENCES clusterservices (service_name, cluster_id); ALTER TABLE execution_command ADD CONSTRAINT FK_execution_command_task_id FOREIGN KEY (task_id) REFERENCES host_role_command (task_id); ALTER TABLE host_role_command ADD CONSTRAINT FK_host_role_command_stage_id FOREIGN KEY (stage_id, request_id) REFERENCES stage (stage_id, request_id); -ALTER TABLE host_role_command ADD CONSTRAINT FK_host_role_command_host_name FOREIGN KEY (host_name) REFERENCES hosts (host_name); ---ALTER TABLE host_role_command ADD CONSTRAINT FK_host_role_command_host_id FOREIGN KEY (host_id) REFERENCES hosts (host_id); +ALTER TABLE host_role_command ADD CONSTRAINT FK_host_role_command_host_id FOREIGN KEY (host_id) REFERENCES hosts (host_id); ALTER TABLE role_success_criteria ADD CONSTRAINT role_success_criteria_stage_id FOREIGN KEY (stage_id, request_id) REFERENCES stage (stage_id, request_id); ALTER TABLE stage ADD CONSTRAINT FK_stage_request_id FOREIGN KEY (request_id) REFERENCES request (request_id); ALTER TABLE request ADD CONSTRAINT FK_request_schedule_id FOREIGN KEY (request_schedule_id) REFERENCES requestschedule (schedule_id); http://git-wip-us.apache.org/repos/asf/ambari/blob/ee79dd21/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/ExecutionCommandWrapperTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/ExecutionCommandWrapperTest.java b/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/ExecutionCommandWrapperTest.java index ca07938..66efea1 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/ExecutionCommandWrapperTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/ExecutionCommandWrapperTest.java @@ -52,7 +52,7 @@ import com.google.inject.Guice; import com.google.inject.Injector; public class ExecutionCommandWrapperTest { - + private static final String HOST1 = "dev01.ambari.apache.org"; private static final String CLUSTER1 = "c1"; private static final String CLUSTER_VERSION_TAG = "clusterVersion"; @@ -87,11 +87,12 @@ public class ExecutionCommandWrapperTest { private static Map<String, String> SERVICE_SITE_SERVICE; private static Map<String, String> SERVICE_SITE_HOST; private static Map<String, Map<String, String>> CONFIG_ATTRIBUTES; - + private static Injector injector; private static Clusters clusters; private static ConfigFactory configFactory; private static ConfigHelper configHelper; + private static StageFactory stageFactory; @BeforeClass public static void setup() throws AmbariException { @@ -99,35 +100,36 @@ public class ExecutionCommandWrapperTest { injector.getInstance(GuiceJpaInitializer.class); configHelper = injector.getInstance(ConfigHelper.class); configFactory = injector.getInstance(ConfigFactory.class); - + stageFactory = injector.getInstance(StageFactory.class); + clusters = injector.getInstance(Clusters.class); clusters.addHost(HOST1); clusters.getHost(HOST1).persist(); clusters.addCluster(CLUSTER1, new StackId("HDP-0.1")); - + Cluster cluster1 = clusters.getCluster(CLUSTER1); - + SERVICE_SITE_CLUSTER = new HashMap<String, String>(); SERVICE_SITE_CLUSTER.put(SERVICE_SITE_NAME1, SERVICE_SITE_VAL1); SERVICE_SITE_CLUSTER.put(SERVICE_SITE_NAME2, SERVICE_SITE_VAL2); SERVICE_SITE_CLUSTER.put(SERVICE_SITE_NAME3, SERVICE_SITE_VAL3); SERVICE_SITE_CLUSTER.put(SERVICE_SITE_NAME4, SERVICE_SITE_VAL4); - + SERVICE_SITE_SERVICE = new HashMap<String, String>(); SERVICE_SITE_SERVICE.put(SERVICE_SITE_NAME1, SERVICE_SITE_VAL1_S); SERVICE_SITE_SERVICE.put(SERVICE_SITE_NAME2, SERVICE_SITE_VAL2_S); SERVICE_SITE_SERVICE.put(SERVICE_SITE_NAME5, SERVICE_SITE_VAL5_S); - + SERVICE_SITE_HOST = new HashMap<String, String>(); SERVICE_SITE_HOST.put(SERVICE_SITE_NAME2, SERVICE_SITE_VAL2_H); SERVICE_SITE_HOST.put(SERVICE_SITE_NAME6, SERVICE_SITE_VAL6_H); - + GLOBAL_CLUSTER = new HashMap<String, String>(); GLOBAL_CLUSTER.put(GLOBAL_NAME1, GLOBAL_CLUSTER_VAL1); GLOBAL_CLUSTER.put(GLOBAL_NAME2, GLOBAL_CLUSTER_VAL2); - + CONFIG_ATTRIBUTES = new HashMap<String, Map<String,String>>(); - + //Cluster level global config Config globalConfig = configFactory.createNew(cluster1, GLOBAL_CONFIG, GLOBAL_CLUSTER, CONFIG_ATTRIBUTES); globalConfig.setTag(CLUSTER_VERSION_TAG); @@ -137,26 +139,26 @@ public class ExecutionCommandWrapperTest { Config serviceSiteConfigCluster = configFactory.createNew(cluster1, SERVICE_SITE_CONFIG, SERVICE_SITE_CLUSTER, CONFIG_ATTRIBUTES); serviceSiteConfigCluster.setTag(CLUSTER_VERSION_TAG); cluster1.addConfig(serviceSiteConfigCluster); - + //Service level service config Config serviceSiteConfigService = configFactory.createNew(cluster1, SERVICE_SITE_CONFIG, SERVICE_SITE_SERVICE, CONFIG_ATTRIBUTES); serviceSiteConfigService.setTag(SERVICE_VERSION_TAG); cluster1.addConfig(serviceSiteConfigService); - + //Host level service config Config serviceSiteConfigHost = configFactory.createNew(cluster1, SERVICE_SITE_CONFIG, SERVICE_SITE_HOST, CONFIG_ATTRIBUTES); serviceSiteConfigHost.setTag(HOST_VERSION_TAG); cluster1.addConfig(serviceSiteConfigHost); - + ActionDBAccessor db = injector.getInstance(ActionDBAccessorImpl.class); - + createTask(db, 1, 1, HOST1, CLUSTER1); - + } - + private static void createTask(ActionDBAccessor db, long requestId, long stageId, String hostName, String clusterName) throws AmbariException { - - Stage s = new Stage(requestId, "/var/log", clusterName, 1L, "execution command wrapper test", "clusterHostInfo", "commandParamsStage", "hostParamsStage"); + + Stage s = stageFactory.createNew(requestId, "/var/log", clusterName, 1L, "execution command wrapper test", "clusterHostInfo", "commandParamsStage", "hostParamsStage"); s.setStageId(stageId); s.addHostRoleExecutionCommand(hostName, Role.NAMENODE, RoleCommand.START, @@ -167,33 +169,33 @@ public class ExecutionCommandWrapperTest { Request request = new Request(stages, clusters); db.persistActions(request); } - + @Test public void testGetExecutionCommand() throws JSONException, AmbariException { - - + + Map<String, Map<String, String>> confs = new HashMap<String, Map<String, String>>(); Map<String, String> configurationsGlobal = new HashMap<String, String>(); configurationsGlobal.put(GLOBAL_NAME1, GLOBAL_VAL1); confs.put(GLOBAL_CONFIG, configurationsGlobal); - + Map<String, Map<String, String>> confTags = new HashMap<String, Map<String, String>>(); Map<String, String> confTagServiceSite = new HashMap<String, String>(); - + confTagServiceSite.put("tag", CLUSTER_VERSION_TAG); confTagServiceSite.put("service_override_tag", SERVICE_VERSION_TAG); confTagServiceSite.put("host_override_tag", HOST_VERSION_TAG); - + confTags.put(SERVICE_SITE_CONFIG, confTagServiceSite); - + Map<String, String> confTagGlobal = Collections.singletonMap("tag", CLUSTER_VERSION_TAG); - + confTags.put(GLOBAL_CONFIG, confTagGlobal); - - + + ExecutionCommand executionCommand = new ExecutionCommand(); - - + + executionCommand.setClusterName(CLUSTER1); executionCommand.setTaskId(1); executionCommand.setCommandId("1-1"); @@ -206,63 +208,63 @@ public class ExecutionCommandWrapperTest { executionCommand.setServiceName("HDFS"); executionCommand.setCommandType(AgentCommandType.EXECUTION_COMMAND); executionCommand.setCommandParams(Collections.<String, String>emptyMap()); - + String json = StageUtils.getGson().toJson(executionCommand, ExecutionCommand.class); ExecutionCommandWrapper execCommWrap = new ExecutionCommandWrapper(json); ExecutionCommand processedExecutionCommand = execCommWrap.getExecutionCommand(); - + Map<String, String> serviceSiteConfig = processedExecutionCommand.getConfigurations().get(SERVICE_SITE_CONFIG); - + Assert.assertEquals(SERVICE_SITE_VAL1_S, serviceSiteConfig.get(SERVICE_SITE_NAME1)); Assert.assertEquals(SERVICE_SITE_VAL2_H, serviceSiteConfig.get(SERVICE_SITE_NAME2)); Assert.assertEquals(SERVICE_SITE_VAL3, serviceSiteConfig.get(SERVICE_SITE_NAME3)); Assert.assertEquals(SERVICE_SITE_VAL4, serviceSiteConfig.get(SERVICE_SITE_NAME4)); Assert.assertEquals(SERVICE_SITE_VAL5_S, serviceSiteConfig.get(SERVICE_SITE_NAME5)); Assert.assertEquals(SERVICE_SITE_VAL6_H, serviceSiteConfig.get(SERVICE_SITE_NAME6)); - + Map<String, String> globalConfig = processedExecutionCommand.getConfigurations().get(GLOBAL_CONFIG); - + Assert.assertEquals(GLOBAL_VAL1, globalConfig.get(GLOBAL_NAME1)); Assert.assertEquals(GLOBAL_CLUSTER_VAL2, globalConfig.get(GLOBAL_NAME2)); - + //Union of all keys of service site configs Set<String> serviceSiteKeys = new HashSet<String>(); serviceSiteKeys.addAll(SERVICE_SITE_CLUSTER.keySet()); serviceSiteKeys.addAll(SERVICE_SITE_SERVICE.keySet()); serviceSiteKeys.addAll(SERVICE_SITE_HOST.keySet()); - + Assert.assertEquals(serviceSiteKeys.size(), serviceSiteConfig.size()); - + } - + @Test public void testGetMergedConfig() { Map<String, String> baseConfig = new HashMap<String, String>(); - + baseConfig.put(SERVICE_SITE_NAME1, SERVICE_SITE_VAL1); baseConfig.put(SERVICE_SITE_NAME2, SERVICE_SITE_VAL2); baseConfig.put(SERVICE_SITE_NAME3, SERVICE_SITE_VAL3); baseConfig.put(SERVICE_SITE_NAME4, SERVICE_SITE_VAL4); baseConfig.put(SERVICE_SITE_NAME5, SERVICE_SITE_VAL5); - + Map<String, String> overrideConfig = new HashMap<String, String>(); - + overrideConfig.put(SERVICE_SITE_NAME2, SERVICE_SITE_VAL2_H); overrideConfig.put(SERVICE_SITE_NAME6, SERVICE_SITE_VAL6_H); - - + + Map<String, String> mergedConfig = configHelper.getMergedConfig(baseConfig, overrideConfig); - - + + Set<String> configsKeys = new HashSet<String>(); configsKeys.addAll(baseConfig.keySet()); configsKeys.addAll(overrideConfig.keySet()); - + Assert.assertEquals(configsKeys.size(), mergedConfig.size()); - + Assert.assertEquals(SERVICE_SITE_VAL1, mergedConfig.get(SERVICE_SITE_NAME1)); Assert.assertEquals(SERVICE_SITE_VAL2_H, mergedConfig.get(SERVICE_SITE_NAME2)); Assert.assertEquals(SERVICE_SITE_VAL3, mergedConfig.get(SERVICE_SITE_NAME3)); http://git-wip-us.apache.org/repos/asf/ambari/blob/ee79dd21/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/StageTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/StageTest.java b/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/StageTest.java index cd424d4..bb64e48 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/StageTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/StageTest.java @@ -18,12 +18,18 @@ package org.apache.ambari.server.actionmanager; +import com.google.inject.Guice; +import com.google.inject.Inject; +import com.google.inject.Injector; import org.apache.ambari.server.Role; import org.apache.ambari.server.RoleCommand; +import org.apache.ambari.server.orm.GuiceJpaInitializer; +import org.apache.ambari.server.orm.InMemoryDefaultTestModule; import org.apache.ambari.server.serveraction.ServerAction; import org.apache.ambari.server.serveraction.upgrades.ConfigureAction; import org.apache.ambari.server.state.svccomphost.ServiceComponentHostServerActionEvent; import org.apache.ambari.server.utils.StageUtils; +import org.junit.Before; import org.junit.Test; import java.util.Collections; @@ -41,10 +47,21 @@ public class StageTest { + SERVER_HOST_NAME + "], slave_hosts=[" + SERVER_HOST_NAME + "]}"; + Injector injector; + + @Inject + StageFactory stageFactory; + + @Before + public void setup() throws Exception { + injector = Guice.createInjector(new InMemoryDefaultTestModule()); + injector.getInstance(GuiceJpaInitializer.class); + injector.injectMembers(this); + } @Test public void testAddServerActionCommand_userName() throws Exception { - final Stage stage = new Stage((long) 1, "/tmp", "cluster1", (long) 978, "context", CLUSTER_HOST_INFO, + final Stage stage = stageFactory.createNew((long) 1, "/tmp", "cluster1", (long) 978, "context", CLUSTER_HOST_INFO, "{\"host_param\":\"param_value\"}", "{\"stage_param\":\"param_value\"}"); stage.addServerActionCommand(ConfigureAction.class.getName(), http://git-wip-us.apache.org/repos/asf/ambari/blob/ee79dd21/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionDBAccessorImpl.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionDBAccessorImpl.java b/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionDBAccessorImpl.java index 6a6f75a..98ecda1 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionDBAccessorImpl.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionDBAccessorImpl.java @@ -94,6 +94,10 @@ public class TestActionDBAccessorImpl { @Inject private HostRoleCommandDAO hostRoleCommandDAO; + @Inject + private StageFactory stageFactory; + + @Before public void setup() throws AmbariException { InMemoryDefaultTestModule defaultTestModule = new InMemoryDefaultTestModule(); @@ -506,7 +510,7 @@ public class TestActionDBAccessorImpl { @Test public void testAbortRequest() throws AmbariException { - Stage s = new Stage(requestId, "/a/b", "cluster1", 1L, "action db accessor test", + Stage s = stageFactory.createNew(requestId, "/a/b", "cluster1", 1L, "action db accessor test", "clusterHostInfo", "commandParamsStage", "hostParamsStage"); s.setStageId(stageId); @@ -593,7 +597,7 @@ public class TestActionDBAccessorImpl { @Test public void testGet1000TasksFromOracleDB() throws Exception { - Stage s = new Stage(requestId, "/a/b", "cluster1", 1L, "action db accessor test", + Stage s = stageFactory.createNew(requestId, "/a/b", "cluster1", 1L, "action db accessor test", "clusterHostInfo", "commandParamsStage", "hostParamsStage"); s.setStageId(stageId); for (int i = 1000; i < 2002; i++) { @@ -655,7 +659,7 @@ public class TestActionDBAccessorImpl { } private Stage createStubStage(String hostname, long requestId, long stageId) { - Stage s = new Stage(requestId, "/a/b", "cluster1", 1L, "action db accessor test", + Stage s = stageFactory.createNew(requestId, "/a/b", "cluster1", 1L, "action db accessor test", "clusterHostInfo", "commandParamsStage", "hostParamsStage"); s.setStageId(stageId); s.addHostRoleExecutionCommand(hostname, Role.HBASE_MASTER, @@ -673,7 +677,7 @@ public class TestActionDBAccessorImpl { private void populateActionDBWithCustomAction(ActionDBAccessor db, String hostname, long requestId, long stageId) throws AmbariException { - Stage s = new Stage(requestId, "/a/b", "cluster1", 1L, "action db accessor test", + Stage s = stageFactory.createNew(requestId, "/a/b", "cluster1", 1L, "action db accessor test", "", "commandParamsStage", "hostParamsStage"); s.setStageId(stageId); s.addHostRoleExecutionCommand(hostname, Role.valueOf(actionName), @@ -693,7 +697,7 @@ public class TestActionDBAccessorImpl { private void populateActionDBWithServerAction(ActionDBAccessor db, String hostname, long requestId, long stageId) throws AmbariException { - Stage s = new Stage(requestId, "/a/b", "cluster1", 1L, "action db accessor test", + Stage s = stageFactory.createNew(requestId, "/a/b", "cluster1", 1L, "action db accessor test", "", "commandParamsStage", "hostParamsStage"); s.setStageId(stageId); s.addServerActionCommand(serverActionName, Role.AMBARI_SERVER_ACTION, RoleCommand.ACTIONEXECUTE, clusterName, null, null, "command details", null, 300, false); http://git-wip-us.apache.org/repos/asf/ambari/blob/ee79dd21/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionManager.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionManager.java b/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionManager.java index 5e20bee..f8b3daf 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionManager.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionManager.java @@ -64,12 +64,15 @@ public class TestActionManager { private Clusters clusters; private UnitOfWork unitOfWork; + private StageFactory stageFactory; @Before public void setup() throws AmbariException { injector = Guice.createInjector(new InMemoryDefaultTestModule()); injector.getInstance(GuiceJpaInitializer.class); clusters = injector.getInstance(Clusters.class); + stageFactory = injector.getInstance(StageFactory.class); + clusters.addHost(hostname); clusters.getHost(hostname).persist(); StackId stackId = new StackId("HDP-0.1"); @@ -169,7 +172,7 @@ public class TestActionManager { } private void populateActionDB(ActionDBAccessor db, String hostname) throws AmbariException { - Stage s = new Stage(requestId, "/a/b", "cluster1", 1L, "action manager test", "clusterHostInfo", "commandParamsStage", "hostParamsStage"); + Stage s = stageFactory.createNew(requestId, "/a/b", "cluster1", 1L, "action manager test", "clusterHostInfo", "commandParamsStage", "hostParamsStage"); s.setStageId(stageId); s.addHostRoleExecutionCommand(hostname, Role.HBASE_MASTER, RoleCommand.START, http://git-wip-us.apache.org/repos/asf/ambari/blob/ee79dd21/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionScheduler.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionScheduler.java b/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionScheduler.java index dd93176..e565922 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionScheduler.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionScheduler.java @@ -46,6 +46,7 @@ import java.util.TreeMap; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; +import com.google.inject.Inject; import junit.framework.Assert; import org.apache.ambari.server.AmbariException; @@ -62,6 +63,10 @@ import org.apache.ambari.server.agent.ExecutionCommand; import org.apache.ambari.server.configuration.Configuration; import org.apache.ambari.server.controller.HostsMap; import org.apache.ambari.server.events.publishers.AmbariEventPublisher; +import org.apache.ambari.server.orm.GuiceJpaInitializer; +import org.apache.ambari.server.orm.InMemoryDefaultTestModule; +import org.apache.ambari.server.orm.dao.HostDAO; +import org.apache.ambari.server.orm.entities.HostEntity; import org.apache.ambari.server.orm.entities.RequestEntity; import org.apache.ambari.server.serveraction.MockServerAction; import org.apache.ambari.server.serveraction.ServerActionExecutor; @@ -80,7 +85,7 @@ import org.apache.ambari.server.state.svccomphost.ServiceComponentHostUpgradeEve import org.apache.ambari.server.utils.StageUtils; import org.easymock.Capture; import org.easymock.EasyMock; -import org.junit.BeforeClass; +import org.junit.Before; import org.junit.Test; import org.mockito.ArgumentCaptor; import org.mockito.invocation.InvocationOnMock; @@ -110,9 +115,23 @@ public class TestActionScheduler { private final String hostname = "ahost.ambari.apache.org"; private final int MAX_CYCLE_ITERATIONS = 100; - @BeforeClass - public static void beforeClass() throws AmbariException { - injector = Guice.createInjector(new MockModule()); + @Inject + HostRoleCommandFactory hostRoleCommandFactory; + + @Inject + StageFactory stageFactory; + + @Inject + StageUtils stageUtils; + + @Inject + HostDAO hostDAO; + + @Before + public void setup() throws Exception { + injector = Guice.createInjector(new InMemoryDefaultTestModule()); + injector.getInstance(GuiceJpaInitializer.class); + injector.injectMembers(this); } /** @@ -121,7 +140,6 @@ public class TestActionScheduler { */ @Test public void testActionSchedule() throws Exception { - Type type = new TypeToken<Map<String, Set<String>>>() {}.getType(); Map<String, List<String>> clusterHostInfo = StageUtils.getGson().fromJson(CLUSTER_HOST_INFO, type); @@ -146,6 +164,9 @@ public class TestActionScheduler { HashMap<String, ServiceComponentHost> hosts = new HashMap<String, ServiceComponentHost>(); hosts.put(hostname, sch); + HostEntity hostEntity = new HostEntity(); + hostEntity.setHostName(hostname); + hostDAO.merge(hostEntity); when(scomp.getServiceComponentHosts()).thenReturn(hosts); when(fsm.getHost(anyString())).thenReturn(host); @@ -387,6 +408,13 @@ public class TestActionScheduler { String hostname2 = "host2"; Host host1 = mock(Host.class); Host host2 = mock(Host.class); + HostEntity hostEntity1 = new HostEntity(); + hostEntity1.setHostName(hostname1); + HostEntity hostEntity2 = new HostEntity(); + hostEntity2.setHostName(hostname2); + hostDAO.merge(hostEntity1); + hostDAO.merge(hostEntity2); + HashMap<String, ServiceComponentHost> hosts = new HashMap<String, ServiceComponentHost>(); hosts.put(hostname1, sch1); @@ -409,7 +437,7 @@ public class TestActionScheduler { when(serviceObj.getCluster()).thenReturn(oneClusterMock); final List<Stage> stages = new ArrayList<Stage>(); - Stage stage = new Stage(1, "/tmp", "cluster1", 1L, "stageWith2Tasks", + Stage stage = stageFactory.createNew(1, "/tmp", "cluster1", 1L, "stageWith2Tasks", CLUSTER_HOST_INFO, "{\"command_param\":\"param_value\"}", "{\"host_param\":\"param_value\"}"); addInstallTaskToStage(stage, hostname1, "cluster1", Role.DATANODE, RoleCommand.INSTALL, Service.Type.HDFS, 1); @@ -788,11 +816,11 @@ public class TestActionScheduler { assertEquals("test", stages.get(0).getRequestContext()); } - private static Stage getStageWithServerAction(long requestId, long stageId, + private Stage getStageWithServerAction(long requestId, long stageId, Map<String, String> payload, String requestContext, int timeout) { String serverHostname = StageUtils.getHostName(); - Stage stage = new Stage(requestId, "/tmp", "cluster1", 1L, requestContext, CLUSTER_HOST_INFO, + Stage stage = stageFactory.createNew(requestId, "/tmp", "cluster1", 1L, requestContext, CLUSTER_HOST_INFO, "{}", "{}"); stage.setStageId(stageId); @@ -1218,6 +1246,7 @@ public class TestActionScheduler { when(scomp.getServiceComponentHost(anyString())).thenReturn(sch); when(serviceObj.getCluster()).thenReturn(oneClusterMock); + String host1 = "host1"; String host2 = "host2"; Host host = mock(Host.class); @@ -1234,7 +1263,7 @@ public class TestActionScheduler { final List<Stage> stages = new ArrayList<Stage>(); long now = System.currentTimeMillis(); - Stage stage = new Stage(1, "/tmp", "cluster1", 1L, + Stage stage = stageFactory.createNew(1, "/tmp", "cluster1", 1L, "testRequestFailureBasedOnSuccessFactor", CLUSTER_HOST_INFO, "", ""); stage.setStageId(1); @@ -1384,6 +1413,7 @@ public class TestActionScheduler { stage.getOrderedHostRoleCommands().get(index).setStatus(statusesAtIterThree[index]); } + // Fails becuse HostRoleCommand doesn't have a hostName scheduler.doWork(); // Request is aborted because HBASE_CLIENT's success factor (1) is not met @@ -1425,7 +1455,7 @@ public class TestActionScheduler { final List<Stage> stages = new ArrayList<Stage>(); long now = System.currentTimeMillis(); - Stage stage = new Stage(1, "/tmp", "cluster1", 1L, "testRequestFailureBasedOnSuccessFactor", + Stage stage = stageFactory.createNew(1, "/tmp", "cluster1", 1L, "testRequestFailureBasedOnSuccessFactor", CLUSTER_HOST_INFO, "", ""); stage.setStageId(1); stage.addHostRoleExecutionCommand("host1", Role.DATANODE, RoleCommand.UPGRADE, @@ -1567,7 +1597,7 @@ public class TestActionScheduler { private Stage getStageWithSingleTask(String hostname, String clusterName, Role role, RoleCommand roleCommand, Service.Type service, int taskId, int stageId, int requestId) { - Stage stage = new Stage(requestId, "/tmp", clusterName, 1L, "getStageWithSingleTask", + Stage stage = stageFactory.createNew(requestId, "/tmp", clusterName, 1L, "getStageWithSingleTask", CLUSTER_HOST_INFO, "{\"host_param\":\"param_value\"}", "{\"stage_param\":\"param_value\"}"); stage.setStageId(stageId); stage.addHostRoleExecutionCommand(hostname, role, roleCommand, @@ -1719,7 +1749,6 @@ public class TestActionScheduler { assertTrue(ac.get(0) instanceof ExecutionCommand); assertEquals(String.valueOf(requestId2) + "-" + stageId, ((ExecutionCommand) (ac.get(0))).getCommandId()); assertEquals(clusterHostInfo2, ((ExecutionCommand) (ac.get(0))).getClusterHostInfo()); - } @@ -1763,7 +1792,7 @@ public class TestActionScheduler { when(serviceObj.getCluster()).thenReturn(oneClusterMock); final List<Stage> stages = new ArrayList<Stage>(); - Stage stage1 = new Stage(1, "/tmp", "cluster1", 1L, "stageWith2Tasks", + Stage stage1 = stageFactory.createNew(1, "/tmp", "cluster1", 1L, "stageWith2Tasks", CLUSTER_HOST_INFO, "", ""); addInstallTaskToStage(stage1, hostname1, "cluster1", Role.HBASE_MASTER, RoleCommand.INSTALL, Service.Type.HBASE, 1); @@ -2246,6 +2275,9 @@ public class TestActionScheduler { ActionQueue aq = new ActionQueue(); Clusters fsm = EasyMock.createMock(Clusters.class); Configuration conf = new Configuration(new Properties()); + HostEntity hostEntity1 = new HostEntity(); + hostEntity1.setHostName("h1"); + hostDAO.merge(hostEntity1); db.abortHostRole("h1", -1L, -1L, "AMBARI_SERVER_ACTION"); EasyMock.expectLastCall(); @@ -2256,11 +2288,11 @@ public class TestActionScheduler { new HostsMap((String) null), unitOfWork, null, conf); - HostRoleCommand hrc1 = new HostRoleCommand("h1", Role.NAMENODE, null, RoleCommand.EXECUTE); + HostRoleCommand hrc1 = hostRoleCommandFactory.create("h1", Role.NAMENODE, null, RoleCommand.EXECUTE); hrc1.setStatus(HostRoleStatus.COMPLETED); - HostRoleCommand hrc3 = new HostRoleCommand("h1", Role.AMBARI_SERVER_ACTION, null, RoleCommand.CUSTOM_COMMAND); + HostRoleCommand hrc3 = hostRoleCommandFactory.create("h1", Role.AMBARI_SERVER_ACTION, null, RoleCommand.CUSTOM_COMMAND); hrc3.setStatus(HostRoleStatus.HOLDING); - HostRoleCommand hrc4 = new HostRoleCommand("h1", Role.FLUME_HANDLER, null, RoleCommand.EXECUTE); + HostRoleCommand hrc4 = hostRoleCommandFactory.create("h1", Role.FLUME_HANDLER, null, RoleCommand.EXECUTE); hrc4.setStatus(HostRoleStatus.PENDING); List<HostRoleCommand> hostRoleCommands = Arrays.asList(hrc1, hrc3, hrc4); http://git-wip-us.apache.org/repos/asf/ambari/blob/ee79dd21/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestStage.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestStage.java b/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestStage.java index 7ee6045..13453df 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestStage.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestStage.java @@ -19,10 +19,16 @@ package org.apache.ambari.server.actionmanager; import static org.junit.Assert.*; +import com.google.inject.Guice; +import com.google.inject.Inject; +import com.google.inject.Injector; import org.apache.ambari.server.Role; import org.apache.ambari.server.RoleCommand; 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.utils.StageUtils; +import org.junit.Before; import org.junit.Test; import java.util.Map; @@ -32,6 +38,21 @@ public class TestStage { private static final String CLUSTER_HOST_INFO = "cluster_host_info"; + Injector injector; + + @Inject + StageFactory stageFactory; + + @Inject + StageUtils stageUtils; + + @Before + public void setup() throws Exception { + injector = Guice.createInjector(new InMemoryDefaultTestModule()); + injector.getInstance(GuiceJpaInitializer.class); + injector.injectMembers(this); + } + @Test public void testTaskTimeout() { Stage s = StageUtils.getATestStage(1, 1, "h1", CLUSTER_HOST_INFO, "{\"host_param\":\"param_value\"}", "{\"stage_param\":\"param_value\"}"); @@ -49,11 +70,8 @@ public class TestStage { @Test public void testGetRequestContext() { - - Stage stage = new Stage(1, "/logDir", "c1", 1L, "My Context", CLUSTER_HOST_INFO, "", ""); + Stage stage = stageFactory.createNew(1, "/logDir", "c1", 1L, "My Context", CLUSTER_HOST_INFO, "", ""); assertEquals("My Context", stage.getRequestContext()); assertEquals(CLUSTER_HOST_INFO, stage.getClusterHostInfo()); } - - } http://git-wip-us.apache.org/repos/asf/ambari/blob/ee79dd21/ambari-server/src/test/java/org/apache/ambari/server/agent/AgentResourceTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/agent/AgentResourceTest.java b/ambari-server/src/test/java/org/apache/ambari/server/agent/AgentResourceTest.java index f4d9c63..273158f 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/agent/AgentResourceTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/agent/AgentResourceTest.java @@ -29,6 +29,7 @@ import junit.framework.Assert; import org.apache.ambari.server.actionmanager.ActionDBAccessor; import org.apache.ambari.server.actionmanager.ActionManager; import org.apache.ambari.server.actionmanager.HostRoleCommandFactory; +import org.apache.ambari.server.actionmanager.HostRoleCommandFactoryImpl; import org.apache.ambari.server.actionmanager.StageFactory; import org.apache.ambari.server.agent.rest.AgentResource; import org.apache.ambari.server.api.services.AmbariMetaInfo; @@ -329,7 +330,8 @@ public class AgentResourceTest extends JerseyTest { install(new FactoryModuleBuilder().implement(RequestExecution.class, RequestExecutionImpl.class).build(RequestExecutionFactory.class)); install(new FactoryModuleBuilder().build(StageFactory.class)); - install(new FactoryModuleBuilder().build(HostRoleCommandFactory.class)); + + bind(HostRoleCommandFactory.class).to(HostRoleCommandFactoryImpl.class); bind(SecurityHelper.class).toInstance(SecurityHelperImpl.getInstance()); bind(AmbariEventPublisher.class).toInstance(EasyMock.createMock(AmbariEventPublisher.class)); bind(StackManagerFactory.class).toInstance( http://git-wip-us.apache.org/repos/asf/ambari/blob/ee79dd21/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java b/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java index 5ae6d5d..39192c4 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java @@ -70,10 +70,12 @@ import org.apache.ambari.server.actionmanager.ActionDBAccessor; import org.apache.ambari.server.actionmanager.ActionDBAccessorImpl; import org.apache.ambari.server.actionmanager.ActionManager; import org.apache.ambari.server.actionmanager.HostRoleCommand; +import org.apache.ambari.server.actionmanager.HostRoleCommandFactory; import org.apache.ambari.server.actionmanager.HostRoleStatus; import org.apache.ambari.server.actionmanager.Request; import org.apache.ambari.server.actionmanager.RequestFactory; import org.apache.ambari.server.actionmanager.Stage; +import org.apache.ambari.server.actionmanager.StageFactory; import org.apache.ambari.server.agent.HostStatus.Status; import org.apache.ambari.server.api.services.AmbariMetaInfo; import org.apache.ambari.server.configuration.Configuration; @@ -82,8 +84,8 @@ import org.apache.ambari.server.events.publishers.AmbariEventPublisher; 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.RepositoryVersionDAO; -import org.apache.ambari.server.orm.entities.RepositoryVersionEntity; +import org.apache.ambari.server.orm.dao.*; +import org.apache.ambari.server.orm.entities.*; import org.apache.ambari.server.serveraction.kerberos.KerberosIdentityDataFileWriter; import org.apache.ambari.server.serveraction.kerberos.KerberosIdentityDataFileWriterFactory; import org.apache.ambari.server.serveraction.kerberos.KerberosServerAction; @@ -133,15 +135,38 @@ public class TestHeartbeatHandler { long requestId = 23; long stageId = 31; + private final static StackId HDP_22_STACK = new StackId("HDP", "2.2.0"); + @Inject AmbariMetaInfo metaInfo; + @Inject Configuration config; + @Inject ActionDBAccessor actionDBAccessor; + @Inject OrmTestHelper helper; + @Inject + ResourceTypeDAO resourceTypeDAO; + + @Inject + StackDAO stackDAO; + + @Inject + ClusterDAO clusterDAO; + + @Inject + HostDAO hostDAO; + + @Inject + StageFactory stageFactory; + + @Inject + HostRoleCommandFactory hostRoleCommandFactory; + private UnitOfWork unitOfWork; @Rule @@ -224,12 +249,6 @@ public class TestHeartbeatHandler { @SuppressWarnings("unchecked") public void testHeartbeatWithConfigs() throws Exception { Cluster cluster = getDummyCluster(); - - @SuppressWarnings("serial") - Set<String> hostNames = new HashSet<String>(){{ - add(DummyHostname1); - }}; - clusters.mapHostsToCluster(hostNames, DummyCluster); Service hdfs = cluster.addService(HDFS); hdfs.persist(); hdfs.addServiceComponent(DATANODE).persist(); @@ -273,7 +292,9 @@ public class TestHeartbeatHandler { reports.add(cr); hb.setReports(reports); - final HostRoleCommand command = new HostRoleCommand(DummyHostname1, + HostEntity host1 = hostDAO.findByName(DummyHostname1); + Assert.assertNotNull(host1); + final HostRoleCommand command = hostRoleCommandFactory.create(DummyHostname1, Role.DATANODE, null, null); ActionManager am = getMockActionManager(); @@ -295,12 +316,6 @@ public class TestHeartbeatHandler { @SuppressWarnings("unchecked") public void testRestartRequiredAfterInstallClient() throws Exception { Cluster cluster = getDummyCluster(); - - @SuppressWarnings("serial") - Set<String> hostNames = new HashSet<String>(){{ - add(DummyHostname1); - }}; - clusters.mapHostsToCluster(hostNames, DummyCluster); Service hdfs = cluster.addService(HDFS); hdfs.persist(); hdfs.addServiceComponent(HDFS_CLIENT).persist(); @@ -339,7 +354,7 @@ public class TestHeartbeatHandler { reports.add(cr); hb.setReports(reports); - final HostRoleCommand command = new HostRoleCommand(DummyHostname1, + final HostRoleCommand command = hostRoleCommandFactory.create(DummyHostname1, Role.DATANODE, null, null); ActionManager am = getMockActionManager(); @@ -363,12 +378,6 @@ public class TestHeartbeatHandler { @SuppressWarnings("unchecked") public void testHeartbeatCustomCommandWithConfigs() throws Exception { Cluster cluster = getDummyCluster(); - - @SuppressWarnings("serial") - Set<String> hostNames = new HashSet<String>(){{ - add(DummyHostname1); - }}; - clusters.mapHostsToCluster(hostNames, DummyCluster); Service hdfs = cluster.addService(HDFS); hdfs.persist(); hdfs.addServiceComponent(DATANODE).persist(); @@ -428,7 +437,7 @@ public class TestHeartbeatHandler { reports.add(crn); hb.setReports(reports); - final HostRoleCommand command = new HostRoleCommand(DummyHostname1, + final HostRoleCommand command = hostRoleCommandFactory.create(DummyHostname1, Role.DATANODE, null, null); ActionManager am = getMockActionManager(); @@ -453,12 +462,6 @@ public class TestHeartbeatHandler { @SuppressWarnings("unchecked") public void testHeartbeatCustomStartStop() throws Exception { Cluster cluster = getDummyCluster(); - - @SuppressWarnings("serial") - Set<String> hostNames = new HashSet<String>(){{ - add(DummyHostname1); - }}; - clusters.mapHostsToCluster(hostNames, DummyCluster); Service hdfs = cluster.addService(HDFS); hdfs.persist(); hdfs.addServiceComponent(DATANODE).persist(); @@ -516,7 +519,7 @@ public class TestHeartbeatHandler { assertTrue(serviceComponentHost1.isRestartRequired()); - final HostRoleCommand command = new HostRoleCommand(DummyHostname1, + final HostRoleCommand command = hostRoleCommandFactory.create(DummyHostname1, Role.DATANODE, null, null); ActionManager am = getMockActionManager(); @@ -543,12 +546,6 @@ public class TestHeartbeatHandler { @SuppressWarnings("unchecked") public void testStatusHeartbeat() throws Exception { Cluster cluster = getDummyCluster(); - - @SuppressWarnings("serial") - Set<String> hostNames = new HashSet<String>(){{ - add(DummyHostname1); - }}; - clusters.mapHostsToCluster(hostNames, DummyCluster); Service hdfs = cluster.addService(HDFS); hdfs.persist(); hdfs.addServiceComponent(DATANODE).persist(); @@ -597,7 +594,7 @@ public class TestHeartbeatHandler { componentStatuses.add(componentStatus2); hb.setComponentStatus(componentStatuses); - final HostRoleCommand command = new HostRoleCommand(DummyHostname1, + final HostRoleCommand command = hostRoleCommandFactory.create(DummyHostname1, Role.DATANODE, null, null); ActionManager am = getMockActionManager(); @@ -625,12 +622,6 @@ public class TestHeartbeatHandler { @SuppressWarnings("unchecked") public void testStatusHeartbeatWithAnnotation() throws Exception { Cluster cluster = getDummyCluster(); - - @SuppressWarnings("serial") - Set<String> hostNames = new HashSet<String>(){{ - add(DummyHostname1); - }}; - clusters.mapHostsToCluster(hostNames, DummyCluster); Service hdfs = cluster.addService(HDFS); hdfs.persist(); hdfs.addServiceComponent(DATANODE).persist(); @@ -648,7 +639,7 @@ public class TestHeartbeatHandler { ArrayList<ComponentStatus> componentStatuses = new ArrayList<ComponentStatus>(); hb.setComponentStatus(componentStatuses); - final HostRoleCommand command = new HostRoleCommand(DummyHostname1, + final HostRoleCommand command = hostRoleCommandFactory.create(DummyHostname1, Role.DATANODE, null, null); ActionManager am = getMockActionManager(); @@ -683,12 +674,6 @@ public class TestHeartbeatHandler { @SuppressWarnings("unchecked") public void testLiveStatusUpdateAfterStopFailed() throws Exception { Cluster cluster = getDummyCluster(); - - @SuppressWarnings("serial") - Set<String> hostNames = new HashSet<String>(){{ - add(DummyHostname1); - }}; - clusters.mapHostsToCluster(hostNames, DummyCluster); Service hdfs = cluster.addService(HDFS); hdfs.persist(); hdfs.addServiceComponent(DATANODE).persist(); @@ -739,7 +724,7 @@ public class TestHeartbeatHandler { hb.setComponentStatus(componentStatuses); - final HostRoleCommand command = new HostRoleCommand(DummyHostname1, + final HostRoleCommand command = hostRoleCommandFactory.create(DummyHostname1, Role.DATANODE, null, null); ActionManager am = getMockActionManager(); @@ -804,7 +789,7 @@ public class TestHeartbeatHandler { } private void populateActionDB(ActionDBAccessor db, String DummyHostname1) throws AmbariException { - Stage s = new Stage(requestId, "/a/b", DummyCluster, 1L, "heartbeat handler test", + Stage s = stageFactory.createNew(requestId, "/a/b", DummyCluster, 1L, "heartbeat handler test", "clusterHostInfo", "commandParamsStage", "hostParamsStage"); s.setStageId(stageId); String filename = null; @@ -1144,12 +1129,6 @@ public class TestHeartbeatHandler { @SuppressWarnings("unchecked") public void testTaskInProgressHandling() throws AmbariException, InvalidStateTransitionException { Cluster cluster = getDummyCluster(); - - @SuppressWarnings("serial") - Set<String> hostNames = new HashSet<String>(){{ - add(DummyHostname1); - }}; - clusters.mapHostsToCluster(hostNames, DummyCluster); Service hdfs = cluster.addService(HDFS); hdfs.persist(); hdfs.addServiceComponent(DATANODE).persist(); @@ -1187,7 +1166,7 @@ public class TestHeartbeatHandler { hb.setReports(reports); hb.setComponentStatus(new ArrayList<ComponentStatus>()); - final HostRoleCommand command = new HostRoleCommand(DummyHostname1, + final HostRoleCommand command = hostRoleCommandFactory.create(DummyHostname1, Role.DATANODE, null, RoleCommand.INSTALL); ActionManager am = getMockActionManager(); @@ -1207,12 +1186,6 @@ public class TestHeartbeatHandler { @SuppressWarnings("unchecked") public void testOPFailedEventForAbortedTask() throws AmbariException, InvalidStateTransitionException { Cluster cluster = getDummyCluster(); - - @SuppressWarnings("serial") - Set<String> hostNames = new HashSet<String>(){{ - add(DummyHostname1); - }}; - clusters.mapHostsToCluster(hostNames, DummyCluster); Service hdfs = cluster.addService(HDFS); hdfs.persist(); hdfs.addServiceComponent(DATANODE).persist(); @@ -1228,7 +1201,7 @@ public class TestHeartbeatHandler { getServiceComponent(DATANODE).getServiceComponentHost(DummyHostname1); serviceComponentHost1.setState(State.INSTALLING); - Stage s = new Stage(1, "/a/b", "cluster1", 1L, "action manager test", + Stage s = stageFactory.createNew(1, "/a/b", "cluster1", 1L, "action manager test", "clusterHostInfo", "commandParamsStage", "hostParamsStage"); s.setStageId(1); s.addHostRoleExecutionCommand(DummyHostname1, Role.DATANODE, RoleCommand.INSTALL, @@ -1263,7 +1236,7 @@ public class TestHeartbeatHandler { hb.setReports(reports); hb.setComponentStatus(new ArrayList<ComponentStatus>()); - final HostRoleCommand command = new HostRoleCommand(DummyHostname1, + final HostRoleCommand command = hostRoleCommandFactory.create(DummyHostname1, Role.DATANODE, null, null); ActionManager am = getMockActionManager(); @@ -1292,12 +1265,6 @@ public class TestHeartbeatHandler { public void testCommandReportOnHeartbeatUpdatedState() throws AmbariException, InvalidStateTransitionException { Cluster cluster = getDummyCluster(); - - @SuppressWarnings("serial") - Set<String> hostNames = new HashSet<String>() {{ - add(DummyHostname1); - }}; - clusters.mapHostsToCluster(hostNames, DummyCluster); Service hdfs = cluster.addService(HDFS); hdfs.persist(); hdfs.addServiceComponent(DATANODE).persist(); @@ -1331,7 +1298,7 @@ public class TestHeartbeatHandler { hb.setReports(reports); hb.setComponentStatus(new ArrayList<ComponentStatus>()); - final HostRoleCommand command = new HostRoleCommand(DummyHostname1, + final HostRoleCommand command = hostRoleCommandFactory.create(DummyHostname1, Role.DATANODE, null, null); ActionManager am = getMockActionManager(); @@ -1416,12 +1383,6 @@ public class TestHeartbeatHandler { @SuppressWarnings("unchecked") public void testUpgradeSpecificHandling() throws AmbariException, InvalidStateTransitionException { Cluster cluster = getDummyCluster(); - - @SuppressWarnings("serial") - Set<String> hostNames = new HashSet<String>() {{ - add(DummyHostname1); - }}; - clusters.mapHostsToCluster(hostNames, DummyCluster); Service hdfs = cluster.addService(HDFS); hdfs.persist(); hdfs.addServiceComponent(DATANODE).persist(); @@ -1455,7 +1416,7 @@ public class TestHeartbeatHandler { hb.setReports(reports); hb.setComponentStatus(new ArrayList<ComponentStatus>()); - final HostRoleCommand command = new HostRoleCommand(DummyHostname1, + final HostRoleCommand command = hostRoleCommandFactory.create(DummyHostname1, Role.DATANODE, null, null); ActionManager am = getMockActionManager(); @@ -1514,14 +1475,6 @@ public class TestHeartbeatHandler { @SuppressWarnings("unchecked") public void testStatusHeartbeatWithVersion() throws Exception { Cluster cluster = getDummyCluster(); - - @SuppressWarnings("serial") - Set<String> hostNames = new HashSet<String>(){{ - add(DummyHostname1); - }}; - - clusters.mapHostsToCluster(hostNames, DummyCluster); - Service hdfs = cluster.addService(HDFS); hdfs.persist(); hdfs.addServiceComponent(DATANODE).persist(); @@ -1591,14 +1544,6 @@ public class TestHeartbeatHandler { @SuppressWarnings("unchecked") public void testComponentUpgradeCompleteReport() throws AmbariException, InvalidStateTransitionException { Cluster cluster = getDummyCluster(); - - @SuppressWarnings("serial") - Set<String> hostNames = new HashSet<String>(){{ - add(DummyHostname1); - }}; - - clusters.mapHostsToCluster(hostNames, DummyCluster); - Service hdfs = cluster.addService(HDFS); hdfs.persist(); hdfs.addServiceComponent(DATANODE).persist(); @@ -1657,7 +1602,7 @@ public class TestHeartbeatHandler { hb.setReports(reports); ActionQueue aq = new ActionQueue(); - final HostRoleCommand command = new HostRoleCommand(DummyHostname1, + final HostRoleCommand command = hostRoleCommandFactory.create(DummyHostname1, Role.DATANODE, null, null); ActionManager am = getMockActionManager(); @@ -1681,14 +1626,6 @@ public class TestHeartbeatHandler { @SuppressWarnings("unchecked") public void testComponentUpgradeInProgressReport() throws AmbariException, InvalidStateTransitionException { Cluster cluster = getDummyCluster(); - - @SuppressWarnings("serial") - Set<String> hostNames = new HashSet<String>(){{ - add(DummyHostname1); - }}; - - clusters.mapHostsToCluster(hostNames, DummyCluster); - Service hdfs = cluster.addService(HDFS); hdfs.persist(); hdfs.addServiceComponent(DATANODE).persist(); @@ -1747,7 +1684,7 @@ public class TestHeartbeatHandler { hb.setReports(reports); ActionQueue aq = new ActionQueue(); - final HostRoleCommand command = new HostRoleCommand(DummyHostname1, + final HostRoleCommand command = hostRoleCommandFactory.create(DummyHostname1, Role.DATANODE, null, null); ActionManager am = getMockActionManager(); @@ -1773,14 +1710,6 @@ public class TestHeartbeatHandler { @SuppressWarnings("unchecked") public void testComponentUpgradeFailReport() throws AmbariException, InvalidStateTransitionException { Cluster cluster = getDummyCluster(); - - @SuppressWarnings("serial") - Set<String> hostNames = new HashSet<String>(){{ - add(DummyHostname1); - }}; - - clusters.mapHostsToCluster(hostNames, DummyCluster); - Service hdfs = cluster.addService(HDFS); hdfs.persist(); hdfs.addServiceComponent(DATANODE).persist(); @@ -1805,8 +1734,8 @@ public class TestHeartbeatHandler { serviceComponentHost1.setDesiredStackVersion(stack130); serviceComponentHost2.setStackVersion(stack120); - Stage s = new Stage(requestId, "/a/b", "cluster1", 1L, "action manager test", - "clusterHostInfo", "commandParamsStage", "hostParamsStage"); + Stage s = stageFactory.createNew(requestId, "/a/b", "cluster1", 1L, "action manager test", + "clusterHostInfo", "commandParamsStage", "hostParamsStage"); s.setStageId(stageId); s.addHostRoleExecutionCommand(DummyHostname1, Role.DATANODE, RoleCommand.UPGRADE, new ServiceComponentHostUpgradeEvent(Role.DATANODE.toString(), @@ -1870,7 +1799,7 @@ public class TestHeartbeatHandler { hb.setReports(reports); ActionQueue aq = new ActionQueue(); - final HostRoleCommand command = new HostRoleCommand(DummyHostname1, + final HostRoleCommand command = hostRoleCommandFactory.create(DummyHostname1, Role.DATANODE, null, null); ActionManager am = getMockActionManager(); @@ -1903,7 +1832,6 @@ public class TestHeartbeatHandler { Cluster cluster = getDummyCluster(); Host hostObject = clusters.getHost(DummyHostname1); - clusters.mapHostToCluster(hostObject.getHostName(), cluster.getClusterName()); Service hdfs = cluster.addService(HDFS); hdfs.persist(); hdfs.addServiceComponent(DATANODE).persist(); @@ -1915,8 +1843,7 @@ public class TestHeartbeatHandler { ActionQueue aq = new ActionQueue(); - final HostRoleCommand command = new HostRoleCommand(DummyHostname1, - Role.DATANODE, null, null); + final HostRoleCommand command = hostRoleCommandFactory.create(DummyHostname1, Role.DATANODE, null, null); ActionManager am = getMockActionManager(); expect(am.getTasks(anyObject(List.class))).andReturn( new ArrayList<HostRoleCommand>() {{ @@ -1987,7 +1914,6 @@ public class TestHeartbeatHandler { Cluster cluster = getDummyCluster(); Host hostObject = clusters.getHost(DummyHostname1); - clusters.mapHostToCluster(hostObject.getHostName(), cluster.getClusterName()); Service hdfs = cluster.addService(HDFS); hdfs.persist(); hdfs.addServiceComponent(DATANODE).persist(); @@ -1999,7 +1925,7 @@ public class TestHeartbeatHandler { ActionQueue aq = new ActionQueue(); - final HostRoleCommand command = new HostRoleCommand(DummyHostname1, + final HostRoleCommand command = hostRoleCommandFactory.create(DummyHostname1, Role.DATANODE, null, null); ActionManager am = getMockActionManager(); expect(am.getTasks(anyObject(List.class))).andReturn( @@ -2221,7 +2147,7 @@ public class TestHeartbeatHandler { ActionQueue aq = new ActionQueue(); - final HostRoleCommand command = new HostRoleCommand(DummyHostname1, + final HostRoleCommand command = hostRoleCommandFactory.create(DummyHostname1, Role.DATANODE, null, null); ActionManager am = getMockActionManager(); @@ -2338,26 +2264,58 @@ public class TestHeartbeatHandler { private Cluster getDummyCluster() throws AmbariException { - clusters.addHost(DummyHostname1); - clusters.getHost(DummyHostname1).setOsType(DummyOsType); - - Map<String, String> hostAttributes = new HashMap<String, String>(); - hostAttributes.put("os_family", "redhat"); - hostAttributes.put("os_release_version", "6.3"); - clusters.getHost(DummyHostname1).setHostAttributes(hostAttributes); - - clusters.getHost(DummyHostname1).persist(); - + StackEntity stackEntity = stackDAO.find(HDP_22_STACK.getStackName(), HDP_22_STACK.getStackVersion()); + org.junit.Assert.assertNotNull(stackEntity); + + // Create the cluster + ResourceTypeEntity resourceTypeEntity = new ResourceTypeEntity(); + resourceTypeEntity.setId(ResourceTypeEntity.CLUSTER_RESOURCE_TYPE); + resourceTypeEntity.setName(ResourceTypeEntity.CLUSTER_RESOURCE_TYPE_NAME); + resourceTypeEntity = resourceTypeDAO.merge(resourceTypeEntity); + + ResourceEntity resourceEntity = new ResourceEntity(); + resourceEntity.setResourceType(resourceTypeEntity); + + ClusterEntity clusterEntity = new ClusterEntity(); + clusterEntity.setClusterName(DummyCluster); + clusterEntity.setClusterInfo("test_cluster_info1"); + clusterEntity.setResource(resourceEntity); + clusterEntity.setDesiredStack(stackEntity); + + clusterDAO.create(clusterEntity); + StackId stackId = new StackId(DummyStackId); - clusters.addCluster(DummyCluster, stackId); - + Cluster cluster = clusters.getCluster(DummyCluster); - + cluster.setDesiredStackVersion(stackId); cluster.setCurrentStackVersion(stackId); helper.getOrCreateRepositoryVersion(stackId, stackId.getStackVersion()); cluster.createClusterVersion(stackId, stackId.getStackVersion(), "admin", RepositoryVersionState.UPGRADING); + + Set<String> hostNames = new HashSet<String>(){{ + add(DummyHostname1); + }}; + + Map<String, String> hostAttributes = new HashMap<String, String>(); + hostAttributes.put("os_family", "redhat"); + hostAttributes.put("os_release_version", "6.3"); + + List<HostEntity> hostEntities = new ArrayList<HostEntity>(); + for(String hostName : hostNames) { + clusters.addHost(hostName); + Host host = clusters.getHost(hostName); + host.setHostAttributes(hostAttributes); + host.persist(); + + HostEntity hostEntity = hostDAO.findByName(hostName); + Assert.assertNotNull(hostEntity); + hostEntities.add(hostEntity); + } + clusterEntity.setHostEntities(hostEntities); + clusters.mapHostsToCluster(hostNames, DummyCluster); + return cluster; } @@ -2365,8 +2323,6 @@ public class TestHeartbeatHandler { @SuppressWarnings("unchecked") public void testCommandStatusProcesses() throws Exception { Cluster cluster = getDummyCluster(); - Host hostObject = clusters.getHost(DummyHostname1); - clusters.mapHostToCluster(hostObject.getHostName(), cluster.getClusterName()); Service hdfs = cluster.addService(HDFS); hdfs.persist(); hdfs.addServiceComponent(DATANODE).persist(); @@ -2409,7 +2365,7 @@ public class TestHeartbeatHandler { componentStatuses.add(componentStatus1); hb.setComponentStatus(componentStatuses); - final HostRoleCommand command = new HostRoleCommand(DummyHostname1, + final HostRoleCommand command = hostRoleCommandFactory.create(DummyHostname1, Role.DATANODE, null, null); ActionManager am = getMockActionManager(); @@ -2448,8 +2404,6 @@ public class TestHeartbeatHandler { @SuppressWarnings("unchecked") public void testCommandStatusProcesses_empty() throws Exception { Cluster cluster = getDummyCluster(); - Host hostObject = clusters.getHost(DummyHostname1); - clusters.mapHostToCluster(hostObject.getHostName(), cluster.getClusterName()); Service hdfs = cluster.addService(HDFS); hdfs.persist(); hdfs.addServiceComponent(DATANODE).persist(); @@ -2476,7 +2430,7 @@ public class TestHeartbeatHandler { componentStatuses.add(componentStatus1); hb.setComponentStatus(componentStatuses); - final HostRoleCommand command = new HostRoleCommand(DummyHostname1, + final HostRoleCommand command = hostRoleCommandFactory.create(DummyHostname1, Role.DATANODE, null, null); ActionManager am = getMockActionManager(); @@ -2509,15 +2463,6 @@ public class TestHeartbeatHandler { replay(am); Cluster cluster = getDummyCluster(); - - @SuppressWarnings("serial") - Set<String> hostNames = new HashSet<String>() { - { - add(DummyHostname1); - } - }; - clusters.mapHostsToCluster(hostNames, DummyCluster); - Clusters fsm = clusters; Host hostObject = clusters.getHost(DummyHostname1); hostObject.setIPv4("ipv4"); @@ -2569,7 +2514,7 @@ public class TestHeartbeatHandler { // heartbeat which performs some async tasks EventBusSynchronizer.synchronizeAmbariEventPublisher(injector); - final HostRoleCommand command = new HostRoleCommand(DummyHostname1, + final HostRoleCommand command = hostRoleCommandFactory.create(DummyHostname1, Role.DATANODE, null, null); ActionManager am = getMockActionManager(); @@ -2578,14 +2523,6 @@ public class TestHeartbeatHandler { replay(am); Cluster cluster = getDummyCluster(); - - @SuppressWarnings("serial") - Set<String> hostNames = new HashSet<String>() {{ - add(DummyHostname1); - }}; - clusters.mapHostsToCluster(hostNames, DummyCluster); - - HeartBeatHandler handler = getHeartBeatHandler(am, new ActionQueue()); HeartBeat hb = new HeartBeat(); @@ -2698,7 +2635,7 @@ public class TestHeartbeatHandler { ActionQueue aq = new ActionQueue(); - final HostRoleCommand command = new HostRoleCommand(DummyHostname1, + final HostRoleCommand command = hostRoleCommandFactory.create(DummyHostname1, Role.DATANODE, null, null); ActionManager am = getMockActionManager(); @@ -2729,7 +2666,7 @@ public class TestHeartbeatHandler { ActionQueue aq = new ActionQueue(); - final HostRoleCommand command = new HostRoleCommand(DummyHostname1, + final HostRoleCommand command = hostRoleCommandFactory.create(DummyHostname1, Role.DATANODE, null, null); ActionManager am = getMockActionManager(); http://git-wip-us.apache.org/repos/asf/ambari/blob/ee79dd21/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelperTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelperTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelperTest.java index 947a76f..33bb830 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelperTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariCustomCommandExecutionHelperTest.java @@ -63,8 +63,7 @@ import com.google.inject.Injector; import com.google.inject.persist.PersistService; @RunWith(MockitoJUnitRunner.class) -public class - AmbariCustomCommandExecutionHelperTest { +public class AmbariCustomCommandExecutionHelperTest { private Injector injector; private AmbariManagementController controller; private AmbariMetaInfo ambariMetaInfo; @@ -98,10 +97,6 @@ public class injector.getInstance(PersistService.class).stop(); } - - - - @SuppressWarnings("serial") @Test public void testRefreshQueueCustomCommand() { http://git-wip-us.apache.org/repos/asf/ambari/blob/ee79dd21/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java index 0ac1ba4..06f9e8a 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java @@ -73,6 +73,7 @@ import org.apache.ambari.server.actionmanager.HostRoleCommand; import org.apache.ambari.server.actionmanager.HostRoleStatus; import org.apache.ambari.server.actionmanager.Request; import org.apache.ambari.server.actionmanager.Stage; +import org.apache.ambari.server.actionmanager.StageFactory; import org.apache.ambari.server.actionmanager.TargetHostType; import org.apache.ambari.server.agent.ExecutionCommand; import org.apache.ambari.server.api.services.AmbariMetaInfo; @@ -197,6 +198,7 @@ public class AmbariManagementControllerTest { private ConfigHelper configHelper; private ConfigGroupFactory configGroupFactory; private OrmTestHelper helper; + private StageFactory stageFactory; @Rule public ExpectedException expectedException = ExpectedException.none(); @@ -223,6 +225,7 @@ public class AmbariManagementControllerTest { configHelper = injector.getInstance(ConfigHelper.class); configGroupFactory = injector.getInstance(ConfigGroupFactory.class); helper = injector.getInstance(OrmTestHelper.class); + stageFactory = injector.getInstance(StageFactory.class); } @After @@ -7776,8 +7779,8 @@ public class AmbariManagementControllerTest { List<Stage> stages = new ArrayList<Stage>(); - stages.add(new Stage(requestId1, "/a1", clusterName, 1L, context, - CLUSTER_HOST_INFO, "", "")); + stages.add(stageFactory.createNew(requestId1, "/a1", clusterName, 1L, context, + CLUSTER_HOST_INFO, "", "")); stages.get(0).setStageId(1); stages.get(0).addHostRoleExecutionCommand(hostName1, Role.HBASE_MASTER, RoleCommand.START, @@ -7785,7 +7788,7 @@ public class AmbariManagementControllerTest { hostName1, System.currentTimeMillis()), clusterName, "HBASE", false); - stages.add(new Stage(requestId1, "/a2", clusterName, 1L, context, + stages.add(stageFactory.createNew(requestId1, "/a2", clusterName, 1L, context, CLUSTER_HOST_INFO, "", "")); stages.get(1).setStageId(2); stages.get(1).addHostRoleExecutionCommand(hostName1, Role.HBASE_CLIENT, @@ -7793,7 +7796,7 @@ public class AmbariManagementControllerTest { new ServiceComponentHostStartEvent(Role.HBASE_CLIENT.toString(), hostName1, System.currentTimeMillis()), clusterName, "HBASE", false); - stages.add(new Stage(requestId1, "/a3", clusterName, 1L, context, + stages.add(stageFactory.createNew(requestId1, "/a3", clusterName, 1L, context, CLUSTER_HOST_INFO, "", "")); stages.get(2).setStageId(3); stages.get(2).addHostRoleExecutionCommand(hostName1, Role.HBASE_CLIENT, @@ -7805,7 +7808,7 @@ public class AmbariManagementControllerTest { actionDB.persistActions(request); stages.clear(); - stages.add(new Stage(requestId2, "/a4", clusterName, 1L, context, + stages.add(stageFactory.createNew(requestId2, "/a4", clusterName, 1L, context, CLUSTER_HOST_INFO, "", "")); stages.get(0).setStageId(4); stages.get(0).addHostRoleExecutionCommand(hostName1, Role.HBASE_CLIENT, @@ -7813,7 +7816,7 @@ public class AmbariManagementControllerTest { new ServiceComponentHostStartEvent(Role.HBASE_CLIENT.toString(), hostName1, System.currentTimeMillis()), clusterName, "HBASE", false); - stages.add(new Stage(requestId2, "/a5", clusterName, 1L, context, + stages.add(stageFactory.createNew(requestId2, "/a5", clusterName, 1L, context, CLUSTER_HOST_INFO, "", "")); stages.get(1).setStageId(5); stages.get(1).addHostRoleExecutionCommand(hostName1, Role.HBASE_CLIENT, http://git-wip-us.apache.org/repos/asf/ambari/blob/ee79dd21/ambari-server/src/test/java/org/apache/ambari/server/controller/KerberosHelperTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/KerberosHelperTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/KerberosHelperTest.java index 1cc9637..cf903d0 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/controller/KerberosHelperTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/KerberosHelperTest.java @@ -18,15 +18,7 @@ package org.apache.ambari.server.controller; -import static org.easymock.EasyMock.anyLong; -import static org.easymock.EasyMock.anyObject; -import static org.easymock.EasyMock.capture; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.expectLastCall; -import static org.easymock.EasyMock.getCurrentArguments; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.reset; -import static org.easymock.EasyMock.verify; +import static org.easymock.EasyMock.*; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -73,6 +65,8 @@ import org.apache.ambari.server.serveraction.kerberos.KerberosOperationException import org.apache.ambari.server.serveraction.kerberos.KerberosOperationHandler; import org.apache.ambari.server.serveraction.kerberos.KerberosOperationHandlerFactory; import org.apache.ambari.server.stack.StackManagerFactory; +import org.apache.ambari.server.stageplanner.RoleGraphFactory; +import org.apache.ambari.server.stageplanner.RoleGraphFactoryImpl; import org.apache.ambari.server.state.Cluster; import org.apache.ambari.server.state.Clusters; import org.apache.ambari.server.state.Config; @@ -177,6 +171,7 @@ public class KerberosHelperTest extends EasyMockSupport { bind(ActionManager.class).toInstance(createNiceMock(ActionManager.class)); bind(RequestFactory.class).toInstance(createNiceMock(RequestFactory.class)); bind(StageFactory.class).toInstance(createNiceMock(StageFactory.class)); + bind(RoleGraphFactory.class).to(RoleGraphFactoryImpl.class); bind(Clusters.class).toInstance(createNiceMock(ClustersImpl.class)); bind(ConfigHelper.class).toInstance(createNiceMock(ConfigHelper.class)); bind(KerberosOperationHandlerFactory.class).toInstance(kerberosOperationHandlerFactory); @@ -336,6 +331,7 @@ public class KerberosHelperTest extends EasyMockSupport { @Test public void testExecuteCustomOperationsInvalidOperation() throws Exception { KerberosHelper kerberosHelper = injector.getInstance(KerberosHelper.class); + final Cluster cluster = createNiceMock(Cluster.class); try { @@ -349,6 +345,7 @@ public class KerberosHelperTest extends EasyMockSupport { @Test(expected = AmbariException.class) public void testRegenerateKeytabsInvalidValue() throws Exception { KerberosHelper kerberosHelper = injector.getInstance(KerberosHelper.class); + final Cluster cluster = createNiceMock(Cluster.class); kerberosHelper.executeCustomOperations(cluster, @@ -1294,6 +1291,7 @@ public class KerberosHelperTest extends EasyMockSupport { @Test public void testIsClusterKerberosEnabled_false() throws Exception { KerberosHelper kerberosHelper = injector.getInstance(KerberosHelper.class); + Cluster cluster = createStrictMock(Cluster.class); expect(cluster.getSecurityType()).andReturn(SecurityType.NONE); @@ -1306,6 +1304,7 @@ public class KerberosHelperTest extends EasyMockSupport { @Test public void testIsClusterKerberosEnabled_true() throws Exception { KerberosHelper kerberosHelper = injector.getInstance(KerberosHelper.class); + Cluster cluster = createStrictMock(Cluster.class); expect(cluster.getSecurityType()).andReturn(SecurityType.KERBEROS); @@ -1318,6 +1317,7 @@ public class KerberosHelperTest extends EasyMockSupport { @Test public void testGetManageIdentitiesDirective_NotSet() throws Exception { KerberosHelper kerberosHelper = injector.getInstance(KerberosHelper.class); + assertEquals(null, kerberosHelper.getManageIdentitiesDirective(null)); assertEquals(null, kerberosHelper.getManageIdentitiesDirective(Collections.<String, String>emptyMap())); @@ -1344,6 +1344,7 @@ public class KerberosHelperTest extends EasyMockSupport { @Test public void testGetManageIdentitiesDirective_True() throws Exception { KerberosHelper kerberosHelper = injector.getInstance(KerberosHelper.class); + assertEquals(Boolean.TRUE, kerberosHelper.getManageIdentitiesDirective(Collections.singletonMap(KerberosHelper.DIRECTIVE_MANAGE_KERBEROS_IDENTITIES, "true"))); assertEquals(Boolean.TRUE, kerberosHelper.getManageIdentitiesDirective(Collections.singletonMap(KerberosHelper.DIRECTIVE_MANAGE_KERBEROS_IDENTITIES, "not_false"))); @@ -1361,6 +1362,7 @@ public class KerberosHelperTest extends EasyMockSupport { @Test public void testGetManageIdentitiesDirective_False() throws Exception { KerberosHelper kerberosHelper = injector.getInstance(KerberosHelper.class); + assertEquals(Boolean.FALSE, kerberosHelper.getManageIdentitiesDirective(Collections.singletonMap(KerberosHelper.DIRECTIVE_MANAGE_KERBEROS_IDENTITIES, "false"))); assertEquals(Boolean.FALSE, kerberosHelper.getManageIdentitiesDirective( http://git-wip-us.apache.org/repos/asf/ambari/blob/ee79dd21/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/CalculatedStatusTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/CalculatedStatusTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/CalculatedStatusTest.java index d11dae0..79674cb 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/CalculatedStatusTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/CalculatedStatusTest.java @@ -27,11 +27,18 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; +import com.google.inject.Guice; +import com.google.inject.Inject; +import com.google.inject.Injector; import org.apache.ambari.server.Role; import org.apache.ambari.server.RoleCommand; import org.apache.ambari.server.actionmanager.HostRoleCommand; +import org.apache.ambari.server.actionmanager.HostRoleCommandFactory; import org.apache.ambari.server.actionmanager.HostRoleStatus; import org.apache.ambari.server.actionmanager.Stage; +import org.apache.ambari.server.actionmanager.StageFactory; +import org.apache.ambari.server.orm.GuiceJpaInitializer; +import org.apache.ambari.server.orm.InMemoryDefaultTestModule; import org.apache.ambari.server.orm.entities.HostRoleCommandEntity; import org.apache.ambari.server.orm.entities.StageEntity; import org.junit.Before; @@ -43,6 +50,11 @@ import org.junit.Test; @SuppressWarnings("unchecked") public class CalculatedStatusTest { + private Injector m_injector; + + @Inject + HostRoleCommandFactory hostRoleCommandFactory; + private static long taskId = 0L; private static long stageId = 0L; @@ -50,6 +62,10 @@ public class CalculatedStatusTest { @Before() public void setup() throws Exception { + m_injector = Guice.createInjector(new InMemoryDefaultTestModule()); + m_injector.getInstance(GuiceJpaInitializer.class); + m_injector.injectMembers(this); + s_field = HostRoleCommand.class.getDeclaredField("taskId"); s_field.setAccessible(true); } @@ -442,7 +458,6 @@ public class CalculatedStatusTest { // create 5th stage that is a repeat of an earlier one HostRoleCommandEntity entity = new HostRoleCommandEntity(); entity.setTaskId(taskId++); - entity.setHostName("h2"); entity.setStatus(HostRoleStatus.PENDING); stages.addAll(getStages(Collections.singleton(entity))); @@ -460,7 +475,6 @@ public class CalculatedStatusTest { HostRoleStatus status = statuses[i]; HostRoleCommandEntity entity = new HostRoleCommandEntity(); entity.setTaskId(taskId++); - entity.setHostName("h" + i); entity.setStatus(status); entities.add(entity); @@ -501,12 +515,12 @@ public class CalculatedStatusTest { private final List<HostRoleCommand> hostRoleCommands = new LinkedList<HostRoleCommand>(); private TestStage() { - super(1L, "", "", 1L, "", "", "", ""); + super(1L, "", "", 1L, "", "", "", "", hostRoleCommandFactory); } void setHostRoleCommands(Collection<HostRoleCommandEntity> tasks) { for (HostRoleCommandEntity task : tasks) { - TestCommand command = new TestCommand(task.getHostName(), taskId++); + HostRoleCommand command = HostRoleCommandHelper.createWithTaskId(task.getHostName(), taskId++, hostRoleCommandFactory); command.setStatus(task.getStatus()); hostRoleCommands.add(command); } @@ -518,16 +532,16 @@ public class CalculatedStatusTest { } } - private class TestCommand extends HostRoleCommand { + private static class HostRoleCommandHelper { - public TestCommand(String host, long taskId) { - super(host, Role.AMBARI_SERVER_ACTION, null, RoleCommand.START); + public static HostRoleCommand createWithTaskId(String hostName, long taskId, HostRoleCommandFactory hostRoleCommandFactory1) { + HostRoleCommand hrc = hostRoleCommandFactory1.create(hostName, Role.AMBARI_SERVER_ACTION, null, RoleCommand.START); try { - s_field.set(this, Long.valueOf(taskId)); + s_field.set(hrc, Long.valueOf(taskId)); } catch (Exception e) { e.printStackTrace(); } + return hrc; } - } } \ No newline at end of file
