ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alejan...@apache.org
Subject ambari git commit: REVERT. Unintended commit c3ebed4c86370120e5172eeff54ed426eae97fb3
Date Wed, 25 Mar 2015 21:11:08 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 295f4f5bc -> 7f8992ec8


REVERT. Unintended commit c3ebed4c86370120e5172eeff54ed426eae97fb3


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

Branch: refs/heads/trunk
Commit: 7f8992ec8c0e2bd8a41b37d16e9483184caf2c4d
Parents: 295f4f5
Author: Alejandro Fernandez <afernandez@hortonworks.com>
Authored: Wed Mar 25 14:04:32 2015 -0700
Committer: Alejandro Fernandez <afernandez@hortonworks.com>
Committed: Wed Mar 25 14:11:00 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, 63 insertions(+), 71 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/7f8992ec/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 0bbda53..5d5a1e8 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_id", nullable = false, insertable = false, updatable
= false)
+  @javax.persistence.Column(name = "host_name", nullable = false, insertable = false, updatable
= false)
   @Id
-  private Long hostId;
+  private String hostName;
 
   @Column(name = "available_mem", nullable = false, insertable = true, updatable = true)
   @Basic
@@ -64,9 +64,17 @@ public class HostStateEntity {
   
 
   @OneToOne
-  @JoinColumn(name = "host_id", referencedColumnName = "id", nullable = false)
+  @JoinColumn(name = "host_name", referencedColumnName = "host_name", nullable = false)
   private HostEntity hostEntity;
 
+  public String getHostName() {
+    return hostName;
+  }
+
+  public void setHostName(String hostName) {
+    this.hostName = hostName;
+  }
+
   public Long getAvailableMem() {
     return availableMem;
   }
@@ -122,27 +130,22 @@ 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 = hostId != null ? hostId.intValue() : 0;
-    /*
+    int result = hostName != null ? hostName.hashCode() : 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/7f8992ec/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 00bb69e..92f1dac 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,6 +121,7 @@ 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) {
@@ -128,8 +129,10 @@ 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) {
@@ -168,7 +171,7 @@ public class UpgradeCatalog210 extends AbstractUpgradeCatalog {
           "It is possible it did not exist or the deletion failed. " +  e.getMessage());
     }
 
-    // Re-add the FK to the cluster_id; will add the host_id at the end.
+    // Readd 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);
 
@@ -182,8 +185,8 @@ 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)");
 
+    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
@@ -191,6 +194,8 @@ public class UpgradeCatalog210 extends AbstractUpgradeCatalog {
         "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",
@@ -204,27 +209,20 @@ public class UpgradeCatalog210 extends AbstractUpgradeCatalog {
 
 
     // Add host_id to the host-related tables, and populate the host_id, one table at a time.
-    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");
-      }
+    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");
     }
-    
+
     // 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/7f8992ec/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 214d980..c63be06 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
@@ -150,10 +150,12 @@ CREATE TABLE hoststate (
   available_mem BIGINT NOT NULL,
   current_state VARCHAR(255) NOT NULL,
   health_status VARCHAR(255),
-  host_id BIGINT NOT NULL,
+  host_name VARCHAR(255) NOT NULL,
+  --host_id BIGINT NOT NULL,
   time_in_state BIGINT NOT NULL,
   maintenance_state VARCHAR(512),
-  PRIMARY KEY (host_id));
+  PRIMARY KEY (host_name));
+  --PRIMARY KEY (host_id));
 
 CREATE TABLE host_version (
   id BIGINT NOT NULL,
@@ -571,7 +573,8 @@ 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_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 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/7f8992ec/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 f0815ba..307afbe 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
@@ -139,10 +139,12 @@ CREATE TABLE hoststate (
   available_mem NUMBER(19) NOT NULL,
   current_state VARCHAR2(255) NOT NULL,
   health_status VARCHAR2(255) NULL,
-  host_id NUMBER(19) NOT NULL,
+  host_name VARCHAR2(255) NOT NULL,
+  --host_id NUMBER(19) NOT NULL,
   time_in_state NUMBER(19) NOT NULL,
   maintenance_state VARCHAR2(512),
-  PRIMARY KEY (host_id));
+  PRIMARY KEY (host_name));
+  --PRIMARY KEY (host_id));
 
 CREATE TABLE host_version (
   id NUMBER(19) NOT NULL,
@@ -560,7 +562,8 @@ 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_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 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/7f8992ec/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 fc5ad50..38e95ae 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
@@ -148,10 +148,12 @@ CREATE TABLE hoststate (
   available_mem BIGINT NOT NULL,
   current_state VARCHAR(255) NOT NULL,
   health_status VARCHAR(255),
-  host_id BIGINT NOT NULL,
+  host_name VARCHAR(255) NOT NULL,
+  --host_id BIGINT NOT NULL,
   time_in_state BIGINT NOT NULL,
   maintenance_state VARCHAR(512),
-  PRIMARY KEY (host_id));
+  PRIMARY KEY (host_name));
+  --PRIMARY KEY (host_id));
 
 CREATE TABLE host_version (
   id BIGINT NOT NULL,
@@ -561,7 +563,8 @@ 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_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 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/7f8992ec/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 369e8ac..2e88853 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,10 +171,12 @@ CREATE TABLE ambari.hoststate (
   available_mem BIGINT NOT NULL,
   current_state VARCHAR(255) NOT NULL,
   health_status VARCHAR(255),
-  host_id BIGINT NOT NULL,
+  host_name VARCHAR(255) NOT NULL,
+  --host_id BIGINT NOT NULL,
   time_in_state BIGINT NOT NULL,
   maintenance_state VARCHAR(512),
-  PRIMARY KEY (host_id));
+  PRIMARY KEY (host_name));
+  --PRIMARY KEY (host_id));
 GRANT ALL PRIVILEGES ON TABLE ambari.hoststate TO :username;
 
 CREATE TABLE ambari.host_version (
@@ -630,7 +632,8 @@ 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_id FOREIGN KEY (host_id) REFERENCES
ambari.hosts (host_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.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/7f8992ec/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 2f2f383..330945c 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql
@@ -62,16 +62,7 @@ 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_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));
@@ -151,7 +142,8 @@ 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_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 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/7f8992ec/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 a4849c2..0d7cd08 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,6 +29,8 @@ 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;
@@ -40,8 +42,6 @@ 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,21 +80,19 @@ 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;
@@ -107,11 +105,6 @@ public class UpgradeCatalog210Test {
 
     // Verification section
     verifyHosts(hostsColumnCapture);
-
-    for (Capture<DBColumnInfo> columnCapture : hostRelatedCaptures) {
-      verifyContainsHostIdColumn(columnCapture);
-    }
-
   }
 
   private void verifyHosts(Capture<DBAccessor.DBColumnInfo> hostsColumnCapture) {
@@ -120,12 +113,6 @@ 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