Repository: ambari Updated Branches: refs/heads/trunk 97347b7d7 -> 1487ad371
http://git-wip-us.apache.org/repos/asf/ambari/blob/1487ad37/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 90cc33b..f728bdf 100644 --- a/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql +++ b/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql @@ -100,15 +100,13 @@ CREATE TABLE hostcomponentdesiredstate ( component_name VARCHAR(255) NOT NULL, desired_stack_version VARCHAR(255) NOT NULL, desired_state VARCHAR(255) NOT NULL, - host_name VARCHAR(255) NOT NULL, - --host_id BIGINT NOT NULL, + host_id BIGINT NOT NULL, service_name VARCHAR(255) NOT NULL, admin_state VARCHAR(32), maintenance_state VARCHAR(32) NOT NULL, security_state VARCHAR(32) NOT NULL DEFAULT 'UNSECURED', restart_required SMALLINT NOT NULL DEFAULT 0, - PRIMARY KEY (cluster_id, component_name, host_name, service_name)); - --PRIMARY KEY (cluster_id, component_name, host_id, service_name)); + PRIMARY KEY (cluster_id, component_name, host_id, service_name)); CREATE TABLE hostcomponentstate ( cluster_id BIGINT NOT NULL, @@ -116,16 +114,14 @@ CREATE TABLE hostcomponentstate ( version VARCHAR(32) NOT NULL DEFAULT 'UNKNOWN', current_stack_version VARCHAR(255) NOT NULL, current_state VARCHAR(255) NOT NULL, - host_name VARCHAR(255) NOT NULL, - --host_id BIGINT NOT NULL, + host_id BIGINT NOT NULL, service_name VARCHAR(255) NOT NULL, upgrade_state VARCHAR(32) NOT NULL DEFAULT 'NONE', security_state VARCHAR(32) NOT NULL DEFAULT 'UNSECURED', - PRIMARY KEY (cluster_id, component_name, host_name, service_name)); - --PRIMARY KEY (cluster_id, component_name, host_id, service_name)); + PRIMARY KEY (cluster_id, component_name, host_id, service_name)); CREATE TABLE hosts ( - id BIGINT NOT NULL, + host_id BIGINT NOT NULL, host_name VARCHAR(255) NOT NULL, cpu_count INTEGER NOT NULL, ph_cpu_count INTEGER, @@ -141,19 +137,17 @@ CREATE TABLE hosts ( os_type VARCHAR(255) NOT NULL, rack_info VARCHAR(255) NOT NULL, total_mem BIGINT NOT NULL, - PRIMARY KEY (id)); + PRIMARY KEY (host_id)); CREATE TABLE hoststate ( agent_version VARCHAR(255) NOT NULL, available_mem BIGINT NOT NULL, current_state VARCHAR(255) NOT NULL, health_status VARCHAR(255), - host_name VARCHAR(255) NOT NULL, - --host_id BIGINT NOT NULL, + host_id BIGINT NOT NULL, time_in_state BIGINT NOT NULL, maintenance_state VARCHAR(512), - PRIMARY KEY (host_name)); - --PRIMARY KEY (host_id)); + PRIMARY KEY (host_id)); CREATE TABLE host_version ( id BIGINT NOT NULL, @@ -565,7 +559,7 @@ CREATE TABLE widget_layout_user_widget ( ); CREATE TABLE artifact ( - artifact_name VARCHAR(255) NOT NULL, + artifact_name VARCHAR(255) NOT NULL,bug33634 artifact_data TEXT NOT NULL, foreign_keys VARCHAR(255) NOT NULL, PRIMARY KEY (artifact_name, foreign_keys)); @@ -591,37 +585,34 @@ ALTER TABLE clusterconfigmapping ADD CONSTRAINT clusterconfigmappingcluster_id F ALTER TABLE clusterstate ADD CONSTRAINT FK_clusterstate_cluster_id FOREIGN KEY (cluster_id) REFERENCES clusters (cluster_id); ALTER TABLE cluster_version ADD CONSTRAINT FK_cluster_version_cluster_id FOREIGN KEY (cluster_id) REFERENCES clusters (cluster_id); ALTER TABLE cluster_version ADD CONSTRAINT FK_cluster_version_repovers_id FOREIGN KEY (repo_version_id) REFERENCES repo_version (repo_version_id); -ALTER TABLE hostcomponentdesiredstate ADD CONSTRAINT hstcmponentdesiredstatehstname FOREIGN KEY (host_name) REFERENCES hosts (host_name); ---ALTER TABLE hostcomponentdesiredstate ADD CONSTRAINT hstcmponentdesiredstatehstid FOREIGN KEY (host_id) REFERENCES hosts (id); +ALTER TABLE hostcomponentdesiredstate ADD CONSTRAINT FK_hostcomponentdesiredstate_host_id FOREIGN KEY (host_id) REFERENCES hosts (host_id); ALTER TABLE hostcomponentdesiredstate ADD CONSTRAINT hstcmpnntdesiredstatecmpnntnme FOREIGN KEY (component_name, cluster_id, service_name) REFERENCES servicecomponentdesiredstate (component_name, cluster_id, service_name); 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 hostcomponentstate_host_name FOREIGN KEY (host_name) REFERENCES hosts (host_name); ---ALTER TABLE hostcomponentstate ADD CONSTRAINT hostcomponentstate_host_id FOREIGN KEY (host_id) REFERENCES hosts (id); -ALTER TABLE hoststate ADD CONSTRAINT FK_hoststate_host_name FOREIGN KEY (host_name) REFERENCES hosts (host_name); ---ALTER TABLE hoststate ADD CONSTRAINT FK_hoststate_host_id FOREIGN KEY (host_id) REFERENCES hosts (id); +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 (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 (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); ALTER TABLE ClusterHostMapping ADD CONSTRAINT FK_clusterhostmapping_cluster_id FOREIGN KEY (cluster_id) REFERENCES clusters (cluster_id); -ALTER TABLE ClusterHostMapping ADD CONSTRAINT FK_clusterhostmapping_host_id FOREIGN KEY (host_id) REFERENCES hosts (id); +ALTER TABLE ClusterHostMapping ADD CONSTRAINT FK_clusterhostmapping_host_id FOREIGN KEY (host_id) REFERENCES hosts (host_id); ALTER TABLE hostconfigmapping ADD CONSTRAINT FK_hostconfmapping_cluster_id FOREIGN KEY (cluster_id) REFERENCES clusters (cluster_id); ALTER TABLE hostconfigmapping ADD CONSTRAINT FK_hostconfmapping_host_name FOREIGN KEY (host_name) REFERENCES hosts (host_name); ---ALTER TABLE hostconfigmapping ADD CONSTRAINT FK_hostconfmapping_host_id FOREIGN KEY (host_id) REFERENCES hosts (id); +--ALTER TABLE hostconfigmapping ADD CONSTRAINT FK_hostconfmapping_host_id FOREIGN KEY (host_id) REFERENCES hosts (host_id); ALTER TABLE configgroup ADD CONSTRAINT FK_configgroup_cluster_id FOREIGN KEY (cluster_id) REFERENCES clusters (cluster_id); ALTER TABLE confgroupclusterconfigmapping ADD CONSTRAINT FK_confg FOREIGN KEY (version_tag, config_type, cluster_id) REFERENCES clusterconfig (version_tag, type_name, cluster_id); ALTER TABLE confgroupclusterconfigmapping ADD CONSTRAINT FK_cgccm_gid FOREIGN KEY (config_group_id) REFERENCES configgroup (group_id); ALTER TABLE configgrouphostmapping ADD CONSTRAINT FK_cghm_cgid FOREIGN KEY (config_group_id) REFERENCES configgroup (group_id); ALTER TABLE configgrouphostmapping ADD CONSTRAINT FK_cghm_hname FOREIGN KEY (host_name) REFERENCES hosts (host_name); ---ALTER TABLE configgrouphostmapping ADD CONSTRAINT FK_cghm_host_id FOREIGN KEY (host_id) REFERENCES hosts (id); +--ALTER TABLE configgrouphostmapping ADD CONSTRAINT FK_cghm_host_id FOREIGN KEY (host_id) REFERENCES hosts (host_id); ALTER TABLE requestschedulebatchrequest ADD CONSTRAINT FK_rsbatchrequest_schedule_id FOREIGN KEY (schedule_id) REFERENCES requestschedule (schedule_id); ALTER TABLE hostgroup ADD CONSTRAINT FK_hg_blueprint_name FOREIGN KEY (blueprint_name) REFERENCES blueprint(blueprint_name); ALTER TABLE hostgroup_component ADD CONSTRAINT FK_hgc_blueprint_name FOREIGN KEY (blueprint_name, hostgroup_name) REFERENCES hostgroup (blueprint_name, name); @@ -671,7 +662,7 @@ CREATE TABLE kerberos_principal_host ( ALTER TABLE kerberos_principal_host ADD CONSTRAINT FK_krb_pr_host_hostname FOREIGN KEY (host_name) REFERENCES hosts (host_name) ON DELETE CASCADE; ---ALTER TABLE kerberos_principal_host ADD CONSTRAINT FK_krb_pr_host_id FOREIGN KEY (host_id) REFERENCES hosts (id) ON DELETE CASCADE; +--ALTER TABLE kerberos_principal_host ADD CONSTRAINT FK_krb_pr_host_id FOREIGN KEY (host_id) REFERENCES hosts (host_id) ON DELETE CASCADE; ALTER TABLE kerberos_principal_host ADD CONSTRAINT FK_krb_pr_host_principalname http://git-wip-us.apache.org/repos/asf/ambari/blob/1487ad37/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 5cb187c..034639d 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 @@ -120,15 +120,13 @@ CREATE TABLE ambari.hostcomponentdesiredstate ( component_name VARCHAR(255) NOT NULL, desired_stack_version VARCHAR(255) NOT NULL, desired_state VARCHAR(255) NOT NULL, - host_name VARCHAR(255) NOT NULL, - --host_id BIGINT NOT NULL, + host_id BIGINT NOT NULL, service_name VARCHAR(255) NOT NULL, admin_state VARCHAR(32), maintenance_state VARCHAR(32) NOT NULL, security_state VARCHAR(32) NOT NULL DEFAULT 'UNSECURED', restart_required SMALLINT NOT NULL DEFAULT 0, - PRIMARY KEY (cluster_id, component_name, host_name, service_name)); - --PRIMARY KEY (cluster_id, component_name, host_id, service_name)); + PRIMARY KEY (cluster_id, component_name, host_id, service_name)); GRANT ALL PRIVILEGES ON TABLE ambari.hostcomponentdesiredstate TO :username; CREATE TABLE ambari.hostcomponentstate ( @@ -137,17 +135,15 @@ CREATE TABLE ambari.hostcomponentstate ( version VARCHAR(32) NOT NULL DEFAULT 'UNKNOWN', current_stack_version VARCHAR(255) NOT NULL, current_state VARCHAR(255) NOT NULL, - host_name VARCHAR(255) NOT NULL, - --host_id BIGINT NOT NULL, + host_id BIGINT NOT NULL, service_name VARCHAR(255) NOT NULL, upgrade_state VARCHAR(32) NOT NULL DEFAULT 'NONE', security_state VARCHAR(32) NOT NULL DEFAULT 'UNSECURED', - PRIMARY KEY (cluster_id, component_name, host_name, service_name)); - --PRIMARY KEY (cluster_id, component_name, host_id, service_name)); + PRIMARY KEY (cluster_id, component_name, host_id, service_name)); GRANT ALL PRIVILEGES ON TABLE ambari.hostcomponentstate TO :username; CREATE TABLE ambari.hosts ( - id BIGINT NOT NULL, + host_id BIGINT NOT NULL, host_name VARCHAR(255) NOT NULL, cpu_count INTEGER NOT NULL, ph_cpu_count INTEGER, @@ -163,7 +159,7 @@ CREATE TABLE ambari.hosts ( os_type VARCHAR(255) NOT NULL, rack_info VARCHAR(255) NOT NULL, total_mem BIGINT NOT NULL, - PRIMARY KEY (id)); + PRIMARY KEY (host_id)); GRANT ALL PRIVILEGES ON TABLE ambari.hosts TO :username; CREATE TABLE ambari.hoststate ( @@ -171,12 +167,10 @@ CREATE TABLE ambari.hoststate ( available_mem BIGINT NOT NULL, current_state VARCHAR(255) NOT NULL, health_status VARCHAR(255), - host_name VARCHAR(255) NOT NULL, - --host_id BIGINT NOT NULL, + host_id BIGINT NOT NULL, time_in_state BIGINT NOT NULL, maintenance_state VARCHAR(512), - PRIMARY KEY (host_name)); - --PRIMARY KEY (host_id)); + PRIMARY KEY (host_id)); GRANT ALL PRIVILEGES ON TABLE ambari.hoststate TO :username; CREATE TABLE ambari.host_version ( @@ -663,31 +657,28 @@ ALTER TABLE ambari.clusterconfigmapping ADD CONSTRAINT clusterconfigmappingclust ALTER TABLE ambari.clusterstate ADD CONSTRAINT FK_clusterstate_cluster_id FOREIGN KEY (cluster_id) REFERENCES ambari.clusters (cluster_id); ALTER TABLE ambari.cluster_version ADD CONSTRAINT FK_cluster_version_cluster_id FOREIGN KEY (cluster_id) REFERENCES ambari.clusters (cluster_id); ALTER TABLE ambari.cluster_version ADD CONSTRAINT FK_cluster_version_repovers_id FOREIGN KEY (repo_version_id) REFERENCES ambari.repo_version (repo_version_id); -ALTER TABLE ambari.hostcomponentdesiredstate ADD CONSTRAINT hstcmponentdesiredstatehstname FOREIGN KEY (host_name) REFERENCES ambari.hosts (host_name); ---ALTER TABLE ambari.hostcomponentdesiredstate ADD CONSTRAINT hstcmponentdesiredstatehstid FOREIGN KEY (host_id) REFERENCES ambari.hosts (id); +ALTER TABLE ambari.hostcomponentdesiredstate ADD CONSTRAINT FK_hostcomponentdesiredstate_host_id FOREIGN KEY (host_id) REFERENCES ambari.hosts (host_id); ALTER TABLE ambari.hostcomponentdesiredstate ADD CONSTRAINT hstcmpnntdesiredstatecmpnntnme FOREIGN KEY (component_name, cluster_id, service_name) REFERENCES ambari.servicecomponentdesiredstate (component_name, cluster_id, service_name); 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 hostcomponentstate_host_name FOREIGN KEY (host_name) REFERENCES ambari.hosts (host_name); ---ALTER TABLE ambari.hostcomponentstate ADD CONSTRAINT hostcomponentstate_host_id FOREIGN KEY (host_id) REFERENCES ambari.hosts (id); -ALTER TABLE ambari.hoststate ADD CONSTRAINT FK_hoststate_host_name FOREIGN KEY (host_name) REFERENCES ambari.hosts (host_name); ---ALTER TABLE ambari.hoststate ADD CONSTRAINT FK_hoststate_host_id FOREIGN KEY (host_id) REFERENCES ambari.hosts (host_id); +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 (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 (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); ALTER TABLE ambari.ClusterHostMapping ADD CONSTRAINT FK_clusterhostmapping_cluster_id FOREIGN KEY (cluster_id) REFERENCES ambari.clusters (cluster_id); -ALTER TABLE ambari.ClusterHostMapping ADD CONSTRAINT FK_clusterhostmapping_host_id FOREIGN KEY (host_id) REFERENCES ambari.hosts (id); +ALTER TABLE ambari.ClusterHostMapping ADD CONSTRAINT FK_clusterhostmapping_host_id FOREIGN KEY (host_id) REFERENCES ambari.hosts (host_id); ALTER TABLE ambari.hostconfigmapping ADD CONSTRAINT FK_hostconfmapping_cluster_id FOREIGN KEY (cluster_id) REFERENCES ambari.clusters (cluster_id); ALTER TABLE ambari.hostconfigmapping ADD CONSTRAINT FK_hostconfmapping_host_name FOREIGN KEY (host_name) REFERENCES ambari.hosts (host_name); ---ALTER TABLE ambari.hostconfigmapping ADD CONSTRAINT FK_hostconfmapping_host_id FOREIGN KEY (host_id) REFERENCES ambari.hosts (id); +--ALTER TABLE ambari.hostconfigmapping ADD CONSTRAINT FK_hostconfmapping_host_id FOREIGN KEY (host_id) REFERENCES ambari.hosts (host_id); ALTER TABLE ambari.configgroup ADD CONSTRAINT FK_configgroup_cluster_id FOREIGN KEY (cluster_id) REFERENCES ambari.clusters (cluster_id); ALTER TABLE ambari.configgrouphostmapping ADD CONSTRAINT FK_cghm_cgid FOREIGN KEY (config_group_id) REFERENCES ambari.configgroup (group_id); ALTER TABLE ambari.configgrouphostmapping ADD CONSTRAINT FK_cghm_hname FOREIGN KEY (host_name) REFERENCES ambari.hosts (host_name); @@ -745,7 +736,7 @@ GRANT ALL PRIVILEGES ON TABLE ambari.kerberos_principal_host TO :username; ALTER TABLE ambari.kerberos_principal_host ADD CONSTRAINT FK_krb_pr_host_hostname FOREIGN KEY (host_name) REFERENCES ambari.hosts (host_name) ON DELETE CASCADE; ---ALTER TABLE ambari.kerberos_principal_host ADD CONSTRAINT FK_krb_pr_host_id FOREIGN KEY (host_id) REFERENCES ambari.hosts (id) ON DELETE CASCADE; +--ALTER TABLE ambari.kerberos_principal_host ADD CONSTRAINT FK_krb_pr_host_id FOREIGN KEY (host_id) REFERENCES ambari.hosts (host_id) ON DELETE CASCADE; ALTER TABLE ambari.kerberos_principal_host ADD CONSTRAINT FK_krb_pr_host_principalname http://git-wip-us.apache.org/repos/asf/ambari/blob/1487ad37/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 f506761..01c6a0c 100644 --- a/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql +++ b/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql @@ -41,10 +41,21 @@ CREATE TABLE clusterservices (service_name VARCHAR(255) NOT NULL, cluster_id BIG CREATE TABLE clusterstate (cluster_id BIGINT NOT NULL, current_cluster_state VARCHAR(255) NOT NULL, current_stack_version VARCHAR(255) NOT NULL, PRIMARY KEY CLUSTERED (cluster_id)); CREATE TABLE cluster_version (id BIGINT NOT NULL, cluster_id BIGINT NOT NULL, repo_version_id BIGINT NOT NULL, state VARCHAR(255) NOT NULL, start_time BIGINT NOT NULL, end_time BIGINT, user_name VARCHAR(255), PRIMARY KEY (id)); CREATE TABLE hostcomponentdesiredstate (cluster_id BIGINT NOT NULL, component_name VARCHAR(255) NOT NULL, desired_stack_version VARCHAR(255) NOT NULL, desired_state VARCHAR(255) NOT NULL, host_name VARCHAR(255) NOT NULL, service_name VARCHAR(255) NOT NULL, admin_state VARCHAR(32), maintenance_state VARCHAR(32) NOT NULL, security_state VARCHAR(32) NOT NULL DEFAULT 'UNSECURED', restart_required BIT NOT NULL DEFAULT 0, PRIMARY KEY CLUSTERED (cluster_id, component_name, host_name, service_name)); -CREATE TABLE hostcomponentstate (cluster_id BIGINT NOT NULL, component_name VARCHAR(255) NOT NULL, version VARCHAR(32) NOT NULL DEFAULT 'UNKNOWN', current_stack_version VARCHAR(255) NOT NULL, current_state VARCHAR(255) NOT NULL, host_name VARCHAR(255) NOT NULL, service_name VARCHAR(255) NOT NULL, upgrade_state VARCHAR(32) NOT NULL DEFAULT 'NONE', security_state VARCHAR(32) NOT NULL DEFAULT 'UNSECURED', PRIMARY KEY CLUSTERED (cluster_id, component_name, host_name, service_name)); + +CREATE TABLE hostcomponentstate ( + cluster_id BIGINT NOT NULL, + component_name VARCHAR(255) NOT NULL, + version VARCHAR(32) NOT NULL DEFAULT 'UNKNOWN', + current_stack_version VARCHAR(255) NOT NULL, + current_state VARCHAR(255) NOT NULL, + host_id BIGINT NOT NULL, + service_name VARCHAR(255) NOT NULL, + upgrade_state VARCHAR(32) NOT NULL DEFAULT 'NONE', + security_state VARCHAR(32) NOT NULL DEFAULT 'UNSECURED', + PRIMARY KEY CLUSTERED (cluster_id, component_name, host_id, service_name)); CREATE TABLE hosts ( - id BIGINT NOT NULL, + host_id BIGINT NOT NULL, host_name VARCHAR(255) NOT NULL, cpu_count INTEGER NOT NULL, ph_cpu_count INTEGER, @@ -60,9 +71,18 @@ CREATE TABLE hosts ( os_type VARCHAR(255) NOT NULL, rack_info VARCHAR(255) NOT NULL, total_mem BIGINT NOT NULL, - PRIMARY KEY CLUSTERED (id)); + PRIMARY KEY CLUSTERED (host_id)); + +CREATE TABLE hoststate ( + agent_version VARCHAR(255) NOT NULL, + available_mem BIGINT NOT NULL, + current_state VARCHAR(255) NOT NULL, + health_status VARCHAR(255), + host_id BIGINT NOT NULL, + time_in_state BIGINT NOT NULL, + maintenance_state VARCHAR(512), + PRIMARY KEY CLUSTERED (host_id)); -CREATE TABLE hoststate (agent_version VARCHAR(255) NOT NULL, available_mem BIGINT NOT NULL, current_state VARCHAR(255) NOT NULL, health_status VARCHAR(255), host_name VARCHAR(255) NOT NULL, time_in_state BIGINT NOT NULL, maintenance_state VARCHAR(512), PRIMARY KEY CLUSTERED (host_name)); CREATE TABLE servicecomponentdesiredstate (component_name VARCHAR(255) NOT NULL, cluster_id BIGINT NOT NULL, desired_stack_version VARCHAR(255) NOT NULL, desired_state VARCHAR(255) NOT NULL, service_name VARCHAR(255) NOT NULL, PRIMARY KEY CLUSTERED (component_name, cluster_id, service_name)); CREATE TABLE servicedesiredstate (cluster_id BIGINT NOT NULL, desired_host_role_mapping INTEGER NOT NULL, desired_stack_version VARCHAR(255) NOT NULL, desired_state VARCHAR(255) NOT NULL, service_name VARCHAR(255) NOT NULL, maintenance_state VARCHAR(32) NOT NULL, security_state VARCHAR(32) NOT NULL DEFAULT 'UNSECURED', PRIMARY KEY CLUSTERED (cluster_id, service_name)); CREATE TABLE users (user_id INTEGER, principal_id BIGINT NOT NULL, ldap_user INTEGER NOT NULL DEFAULT 0, user_name VARCHAR(255) NOT NULL, create_time DATETIME DEFAULT GETDATE(), user_password VARCHAR(255), active INTEGER NOT NULL DEFAULT 1, PRIMARY KEY CLUSTERED (user_id), UNIQUE (ldap_user, user_name)); @@ -137,36 +157,34 @@ ALTER TABLE clusterstate ADD CONSTRAINT FK_clusterstate_cluster_id FOREIGN KEY ( ALTER TABLE cluster_version ADD CONSTRAINT FK_cluster_version_cluster_id FOREIGN KEY (cluster_id) REFERENCES clusters (cluster_id); ALTER TABLE cluster_version ADD CONSTRAINT FK_cluster_version_repovers_id FOREIGN KEY (repo_version_id) REFERENCES repo_version (repo_version_id); ALTER TABLE hostcomponentdesiredstate ADD CONSTRAINT hstcmponentdesiredstatehstname FOREIGN KEY (host_name) REFERENCES hosts (host_name); ---ALTER TABLE hostcomponentdesiredstate ADD CONSTRAINT hstcmponentdesiredstatehstid FOREIGN KEY (host_id) REFERENCES hosts (id); +--ALTER TABLE hostcomponentdesiredstate ADD CONSTRAINT hstcmponentdesiredstatehstid FOREIGN KEY (host_id) REFERENCES hosts (host_id); ALTER TABLE hostcomponentdesiredstate ADD CONSTRAINT hstcmpnntdesiredstatecmpnntnme FOREIGN KEY (component_name, cluster_id, service_name) REFERENCES servicecomponentdesiredstate (component_name, cluster_id, service_name); 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 hostcomponentstate_host_name FOREIGN KEY (host_name) REFERENCES hosts (host_name); ---ALTER TABLE hostcomponentstate ADD CONSTRAINT hostcomponentstate_host_id FOREIGN KEY (host_id) REFERENCES hosts (id); -ALTER TABLE hoststate ADD CONSTRAINT FK_hoststate_host_name FOREIGN KEY (host_name) REFERENCES hosts (host_name); ---ALTER TABLE hoststate ADD CONSTRAINT FK_hoststate_host_id FOREIGN KEY (host_id) REFERENCES hosts (id); +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 (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 (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); ALTER TABLE ClusterHostMapping ADD CONSTRAINT FK_clusterhostmapping_cluster_id FOREIGN KEY (cluster_id) REFERENCES clusters (cluster_id); -ALTER TABLE ClusterHostMapping ADD CONSTRAINT FK_clusterhostmapping_host_id FOREIGN KEY (host_id) REFERENCES hosts (id); +ALTER TABLE ClusterHostMapping ADD CONSTRAINT FK_clusterhostmapping_host_id FOREIGN KEY (host_id) REFERENCES hosts (host_id); ALTER TABLE hostconfigmapping ADD CONSTRAINT FK_hostconfmapping_cluster_id FOREIGN KEY (cluster_id) REFERENCES clusters (cluster_id); ALTER TABLE hostconfigmapping ADD CONSTRAINT FK_hostconfmapping_host_name FOREIGN KEY (host_name) REFERENCES hosts (host_name); ---ALTER TABLE hostconfigmapping ADD CONSTRAINT FK_hostconfmapping_host_id FOREIGN KEY (host_id) REFERENCES hosts (id); +--ALTER TABLE hostconfigmapping ADD CONSTRAINT FK_hostconfmapping_host_id FOREIGN KEY (host_id) REFERENCES hosts (host_id); ALTER TABLE configgroup ADD CONSTRAINT FK_configgroup_cluster_id FOREIGN KEY (cluster_id) REFERENCES clusters (cluster_id); ALTER TABLE confgroupclusterconfigmapping ADD CONSTRAINT FK_confg FOREIGN KEY (cluster_id, config_type, version_tag) REFERENCES clusterconfig (cluster_id, type_name, version_tag); ALTER TABLE confgroupclusterconfigmapping ADD CONSTRAINT FK_cgccm_gid FOREIGN KEY (config_group_id) REFERENCES configgroup (group_id); ALTER TABLE configgrouphostmapping ADD CONSTRAINT FK_cghm_cgid FOREIGN KEY (config_group_id) REFERENCES configgroup (group_id); ALTER TABLE configgrouphostmapping ADD CONSTRAINT FK_cghm_hname FOREIGN KEY (host_name) REFERENCES hosts (host_name); ---ALTER TABLE configgrouphostmapping ADD CONSTRAINT FK_cghm_host_id FOREIGN KEY (host_id) REFERENCES hosts (id); +--ALTER TABLE configgrouphostmapping ADD CONSTRAINT FK_cghm_host_id FOREIGN KEY (host_id) REFERENCES hosts (host_id); ALTER TABLE requestschedulebatchrequest ADD CONSTRAINT FK_rsbatchrequest_schedule_id FOREIGN KEY (schedule_id) REFERENCES requestschedule (schedule_id); ALTER TABLE hostgroup ADD CONSTRAINT FK_hg_blueprint_name FOREIGN KEY (blueprint_name) REFERENCES blueprint(blueprint_name); ALTER TABLE hostgroup_component ADD CONSTRAINT FK_hgc_blueprint_name FOREIGN KEY (blueprint_name, hostgroup_name) REFERENCES hostgroup (blueprint_name, name); @@ -214,7 +232,7 @@ CREATE TABLE kerberos_principal_host ( ALTER TABLE kerberos_principal_host ADD CONSTRAINT FK_krb_pr_host_hostname FOREIGN KEY (host_name) REFERENCES hosts (host_name) ON DELETE CASCADE; ---ALTER TABLE kerberos_principal_host ADD CONSTRAINT FK_krb_pr_host_id FOREIGN KEY (host_id) REFERENCES hosts (id) ON DELETE CASCADE; +--ALTER TABLE kerberos_principal_host ADD CONSTRAINT FK_krb_pr_host_id FOREIGN KEY (host_id) REFERENCES hosts (host_id) ON DELETE CASCADE; ALTER TABLE kerberos_principal_host ADD CONSTRAINT FK_krb_pr_host_principalname http://git-wip-us.apache.org/repos/asf/ambari/blob/1487ad37/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/HostComponentDesiredStateDAOTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/HostComponentDesiredStateDAOTest.java b/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/HostComponentDesiredStateDAOTest.java index 7b34827..b7a0677 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/HostComponentDesiredStateDAOTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/HostComponentDesiredStateDAOTest.java @@ -46,25 +46,20 @@ public class HostComponentDesiredStateDAOTest { EntityManager entityManager = createNiceMock(EntityManager.class); HostDAO hostDAO = createNiceMock(HostDAO.class); HostEntity hostEntity = createNiceMock(HostEntity.class); - + HostComponentDesiredStateEntity hostComponentDesiredStateEntity = createNiceMock(HostComponentDesiredStateEntity.class); - - expect(hostComponentDesiredStateEntity.getHostName()).andReturn("host1"); - expect(hostDAO.findByName("host1")).andReturn(hostEntity); + expect(hostComponentDesiredStateEntity.getHostEntity()).andReturn(hostEntity); expect(entityManagerProvider.get()).andReturn(entityManager).anyTimes(); - expect(entityManager.merge(hostComponentDesiredStateEntity)).andReturn(hostComponentDesiredStateEntity).anyTimes(); entityManager.remove(hostComponentDesiredStateEntity); - hostEntity.removeHostComponentDesiredStateEntity(hostComponentDesiredStateEntity); expect(hostDAO.merge(hostEntity)).andReturn(hostEntity).anyTimes(); replay(entityManagerProvider, entityManager, hostDAO, hostEntity, hostComponentDesiredStateEntity); - HostComponentDesiredStateDAO dao = new HostComponentDesiredStateDAO(); dao.entityManagerProvider = entityManagerProvider; dao.hostDAO = hostDAO; http://git-wip-us.apache.org/repos/asf/ambari/blob/1487ad37/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceComponentTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceComponentTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceComponentTest.java index 3093c2f..00894f1 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceComponentTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceComponentTest.java @@ -18,6 +18,7 @@ package org.apache.ambari.server.state; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.fail; import java.util.HashMap; @@ -33,11 +34,13 @@ import org.apache.ambari.server.orm.InMemoryDefaultTestModule; import org.apache.ambari.server.orm.OrmTestHelper; import org.apache.ambari.server.orm.dao.HostComponentDesiredStateDAO; import org.apache.ambari.server.orm.dao.HostComponentStateDAO; +import org.apache.ambari.server.orm.dao.HostDAO; import org.apache.ambari.server.orm.dao.ServiceComponentDesiredStateDAO; import org.apache.ambari.server.orm.entities.HostComponentDesiredStateEntity; import org.apache.ambari.server.orm.entities.HostComponentDesiredStateEntityPK; import org.apache.ambari.server.orm.entities.HostComponentStateEntity; import org.apache.ambari.server.orm.entities.HostComponentStateEntityPK; +import org.apache.ambari.server.orm.entities.HostEntity; import org.apache.ambari.server.orm.entities.ServiceComponentDesiredStateEntity; import org.apache.ambari.server.orm.entities.ServiceComponentDesiredStateEntityPK; import org.junit.After; @@ -61,6 +64,7 @@ public class ServiceComponentTest { private ServiceComponentHostFactory serviceComponentHostFactory; private AmbariMetaInfo metaInfo; private OrmTestHelper helper; + private HostDAO hostDAO; @Before public void setup() throws Exception { @@ -73,6 +77,7 @@ public class ServiceComponentTest { serviceComponentHostFactory = injector.getInstance( ServiceComponentHostFactory.class); helper = injector.getInstance(OrmTestHelper.class); + hostDAO = injector.getInstance(HostDAO.class); metaInfo = injector.getInstance(AmbariMetaInfo.class); clusterName = "foo"; @@ -209,6 +214,9 @@ public class ServiceComponentTest { addHostToCluster("h2", service.getCluster().getClusterName()); addHostToCluster("h3", service.getCluster().getClusterName()); + HostEntity hostEntity1 = hostDAO.findByName("h1"); + assertNotNull(hostEntity1); + ServiceComponentHost sch1 = serviceComponentHostFactory.createNew(sc, "h1"); ServiceComponentHost sch2 = @@ -265,11 +273,11 @@ public class ServiceComponentTest { dPK.setClusterId(cluster.getClusterId()); dPK.setComponentName(componentName); - dPK.setHostName("h1"); + dPK.setHostId(hostEntity1.getHostId()); dPK.setServiceName(serviceName); lPK.setClusterId(cluster.getClusterId()); lPK.setComponentName(componentName); - lPK.setHostName("h1"); + lPK.setHostId(hostEntity1.getHostId()); lPK.setServiceName(serviceName); HostComponentDesiredStateEntity desiredStateEntity = http://git-wip-us.apache.org/repos/asf/ambari/blob/1487ad37/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersTest.java index c2ab35f..20eafe0 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersTest.java @@ -48,6 +48,7 @@ import org.apache.ambari.server.orm.dao.HostDAO; import org.apache.ambari.server.orm.entities.ClusterStateEntity; import org.apache.ambari.server.orm.entities.HostComponentDesiredStateEntityPK; import org.apache.ambari.server.orm.entities.HostComponentStateEntityPK; +import org.apache.ambari.server.orm.entities.HostEntity; import org.apache.ambari.server.state.Cluster; import org.apache.ambari.server.state.Clusters; import org.apache.ambari.server.state.Config; @@ -76,6 +77,8 @@ public class ClustersTest { private AmbariMetaInfo metaInfo; @Inject private OrmTestHelper helper; + @Inject + private HostDAO hostDAO; @Before public void setup() throws Exception { @@ -403,6 +406,8 @@ public class ClustersTest { ServiceComponentHost nameNodeHost = nameNode.addServiceComponentHost(h1); nameNodeHost.persist(); + HostEntity nameNodeHostEntity = hostDAO.findByName(nameNodeHost.getHostName()); + Assert.assertNotNull(nameNodeHostEntity); ServiceComponentHost dataNodeHost = dataNode.addServiceComponentHost(h2); dataNodeHost.persist(); @@ -415,12 +420,12 @@ public class ClustersTest { HostComponentDesiredStateEntityPK hkdspk = new HostComponentDesiredStateEntityPK(); hkspk.setClusterId(nameNodeHost.getClusterId()); - hkspk.setHostName(nameNodeHost.getHostName()); + hkspk.setHostId(nameNodeHostEntity.getHostId()); hkspk.setServiceName(nameNodeHost.getServiceName()); hkspk.setComponentName(nameNodeHost.getServiceComponentName()); hkdspk.setClusterId(nameNodeHost.getClusterId()); - hkdspk.setHostName(nameNodeHost.getHostName()); + hkdspk.setHostId(nameNodeHostEntity.getHostId()); hkdspk.setServiceName(nameNodeHost.getServiceName()); hkdspk.setComponentName(nameNodeHost.getServiceComponentName()); @@ -432,7 +437,7 @@ public class ClustersTest { clusters.deleteCluster(c1); - Assert.assertEquals(2, injector.getInstance(HostDAO.class).findAll().size()); + Assert.assertEquals(2, hostDAO.findAll().size()); Assert.assertNull(injector.getInstance(HostComponentStateDAO.class).findByPK(hkspk)); Assert.assertNull(injector.getInstance(HostComponentDesiredStateDAO.class).findByPK(hkdspk)); Assert.assertEquals(0, injector.getProvider(EntityManager.class).get().createQuery("SELECT config FROM ClusterConfigEntity config").getResultList().size()); http://git-wip-us.apache.org/repos/asf/ambari/blob/1487ad37/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostTest.java index ba19154..137575e 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostTest.java @@ -35,10 +35,12 @@ import org.apache.ambari.server.orm.InMemoryDefaultTestModule; import org.apache.ambari.server.orm.OrmTestHelper; import org.apache.ambari.server.orm.dao.HostComponentDesiredStateDAO; import org.apache.ambari.server.orm.dao.HostComponentStateDAO; +import org.apache.ambari.server.orm.dao.HostDAO; import org.apache.ambari.server.orm.entities.HostComponentDesiredStateEntity; import org.apache.ambari.server.orm.entities.HostComponentDesiredStateEntityPK; import org.apache.ambari.server.orm.entities.HostComponentStateEntity; import org.apache.ambari.server.orm.entities.HostComponentStateEntityPK; +import org.apache.ambari.server.orm.entities.HostEntity; import org.apache.ambari.server.state.Cluster; import org.apache.ambari.server.state.Clusters; import org.apache.ambari.server.state.Config; @@ -99,6 +101,8 @@ public class ServiceComponentHostTest { private ConfigHelper configHelper; @Inject private OrmTestHelper helper; + @Inject + HostDAO hostDAO; @Before public void setup() throws Exception { @@ -1082,6 +1086,8 @@ public class ServiceComponentHostTest { helper.getOrCreateRepositoryVersion(stackId.getStackName(), stackId.getStackVersion()); c2.createClusterVersion(stackId.getStackName(), stackId.getStackVersion(), "admin", RepositoryVersionState.UPGRADING); clusters.mapHostToCluster(hostName, clusterName); + HostEntity hostEntity = hostDAO.findByName(hostName); + Assert.assertNotNull(hostEntity); Cluster cluster = clusters.getCluster(clusterName); @@ -1093,7 +1099,7 @@ public class ServiceComponentHostTest { pk.setClusterId(Long.valueOf(cluster.getClusterId())); pk.setComponentName(sch1.getServiceComponentName()); pk.setServiceName(sch1.getServiceName()); - pk.setHostName(hostName); + pk.setHostId(hostEntity.getHostId()); HostComponentDesiredStateDAO dao = injector.getInstance(HostComponentDesiredStateDAO.class); HostComponentDesiredStateEntity entity = dao.findByPK(pk); @@ -1105,7 +1111,6 @@ public class ServiceComponentHostTest { entity = dao.findByPK(pk); Assert.assertEquals(MaintenanceState.ON, entity.getMaintenanceState()); - } @@ -1119,6 +1124,9 @@ public class ServiceComponentHostTest { clusters.addHost(hostName); setOsFamily(clusters.getHost(hostName), "redhat", "5.9"); clusters.getHost(hostName).persist(); + HostEntity hostEntity = hostDAO.findByName(hostName); + Assert.assertNotNull(hostEntity); + Cluster c2 = clusters.getCluster(clusterName); StackId stackId = new StackId(stackVersion); c2.setDesiredStackVersion(stackId); @@ -1136,7 +1144,7 @@ public class ServiceComponentHostTest { pkHostComponentDesiredState.setClusterId(cluster.getClusterId()); pkHostComponentDesiredState.setComponentName(sch1.getServiceComponentName()); pkHostComponentDesiredState.setServiceName(sch1.getServiceName()); - pkHostComponentDesiredState.setHostName(hostName); + pkHostComponentDesiredState.setHostId(hostEntity.getHostId()); HostComponentStateDAO daoHostComponentState = injector.getInstance(HostComponentStateDAO.class); HostComponentStateEntity entityHostComponentState; @@ -1144,7 +1152,7 @@ public class ServiceComponentHostTest { pkHostComponentState.setClusterId(cluster.getClusterId()); pkHostComponentState.setComponentName(sch1.getServiceComponentName()); pkHostComponentState.setServiceName(sch1.getServiceName()); - pkHostComponentState.setHostName(hostName); + pkHostComponentState.setHostId(hostEntity.getHostId()); for(SecurityState state: SecurityState.values()) { sch1.setSecurityState(state); http://git-wip-us.apache.org/repos/asf/ambari/blob/1487ad37/ambari-server/src/test/java/org/apache/ambari/server/upgrade/SectionDDL.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/SectionDDL.java b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/SectionDDL.java new file mode 100644 index 0000000..0f6b908 --- /dev/null +++ b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/SectionDDL.java @@ -0,0 +1,44 @@ +/* + * 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 + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ambari.server.upgrade; + +import org.apache.ambari.server.orm.DBAccessor; + +import java.sql.SQLException; + +/** + * Interface to encapsulate the logic that a DDL update requires for a particular feature or collection of tables. + * Typically, each section initializes capture groups, then creates tables/columns, and then verifies expectations. + */ +public interface SectionDDL { + + /** + * Execute any commands to create table/columns and store in the capture group. + * @param dbAccessor + * @throws SQLException + */ + public void execute(DBAccessor dbAccessor) throws SQLException; + + /** + * Retrieve the capture groups and make assertions about tables/columns created. + * @param dbAccessor + * @throws SQLException + */ + public void verify(DBAccessor dbAccessor) throws SQLException; +} http://git-wip-us.apache.org/repos/asf/ambari/blob/1487ad37/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog150Test.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog150Test.java b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog150Test.java index af6721c..37328e8 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog150Test.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog150Test.java @@ -136,7 +136,6 @@ public class UpgradeCatalog150Test { hostComponentDesiredStateEntity.setServiceName(clusterServiceEntity.getServiceName()); hostComponentDesiredStateEntity.setServiceComponentDesiredStateEntity(componentDesiredStateEntity); hostComponentDesiredStateEntity.setHostEntity(hostEntity); - hostComponentDesiredStateEntity.setHostName(hostEntity.getHostName()); hostComponentDesiredStateDAO.create(hostComponentDesiredStateEntity); http://git-wip-us.apache.org/repos/asf/ambari/blob/1487ad37/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog170Test.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog170Test.java b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog170Test.java index 6fa3e0a..2bf6d96 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog170Test.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog170Test.java @@ -541,6 +541,11 @@ public class UpgradeCatalog170Test { @Test public void testMoveHcatalogIntoHiveService() throws AmbariException { + UpgradeCatalog170 upgradeCatalog170 = injector.getInstance(UpgradeCatalog170.class); + ServiceComponentDesiredStateDAO serviceComponentDesiredStateDAO = injector.getInstance(ServiceComponentDesiredStateDAO.class); + HostComponentDesiredStateDAO hostComponentDesiredStateDAO = injector.getInstance(HostComponentDesiredStateDAO.class); + HostComponentStateDAO hostComponentStateDAO = injector.getInstance(HostComponentStateDAO.class); + final ClusterEntity clusterEntity = upgradeCatalogHelper.createCluster( injector, CLUSTER_NAME, DESIRED_STACK_VERSION); final ClusterServiceEntity clusterServiceEntityHDFS = upgradeCatalogHelper.addService( @@ -563,10 +568,9 @@ public class UpgradeCatalog170Test { upgradeCatalogHelper.addComponent(injector, clusterEntity, clusterServiceEntityWEBHCAT, hostEntity, "WEBHCAT_SERVER", DESIRED_STACK_VERSION); - UpgradeCatalog170 upgradeCatalog170 = injector.getInstance(UpgradeCatalog170.class); + upgradeCatalog170.moveHcatalogIntoHiveService(); - ServiceComponentDesiredStateDAO serviceComponentDesiredStateDAO = injector.getInstance(ServiceComponentDesiredStateDAO.class); ServiceComponentDesiredStateEntityPK pkHCATInHive = new ServiceComponentDesiredStateEntityPK(); pkHCATInHive.setComponentName("HCAT"); pkHCATInHive.setClusterId(clusterEntity.getClusterId()); @@ -574,21 +578,19 @@ public class UpgradeCatalog170Test { ServiceComponentDesiredStateEntity serviceComponentDesiredStateEntity = serviceComponentDesiredStateDAO.findByPK(pkHCATInHive); assertNotNull(serviceComponentDesiredStateEntity); - HostComponentDesiredStateDAO hostComponentDesiredStateDAO = injector.getInstance(HostComponentDesiredStateDAO.class); HostComponentDesiredStateEntityPK hcDesiredStateEntityPk = new HostComponentDesiredStateEntityPK(); hcDesiredStateEntityPk.setServiceName("HIVE"); hcDesiredStateEntityPk.setClusterId(clusterEntity.getClusterId()); hcDesiredStateEntityPk.setComponentName("HCAT"); - hcDesiredStateEntityPk.setHostName(HOST_NAME); + hcDesiredStateEntityPk.setHostId(hostEntity.getHostId()); HostComponentDesiredStateEntity hcDesiredStateEntity = hostComponentDesiredStateDAO.findByPK(hcDesiredStateEntityPk); assertNotNull(hcDesiredStateEntity); - HostComponentStateDAO hostComponentStateDAO = injector.getInstance(HostComponentStateDAO.class); HostComponentStateEntityPK hcStateEntityPk = new HostComponentStateEntityPK(); hcStateEntityPk.setServiceName("HIVE"); hcStateEntityPk.setClusterId(clusterEntity.getClusterId()); hcStateEntityPk.setComponentName("HCAT"); - hcStateEntityPk.setHostName(HOST_NAME); + hcStateEntityPk.setHostId(hostEntity.getHostId()); HostComponentStateEntity hcStateEntity = hostComponentStateDAO.findByPK(hcStateEntityPk); assertNotNull(hcStateEntity); } http://git-wip-us.apache.org/repos/asf/ambari/blob/1487ad37/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog200Test.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog200Test.java b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog200Test.java index 9c39749..96d5134 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog200Test.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog200Test.java @@ -531,6 +531,12 @@ public class UpgradeCatalog200Test { */ @Test public void testDeleteNagiosService() throws Exception { + UpgradeCatalog200 upgradeCatalog200 = injector.getInstance(UpgradeCatalog200.class); + ServiceComponentDesiredStateDAO serviceComponentDesiredStateDAO = injector.getInstance(ServiceComponentDesiredStateDAO.class); + HostComponentDesiredStateDAO hostComponentDesiredStateDAO = injector.getInstance(HostComponentDesiredStateDAO.class); + HostComponentStateDAO hostComponentStateDAO = injector.getInstance(HostComponentStateDAO.class); + ClusterServiceDAO clusterServiceDao = injector.getInstance(ClusterServiceDAO.class); + final ClusterEntity clusterEntity = upgradeCatalogHelper.createCluster( injector, CLUSTER_NAME, DESIRED_STACK_VERSION); @@ -544,9 +550,6 @@ public class UpgradeCatalog200Test { clusterServiceEntityNagios, hostEntity, "NAGIOS_SERVER", DESIRED_STACK_VERSION); - UpgradeCatalog200 upgradeCatalog200 = injector.getInstance(UpgradeCatalog200.class); - - ServiceComponentDesiredStateDAO serviceComponentDesiredStateDAO = injector.getInstance(ServiceComponentDesiredStateDAO.class); ServiceComponentDesiredStateEntityPK pkNagiosServer = new ServiceComponentDesiredStateEntityPK(); pkNagiosServer.setComponentName("NAGIOS_SERVER"); pkNagiosServer.setClusterId(clusterEntity.getClusterId()); @@ -554,25 +557,22 @@ public class UpgradeCatalog200Test { ServiceComponentDesiredStateEntity serviceComponentDesiredStateEntity = serviceComponentDesiredStateDAO.findByPK(pkNagiosServer); assertNotNull(serviceComponentDesiredStateEntity); - HostComponentDesiredStateDAO hostComponentDesiredStateDAO = injector.getInstance(HostComponentDesiredStateDAO.class); HostComponentDesiredStateEntityPK hcDesiredStateEntityPk = new HostComponentDesiredStateEntityPK(); hcDesiredStateEntityPk.setServiceName("NAGIOS"); hcDesiredStateEntityPk.setClusterId(clusterEntity.getClusterId()); hcDesiredStateEntityPk.setComponentName("NAGIOS_SERVER"); - hcDesiredStateEntityPk.setHostName(HOST_NAME); + hcDesiredStateEntityPk.setHostId(hostEntity.getHostId()); HostComponentDesiredStateEntity hcDesiredStateEntity = hostComponentDesiredStateDAO.findByPK(hcDesiredStateEntityPk); assertNotNull(hcDesiredStateEntity); - HostComponentStateDAO hostComponentStateDAO = injector.getInstance(HostComponentStateDAO.class); HostComponentStateEntityPK hcStateEntityPk = new HostComponentStateEntityPK(); hcStateEntityPk.setServiceName("NAGIOS"); hcStateEntityPk.setClusterId(clusterEntity.getClusterId()); hcStateEntityPk.setComponentName("NAGIOS_SERVER"); - hcStateEntityPk.setHostName(HOST_NAME); + hcStateEntityPk.setHostId(hostEntity.getHostId()); HostComponentStateEntity hcStateEntity = hostComponentStateDAO.findByPK(hcStateEntityPk); assertNotNull(hcStateEntity); - ClusterServiceDAO clusterServiceDao = injector.getInstance(ClusterServiceDAO.class); ClusterServiceEntity clusterService = clusterServiceDao.findByClusterAndServiceNames( CLUSTER_NAME, "NAGIOS"); http://git-wip-us.apache.org/repos/asf/ambari/blob/1487ad37/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog210Test.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog210Test.java b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog210Test.java index 47cadf3..513e98a 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog210Test.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog210Test.java @@ -29,8 +29,6 @@ import org.apache.ambari.server.orm.DBAccessor; import org.apache.ambari.server.orm.DBAccessor.DBColumnInfo; 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.state.stack.OsFamily; import org.easymock.Capture; import org.junit.After; @@ -42,6 +40,8 @@ import javax.persistence.EntityManager; import java.lang.reflect.Field; import java.sql.Connection; import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.HashMap; import java.util.List; import static org.easymock.EasyMock.capture; @@ -59,10 +59,6 @@ import static org.easymock.EasyMock.verify; * {@link org.apache.ambari.server.upgrade.UpgradeCatalog210} unit tests. */ public class UpgradeCatalog210Test { - private final String CLUSTER_NAME = "c1"; - private final String HOST_NAME = "h1"; - private final String DESIRED_STACK_VERSION = "{\"stackName\":\"HDP\",\"stackVersion\":\"2.0.6\"}"; - private Injector injector; private Provider<EntityManager> entityManagerProvider = createStrictMock(Provider.class); private EntityManager entityManager = createNiceMock(EntityManager.class); @@ -92,40 +88,18 @@ public class UpgradeCatalog210Test { ResultSet resultSet = createNiceMock(ResultSet.class); expect(configuration.getDatabaseUrl()).andReturn(Configuration.JDBC_IN_MEMORY_URL).anyTimes(); - HostDAO hostDao = createNiceMock(HostDAO.class); - HostEntity mockHost = createNiceMock(HostEntity.class); - expect(hostDao.findByName("foo")).andReturn(mockHost).anyTimes(); - - // Column Capture section - Capture<DBAccessor.DBColumnInfo> hostsColumnCapture = new Capture<DBAccessor.DBColumnInfo>(); - Capture<DBAccessor.DBColumnInfo> viewInstanceColumnCapture = new Capture<DBAccessor.DBColumnInfo>(); - Capture<DBAccessor.DBColumnInfo> viewParamColumnCapture = new Capture<DBAccessor.DBColumnInfo>(); - - // Add columns and alter table section - dbAccessor.addColumn(eq("hosts"), capture(hostsColumnCapture)); - - dbAccessor.addColumn(eq("viewinstance"), capture(viewInstanceColumnCapture)); - dbAccessor.addColumn(eq("viewparameter"), capture(viewParamColumnCapture)); + // Create DDL sections with their own capture groups + HostSectionDDL hostSectionDDL = new HostSectionDDL(); + WidgetSectionDDL widgetSectionDDL = new WidgetSectionDDL(); + ViewSectionDDL viewSectionDDL = new ViewSectionDDL(); - Capture<List<DBColumnInfo>> userWidgetColumnsCapture = new Capture<List<DBColumnInfo>>(); - Capture<List<DBColumnInfo>> widgetLayoutColumnsCapture = new Capture<List<DBColumnInfo>>(); - Capture<List<DBColumnInfo>> widgetLayoutUserWidgetColumnsCapture = new Capture<List<DBColumnInfo>>(); + // Execute any DDL schema changes + hostSectionDDL.execute(dbAccessor); + widgetSectionDDL.execute(dbAccessor); + viewSectionDDL.execute(dbAccessor); - // User Widget - dbAccessor.createTable(eq("user_widget"), - capture(userWidgetColumnsCapture), eq("id")); - - // Widget Layout - dbAccessor.createTable(eq("widget_layout"), - capture(widgetLayoutColumnsCapture), eq("id")); - - // Widget Layout User Widget - dbAccessor.createTable(eq("widget_layout_user_widget"), - capture(widgetLayoutUserWidgetColumnsCapture), eq("widget_layout_id"), eq("user_widget_id")); - - // Replay section + // Replay sections replay(dbAccessor, configuration, resultSet); - replay(hostDao, mockHost); AbstractUpgradeCatalog upgradeCatalog = getUpgradeCatalog(dbAccessor); Class<?> c = AbstractUpgradeCatalog.class; @@ -136,35 +110,10 @@ public class UpgradeCatalog210Test { upgradeCatalog.executeDDLUpdates(); verify(dbAccessor, configuration, resultSet); - // Verification section - verifyHosts(hostsColumnCapture); - verifyViewInstance(viewInstanceColumnCapture); - verifyViewParameter(viewParamColumnCapture); - - - // Verify widget tables - assertEquals(12, userWidgetColumnsCapture.getValue().size()); - assertEquals(4, widgetLayoutColumnsCapture.getValue().size()); - assertEquals(3, widgetLayoutUserWidgetColumnsCapture.getValue().size()); - } - - private void verifyHosts(Capture<DBAccessor.DBColumnInfo> hostsColumnCapture) { - DBColumnInfo hostsIdColumn = hostsColumnCapture.getValue(); - Assert.assertEquals(Long.class, hostsIdColumn.getType()); - Assert.assertEquals("id", hostsIdColumn.getName()); - } - - private void verifyViewInstance(Capture<DBAccessor.DBColumnInfo> viewInstanceColumnCapture) { - DBColumnInfo clusterIdColumn = viewInstanceColumnCapture.getValue(); - Assert.assertEquals(String.class, clusterIdColumn.getType()); - Assert.assertEquals("cluster_handle", clusterIdColumn.getName()); - } - - - private void verifyViewParameter(Capture<DBAccessor.DBColumnInfo> viewParamColumnCapture) { - DBColumnInfo clusterConfigColumn = viewParamColumnCapture.getValue(); - Assert.assertEquals(String.class, clusterConfigColumn.getType()); - Assert.assertEquals("cluster_config", clusterConfigColumn.getName()); + // Verify sections + hostSectionDDL.verify(dbAccessor); + widgetSectionDDL.verify(dbAccessor); + viewSectionDDL.verify(dbAccessor); } /** @@ -199,4 +148,180 @@ public class UpgradeCatalog210Test { Assert.assertEquals("2.1.0", upgradeCatalog.getTargetVersion()); } + + // *********** Inner Classes that represent sections of the DDL *********** + // ************************************************************************ + + /** + * Verify that all of the host-related tables added a column for the host_id + */ + class HostSectionDDL implements SectionDDL { + + HashMap<String, Capture<DBColumnInfo>> captures; + + public HostSectionDDL() { + // Capture all tables that will have the host_id column added to it. + captures = new HashMap<String, Capture<DBColumnInfo>>(); + + // Column Capture section + // Hosts + Capture<DBAccessor.DBColumnInfo> hostsColumnCapture = new Capture<DBAccessor.DBColumnInfo>(); + Capture<DBAccessor.DBColumnInfo> hostComponentStateColumnCapture = new Capture<DBAccessor.DBColumnInfo>(); + Capture<DBAccessor.DBColumnInfo> hostComponentDesiredStateColumnCapture = new Capture<DBAccessor.DBColumnInfo>(); + Capture<DBAccessor.DBColumnInfo> hostStateColumnCapture = new Capture<DBAccessor.DBColumnInfo>(); + Capture<DBAccessor.DBColumnInfo> clusterHostMappingColumnCapture = new Capture<DBAccessor.DBColumnInfo>(); + + // TODO, include other tables. + captures.put("hosts", hostsColumnCapture); + captures.put("hostcomponentstate", hostComponentStateColumnCapture); + captures.put("hostcomponentdesiredstate", hostComponentDesiredStateColumnCapture); + captures.put("hoststate", hostStateColumnCapture); + captures.put("ClusterHostMapping", clusterHostMappingColumnCapture); + } + + /** + * {@inheritDoc} + */ + @Override + public void execute(DBAccessor dbAccessor) throws SQLException { + // Add columns and alter table section + dbAccessor.addColumn(eq("hosts"), capture(captures.get("hosts"))); + dbAccessor.addColumn(eq("hostcomponentstate"), capture(captures.get("hostcomponentstate"))); + dbAccessor.addColumn(eq("hostcomponentdesiredstate"), capture(captures.get("hostcomponentdesiredstate"))); + dbAccessor.addColumn(eq("hoststate"), capture(captures.get("hoststate"))); + dbAccessor.addColumn(eq("ClusterHostMapping"), capture(captures.get("ClusterHostMapping"))); + } + + /** + * {@inheritDoc} + */ + @Override + public void verify(DBAccessor dbAccessor) throws SQLException { + // Verification section + for (Capture<DBColumnInfo> columnCapture : captures.values()) { + verifyContainsHostIdColumn(columnCapture); + } + } + + /** + * Verify that the column capture of the table contains a host_id column of type Long. + * This is needed for all of the host-related tables that are switching from the + * host_name to the host_id. + * @param columnCapture + */ + private void verifyContainsHostIdColumn(Capture<DBAccessor.DBColumnInfo> columnCapture) { + DBColumnInfo idColumn = columnCapture.getValue(); + Assert.assertEquals(Long.class, idColumn.getType()); + Assert.assertEquals("host_id", idColumn.getName()); + } + } + + /** + * Verify that the user_widget, widget_layout, and widget_layout_user_widget tables are created correctly. + */ + class WidgetSectionDDL implements SectionDDL { + + HashMap<String, Capture<List<DBColumnInfo>>> captures; + + public WidgetSectionDDL() { + captures = new HashMap<String, Capture<List<DBColumnInfo>>>(); + + Capture<List<DBColumnInfo>> userWidgetColumnsCapture = new Capture<List<DBColumnInfo>>(); + Capture<List<DBColumnInfo>> widgetLayoutColumnsCapture = new Capture<List<DBColumnInfo>>(); + Capture<List<DBColumnInfo>> widgetLayoutUserWidgetColumnsCapture = new Capture<List<DBColumnInfo>>(); + + captures.put("user_widget", userWidgetColumnsCapture); + captures.put("widget_layout", widgetLayoutColumnsCapture); + captures.put("widget_layout_user_widget", widgetLayoutUserWidgetColumnsCapture); + } + + /** + * {@inheritDoc} + */ + @Override + public void execute(DBAccessor dbAccessor) throws SQLException { + Capture<List<DBColumnInfo>> userWidgetColumnsCapture = captures.get("user_widget"); + Capture<List<DBColumnInfo>> widgetLayoutColumnsCapture = captures.get("widget_layout"); + Capture<List<DBColumnInfo>> widgetLayoutUserWidgetColumnsCapture = captures.get("widget_layout_user_widget"); + + // User Widget + dbAccessor.createTable(eq("user_widget"), + capture(userWidgetColumnsCapture), eq("id")); + + // Widget Layout + dbAccessor.createTable(eq("widget_layout"), + capture(widgetLayoutColumnsCapture), eq("id")); + + // Widget Layout User Widget + dbAccessor.createTable(eq("widget_layout_user_widget"), + capture(widgetLayoutUserWidgetColumnsCapture), eq("widget_layout_id"), eq("user_widget_id")); + } + + /** + * {@inheritDoc} + */ + @Override + public void verify(DBAccessor dbAccessor) throws SQLException { + Capture<List<DBColumnInfo>> userWidgetColumnsCapture = captures.get("user_widget"); + Capture<List<DBColumnInfo>> widgetLayoutColumnsCapture = captures.get("widget_layout"); + Capture<List<DBColumnInfo>> widgetLayoutUserWidgetColumnsCapture = captures.get("widget_layout_user_widget"); + + // Verify widget tables + assertEquals(12, userWidgetColumnsCapture.getValue().size()); + assertEquals(4, widgetLayoutColumnsCapture.getValue().size()); + assertEquals(3, widgetLayoutUserWidgetColumnsCapture.getValue().size()); + } + } + + /** + * Verify view changes + */ + class ViewSectionDDL implements SectionDDL { + + HashMap<String, Capture<DBColumnInfo>> captures; + + public ViewSectionDDL() { + captures = new HashMap<String, Capture<DBColumnInfo>>(); + + Capture<DBAccessor.DBColumnInfo> viewInstanceColumnCapture = new Capture<DBAccessor.DBColumnInfo>(); + Capture<DBAccessor.DBColumnInfo> viewParamColumnCapture = new Capture<DBAccessor.DBColumnInfo>(); + + captures.put("viewinstance", viewInstanceColumnCapture); + captures.put("viewparameter", viewParamColumnCapture); + } + + /** + * {@inheritDoc} + */ + @Override + public void execute(DBAccessor dbAccessor) throws SQLException { + Capture<DBColumnInfo> viewInstanceColumnCapture = captures.get("viewinstance"); + Capture<DBColumnInfo> viewParamColumnCapture = captures.get("viewparameter"); + + dbAccessor.addColumn(eq("viewinstance"), capture(viewInstanceColumnCapture)); + dbAccessor.addColumn(eq("viewparameter"), capture(viewParamColumnCapture)); + } + + /** + * {@inheritDoc} + */ + @Override + public void verify(DBAccessor dbAccessor) throws SQLException { + verifyViewInstance(captures.get("viewinstance")); + verifyViewParameter(captures.get("viewparameter")); + } + + private void verifyViewInstance(Capture<DBAccessor.DBColumnInfo> viewInstanceColumnCapture) { + DBColumnInfo clusterIdColumn = viewInstanceColumnCapture.getValue(); + Assert.assertEquals(String.class, clusterIdColumn.getType()); + Assert.assertEquals("cluster_handle", clusterIdColumn.getName()); + } + + + private void verifyViewParameter(Capture<DBAccessor.DBColumnInfo> viewParamColumnCapture) { + DBColumnInfo clusterConfigColumn = viewParamColumnCapture.getValue(); + Assert.assertEquals(String.class, clusterConfigColumn.getType()); + Assert.assertEquals("cluster_config", clusterConfigColumn.getName()); + } + } } http://git-wip-us.apache.org/repos/asf/ambari/blob/1487ad37/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalogHelper.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalogHelper.java b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalogHelper.java index b5db360..aa9d26b 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalogHelper.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalogHelper.java @@ -178,7 +178,6 @@ public class UpgradeCatalogHelper { HostComponentDesiredStateDAO hostComponentDesiredStateDAO = injector.getInstance(HostComponentDesiredStateDAO.class); HostComponentDesiredStateEntity hostComponentDesiredStateEntity = new HostComponentDesiredStateEntity(); hostComponentDesiredStateEntity.setClusterId(clusterEntity.getClusterId()); - hostComponentDesiredStateEntity.setHostName(hostEntity.getHostName()); hostComponentDesiredStateEntity.setComponentName(componentName); hostComponentDesiredStateEntity.setServiceName(clusterServiceEntity.getServiceName()); hostComponentDesiredStateEntity.setAdminState(HostComponentAdminState.INSERVICE); @@ -188,7 +187,6 @@ public class UpgradeCatalogHelper { HostComponentStateEntity hostComponentStateEntity = new HostComponentStateEntity(); hostComponentStateEntity.setHostEntity(hostEntity); - hostComponentStateEntity.setHostName(hostEntity.getHostName()); hostComponentStateEntity.setComponentName(componentName); hostComponentStateEntity.setServiceName(clusterServiceEntity.getServiceName()); hostComponentStateEntity.setClusterId(clusterEntity.getClusterId()); http://git-wip-us.apache.org/repos/asf/ambari/blob/1487ad37/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalogTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalogTest.java b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalogTest.java index b0c8fd9..eb53b03 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalogTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalogTest.java @@ -75,6 +75,11 @@ public class UpgradeCatalogTest { public String getTargetVersion() { return "1.4.9"; } + + @Override + public String[] getCompatibleVersions() { + return new String[] {"1.4.9", "1.5.*", "1.7.*", "2.0.*"}; + } } private static class UpgradeHelperModuleTest extends InMemoryDefaultTestModule { @@ -85,8 +90,11 @@ public class UpgradeCatalogTest { // Add binding to each newly created catalog Multibinder<UpgradeCatalog> catalogBinder = Multibinder.newSetBinder(binder(), UpgradeCatalog.class); - catalogBinder.addBinding().to(UpgradeCatalog150.class); catalogBinder.addBinding().to(UpgradeCatalog149.class); + catalogBinder.addBinding().to(UpgradeCatalog150.class); + catalogBinder.addBinding().to(UpgradeCatalog170.class); + catalogBinder.addBinding().to(UpgradeCatalog200.class); + catalogBinder.addBinding().to(UpgradeCatalog210.class); } } @@ -109,15 +117,52 @@ public class UpgradeCatalogTest { Set<UpgradeCatalog> upgradeCatalogSet = schemaUpgradeHelper.getAllUpgradeCatalogs(); Assert.assertNotNull(upgradeCatalogSet); - Assert.assertEquals(2, upgradeCatalogSet.size()); + Assert.assertEquals(5, upgradeCatalogSet.size()); - List<UpgradeCatalog> upgradeCatalogs = - schemaUpgradeHelper.getUpgradePath(null, "1.5.1"); + List<UpgradeCatalog> upgradeCatalogs = schemaUpgradeHelper.getUpgradePath(null, "1.5.1"); Assert.assertNotNull(upgradeCatalogs); Assert.assertEquals(2, upgradeCatalogs.size()); Assert.assertEquals("1.4.9", upgradeCatalogs.get(0).getTargetVersion()); Assert.assertEquals("1.5.0", upgradeCatalogs.get(1).getTargetVersion()); + + schemaUpgradeHelper.validateUpgradePath(upgradeCatalogs, "1.5.0"); + } + + @Test + public void testValidateUpgradePath() throws Exception { + SchemaUpgradeHelper schemaUpgradeHelper = injector.getInstance(SchemaUpgradeHelper.class); + + Set<UpgradeCatalog> upgradeCatalogSet = schemaUpgradeHelper.getAllUpgradeCatalogs(); + + Assert.assertNotNull(upgradeCatalogSet); + Assert.assertEquals(5, upgradeCatalogSet.size()); + + List<UpgradeCatalog> upgradeCatalogs = schemaUpgradeHelper.getUpgradePath(null, "2.1.0"); + + Assert.assertNotNull(upgradeCatalogs); + Assert.assertEquals(5, upgradeCatalogs.size()); + Assert.assertEquals("1.4.9", upgradeCatalogs.get(0).getTargetVersion()); + Assert.assertEquals("1.5.0", upgradeCatalogs.get(1).getTargetVersion()); + Assert.assertEquals("1.7.0", upgradeCatalogs.get(2).getTargetVersion()); + Assert.assertEquals("2.0.0", upgradeCatalogs.get(3).getTargetVersion()); + Assert.assertEquals("2.1.0", upgradeCatalogs.get(4).getTargetVersion()); + + try { + // This is a valid path, so should not throw exception. + schemaUpgradeHelper.validateUpgradePath(upgradeCatalogs, "2.0.0"); + } catch (Throwable ex) { + Assert.assertTrue(false); + } + + Throwable e = null; + try { + // This is an invalid path, so should throw exception. + schemaUpgradeHelper.validateUpgradePath(upgradeCatalogs, "2.1.0"); + } catch (Throwable ex) { + e = ex; + } + Assert.assertTrue(e instanceof AmbariException); } @Test
