You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by al...@apache.org on 2015/03/25 20:04:21 UTC

[1/2] ambari git commit: AMBARI-10209. ClusterHostMapping table prevents cluster deployment, missing host_id column (alejandro)

Repository: ambari
Updated Branches:
  refs/heads/trunk 907166990 -> ae9c18141


AMBARI-10209. ClusterHostMapping table prevents cluster deployment, missing host_id column (alejandro)


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

Branch: refs/heads/trunk
Commit: ae9c18141f5d612942bd210e5d64e352e2f23846
Parents: d44a478
Author: Alejandro Fernandez <af...@hortonworks.com>
Authored: Wed Mar 25 11:22:34 2015 -0700
Committer: Alejandro Fernandez <af...@hortonworks.com>
Committed: Wed Mar 25 12:03:20 2015 -0700

----------------------------------------------------------------------
 ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql  | 6 ++----
 ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql | 6 ++----
 .../src/main/resources/Ambari-DDL-Postgres-CREATE.sql         | 6 ++----
 .../main/resources/Ambari-DDL-Postgres-EMBEDDED-CREATE.sql    | 6 ++----
 .../src/main/resources/Ambari-DDL-SQLServer-CREATE.sql        | 7 ++++++-
 5 files changed, 14 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/ae9c1814/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 f241544..214d980 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
@@ -320,10 +320,8 @@ CREATE TABLE metainfo (
 
 CREATE TABLE ClusterHostMapping (
   cluster_id BIGINT NOT NULL,
-  host_name VARCHAR(255) NOT NULL,
-  --host_id BIGINT NOT NULL,
-  PRIMARY KEY (cluster_id, host_name));
-  --PRIMARY KEY (cluster_id, host_id));
+  host_id BIGINT NOT NULL,
+  PRIMARY KEY (cluster_id, host_id));
 
 CREATE TABLE ambari_sequences (
   sequence_name VARCHAR(255),

http://git-wip-us.apache.org/repos/asf/ambari/blob/ae9c1814/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 ab55141..f0815ba 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
@@ -310,10 +310,8 @@ CREATE TABLE metainfo (
 
 CREATE TABLE ClusterHostMapping (
   cluster_id NUMBER(19) NOT NULL,
-  host_name VARCHAR2(255) NOT NULL,
-  --host_id NUMBER(19) NOT NULL,
-  PRIMARY KEY (cluster_id, host_name));
-  --PRIMARY KEY (cluster_id, host_id));
+  host_id NUMBER(19) NOT NULL,
+  PRIMARY KEY (cluster_id, host_id));
 
 CREATE TABLE ambari_sequences (
   sequence_name VARCHAR2(50) NOT NULL,

http://git-wip-us.apache.org/repos/asf/ambari/blob/ae9c1814/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 dcf6fba..fc5ad50 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
@@ -290,10 +290,8 @@ CREATE TABLE requestoperationlevel (
 
 CREATE TABLE ClusterHostMapping (
   cluster_id BIGINT NOT NULL,
-  host_name VARCHAR(255) NOT NULL,
-  --host_id BIGINT NOT NULL,
-  PRIMARY KEY (cluster_id, host_name));
-  --PRIMARY KEY (cluster_id, host_id));
+  host_id BIGINT NOT NULL,
+  PRIMARY KEY (cluster_id, host_id));
 
 CREATE TABLE key_value_store (
   "key" VARCHAR(255),

http://git-wip-us.apache.org/repos/asf/ambari/blob/ae9c1814/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 a291bc4..369e8ac 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
@@ -327,10 +327,8 @@ GRANT ALL PRIVILEGES ON TABLE ambari.requestoperationlevel TO :username;
 
 CREATE TABLE ambari.ClusterHostMapping (
   cluster_id BIGINT NOT NULL,
-  host_name VARCHAR(255) NOT NULL,
-  --host_id BIGINT NOT NULL,
-  PRIMARY KEY (cluster_id, host_name));
-  --PRIMARY KEY (cluster_id, host_id));
+  host_id BIGINT NOT NULL,
+  PRIMARY KEY (cluster_id, host_id));
 GRANT ALL PRIVILEGES ON TABLE ambari.ClusterHostMapping TO :username;
 
 CREATE TABLE ambari.key_value_store (

http://git-wip-us.apache.org/repos/asf/ambari/blob/ae9c1814/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 566562f..2f2f383 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql
@@ -84,7 +84,12 @@ CREATE TABLE stage (stage_id BIGINT NOT NULL, request_id BIGINT NOT NULL, cluste
 CREATE TABLE request (request_id BIGINT NOT NULL, cluster_id BIGINT, command_name VARCHAR(255), create_time BIGINT NOT NULL, end_time BIGINT NOT NULL, exclusive_execution BIT NOT NULL DEFAULT 0, inputs VARBINARY(8000), request_context VARCHAR(255), request_type VARCHAR(255), request_schedule_id BIGINT, start_time BIGINT NOT NULL, status VARCHAR(255), PRIMARY KEY CLUSTERED (request_id));
 CREATE TABLE requestresourcefilter (filter_id BIGINT NOT NULL, request_id BIGINT NOT NULL, service_name VARCHAR(255), component_name VARCHAR(255), hosts VARBINARY(8000), PRIMARY KEY CLUSTERED (filter_id));
 CREATE TABLE requestoperationlevel (operation_level_id BIGINT NOT NULL, request_id BIGINT NOT NULL, level_name VARCHAR(255), cluster_name VARCHAR(255), service_name VARCHAR(255), host_component_name VARCHAR(255), host_name VARCHAR(255), PRIMARY KEY CLUSTERED (operation_level_id));
-CREATE TABLE ClusterHostMapping (cluster_id BIGINT NOT NULL, host_name VARCHAR(255) NOT NULL, PRIMARY KEY CLUSTERED (cluster_id, host_name));
+
+CREATE TABLE ClusterHostMapping (
+  cluster_id BIGINT NOT NULL,
+  host_id BIGINT NOT NULL,
+  PRIMARY KEY CLUSTERED (cluster_id, host_id));
+
 CREATE TABLE key_value_store ([key] VARCHAR(255), [value] VARCHAR(MAX), PRIMARY KEY CLUSTERED ([key]));
 CREATE TABLE hostconfigmapping (cluster_id BIGINT NOT NULL, host_name VARCHAR(255) NOT NULL, type_name VARCHAR(255) NOT NULL, version_tag VARCHAR(255) NOT NULL, service_name VARCHAR(255), create_timestamp BIGINT NOT NULL, selected INTEGER NOT NULL DEFAULT 0, user_name VARCHAR(255) NOT NULL DEFAULT '_db', PRIMARY KEY CLUSTERED (cluster_id, host_name, type_name, create_timestamp));
 CREATE TABLE metainfo ([metainfo_key] VARCHAR(255), [metainfo_value] VARCHAR(255), PRIMARY KEY CLUSTERED ([metainfo_key]));


[2/2] ambari git commit: other tables for clean delete of hosts

Posted by al...@apache.org.
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 <af...@hortonworks.com>
Authored: Wed Mar 25 00:28:55 2015 -0700
Committer: Alejandro Fernandez <af...@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