AMBARI-12538. Attempting to access the Ambari Dashboard results in an HTTP 500 
Error after changing cluster name and restarting the Ambari server (aonishuk)


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

Branch: refs/heads/trunk
Commit: 37f8c88f205b196fb02324169f5f55650af0d568
Parents: 0963334
Author: Andrew Onishuk <aonis...@hortonworks.com>
Authored: Wed Sep 9 16:54:43 2015 +0300
Committer: Andrew Onishuk <aonis...@hortonworks.com>
Committed: Wed Sep 9 16:54:43 2015 +0300

----------------------------------------------------------------------
 .../controller/internal/BaseClusterRequest.java | 17 ++---
 .../internal/ClusterResourceProvider.java       |  2 +-
 .../internal/ExportBlueprintRequest.java        |  9 ++-
 .../internal/HostResourceProvider.java          |  2 +-
 .../internal/ProvisionClusterRequest.java       | 22 ++++++
 .../internal/ScaleClusterRequest.java           | 22 ++++++
 .../server/orm/dao/TopologyRequestDAO.java      |  6 +-
 .../orm/entities/TopologyRequestEntity.java     | 14 ++--
 .../ambari/server/topology/AmbariContext.java   | 58 ++++++++++------
 .../topology/ClusterConfigurationRequest.java   | 13 +++-
 .../ambari/server/topology/ClusterTopology.java | 14 ++--
 .../server/topology/ClusterTopologyImpl.java    | 35 +++++++---
 .../ambari/server/topology/HostRequest.java     | 17 ++---
 .../ambari/server/topology/LogicalRequest.java  | 10 ++-
 .../server/topology/PersistedStateImpl.java     | 16 ++---
 .../ambari/server/topology/TopologyManager.java | 42 +++++++-----
 .../ambari/server/topology/TopologyRequest.java |  6 +-
 .../server/topology/TopologyRequestFactory.java |  4 +-
 .../topology/TopologyRequestFactoryImpl.java    |  2 +-
 .../server/upgrade/UpgradeCatalog212.java       | 71 ++++++++++++++++++++
 .../main/resources/Ambari-DDL-MySQL-CREATE.sql  |  3 +-
 .../main/resources/Ambari-DDL-Oracle-CREATE.sql |  3 +-
 .../resources/Ambari-DDL-Postgres-CREATE.sql    |  3 +-
 .../Ambari-DDL-Postgres-EMBEDDED-CREATE.sql     |  3 +-
 .../resources/Ambari-DDL-SQLAnywhere-CREATE.sql |  3 +-
 .../resources/Ambari-DDL-SQLServer-CREATE.sql   |  3 +-
 .../BlueprintConfigurationProcessorTest.java    |  2 +-
 .../internal/ClusterResourceProviderTest.java   |  2 +-
 .../internal/ExportBlueprintRequestTest.java    |  2 +
 .../internal/ProvisionClusterRequestTest.java   |  6 +-
 .../internal/ScaleClusterRequestTest.java       | 12 ++--
 .../orm/dao/TopologyLogicalRequestDAOTest.java  |  4 +-
 .../server/orm/dao/TopologyRequestDAOTest.java  |  8 +--
 .../server/topology/AmbariContextTest.java      | 17 +++--
 .../topology/ClusterTopologyImplTest.java       |  7 +-
 .../server/topology/TopologyManagerTest.java    | 12 ++--
 .../server/upgrade/UpgradeCatalog212Test.java   | 47 +++++++++++++
 37 files changed, 374 insertions(+), 145 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/37f8c88f/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/BaseClusterRequest.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/BaseClusterRequest.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/BaseClusterRequest.java
index 7f6a634..22bffe6 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/BaseClusterRequest.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/BaseClusterRequest.java
@@ -46,9 +46,9 @@ public abstract class BaseClusterRequest implements 
TopologyRequest {
   protected final Map<String, HostGroupInfo> hostGroupInfoMap = new 
HashMap<String, HostGroupInfo>();
 
   /**
-   * cluster name
+   * cluster id
    */
-  protected String clusterName;
+  protected Long clusterId;
 
   /**
    * blueprint
@@ -86,8 +86,8 @@ public abstract class BaseClusterRequest implements 
TopologyRequest {
   }
 
   @Override
-  public String getClusterName() {
-    return clusterName;
+  public Long getClusterId() {
+    return clusterId;
   }
 
   @Override
@@ -138,15 +138,6 @@ public abstract class BaseClusterRequest implements 
TopologyRequest {
   }
 
   /**
-   * Set the request cluster name.
-   *
-   * @param clusterName  cluster name
-   */
-  protected void setClusterName(String clusterName) {
-    this.clusterName = clusterName;
-  }
-
-  /**
    * Set the request blueprint.
    *
    * @param blueprint blueprint

http://git-wip-us.apache.org/repos/asf/ambari/blob/37f8c88f/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterResourceProvider.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterResourceProvider.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterResourceProvider.java
index 812aa5d..7e75a75 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterResourceProvider.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterResourceProvider.java
@@ -463,7 +463,7 @@ public class ClusterResourceProvider extends 
AbstractControllerResourceProvider
     LOG.info("Creating Cluster '" + properties.get(CLUSTER_NAME_PROPERTY_ID) +
         "' based on blueprint '" + 
String.valueOf(properties.get(BLUEPRINT_PROPERTY_ID)) + "'.");
 
-    TopologyRequest createClusterRequest;
+    ProvisionClusterRequest createClusterRequest;
     try {
       createClusterRequest = 
topologyRequestFactory.createProvisionClusterRequest(properties);
     } catch (InvalidTopologyTemplateException e) {

http://git-wip-us.apache.org/repos/asf/ambari/blob/37f8c88f/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ExportBlueprintRequest.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ExportBlueprintRequest.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ExportBlueprintRequest.java
index 8b13826..c80ae2c 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ExportBlueprintRequest.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ExportBlueprintRequest.java
@@ -59,6 +59,7 @@ public class ExportBlueprintRequest implements 
TopologyRequest {
   private static AmbariManagementController controller = 
AmbariServer.getController();
 
   private String clusterName;
+  private Long clusterId;
   private Blueprint blueprint;
   private Configuration configuration;
   //todo: Should this map be represented by a new class?
@@ -69,6 +70,8 @@ public class ExportBlueprintRequest implements 
TopologyRequest {
     Resource clusterResource = clusterNode.getObject();
     clusterName = String.valueOf(clusterResource.getPropertyValue(
         ClusterResourceProvider.CLUSTER_NAME_PROPERTY_ID));
+    clusterId = Long.valueOf(String.valueOf(clusterResource.getPropertyValue(
+            ClusterResourceProvider.CLUSTER_ID_PROPERTY_ID)));
 
 
     createConfiguration(clusterNode);
@@ -80,12 +83,16 @@ public class ExportBlueprintRequest implements 
TopologyRequest {
     createBlueprint(exportedHostGroups, parseStack(clusterResource));
   }
 
-  @Override
   public String getClusterName() {
     return clusterName;
   }
 
   @Override
+  public Long getClusterId() {
+    return clusterId;
+  }
+
+  @Override
   public Type getType() {
     return Type.EXPORT;
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/37f8c88f/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostResourceProvider.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostResourceProvider.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostResourceProvider.java
index c7f0e9b..39d4040 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostResourceProvider.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/HostResourceProvider.java
@@ -854,7 +854,7 @@ public class HostResourceProvider extends 
AbstractControllerResourceProvider {
   //todo: for api/v1/hosts we also end up here so we need to ensure proper 400 
response
   //todo: since a user shouldn't be posing to that endpoint
   private RequestStatusResponse submitHostRequests(Request request) throws 
SystemException {
-    TopologyRequest requestRequest;
+    ScaleClusterRequest requestRequest;
     try {
       requestRequest = new ScaleClusterRequest(request.getProperties());
     } catch (InvalidTopologyTemplateException e) {

http://git-wip-us.apache.org/repos/asf/ambari/blob/37f8c88f/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ProvisionClusterRequest.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ProvisionClusterRequest.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ProvisionClusterRequest.java
index 0150141..4a906b1 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ProvisionClusterRequest.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ProvisionClusterRequest.java
@@ -85,6 +85,11 @@ public class ProvisionClusterRequest extends 
BaseClusterRequest {
   private static ConfigurationFactory configurationFactory = new 
ConfigurationFactory();
 
   /**
+   * cluster name
+   */
+  private String clusterName;
+
+  /**
    * default password
    */
   private String defaultPassword;
@@ -120,6 +125,23 @@ public class ProvisionClusterRequest extends 
BaseClusterRequest {
     parseHostGroupInfo(properties);
   }
 
+  public String getClusterName() {
+    return clusterName;
+  }
+
+  public void setClusterName(String clusterName) {
+    this.clusterName = clusterName;
+  }
+
+  @Override
+  public Long getClusterId() {
+    return clusterId;
+  }
+
+  public void setClusterId(Long clusterId) {
+    this.clusterId = clusterId;
+  }
+
   @Override
   public Type getType() {
     return Type.PROVISION;

http://git-wip-us.apache.org/repos/asf/ambari/blob/37f8c88f/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ScaleClusterRequest.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ScaleClusterRequest.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ScaleClusterRequest.java
index a6995ed..d784f1d 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ScaleClusterRequest.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ScaleClusterRequest.java
@@ -38,6 +38,11 @@ import java.util.Set;
 public class ScaleClusterRequest extends BaseClusterRequest {
 
   /**
+   * cluster name
+   */
+  private String clusterName;
+
+  /**
    * Constructor.
    *
    * @param propertySet  set of request properties
@@ -58,6 +63,23 @@ public class ScaleClusterRequest extends BaseClusterRequest {
     }
   }
 
+  public String getClusterName() {
+    return clusterName;
+  }
+
+  public void setClusterName(String clusterName) {
+    this.clusterName = clusterName;
+  }
+
+  @Override
+  public Long getClusterId() {
+    return clusterId;
+  }
+
+  public void setClusterId(Long clusterId) {
+    this.clusterId = clusterId;
+  }
+
   @Override
   public Type getType() {
     return Type.SCALE;

http://git-wip-us.apache.org/repos/asf/ambari/blob/37f8c88f/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/TopologyRequestDAO.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/TopologyRequestDAO.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/TopologyRequestDAO.java
index b58129d..65cd59f 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/TopologyRequestDAO.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/TopologyRequestDAO.java
@@ -41,11 +41,11 @@ public class TopologyRequestDAO {
   }
 
   @RequiresSession
-  public List<TopologyRequestEntity> findByCluster(String clusterName) {
+  public List<TopologyRequestEntity> findByClusterId(long clusterId) {
     TypedQuery<TopologyRequestEntity> query = entityManagerProvider.get()
-      .createNamedQuery("TopologyRequestEntity.findByCluster", 
TopologyRequestEntity.class);
+      .createNamedQuery("TopologyRequestEntity.findByClusterId", 
TopologyRequestEntity.class);
 
-    query.setParameter("clusterName", clusterName);
+    query.setParameter("clusterId", clusterId);
     return daoUtils.selectList(query);
   }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/37f8c88f/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/TopologyRequestEntity.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/TopologyRequestEntity.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/TopologyRequestEntity.java
index 8535ed8..923ff9c 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/TopologyRequestEntity.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/TopologyRequestEntity.java
@@ -40,7 +40,7 @@ import java.util.Collection;
                 pkColumnName = "sequence_name", valueColumnName = 
"sequence_value",
                 pkColumnValue = "topology_request_id_seq", initialValue = 0)
 @NamedQueries({
-  @NamedQuery(name = "TopologyRequestEntity.findByCluster", query = "SELECT 
req FROM TopologyRequestEntity req WHERE req.clusterName = :clusterName")
+  @NamedQuery(name = "TopologyRequestEntity.findByClusterId", query = "SELECT 
req FROM TopologyRequestEntity req WHERE req.clusterId = :clusterId")
 })
 public class TopologyRequestEntity {
   @Id
@@ -51,8 +51,8 @@ public class TopologyRequestEntity {
   @Column(name = "action", length = 255, nullable = false)
   private String action;
 
-  @Column(name = "cluster_name", length = 100, nullable = false)
-  private String clusterName;
+  @Column(name = "cluster_id", nullable = true)
+  private Long clusterId;
 
   @Column(name = "bp_name", length = 100, nullable = false)
   private String blueprintName;
@@ -92,12 +92,12 @@ public class TopologyRequestEntity {
     this.action = action;
   }
 
-  public String getClusterName() {
-    return clusterName;
+  public Long getClusterId() {
+    return clusterId;
   }
 
-  public void setClusterName(String clusterName) {
-    this.clusterName = clusterName;
+  public void setClusterId(Long clusterId) {
+    this.clusterId = clusterId;
   }
 
   public String getBlueprintName() {

http://git-wip-us.apache.org/repos/asf/ambari/blob/37f8c88f/ambari-server/src/main/java/org/apache/ambari/server/topology/AmbariContext.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/topology/AmbariContext.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/topology/AmbariContext.java
index 40717cc..0cf3bf2 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/topology/AmbariContext.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/topology/AmbariContext.java
@@ -89,12 +89,12 @@ public class AmbariContext {
 
   private final static Logger LOG = 
LoggerFactory.getLogger(AmbariContext.class);
 
-  public boolean isClusterKerberosEnabled(String clusterName) {
+  public boolean isClusterKerberosEnabled(long clusterId) {
     Cluster cluster;
     try {
-      cluster = getController().getClusters().getCluster(clusterName);
+      cluster = getController().getClusters().getClusterById(clusterId);
     } catch (AmbariException e) {
-      throw new RuntimeException("Parent Cluster resource doesn't exist.  
clusterName= " + clusterName);
+      throw new RuntimeException("Parent Cluster resource doesn't exist.  
clusterId= " + clusterId);
     }
     return cluster.getSecurityType() == SecurityType.KERBEROS;
   }
@@ -136,11 +136,10 @@ public class AmbariContext {
     return getController().getActionManager().getTaskById(id);
   }
 
-  public void createAmbariResources(ClusterTopology topology) {
-    String clusterName = topology.getClusterName();
+  public void createAmbariResources(ClusterTopology topology, String 
clusterName) {
     Stack stack = topology.getBlueprint().getStack();
     createAmbariClusterResource(clusterName, stack.getName(), 
stack.getVersion());
-    createAmbariServiceAndComponentResources(topology);
+    createAmbariServiceAndComponentResources(topology, clusterName);
   }
 
   public void createAmbariClusterResource(String clusterName, String 
stackName, String stackVersion) {
@@ -154,8 +153,7 @@ public class AmbariContext {
     }
   }
 
-  public void createAmbariServiceAndComponentResources(ClusterTopology 
topology) {
-    String clusterName = topology.getClusterName();
+  public void createAmbariServiceAndComponentResources(ClusterTopology 
topology, String clusterName) {
     Collection<String> services = topology.getBlueprint().getServices();
 
     try {
@@ -200,7 +198,7 @@ public class AmbariContext {
     }
   }
 
-  public void createAmbariHostResources(String clusterName, String hostName, 
Map<String, Collection<String>> components) {
+  public void createAmbariHostResources(long  clusterId, String hostName, 
Map<String, Collection<String>> components) {
     Host host;
     try {
       host = getController().getClusters().getHost(hostName);
@@ -210,6 +208,14 @@ public class AmbariContext {
           "Unable to obtain host instance '%s' when persisting host 
resources", hostName));
     }
 
+    String clusterName = null;
+    try {
+      clusterName = getClusterName(clusterId);
+    } catch (AmbariException e) {
+      LOG.error("Cannot get cluster name for clusterId = " + clusterId, e);
+      throw new RuntimeException(e);
+    }
+
     Map<String, Object> properties = new HashMap<String, Object>();
     properties.put(HostResourceProvider.HOST_CLUSTER_NAME_PROPERTY_ID, 
clusterName);
     properties.put(HostResourceProvider.HOST_NAME_PROPERTY_ID, hostName);
@@ -250,12 +256,12 @@ public class AmbariContext {
    */
   //todo: do once for all configs
   public void convertGlobalProperties(ClusterTopology topology,
-                                      Map<String, Map<String, String>> 
blueprintConfigurations) {
+                                      Map<String, Map<String, String>> 
blueprintConfigurations) throws AmbariException {
 
     Stack stack = topology.getBlueprint().getStack();
     StackId stackId = new StackId(stack.getName(), stack.getVersion());
     getController().getConfigHelper().moveDeprecatedGlobals(
-        stackId, blueprintConfigurations, topology.getClusterName());
+        stackId, blueprintConfigurations, 
getClusterName(topology.getClusterId()));
   }
 
   public Long getNextRequestId() {
@@ -387,10 +393,10 @@ public class AmbariContext {
     }
   }
 
-  public boolean doesConfigurationWithTagExist(String clusterName, String tag) 
{
+  public boolean doesConfigurationWithTagExist(long clusterId, String tag) {
     boolean isTopologyResolved = false;
     try {
-      Cluster cluster = getController().getClusters().getCluster(clusterName);
+      Cluster cluster = 
getController().getClusters().getClusterById(clusterId);
       Collection<DesiredConfig> desiredConfigs = 
cluster.getDesiredConfigs().values();
       for (DesiredConfig config : desiredConfigs) {
         if (config.getTag().equals(tag)) {
@@ -400,10 +406,10 @@ public class AmbariContext {
       }
     } catch (ClusterNotFoundException e) {
       LOG.info("Attempted to determine if configuration is topology resolved 
for a non-existent cluster: {}",
-          clusterName);
+              clusterId);
     } catch (AmbariException e) {
       throw new RuntimeException(
-          "Unable to determine if cluster config is topology resolved due to 
unknown error: " + e, e);
+              "Unable to determine if cluster config is topology resolved due 
to unknown error: " + e, e);
     }
 
     return isTopologyResolved;
@@ -413,10 +419,10 @@ public class AmbariContext {
     return persistedState;
   }
 
-  public boolean isHostRegisteredWithCluster(String cluster, String host) {
+  public boolean isHostRegisteredWithCluster(long clusterId, String host) {
     boolean found = false;
     try {
-      Collection<Host> hosts = 
getController().getClusters().getCluster(cluster).getHosts();
+      Collection<Host> hosts = 
getController().getClusters().getClusterById(clusterId).getHosts();
       for (Host h : hosts) {
         if (h.getHostName().equals(host)) {
           found = true;
@@ -424,11 +430,19 @@ public class AmbariContext {
         }
       }
     } catch (AmbariException e) {
-      throw new RuntimeException(String.format("Unable to get hosts for 
cluster '%s': %s", cluster, e), e);
+      throw new RuntimeException(String.format("Unable to get hosts for 
cluster ID = %s: %s", clusterId, e), e);
     }
     return found;
   }
 
+  public long getClusterId(String clusterName) throws AmbariException {
+    return 
getController().getClusters().getCluster(clusterName).getClusterId();
+  }
+
+  public String getClusterName(long clusterId) throws AmbariException {
+    return 
getController().getClusters().getClusterById(clusterId).getClusterName();
+  }
+
   /**
    * Add the new host to an existing config group.
    */
@@ -438,10 +452,10 @@ public class AmbariContext {
     Cluster cluster;
     try {
       clusters = getController().getClusters();
-      cluster = clusters.getCluster(topology.getClusterName());
+      cluster = clusters.getClusterById(topology.getClusterId());
     } catch (AmbariException e) {
       throw new RuntimeException(String.format(
-          "Attempt to add hosts to a non-existent cluster: '%s'", 
topology.getClusterName()));
+          "Attempt to add hosts to a non-existent cluster: '%s'", 
topology.getClusterId()));
     }
     // I don't know of a method to get config group by name
     //todo: add a method to get config group by name
@@ -472,7 +486,7 @@ public class AmbariContext {
    * For each host group with configuration specified in the blueprint, a 
config group is created
    * and the hosts associated with the host group are assigned to the config 
group.
    */
-  private void createConfigGroupsAndRegisterHost(ClusterTopology topology, 
String groupName) {
+  private void createConfigGroupsAndRegisterHost(ClusterTopology topology, 
String groupName) throws AmbariException {
     Map<String, Map<String, Config>> groupConfigs = new HashMap<String, 
Map<String, Config>>();
     Stack stack = topology.getBlueprint().getStack();
 
@@ -515,7 +529,7 @@ public class AmbariContext {
           get(groupName).getHostNames();
 
       ConfigGroupRequest request = new ConfigGroupRequest(
-          null, topology.getClusterName(), absoluteGroupName, service, "Host 
Group Configuration",
+          null, getClusterName(topology.getClusterId()), absoluteGroupName, 
service, "Host Group Configuration",
           new HashSet<String>(groupHosts), serviceConfigs);
 
       // get the config group provider and create config group resource

http://git-wip-us.apache.org/repos/asf/ambari/blob/37f8c88f/ambari-server/src/main/java/org/apache/ambari/server/topology/ClusterConfigurationRequest.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/topology/ClusterConfigurationRequest.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/topology/ClusterConfigurationRequest.java
index b9f2eb8..1ebde17 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/topology/ClusterConfigurationRequest.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/topology/ClusterConfigurationRequest.java
@@ -137,7 +137,14 @@ public class ClusterConfigurationRequest {
    * @param configurationRequests a list of requests to send to the 
AmbariManagementController.
    */
   private void setConfigurationsOnCluster(List<BlueprintServiceConfigRequest> 
configurationRequests,
-                                          String tag, Set<String> 
updatedConfigTypes)  {
+                                         String tag, Set<String> 
updatedConfigTypes)  {
+    String clusterName = null;
+    try {
+      clusterName = 
ambariContext.getClusterName(clusterTopology.getClusterId());
+    } catch (AmbariException e) {
+      LOG.error("Cannot get cluster name for clusterId = " + 
clusterTopology.getClusterId(), e);
+      throw new RuntimeException(e);
+    }
     // iterate over services to deploy
     for (BlueprintServiceConfigRequest blueprintConfigRequest : 
configurationRequests) {
       ClusterRequest clusterRequest = null;
@@ -145,7 +152,7 @@ public class ClusterConfigurationRequest {
       List<ConfigurationRequest> requestsPerService = new 
LinkedList<ConfigurationRequest>();
       for (BlueprintServiceConfigElement blueprintElement : 
blueprintConfigRequest.getConfigElements()) {
         Map<String, Object> clusterProperties = new HashMap<String, Object>();
-        
clusterProperties.put(ClusterResourceProvider.CLUSTER_NAME_PROPERTY_ID, 
clusterTopology.getClusterName());
+        
clusterProperties.put(ClusterResourceProvider.CLUSTER_NAME_PROPERTY_ID, 
clusterName);
         
clusterProperties.put(ClusterResourceProvider.CLUSTER_DESIRED_CONFIGS_PROPERTY_ID
 + "/type", blueprintElement.getTypeName());
         
clusterProperties.put(ClusterResourceProvider.CLUSTER_DESIRED_CONFIGS_PROPERTY_ID
 + "/tag", tag);
         for (Map.Entry<String, String> entry : 
blueprintElement.getConfiguration().entrySet()) {
@@ -206,7 +213,7 @@ public class ClusterConfigurationRequest {
       // if this is a request to resolve config, then wait until resolution is 
completed
       try {
         // wait until the cluster topology configuration is set/resolved
-        
ambariContext.waitForConfigurationResolution(clusterTopology.getClusterName(), 
updatedConfigTypes);
+        ambariContext.waitForConfigurationResolution(clusterName, 
updatedConfigTypes);
       } catch (AmbariException e) {
         LOG.error("Error while attempting to wait for the cluster 
configuration to reach TOPOLOGY_RESOLVED state.", e);
       }

http://git-wip-us.apache.org/repos/asf/ambari/blob/37f8c88f/ambari-server/src/main/java/org/apache/ambari/server/topology/ClusterTopology.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/topology/ClusterTopology.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/topology/ClusterTopology.java
index 9a9929b..284a913 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/topology/ClusterTopology.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/topology/ClusterTopology.java
@@ -19,7 +19,6 @@
 package org.apache.ambari.server.topology;
 
 import org.apache.ambari.server.controller.RequestStatusResponse;
-import org.apache.ambari.server.state.SecurityType;
 
 import java.util.Collection;
 import java.util.Map;
@@ -31,11 +30,18 @@ import java.util.Map;
 public interface ClusterTopology {
 
   /**
-   * Get the name of the cluster.
+   * Get the id of the cluster.
    *
-   * @return cluster name
+   * @return cluster id
    */
-  public String getClusterName();
+  public Long getClusterId();
+
+  /**
+   * Set the id of the cluster.
+   *
+   * @param clusterId cluster id
+   */
+  public void setClusterId(Long clusterId);
 
   /**
    * Get the blueprint associated with the cluster.

http://git-wip-us.apache.org/repos/asf/ambari/blob/37f8c88f/ambari-server/src/main/java/org/apache/ambari/server/topology/ClusterTopologyImpl.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/topology/ClusterTopologyImpl.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/topology/ClusterTopologyImpl.java
index 9dbd197..5b716ae 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/topology/ClusterTopologyImpl.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/topology/ClusterTopologyImpl.java
@@ -19,6 +19,7 @@
 
 package org.apache.ambari.server.topology;
 
+import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.controller.RequestStatusResponse;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -37,7 +38,8 @@ import java.util.Set;
  */
 public class ClusterTopologyImpl implements ClusterTopology {
 
-  private String clusterName;
+  private Long clusterId;
+
   //todo: currently topology is only associated with a single bp
   //todo: this will need to change to allow usage of multiple bp's for the 
same cluster
   //todo: for example: provision using bp1 and scale using bp2
@@ -52,7 +54,7 @@ public class ClusterTopologyImpl implements ClusterTopology {
   //todo: will need to convert all usages of hostgroup name to use fully 
qualified name (BP/HG)
   //todo: for now, restrict scaling to the same BP
   public ClusterTopologyImpl(AmbariContext ambariContext, TopologyRequest 
topologyRequest) throws InvalidTopologyException {
-    this.clusterName = topologyRequest.getClusterName();
+    this.clusterId = topologyRequest.getClusterId();
     // provision cluster currently requires that all hostgroups have same BP 
so it is ok to use root level BP here
     this.blueprint = topologyRequest.getBlueprint();
     this.configuration = topologyRequest.getConfiguration();
@@ -65,13 +67,13 @@ public class ClusterTopologyImpl implements ClusterTopology 
{
 
   //todo: only used in tests, remove.  Validators not invoked when this 
constructor is used.
   public ClusterTopologyImpl(AmbariContext ambariContext,
-                             String clusterName,
+                             Long clusterId,
                              Blueprint blueprint,
                              Configuration configuration,
                              Map<String, HostGroupInfo> hostGroupInfo)
                                 throws InvalidTopologyException {
 
-    this.clusterName = clusterName;
+    this.clusterId = clusterId;
     this.blueprint = blueprint;
     this.configuration = configuration;
 
@@ -85,8 +87,13 @@ public class ClusterTopologyImpl implements ClusterTopology {
   }
 
   @Override
-  public String getClusterName() {
-    return clusterName;
+  public Long getClusterId() {
+    return clusterId;
+  }
+
+  @Override
+  public void setClusterId(Long clusterId) {
+    this.clusterId = clusterId;
   }
 
   @Override
@@ -203,17 +210,27 @@ public class ClusterTopologyImpl implements 
ClusterTopology {
 
   @Override
   public boolean isClusterKerberosEnabled() {
-    return ambariContext.isClusterKerberosEnabled(getClusterName());
+    return ambariContext.isClusterKerberosEnabled(getClusterId());
   }
 
   @Override
   public RequestStatusResponse installHost(String hostName) {
-    return ambariContext.installHost(hostName, getClusterName());
+    try {
+      return ambariContext.installHost(hostName, 
ambariContext.getClusterName(getClusterId()));
+    } catch (AmbariException e) {
+      LOG.error("Cannot get cluster name for clusterId = " + getClusterId(), 
e);
+      throw new RuntimeException(e);
+    }
   }
 
   @Override
   public RequestStatusResponse startHost(String hostName) {
-    return ambariContext.startHost(hostName, getClusterName());
+    try {
+      return ambariContext.startHost(hostName, 
ambariContext.getClusterName(getClusterId()));
+    } catch (AmbariException e) {
+      LOG.error("Cannot get cluster name for clusterId = " + getClusterId(), 
e);
+      throw new RuntimeException(e);
+    }
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/ambari/blob/37f8c88f/ambari-server/src/main/java/org/apache/ambari/server/topology/HostRequest.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/topology/HostRequest.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/topology/HostRequest.java
index cc82a63..518cbaf 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/topology/HostRequest.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/topology/HostRequest.java
@@ -25,6 +25,7 @@ import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.actionmanager.HostRoleCommand;
 import org.apache.ambari.server.api.predicate.InvalidQueryException;
 import org.apache.ambari.server.api.predicate.PredicateCompiler;
@@ -56,7 +57,7 @@ public class HostRequest implements Comparable<HostRequest> {
   private String hostgroupName;
   private Predicate predicate;
   private String hostname = null;
-  private String cluster;
+  private long clusterId;
   private boolean containsMaster;
   private final long id;
   private boolean isOutstanding = true;
@@ -74,11 +75,11 @@ public class HostRequest implements Comparable<HostRequest> 
{
 
   private static PredicateCompiler predicateCompiler = new PredicateCompiler();
 
-  public HostRequest(long requestId, long id, String cluster, String hostname, 
String blueprintName,
+  public HostRequest(long requestId, long id, long clusterId, String hostname, 
String blueprintName,
                      HostGroup hostGroup, Predicate predicate, ClusterTopology 
topology) {
     this.requestId = requestId;
     this.id = id;
-    this.cluster = cluster;
+    this.clusterId = clusterId;
     blueprint = blueprintName;
     this.hostGroup = hostGroup;
     hostgroupName = hostGroup.getName();
@@ -105,7 +106,7 @@ public class HostRequest implements Comparable<HostRequest> 
{
 
     this.requestId = requestId;
     this.id = id;
-    cluster = topology.getClusterName();
+    clusterId = topology.getClusterId();
     blueprint = topology.getBlueprint().getName();
     hostgroupName = entity.getTopologyHostGroupEntity().getName();
     hostGroup = topology.getBlueprint().getHostGroup(hostgroupName);
@@ -118,7 +119,7 @@ public class HostRequest implements Comparable<HostRequest> 
{
 
     //todo: we may be able to simplify by just checking hostname
     isOutstanding = hostname == null || !topology.getAmbariContext().
-        isHostRegisteredWithCluster(cluster, hostname);
+        isHostRegisteredWithCluster(clusterId, hostname);
 
     LOG.info("HostRequest: Successfully recovered host request for host: " +
         (hostname == null ? "Host Assignment Pending" : hostname));
@@ -147,8 +148,8 @@ public class HostRequest implements Comparable<HostRequest> 
{
     return requestId;
   }
 
-  public String getClusterName() {
-    return cluster;
+  public long getClusterId() {
+    return clusterId;
   }
   public String getBlueprint() {
     return blueprint;
@@ -428,7 +429,7 @@ public class HostRequest implements Comparable<HostRequest> 
{
       for (String service : group.getServices()) {
         serviceComponents.put(service, new HashSet<String> 
(group.getComponents(service)));
       }
-      ambariContext.createAmbariHostResources(getClusterName(), getHostName(), 
serviceComponents);
+      ambariContext.createAmbariHostResources(getClusterId(), getHostName(), 
serviceComponents);
     }
   }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/37f8c88f/ambari-server/src/main/java/org/apache/ambari/server/topology/LogicalRequest.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/topology/LogicalRequest.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/topology/LogicalRequest.java
index 34f8262..f29e0f4 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/topology/LogicalRequest.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/topology/LogicalRequest.java
@@ -69,8 +69,7 @@ public class LogicalRequest extends Request {
       throws AmbariException {
 
     //todo: abstract usage of controller, etc ...
-    super(id, getController().getClusters().getCluster(
-        request.getClusterName()).getClusterId(), 
getController().getClusters());
+    super(id, topology.getClusterId(), getController().getClusters());
 
     setRequestContext(String.format("Logical Request: %s", 
request.getDescription()));
 
@@ -82,8 +81,7 @@ public class LogicalRequest extends Request {
                         TopologyLogicalRequestEntity requestEntity) throws 
AmbariException {
 
     //todo: abstract usage of controller, etc ...
-    super(id, getController().getClusters().getCluster(
-        request.getClusterName()).getClusterId(), 
getController().getClusters());
+    super(id, topology.getClusterId(), getController().getClusters());
 
     setRequestContext(String.format("Logical Request: %s", 
request.getDescription()));
 
@@ -313,14 +311,14 @@ public class LogicalRequest extends Request {
         if (! hostnames.isEmpty()) {
           // host names are specified
           String hostname = hostnames.get(i);
-          HostRequest hostRequest = new HostRequest(getRequestId(), 
hostIdCounter.getAndIncrement(), getClusterName(),
+          HostRequest hostRequest = new HostRequest(getRequestId(), 
hostIdCounter.getAndIncrement(), getClusterId(),
               hostname, blueprint.getName(), 
blueprint.getHostGroup(groupName), null, topology);
           synchronized (requestsWithReservedHosts) {
             requestsWithReservedHosts.put(hostname, hostRequest);
           }
         } else {
           // host count is specified
-          HostRequest hostRequest = new HostRequest(getRequestId(), 
hostIdCounter.getAndIncrement(), getClusterName(),
+          HostRequest hostRequest = new HostRequest(getRequestId(), 
hostIdCounter.getAndIncrement(), getClusterId(),
               null, blueprint.getName(), blueprint.getHostGroup(groupName), 
hostGroupInfo.getPredicate(), topology);
           outstandingHostRequests.add(hostRequest);
         }

http://git-wip-us.apache.org/repos/asf/ambari/blob/37f8c88f/ambari-server/src/main/java/org/apache/ambari/server/topology/PersistedStateImpl.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/topology/PersistedStateImpl.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/topology/PersistedStateImpl.java
index 894bc6d..e0caa18 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/topology/PersistedStateImpl.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/topology/PersistedStateImpl.java
@@ -131,14 +131,14 @@ public class PersistedStateImpl implements PersistedState 
{
     Map<ClusterTopology, List<LogicalRequest>> allRequests = new 
HashMap<ClusterTopology, List<LogicalRequest>>();
     Collection<TopologyRequestEntity> entities = topologyRequestDAO.findAll();
 
-    Map<String, ClusterTopology> topologyRequests = new HashMap<String, 
ClusterTopology>();
+    Map<Long, ClusterTopology> topologyRequests = new HashMap<Long, 
ClusterTopology>();
     for (TopologyRequestEntity entity : entities) {
       TopologyRequest replayedRequest = new ReplayedTopologyRequest(entity);
-      ClusterTopology clusterTopology = 
topologyRequests.get(replayedRequest.getClusterName());
+      ClusterTopology clusterTopology = 
topologyRequests.get(replayedRequest.getClusterId());
       if (clusterTopology == null) {
         try {
           clusterTopology = new ClusterTopologyImpl(ambariContext, 
replayedRequest);
-          topologyRequests.put(replayedRequest.getClusterName(), 
clusterTopology);
+          topologyRequests.put(replayedRequest.getClusterId(), 
clusterTopology);
           allRequests.put(clusterTopology, new ArrayList<LogicalRequest>());
         } catch (InvalidTopologyException e) {
           throw new RuntimeException("Failed to construct cluster topology 
while replaying request: " + e, e);
@@ -183,7 +183,7 @@ public class PersistedStateImpl implements PersistedState {
     }
 
     
entity.setClusterAttributes(attributesAsString(request.getConfiguration().getAttributes()));
-    entity.setClusterName(request.getClusterName());
+    entity.setClusterId(request.getClusterId());
     
entity.setClusterProperties(propertiesAsString(request.getConfiguration().getProperties()));
     entity.setDescription(request.getDescription());
 
@@ -299,7 +299,7 @@ public class PersistedStateImpl implements PersistedState {
   }
 
   private static class ReplayedTopologyRequest implements TopologyRequest {
-    private final String clusterName;
+    private final Long clusterId;
     private final Type type;
     private final String description;
     private final Blueprint blueprint;
@@ -307,7 +307,7 @@ public class PersistedStateImpl implements PersistedState {
     private final Map<String, HostGroupInfo> hostGroupInfoMap = new 
HashMap<String, HostGroupInfo>();
 
     public ReplayedTopologyRequest(TopologyRequestEntity entity) {
-      clusterName = entity.getClusterName();
+      clusterId = entity.getClusterId();
       type = Type.valueOf(entity.getAction());
       description = entity.getDescription();
 
@@ -323,8 +323,8 @@ public class PersistedStateImpl implements PersistedState {
     }
 
     @Override
-    public String getClusterName() {
-      return clusterName;
+    public Long getClusterId() {
+      return clusterId;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/ambari/blob/37f8c88f/ambari-server/src/main/java/org/apache/ambari/server/topology/TopologyManager.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/topology/TopologyManager.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/topology/TopologyManager.java
index 5f3bb9d..64be609 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/topology/TopologyManager.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/topology/TopologyManager.java
@@ -34,6 +34,8 @@ import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.actionmanager.HostRoleCommand;
 import org.apache.ambari.server.actionmanager.Request;
 import org.apache.ambari.server.controller.RequestStatusResponse;
+import org.apache.ambari.server.controller.internal.ProvisionClusterRequest;
+import org.apache.ambari.server.controller.internal.ScaleClusterRequest;
 import org.apache.ambari.server.controller.internal.Stack;
 import org.apache.ambari.server.orm.dao.HostRoleCommandStatusSummaryDTO;
 import org.apache.ambari.server.orm.entities.StageEntity;
@@ -62,7 +64,7 @@ public class TopologyManager {
   // priority is given to oldest outstanding requests
   private final Collection<LogicalRequest> outstandingRequests = new 
ArrayList<LogicalRequest>();
   //todo: currently only support a single cluster
-  private Map<String, ClusterTopology> clusterTopologyMap = new 
HashMap<String, ClusterTopology>();
+  private Map<Long, ClusterTopology> clusterTopologyMap = new HashMap<Long, 
ClusterTopology>();
 
   //todo: inject
   private static LogicalRequestFactory logicalRequestFactory = new 
LogicalRequestFactory();
@@ -95,18 +97,23 @@ public class TopologyManager {
     }
   }
 
-  public RequestStatusResponse provisionCluster(TopologyRequest request) 
throws InvalidTopologyException, AmbariException {
+  public RequestStatusResponse provisionCluster(ProvisionClusterRequest 
request) throws InvalidTopologyException, AmbariException {
     ensureInitialized();
     ClusterTopology topology = new ClusterTopologyImpl(ambariContext, request);
-    // persist request after it has successfully validated
-    PersistedTopologyRequest persistedRequest = 
persistedState.persistTopologyRequest(request);
+    String clusterName = request.getClusterName();
 
     // get the id prior to creating ambari resources which increments the 
counter
     Long provisionId = ambariContext.getNextRequestId();
-    ambariContext.createAmbariResources(topology);
+    ambariContext.createAmbariResources(topology, clusterName);
+
+    long clusterId = ambariContext.getClusterId(clusterName);
+    topology.setClusterId(clusterId);
+    request.setClusterId(clusterId);
+    // persist request after it has successfully validated
+    PersistedTopologyRequest persistedRequest = 
persistedState.persistTopologyRequest(request);
 
-    String clusterName = topology.getClusterName();
-    clusterTopologyMap.put(clusterName, topology);
+
+    clusterTopologyMap.put(clusterId, topology);
 
     addClusterConfigRequest(topology, new 
ClusterConfigurationRequest(ambariContext, topology, true));
     LogicalRequest logicalRequest = processRequest(persistedRequest, topology, 
provisionId);
@@ -118,13 +125,14 @@ public class TopologyManager {
     return getRequestStatus(logicalRequest.getRequestId());
   }
 
-  public RequestStatusResponse scaleHosts(TopologyRequest request)
+  public RequestStatusResponse scaleHosts(ScaleClusterRequest request)
       throws InvalidTopologyException, AmbariException {
 
     ensureInitialized();
     LOG.info("TopologyManager.scaleHosts: Entering");
     String clusterName = request.getClusterName();
-    ClusterTopology topology = clusterTopologyMap.get(clusterName);
+    long clusterId = ambariContext.getClusterId(clusterName);
+    ClusterTopology topology = clusterTopologyMap.get(clusterId);
     if (topology == null) {
       throw new InvalidTopologyException("Unable to retrieve cluster topology 
for cluster. This is most likely a " +
                                          "result of trying to scale a cluster 
via the API which was created using " +
@@ -132,7 +140,7 @@ public class TopologyManager {
                                          "blueprint can be scaled with this 
API.  If the cluster was originally created " +
                                          "via the API as described above, 
please file a Jira for this matter.");
     }
-
+    request.setClusterId(clusterId);
     PersistedTopologyRequest persistedRequest = 
persistedState.persistTopologyRequest(request);
     // this registers/updates all request host groups
     topology.update(request);
@@ -162,7 +170,7 @@ public class TopologyManager {
           }
 
           LOG.info("TopologyManager.onHostRegistered: processing accepted host 
offer for reserved host = {}", hostName);
-          
processAcceptedHostOffer(getClusterTopology(request.getClusterName()), 
response, host);
+          processAcceptedHostOffer(getClusterTopology(request.getClusterId()), 
response, host);
           matchedToRequest = true;
         }
       }
@@ -178,7 +186,7 @@ public class TopologyManager {
               case ACCEPTED:
                 matchedToRequest = true;
                 LOG.info("TopologyManager.onHostRegistered: processing 
accepted host offer for matched host = {}", hostName);
-                
processAcceptedHostOffer(getClusterTopology(request.getClusterName()), 
hostOfferResponse, host);
+                
processAcceptedHostOffer(getClusterTopology(request.getClusterId()), 
hostOfferResponse, host);
                 break;
               case DECLINED_DONE:
                 LOG.info("TopologyManager.onHostRegistered: DECLINED_DONE 
received for host = {}", hostName);
@@ -284,9 +292,9 @@ public class TopologyManager {
     return requestStatusResponses;
   }
 
-  public ClusterTopology getClusterTopology(String clusterName) {
+  public ClusterTopology getClusterTopology(Long clusterId) {
     ensureInitialized();
-    return clusterTopologyMap.get(clusterName);
+    return clusterTopologyMap.get(clusterId);
   }
 
   public Map<String, Collection<String>> getProjectedTopology() {
@@ -355,7 +363,7 @@ public class TopologyManager {
             hostIterator.remove();
             LOG.info("TopologyManager.processRequest: host name = {} was 
ACCEPTED by LogicalRequest ID = {} , host has been removed from available 
hosts.",
               host.getHostName(), logicalRequest.getRequestId());
-            
processAcceptedHostOffer(getClusterTopology(logicalRequest.getClusterName()), 
response, host);
+            
processAcceptedHostOffer(getClusterTopology(logicalRequest.getClusterId()), 
response, host);
             break;
           case DECLINED_DONE:
             requestHostComplete = true;
@@ -432,7 +440,7 @@ public class TopologyManager {
     boolean configChecked = false;
     for (Map.Entry<ClusterTopology, List<LogicalRequest>> requestEntry : 
persistedRequests.entrySet()) {
       ClusterTopology topology = requestEntry.getKey();
-      clusterTopologyMap.put(topology.getClusterName(), topology);
+      clusterTopologyMap.put(topology.getClusterId(), topology);
 
       for (LogicalRequest logicalRequest : requestEntry.getValue()) {
         allRequests.put(logicalRequest.getRequestId(), logicalRequest);
@@ -460,7 +468,7 @@ public class TopologyManager {
 
       if (! configChecked) {
         configChecked = true;
-        if (! 
ambariContext.doesConfigurationWithTagExist(topology.getClusterName(), 
TOPOLOGY_RESOLVED_TAG)) {
+        if (! 
ambariContext.doesConfigurationWithTagExist(topology.getClusterId(), 
TOPOLOGY_RESOLVED_TAG)) {
           LOG.info("TopologyManager.replayRequests: no config with 
TOPOLOGY_RESOLVED found, adding cluster config request");
           addClusterConfigRequest(topology, new 
ClusterConfigurationRequest(ambariContext, topology, false));
         }

http://git-wip-us.apache.org/repos/asf/ambari/blob/37f8c88f/ambari-server/src/main/java/org/apache/ambari/server/topology/TopologyRequest.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/topology/TopologyRequest.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/topology/TopologyRequest.java
index d102c21..516ea14 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/topology/TopologyRequest.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/topology/TopologyRequest.java
@@ -31,11 +31,11 @@ public interface TopologyRequest {
   public enum Type { PROVISION, SCALE, EXPORT }
 
   /**
-   * Get the cluster name associated with the request.
+   * Get the cluster id associated with the request. Can be <code>null</code>.
    *
-   * @return associated cluster name
+   * @return associated cluster id
    */
-  public String getClusterName();
+  public Long getClusterId();
 
   /**
    * Get the request type.

http://git-wip-us.apache.org/repos/asf/ambari/blob/37f8c88f/ambari-server/src/main/java/org/apache/ambari/server/topology/TopologyRequestFactory.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/topology/TopologyRequestFactory.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/topology/TopologyRequestFactory.java
index 284fbba..da0c9e1 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/topology/TopologyRequestFactory.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/topology/TopologyRequestFactory.java
@@ -19,12 +19,14 @@
 
 package org.apache.ambari.server.topology;
 
+import org.apache.ambari.server.controller.internal.ProvisionClusterRequest;
+
 import java.util.Map;
 
 /**
  * Factory for creating topology requests.
  */
 public interface TopologyRequestFactory {
-  public TopologyRequest createProvisionClusterRequest(Map<String, Object> 
properties) throws InvalidTopologyTemplateException;
+  public ProvisionClusterRequest createProvisionClusterRequest(Map<String, 
Object> properties) throws InvalidTopologyTemplateException;
   // todo: use to create other request types
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/37f8c88f/ambari-server/src/main/java/org/apache/ambari/server/topology/TopologyRequestFactoryImpl.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/topology/TopologyRequestFactoryImpl.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/topology/TopologyRequestFactoryImpl.java
index 7c6a8ce..8b23b44 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/topology/TopologyRequestFactoryImpl.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/topology/TopologyRequestFactoryImpl.java
@@ -28,7 +28,7 @@ import java.util.Map;
  */
 public class TopologyRequestFactoryImpl implements TopologyRequestFactory {
   @Override
-  public TopologyRequest createProvisionClusterRequest(Map<String, Object> 
properties) throws InvalidTopologyTemplateException {
+  public ProvisionClusterRequest createProvisionClusterRequest(Map<String, 
Object> properties) throws InvalidTopologyTemplateException {
     return new ProvisionClusterRequest(properties);
   }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/37f8c88f/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog212.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog212.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog212.java
index 0b3d75c..b97a7f4 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog212.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog212.java
@@ -37,6 +37,10 @@ import org.apache.ambari.server.utils.VersionUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.Statement;
+
 import com.google.inject.Inject;
 import com.google.inject.Injector;
 
@@ -51,6 +55,13 @@ public class UpgradeCatalog212 extends 
AbstractUpgradeCatalog {
   private static final String HBASE_SITE = "hbase-site";
   private static final String CLUSTER_ENV = "cluster-env";
 
+  private static final String TOPOLOGY_REQUEST_TABLE = "topology_request";
+  private static final String CLUSTERS_TABLE = "clusters";
+  private static final String CLUSTERS_TABLE_CLUSTER_ID_COLUMN = "cluster_id";
+  private static final String TOPOLOGY_REQUEST_CLUSTER_NAME_COLUMN = 
"cluster_name";
+  private static final String TOPOLOGY_REQUEST_CLUSTER_ID_COLUMN = 
"cluster_id";
+  private static final String TOPOLOGY_REQUEST_CLUSTER_ID_FK_CONSTRAINT_NAME = 
"FK_topology_request_cluster_id";
+
   private static final String HOST_ROLE_COMMAND_TABLE = "host_role_command";
   private static final String HOST_ROLE_COMMAND_SKIP_COLUMN = 
"auto_skip_on_failure";
 
@@ -101,14 +112,34 @@ public class UpgradeCatalog212 extends 
AbstractUpgradeCatalog {
    */
   @Override
   protected void executeDDLUpdates() throws AmbariException, SQLException {
+    executeTopologyDDLUpdates();
     executeHostRoleCommandDDLUpdates();
   }
 
+  private void executeTopologyDDLUpdates() throws AmbariException, 
SQLException {
+    dbAccessor.addColumn(TOPOLOGY_REQUEST_TABLE, new 
DBColumnInfo(TOPOLOGY_REQUEST_CLUSTER_ID_COLUMN,
+        Long.class, null, null, true));
+    // TOPOLOGY_REQUEST_CLUSTER_NAME_COLUMN will be deleted in PreDML. We need 
a cluster name to set cluster id.
+    // dbAccessor.dropColumn(TOPOLOGY_REQUEST_TABLE, 
TOPOLOGY_REQUEST_CLUSTER_NAME_COLUMN);
+    // dbAccessor.setColumnNullable(TOPOLOGY_REQUEST_TABLE, 
TOPOLOGY_REQUEST_CLUSTER_ID_COLUMN, false);
+    // dbAccessor.addFKConstraint(TOPOLOGY_REQUEST_TABLE, 
TOPOLOGY_REQUEST_CLUSTER_ID_FK_CONSTRAINT_NAME,
+    //     TOPOLOGY_REQUEST_CLUSTER_ID_COLUMN, CLUSTERS_TABLE, 
CLUSTERS_TABLE_CLUSTER_ID_COLUMN, false);
+  }
+
   /**
    * {@inheritDoc}
    */
   @Override
   protected void executePreDMLUpdates() throws AmbariException, SQLException {
+    addClusterIdToTopology();
+    finilizeTopologyDDL();
+  }
+
+  protected void finilizeTopologyDDL() throws AmbariException, SQLException {
+    dbAccessor.dropColumn(TOPOLOGY_REQUEST_TABLE, 
TOPOLOGY_REQUEST_CLUSTER_NAME_COLUMN);
+    dbAccessor.setColumnNullable(TOPOLOGY_REQUEST_TABLE, 
TOPOLOGY_REQUEST_CLUSTER_ID_COLUMN, false);
+    dbAccessor.addFKConstraint(TOPOLOGY_REQUEST_TABLE, 
TOPOLOGY_REQUEST_CLUSTER_ID_FK_CONSTRAINT_NAME,
+        TOPOLOGY_REQUEST_CLUSTER_ID_COLUMN, CLUSTERS_TABLE, 
CLUSTERS_TABLE_CLUSTER_ID_COLUMN, false);
   }
 
   /**
@@ -120,6 +151,46 @@ public class UpgradeCatalog212 extends 
AbstractUpgradeCatalog {
     addMissingConfigs();
   }
 
+  protected void addClusterIdToTopology() throws AmbariException, SQLException 
{
+    Map<String, Long> clusterNameIdMap = new HashMap<String, Long>();
+    try (Statement statement = dbAccessor.getConnection().createStatement();
+         ResultSet rs = statement.executeQuery("SELECT DISTINCT cluster_name, 
cluster_id FROM clusters");
+    ) {
+      while (rs.next()) {
+        long clusterId = rs.getLong("cluster_id");
+        String clusterName = rs.getString("cluster_name");
+        clusterNameIdMap.put(clusterName, clusterId);
+      }
+    }
+
+    for (String clusterName : clusterNameIdMap.keySet()) {
+      try (PreparedStatement preparedStatement = 
dbAccessor.getConnection().prepareStatement("UPDATE topology_request " +
+          "SET cluster_id=? WHERE cluster_name=?");
+      ) {
+        preparedStatement.setLong(1, clusterNameIdMap.get(clusterName));
+        preparedStatement.setString(2, clusterName);
+        preparedStatement.executeUpdate();
+      }
+    }
+
+    // Set cluster id for all null values.
+    // Useful if cluster was renamed and cluster name does not match.
+    if (clusterNameIdMap.entrySet().size() >= 1) {
+      try (PreparedStatement preparedStatement = 
dbAccessor.getConnection().prepareStatement("UPDATE topology_request " +
+          "SET cluster_id=? WHERE cluster_id IS NULL");
+      ) {
+        preparedStatement.setLong(1, 
clusterNameIdMap.entrySet().iterator().next().getValue());
+        preparedStatement.executeUpdate();
+      }
+    }
+    if (clusterNameIdMap.entrySet().size() == 0) {
+      LOG.warn("Cluster not found. topology_request.cluster_id is not set");
+    }
+    if (clusterNameIdMap.entrySet().size() > 1) {
+      LOG.warn("Found more than one cluster. topology_request.cluster_id can 
be incorrect if you have renamed the cluster.");
+    }
+  }
+
   protected void addMissingConfigs() throws AmbariException {
     updateHiveConfigs();
     updateHbaseAndClusterConfigurations();

http://git-wip-us.apache.org/repos/asf/ambari/blob/37f8c88f/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 70623d8..1511385 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
@@ -589,7 +589,7 @@ CREATE TABLE artifact (
 CREATE TABLE topology_request (
   id BIGINT NOT NULL,
   action VARCHAR(255) NOT NULL,
-  cluster_name VARCHAR(100) NOT NULL,
+  cluster_id BIGINT NOT NULL,
   bp_name VARCHAR(100) NOT NULL,
   cluster_properties LONGTEXT,
   cluster_attributes LONGTEXT,
@@ -725,6 +725,7 @@ ALTER TABLE groups ADD CONSTRAINT FK_groups_principal_id 
FOREIGN KEY (principal_
 ALTER TABLE clusters ADD CONSTRAINT FK_clusters_resource_id FOREIGN KEY 
(resource_id) REFERENCES adminresource(resource_id);
 ALTER TABLE widget_layout_user_widget ADD CONSTRAINT FK_widget_layout_id 
FOREIGN KEY (widget_layout_id) REFERENCES widget_layout(id);
 ALTER TABLE widget_layout_user_widget ADD CONSTRAINT FK_widget_id FOREIGN KEY 
(widget_id) REFERENCES widget(id);
+ALTER TABLE topology_request ADD CONSTRAINT FK_topology_request_cluster_id 
FOREIGN KEY (cluster_id) REFERENCES clusters(cluster_id);
 ALTER TABLE topology_hostgroup ADD CONSTRAINT FK_hostgroup_req_id FOREIGN KEY 
(request_id) REFERENCES topology_request(id);
 ALTER TABLE topology_host_info ADD CONSTRAINT FK_hostinfo_group_id FOREIGN KEY 
(group_id) REFERENCES topology_hostgroup(id);
 ALTER TABLE topology_logical_request ADD CONSTRAINT FK_logicalreq_req_id 
FOREIGN KEY (request_id) REFERENCES topology_request(id);

http://git-wip-us.apache.org/repos/asf/ambari/blob/37f8c88f/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 0cedeb7..a3c1625 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
@@ -578,7 +578,7 @@ CREATE TABLE artifact (
 CREATE TABLE topology_request (
   id NUMBER(19) NOT NULL,
   action VARCHAR(255) NOT NULL,
-  cluster_name VARCHAR(100) NOT NULL,
+  cluster_id NUMBER(19) NOT NULL,
   bp_name VARCHAR(100) NOT NULL,
   cluster_properties CLOB,
   cluster_attributes CLOB,
@@ -714,6 +714,7 @@ ALTER TABLE groups ADD CONSTRAINT FK_groups_principal_id 
FOREIGN KEY (principal_
 ALTER TABLE clusters ADD CONSTRAINT FK_clusters_resource_id FOREIGN KEY 
(resource_id) REFERENCES adminresource(resource_id);
 ALTER TABLE widget_layout_user_widget ADD CONSTRAINT FK_widget_layout_id 
FOREIGN KEY (widget_layout_id) REFERENCES widget_layout(id);
 ALTER TABLE widget_layout_user_widget ADD CONSTRAINT FK_widget_id FOREIGN KEY 
(widget_id) REFERENCES widget(id);
+ALTER TABLE topology_request ADD CONSTRAINT FK_topology_request_cluster_id 
FOREIGN KEY (cluster_id) REFERENCES clusters(cluster_id);
 ALTER TABLE topology_hostgroup ADD CONSTRAINT FK_hostgroup_req_id FOREIGN KEY 
(request_id) REFERENCES topology_request(id);
 ALTER TABLE topology_host_info ADD CONSTRAINT FK_hostinfo_group_id FOREIGN KEY 
(group_id) REFERENCES topology_hostgroup(id);
 ALTER TABLE topology_logical_request ADD CONSTRAINT FK_logicalreq_req_id 
FOREIGN KEY (request_id) REFERENCES topology_request(id);

http://git-wip-us.apache.org/repos/asf/ambari/blob/37f8c88f/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 b070bff..2636eef 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
@@ -583,7 +583,7 @@ CREATE TABLE artifact (
 CREATE TABLE topology_request (
   id BIGINT NOT NULL,
   action VARCHAR(255) NOT NULL,
-  cluster_name VARCHAR(100) NOT NULL,
+  cluster_id BIGINT NOT NULL,
   bp_name VARCHAR(100) NOT NULL,
   cluster_properties TEXT,
   cluster_attributes TEXT,
@@ -716,6 +716,7 @@ ALTER TABLE serviceconfighosts ADD CONSTRAINT 
FK_scvhosts_host_id FOREIGN KEY (h
 ALTER TABLE clusters ADD CONSTRAINT FK_clusters_resource_id FOREIGN KEY 
(resource_id) REFERENCES adminresource(resource_id);
 ALTER TABLE widget_layout_user_widget ADD CONSTRAINT FK_widget_layout_id 
FOREIGN KEY (widget_layout_id) REFERENCES widget_layout(id);
 ALTER TABLE widget_layout_user_widget ADD CONSTRAINT FK_widget_id FOREIGN KEY 
(widget_id) REFERENCES widget(id);
+ALTER TABLE topology_request ADD CONSTRAINT FK_topology_request_cluster_id 
FOREIGN KEY (cluster_id) REFERENCES clusters(cluster_id);
 ALTER TABLE topology_hostgroup ADD CONSTRAINT FK_hostgroup_req_id FOREIGN KEY 
(request_id) REFERENCES topology_request(id);
 ALTER TABLE topology_host_info ADD CONSTRAINT FK_hostinfo_group_id FOREIGN KEY 
(group_id) REFERENCES topology_hostgroup(id);
 ALTER TABLE topology_logical_request ADD CONSTRAINT FK_logicalreq_req_id 
FOREIGN KEY (request_id) REFERENCES topology_request(id);

http://git-wip-us.apache.org/repos/asf/ambari/blob/37f8c88f/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 0af584e..d515fa6 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
@@ -655,7 +655,7 @@ GRANT ALL PRIVILEGES ON TABLE 
ambari.widget_layout_user_widget TO :username;
 CREATE TABLE ambari.topology_request (
   id BIGINT NOT NULL,
   action VARCHAR(255) NOT NULL,
-  cluster_name VARCHAR(100) NOT NULL,
+  cluster_id BIGINT NOT NULL,
   bp_name VARCHAR(100) NOT NULL,
   cluster_properties TEXT,
   cluster_attributes TEXT,
@@ -795,6 +795,7 @@ ALTER TABLE ambari.groups ADD CONSTRAINT 
FK_groups_principal_id FOREIGN KEY (pri
 ALTER TABLE ambari.clusters ADD CONSTRAINT FK_clusters_resource_id FOREIGN KEY 
(resource_id) REFERENCES ambari.adminresource(resource_id);
 ALTER TABLE ambari.widget_layout_user_widget ADD CONSTRAINT 
FK_widget_layout_id FOREIGN KEY (widget_layout_id) REFERENCES 
ambari.widget_layout(id);
 ALTER TABLE ambari.widget_layout_user_widget ADD CONSTRAINT FK_widget_id 
FOREIGN KEY (widget_id) REFERENCES ambari.widget(id);
+ALTER TABLE ambari.topology_request ADD CONSTRAINT 
FK_topology_request_cluster_id FOREIGN KEY (cluster_id) REFERENCES 
ambari.clusters(cluster_id);
 ALTER TABLE ambari.topology_hostgroup ADD CONSTRAINT FK_hostgroup_req_id 
FOREIGN KEY (request_id) REFERENCES ambari.topology_request(id);
 ALTER TABLE ambari.topology_host_info ADD CONSTRAINT FK_hostinfo_group_id 
FOREIGN KEY (group_id) REFERENCES ambari.topology_hostgroup(id);
 ALTER TABLE ambari.topology_logical_request ADD CONSTRAINT 
FK_logicalreq_req_id FOREIGN KEY (request_id) REFERENCES 
ambari.topology_request(id);

http://git-wip-us.apache.org/repos/asf/ambari/blob/37f8c88f/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql 
b/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql
index 3142471..807ccd5 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql
@@ -578,7 +578,7 @@ CREATE TABLE artifact (
 CREATE TABLE topology_request (
   id NUMERIC(19) NOT NULL,
   action VARCHAR(255) NOT NULL,
-  cluster_name VARCHAR(100) NOT NULL,
+  cluster_id NUMERIC(19) NOT NULL,
   bp_name VARCHAR(100) NOT NULL,
   cluster_properties TEXT,
   cluster_attributes TEXT,
@@ -714,6 +714,7 @@ ALTER TABLE groups ADD CONSTRAINT FK_groups_principal_id 
FOREIGN KEY (principal_
 ALTER TABLE clusters ADD CONSTRAINT FK_clusters_resource_id FOREIGN KEY 
(resource_id) REFERENCES adminresource(resource_id);
 ALTER TABLE widget_layout_user_widget ADD CONSTRAINT FK_widget_layout_id 
FOREIGN KEY (widget_layout_id) REFERENCES widget_layout(id);
 ALTER TABLE widget_layout_user_widget ADD CONSTRAINT FK_widget_id FOREIGN KEY 
(widget_id) REFERENCES widget(id);
+ALTER TABLE topology_request ADD CONSTRAINT FK_topology_request_cluster_id 
FOREIGN KEY (cluster_id) REFERENCES clusters(cluster_id);
 ALTER TABLE topology_hostgroup ADD CONSTRAINT FK_hostgroup_req_id FOREIGN KEY 
(request_id) REFERENCES topology_request(id);
 ALTER TABLE topology_host_info ADD CONSTRAINT FK_hostinfo_group_id FOREIGN KEY 
(group_id) REFERENCES topology_hostgroup(id);
 ALTER TABLE topology_logical_request ADD CONSTRAINT FK_logicalreq_req_id 
FOREIGN KEY (request_id) REFERENCES topology_request(id);

http://git-wip-us.apache.org/repos/asf/ambari/blob/37f8c88f/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 36e280f..1f95f0f 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql
@@ -693,7 +693,7 @@ CREATE TABLE widget_layout_user_widget (
 CREATE TABLE topology_request (
   id BIGINT NOT NULL,
   action VARCHAR(255) NOT NULL,
-  cluster_name VARCHAR(100) NOT NULL,
+  cluster_id BIGINT NOT NULL,
   bp_name VARCHAR(100) NOT NULL,
   cluster_properties TEXT,
   cluster_attributes TEXT,
@@ -831,6 +831,7 @@ ALTER TABLE serviceconfighosts ADD CONSTRAINT 
FK_scvhosts_host_id FOREIGN KEY (h
 ALTER TABLE clusters ADD CONSTRAINT FK_clusters_resource_id FOREIGN KEY 
(resource_id) REFERENCES adminresource(resource_id);
 ALTER TABLE widget_layout_user_widget ADD CONSTRAINT FK_widget_layout_id 
FOREIGN KEY (widget_layout_id) REFERENCES widget_layout(id);
 ALTER TABLE widget_layout_user_widget ADD CONSTRAINT FK_widget_id FOREIGN KEY 
(widget_id) REFERENCES widget(id);
+ALTER TABLE topology_request ADD CONSTRAINT FK_topology_request_cluster_id 
FOREIGN KEY (cluster_id) REFERENCES clusters(cluster_id);
 ALTER TABLE topology_hostgroup ADD CONSTRAINT FK_hostgroup_req_id FOREIGN KEY 
(request_id) REFERENCES topology_request(id);
 ALTER TABLE topology_host_info ADD CONSTRAINT FK_hostinfo_group_id FOREIGN KEY 
(group_id) REFERENCES topology_hostgroup(id);
 ALTER TABLE topology_logical_request ADD CONSTRAINT FK_logicalreq_req_id 
FOREIGN KEY (request_id) REFERENCES topology_request(id);

http://git-wip-us.apache.org/repos/asf/ambari/blob/37f8c88f/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/BlueprintConfigurationProcessorTest.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/BlueprintConfigurationProcessorTest.java
 
b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/BlueprintConfigurationProcessorTest.java
index a881472..a97ca74 100644
--- 
a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/BlueprintConfigurationProcessorTest.java
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/BlueprintConfigurationProcessorTest.java
@@ -5156,7 +5156,7 @@ public class BlueprintConfigurationProcessorTest {
 
     replay(bp);
 
-    return new ClusterTopologyImpl(ambariConext, CLUSTER_NAME, blueprint, 
configuration, hostGroupInfo);
+    return new ClusterTopologyImpl(ambariConext, 1L, blueprint, configuration, 
hostGroupInfo);
   }
 
   private class TestHostGroup {

http://git-wip-us.apache.org/repos/asf/ambari/blob/37f8c88f/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterResourceProviderTest.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterResourceProviderTest.java
 
b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterResourceProviderTest.java
index 4c0a564..0b2e905 100644
--- 
a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterResourceProviderTest.java
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterResourceProviderTest.java
@@ -80,7 +80,7 @@ public class ClusterResourceProviderTest {
   private static final Request request = createNiceMock(Request.class);
   private static final TopologyManager topologyManager = 
createStrictMock(TopologyManager.class);
   private static final TopologyRequestFactory topologyFactory = 
createStrictMock(TopologyRequestFactory.class);
-  private static final TopologyRequest topologyRequest = 
createNiceMock(TopologyRequest.class);
+  private static final ProvisionClusterRequest topologyRequest = 
createNiceMock(ProvisionClusterRequest.class);
   private static final BlueprintFactory blueprintFactory = 
createStrictMock(BlueprintFactory.class);
   private static final Blueprint blueprint = createNiceMock(Blueprint.class);
   private static final RequestStatusResponse requestStatusResponse = 
createNiceMock(RequestStatusResponse.class);

http://git-wip-us.apache.org/repos/asf/ambari/blob/37f8c88f/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ExportBlueprintRequestTest.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ExportBlueprintRequestTest.java
 
b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ExportBlueprintRequestTest.java
index 1c3310d..94ba90f 100644
--- 
a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ExportBlueprintRequestTest.java
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ExportBlueprintRequestTest.java
@@ -58,6 +58,7 @@ import static org.junit.Assert.fail;
 @SuppressWarnings("unchecked")
 public class ExportBlueprintRequestTest {
   private static final String CLUSTER_NAME = "c1";
+  private static final String CLUSTER_ID = "2";
 
   private AmbariManagementController controller = 
createNiceMock(AmbariManagementController.class);
 
@@ -86,6 +87,7 @@ public class ExportBlueprintRequestTest {
   public void testExport_noConfigs() throws Exception {
     Resource clusterResource = new ResourceImpl(Resource.Type.Cluster);
     
clusterResource.setProperty(ClusterResourceProvider.CLUSTER_NAME_PROPERTY_ID, 
CLUSTER_NAME);
+    
clusterResource.setProperty(ClusterResourceProvider.CLUSTER_ID_PROPERTY_ID, 
CLUSTER_ID);
     
clusterResource.setProperty(ClusterResourceProvider.CLUSTER_VERSION_PROPERTY_ID,
 "TEST-1.0");
 
     TreeNode<Resource> clusterNode = new TreeNodeImpl<Resource>(null, 
clusterResource, "cluster");

http://git-wip-us.apache.org/repos/asf/ambari/blob/37f8c88f/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ProvisionClusterRequestTest.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ProvisionClusterRequestTest.java
 
b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ProvisionClusterRequestTest.java
index 6864519..21aafc5 100644
--- 
a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ProvisionClusterRequestTest.java
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ProvisionClusterRequestTest.java
@@ -99,7 +99,7 @@ public class ProvisionClusterRequestTest {
     replay(hostResourceProvider);
 
     Map<String, Object> properties = 
createBlueprintRequestPropertiesNameOnly(CLUSTER_NAME, BLUEPRINT_NAME);
-    TopologyRequest provisionClusterRequest = new 
ProvisionClusterRequest(properties);
+    ProvisionClusterRequest provisionClusterRequest = new 
ProvisionClusterRequest(properties);
 
     assertEquals(CLUSTER_NAME, provisionClusterRequest.getClusterName());
     assertEquals(TopologyRequest.Type.PROVISION, 
provisionClusterRequest.getType());
@@ -151,7 +151,7 @@ public class ProvisionClusterRequestTest {
     replay(hostResourceProvider);
 
     Map<String, Object> properties = 
createBlueprintRequestPropertiesCountOnly(CLUSTER_NAME, BLUEPRINT_NAME);
-    TopologyRequest provisionClusterRequest = new 
ProvisionClusterRequest(properties);
+    ProvisionClusterRequest provisionClusterRequest = new 
ProvisionClusterRequest(properties);
 
     assertEquals(CLUSTER_NAME, provisionClusterRequest.getClusterName());
     assertEquals(TopologyRequest.Type.PROVISION, 
provisionClusterRequest.getType());
@@ -203,7 +203,7 @@ public class ProvisionClusterRequestTest {
   @Test
   public void testMultipleGroups() throws Exception {
     Map<String, Object> properties = 
createBlueprintRequestProperties(CLUSTER_NAME, BLUEPRINT_NAME);
-    TopologyRequest provisionClusterRequest = new 
ProvisionClusterRequest(properties);
+    ProvisionClusterRequest provisionClusterRequest = new 
ProvisionClusterRequest(properties);
 
     assertEquals(CLUSTER_NAME, provisionClusterRequest.getClusterName());
     assertEquals(TopologyRequest.Type.PROVISION, 
provisionClusterRequest.getType());

http://git-wip-us.apache.org/repos/asf/ambari/blob/37f8c88f/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ScaleClusterRequestTest.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ScaleClusterRequestTest.java
 
b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ScaleClusterRequestTest.java
index 42938a4..7f70ee0 100644
--- 
a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ScaleClusterRequestTest.java
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ScaleClusterRequestTest.java
@@ -106,7 +106,7 @@ public class ScaleClusterRequestTest {
     reset(hostResourceProvider);
     replay(hostResourceProvider);
 
-    TopologyRequest scaleClusterRequest = new 
ScaleClusterRequest(Collections.singleton(
+    ScaleClusterRequest scaleClusterRequest = new 
ScaleClusterRequest(Collections.singleton(
         createScaleClusterPropertiesGroup1_HostName(CLUSTER_NAME, 
BLUEPRINT_NAME)));
 
     assertEquals(TopologyRequest.Type.SCALE, scaleClusterRequest.getType());
@@ -138,7 +138,7 @@ public class ScaleClusterRequestTest {
     propertySet.add(createScaleClusterPropertiesGroup1_HostName(CLUSTER_NAME, 
BLUEPRINT_NAME));
     propertySet.add(createScaleClusterPropertiesGroup1_HostName2(CLUSTER_NAME, 
BLUEPRINT_NAME));
 
-    TopologyRequest scaleClusterRequest = new ScaleClusterRequest(propertySet);
+    ScaleClusterRequest scaleClusterRequest = new 
ScaleClusterRequest(propertySet);
 
     assertEquals(TopologyRequest.Type.SCALE, scaleClusterRequest.getType());
     assertEquals(String.format("Scale Cluster '%s' (+%s hosts)", CLUSTER_NAME, 
"2"),
@@ -166,7 +166,7 @@ public class ScaleClusterRequestTest {
     reset(hostResourceProvider);
     replay(hostResourceProvider);
 
-    TopologyRequest scaleClusterRequest = new 
ScaleClusterRequest(Collections.singleton(
+    ScaleClusterRequest scaleClusterRequest = new 
ScaleClusterRequest(Collections.singleton(
         createScaleClusterPropertiesGroup1_HostCount(CLUSTER_NAME, 
BLUEPRINT_NAME)));
 
     assertEquals(TopologyRequest.Type.SCALE, scaleClusterRequest.getType());
@@ -193,7 +193,7 @@ public class ScaleClusterRequestTest {
     reset(hostResourceProvider);
     replay(hostResourceProvider);
 
-    TopologyRequest scaleClusterRequest = new 
ScaleClusterRequest(Collections.singleton(
+    ScaleClusterRequest scaleClusterRequest = new 
ScaleClusterRequest(Collections.singleton(
         createScaleClusterPropertiesGroup1_HostCount2(CLUSTER_NAME, 
BLUEPRINT_NAME)));
 
     assertEquals(TopologyRequest.Type.SCALE, scaleClusterRequest.getType());
@@ -216,7 +216,7 @@ public class ScaleClusterRequestTest {
 
   @Test
   public void test_basic_hostCountAndPredicate() throws Exception {
-    TopologyRequest scaleClusterRequest = new 
ScaleClusterRequest(Collections.singleton(
+    ScaleClusterRequest scaleClusterRequest = new 
ScaleClusterRequest(Collections.singleton(
         createScaleClusterPropertiesGroup1_HostCountAndPredicate(CLUSTER_NAME, 
BLUEPRINT_NAME)));
 
     assertEquals(TopologyRequest.Type.SCALE, scaleClusterRequest.getType());
@@ -244,7 +244,7 @@ public class ScaleClusterRequestTest {
     propertySet.add(createScaleClusterPropertiesGroup1_HostCount(CLUSTER_NAME, 
BLUEPRINT_NAME));
     propertySet.add(createScaleClusterPropertiesGroup1_HostName(CLUSTER_NAME, 
BLUEPRINT_NAME));
 
-    TopologyRequest scaleClusterRequest = new ScaleClusterRequest(propertySet);
+    ScaleClusterRequest scaleClusterRequest = new 
ScaleClusterRequest(propertySet);
 
     assertEquals(TopologyRequest.Type.SCALE, scaleClusterRequest.getType());
     assertEquals(String.format("Scale Cluster '%s' (+%s hosts)", CLUSTER_NAME, 
"3"),

http://git-wip-us.apache.org/repos/asf/ambari/blob/37f8c88f/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/TopologyLogicalRequestDAOTest.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/TopologyLogicalRequestDAOTest.java
 
b/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/TopologyLogicalRequestDAOTest.java
index fcffe95..c878a62 100644
--- 
a/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/TopologyLogicalRequestDAOTest.java
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/TopologyLogicalRequestDAOTest.java
@@ -41,8 +41,6 @@ import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
 
-import static org.apache.ambari.server.orm.OrmTestHelper.CLUSTER_NAME;
-
 public class TopologyLogicalRequestDAOTest {
   private Injector injector;
   private TopologyRequestDAO requestDAO;
@@ -73,7 +71,7 @@ public class TopologyLogicalRequestDAOTest {
     requestEntity.setBlueprintName("bp1");
     requestEntity.setClusterAttributes("attributes");
     requestEntity.setClusterProperties("properties");
-    requestEntity.setClusterName(CLUSTER_NAME);
+    requestEntity.setClusterId(clusterId);
     requestEntity.setDescription("description");
     requestDAO.create(requestEntity);
     List<TopologyRequestEntity> requestEntities = requestDAO.findAll();

http://git-wip-us.apache.org/repos/asf/ambari/blob/37f8c88f/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/TopologyRequestDAOTest.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/TopologyRequestDAOTest.java
 
b/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/TopologyRequestDAOTest.java
index 2dd16c7..f5ece39 100644
--- 
a/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/TopologyRequestDAOTest.java
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/TopologyRequestDAOTest.java
@@ -35,8 +35,6 @@ import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
 
-import static org.apache.ambari.server.orm.OrmTestHelper.CLUSTER_NAME;
-
 public class TopologyRequestDAOTest {
   private Injector injector;
   private TopologyRequestDAO requestDAO;
@@ -63,7 +61,7 @@ public class TopologyRequestDAOTest {
     requestEntity.setBlueprintName("bp1");
     requestEntity.setClusterAttributes("attributes");
     requestEntity.setClusterProperties("properties");
-    requestEntity.setClusterName(CLUSTER_NAME);
+    requestEntity.setClusterId(clusterId);
     requestEntity.setDescription("description");
     TopologyHostGroupEntity hostGroupEntity = new TopologyHostGroupEntity();
     hostGroupEntity.setName("hg1");
@@ -113,8 +111,8 @@ public class TopologyRequestDAOTest {
   }
 
   @Test
-  public void testFindByClusterName() throws Exception {
+  public void testFindByClusterId() throws Exception {
     create();
-    testRequestEntity(requestDAO.findByCluster(CLUSTER_NAME));
+    testRequestEntity(requestDAO.findByClusterId(clusterId));
   }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/37f8c88f/ambari-server/src/test/java/org/apache/ambari/server/topology/AmbariContextTest.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/topology/AmbariContextTest.java
 
b/ambari-server/src/test/java/org/apache/ambari/server/topology/AmbariContextTest.java
index 8c94f1e..1038b60 100644
--- 
a/ambari-server/src/test/java/org/apache/ambari/server/topology/AmbariContextTest.java
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/topology/AmbariContextTest.java
@@ -79,6 +79,7 @@ public class AmbariContextTest {
 
   private static final String BP_NAME = "testBP";
   private static final String CLUSTER_NAME = "testCluster";
+  private static final long CLUSTER_ID = 1L;
   private static final String STACK_NAME = "testStack";
   private static final String STACK_VERSION = "testVersion";
   private static final String HOST_GROUP_1 = "group1";
@@ -88,7 +89,7 @@ public class AmbariContextTest {
   StackId stackId = new StackId(STACK_NAME, STACK_VERSION);
 
   private static final AmbariContext context = new AmbariContext();
-  private static final AmbariManagementController controller = 
createStrictMock(AmbariManagementController.class);
+  private static final AmbariManagementController controller = 
createNiceMock(AmbariManagementController.class);
   private static final ClusterController clusterController = 
createStrictMock(ClusterController.class);
   private static final HostResourceProvider hostResourceProvider = 
createStrictMock(HostResourceProvider.class);
   private static final ServiceResourceProvider serviceResourceProvider = 
createStrictMock(ServiceResourceProvider.class);
@@ -98,8 +99,8 @@ public class AmbariContextTest {
   private static final ClusterTopology topology = 
createNiceMock(ClusterTopology.class);
   private static final Blueprint blueprint = createNiceMock(Blueprint.class);
   private static final Stack stack = createNiceMock(Stack.class);
-  private static final Clusters clusters = createStrictMock(Clusters.class);
-  private static final Cluster cluster = createStrictMock(Cluster.class);
+  private static final Clusters clusters = createNiceMock(Clusters.class);
+  private static final Cluster cluster = createNiceMock(Cluster.class);
   private static final HostGroupInfo group1Info = 
createNiceMock(HostGroupInfo.class);
   private static final ConfigHelper configHelper = 
createNiceMock(ConfigHelper.class);
   private static final ConfigGroup configGroup1 = 
createMock(ConfigGroup.class);
@@ -171,7 +172,7 @@ public class AmbariContextTest {
     blueprintServices.add("service1");
     blueprintServices.add("service2");
 
-    expect(topology.getClusterName()).andReturn(CLUSTER_NAME).anyTimes();
+    expect(topology.getClusterId()).andReturn(CLUSTER_ID).anyTimes();
     expect(topology.getBlueprint()).andReturn(blueprint).anyTimes();
     
expect(topology.getHostGroupInfo()).andReturn(Collections.singletonMap(HOST_GROUP_1,
 group1Info)).anyTimes();
 
@@ -193,9 +194,13 @@ public class AmbariContextTest {
     expect(controller.getConfigHelper()).andReturn(configHelper).anyTimes();
 
     expect(clusters.getCluster(CLUSTER_NAME)).andReturn(cluster).anyTimes();
+    expect(clusters.getClusterById(CLUSTER_ID)).andReturn(cluster).anyTimes();
     expect(clusters.getHost(HOST1)).andReturn(host1).anyTimes();
     expect(clusters.getHost(HOST2)).andReturn(host2).anyTimes();
 
+    expect(cluster.getClusterId()).andReturn(CLUSTER_ID).anyTimes();
+    expect(cluster.getClusterName()).andReturn(CLUSTER_NAME).anyTimes();
+
     expect(host1.getHostId()).andReturn(1L).anyTimes();
     expect(host2.getHostId()).andReturn(2L).anyTimes();
 
@@ -229,8 +234,6 @@ public class AmbariContextTest {
     Capture<ClusterRequest> clusterRequestCapture = new 
Capture<ClusterRequest>();
     controller.createCluster(capture(clusterRequestCapture));
     expectLastCall().once();
-    expect(controller.getClusters()).andReturn(clusters).anyTimes();
-    expect(clusters.getCluster(CLUSTER_NAME)).andReturn(cluster).anyTimes();
     expect(cluster.getServices()).andReturn(clusterServices).anyTimes();
 
     Capture<Set<ServiceRequest>> serviceRequestCapture = new 
Capture<Set<ServiceRequest>>();
@@ -254,7 +257,7 @@ public class AmbariContextTest {
     replayAll();
 
     // test
-    context.createAmbariResources(topology);
+    context.createAmbariResources(topology, CLUSTER_NAME);
 
     // assertions
     ClusterRequest clusterRequest = clusterRequestCapture.getValue();

http://git-wip-us.apache.org/repos/asf/ambari/blob/37f8c88f/ambari-server/src/test/java/org/apache/ambari/server/topology/ClusterTopologyImplTest.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/topology/ClusterTopologyImplTest.java
 
b/ambari-server/src/test/java/org/apache/ambari/server/topology/ClusterTopologyImplTest.java
index bbea96c..08aa3d3 100644
--- 
a/ambari-server/src/test/java/org/apache/ambari/server/topology/ClusterTopologyImplTest.java
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/topology/ClusterTopologyImplTest.java
@@ -46,6 +46,7 @@ import static org.powermock.api.easymock.PowerMock.verify;
 public class ClusterTopologyImplTest {
 
   private static final String CLUSTER_NAME = "cluster_name";
+  private static final long CLUSTER_ID = 1L;
   private static final String predicate = "Hosts/host_name=foo";
   private static final Blueprint blueprint = createNiceMock(Blueprint.class);
   private static final HostGroup group1 = createNiceMock(HostGroup.class);
@@ -188,12 +189,16 @@ public class ClusterTopologyImplTest {
       this.type = type;
     }
 
-    @Override
     public String getClusterName() {
       return CLUSTER_NAME;
     }
 
     @Override
+    public Long getClusterId() {
+      return CLUSTER_ID;
+    }
+
+    @Override
     public Type getType() {
       return type;
     }

Reply via email to