ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alejan...@apache.org
Subject ambari git commit: AMBARI-10717. Full Delete of Host : Switch requestoperationlevel and kerberos_principal_host tables to use host_id instead of host_name column (alejandro)
Date Fri, 24 Apr 2015 18:41:16 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 673a2d080 -> 0dd082156


AMBARI-10717. Full Delete of Host : Switch requestoperationlevel and kerberos_principal_host tables to use host_id instead of host_name column (alejandro)


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

Branch: refs/heads/trunk
Commit: 0dd08215681dce64b67314dac03b590e5662ce0d
Parents: 673a2d0
Author: Alejandro Fernandez <afernandez@hortonworks.com>
Authored: Thu Apr 23 17:27:00 2015 -0700
Committer: Alejandro Fernandez <afernandez@hortonworks.com>
Committed: Fri Apr 24 11:38:55 2015 -0700

----------------------------------------------------------------------
 .../ambari/server/actionmanager/Request.java    | 36 ++++++++++-----
 .../ambari/server/agent/HeartBeatHandler.java   | 16 +++++--
 .../orm/dao/KerberosPrincipalHostDAO.java       | 36 +++++++--------
 .../entities/KerberosPrincipalHostEntity.java   | 33 +++++++++-----
 .../entities/KerberosPrincipalHostEntityPK.java | 26 +++++------
 .../entities/RequestOperationLevelEntity.java   | 12 ++---
 .../kerberos/CreateKeytabFilesServerAction.java | 30 +++++++++---
 .../server/state/cluster/ClustersImpl.java      |  4 +-
 .../server/upgrade/UpgradeCatalog210.java       | 48 ++++++++++++--------
 .../main/resources/Ambari-DDL-MySQL-CREATE.sql  | 20 ++------
 .../main/resources/Ambari-DDL-Oracle-CREATE.sql | 23 ++--------
 .../resources/Ambari-DDL-Postgres-CREATE.sql    | 19 ++------
 .../Ambari-DDL-Postgres-EMBEDDED-CREATE.sql     | 19 ++------
 .../resources/Ambari-DDL-SQLServer-CREATE.sql   | 18 ++------
 .../server/upgrade/UpgradeCatalog210Test.java   | 28 ++++++++++--
 15 files changed, 198 insertions(+), 170 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/0dd08215/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/Request.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/Request.java b/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/Request.java
index ab81dfd..faebb20 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/Request.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/Request.java
@@ -22,11 +22,15 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
 
+import com.google.inject.Inject;
 import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.StaticallyInject;
 import org.apache.ambari.server.controller.ExecuteActionRequest;
 import org.apache.ambari.server.controller.internal.RequestOperationLevel;
 import org.apache.ambari.server.controller.internal.RequestResourceFilter;
 import org.apache.ambari.server.controller.spi.Resource;
+import org.apache.ambari.server.orm.dao.HostDAO;
+import org.apache.ambari.server.orm.entities.HostEntity;
 import org.apache.ambari.server.orm.entities.RequestEntity;
 import org.apache.ambari.server.orm.entities.RequestOperationLevelEntity;
 import org.apache.ambari.server.orm.entities.RequestResourceFilterEntity;
@@ -40,6 +44,7 @@ import com.google.gson.Gson;
 import com.google.inject.assistedinject.Assisted;
 import com.google.inject.assistedinject.AssistedInject;
 
+@StaticallyInject
 public class Request {
   private static final Logger LOG = LoggerFactory.getLogger(Request.class);
 
@@ -73,6 +78,9 @@ public class Request {
 
   private Collection<Stage> stages = new ArrayList<Stage>();
 
+  @Inject
+  private static HostDAO hostDAO;
+
   @AssistedInject
   /**
    * Construct new entity
@@ -245,14 +253,17 @@ public class Request {
       requestEntity.setResourceFilterEntities(filterEntities);
     }
 
+
     if (operationLevel != null) {
-      RequestOperationLevelEntity operationLevelEntity =
-              new RequestOperationLevelEntity();
+      HostEntity hostEntity = hostDAO.findByName(operationLevel.getHostName());
+      Long hostId = hostEntity != null ? hostEntity.getHostId() : null;
+
+      RequestOperationLevelEntity operationLevelEntity = new RequestOperationLevelEntity();
       operationLevelEntity.setLevel(operationLevel.getLevel().toString());
       operationLevelEntity.setClusterName(operationLevel.getClusterName());
       operationLevelEntity.setServiceName(operationLevel.getServiceName());
       operationLevelEntity.setHostComponentName(operationLevel.getHostComponentName());
-      operationLevelEntity.setHostName(operationLevel.getHostName());
+      operationLevelEntity.setHostId(hostId);
       operationLevelEntity.setRequestEntity(requestEntity);
       operationLevelEntity.setRequestId(requestId);
       requestEntity.setRequestOperationLevel(operationLevelEntity);
@@ -419,20 +430,23 @@ public class Request {
    */
   public static RequestOperationLevel operationLevelFromEntity(RequestEntity entity) {
     RequestOperationLevel level = null;
-
     RequestOperationLevelEntity operationLevelEntity = entity.getRequestOperationLevel();
+
     if (operationLevelEntity != null) {
+      String hostName = null;
+      if (operationLevelEntity.getHostId() != null) {
+        HostEntity hostEntity = hostDAO.findById(operationLevelEntity.getHostId());
+        hostName = hostEntity.getHostName();
+      }
+
       level = new RequestOperationLevel(
           Resource.Type.valueOf(operationLevelEntity.getLevel()),
-        operationLevelEntity.getClusterName(),
-        operationLevelEntity.getServiceName(),
-        operationLevelEntity.getHostComponentName(),
-        operationLevelEntity.getHostName());
+          operationLevelEntity.getClusterName(),
+          operationLevelEntity.getServiceName(),
+          operationLevelEntity.getHostComponentName(),
+          hostName);
     }
 
     return level;
   }
-
-
-
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/0dd08215/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java b/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java
index 9bdc4b7..1b180eb 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java
@@ -52,7 +52,9 @@ import org.apache.ambari.server.events.publishers.AlertEventPublisher;
 import org.apache.ambari.server.events.publishers.AmbariEventPublisher;
 import org.apache.ambari.server.events.publishers.VersionEventPublisher;
 import org.apache.ambari.server.metadata.ActionMetadata;
+import org.apache.ambari.server.orm.dao.HostDAO;
 import org.apache.ambari.server.orm.dao.KerberosPrincipalHostDAO;
+import org.apache.ambari.server.orm.entities.HostEntity;
 import org.apache.ambari.server.serveraction.kerberos.KerberosIdentityDataFileReader;
 import org.apache.ambari.server.serveraction.kerberos.KerberosIdentityDataFileReaderFactory;
 import org.apache.ambari.server.serveraction.kerberos.KerberosServerAction;
@@ -142,6 +144,9 @@ public class HeartBeatHandler {
   private ConfigHelper configHelper;
 
   @Inject
+  private HostDAO hostDAO;
+
+  @Inject
   private AlertDefinitionHash alertDefinitionHash;
 
   /**
@@ -455,6 +460,11 @@ public class HeartBeatHandler {
       LOG.debug("Received command report: " + report);
       // Fetch HostRoleCommand that corresponds to a given task ID
       HostRoleCommand hostRoleCommand = hostRoleCommandIterator.next();
+      HostEntity hostEntity = hostDAO.findByName(hostname);
+      if (hostEntity == null) {
+        LOG.error("Received a command report and was unable to retrieve HostEntity for hostname = " + hostname);
+        continue;
+      }
 
       // Send event for final command reports for actions
       if (RoleCommand.valueOf(report.getRoleCommand()) == RoleCommand.ACTIONEXECUTE &&
@@ -497,11 +507,11 @@ public class HeartBeatHandler {
             if (keytabs != null) {
               for (Map.Entry<String, String> entry : keytabs.entrySet()) {
                 String principal = entry.getKey();
-                if (!kerberosPrincipalHostDAO.exists(principal, hostname)) {
+                if (!kerberosPrincipalHostDAO.exists(principal, hostEntity.getHostId())) {
                   if (adding) {
-                    kerberosPrincipalHostDAO.create(principal, hostname);
+                    kerberosPrincipalHostDAO.create(principal, hostEntity.getHostId());
                   } else if ("_REMOVED_".equalsIgnoreCase(entry.getValue())) {
-                    kerberosPrincipalHostDAO.remove(principal, hostname);
+                    kerberosPrincipalHostDAO.remove(principal, hostEntity.getHostId());
                   }
                 }
               }

http://git-wip-us.apache.org/repos/asf/ambari/blob/0dd08215/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/KerberosPrincipalHostDAO.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/KerberosPrincipalHostDAO.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/KerberosPrincipalHostDAO.java
index 64e18bb..049afc7 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/KerberosPrincipalHostDAO.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/KerberosPrincipalHostDAO.java
@@ -54,8 +54,8 @@ public class KerberosPrincipalHostDAO {
     entityManagerProvider.get().persist(kerberosPrincipalHostEntity);
   }
 
-  public void create(String principal, String hostName) {
-    create(new KerberosPrincipalHostEntity(principal, hostName));
+  public void create(String principal, Long hostId) {
+    create(new KerberosPrincipalHostEntity(principal, hostId));
   }
 
   /**
@@ -79,7 +79,6 @@ public class KerberosPrincipalHostDAO {
     entityManagerProvider.get().remove(merge(kerberosPrincipalHostEntity));
   }
 
-
   /**
    * Refresh the state of the instance from the database,
    * overwriting changes made to the entity, if any.
@@ -91,7 +90,6 @@ public class KerberosPrincipalHostDAO {
     entityManagerProvider.get().refresh(kerberosPrincipalHostEntity);
   }
 
-
   /**
    * Finds KerberosPrincipalHostEntities for the requested principal
    *
@@ -109,14 +107,14 @@ public class KerberosPrincipalHostDAO {
   /**
    * Find KerberosPrincipalHostEntities for the requested host
    *
-   * @param hostName a String indicating the name of the requested host
+   * @param hostId a Long indicating the id of the requested host
    * @return a List of requested KerberosPrincipalHostEntities or null if none were found
    */
   @RequiresSession
-  public List<KerberosPrincipalHostEntity> findByHost(String hostName) {
+  public List<KerberosPrincipalHostEntity> findByHost(Long hostId) {
     final TypedQuery<KerberosPrincipalHostEntity> query = entityManagerProvider.get()
         .createNamedQuery("KerberosPrincipalHostEntityFindByHost", KerberosPrincipalHostEntity.class);
-    query.setParameter("hostName", hostName);
+    query.setParameter("hostId", hostId);
     return query.getResultList();
   }
 
@@ -135,13 +133,13 @@ public class KerberosPrincipalHostDAO {
    * Find the KerberosPrincipalHostEntity for the requested principal name and host
    *
    * @param principalName a String indicating the name of the requested principal
-   * @param hostName      a String indicating the name of the requested host
+   * @param hostId        a Long indicating the id of the requested host
    * @return the KerberosPrincipalHostEntity or null if not found
    */
   @RequiresSession
-  public KerberosPrincipalHostEntity find(String principalName, String hostName) {
+  public KerberosPrincipalHostEntity find(String principalName, Long hostId) {
     return entityManagerProvider.get().find(KerberosPrincipalHostEntity.class,
-        new KerberosPrincipalHostEntityPK(principalName, hostName));
+        new KerberosPrincipalHostEntityPK(principalName, hostId));
   }
 
   /**
@@ -171,23 +169,23 @@ public class KerberosPrincipalHostDAO {
   /**
    * Remove KerberosPrincipalHostEntity instances for the specified host
    *
-   * @param hostName a String indicating the name of the host
+   * @param hostId a Long indicating the id of the host
    */
   @Transactional
-  public void removeByHost(String hostName) {
-    remove(findByHost(hostName));
+  public void removeByHost(Long hostId) {
+    remove(findByHost(hostId));
   }
 
   /**
    * Remove KerberosPrincipalHostEntity instance for the specified principal and host
    *
    * @param principalName a String indicating the name of the principal
-   * @param hostName      a String indicating the name of the host
+   * @param hostId        a Long indicating the id of the host
    * @see #remove(org.apache.ambari.server.orm.entities.KerberosPrincipalHostEntity)
    */
   @Transactional
-  public void remove(String principalName, String hostName) {
-    remove(new KerberosPrincipalHostEntity(principalName, hostName));
+  public void remove(String principalName, Long hostId) {
+    remove(new KerberosPrincipalHostEntity(principalName, hostId));
   }
 
   /**
@@ -206,12 +204,12 @@ public class KerberosPrincipalHostDAO {
    * Tests the existence of a particular principal on a specific host
    *
    * @param principalName a String indicating the name of the principal to test
-   * @param hostName      a String indicating the name of the host to test
+   * @param hostId      a LOng indicating the id of the host to test
    * @return true if the requested principal exists
    */
   @RequiresSession
-  public boolean exists(String principalName, String hostName) {
-    return find(principalName, hostName) != null;
+  public boolean exists(String principalName, Long hostId) {
+    return find(principalName, hostId) != null;
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/ambari/blob/0dd08215/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/KerberosPrincipalHostEntity.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/KerberosPrincipalHostEntity.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/KerberosPrincipalHostEntity.java
index 07c960d..d8266e5 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/KerberosPrincipalHostEntity.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/KerberosPrincipalHostEntity.java
@@ -41,7 +41,7 @@ import javax.persistence.Table;
     @NamedQuery(name = "KerberosPrincipalHostEntityFindByPrincipal",
         query = "SELECT kph FROM KerberosPrincipalHostEntity kph WHERE kph.principalName=:principalName"),
     @NamedQuery(name = "KerberosPrincipalHostEntityFindByHost",
-        query = "SELECT kph FROM KerberosPrincipalHostEntity kph WHERE kph.hostName=:hostName")
+        query = "SELECT kph FROM KerberosPrincipalHostEntity kph WHERE kph.hostId=:hostId")
 })
 public class KerberosPrincipalHostEntity {
 
@@ -50,15 +50,15 @@ public class KerberosPrincipalHostEntity {
   private String principalName;
 
   @Id
-  @Column(name = "host_name", insertable = true, updatable = false, nullable = false)
-  private String hostName;
+  @Column(name = "host_id", insertable = true, updatable = false, nullable = false)
+  private Long hostId;
 
   @ManyToOne
   @JoinColumn(name = "principal_name", referencedColumnName = "principal_name", nullable = false, insertable = false, updatable = false)
   private KerberosPrincipalEntity principalEntity;
 
   @ManyToOne
-  @JoinColumn(name = "host_name", referencedColumnName = "host_name", nullable = false, insertable = false, updatable = false)
+  @JoinColumn(name = "host_id", referencedColumnName = "host_id", nullable = false, insertable = false, updatable = false)
   private HostEntity hostEntity;
 
   /**
@@ -71,11 +71,11 @@ public class KerberosPrincipalHostEntity {
    * Constructs a new KerberosPrincipalHostEntity
    *
    * @param principalName a String indicating this KerberosPrincipalHostEntity's principal name
-   * @param hostName      a String indicating the KerberosPrincipalHostEntity's host name
+   * @param hostId a Long indicating the KerberosPrincipalHostEntity's host id
    */
-  public KerberosPrincipalHostEntity(String principalName, String hostName) {
+  public KerberosPrincipalHostEntity(String principalName, Long hostId) {
     setPrincipalName(principalName);
-    setHostName(hostName);
+    setHostId(hostId);
   }
 
   /**
@@ -102,16 +102,25 @@ public class KerberosPrincipalHostEntity {
    * @return a String indicating this KerberosHostHostEntity's host name
    */
   public String getHostName() {
-    return hostName;
+    return hostEntity != null ? hostEntity.getHostName() : null;
   }
 
   /**
-   * Sets the host name for this KerberosHostHostEntity
+   * Gets the host id for this KerberosHostHostEntity
    *
-   * @param hostName a String indicating this KerberosHostHostEntity's host name
+   * @return a Long indicating this KerberosHostHostEntity's host id
    */
-  public void setHostName(String hostName) {
-    this.hostName = hostName;
+  public Long getHostId() {
+    return hostId;
+  }
+
+  /**
+   * Sets the host id for this KerberosHostHostEntity
+   *
+   * @param hostId a Long indicating this KerberosHostHostEntity's host id
+   */
+  public void setHostId(Long hostId) {
+    this.hostId = hostId;
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/ambari/blob/0dd08215/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/KerberosPrincipalHostEntityPK.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/KerberosPrincipalHostEntityPK.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/KerberosPrincipalHostEntityPK.java
index 704476e..1fd520d 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/KerberosPrincipalHostEntityPK.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/KerberosPrincipalHostEntityPK.java
@@ -32,15 +32,15 @@ public class KerberosPrincipalHostEntityPK implements Serializable{
   private String principalName = null;
 
   @Id
-  @Column(name = "host_name", insertable = false, updatable = false, nullable = false)
-  private String hostName = null;
+  @Column(name = "host_id", insertable = false, updatable = false, nullable = false)
+  private Long hostId = null;
 
   public KerberosPrincipalHostEntityPK() {
   }
 
-  public KerberosPrincipalHostEntityPK(String principalName, String hostName) {
+  public KerberosPrincipalHostEntityPK(String principalName, Long hostId) {
     setPrincipalName(principalName);
-    setHostName(hostName);
+    setHostId(hostId);
   }
 
   /**
@@ -62,21 +62,21 @@ public class KerberosPrincipalHostEntityPK implements Serializable{
   }
 
   /**
-   * Get the host name.
+   * Get the host id.
    *
-   * @return host name
+   * @return host id
    */
-  public String getHostName() {
-    return hostName;
+  public Long getHostId() {
+    return hostId;
   }
 
   /**
    * Set the configuration type.
    *
-   * @param hostName host name
+   * @param hostId host id
    */
-  public void setHostName(String hostName) {
-    this.hostName = hostName;
+  public void setHostId(Long hostId) {
+    this.hostId = hostId;
   }
 
   @Override
@@ -91,11 +91,11 @@ public class KerberosPrincipalHostEntityPK implements Serializable{
     KerberosPrincipalHostEntityPK that = (KerberosPrincipalHostEntityPK) o;
 
     return this.principalName.equals(that.principalName) &&
-        this.hostName.equals(that.hostName);
+        this.hostId.equals(that.hostId);
   }
 
   @Override
   public int hashCode() {
-    return 31 * principalName.hashCode() + hostName.hashCode();
+    return 31 * principalName.hashCode() + hostId.hashCode();
   }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/0dd08215/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/RequestOperationLevelEntity.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/RequestOperationLevelEntity.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/RequestOperationLevelEntity.java
index 4c38a97..2c11e55 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/RequestOperationLevelEntity.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/RequestOperationLevelEntity.java
@@ -78,9 +78,9 @@ public class RequestOperationLevelEntity {
   @Basic
   private String hostComponentName;
 
-  @Column(name = "host_name")
+  @Column(name = "host_id", nullable=true, insertable=true, updatable=true) // Notice that allowed to be null
   @Basic
-  private String hostName;
+  private Long hostId;
 
   public String getLevel() {
     return level;
@@ -114,12 +114,12 @@ public class RequestOperationLevelEntity {
     this.hostComponentName = hostComponentName;
   }
 
-  public String getHostName() {
-    return hostName;
+  public Long getHostId() {
+    return hostId;
   }
 
-  public void setHostName(String hostName) {
-    this.hostName = hostName;
+  public void setHostId(Long hostId) {
+    this.hostId = hostId;
   }
 
   public Long getRequestId() {

http://git-wip-us.apache.org/repos/asf/ambari/blob/0dd08215/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/CreateKeytabFilesServerAction.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/CreateKeytabFilesServerAction.java b/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/CreateKeytabFilesServerAction.java
index 5e8b451..f48c4cf 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/CreateKeytabFilesServerAction.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/CreateKeytabFilesServerAction.java
@@ -23,8 +23,10 @@ import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.actionmanager.HostRoleStatus;
 import org.apache.ambari.server.agent.CommandReport;
 import org.apache.ambari.server.configuration.Configuration;
+import org.apache.ambari.server.orm.dao.HostDAO;
 import org.apache.ambari.server.orm.dao.KerberosPrincipalDAO;
 import org.apache.ambari.server.orm.dao.KerberosPrincipalHostDAO;
+import org.apache.ambari.server.orm.entities.HostEntity;
 import org.apache.ambari.server.orm.entities.KerberosPrincipalEntity;
 import org.apache.commons.codec.digest.DigestUtils;
 import org.apache.directory.server.kerberos.shared.keytab.Keytab;
@@ -71,6 +73,12 @@ public class CreateKeytabFilesServerAction extends KerberosServerAction {
   private Configuration configuration;
 
   /**
+   * HostDAO used to retrieveHost Entity object
+   */
+  @Inject
+  private HostDAO hostDAO;
+
+  /**
    * A map of data used to track what has been processed in order to optimize the creation of keytabs
    * such as knowing when to create a cached keytab file or use a cached keytab file.
    */
@@ -150,25 +158,25 @@ public class CreateKeytabFilesServerAction extends KerberosServerAction {
         Map<String, String> principalPasswordMap = getPrincipalPasswordMap(requestSharedDataContext);
         Map<String, Integer> principalKeyNumberMap = getPrincipalKeyNumberMap(requestSharedDataContext);
 
-        String host = identityRecord.get(KerberosIdentityDataFileReader.HOSTNAME);
+        String hostName = identityRecord.get(KerberosIdentityDataFileReader.HOSTNAME);
         String keytabFilePath = identityRecord.get(KerberosIdentityDataFileReader.KEYTAB_FILE_PATH);
 
-        if ((host != null) && !host.isEmpty() && (keytabFilePath != null) && !keytabFilePath.isEmpty()) {
+        if ((hostName != null) && !hostName.isEmpty() && (keytabFilePath != null) && !keytabFilePath.isEmpty()) {
           Set<String> visitedPrincipalKeys = visitedIdentities.get(evaluatedPrincipal);
-          String visitationKey = String.format("%s|%s", host, keytabFilePath);
+          String visitationKey = String.format("%s|%s", hostName, keytabFilePath);
 
           if ((visitedPrincipalKeys == null) || !visitedPrincipalKeys.contains(visitationKey)) {
             // Look up the current evaluatedPrincipal's password.
             // If found create the keytab file, else try to find it in the cache.
             String password = principalPasswordMap.get(evaluatedPrincipal);
 
-            message = String.format("Creating keytab file for %s on host %s", evaluatedPrincipal, host);
+            message = String.format("Creating keytab file for %s on host %s", evaluatedPrincipal, hostName);
             LOG.info(message);
             actionLog.writeStdOut(message);
 
             // Determine where to store the keytab file.  It should go into a host-specific
             // directory under the previously determined data directory.
-            File hostDirectory = new File(getDataDirectoryPath(), host);
+            File hostDirectory = new File(getDataDirectoryPath(), hostName);
 
             // Ensure the host directory exists...
             if (!hostDirectory.exists() && hostDirectory.mkdirs()) {
@@ -178,9 +186,17 @@ public class CreateKeytabFilesServerAction extends KerberosServerAction {
 
             if (hostDirectory.exists()) {
               File destinationKeytabFile = new File(hostDirectory, DigestUtils.sha1Hex(keytabFilePath));
+              HostEntity hostEntity = hostDAO.findByName(hostName);
+              if (hostEntity == null) {
+                message = "Failed to find HostEntity for hostname = " + hostName;
+                actionLog.writeStdErr(message);
+                LOG.error(message);
+                commandReport = createCommandReport(1, HostRoleStatus.FAILED, "{}", actionLog.getStdOut(), actionLog.getStdErr());
+                return commandReport;
+              }
 
               if (password == null) {
-                if (kerberosPrincipalHostDAO.exists(evaluatedPrincipal, host)) {
+                if (kerberosPrincipalHostDAO.exists(evaluatedPrincipal, hostEntity.getHostId())) {
                   // There is nothing to do for this since it must already exist and we don't want to
                   // regenerate the keytab
                   message = String.format("Skipping keytab file for %s, missing password indicates nothing to do", evaluatedPrincipal);
@@ -304,7 +320,7 @@ public class CreateKeytabFilesServerAction extends KerberosServerAction {
             visitedPrincipalKeys.add(visitationKey);
           }
           else {
-            LOG.debug(String.format("Skipping previously processed keytab for %s on host %s", evaluatedPrincipal, host));
+            LOG.debug(String.format("Skipping previously processed keytab for %s on host %s", evaluatedPrincipal, hostName));
           }
         }
       }

http://git-wip-us.apache.org/repos/asf/ambari/blob/0dd08215/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClustersImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClustersImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClustersImpl.java
index f8066ca..9e63ff2 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClustersImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/cluster/ClustersImpl.java
@@ -717,7 +717,7 @@ public class ClustersImpl implements Clusters {
       deleteConfigGroupHostMapping(hostEntity.getHostId());
 
       // Remove mapping of principals to the unmapped host
-      kerberosPrincipalHostDAO.removeByHost(hostname);
+      kerberosPrincipalHostDAO.removeByHost(hostEntity.getHostId());
     } finally {
       w.unlock();
     }
@@ -775,7 +775,7 @@ public class ClustersImpl implements Clusters {
       hostsById.remove(entity.getHostId());
 
       // Remove mapping of principals to deleted host
-      kerberosPrincipalHostDAO.removeByHost(hostname);
+      kerberosPrincipalHostDAO.removeByHost(entity.getHostId());
 
       // publish the event
       HostRemovedEvent event = new HostRemovedEvent(hostname);

http://git-wip-us.apache.org/repos/asf/ambari/blob/0dd08215/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 6249d2a..c7866db 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
@@ -54,6 +54,7 @@ import com.google.inject.persist.Transactional;
  */
 public class UpgradeCatalog210 extends AbstractUpgradeCatalog {
   private static final String CLUSTERS_TABLE = "clusters";
+  private static final String CLUSTER_HOST_MAPPING_TABLE = "ClusterHostMapping";
   private static final String HOSTS_TABLE = "hosts";
   private static final String HOST_COMPONENT_DESIRED_STATE_TABLE = "hostcomponentdesiredstate";
   private static final String HOST_COMPONENT_STATE_TABLE = "hostcomponentstate";
@@ -63,8 +64,9 @@ public class UpgradeCatalog210 extends AbstractUpgradeCatalog {
   private static final String HOST_CONFIG_MAPPING_TABLE = "hostconfigmapping";
   private static final String CONFIG_GROUP_HOST_MAPPING_TABLE = "configgrouphostmapping";
   private static final String KERBEROS_PRINCIPAL_HOST_TABLE = "kerberos_principal_host";
+  private static final String KERBEROS_PRINCIPAL_TABLE = "kerberos_principal";
+  private static final String REQUEST_OPERATION_LEVEL_TABLE = "requestoperationlevel";
   private static final String SERVICE_CONFIG_HOSTS_TABLE = "serviceconfighosts";
-  private static final String CLUSTER_HOST_MAPPING_TABLE = "ClusterHostMapping";
   private static final String WIDGET_TABLE = "widget";
   private static final String WIDGET_LAYOUT_TABLE = "widget_layout";
   private static final String WIDGET_LAYOUT_USER_WIDGET_TABLE = "widget_layout_user_widget";
@@ -205,7 +207,10 @@ public class UpgradeCatalog210 extends AbstractUpgradeCatalog {
       dbAccessor.executeQuery("ALTER TABLE " + HOST_STATE_TABLE + " DROP CONSTRAINT FK_hoststate_host_name");
       dbAccessor.executeQuery("ALTER TABLE " + HOST_VERSION_TABLE + " DROP CONSTRAINT FK_host_version_host_name");
       dbAccessor.executeQuery("ALTER TABLE " + CONFIG_GROUP_HOST_MAPPING_TABLE + " DROP CONSTRAINT FK_cghm_hname");
+      // FK_krb_pr_host_hostname used to have a CASCADE DELETE, which is not needed.
       dbAccessor.executeQuery("ALTER TABLE " + KERBEROS_PRINCIPAL_HOST_TABLE + " DROP CONSTRAINT FK_krb_pr_host_hostname");
+      // FK_krb_pr_host_principalname used to have a CASCADE DELETE, which is not needed, so it will be recreated without it.
+      dbAccessor.executeQuery("ALTER TABLE " + KERBEROS_PRINCIPAL_HOST_TABLE + " DROP CONSTRAINT FK_krb_pr_host_principalname");
 
       // This FK name is actually different on Derby.
       dbAccessor.executeQuery("ALTER TABLE " + HOST_CONFIG_MAPPING_TABLE + " DROP CONSTRAINT FK_hostconfigmapping_host_name");
@@ -216,7 +221,10 @@ public class UpgradeCatalog210 extends AbstractUpgradeCatalog {
       dbAccessor.dropConstraint(HOST_STATE_TABLE, "FK_hoststate_host_name");
       dbAccessor.dropConstraint(HOST_VERSION_TABLE, "FK_host_version_host_name");
       dbAccessor.dropConstraint(CONFIG_GROUP_HOST_MAPPING_TABLE, "FK_cghm_hname");
+      // FK_krb_pr_host_hostname used to have a CASCADE DELETE, which is not needed.
       dbAccessor.dropConstraint(KERBEROS_PRINCIPAL_HOST_TABLE, "FK_krb_pr_host_hostname");
+      // FK_krb_pr_host_principalname used to have a CASCADE DELETE, which is not needed, so it will be recreated without it.
+      dbAccessor.executeQuery("ALTER TABLE " + KERBEROS_PRINCIPAL_HOST_TABLE + " DROP CONSTRAINT FK_krb_pr_host_principalname");
 
       dbAccessor.dropConstraint(HOST_CONFIG_MAPPING_TABLE, "FK_hostconfmapping_host_name");
     }
@@ -253,14 +261,7 @@ public class UpgradeCatalog210 extends AbstractUpgradeCatalog {
     dbAccessor.executeQuery("ALTER TABLE " + HOSTS_TABLE + " 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(KERBEROS_PRINCIPAL_HOST_TABLE, "FK_krb_pr_host_host_name",
-        "host_name", HOSTS_TABLE, "host_name", false);
-
-
     // Add host_id to the host-related tables, and populate the host_id, one table at a time.
-    // TODO, include other tables.
     String[] tablesToAddHostID = new String[] {
         CONFIG_GROUP_HOST_MAPPING_TABLE,
         CLUSTER_HOST_MAPPING_TABLE,
@@ -270,6 +271,8 @@ public class UpgradeCatalog210 extends AbstractUpgradeCatalog {
         HOST_ROLE_COMMAND_TABLE,
         HOST_STATE_TABLE,
         HOST_VERSION_TABLE,
+        KERBEROS_PRINCIPAL_HOST_TABLE,
+        REQUEST_OPERATION_LEVEL_TABLE,
         SERVICE_CONFIG_HOSTS_TABLE
     };
 
@@ -289,16 +292,18 @@ public class UpgradeCatalog210 extends AbstractUpgradeCatalog {
         }
       }
 
-      if (databaseType == Configuration.DatabaseType.DERBY) {
-        // This is a workaround for UpgradeTest.java unit test
-        dbAccessor.executeQuery("ALTER TABLE " + tableName + " ALTER column " + HOST_ID_COL + " NOT NULL");
-      } else {
-        dbAccessor.executeQuery("ALTER TABLE " + tableName + " ALTER column " + HOST_ID_COL + " SET NOT NULL");
+      // The one exception for setting NOT NULL is the requestoperationlevel table
+      if (tableName != REQUEST_OPERATION_LEVEL_TABLE) {
+        if (databaseType == Configuration.DatabaseType.DERBY) {
+          // This is a workaround for UpgradeTest.java unit test
+          dbAccessor.executeQuery("ALTER TABLE " + tableName + " ALTER column " + HOST_ID_COL + " NOT NULL");
+        } else {
+          dbAccessor.executeQuery("ALTER TABLE " + tableName + " ALTER column " + HOST_ID_COL + " SET NOT NULL");
+        }
       }
     }
 
     // These are the FKs that have already been corrected.
-    // TODO, include other tables.
     dbAccessor.addFKConstraint(CONFIG_GROUP_HOST_MAPPING_TABLE, "FK_cghm_host_id",
         "host_id", HOSTS_TABLE, "host_id", false);
     dbAccessor.addFKConstraint(CLUSTER_HOST_MAPPING_TABLE, "FK_clusterhostmapping_host_id",
@@ -311,13 +316,15 @@ public class UpgradeCatalog210 extends AbstractUpgradeCatalog {
         "host_id", HOSTS_TABLE, "host_id", false);
     dbAccessor.addFKConstraint(HOST_STATE_TABLE, "FK_hoststate_host_id",
         "host_id", HOSTS_TABLE, "host_id", false);
+    dbAccessor.addFKConstraint(KERBEROS_PRINCIPAL_HOST_TABLE, "FK_krb_pr_host_id",
+        "host_id", HOSTS_TABLE, "host_id", false);
+    dbAccessor.addFKConstraint(KERBEROS_PRINCIPAL_HOST_TABLE, "FK_krb_pr_host_principalname",
+        "principal_name", KERBEROS_PRINCIPAL_TABLE, "principal_name", false);
     dbAccessor.addFKConstraint(SERVICE_CONFIG_HOSTS_TABLE, "FK_scvhosts_host_id",
         "host_id", HOSTS_TABLE, "host_id", false);
 
 
-
     // For any tables where the host_name was part of the PK, need to drop the PK, and recreate it with the host_id
-    // TODO, include other tables.
     String[] tablesWithHostNameInPK =  new String[] {
         CONFIG_GROUP_HOST_MAPPING_TABLE,
         CLUSTER_HOST_MAPPING_TABLE,
@@ -325,6 +332,7 @@ public class UpgradeCatalog210 extends AbstractUpgradeCatalog {
         HOST_COMPONENT_STATE_TABLE,
         HOST_COMPONENT_DESIRED_STATE_TABLE,
         HOST_STATE_TABLE,
+        KERBEROS_PRINCIPAL_HOST_TABLE,
         SERVICE_CONFIG_HOSTS_TABLE
     };
 
@@ -342,8 +350,8 @@ public class UpgradeCatalog210 extends AbstractUpgradeCatalog {
       dbAccessor.executeQuery("ALTER TABLE " + HOST_COMPONENT_STATE_TABLE + " DROP CONSTRAINT hostcomponentstate_pkey");
       dbAccessor.executeQuery("ALTER TABLE " + HOST_COMPONENT_DESIRED_STATE_TABLE + " DROP CONSTRAINT hostcomponentdesiredstate_pkey");
       dbAccessor.executeQuery("ALTER TABLE " + HOST_STATE_TABLE + " DROP CONSTRAINT hoststate_pkey");
+      dbAccessor.executeQuery("ALTER TABLE " + KERBEROS_PRINCIPAL_HOST_TABLE + " DROP CONSTRAINT kerberos_principal_host_pkey");
       dbAccessor.executeQuery("ALTER TABLE " + SERVICE_CONFIG_HOSTS_TABLE + " DROP CONSTRAINT serviceconfighosts_pkey");
-      // TODO, include other tables.
     }
     dbAccessor.executeQuery("ALTER TABLE " + CONFIG_GROUP_HOST_MAPPING_TABLE +
         " ADD CONSTRAINT configgrouphostmapping_pkey PRIMARY KEY (config_group_id, host_id)");
@@ -357,9 +365,10 @@ public class UpgradeCatalog210 extends AbstractUpgradeCatalog {
         " ADD CONSTRAINT hostcomponentdesiredstate_pkey PRIMARY KEY (cluster_id, component_name, host_id, service_name)");
     dbAccessor.executeQuery("ALTER TABLE " + HOST_STATE_TABLE +
         " ADD CONSTRAINT hoststate_pkey PRIMARY KEY (host_id)");
+    dbAccessor.executeQuery("ALTER TABLE " + KERBEROS_PRINCIPAL_HOST_TABLE +
+        " ADD CONSTRAINT kerberos_principal_host_pkey PRIMARY KEY (principal_name, host_id)");
     dbAccessor.executeQuery("ALTER TABLE " + SERVICE_CONFIG_HOSTS_TABLE +
         " ADD CONSTRAINT serviceconfighosts_pkey PRIMARY KEY (service_config_id, host_id)");
-    // TODO, include other tables.
 
     // Finish by deleting the unnecessary host_name columns.
     dbAccessor.dropColumn(CONFIG_GROUP_HOST_MAPPING_TABLE, "host_name");
@@ -370,10 +379,11 @@ public class UpgradeCatalog210 extends AbstractUpgradeCatalog {
     dbAccessor.dropColumn(HOST_ROLE_COMMAND_TABLE, "host_name");
     dbAccessor.dropColumn(HOST_STATE_TABLE, "host_name");
     dbAccessor.dropColumn(HOST_VERSION_TABLE, "host_name");
+    dbAccessor.dropColumn(KERBEROS_PRINCIPAL_HOST_TABLE, "host_name");
+    dbAccessor.dropColumn(REQUEST_OPERATION_LEVEL_TABLE, "host_name");
 
     // Notice that the column name doesn't have an underscore here.
     dbAccessor.dropColumn(SERVICE_CONFIG_HOSTS_TABLE, "hostname");
-    // TODO, include other tables.
 
     // view columns for cluster association
     dbAccessor.addColumn(VIEW_INSTANCE_TABLE, new DBColumnInfo("cluster_handle", String.class, 255, null, true));

http://git-wip-us.apache.org/repos/asf/ambari/blob/0dd08215/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 1a146e0..d9e546f 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
@@ -26,9 +26,6 @@ delimiter ;
 
 # USE @schema;
 
--- DEVELOPER COMMENT
--- Ambari is transitioning to make the host_id the FK instead of the host_name.
--- Please do not remove lines that are related to this change and are being staged.
 
 CREATE TABLE stack(
   stack_id BIGINT NOT NULL,
@@ -294,8 +291,7 @@ CREATE TABLE requestoperationlevel (
   cluster_name VARCHAR(255),
   service_name VARCHAR(255),
   host_component_name VARCHAR(255),
-  host_name VARCHAR(255),
-  -- host_id BIGINT NOT NULL,
+  host_id BIGINT NOT NULL,
   PRIMARY KEY (operation_level_id));
 
 CREATE TABLE key_value_store (`key` VARCHAR(255),
@@ -674,18 +670,12 @@ CREATE TABLE kerberos_principal (
 
 CREATE TABLE kerberos_principal_host (
   principal_name VARCHAR(255) NOT NULL,
-  host_name VARCHAR(255) NOT NULL,
-  -- host_id BIGINT NOT NULL,
-  PRIMARY KEY(principal_name, host_name)
-  -- PRIMARY KEY(principal_name, host_id)
+  host_id BIGINT NOT NULL,
+  PRIMARY KEY(principal_name, host_id)
 );
 
-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 (host_id) ON DELETE CASCADE;
-
-ALTER TABLE kerberos_principal_host
-ADD CONSTRAINT FK_krb_pr_host_principalname
-FOREIGN KEY (principal_name) REFERENCES kerberos_principal (principal_name) ON DELETE CASCADE;
+ALTER TABLE kerberos_principal_host ADD CONSTRAINT FK_krb_pr_host_id FOREIGN KEY (host_id) REFERENCES hosts (host_id);
+ALTER TABLE kerberos_principal_host ADD CONSTRAINT FK_krb_pr_host_principalname FOREIGN KEY (principal_name) REFERENCES kerberos_principal (principal_name);
 -- Kerberos (end)
 
 -- Alerting Framework

http://git-wip-us.apache.org/repos/asf/ambari/blob/0dd08215/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 bc6bd32..37aaf7d 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
@@ -16,10 +16,6 @@
 -- limitations under the License.
 --
 
--- DEVELOPER COMMENT
--- Ambari is transitioning to make the host_id the FK instead of the host_name.
--- Please do not remove lines that are related to this change and are being staged.
-
 ------create tables---------
 CREATE TABLE stack(
   stack_id NUMBER(19) NOT NULL,
@@ -285,8 +281,7 @@ CREATE TABLE requestoperationlevel (
   cluster_name VARCHAR2(255),
   service_name VARCHAR2(255),
   host_component_name VARCHAR2(255),
-  host_name VARCHAR2(255),
-  --host_id NUMBER(19) NOT NULL,
+  host_id NUMBER(19) NOT NULL,
   PRIMARY KEY (operation_level_id));
 
 CREATE TABLE key_value_store (
@@ -665,20 +660,12 @@ CREATE TABLE kerberos_principal (
 
 CREATE TABLE kerberos_principal_host (
   principal_name VARCHAR2(255) NOT NULL,
-  host_name VARCHAR2(255) NOT NULL,
-  --host_id NUMBER(19) NOT NULL,
-  PRIMARY KEY(principal_name, host_name)
-  --PRIMARY KEY(principal_name, host_id)
+  host_id NUMBER(19) NOT NULL,
+  PRIMARY KEY(principal_name, host_id)
 );
 
-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 (host_id) ON DELETE CASCADE;
-
-ALTER TABLE kerberos_principal_host
-ADD CONSTRAINT FK_krb_pr_host_principalname
-FOREIGN KEY (principal_name) REFERENCES kerberos_principal (principal_name) ON DELETE CASCADE;
+ALTER TABLE kerberos_principal_host ADD CONSTRAINT FK_krb_pr_host_id FOREIGN KEY (host_id) REFERENCES hosts (host_id);
+ALTER TABLE kerberos_principal_host ADD CONSTRAINT FK_krb_pr_host_principalname FOREIGN KEY (principal_name) REFERENCES kerberos_principal (principal_name);
 -- Kerberos (end)
 
 -- Alerting Framework

http://git-wip-us.apache.org/repos/asf/ambari/blob/0dd08215/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 f2a016f..c3f8c1c 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
@@ -297,8 +297,7 @@ CREATE TABLE requestoperationlevel (
   cluster_name VARCHAR(255),
   service_name VARCHAR(255),
   host_component_name VARCHAR(255),
-  host_name VARCHAR(255),
-  --host_id BIGINT NOT NULL,
+  host_id BIGINT NOT NULL,
   PRIMARY KEY (operation_level_id));
 
 CREATE TABLE ClusterHostMapping (
@@ -667,20 +666,12 @@ CREATE TABLE kerberos_principal (
 
 CREATE TABLE kerberos_principal_host (
   principal_name VARCHAR(255) NOT NULL,
-  host_name VARCHAR(255) NOT NULL,
-  --host_id BIGINT NOT NULL,
-  PRIMARY KEY(principal_name, host_name)
-  --PRIMARY KEY(principal_name, host_id)
+  host_id BIGINT NOT NULL,
+  PRIMARY KEY(principal_name, host_id)
 );
 
-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 (host_id) ON DELETE CASCADE;
-
-ALTER TABLE kerberos_principal_host
-ADD CONSTRAINT FK_krb_pr_host_principalname
-FOREIGN KEY (principal_name) REFERENCES kerberos_principal (principal_name) ON DELETE CASCADE;
+ALTER TABLE kerberos_principal_host ADD CONSTRAINT FK_krb_pr_host_id FOREIGN KEY (host_id) REFERENCES hosts (host_id);
+ALTER TABLE kerberos_principal_host ADD CONSTRAINT FK_krb_pr_host_principalname FOREIGN KEY (principal_name) REFERENCES kerberos_principal (principal_name);
 -- Kerberos (end)
 
 -- Alerting Framework

http://git-wip-us.apache.org/repos/asf/ambari/blob/0dd08215/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 38a241d..0d6d24d 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
@@ -334,8 +334,7 @@ CREATE TABLE ambari.requestoperationlevel (
   cluster_name VARCHAR(255),
   service_name VARCHAR(255),
   host_component_name VARCHAR(255),
-  host_name VARCHAR(255),
-  --host_id BIGINT NOT NULL,
+  host_id BIGINT NOT NULL,
   PRIMARY KEY (operation_level_id));
 GRANT ALL PRIVILEGES ON TABLE ambari.requestoperationlevel TO :username;
 
@@ -741,21 +740,13 @@ GRANT ALL PRIVILEGES ON TABLE ambari.kerberos_principal TO :username;
 
 CREATE TABLE ambari.kerberos_principal_host (
   principal_name VARCHAR(255) NOT NULL,
-  host_name VARCHAR(255) NOT NULL,
-  --host_id BIGINT NOT NULL,
-  PRIMARY KEY(principal_name, host_name)
-  --PRIMARY KEY(principal_name, host_id)
+  host_id BIGINT NOT NULL,
+  PRIMARY KEY(principal_name, host_id)
 );
 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 (host_id) ON DELETE CASCADE;
-
-ALTER TABLE ambari.kerberos_principal_host
-ADD CONSTRAINT FK_krb_pr_host_principalname
-FOREIGN KEY (principal_name) REFERENCES ambari.kerberos_principal (principal_name) 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);
+ALTER TABLE ambari.kerberos_principal_host ADD CONSTRAINT FK_krb_pr_host_principalname FOREIGN KEY (principal_name) REFERENCES ambari.kerberos_principal (principal_name);
 -- Kerberos (end)
 
 -- Alerting Framework

http://git-wip-us.apache.org/repos/asf/ambari/blob/0dd08215/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 30959d0..f5433f1 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql
@@ -328,7 +328,7 @@ CREATE TABLE requestoperationlevel (
   cluster_name VARCHAR(255),
   service_name VARCHAR(255),
   host_component_name VARCHAR(255),
-  host_name VARCHAR(255),
+  host_id BIGINT NOT NULL,
   PRIMARY KEY CLUSTERED (operation_level_id)
   );
   
@@ -784,20 +784,12 @@ CREATE TABLE kerberos_principal (
 
 CREATE TABLE kerberos_principal_host (
   principal_name VARCHAR(255) NOT NULL,
-  host_name VARCHAR(255) NOT NULL,
-  --host_id BIGINT NOT NULL,
-  PRIMARY KEY CLUSTERED (principal_name, host_name)
-  --PRIMARY KEY CLUSTERED (principal_name, host_id)
+  host_id BIGINT NOT NULL,
+  PRIMARY KEY CLUSTERED (principal_name, host_id)
 );
 
-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 (host_id) ON DELETE CASCADE;
-
-ALTER TABLE kerberos_principal_host
-ADD CONSTRAINT FK_krb_pr_host_principalname
-FOREIGN KEY (principal_name) REFERENCES kerberos_principal (principal_name) ON DELETE CASCADE;
+ALTER TABLE kerberos_principal_host ADD CONSTRAINT FK_krb_pr_host_id FOREIGN KEY (host_id) REFERENCES hosts (host_id);
+ALTER TABLE kerberos_principal_host ADD CONSTRAINT FK_krb_pr_host_principalname FOREIGN KEY (principal_name) REFERENCES kerberos_principal (principal_name);
 -- Kerberos (end)
 
 -- Alerting Framework

http://git-wip-us.apache.org/repos/asf/ambari/blob/0dd08215/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 714b6b7..d150d76 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
@@ -243,18 +243,31 @@ public class UpgradeCatalog210Test {
 
       // Column Capture section
       // Hosts
+      Capture<DBAccessor.DBColumnInfo> clusterHostMappingColumnCapture = new Capture<DBAccessor.DBColumnInfo>();
+      Capture<DBAccessor.DBColumnInfo> configGroupHostMappingColumnCapture = new Capture<DBAccessor.DBColumnInfo>();
+      Capture<DBAccessor.DBColumnInfo> hostConfigMappingColumnCapture = new Capture<DBAccessor.DBColumnInfo>();
       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> hostRoleCommandColumnCapture = new Capture<DBAccessor.DBColumnInfo>();
       Capture<DBAccessor.DBColumnInfo> hostStateColumnCapture = new Capture<DBAccessor.DBColumnInfo>();
-      Capture<DBAccessor.DBColumnInfo> clusterHostMappingColumnCapture = new Capture<DBAccessor.DBColumnInfo>();
+      Capture<DBAccessor.DBColumnInfo> hostVersionColumnCapture = new Capture<DBAccessor.DBColumnInfo>();
+      Capture<DBAccessor.DBColumnInfo> kerberosPrincipalHostColumnCapture = new Capture<DBAccessor.DBColumnInfo>();
+      Capture<DBAccessor.DBColumnInfo> requestOperationLevelColumnCapture = new Capture<DBAccessor.DBColumnInfo>();
+      Capture<DBAccessor.DBColumnInfo> serviceConfigHostsColumnCapture = new Capture<DBAccessor.DBColumnInfo>();
 
-      // TODO, include other tables.
+      captures.put("ClusterHostMapping", clusterHostMappingColumnCapture);
+      captures.put("configgrouphostmapping", configGroupHostMappingColumnCapture);
+      captures.put("hostconfigmapping", hostConfigMappingColumnCapture);
       captures.put("hosts", hostsColumnCapture);
       captures.put("hostcomponentstate", hostComponentStateColumnCapture);
       captures.put("hostcomponentdesiredstate", hostComponentDesiredStateColumnCapture);
+      captures.put("host_role_command", hostRoleCommandColumnCapture);
       captures.put("hoststate", hostStateColumnCapture);
-      captures.put("ClusterHostMapping", clusterHostMappingColumnCapture);
+      captures.put("host_version", hostVersionColumnCapture);
+      captures.put("kerberos_principal_host", kerberosPrincipalHostColumnCapture);
+      captures.put("requestoperationlevel", requestOperationLevelColumnCapture);
+      captures.put("serviceconfighosts", serviceConfigHostsColumnCapture);
     }
 
     /**
@@ -263,11 +276,18 @@ public class UpgradeCatalog210Test {
     @Override
     public void execute(DBAccessor dbAccessor) throws SQLException {
       // Add columns and alter table section
+      dbAccessor.addColumn(eq("ClusterHostMapping"), capture(captures.get("ClusterHostMapping")));
+      dbAccessor.addColumn(eq("configgrouphostmapping"), capture(captures.get("configgrouphostmapping")));
+      dbAccessor.addColumn(eq("hostconfigmapping"), capture(captures.get("hostconfigmapping")));
       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("host_role_command"), capture(captures.get("host_role_command")));
       dbAccessor.addColumn(eq("hoststate"), capture(captures.get("hoststate")));
-      dbAccessor.addColumn(eq("ClusterHostMapping"), capture(captures.get("ClusterHostMapping")));
+      dbAccessor.addColumn(eq("host_version"), capture(captures.get("host_version")));
+      dbAccessor.addColumn(eq("kerberos_principal_host"), capture(captures.get("kerberos_principal_host")));
+      dbAccessor.addColumn(eq("requestoperationlevel"), capture(captures.get("requestoperationlevel")));
+      dbAccessor.addColumn(eq("serviceconfighosts"), capture(captures.get("serviceconfighosts")));
     }
 
     /**


Mime
View raw message