http://git-wip-us.apache.org/repos/asf/ambari/blob/f3520c09/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/upgrade/HostVersionOutOfSyncListener.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/upgrade/HostVersionOutOfSyncListener.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/upgrade/HostVersionOutOfSyncListener.java
index 2eb89a2..f4c8a3a 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/upgrade/HostVersionOutOfSyncListener.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/upgrade/HostVersionOutOfSyncListener.java
@@ -122,13 +122,14 @@ public class HostVersionOutOfSyncListener {
         // If added components do not advertise version, it makes no sense to 
mark version OUT_OF_SYNC
         // We perform check per-stack version, because component may be not 
versionAdvertised in current
         // stack, but become versionAdvertised in some future (installed, but 
not yet upgraded to) stack
-        String serviceName = event.getServiceName();
+        String serviceDisplayName = event.getServiceDisplayName();
         String componentName = event.getComponentName();
         ComponentInfo component = 
ami.get().getComponent(hostStackId.getStackName(),
-                hostStackId.getStackVersion(), serviceName, componentName);
+                hostStackId.getStackVersion(), serviceDisplayName, 
componentName);
 
         if (!component.isVersionAdvertised()) {
-          RepositoryVersionState state = checkAllHostComponents(hostStackId, 
hostVersionEntity.getHostEntity());
+          RepositoryVersionState state = checkAllHostComponents(hostStackId, 
serviceDisplayName,
+                                                                
hostVersionEntity.getHostEntity());
           if (null != state) {
             hostVersionEntity.setState(state);
             hostVersionDAO.get().merge(hostVersionEntity);
@@ -168,14 +169,14 @@ public class HostVersionOutOfSyncListener {
         HostEntity hostEntity = hostVersionEntity.getHostEntity();
         RepositoryVersionEntity repoVersionEntity = 
hostVersionEntity.getRepositoryVersion();
         StackId stackId = repoVersionEntity.getStackId();
-
+        String serviceDisplayName = event.getServiceDisplayName();
         if (null == stackId) {
           LOG.info("Stack id could not be loaded for host version {}, repo 
{}", hostVersionEntity.getHostName(),
               repoVersionEntity.getVersion());
           continue;
         }
 
-        RepositoryVersionState repoState = checkAllHostComponents(stackId, 
hostEntity);
+        RepositoryVersionState repoState = checkAllHostComponents(stackId, 
serviceDisplayName, hostEntity);
         if (null != repoState) {
           hostVersionEntity.setState(repoState);
           hostVersionDAO.get().merge(hostVersionEntity);
@@ -198,14 +199,14 @@ public class HostVersionOutOfSyncListener {
    * @param host    the host entity to find components
    * @return {@code null} if there should be no state change.  non-{@code 
null} to change it
    */
-  private RepositoryVersionState checkAllHostComponents(StackId stackId,
+  private RepositoryVersionState checkAllHostComponents(StackId stackId, 
String serviceDisplayName,
       HostEntity host) throws AmbariException {
 
     Collection<HostComponentDesiredStateEntity> hostComponents = 
host.getHostComponentDesiredStateEntities();
 
     for (HostComponentDesiredStateEntity hostComponent : hostComponents) {
       ComponentInfo ci = ami.get().getComponent(stackId.getStackName(), 
stackId.getStackVersion(),
-          hostComponent.getServiceName(), hostComponent.getComponentName());
+              serviceDisplayName, hostComponent.getComponentName());
 
       if (ci.isVersionAdvertised()) {
         return null;
@@ -227,8 +228,7 @@ public class HostVersionOutOfSyncListener {
 
       Map<String, ServiceComponent> serviceComponents = 
cluster.getService(event.getServiceName()).getServiceComponents();
       // Determine hosts that become OUT_OF_SYNC when adding components for 
new service
-      Map<String, List<ServiceComponent>> affectedHosts =
-        new HashMap<>();
+      Map<String, List<ServiceComponent>> affectedHosts = new HashMap<>();
       for (ServiceComponent component : serviceComponents.values()) {
         for (String hostname : component.getServiceComponentHosts().keySet()) {
           if (! affectedHosts.containsKey(hostname)) {

http://git-wip-us.apache.org/repos/asf/ambari/blob/f3520c09/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClusterServiceDAO.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClusterServiceDAO.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClusterServiceDAO.java
index 09419ec..0eeb19b 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClusterServiceDAO.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ClusterServiceDAO.java
@@ -1,4 +1,4 @@
-/*
+/**
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
  * distributed with this work for additional information
@@ -46,11 +46,12 @@ public class ClusterServiceDAO {
   }
 
   @RequiresSession
-  public ClusterServiceEntity findByClusterAndServiceNames(String  
clusterName, String serviceName) {
+  public ClusterServiceEntity findById(Long clusterId, Long serviceGroupId, 
Long serviceId) {
     TypedQuery<ClusterServiceEntity> query = entityManagerProvider.get()
-            .createNamedQuery("clusterServiceByClusterAndServiceNames", 
ClusterServiceEntity.class);
-    query.setParameter("clusterName", clusterName);
-    query.setParameter("serviceName", serviceName);
+      .createNamedQuery("clusterServiceById", ClusterServiceEntity.class);
+    query.setParameter("clusterId", clusterId);
+    query.setParameter("serviceGroupId", serviceGroupId);
+    query.setParameter("serviceId", serviceId);
 
     try {
       return query.getSingleResult();

http://git-wip-us.apache.org/repos/asf/ambari/blob/f3520c09/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostComponentDesiredStateDAO.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostComponentDesiredStateDAO.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostComponentDesiredStateDAO.java
index 57e409c..6f6fa43 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostComponentDesiredStateDAO.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostComponentDesiredStateDAO.java
@@ -62,15 +62,21 @@ public class HostComponentDesiredStateDAO {
   /**
    * Retrieve the single Host Component Desired State for the given unique 
service, component, and host.
    *
-   * @param serviceName Service Name
+   * @param clusterId Cluster ID
+   * @param serviceGroupId Service Group ID
+   * @param serviceId Service ID
    * @param componentName Component Name
    * @param hostName Host Name
    * @return Return all of the Host Component States that match the criteria.
    */
   @RequiresSession
-  public HostComponentDesiredStateEntity findByServiceComponentAndHost(String 
serviceName, String componentName, String hostName) {
-    final TypedQuery<HostComponentDesiredStateEntity> query = 
entityManagerProvider.get().createNamedQuery("HostComponentDesiredStateEntity.findByServiceComponentAndHost",
 HostComponentDesiredStateEntity.class);
-    query.setParameter("serviceName", serviceName);
+  public HostComponentDesiredStateEntity findByServiceComponentAndHost(
+    Long clusterId, Long serviceGroupId, Long serviceId, String componentName, 
String hostName) {
+    final TypedQuery<HostComponentDesiredStateEntity> query = 
entityManagerProvider.get().createNamedQuery(
+      "HostComponentDesiredStateEntity.findByServiceComponentAndHost", 
HostComponentDesiredStateEntity.class);
+    query.setParameter("clusterId", clusterId);
+    query.setParameter("serviceGroupId", serviceGroupId);
+    query.setParameter("serviceId", serviceId);
     query.setParameter("componentName", componentName);
     query.setParameter("hostName", hostName);
 
@@ -81,19 +87,21 @@ public class HostComponentDesiredStateDAO {
    * Retrieve the single Host Component Desired State for the given unique 
cluster, service, component, and host.
    *
    * @param clusterId Cluster ID
-   * @param serviceName Service Name
+   * @param serviceGroupId Service Group ID
+   * @param serviceId Service ID
    * @param componentName Component Name
    * @param hostId Host ID
    * @return Return the Host Component Desired State entity that match the 
criteria.
    */
   @RequiresSession
-  public HostComponentDesiredStateEntity findByIndex(Long clusterId, String 
serviceName,
+  public HostComponentDesiredStateEntity findByIndex(Long clusterId, Long 
serviceGroupId, Long serviceId,
                                                      String componentName, 
Long hostId) {
     final TypedQuery<HostComponentDesiredStateEntity> query = 
entityManagerProvider.get()
       .createNamedQuery("HostComponentDesiredStateEntity.findByIndex", 
HostComponentDesiredStateEntity.class);
 
     query.setParameter("clusterId", clusterId);
-    query.setParameter("serviceName", serviceName);
+    query.setParameter("serviceGroupId", serviceGroupId);
+    query.setParameter("serviceId", serviceId);
     query.setParameter("componentName", componentName);
     query.setParameter("hostId", hostId);
 
@@ -135,4 +143,4 @@ public class HostComponentDesiredStateDAO {
     remove(findById(id));
   }
 
-}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/f3520c09/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostComponentStateDAO.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostComponentStateDAO.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostComponentStateDAO.java
index ad6867e..7115b28 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostComponentStateDAO.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostComponentStateDAO.java
@@ -1,4 +1,4 @@
-/*
+/**
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
  * distributed with this work for additional information
@@ -74,13 +74,17 @@ public class HostComponentStateDAO {
   /**
    * Retrieve all of the Host Component States for the given service.
    *
-   * @param serviceName Service Name
+   * @param clusterId Cluster ID
+   * @param serviceGroupId Service Group ID
+   * @param serviceId Service ID
    * @return Return all of the Host Component States that match the criteria.
    */
   @RequiresSession
-  public List<HostComponentStateEntity> findByService(String serviceName) {
+  public List<HostComponentStateEntity> findByService( Long clusterId, Long 
serviceGroupId, Long serviceId) {
     final TypedQuery<HostComponentStateEntity> query = 
entityManagerProvider.get().createNamedQuery("HostComponentStateEntity.findByService",
 HostComponentStateEntity.class);
-    query.setParameter("serviceName", serviceName);
+    query.setParameter("clusterId", clusterId);
+    query.setParameter("serviceGroupId", serviceGroupId);
+    query.setParameter("serviceId", serviceId);
 
     return daoUtils.selectList(query);
   }
@@ -88,45 +92,34 @@ public class HostComponentStateDAO {
   /**
    * Retrieve all of the Host Component States for the given service and 
component.
    *
-   * @param serviceName Service Name
+   * @param clusterId Cluster ID
+   * @param serviceGroupId Service Group ID
+   * @param serviceId Service ID
    * @param componentName Component Name
    * @return Return all of the Host Component States that match the criteria.
    */
   @RequiresSession
-  public List<HostComponentStateEntity> findByServiceAndComponent(String 
serviceName, String componentName) {
+  public List<HostComponentStateEntity> findByServiceAndComponent(
+    Long clusterId, Long serviceGroupId, Long serviceId, String componentName) 
{
     final TypedQuery<HostComponentStateEntity> query = 
entityManagerProvider.get().createNamedQuery("HostComponentStateEntity.findByServiceAndComponent",
 HostComponentStateEntity.class);
-    query.setParameter("serviceName", serviceName);
+    query.setParameter("clusterId", clusterId);
+    query.setParameter("serviceGroupId", serviceGroupId);
+    query.setParameter("serviceId", serviceId);
     query.setParameter("componentName", componentName);
 
     return daoUtils.selectList(query);
   }
 
   /**
-   * Retrieve the single Host Component State for the given unique service, 
component, and host.
-   *
-   * @param serviceName Service Name
-   * @param componentName Component Name
-   * @param hostName Host Name
-   * @return Return all of the Host Component States that match the criteria.
-   */
-  @RequiresSession
-  public HostComponentStateEntity findByServiceComponentAndHost(String 
serviceName, String componentName, String hostName) {
-    final TypedQuery<HostComponentStateEntity> query = 
entityManagerProvider.get().createNamedQuery("HostComponentStateEntity.findByServiceComponentAndHost",
 HostComponentStateEntity.class);
-    query.setParameter("serviceName", serviceName);
-    query.setParameter("componentName", componentName);
-    query.setParameter("hostName", hostName);
-
-    return daoUtils.selectSingle(query);
-  }
-
-  /**
    * Retrieve the single Host Component State for the given unique cluster,
    * service, component, and host.
    *
    * @param clusterId
    *          Cluster ID
-   * @param serviceName
-   *          Service Name
+   * @param serviceGroupId
+   *          Service Group ID
+   * @param serviceId
+   *          Service ID
    * @param componentName
    *          Component Name
    * @param hostId
@@ -134,12 +127,13 @@ public class HostComponentStateDAO {
    * @return Return all of the Host Component States that match the criteria.
    */
   @RequiresSession
-  public HostComponentStateEntity findByIndex(Long clusterId, String 
serviceName,
-      String componentName, Long hostId) {
+  public HostComponentStateEntity findByIndex(Long clusterId, Long 
serviceGroupId, Long serviceId,
+                                              String componentName, Long 
hostId) {
     final TypedQuery<HostComponentStateEntity> query = 
entityManagerProvider.get().createNamedQuery(
         "HostComponentStateEntity.findByIndex", 
HostComponentStateEntity.class);
     query.setParameter("clusterId", clusterId);
-    query.setParameter("serviceName", serviceName);
+    query.setParameter("serviceGroupId", serviceGroupId);
+    query.setParameter("serviceId", serviceId);
     query.setParameter("componentName", componentName);
     query.setParameter("hostId", hostId);
 
@@ -178,22 +172,27 @@ public class HostComponentStateDAO {
   }
 
   /**
-   * @param serviceName
+   * @param clusterId
+   * @param serviceGroupId
+   * @param serviceId
    * @param componentName
    * @param version
    * @return a list of host components whose version that does NOT match the 
give version
    */
   @RequiresSession
-  public List<HostComponentStateEntity> 
findByServiceAndComponentAndNotVersion(String serviceName,
-      String componentName, String version) {
+  public List<HostComponentStateEntity> 
findByServiceAndComponentAndNotVersion(Long clusterId, Long serviceGroupId,
+                                                                               
Long serviceId, String componentName,
+                                                                               
String version) {
 
     final TypedQuery<HostComponentStateEntity> query = 
entityManagerProvider.get().createNamedQuery(
-        "HostComponentStateEntity.findByServiceAndComponentAndNotVersion", 
HostComponentStateEntity.class);
+      "HostComponentStateEntity.findByServiceAndComponentAndNotVersion", 
HostComponentStateEntity.class);
 
-    query.setParameter("serviceName", serviceName);
+    query.setParameter("clusterId", clusterId);
+    query.setParameter("serviceGroupId", serviceGroupId);
+    query.setParameter("serviceId", serviceId);
     query.setParameter("componentName", componentName);
     query.setParameter("version", version);
 
     return daoUtils.selectList(query);
   }
-}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/f3520c09/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ServiceComponentDesiredStateDAO.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ServiceComponentDesiredStateDAO.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ServiceComponentDesiredStateDAO.java
index dfe7d7b..61bc9ae 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ServiceComponentDesiredStateDAO.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ServiceComponentDesiredStateDAO.java
@@ -74,20 +74,23 @@ public class ServiceComponentDesiredStateDAO {
    *
    * @param clusterId
    *          the cluster ID
-   * @param serviceName
-   *          the service name (not {@code null})
+   * @param serviceGroupId
+   *          the service group ID
+   * @param serviceId
+   *          the service ID
    * @param componentName
    *          the component name (not {@code null})
    */
   @RequiresSession
-  public ServiceComponentDesiredStateEntity findByName(long clusterId, String 
serviceName,
-      String componentName) {
+  public ServiceComponentDesiredStateEntity findByName(long clusterId, long 
serviceGroupId, long serviceId,
+       String componentName) {
     EntityManager entityManager = entityManagerProvider.get();
     TypedQuery<ServiceComponentDesiredStateEntity> query = 
entityManager.createNamedQuery(
         "ServiceComponentDesiredStateEntity.findByName", 
ServiceComponentDesiredStateEntity.class);
 
     query.setParameter("clusterId", clusterId);
-    query.setParameter("serviceName", serviceName);
+    query.setParameter("serviceGroupId", serviceGroupId);
+    query.setParameter("serviceId", serviceId);
     query.setParameter("componentName", componentName);
 
     ServiceComponentDesiredStateEntity entity = null;
@@ -120,8 +123,8 @@ public class ServiceComponentDesiredStateDAO {
   }
 
   @Transactional
-  public void removeByName(long clusterId, String serviceName, String 
componentName) {
-    ServiceComponentDesiredStateEntity entity = findByName(clusterId, 
serviceName, componentName);
+  public void removeByName(long clusterId, long serviceGroupId, long 
serviceId, String componentName) {
+    ServiceComponentDesiredStateEntity entity = findByName(clusterId, 
serviceGroupId, serviceId, componentName);
     if (null != entity) {
       entityManagerProvider.get().remove(entity);
     }
@@ -129,19 +132,21 @@ public class ServiceComponentDesiredStateDAO {
 
   /**
    * @param clusterId     the cluster id
-   * @param serviceName   the service name
+   * @param serviceGroupId   the service group id
+   * @param serviceId   the service id
    * @param componentName the component name
    * @return the list of repository versions for a component
    */
   @RequiresSession
-  public List<ServiceComponentVersionEntity> findVersions(long clusterId, 
String serviceName,
+  public List<ServiceComponentVersionEntity> findVersions(long clusterId, long 
serviceGroupId, long serviceId,
       String componentName) {
     EntityManager entityManager = entityManagerProvider.get();
     TypedQuery<ServiceComponentVersionEntity> query = 
entityManager.createNamedQuery(
         "ServiceComponentVersionEntity.findByComponent", 
ServiceComponentVersionEntity.class);
 
     query.setParameter("clusterId", clusterId);
-    query.setParameter("serviceName", serviceName);
+    query.setParameter("serviceGroupId", serviceGroupId);
+    query.setParameter("serviceId", serviceId);
     query.setParameter("componentName", componentName);
 
     return daoUtils.selectList(query);
@@ -150,13 +155,14 @@ public class ServiceComponentDesiredStateDAO {
   /**
    * Gets a specific version for a component
    * @param clusterId     the cluster id
-   * @param serviceName   the service name
+   * @param serviceGroupId   the service group id
+   * @param serviceId   the service id
    * @param componentName the component name
    * @param version       the component version to find
    * @return the version entity, or {@code null} if not found
    */
   @RequiresSession
-  public ServiceComponentVersionEntity findVersion(long clusterId, String 
serviceName,
+  public ServiceComponentVersionEntity findVersion(long clusterId, long 
serviceGroupId, long serviceId,
       String componentName, String version) {
 
     EntityManager entityManager = entityManagerProvider.get();
@@ -164,7 +170,8 @@ public class ServiceComponentDesiredStateDAO {
         "ServiceComponentVersionEntity.findByComponentAndVersion", 
ServiceComponentVersionEntity.class);
 
     query.setParameter("clusterId", clusterId);
-    query.setParameter("serviceName", serviceName);
+    query.setParameter("serviceGroupId", serviceGroupId);
+    query.setParameter("serviceId", serviceId);
     query.setParameter("componentName", componentName);
     query.setParameter("repoVersion", version);
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/f3520c09/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ServiceGroupDAO.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ServiceGroupDAO.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ServiceGroupDAO.java
index dc997b0..63e78d6 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ServiceGroupDAO.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ServiceGroupDAO.java
@@ -46,11 +46,11 @@ public class ServiceGroupDAO {
   }
 
   @RequiresSession
-  public ServiceGroupEntity findByClusterAndServiceGroupNames(String 
clusterName, String serviceGroupName) {
+  public ServiceGroupEntity findByClusterAndServiceGroupIds(Long clusterId, 
Long serviceGroupId) {
     TypedQuery<ServiceGroupEntity> query = entityManagerProvider.get()
-      .createNamedQuery("serviceGroupByClusterAndServiceGroupNames", 
ServiceGroupEntity.class);
-    query.setParameter("clusterName", clusterName);
-    query.setParameter("serviceGroupName", serviceGroupName);
+      .createNamedQuery("serviceGroupByClusterAndServiceGroupIds", 
ServiceGroupEntity.class);
+    query.setParameter("clusterId", clusterId);
+    query.setParameter("serviceGroupId", serviceGroupId);
 
     try {
       return query.getSingleResult();

http://git-wip-us.apache.org/repos/asf/ambari/blob/f3520c09/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ClusterServiceEntity.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ClusterServiceEntity.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ClusterServiceEntity.java
index 2af9a47..f4ce5f9 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ClusterServiceEntity.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ClusterServiceEntity.java
@@ -24,24 +24,35 @@ import javax.persistence.Basic;
 import javax.persistence.CascadeType;
 import javax.persistence.Column;
 import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
 import javax.persistence.Id;
 import javax.persistence.JoinColumn;
+import javax.persistence.JoinColumns;
 import javax.persistence.ManyToOne;
 import javax.persistence.NamedQueries;
 import javax.persistence.NamedQuery;
 import javax.persistence.OneToMany;
 import javax.persistence.OneToOne;
+import javax.persistence.TableGenerator;
 
 @javax.persistence.IdClass(ClusterServiceEntityPK.class)
 @javax.persistence.Table(name = "clusterservices")
 @NamedQueries({
-        @NamedQuery(name = "clusterServiceByClusterAndServiceNames", query =
-                "SELECT clusterService " +
-                        "FROM ClusterServiceEntity clusterService " +
-                        "JOIN clusterService.clusterEntity cluster " +
-                        "WHERE clusterService.serviceName=:serviceName AND 
cluster.clusterName=:clusterName")
+  @NamedQuery(name = "clusterServiceById", query =
+    "SELECT clusterService " +
+      "FROM ClusterServiceEntity clusterService " +
+      "JOIN clusterService.serviceGroupEntity serviceGroup " +
+      "WHERE clusterService.serviceId=:serviceId " +
+      "AND  serviceGroup.serviceGroupId=:serviceGroupId " +
+      "AND serviceGroup.clusterId=:clusterId")
 })
 @Entity
+@TableGenerator(name = "service_id_generator",
+  table = "ambari_sequences", pkColumnName = "sequence_name", valueColumnName 
= "sequence_value"
+  , pkColumnValue = "service_id_seq"
+  , initialValue = 1
+)
 public class ClusterServiceEntity {
 
   @Id
@@ -49,17 +60,34 @@ public class ClusterServiceEntity {
   private Long clusterId;
 
   @Id
+  @Column(name = "service_group_id", nullable = false, insertable = false, 
updatable = false, length = 10)
+  private Long serviceGroupId;
+
+  @Id
+  @Column(name = "id", nullable = false, insertable = true, updatable = true)
+  @GeneratedValue(strategy = GenerationType.TABLE, generator = 
"service_id_generator")
+  private Long serviceId;
+
   @Column(name = "service_name", nullable = false, insertable = true, 
updatable = true)
   private String serviceName;
 
+  @Column(name = "service_display_name", nullable = false, insertable = true, 
updatable = true)
+  private String serviceDisplayName;
+
   @Basic
   @Column(name = "service_enabled", nullable = false, insertable = true, 
updatable = true, length = 10)
   private Integer serviceEnabled = 0;
 
+
   @ManyToOne
-  @JoinColumn(name = "cluster_id", referencedColumnName = "cluster_id", 
nullable = false)
+  @JoinColumn(name = "cluster_id", referencedColumnName = "cluster_id", 
nullable = false, insertable = false, updatable = false)
   private ClusterEntity clusterEntity;
 
+  @ManyToOne
+  @JoinColumns({@JoinColumn(name = "cluster_id", referencedColumnName = 
"cluster_id", nullable = false),
+    @JoinColumn(name = "service_group_id", referencedColumnName = "id", 
nullable = false)})
+  private ServiceGroupEntity serviceGroupEntity;
+
   @OneToOne(mappedBy = "clusterServiceEntity", cascade = { 
CascadeType.PERSIST, CascadeType.MERGE })
   private ServiceDesiredStateEntity serviceDesiredStateEntity;
 
@@ -74,6 +102,22 @@ public class ClusterServiceEntity {
     this.clusterId = clusterId;
   }
 
+  public Long getServiceGroupId() {
+    return serviceGroupId;
+  }
+
+  public void setServiceGroupId(Long serviceGroupId) {
+    this.serviceGroupId = serviceGroupId;
+  }
+
+  public Long getServiceId() {
+    return serviceId;
+  }
+
+  public void setServiceId(Long serviceId) {
+    this.serviceId = serviceId;
+  }
+
   public String getServiceName() {
     return serviceName;
   }
@@ -82,6 +126,14 @@ public class ClusterServiceEntity {
     this.serviceName = serviceName;
   }
 
+  public String getServiceDisplayName() {
+    return serviceDisplayName;
+  }
+
+  public void setServiceDisplayName(String serviceDisplayName) {
+    this.serviceDisplayName = serviceDisplayName;
+  }
+
   public int getServiceEnabled() {
     return serviceEnabled;
   }
@@ -98,9 +150,11 @@ public class ClusterServiceEntity {
     ClusterServiceEntity that = (ClusterServiceEntity) o;
 
     if (clusterId != null ? !clusterId.equals(that.clusterId) : that.clusterId 
!= null) return false;
+    if (serviceGroupId != null ? !serviceGroupId.equals(that.serviceGroupId) : 
that.serviceGroupId != null) return false;
+    if (serviceId != null ? !serviceId.equals(that.serviceId) : that.serviceId 
!= null) return false;
     if (serviceEnabled != null ? !serviceEnabled.equals(that.serviceEnabled) : 
that.serviceEnabled != null)
       return false;
-    if (serviceName != null ? !serviceName.equals(that.serviceName) : 
that.serviceName != null) return false;
+    if (serviceDisplayName != null ? 
!serviceDisplayName.equals(that.serviceDisplayName) : that.serviceDisplayName 
!= null) return false;
 
     return true;
   }
@@ -108,7 +162,9 @@ public class ClusterServiceEntity {
   @Override
   public int hashCode() {
     int result = clusterId !=null ? clusterId.intValue() : 0;
-    result = 31 * result + (serviceName != null ? serviceName.hashCode() : 0);
+    result = 31 * result + (serviceGroupId != null ? serviceGroupId.hashCode() 
: 0);
+    result = 31 * result + (serviceId != null ? serviceId.hashCode() : 0);
+    result = 31 * result + (serviceDisplayName != null ? 
serviceDisplayName.hashCode() : 0);
     result = 31 * result + serviceEnabled;
     return result;
   }
@@ -121,6 +177,14 @@ public class ClusterServiceEntity {
     this.clusterEntity = clusterEntity;
   }
 
+  public ServiceGroupEntity getClusterServiceGroupEntity() {
+    return serviceGroupEntity;
+  }
+
+  public void setServiceGroupEntity(ServiceGroupEntity serviceGroupEntity) {
+    this.serviceGroupEntity = serviceGroupEntity;
+  }
+
   public ServiceDesiredStateEntity getServiceDesiredStateEntity() {
     return serviceDesiredStateEntity;
   }
@@ -137,4 +201,4 @@ public class ClusterServiceEntity {
     this.serviceComponentDesiredStateEntities = 
serviceComponentDesiredStateEntities;
   }
 
-}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/f3520c09/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ClusterServiceEntityPK.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ClusterServiceEntityPK.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ClusterServiceEntityPK.java
index 578edea..760c08e 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ClusterServiceEntityPK.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ClusterServiceEntityPK.java
@@ -37,16 +37,28 @@ public class ClusterServiceEntityPK implements Serializable 
{
     this.clusterId = clusterId;
   }
 
-  private String serviceName;
+  private Long serviceGroupId;
 
   @Id
-  @Column(name = "service_name", nullable = false, insertable = true, 
updatable = true)
-  public String getServiceName() {
-    return serviceName;
+  @Column(name = "service_group_id", nullable = false, insertable = true, 
updatable = true, length = 10)
+  public Long getServiceGroupId() {
+    return serviceGroupId;
   }
 
-  public void setServiceName(String serviceName) {
-    this.serviceName = serviceName;
+  public void setServiceGroupId(Long serviceGroupId) {
+    this.serviceGroupId = serviceGroupId;
+  }
+
+  private Long serviceId;
+
+  @Id
+  @Column(name = "id", nullable = false, insertable = true, updatable = true, 
length = 10)
+  public Long getServiceId() {
+    return serviceId;
+  }
+
+  public void setServiceId(Long serviceId) {
+    this.serviceId = serviceId;
   }
 
   @Override
@@ -57,7 +69,8 @@ public class ClusterServiceEntityPK implements Serializable {
     ClusterServiceEntityPK that = (ClusterServiceEntityPK) o;
 
     if (clusterId != null ? !clusterId.equals(that.clusterId) : that.clusterId 
!= null) return false;
-    if (serviceName != null ? !serviceName.equals(that.serviceName) : 
that.serviceName != null) return false;
+    if (serviceGroupId != null ? !serviceGroupId.equals(that.serviceGroupId) : 
that.serviceGroupId != null) return false;
+    if (serviceId != null ? !serviceId.equals(that.serviceId) : that.serviceId 
!= null) return false;
 
     return true;
   }
@@ -65,7 +78,8 @@ public class ClusterServiceEntityPK implements Serializable {
   @Override
   public int hashCode() {
     int result = clusterId !=null ? clusterId.intValue() : 0;
-    result = 31 * result + (serviceName != null ? serviceName.hashCode() : 0);
+    result = 31 * result + (serviceGroupId != null ? serviceGroupId.hashCode() 
: 0);
+    result = 31 * result + (serviceId != null ? serviceId.hashCode() : 0);
     return result;
   }
-}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/f3520c09/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentDesiredStateEntity.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentDesiredStateEntity.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentDesiredStateEntity.java
index 36a7a25..fafec3d 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentDesiredStateEntity.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentDesiredStateEntity.java
@@ -1,4 +1,4 @@
-/*
+/**
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
  * distributed with this work for additional information
@@ -48,7 +48,7 @@ import com.google.common.base.Objects;
   name = "hostcomponentdesiredstate",
   uniqueConstraints = @UniqueConstraint(
     name = "UQ_hcdesiredstate_name",
-    columnNames = { "component_name", "service_name", "host_id", "cluster_id" 
}) )
+    columnNames = { "component_name", "service_id", "host_id", 
"service_group_id", "cluster_id" }) )
 @TableGenerator(
   name = "hostcomponentdesiredstate_id_generator",
   table = "ambari_sequences",
@@ -59,14 +59,14 @@ import com.google.common.base.Objects;
 @NamedQueries({
     @NamedQuery(name = "HostComponentDesiredStateEntity.findAll", query = 
"SELECT hcds from HostComponentDesiredStateEntity hcds"),
 
-    @NamedQuery(name = 
"HostComponentDesiredStateEntity.findByServiceAndComponent", query =
-        "SELECT hcds from HostComponentDesiredStateEntity hcds WHERE 
hcds.serviceName=:serviceName AND hcds.componentName=:componentName"),
+  @NamedQuery(name = 
"HostComponentDesiredStateEntity.findByServiceAndComponent", query =
+    "SELECT hcds from HostComponentDesiredStateEntity hcds WHERE 
hcds.clusterId=:clusterId AND hcds.serviceGroupId=:serviceGroupId AND 
hcds.serviceId=:serviceId AND hcds.componentName=:componentName"),
 
-    @NamedQuery(name = 
"HostComponentDesiredStateEntity.findByServiceComponentAndHost", query =
-        "SELECT hcds from HostComponentDesiredStateEntity hcds WHERE 
hcds.serviceName=:serviceName AND hcds.componentName=:componentName AND 
hcds.hostEntity.hostName=:hostName"),
+  @NamedQuery(name = 
"HostComponentDesiredStateEntity.findByServiceComponentAndHost", query =
+    "SELECT hcds from HostComponentDesiredStateEntity hcds WHERE 
hcds.clusterId=:clusterId AND hcds.serviceGroupId=:serviceGroupId AND 
hcds.serviceId=:serviceId AND hcds.componentName=:componentName AND 
hcds.hostEntity.hostName=:hostName"),
 
   @NamedQuery(name = "HostComponentDesiredStateEntity.findByIndex", query =
-    "SELECT hcds from HostComponentDesiredStateEntity hcds WHERE 
hcds.clusterId=:clusterId AND hcds.serviceName=:serviceName AND 
hcds.componentName=:componentName AND hcds.hostId=:hostId"),
+    "SELECT hcds from HostComponentDesiredStateEntity hcds WHERE 
hcds.clusterId=:clusterId AND hcds.serviceGroupId=:serviceGroupId AND 
hcds.serviceId=:serviceId AND hcds.componentName=:componentName AND 
hcds.hostId=:hostId"),
 })
 public class HostComponentDesiredStateEntity {
 
@@ -79,8 +79,11 @@ public class HostComponentDesiredStateEntity {
   @Column(name = "cluster_id", nullable = false, insertable = false, updatable 
= false, length = 10)
   private Long clusterId;
 
-  @Column(name = "service_name", nullable = false, insertable = false, 
updatable = false)
-  private String serviceName;
+  @Column(name = "service_group_id", nullable = false, insertable = false, 
updatable = false, length = 10)
+  private Long serviceGroupId;
+
+  @Column(name = "service_id", nullable = false, insertable = false, updatable 
= false, length = 10)
+  private Long serviceId;
 
   @Column(name = "host_id", nullable = false, insertable = false, updatable = 
false)
   private Long hostId;
@@ -99,9 +102,10 @@ public class HostComponentDesiredStateEntity {
 
   @ManyToOne
   @JoinColumns({
-      @JoinColumn(name = "cluster_id", referencedColumnName = "cluster_id", 
nullable = false),
-      @JoinColumn(name = "service_name", referencedColumnName = 
"service_name", nullable = false),
-      @JoinColumn(name = "component_name", referencedColumnName = 
"component_name", nullable = false)})
+    @JoinColumn(name = "cluster_id", referencedColumnName = "cluster_id", 
nullable = false),
+    @JoinColumn(name = "service_group_id", referencedColumnName = 
"service_group_id", nullable = false),
+    @JoinColumn(name = "service_id", referencedColumnName = "service_id", 
nullable = false),
+    @JoinColumn(name = "component_name", referencedColumnName = 
"component_name", nullable = false)})
   private ServiceComponentDesiredStateEntity 
serviceComponentDesiredStateEntity;
 
   @ManyToOne
@@ -126,14 +130,18 @@ public class HostComponentDesiredStateEntity {
     this.clusterId = clusterId;
   }
 
-  public String getServiceName() {
-    return serviceName;
+  public Long getServiceGroupId() {
+    return serviceGroupId;
   }
 
-  public void setServiceName(String serviceName) {
-    this.serviceName = serviceName;
+  public void setServiceGroupId(Long serviceGroupId) {
+    this.serviceGroupId = serviceGroupId;
   }
 
+  public Long getServiceId() { return serviceId; }
+
+  public void setServiceId(Long serviceId) { this.serviceId = serviceId; }
+
   public Long getHostId() {
     return hostEntity != null ? hostEntity.getHostId() : null;
   }
@@ -189,19 +197,23 @@ public class HostComponentDesiredStateEntity {
       return false;
     }
 
-    if (!Objects.equal(componentName, that.componentName)) {
+    if (!Objects.equal(serviceGroupId, that.serviceGroupId)) {
       return false;
     }
 
-    if (!Objects.equal(desiredState, that.desiredState)) {
+    if (!Objects.equal(serviceId, that.serviceId)) {
       return false;
     }
 
-    if (!Objects.equal(hostEntity, that.hostEntity)) {
+    if (!Objects.equal(componentName, that.componentName)) {
+      return false;
+    }
+
+    if (!Objects.equal(desiredState, that.desiredState)) {
       return false;
     }
 
-    if (!Objects.equal(serviceName, that.serviceName)) {
+    if (!Objects.equal(hostEntity, that.hostEntity)) {
       return false;
     }
 
@@ -212,10 +224,11 @@ public class HostComponentDesiredStateEntity {
   public int hashCode() {
     int result = id != null ? id.hashCode() : 0;
     result = 31 * result + (clusterId != null ? clusterId.hashCode() : 0);
+    result = 31 * result + (serviceGroupId != null ? serviceGroupId.hashCode() 
: 0);
+    result = 31 * result + (serviceId != null ? serviceId.hashCode() : 0);
     result = 31 * result + (hostEntity != null ? hostEntity.hashCode() : 0);
     result = 31 * result + (componentName != null ? componentName.hashCode() : 
0);
     result = 31 * result + (desiredState != null ? desiredState.hashCode() : 
0);
-    result = 31 * result + (serviceName != null ? serviceName.hashCode() : 0);
     return result;
   }
 
@@ -249,7 +262,8 @@ public class HostComponentDesiredStateEntity {
    */
   @Override
   public String toString() {
-    return Objects.toStringHelper(this).add("serviceName", 
serviceName).add("componentName",
-        componentName).add("hostId", hostId).add("desiredState", 
desiredState).toString();
+    return Objects.toStringHelper(this).add("clusterId", clusterId).add(
+      "serviceGroupId", serviceGroupId).add("serviceId", 
serviceId).add("componentName",
+      componentName).add("hostId", hostId).add("desiredState", 
desiredState).toString();
   }
-}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/f3520c09/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentStateEntity.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentStateEntity.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentStateEntity.java
index 0d295a4..8994384 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentStateEntity.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostComponentStateEntity.java
@@ -1,4 +1,4 @@
-/*
+/**
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
  * distributed with this work for additional information
@@ -56,20 +56,28 @@ import com.google.common.base.Objects;
         query = "SELECT hcs from HostComponentStateEntity hcs WHERE 
hcs.hostEntity.hostName=:hostName"),
     @NamedQuery(
         name = "HostComponentStateEntity.findByService",
-        query = "SELECT hcs from HostComponentStateEntity hcs WHERE 
hcs.serviceName=:serviceName"),
+        query = "SELECT hcs from HostComponentStateEntity  hcs WHERE 
hcs.clusterId=:clusterId " +
+                "AND hcs.serviceGroupId=:serviceGroupId AND 
hcs.serviceId=:serviceId " ),
     @NamedQuery(
         name = "HostComponentStateEntity.findByServiceAndComponent",
-        query = "SELECT hcs from HostComponentStateEntity hcs WHERE 
hcs.serviceName=:serviceName AND hcs.componentName=:componentName"),
+        query = "SELECT hcs from HostComponentStateEntity hcs WHERE 
hcs.clusterId=:clusterId " +
+                "AND hcs.serviceGroupId=:serviceGroupId AND 
hcs.serviceId=:serviceId " +
+                "AND hcs.componentName=:componentName"),
     @NamedQuery(
         name = "HostComponentStateEntity.findByServiceComponentAndHost",
-        query = "SELECT hcs from HostComponentStateEntity hcs WHERE 
hcs.serviceName=:serviceName AND hcs.componentName=:componentName AND 
hcs.hostEntity.hostName=:hostName"),
-    @NamedQuery(
-        name = "HostComponentStateEntity.findByIndex",
-        query = "SELECT hcs from HostComponentStateEntity hcs WHERE 
hcs.clusterId=:clusterId AND hcs.serviceName=:serviceName AND 
hcs.componentName=:componentName AND hcs.hostId=:hostId"),
+        query = "SELECT hcs from HostComponentStateEntity hcs WHERE 
hcs.clusterId=:clusterId " +
+                "AND hcs.serviceGroupId=:serviceGroupId AND 
hcs.serviceId=:serviceId " +
+                "AND hcs.componentName=:componentName AND 
hcs.hostEntity.hostName=:hostName"),
     @NamedQuery(
         name = 
"HostComponentStateEntity.findByServiceAndComponentAndNotVersion",
-        query = "SELECT hcs from HostComponentStateEntity hcs WHERE 
hcs.serviceName=:serviceName AND hcs.componentName=:componentName AND 
hcs.version != :version")
-})
+        query = "SELECT hcs from HostComponentStateEntity hcs WHERE 
hcs.clusterId=:clusterId " +
+                "AND hcs.serviceGroupId=:serviceGroupId AND 
hcs.serviceId=:serviceId " +
+                "AND hcs.componentName=:componentName AND 
hcs.hostEntity.hostName=:hostName " +
+                "AND hcs.version != :version"),
+    @NamedQuery(
+        name = "HostComponentStateEntity.findByIndex",
+        query = "SELECT hcs from HostComponentStateEntity hcs WHERE 
hcs.clusterId=:clusterId " +
+                "AND hcs.serviceGroupId=:serviceGroupId AND 
hcs.serviceId=:serviceId AND hcs.componentName=:componentName AND 
hcs.hostId=:hostId") })
 
 public class HostComponentStateEntity {
 
@@ -81,8 +89,11 @@ public class HostComponentStateEntity {
   @Column(name = "cluster_id", nullable = false, insertable = false, updatable 
= false, length = 10)
   private Long clusterId;
 
-  @Column(name = "service_name", nullable = false, insertable = false, 
updatable = false)
-  private String serviceName;
+  @Column(name = "service_group_id", nullable = false, insertable = false, 
updatable = false, length = 10)
+  private Long serviceGroupId;
+
+  @Column(name = "service_id", nullable = false, insertable = false, updatable 
= false, length = 10)
+  private Long serviceId;
 
   @Column(name = "host_id", nullable = false, insertable = false, updatable = 
false)
   private Long hostId;
@@ -106,9 +117,10 @@ public class HostComponentStateEntity {
 
   @ManyToOne
   @JoinColumns({
-      @JoinColumn(name = "cluster_id", referencedColumnName = "cluster_id", 
nullable = false),
-      @JoinColumn(name = "service_name", referencedColumnName = 
"service_name", nullable = false),
-      @JoinColumn(name = "component_name", referencedColumnName = 
"component_name", nullable = false) })
+    @JoinColumn(name = "cluster_id", referencedColumnName = "cluster_id", 
nullable = false),
+    @JoinColumn(name = "service_group_id", referencedColumnName = 
"service_group_id", nullable = false),
+    @JoinColumn(name = "service_id", referencedColumnName = "service_id", 
nullable = false),
+    @JoinColumn(name = "component_name", referencedColumnName = 
"component_name", nullable = false) })
   private ServiceComponentDesiredStateEntity 
serviceComponentDesiredStateEntity;
 
   @ManyToOne
@@ -123,16 +135,24 @@ public class HostComponentStateEntity {
     return clusterId;
   }
 
+  public void setServiceGroupId(Long serviceGroupId) {
+    this.serviceGroupId = serviceGroupId;
+  }
+
+  public Long getServiceGroupId() {
+    return serviceGroupId;
+  }
+
   public void setClusterId(Long clusterId) {
     this.clusterId = clusterId;
   }
 
-  public String getServiceName() {
-    return serviceName;
+  public Long getServiceId() {
+    return this.serviceId;
   }
 
-  public void setServiceName(String serviceName) {
-    this.serviceName = serviceName;
+  public void setServiceId(Long serviceId) {
+    this.serviceId = serviceId;
   }
 
   public String getHostName() {
@@ -195,6 +215,14 @@ public class HostComponentStateEntity {
       return false;
     }
 
+    if (serviceGroupId != null ? !serviceGroupId.equals(that.serviceGroupId) : 
that.serviceGroupId != null) {
+      return false;
+    }
+
+    if (serviceId != null ? !serviceId.equals(that.serviceId) : that.serviceId 
!= null) {
+      return false;
+    }
+
     if (componentName != null ? !componentName.equals(that.componentName)
         : that.componentName != null) {
       return false;
@@ -214,10 +242,6 @@ public class HostComponentStateEntity {
       return false;
     }
 
-    if (serviceName != null ? !serviceName.equals(that.serviceName) : 
that.serviceName != null) {
-      return false;
-    }
-
     if (version != null ? !version.equals(that.version) : that.version != 
null) {
       return false;
     }
@@ -229,11 +253,12 @@ public class HostComponentStateEntity {
   public int hashCode() {
     int result = id != null ? id.intValue() : 0;
     result = 31 * result + (clusterId != null ? clusterId.intValue() : 0);
+    result = 31 * result + (serviceGroupId != null ? serviceGroupId.intValue() 
: 0);
+    result = 31 * result + (serviceId != null ? serviceId.intValue() : 0);
     result = 31 * result + (hostEntity != null ? hostEntity.hashCode() : 0);
     result = 31 * result + (componentName != null ? componentName.hashCode() : 
0);
     result = 31 * result + (currentState != null ? currentState.hashCode() : 
0);
     result = 31 * result + (upgradeState != null ? upgradeState.hashCode() : 
0);
-    result = 31 * result + (serviceName != null ? serviceName.hashCode() : 0);
     result = 31 * result + (version != null ? version.hashCode() : 0);
     return result;
   }
@@ -260,8 +285,9 @@ public class HostComponentStateEntity {
    */
   @Override
   public String toString() {
-    return Objects.toStringHelper(this).add("serviceName", 
serviceName).add("componentName",
-        componentName).add("hostId", hostId).add("state", 
currentState).toString();
+    return Objects.toStringHelper(this).add("clusterId", 
clusterId).add("serviceGroupId", serviceGroupId).add(
+      "serviceId", serviceId).add("componentName", componentName).add(
+      "hostId", hostId).add("state", currentState).toString();
   }
 
-}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/f3520c09/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceComponentDesiredStateEntity.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceComponentDesiredStateEntity.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceComponentDesiredStateEntity.java
index e0f52c6..8a8b380 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceComponentDesiredStateEntity.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceComponentDesiredStateEntity.java
@@ -20,7 +20,6 @@ package org.apache.ambari.server.orm.entities;
 
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Objects;
 
 import javax.persistence.CascadeType;
 import javax.persistence.Column;
@@ -43,14 +42,13 @@ import javax.persistence.UniqueConstraint;
 
 import org.apache.ambari.server.state.RepositoryVersionState;
 import org.apache.ambari.server.state.State;
-import org.apache.commons.lang.builder.EqualsBuilder;
 
 @Entity
 @Table(
     name = "servicecomponentdesiredstate",
     uniqueConstraints = @UniqueConstraint(
         name = "unq_scdesiredstate_name",
-        columnNames = { "component_name", "service_name", "cluster_id" }) )
+        columnNames = { "component_name", "service_id" , "service_group_id", 
"cluster_id" }) )
 @TableGenerator(
     name = "servicecomponentdesiredstate_id_generator",
     table = "ambari_sequences",
@@ -59,9 +57,12 @@ import org.apache.commons.lang.builder.EqualsBuilder;
     pkColumnValue = "servicecomponentdesiredstate_id_seq",
     initialValue = 0)
 @NamedQueries({
- @NamedQuery(
+  @NamedQuery(
     name = "ServiceComponentDesiredStateEntity.findByName",
-    query = "SELECT scds FROM ServiceComponentDesiredStateEntity scds WHERE 
scds.clusterId = :clusterId AND scds.serviceName = :serviceName AND 
scds.componentName = :componentName") })
+    query = "SELECT scds FROM ServiceComponentDesiredStateEntity scds WHERE 
scds.clusterId = :clusterId " +
+      "AND scds.serviceGroupId = :serviceGroupId " +
+      "AND scds.serviceId = :serviceId " +
+      "AND scds.componentName = :componentName") })
 public class ServiceComponentDesiredStateEntity {
 
   @Id
@@ -71,14 +72,17 @@ public class ServiceComponentDesiredStateEntity {
       generator = "servicecomponentdesiredstate_id_generator")
   private Long id;
 
+  @Column(name = "component_name", nullable = false, insertable = true, 
updatable = true)
+  private String componentName;
+
   @Column(name = "cluster_id", nullable = false, insertable = false, updatable 
= false, length = 10)
   private Long clusterId;
 
-  @Column(name = "service_name", nullable = false, insertable = false, 
updatable = false)
-  private String serviceName;
+  @Column(name = "service_group_id", nullable = false, insertable = false, 
updatable = false, length = 10)
+  private Long serviceGroupId;
 
-  @Column(name = "component_name", nullable = false, insertable = true, 
updatable = true)
-  private String componentName;
+  @Column(name = "service_id", nullable = false, insertable = false, updatable 
= false, length = 10)
+  private Long serviceId;
 
   @Column(name = "desired_state", nullable = false, insertable = true, 
updatable = true)
   @Enumerated(EnumType.STRING)
@@ -104,7 +108,12 @@ public class ServiceComponentDesiredStateEntity {
   private RepositoryVersionEntity desiredRepositoryVersion;
 
   @ManyToOne
-  @JoinColumns({@javax.persistence.JoinColumn(name = "cluster_id", 
referencedColumnName = "cluster_id", nullable = false), @JoinColumn(name = 
"service_name", referencedColumnName = "service_name", nullable = false)})
+  @JoinColumns(
+    {
+      @JoinColumn(name = "cluster_id", referencedColumnName = "cluster_id", 
nullable = false),
+      @JoinColumn(name = "service_group_id", referencedColumnName = 
"service_group_id", nullable = false),
+      @JoinColumn(name = "service_id", referencedColumnName = "id", nullable = 
false)
+    })
   private ClusterServiceEntity clusterServiceEntity;
 
   @OneToMany(mappedBy = "serviceComponentDesiredStateEntity")
@@ -113,7 +122,9 @@ public class ServiceComponentDesiredStateEntity {
   @OneToMany(mappedBy = "serviceComponentDesiredStateEntity")
   private Collection<HostComponentDesiredStateEntity> 
hostComponentDesiredStateEntities;
 
-  @OneToMany(mappedBy = "m_serviceComponentDesiredStateEntity", cascade = { 
CascadeType.ALL })
+  @OneToMany(
+    mappedBy = "m_serviceComponentDesiredStateEntity",
+    cascade = {CascadeType.ALL})
   private Collection<ServiceComponentVersionEntity> serviceComponentVersions;
 
   public Long getId() {
@@ -128,13 +139,13 @@ public class ServiceComponentDesiredStateEntity {
     this.clusterId = clusterId;
   }
 
-  public String getServiceName() {
-    return serviceName;
-  }
+  public Long getServiceGroupId() { return serviceGroupId; }
 
-  public void setServiceName(String serviceName) {
-    this.serviceName = serviceName;
-  }
+  public void setServiceGroupId(Long serviceGroupId) { this.serviceGroupId = 
serviceGroupId; }
+
+  public Long getServiceId() { return serviceId; }
+
+  public void setServiceId(Long serviceId) { this.serviceId = serviceId; }
 
   public String getComponentName() {
     return componentName;
@@ -210,21 +221,43 @@ public class ServiceComponentDesiredStateEntity {
     }
 
     ServiceComponentDesiredStateEntity that = 
(ServiceComponentDesiredStateEntity) o;
-    EqualsBuilder equalsBuilder = new EqualsBuilder();
-    equalsBuilder.append(id, that.id);
-    equalsBuilder.append(clusterId, that.clusterId);
-    equalsBuilder.append(componentName, that.componentName);
-    equalsBuilder.append(desiredState, that.desiredState);
-    equalsBuilder.append(serviceName, that.serviceName);
-    equalsBuilder.append(desiredRepositoryVersion, 
that.desiredRepositoryVersion);
-
-    return equalsBuilder.isEquals();
+
+    if (id != null ? !id.equals(that.id) : that.id != null) {
+      return false;
+    }
+    if (clusterId != null ? !clusterId.equals(that.clusterId) : that.clusterId 
!= null) {
+      return false;
+    }
+    if (serviceGroupId != null ? !serviceGroupId.equals(that.serviceGroupId) : 
that.serviceGroupId != null) {
+      return false;
+    }
+    if (serviceId != null ? !serviceId.equals(that.serviceId) : that.serviceId 
!= null) {
+      return false;
+    }
+    if (componentName != null ? !componentName.equals(that.componentName) : 
that.componentName != null) {
+      return false;
+    }
+    if (desiredState != null ? !desiredState.equals(that.desiredState) : 
that.desiredState != null) {
+      return false;
+    }
+    if (desiredRepositoryVersion != null ? 
!desiredRepositoryVersion.equals(that.desiredRepositoryVersion)
+      : that.desiredRepositoryVersion != null) {
+      return false;
+    }
+    return true;
   }
 
   @Override
   public int hashCode() {
-    return Objects.hash(id, clusterId, serviceName, componentName, 
desiredState,
-        desiredRepositoryVersion);
+    int result = id != null ? id.hashCode() : 0;
+    result = 31 * result + (clusterId != null ? clusterId.hashCode() : 0);
+    result = 31 * result + (serviceGroupId != null ? serviceGroupId.hashCode() 
: 0);
+    result = 31 * result + (serviceId != null ? serviceId.hashCode() : 0);
+    result = 31 * result + (componentName != null ? componentName.hashCode() : 
0);
+    result = 31 * result + (desiredState != null ? desiredState.hashCode() : 
0);
+    result = 31 * result + (desiredRepositoryVersion != null ? 
desiredRepositoryVersion.hashCode() : 0);
+
+    return result;
   }
 
   public ClusterServiceEntity getClusterServiceEntity() {

http://git-wip-us.apache.org/repos/asf/ambari/blob/f3520c09/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceComponentVersionEntity.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceComponentVersionEntity.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceComponentVersionEntity.java
index ffb3b82..309317a 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceComponentVersionEntity.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceComponentVersionEntity.java
@@ -54,15 +54,17 @@ import 
org.apache.ambari.server.state.RepositoryVersionState;
     name = "ServiceComponentVersionEntity.findByComponent",
     query = "SELECT version FROM ServiceComponentVersionEntity version WHERE " 
+
       "version.m_serviceComponentDesiredStateEntity.clusterId = :clusterId AND 
" +
-      "version.m_serviceComponentDesiredStateEntity.serviceName = :serviceName 
AND " +
+      "version.m_serviceComponentDesiredStateEntity.serviceGroupId = 
:serviceGroupId AND " +
+      "version.m_serviceComponentDesiredStateEntity.serviceId = :serviceId AND 
" +
       "version.m_serviceComponentDesiredStateEntity.componentName = 
:componentName"),
   @NamedQuery(
     name = "ServiceComponentVersionEntity.findByComponentAndVersion",
     query = "SELECT version FROM ServiceComponentVersionEntity version WHERE " 
+
-        "version.m_serviceComponentDesiredStateEntity.clusterId = :clusterId 
AND " +
-        "version.m_serviceComponentDesiredStateEntity.serviceName = 
:serviceName AND " +
-        "version.m_serviceComponentDesiredStateEntity.componentName = 
:componentName AND " +
-        "version.m_repositoryVersion.version = :repoVersion")
+      "version.m_serviceComponentDesiredStateEntity.clusterId = :clusterId AND 
" +
+      "version.m_serviceComponentDesiredStateEntity.serviceGroupId = 
:serviceGroupId AND " +
+      "version.m_serviceComponentDesiredStateEntity.serviceId = :serviceId AND 
" +
+      "version.m_serviceComponentDesiredStateEntity.componentName = 
:componentName AND " +
+      "version.m_repositoryVersion.version = :repoVersion")
 })
 
 public class ServiceComponentVersionEntity {

http://git-wip-us.apache.org/repos/asf/ambari/blob/f3520c09/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceDesiredStateEntity.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceDesiredStateEntity.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceDesiredStateEntity.java
index fc26478..e70b522 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceDesiredStateEntity.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceDesiredStateEntity.java
@@ -1,4 +1,4 @@
-/*
+/**
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
  * distributed with this work for additional information
@@ -18,8 +18,6 @@
 
 package org.apache.ambari.server.orm.entities;
 
-import java.util.Objects;
-
 import javax.persistence.Basic;
 import javax.persistence.Column;
 import javax.persistence.Entity;
@@ -27,12 +25,12 @@ import javax.persistence.EnumType;
 import javax.persistence.Enumerated;
 import javax.persistence.Id;
 import javax.persistence.JoinColumn;
+import javax.persistence.JoinColumns;
 import javax.persistence.ManyToOne;
 import javax.persistence.OneToOne;
 
 import org.apache.ambari.server.state.MaintenanceState;
 import org.apache.ambari.server.state.State;
-import org.apache.commons.lang.builder.EqualsBuilder;
 
 @javax.persistence.IdClass(ServiceDesiredStateEntityPK.class)
 @javax.persistence.Table(name = "servicedesiredstate")
@@ -43,9 +41,13 @@ public class ServiceDesiredStateEntity {
   @Id
   private Long clusterId;
 
-  @Column(name = "service_name", nullable = false, insertable = false, 
updatable = false)
+  @Column(name = "service_group_id", nullable = false, insertable = false, 
updatable = false, length = 10)
+  @Id
+  private Long serviceGroupId;
+
+  @Column(name = "service_id", nullable = false, insertable = false, updatable 
= false, length = 10)
   @Id
-  private String serviceName;
+  private Long serviceId;
 
   @Column(name = "desired_state", nullable = false, insertable = true, 
updatable = true)
   @Enumerated(value = EnumType.STRING)
@@ -63,11 +65,12 @@ public class ServiceDesiredStateEntity {
   private short credentialStoreEnabled = 0;
 
   @OneToOne
-  @javax.persistence.JoinColumns(
-      {
-          @JoinColumn(name = "cluster_id", referencedColumnName = 
"cluster_id", nullable = false),
-          @JoinColumn(name = "service_name", referencedColumnName = 
"service_name", nullable = false)
-      })
+  @JoinColumns(
+    {
+      @JoinColumn(name = "cluster_id", referencedColumnName = "cluster_id", 
nullable = false),
+      @JoinColumn(name = "service_group_id", referencedColumnName = 
"service_group_id", nullable = false),
+      @JoinColumn(name = "service_id", referencedColumnName = "id", nullable = 
false)
+    })
   private ClusterServiceEntity clusterServiceEntity;
 
   /**
@@ -81,16 +84,24 @@ public class ServiceDesiredStateEntity {
     return clusterId;
   }
 
+  public void setServiceGroupId(Long serviceGroupId) {
+    this.serviceGroupId = serviceGroupId;
+  }
+
+  public Long getServiceGroupId() {
+    return serviceGroupId;
+  }
+
   public void setClusterId(Long clusterId) {
     this.clusterId = clusterId;
   }
 
-  public String getServiceName() {
-    return serviceName;
+  public Long getServiceId() {
+    return serviceId;
   }
 
-  public void setServiceName(String serviceName) {
-    this.serviceName = serviceName;
+  public void setServiceId(Long serviceId) {
+    this.serviceId = serviceId;
   }
 
   public State getDesiredState() {
@@ -153,23 +164,42 @@ public class ServiceDesiredStateEntity {
     }
 
     ServiceDesiredStateEntity that = (ServiceDesiredStateEntity) o;
-    EqualsBuilder equalsBuilder = new EqualsBuilder();
-    equalsBuilder.append(clusterId, that.clusterId);
-    equalsBuilder.append(desiredState, that.desiredState);
-    equalsBuilder.append(desiredHostRoleMapping, that.desiredHostRoleMapping);
-    equalsBuilder.append(serviceName, that.serviceName);
-    equalsBuilder.append(desiredRepositoryVersion, 
that.desiredRepositoryVersion);
 
-    return equalsBuilder.isEquals();
+    if (clusterId != null ? !clusterId.equals(that.clusterId) : that.clusterId 
!= null) {
+      return false;
+    }
+
+    if (serviceGroupId != null ? !serviceGroupId.equals(that.serviceGroupId) : 
that.serviceGroupId != null) {
+      return false;
+    }
+
+    if (serviceId != null ? !serviceId.equals(that.serviceId) : that.serviceId 
!= null) {
+      return false;
+    }
+
+    if (desiredState != null ? !desiredState.equals(that.desiredState) : 
that.desiredState != null) {
+      return false;
+    }
+
+    if (desiredHostRoleMapping != that.desiredHostRoleMapping) {
+      return false;
+    }
+
+    if (desiredRepositoryVersion != null ? 
!desiredRepositoryVersion.equals(that.desiredRepositoryVersion) : 
that.desiredRepositoryVersion != null) {
+      return false;
+    }
+    return true;
   }
 
-  /**
-   * {@inheritDoc}
-   */
   @Override
   public int hashCode() {
-    return Objects.hash(clusterId, serviceName, desiredState, 
desiredHostRoleMapping,
-        desiredRepositoryVersion);
+    int result = clusterId != null ? clusterId.intValue() : 0;
+    result = 31 * result + (serviceGroupId != null ? serviceGroupId.hashCode() 
: 0);
+    result = 31 * result + (serviceId != null ? serviceId.hashCode() : 0);
+    result = 31 * result + (desiredState != null ? desiredState.hashCode() : 
0);
+    result = 31 * result + desiredHostRoleMapping;
+    result = 31 * result + (desiredRepositoryVersion != null ? 
desiredRepositoryVersion.hashCode() : 0);
+    return result;
   }
 
   public ClusterServiceEntity getClusterServiceEntity() {
@@ -199,4 +229,4 @@ public class ServiceDesiredStateEntity {
     this.desiredRepositoryVersion = desiredRepositoryVersion;
   }
 
-}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/f3520c09/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceDesiredStateEntityPK.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceDesiredStateEntityPK.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceDesiredStateEntityPK.java
index 3fa5289..47926c3 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceDesiredStateEntityPK.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceDesiredStateEntityPK.java
@@ -1,4 +1,4 @@
-/*
+/**
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
  * distributed with this work for additional information
@@ -37,16 +37,28 @@ public class ServiceDesiredStateEntityPK implements 
Serializable {
     this.clusterId = clusterId;
   }
 
-  private String serviceName;
+  private Long serviceGroupId;
 
+  @Column(name = "service_group_id", nullable = false, insertable = true, 
updatable = true, length = 10)
   @Id
-  @Column(name = "service_name", nullable = false, insertable = true, 
updatable = true, length = 32672, precision = 0)
-  public String getServiceName() {
-    return serviceName;
+  public Long getServiceGroupId() {
+    return serviceGroupId;
   }
 
-  public void setServiceName(String serviceName) {
-    this.serviceName = serviceName;
+  public void setServiceGroupId(Long serviceGroupId) {
+    this.serviceGroupId = serviceGroupId;
+  }
+
+  private Long serviceId;
+
+  @Id
+  @Column(name = "service_id", nullable = false, insertable = true, updatable 
= true, length = 10)
+  public Long getServiceId() {
+    return serviceId;
+  }
+
+  public void setServiceId(Long serviceId) {
+    this.serviceId = serviceId;
   }
 
   @Override
@@ -57,7 +69,8 @@ public class ServiceDesiredStateEntityPK implements 
Serializable {
     ServiceDesiredStateEntityPK that = (ServiceDesiredStateEntityPK) o;
 
     if (clusterId != null ? !clusterId.equals(that.clusterId) : that.clusterId 
!= null) return false;
-    if (serviceName != null ? !serviceName.equals(that.serviceName) : 
that.serviceName != null) return false;
+    if (serviceGroupId != null ? !serviceGroupId.equals(that.serviceGroupId) : 
that.serviceGroupId != null) return false;
+    if (serviceId != null ? !serviceId.equals(that.serviceId) : that.serviceId 
!= null) return false;
 
     return true;
   }
@@ -65,7 +78,8 @@ public class ServiceDesiredStateEntityPK implements 
Serializable {
   @Override
   public int hashCode() {
     int result = clusterId != null ? clusterId.intValue() : 0;
-    result = 31 * result + (serviceName != null ? serviceName.hashCode() : 0);
+    result = 31 * result + (serviceGroupId != null ? serviceGroupId.hashCode() 
: 0);
+    result = 31 * result + (serviceId != null ? serviceId.hashCode() : 0);
     return result;
   }
-}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/f3520c09/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceGroupEntity.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceGroupEntity.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceGroupEntity.java
index cd9d2c8..7f8facb 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceGroupEntity.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ServiceGroupEntity.java
@@ -36,11 +36,11 @@ import javax.persistence.TableGenerator;
 @IdClass(ServiceGroupEntityPK.class)
 @Table(name = "servicegroups")
 @NamedQueries({
-  @NamedQuery(name = "serviceGroupByClusterAndServiceGroupNames", query =
+  @NamedQuery(name = "serviceGroupByClusterAndServiceGroupIds", query =
     "SELECT serviceGroup " +
       "FROM ServiceGroupEntity serviceGroup " +
       "JOIN serviceGroup.clusterEntity cluster " +
-      "WHERE serviceGroup.serviceGroupName=:serviceGroupName AND 
cluster.clusterName=:clusterName")
+      "WHERE serviceGroup.serviceGroupId=:serviceGroupId AND 
cluster.clusterId=:clusterId")
 })
 @Entity
 @TableGenerator(name = "service_group_id_generator",

http://git-wip-us.apache.org/repos/asf/ambari/blob/f3520c09/ambari-server/src/main/java/org/apache/ambari/server/orm/models/HostComponentSummary.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/orm/models/HostComponentSummary.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/orm/models/HostComponentSummary.java
index f5b12b5..9f088ff 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/orm/models/HostComponentSummary.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/orm/models/HostComponentSummary.java
@@ -34,7 +34,9 @@ import com.google.inject.Inject;
 
 @StaticallyInject
 public class HostComponentSummary {
-  private String serviceName;
+  private Long clusterId;
+  private Long serviceGroupId;
+  private Long serviceId;
   private String componentName;
   private Long hostId;
   private String hostName;
@@ -50,8 +52,11 @@ public class HostComponentSummary {
   @Inject
   private static HostComponentDesiredStateDAO hostComponentDesiredStateDao;
 
-  public HostComponentSummary(String serviceName, String componentName, Long 
hostId, State desiredState, State currentState) {
-    this.serviceName = serviceName;
+  public HostComponentSummary(Long clusterId, Long serviceGroupId, Long 
serviceId, String componentName, Long hostId,
+                              State desiredState, State currentState) {
+    this.clusterId = clusterId;
+    this.serviceGroupId = serviceGroupId;
+    this.serviceId = serviceId;
     this.componentName = componentName;
     this.hostId = hostId;
 
@@ -80,16 +85,20 @@ public class HostComponentSummary {
     return currentState;
   }
 
-  public static List<HostComponentSummary> getHostComponentSummaries(String 
serviceName, String componentName) {
+  public static List<HostComponentSummary> getHostComponentSummaries(Long 
clusterId, Long serviceGroupId, Long serviceId,
+                                                                     String 
componentName) {
     List<HostComponentSummary> hostComponentSummaries = new ArrayList<>();
-    List<HostComponentStateEntity> hostComponentStates = 
hostComponentStateDao.findByServiceAndComponent(serviceName, componentName);
+    List<HostComponentStateEntity> hostComponentStates = 
hostComponentStateDao.findByServiceAndComponent(clusterId,
+      serviceGroupId, serviceId, componentName);
 
     if (hostComponentStates != null) {
       for (HostComponentStateEntity hcse : hostComponentStates) {
         // Find the corresponding record for HostComponentDesiredStateEntity
-        HostComponentDesiredStateEntity hcdse = 
hostComponentDesiredStateDao.findByServiceComponentAndHost(hcse.getServiceName(),
 hcse.getComponentName(), hcse.getHostName());
+        HostComponentDesiredStateEntity hcdse = 
hostComponentDesiredStateDao.findByServiceComponentAndHost(
+          clusterId, serviceGroupId, serviceId, hcse.getComponentName(), 
hcse.getHostName());
         if (hcdse != null) {
-          HostComponentSummary s = new 
HostComponentSummary(hcse.getServiceName(), hcse.getComponentName(), 
hcse.getHostId(), hcdse.getDesiredState(), hcse.getCurrentState());
+          HostComponentSummary s = new HostComponentSummary(
+            clusterId, serviceGroupId, serviceId, hcse.getComponentName(), 
hcse.getHostId(), hcdse.getDesiredState(), hcse.getCurrentState());
 
           hostComponentSummaries.add(s);
         }
@@ -101,9 +110,11 @@ public class HostComponentSummary {
   @Override
   public int hashCode() {
     int result = 1;
-    result = 31 + (serviceName != null ? serviceName.hashCode() : 0);
+    result = 31 + (clusterId != null ? clusterId.hashCode() : 0);
+    result = 31 + (serviceGroupId != null ? serviceGroupId.hashCode() : 0);
+    result = 31 + (serviceId != null ? serviceId.hashCode() : 0);
     result = result + (componentName != null ? componentName.hashCode() : 0);
     result = result + (hostId != null ? hostId.hashCode() : 0);
     return result;
   }
-}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/f3520c09/ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java 
b/ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java
index ce4c961..c93ac37 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/Cluster.java
@@ -26,6 +26,7 @@ import java.util.Set;
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.ServiceGroupNotFoundException;
 import org.apache.ambari.server.controller.ClusterResponse;
+import org.apache.ambari.server.controller.ServiceComponentHostResponse;
 import org.apache.ambari.server.controller.ServiceConfigVersionResponse;
 import org.apache.ambari.server.events.ClusterConfigChangedEvent;
 import org.apache.ambari.server.metadata.RoleCommandOrder;
@@ -44,7 +45,7 @@ public interface Cluster {
   /**
    * Get the cluster ID
    */
-  long getClusterId();
+  Long getClusterId();
 
   /**
    * Get the Cluster Name
@@ -68,6 +69,9 @@ public interface Cluster {
    */
   void addService(Service service);
 
+  Service addService(ServiceGroup serviceGroup, String serviceName, String 
serviceDisplayName,
+                     RepositoryVersionEntity repositoryVersion) throws 
AmbariException;
+
   /**
    * Add service group to the cluster
    *
@@ -94,6 +98,8 @@ public interface Cluster {
    */
   Service getService(String serviceName) throws AmbariException;
 
+  Service getService(Long serviceId) throws AmbariException;
+
   /**
    * Gets a service from the given component name.
    *
@@ -110,6 +116,8 @@ public interface Cluster {
    */
   Map<String, Service> getServices();
 
+  Map<Long, Service> getServicesById();
+
   /**
    * Get a service group
    *
@@ -119,6 +127,14 @@ public interface Cluster {
   ServiceGroup getServiceGroup(String serviceGroupName) throws 
ServiceGroupNotFoundException;
 
   /**
+   * Get a service group
+   * @param serviceGroupId
+   * @return
+   */
+  ServiceGroup getServiceGroup(Long serviceGroupId) throws 
ServiceGroupNotFoundException;
+
+
+  /**
    * Get all service groups
    *
    * @return
@@ -189,7 +205,7 @@ public interface Cluster {
    * @param serviceComponentHosts
    * @throws AmbariException
    */
-  void addServiceComponentHosts(Collection<ServiceComponentHost> 
serviceComponentHosts) throws AmbariException;
+  Set<ServiceComponentHostResponse> 
addServiceComponentHosts(Collection<ServiceComponentHost> 
serviceComponentHosts) throws AmbariException;
 
   /**
    * Remove ServiceComponentHost from cluster
@@ -504,18 +520,6 @@ public interface Cluster {
   void delete() throws AmbariException;
 
   /**
-   * Add service to the cluster
-   *
-   * @param serviceName       the name of the service to add (not {@code 
null}).
-   * @param repositoryVersion the repository from which the service should be 
installed (not
-   *                          {@code null}).
-   * @return
-   * @throws AmbariException
-   */
-  Service addService(String serviceName, RepositoryVersionEntity 
repositoryVersion)
-    throws AmbariException;
-
-  /**
    * Fetch desired configs for list of hosts in cluster
    *
    * @param hostIds

http://git-wip-us.apache.org/repos/asf/ambari/blob/f3520c09/ambari-server/src/main/java/org/apache/ambari/server/state/Service.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/state/Service.java 
b/ambari-server/src/main/java/org/apache/ambari/server/state/Service.java
index 65189ca..ce0afa9 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/Service.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/Service.java
@@ -26,11 +26,17 @@ import 
org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
 
 public interface Service {
 
-  String getName();
+  Long getClusterId();
+
+  Long getServiceGroupId();
+
+  String getServiceGroupName();
 
-  String getDisplayName();
+  Long getServiceId();
+
+  String getName();
 
-  long getClusterId();
+  String getServiceDisplayName();
 
   Cluster getCluster();
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/f3520c09/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponent.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponent.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponent.java
index 9fb2aba..dd25992 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponent.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponent.java
@@ -44,12 +44,18 @@ public interface ServiceComponent {
 
   String getServiceName();
 
-  long getClusterId();
+  String getServiceDisplayName();
+
+  Long getServiceGroupId();
+
+  Long getClusterId();
 
   String getClusterName();
 
   State getDesiredState();
 
+  Long getServiceId();
+
   void setDesiredState(State state);
 
   /**

http://git-wip-us.apache.org/repos/asf/ambari/blob/f3520c09/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentHost.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentHost.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentHost.java
index 5ff9e37..1b35072 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentHost.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentHost.java
@@ -33,7 +33,7 @@ public interface ServiceComponentHost {
   /**
    * Get the Cluster that this object maps to
    */
-  long getClusterId();
+  Long getClusterId();
 
   /**
    * Get the Cluster that this object maps to
@@ -41,14 +41,36 @@ public interface ServiceComponentHost {
   String getClusterName();
 
   /**
+   * Get the service group name this object maps to
+   * @return Name of the service group
+   */
+  Long getServiceGroupId();
+
+  /**
    * Get the Service this object maps to
    * @return Name of the Service
    */
   String getServiceName();
 
+  Long getServiceId();
+
+  Long getHostComponentId();
+
   boolean isClientComponent();
 
   /**
+   * Get the service group name this object maps to
+   * @return Name of the service group
+   */
+  String getServiceGroupName();
+
+  /**
+   * Get the Real Service this object maps to
+   * @return Name of the Real Service
+   */
+  String getServiceDisplayName();
+
+  /**
    * Get the ServiceComponent this object maps to
    * @return Name of the ServiceComponent
    */

http://git-wip-us.apache.org/repos/asf/ambari/blob/f3520c09/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentImpl.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentImpl.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentImpl.java
index 5f85e38..aa9b3ef 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentImpl.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceComponentImpl.java
@@ -30,6 +30,7 @@ import java.util.concurrent.locks.ReentrantReadWriteLock;
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.ObjectNotFoundException;
 import org.apache.ambari.server.ServiceComponentHostNotFoundException;
+import org.apache.ambari.server.ServiceGroupNotFoundException;
 import org.apache.ambari.server.api.services.AmbariMetaInfo;
 import org.apache.ambari.server.controller.ServiceComponentResponse;
 import org.apache.ambari.server.events.ServiceComponentRecoveryChangedEvent;
@@ -116,7 +117,8 @@ public class ServiceComponentImpl implements 
ServiceComponent {
     ServiceComponentDesiredStateEntity desiredStateEntity = new 
ServiceComponentDesiredStateEntity();
     desiredStateEntity.setComponentName(componentName);
     desiredStateEntity.setDesiredState(State.INIT);
-    desiredStateEntity.setServiceName(service.getName());
+    desiredStateEntity.setServiceGroupId(service.getServiceGroupId());
+    desiredStateEntity.setServiceId(service.getServiceId());
     desiredStateEntity.setClusterId(service.getClusterId());
     desiredStateEntity.setRecoveryEnabled(false);
     
desiredStateEntity.setDesiredRepositoryVersion(service.getDesiredRepositoryVersion());
@@ -173,7 +175,8 @@ public class ServiceComponentImpl implements 
ServiceComponent {
 
       HostComponentDesiredStateEntity hostComponentDesiredStateEntity = 
hostComponentDesiredStateDAO.findByIndex(
         hostComponentStateEntity.getClusterId(),
-        hostComponentStateEntity.getServiceName(),
+        hostComponentStateEntity.getServiceGroupId(),
+        hostComponentStateEntity.getServiceId(),
         hostComponentStateEntity.getComponentName(),
         hostComponentStateEntity.getHostId()
       );
@@ -253,9 +256,13 @@ public class ServiceComponentImpl implements 
ServiceComponent {
   }
 
   @Override
-  public long getClusterId() {
-    return service.getClusterId();
-  }
+  public String getServiceDisplayName() { return 
service.getServiceDisplayName(); }
+
+  @Override
+  public Long getClusterId() { return service.getClusterId(); }
+
+  @Override
+  public Long getServiceGroupId() { return service.getServiceGroupId(); }
 
   @Override
   public Map<String, ServiceComponentHost> getServiceComponentHosts() {
@@ -342,6 +349,11 @@ public class ServiceComponentImpl implements 
ServiceComponent {
   }
 
   @Override
+  public Long getServiceId() {
+    return service.getServiceId();
+  }
+
+  @Override
   public void setDesiredState(State state) {
     if (LOG.isDebugEnabled()) {
       LOG.debug("Setting DesiredState of Service, clusterName={}, 
clusterId={}, serviceName={}, serviceComponentName={}, oldDesiredState={}, 
newDesiredState={}",
@@ -412,14 +424,20 @@ public class ServiceComponentImpl implements 
ServiceComponent {
   @Override
   public ServiceComponentResponse convertToResponse() {
     Cluster cluster = service.getCluster();
+    ServiceGroup sg = null;
     RepositoryVersionEntity repositoryVersionEntity = 
getDesiredRepositoryVersion();
     StackId desiredStackId = repositoryVersionEntity.getStackId();
 
+    try {
+      sg = cluster.getServiceGroup(service.getServiceGroupId());
+    } catch (ServiceGroupNotFoundException e) {
+      LOG.warn("Service Group " + service.getServiceGroupId() + " not found");
+    }
     ServiceComponentResponse r = new ServiceComponentResponse(getClusterId(),
-        cluster.getClusterName(), service.getName(), getName(),
-        desiredStackId, getDesiredState().toString(),
-        getServiceComponentStateCount(), isRecoveryEnabled(), displayName,
-        repositoryVersionEntity.getVersion(), getRepositoryState());
+        cluster.getClusterName(), sg.getServiceGroupId(), 
sg.getServiceGroupName(), service.getServiceId(),
+        service.getName(), service.getServiceDisplayName(), getName(), 
desiredStackId, getDesiredState().toString(),
+        getServiceComponentStateCount(), isRecoveryEnabled(), displayName, 
repositoryVersionEntity.getVersion(),
+        getRepositoryState());
 
     return r;
   }
@@ -457,7 +475,8 @@ public class ServiceComponentImpl implements 
ServiceComponent {
   protected void persistEntities(ServiceComponentDesiredStateEntity 
desiredStateEntity) {
     ClusterServiceEntityPK pk = new ClusterServiceEntityPK();
     pk.setClusterId(service.getClusterId());
-    pk.setServiceName(service.getName());
+    pk.setServiceGroupId(service.getServiceGroupId());
+    pk.setServiceId(service.getServiceId());
     ClusterServiceEntity serviceEntity = clusterServiceDAO.findByPK(pk);
 
     desiredStateEntity.setClusterServiceEntity(serviceEntity);
@@ -623,7 +642,7 @@ public class ServiceComponentImpl implements 
ServiceComponent {
         desiredStateEntityId);
 
     List<ServiceComponentVersionEntity> componentVersions = 
serviceComponentDesiredStateDAO.findVersions(
-        getClusterId(), getServiceName(), getName());
+      getClusterId(), getServiceGroupId(), getServiceId(), getName());
 
     // per component, this list should be small, so iterating here isn't a big 
deal
     Map<String, ServiceComponentVersionEntity> map = new 
HashMap<>(Maps.uniqueIndex(componentVersions,
@@ -669,11 +688,12 @@ public class ServiceComponentImpl implements 
ServiceComponent {
       String desiredVersion = component.getDesiredVersion();
       RepositoryVersionEntity desiredRepositoryVersion = 
service.getDesiredRepositoryVersion();
 
+      // TODO : is this function call rally required. check ?
       List<HostComponentStateEntity> hostComponents = 
hostComponentDAO.findByServiceAndComponentAndNotVersion(
-          component.getServiceName(), component.getComponentName(), 
reportedVersion);
+        getClusterId(), getServiceGroupId(), getServiceId(), 
component.getComponentName(), reportedVersion);
 
       LOG.debug("{}/{} reportedVersion={}, desiredVersion={}, non-matching 
desired count={}, repo_state={}",
-          component.getServiceName(), component.getComponentName(), 
reportedVersion,
+          component.getServiceId(), component.getComponentName(), 
reportedVersion,
           desiredVersion, hostComponents.size(), 
component.getRepositoryState());
 
       // !!! if we are unknown, that means it's never been set.  Try to 
determine it.

http://git-wip-us.apache.org/repos/asf/ambari/blob/f3520c09/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceFactory.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceFactory.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceFactory.java
index a4c953f..883fa2d 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceFactory.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/state/ServiceFactory.java
@@ -21,6 +21,8 @@ package org.apache.ambari.server.state;
 import org.apache.ambari.server.orm.entities.ClusterServiceEntity;
 import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
 
+import com.google.inject.assistedinject.Assisted;
+
 public interface ServiceFactory {
 
   /**
@@ -28,14 +30,20 @@ public interface ServiceFactory {
    *
    * @param cluster
    *          the cluster the service is for (not {@code null).
+   * @param serviceGroup
+   *          the ServiceGroup for the service
    * @param serviceName
    *          the name of the service (not {@code null).
+   * @param serviceDisplayName
+   *          the display name of the service (not {@code null).
    * @param desiredRepositoryVersion
    *          the repository version of the service (not {@code null).
    * @return
    */
-  Service createNew(Cluster cluster, String serviceName,
-      RepositoryVersionEntity desiredRepositoryVersion);
+  Service createNew(Cluster cluster, ServiceGroup serviceGroup,
+                    @Assisted("serviceName") String serviceName,
+                    @Assisted("serviceDisplayName") String serviceDisplayName,
+                    RepositoryVersionEntity desiredRepositoryVersion);
 
   /**
    * Creates an in-memory representation of a service from an existing database
@@ -43,9 +51,11 @@ public interface ServiceFactory {
    *
    * @param cluster
    *          the cluster the service is installed in (not {@code null).
+   * @param serviceGroup
+   *          the ServiceGroup for the service
    * @param serviceEntity
    *          the entity the existing database entry (not {@code null).
    * @return
    */
-  Service createExisting(Cluster cluster, ClusterServiceEntity serviceEntity);
+  Service createExisting(Cluster cluster, ServiceGroup serviceGroup, 
ClusterServiceEntity serviceEntity);
 }

Reply via email to