ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alejan...@apache.org
Subject [2/2] ambari git commit: other tables for clean delete of hosts
Date Wed, 25 Mar 2015 19:04:22 GMT
other tables for clean delete of hosts


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/d44a478c
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/d44a478c
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/d44a478c

Branch: refs/heads/trunk
Commit: d44a478cd2de22b4e93fb8f768831523fa3887b1
Parents: 9071669
Author: Alejandro Fernandez <afernandez@hortonworks.com>
Authored: Wed Mar 25 00:28:55 2015 -0700
Committer: Alejandro Fernandez <afernandez@hortonworks.com>
Committed: Wed Mar 25 12:03:20 2015 -0700

----------------------------------------------------------------------
 .../server/orm/entities/HostStateEntity.java    | 23 ++++++-------
 .../server/upgrade/UpgradeCatalog210.java       | 34 +++++++++++---------
 .../main/resources/Ambari-DDL-MySQL-CREATE.sql  |  9 ++----
 .../main/resources/Ambari-DDL-Oracle-CREATE.sql |  9 ++----
 .../resources/Ambari-DDL-Postgres-CREATE.sql    |  9 ++----
 .../Ambari-DDL-Postgres-EMBEDDED-CREATE.sql     |  9 ++----
 .../resources/Ambari-DDL-SQLServer-CREATE.sql   | 14 ++++++--
 .../server/upgrade/UpgradeCatalog210Test.java   | 27 ++++++++++++----
 8 files changed, 71 insertions(+), 63 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/d44a478c/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostStateEntity.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostStateEntity.java
b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostStateEntity.java
index 5d5a1e8..0bbda53 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostStateEntity.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostStateEntity.java
@@ -35,9 +35,9 @@ import org.apache.ambari.server.state.HostState;
 @Entity
 public class HostStateEntity {
   
-  @javax.persistence.Column(name = "host_name", nullable = false, insertable = false, updatable
= false)
+  @javax.persistence.Column(name = "host_id", nullable = false, insertable = false, updatable
= false)
   @Id
-  private String hostName;
+  private Long hostId;
 
   @Column(name = "available_mem", nullable = false, insertable = true, updatable = true)
   @Basic
@@ -64,17 +64,9 @@ public class HostStateEntity {
   
 
   @OneToOne
-  @JoinColumn(name = "host_name", referencedColumnName = "host_name", nullable = false)
+  @JoinColumn(name = "host_id", referencedColumnName = "id", nullable = false)
   private HostEntity hostEntity;
 
-  public String getHostName() {
-    return hostName;
-  }
-
-  public void setHostName(String hostName) {
-    this.hostName = hostName;
-  }
-
   public Long getAvailableMem() {
     return availableMem;
   }
@@ -130,22 +122,27 @@ public class HostStateEntity {
 
     HostStateEntity that = (HostStateEntity) o;
 
+    if (hostId != null ? hostId != that.hostId : that.hostId != null) return false;
+
+    /*
     if (availableMem != null ? !availableMem.equals(that.availableMem) : that.availableMem
!= null) return false;
     if (timeInState != null ? !timeInState.equals(that.timeInState) : that.timeInState!=
null) return false;
     if (agentVersion != null ? !agentVersion.equals(that.agentVersion) : that.agentVersion
!= null) return false;
     if (currentState != null ? !currentState.equals(that.currentState) : that.currentState
!= null) return false;
-    if (hostName != null ? !hostName.equals(that.hostName) : that.hostName != null) return
false;
+    */
 
     return true;
   }
 
   @Override
   public int hashCode() {
-    int result = hostName != null ? hostName.hashCode() : 0;
+    int result = hostId != null ? hostId.intValue() : 0;
+    /*
     result = 31 * result + (availableMem != null ? availableMem.intValue() : 0);
     result = 31 * result + (timeInState != null ? timeInState.intValue() : 0);
     result = 31 * result + (agentVersion != null ? agentVersion.hashCode() : 0);
     result = 31 * result + (currentState != null ? currentState.hashCode() : 0);
+    */
     return result;
   }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/d44a478c/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog210.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog210.java
b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog210.java
index 92f1dac..00bb69e 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog210.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog210.java
@@ -121,7 +121,6 @@ public class UpgradeCatalog210 extends AbstractUpgradeCatalog {
 
     // Insert host id number into ambari_sequences
     dbAccessor.executeQuery("INSERT INTO ambari_sequences (sequence_name, sequence_value)
VALUES ('host_id_seq', " + hostId + ")");
-    //dbAccessor.insertRow("ambari_sequences", new String[]{"sequence_name", "sequence_value"},
new String[]{"host_id_seq", hostId.toString()}, false);
 
     // Make the hosts id non-null after all the values are populated
     if (databaseType == Configuration.DatabaseType.DERBY) {
@@ -129,10 +128,8 @@ public class UpgradeCatalog210 extends AbstractUpgradeCatalog {
       dbAccessor.executeQuery("ALTER TABLE hosts ALTER column id NOT NULL");
     } else {
       dbAccessor.alterColumn("hosts", new DBColumnInfo("id", Long.class, null, null, false));
-      //dbAccessor.executeQuery("ALTER TABLE hosts ALTER column id SET NOT NULL");
     }
 
-
     // Drop the 8 FK constraints in the host-related tables. They will be recreated later
after the PK is changed.
     // The only host-related table not being included is alert_history.
     if (databaseType == Configuration.DatabaseType.DERBY) {
@@ -171,7 +168,7 @@ public class UpgradeCatalog210 extends AbstractUpgradeCatalog {
           "It is possible it did not exist or the deletion failed. " +  e.getMessage());
     }
 
-    // Readd the FK to the cluster_id; will add the host_id at the end.
+    // Re-add the FK to the cluster_id; will add the host_id at the end.
     dbAccessor.addFKConstraint(CLUSTER_HOST_MAPPING_TABLE, "FK_clusterhostmapping_cluster_id",
         "cluster_id", CLUSTERS_TABLE, "cluster_id", false);
 
@@ -185,17 +182,15 @@ public class UpgradeCatalog210 extends AbstractUpgradeCatalog {
       dbAccessor.dropConstraint(HOSTS_TABLE, "hosts_pkey");
     }
     dbAccessor.executeQuery("ALTER TABLE hosts ADD CONSTRAINT PK_hosts_id PRIMARY KEY (id)");
-
     dbAccessor.executeQuery("ALTER TABLE hosts ADD CONSTRAINT UQ_hosts_host_name UNIQUE (host_name)");
 
+
     // TODO, for now, these still point to the host_name and will be fixed one table at a
time to point to the host id.
     // Re-add the FKs
     dbAccessor.addFKConstraint(HOST_COMPONENT_DESIRED_STATE_TABLE, "hstcmponentdesiredstatehstname",
         "host_name", HOSTS_TABLE, "host_name", false);
     dbAccessor.addFKConstraint(HOST_COMPONENT_STATE_TABLE, "hostcomponentstate_host_name",
         "host_name", HOSTS_TABLE, "host_name", false);
-    dbAccessor.addFKConstraint(HOST_STATE_TABLE, "FK_hoststate_host_name",
-        "host_name", HOSTS_TABLE, "host_name", false);
     dbAccessor.addFKConstraint(HOST_VERSION_TABLE, "FK_host_version_host_name",
         "host_name", HOSTS_TABLE, "host_name", false);
     dbAccessor.addFKConstraint(HOST_ROLE_COMMAND_TABLE, "FK_host_role_command_host_name",
@@ -209,20 +204,27 @@ public class UpgradeCatalog210 extends AbstractUpgradeCatalog {
 
 
     // Add host_id to the host-related tables, and populate the host_id, one table at a time.
-    dbAccessor.addColumn(CLUSTER_HOST_MAPPING_TABLE, new DBColumnInfo("host_id", Long.class,
null, null, true));
-    dbAccessor.executeQuery("UPDATE clusterhostmapping chm SET host_id = (SELECT id FROM
hosts h WHERE h.host_name = chm.host_name) WHERE chm.host_id IS NULL AND chm.host_name IS
NOT NULL");
-
-    if (databaseType == Configuration.DatabaseType.DERBY) {
-      // This is a workaround for UpgradeTest.java unit test
-      dbAccessor.executeQuery("ALTER TABLE clusterhostmapping ALTER column host_id NOT NULL");
-    } else {
-      dbAccessor.executeQuery("ALTER TABLE clusterhostmapping ALTER column host_id SET NOT
NULL");
+    String[] tablesToAddHostID = new String[] {HOST_STATE_TABLE, CLUSTER_HOST_MAPPING_TABLE};
+    for (String tableName : tablesToAddHostID) {
+      dbAccessor.addColumn(tableName, new DBColumnInfo("host_id", Long.class, null, null,
true));
+      dbAccessor.executeQuery("UPDATE " + tableName + " t SET host_id = (SELECT id FROM hosts
h WHERE h.host_name = t.host_name) WHERE t.host_id IS NULL AND t.host_name IS NOT NULL");
+
+      if (databaseType == Configuration.DatabaseType.DERBY) {
+        // This is a workaround for UpgradeTest.java unit test
+        dbAccessor.executeQuery("ALTER TABLE " + tableName + " ALTER column host_id NOT NULL");
+      } else {
+        dbAccessor.executeQuery("ALTER TABLE " + tableName + " ALTER column host_id SET NOT
NULL");
+      }
     }
-
+    
     // These are the FKs that have already been corrected.
+    dbAccessor.addFKConstraint(HOST_STATE_TABLE, "FK_hoststate_host_id",
+        "host_id", HOSTS_TABLE, "id", false);
     dbAccessor.addFKConstraint(CLUSTER_HOST_MAPPING_TABLE, "FK_clusterhostmapping_host_id",
         "host_id", HOSTS_TABLE, "id", false);
 
+    // Finish by deleting the unnecessary host_name columns.
+    dbAccessor.dropColumn(HOST_STATE_TABLE, "host_name");
     dbAccessor.dropColumn(CLUSTER_HOST_MAPPING_TABLE, "host_name");
   }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/d44a478c/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
index be90dce..f241544 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
@@ -150,12 +150,10 @@ CREATE TABLE 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));
 
 CREATE TABLE host_version (
   id BIGINT NOT NULL,
@@ -575,8 +573,7 @@ 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 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 hoststate ADD CONSTRAINT FK_hoststate_host_id FOREIGN KEY (host_id) REFERENCES
hosts (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_repovers_id FOREIGN KEY (repo_version_id)
REFERENCES repo_version (repo_version_id);

http://git-wip-us.apache.org/repos/asf/ambari/blob/d44a478c/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
index 76f0e6b..ab55141 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
@@ -139,12 +139,10 @@ CREATE TABLE hoststate (
   available_mem NUMBER(19) NOT NULL,
   current_state VARCHAR2(255) NOT NULL,
   health_status VARCHAR2(255) NULL,
-  host_name VARCHAR2(255) NOT NULL,
-  --host_id NUMBER(19) NOT NULL,
+  host_id NUMBER(19) NOT NULL,
   time_in_state NUMBER(19) NOT NULL,
   maintenance_state VARCHAR2(512),
-  PRIMARY KEY (host_name));
-  --PRIMARY KEY (host_id));
+  PRIMARY KEY (host_id));
 
 CREATE TABLE host_version (
   id NUMBER(19) NOT NULL,
@@ -564,8 +562,7 @@ 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 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 hoststate ADD CONSTRAINT FK_hoststate_host_id FOREIGN KEY (host_id) REFERENCES
hosts (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_repovers_id FOREIGN KEY (repo_version_id)
REFERENCES repo_version (repo_version_id);

http://git-wip-us.apache.org/repos/asf/ambari/blob/d44a478c/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 0906587..dcf6fba 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
@@ -148,12 +148,10 @@ CREATE TABLE 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));
 
 CREATE TABLE host_version (
   id BIGINT NOT NULL,
@@ -565,8 +563,7 @@ 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 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 hoststate ADD CONSTRAINT FK_hoststate_host_id FOREIGN KEY (host_id) REFERENCES
hosts (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_repovers_id FOREIGN KEY (repo_version_id)
REFERENCES repo_version (repo_version_id);

http://git-wip-us.apache.org/repos/asf/ambari/blob/d44a478c/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 26f4428..a291bc4 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
@@ -171,12 +171,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 (
@@ -634,8 +632,7 @@ 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 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.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_repovers_id FOREIGN KEY (repo_version_id)
REFERENCES ambari.repo_version (repo_version_id);

http://git-wip-us.apache.org/repos/asf/ambari/blob/d44a478c/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 6494a24..566562f 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql
@@ -62,7 +62,16 @@ CREATE TABLE hosts (
   total_mem BIGINT NOT NULL,
   PRIMARY KEY CLUSTERED (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 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 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,8 +146,7 @@ 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 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 hoststate ADD CONSTRAINT FK_hoststate_host_id FOREIGN KEY (host_id) REFERENCES
hosts (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_repovers_id FOREIGN KEY (repo_version_id)
REFERENCES repo_version (repo_version_id);

http://git-wip-us.apache.org/repos/asf/ambari/blob/d44a478c/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 0d7cd08..a4849c2 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.util.ArrayList;
+import java.util.List;
 
 import static org.easymock.EasyMock.*;
 import static org.easymock.EasyMock.capture;
@@ -80,19 +80,21 @@ 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>();
 
+    // Collection to capture all tables that will have the host_id column added to it.
+    List<Capture<DBColumnInfo>> hostRelatedCaptures = new ArrayList<Capture<DBColumnInfo>>();
+    Capture<DBAccessor.DBColumnInfo> hostStateColumnCapture = new Capture<DBAccessor.DBColumnInfo>();
+
+    hostRelatedCaptures.add(hostStateColumnCapture);
+
     // Add columns and alter table section
     dbAccessor.addColumn(eq("hosts"), capture(hostsColumnCapture));
+    dbAccessor.addColumn(eq("hoststate"), capture(hostStateColumnCapture));
 
     // Replay section
     replay(dbAccessor, configuration, resultSet);
-    replay(hostDao, mockHost);
 
     AbstractUpgradeCatalog upgradeCatalog = getUpgradeCatalog(dbAccessor);
     Class<?> c = AbstractUpgradeCatalog.class;
@@ -105,6 +107,11 @@ public class UpgradeCatalog210Test {
 
     // Verification section
     verifyHosts(hostsColumnCapture);
+
+    for (Capture<DBColumnInfo> columnCapture : hostRelatedCaptures) {
+      verifyContainsHostIdColumn(columnCapture);
+    }
+
   }
 
   private void verifyHosts(Capture<DBAccessor.DBColumnInfo> hostsColumnCapture) {
@@ -113,6 +120,12 @@ public class UpgradeCatalog210Test {
     Assert.assertEquals("id", hostsIdColumn.getName());
   }
 
+  private void verifyContainsHostIdColumn(Capture<DBAccessor.DBColumnInfo> columnCapture)
{
+    DBColumnInfo idColumn = columnCapture.getValue();
+    Assert.assertEquals(Long.class, idColumn.getType());
+    Assert.assertEquals("host_id", idColumn.getName());
+  }
+
   /**
    * @param dbAccessor
    * @return


Mime
View raw message