ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vbrodets...@apache.org
Subject [2/2] ambari git commit: AMBARI-22614. Fix unit tests in feature branch to make them workable.(vbrodetskyi)
Date Fri, 08 Dec 2017 17:04:41 GMT
AMBARI-22614. Fix unit tests in feature branch to make them workable.(vbrodetskyi)


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

Branch: refs/heads/branch-feature-AMBARI-14714
Commit: bcbacf0c77fb8aa10a4d5e83df8ebb4650982582
Parents: 490808c
Author: Vitaly Brodetskyi <vbrodetskyi@hortonworks.com>
Authored: Fri Dec 8 19:03:20 2017 +0200
Committer: Vitaly Brodetskyi <vbrodetskyi@hortonworks.com>
Committed: Fri Dec 8 19:03:20 2017 +0200

----------------------------------------------------------------------
 .../ambari/server/stack/StackManager.java       |   3 +
 .../ambari/server/state/ServiceFactory.java     |   2 +-
 .../ExecutionCommandWrapperTest.java            |   4 +-
 .../TestActionSchedulerThreading.java           |   4 +-
 .../server/agent/HeartbeatProcessorTest.java    |   4 +-
 .../server/agent/TestHeartbeatHandler.java      |   7 +-
 .../server/agent/TestHeartbeatMonitor.java      |  16 +-
 .../ClusterResourceDefinitionTest.java          |  21 +-
 .../ServiceResourceDefinitionTest.java          |   6 +-
 .../checks/ComponentExistsInRepoCheckTest.java  |   4 +-
 .../configuration/RecoveryConfigHelperTest.java |  19 +-
 .../AmbariManagementControllerImplTest.java     | 112 ++++---
 .../AmbariManagementControllerTest.java         |  32 +-
 .../StackDefinedPropertyProviderTest.java       |  10 +-
 .../internal/UpgradeResourceProviderTest.java   |  16 +-
 .../UpgradeSummaryResourceProviderTest.java     |   4 +-
 .../VersionDefinitionResourceProviderTest.java  |   4 +-
 .../GeneralServiceCalculatedStateTest.java      |   4 +-
 .../HostVersionOutOfSyncListenerTest.java       |   4 +-
 .../apache/ambari/server/orm/OrmTestHelper.java |  18 +-
 .../ambari/server/state/ConfigHelperTest.java   |  14 +-
 .../apache/ambari/server/state/ServiceTest.java |  23 +-
 .../ambari/server/state/UpgradeHelperTest.java  |  45 ++-
 .../server/state/cluster/ClusterImplTest.java   |  12 +-
 .../server/state/cluster/ClusterTest.java       |  29 +-
 .../server/state/cluster/ClustersTest.java      |  14 +-
 .../ConcurrentServiceConfigVersionTest.java     |  15 +-
 ...omponentHostConcurrentWriteDeadlockTest.java |  15 +-
 .../src/test/resources/cluster-settings.xml     | 322 +++++++++++++++++++
 29 files changed, 616 insertions(+), 167 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/bcbacf0c/ambari-server/src/main/java/org/apache/ambari/server/stack/StackManager.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/stack/StackManager.java b/ambari-server/src/main/java/org/apache/ambari/server/stack/StackManager.java
index fc49a24..dc77f19 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/stack/StackManager.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/stack/StackManager.java
@@ -307,6 +307,9 @@ public class StackManager {
         stackEntity.setStackName(stackName);
         stackEntity.setStackVersion(stackVersion);
 
+        //TODO this is hack which should be removed during merge with BP branch
+        stackEntity.setRepoVersion("");
+
         stackDao.create(stackEntity);
       }
     }

http://git-wip-us.apache.org/repos/asf/ambari/blob/bcbacf0c/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 69eb21d..e6673a3 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
@@ -44,7 +44,7 @@ public interface ServiceFactory {
    * @return
    */
   Service createNew(Cluster cluster, ServiceGroup serviceGroup,
-                    @Assisted List<ServiceKey> serviceDependencies,
+                    List<ServiceKey> serviceDependencies,
                     @Assisted("serviceName") String serviceName,
                     @Assisted("serviceType") String serviceType,
                     RepositoryVersionEntity desiredRepositoryVersion);

http://git-wip-us.apache.org/repos/asf/ambari/blob/bcbacf0c/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/ExecutionCommandWrapperTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/ExecutionCommandWrapperTest.java b/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/ExecutionCommandWrapperTest.java
index 19f940f..b674234 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/ExecutionCommandWrapperTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/ExecutionCommandWrapperTest.java
@@ -43,6 +43,7 @@ import org.apache.ambari.server.state.Clusters;
 import org.apache.ambari.server.state.ConfigFactory;
 import org.apache.ambari.server.state.ConfigHelper;
 import org.apache.ambari.server.state.Service;
+import org.apache.ambari.server.state.ServiceGroup;
 import org.apache.ambari.server.state.StackId;
 import org.apache.ambari.server.state.svccomphost.ServiceComponentHostStartEvent;
 import org.apache.ambari.server.utils.StageUtils;
@@ -115,7 +116,8 @@ public class ExecutionCommandWrapperTest {
 
     OrmTestHelper helper = injector.getInstance(OrmTestHelper.class);
     RepositoryVersionEntity repositoryVersion = helper.getOrCreateRepositoryVersion(cluster1);
-    cluster1.addService(null, "HDFS", "", repositoryVersion);
+    ServiceGroup serviceGroup = cluster1.addServiceGroup("CORE");
+    cluster1.addService(serviceGroup, "HDFS", "HDFS", repositoryVersion);
 
     SERVICE_SITE_CLUSTER = new HashMap<>();
     SERVICE_SITE_CLUSTER.put(SERVICE_SITE_NAME1, SERVICE_SITE_VAL1);

http://git-wip-us.apache.org/repos/asf/ambari/blob/bcbacf0c/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionSchedulerThreading.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionSchedulerThreading.java b/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionSchedulerThreading.java
index 22f23c8..6688510 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionSchedulerThreading.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionSchedulerThreading.java
@@ -42,6 +42,7 @@ import org.apache.ambari.server.state.ConfigFactory;
 import org.apache.ambari.server.state.ConfigHelper;
 import org.apache.ambari.server.state.DesiredConfig;
 import org.apache.ambari.server.state.Service;
+import org.apache.ambari.server.state.ServiceGroup;
 import org.apache.ambari.server.state.StackId;
 import org.junit.After;
 import org.junit.Before;
@@ -108,7 +109,8 @@ public class TestActionSchedulerThreading {
     // add a service
     String serviceName = "ZOOKEEPER";
     RepositoryVersionEntity repositoryVersion = ormTestHelper.getOrCreateRepositoryVersion(cluster);
-    Service service = cluster.addService(null, serviceName, "", repositoryVersion);
+    ServiceGroup serviceGroup = cluster.addServiceGroup("CORE");
+    Service service = cluster.addService(serviceGroup, serviceName, serviceName, repositoryVersion);
     String configType = "zoo.cfg";
 
     Map<String, String> properties = new HashMap<>();

http://git-wip-us.apache.org/repos/asf/ambari/blob/bcbacf0c/ambari-server/src/test/java/org/apache/ambari/server/agent/HeartbeatProcessorTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/agent/HeartbeatProcessorTest.java b/ambari-server/src/test/java/org/apache/ambari/server/agent/HeartbeatProcessorTest.java
index 8a6025f..b7b3e46 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/agent/HeartbeatProcessorTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/agent/HeartbeatProcessorTest.java
@@ -75,6 +75,7 @@ import org.apache.ambari.server.state.Host;
 import org.apache.ambari.server.state.HostState;
 import org.apache.ambari.server.state.Service;
 import org.apache.ambari.server.state.ServiceComponentHost;
+import org.apache.ambari.server.state.ServiceGroup;
 import org.apache.ambari.server.state.StackId;
 import org.apache.ambari.server.state.State;
 import org.apache.ambari.server.state.fsm.InvalidStateTransitionException;
@@ -1310,6 +1311,7 @@ public class HeartbeatProcessorTest {
    */
   private Service addService(Cluster cluster, String serviceName) throws AmbariException {
     RepositoryVersionEntity repositoryVersion = helper.getOrCreateRepositoryVersion(cluster);
-    return cluster.addService(null, serviceName, "", repositoryVersion);
+    ServiceGroup serviceGroup = cluster.addServiceGroup("CORE");
+    return cluster.addService(serviceGroup, serviceName, serviceName, repositoryVersion);
   }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/bcbacf0c/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java b/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java
index 50d4733..ba57449 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java
@@ -91,6 +91,7 @@ import org.apache.ambari.server.state.MaintenanceState;
 import org.apache.ambari.server.state.Service;
 import org.apache.ambari.server.state.ServiceComponent;
 import org.apache.ambari.server.state.ServiceComponentHost;
+import org.apache.ambari.server.state.ServiceGroup;
 import org.apache.ambari.server.state.StackId;
 import org.apache.ambari.server.state.State;
 import org.apache.ambari.server.state.fsm.InvalidStateTransitionException;
@@ -1339,6 +1340,9 @@ public class TestHeartbeatHandler {
     componentMap.put("NAMENODE", nnComponent);
 
     expect(service.getServiceComponents()).andReturn(componentMap);
+    expect(service.getServiceId()).andReturn(1L).atLeastOnce();
+    expect(service.getServiceType()).andReturn("HDFS").atLeastOnce();
+    expect(service.getDesiredStackId()).andReturn(dummyStackId).atLeastOnce();
 
     replay(service, nnComponent);
 
@@ -1575,7 +1579,8 @@ public class TestHeartbeatHandler {
    */
   private Service addService(Cluster cluster, String serviceName) throws AmbariException {
     RepositoryVersionEntity repositoryVersion = helper.getOrCreateRepositoryVersion(cluster);
-    return cluster.addService(null, serviceName, "", repositoryVersion);
+    ServiceGroup serviceGroup = cluster.addServiceGroup("CORE");
+    return cluster.addService(serviceGroup, serviceName, serviceName, repositoryVersion);
   }
 
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/bcbacf0c/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatMonitor.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatMonitor.java b/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatMonitor.java
index 4f8c423..69546bf 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatMonitor.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatMonitor.java
@@ -54,6 +54,7 @@ import org.apache.ambari.server.state.HostState;
 import org.apache.ambari.server.state.Service;
 import org.apache.ambari.server.state.ServiceComponent;
 import org.apache.ambari.server.state.ServiceComponentHost;
+import org.apache.ambari.server.state.ServiceGroup;
 import org.apache.ambari.server.state.StackId;
 import org.apache.ambari.server.state.State;
 import org.apache.ambari.server.state.fsm.InvalidStateTransitionException;
@@ -173,7 +174,8 @@ public class TestHeartbeatMonitor {
 
 
     clusters.mapAndPublishHostsToCluster(hostNames, clusterName);
-    Service hdfs = cluster.addService(null, serviceName, "", repositoryVersion);
+    ServiceGroup serviceGroup = cluster.addServiceGroup("CORE");
+    Service hdfs = cluster.addService(serviceGroup, serviceName, serviceName, repositoryVersion);
     hdfs.addServiceComponent(Role.DATANODE.name());
     hdfs.getServiceComponent(Role.DATANODE.name()).addServiceComponentHost(hostname1);
     hdfs.addServiceComponent(Role.NAMENODE.name());
@@ -275,7 +277,8 @@ public class TestHeartbeatMonitor {
 
 
     clusters.mapAndPublishHostsToCluster(hostNames, clusterName);
-    Service hdfs = cluster.addService(null, serviceName, "", repositoryVersion);
+    ServiceGroup serviceGroup = cluster.addServiceGroup("CORE");
+    Service hdfs = cluster.addService(serviceGroup, serviceName, serviceName, repositoryVersion);
     hdfs.addServiceComponent(Role.DATANODE.name());
     hdfs.getServiceComponent(Role.DATANODE.name()).addServiceComponentHost
     (hostname1);
@@ -382,7 +385,8 @@ public class TestHeartbeatMonitor {
 
     clusters.mapAndPublishHostsToCluster(hostNames, clusterName);
 
-    Service hdfs = cluster.addService(null, serviceName, "", repositoryVersion);
+    ServiceGroup serviceGroup = cluster.addServiceGroup("CORE");
+    Service hdfs = cluster.addService(serviceGroup, serviceName, serviceName, repositoryVersion);
     hdfs.addServiceComponent(Role.DATANODE.name());
     hdfs.getServiceComponent(Role.DATANODE.name()).addServiceComponentHost(hostname1);
     hdfs.addServiceComponent(Role.NAMENODE.name());
@@ -463,7 +467,8 @@ public class TestHeartbeatMonitor {
 
     clusters.mapAndPublishHostsToCluster(hostNames, clusterName);
 
-    Service hdfs = cluster.addService(null, serviceName, "", repositoryVersion);
+    ServiceGroup serviceGroup = cluster.addServiceGroup("CORE");
+    Service hdfs = cluster.addService(serviceGroup, serviceName, serviceName, repositoryVersion);
     hdfs.addServiceComponent(Role.DATANODE.name());
     hdfs.getServiceComponent(Role.DATANODE.name()).addServiceComponentHost(hostname1);
     hdfs.addServiceComponent(Role.NAMENODE.name());
@@ -581,7 +586,8 @@ public class TestHeartbeatMonitor {
 
     clusters.mapAndPublishHostsToCluster(hostNames, clusterName);
 
-    Service hdfs = cluster.addService(null, serviceName, "", repositoryVersion);
+    ServiceGroup serviceGroup = cluster.addServiceGroup("CORE");
+    Service hdfs = cluster.addService(serviceGroup, serviceName, serviceName, repositoryVersion);
 
     hdfs.addServiceComponent(Role.DATANODE.name());
     hdfs.getServiceComponent(Role.DATANODE.name()).addServiceComponentHost(hostname1);

http://git-wip-us.apache.org/repos/asf/ambari/blob/bcbacf0c/ambari-server/src/test/java/org/apache/ambari/server/api/resources/ClusterResourceDefinitionTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/api/resources/ClusterResourceDefinitionTest.java b/ambari-server/src/test/java/org/apache/ambari/server/api/resources/ClusterResourceDefinitionTest.java
index fc24d2c..16ce5b4 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/api/resources/ClusterResourceDefinitionTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/api/resources/ClusterResourceDefinitionTest.java
@@ -51,20 +51,19 @@ public class ClusterResourceDefinitionTest {
     Set<SubResourceDefinition> subResources = resource.getSubResourceDefinitions();
 
     assertEquals(14, subResources.size());
-    assertTrue(includesType(subResources, Resource.Type.Service));
-    assertTrue(includesType(subResources, Resource.Type.ServiceGroup));
-    assertTrue(includesType(subResources, Resource.Type.Host));
-    assertTrue(includesType(subResources, Resource.Type.Configuration));
-    assertTrue(includesType(subResources, Resource.Type.Request));
-    assertTrue(includesType(subResources, Resource.Type.Workflow));
-    assertTrue(includesType(subResources, Resource.Type.ConfigGroup));
-    assertTrue(includesType(subResources, Resource.Type.AlertDefinition));
-    assertTrue(includesType(subResources, Resource.Type.ServiceConfigVersion));
-    assertTrue(includesType(subResources, Resource.Type.ClusterPrivilege));
     assertTrue(includesType(subResources, Resource.Type.Alert));
-    assertTrue(includesType(subResources, Resource.Type.ClusterStackVersion));
+    assertTrue(includesType(subResources, Resource.Type.AlertDefinition));
     assertTrue(includesType(subResources, Resource.Type.Artifact));
     assertTrue(includesType(subResources, Resource.Type.ClusterKerberosDescriptor));
+    assertTrue(includesType(subResources, Resource.Type.ClusterPrivilege));
+    assertTrue(includesType(subResources, Resource.Type.ClusterStackVersion));
+    assertTrue(includesType(subResources, Resource.Type.ConfigGroup));
+    assertTrue(includesType(subResources, Resource.Type.Configuration));
+    assertTrue(includesType(subResources, Resource.Type.Host));
+    assertTrue(includesType(subResources, Resource.Type.Request));
+    assertTrue(includesType(subResources, Resource.Type.ServiceConfigVersion));
+    assertTrue(includesType(subResources, Resource.Type.ServiceGroup));
+    assertTrue(includesType(subResources, Resource.Type.Workflow));
   }
 
   @Test

http://git-wip-us.apache.org/repos/asf/ambari/blob/bcbacf0c/ambari-server/src/test/java/org/apache/ambari/server/api/resources/ServiceResourceDefinitionTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/api/resources/ServiceResourceDefinitionTest.java b/ambari-server/src/test/java/org/apache/ambari/server/api/resources/ServiceResourceDefinitionTest.java
index 75319ea..46c17ff 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/api/resources/ServiceResourceDefinitionTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/api/resources/ServiceResourceDefinitionTest.java
@@ -46,10 +46,12 @@ public class ServiceResourceDefinitionTest {
     ResourceDefinition resource = new ServiceResourceDefinition();
     Set<SubResourceDefinition> subResources = resource.getSubResourceDefinitions();
 
-    assertEquals(3, subResources.size());
-    assertTrue(includesType(subResources, Resource.Type.Component));
+    assertEquals(5, subResources.size());
     assertTrue(includesType(subResources, Resource.Type.Alert));
     assertTrue(includesType(subResources, Resource.Type.Artifact));
+    assertTrue(includesType(subResources, Resource.Type.Component));
+    assertTrue(includesType(subResources, Resource.Type.Configuration));
+    assertTrue(includesType(subResources, Resource.Type.ServiceDependency));
   }
 
   private boolean includesType(Set<SubResourceDefinition> resources, Resource.Type type) {

http://git-wip-us.apache.org/repos/asf/ambari/blob/bcbacf0c/ambari-server/src/test/java/org/apache/ambari/server/checks/ComponentExistsInRepoCheckTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/checks/ComponentExistsInRepoCheckTest.java b/ambari-server/src/test/java/org/apache/ambari/server/checks/ComponentExistsInRepoCheckTest.java
index 2fe8ee0..8987b47 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/checks/ComponentExistsInRepoCheckTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/checks/ComponentExistsInRepoCheckTest.java
@@ -133,6 +133,8 @@ public class ComponentExistsInRepoCheckTest extends EasyMockSupport {
     ZK_SERVICE_COMPONENTS.put("ZOOKEEPER_SERVER", m_zookeeperServer);
     FOO_SERVICE_COMPONENTS.put("FOO_COMPONENT", m_fooComponent);
 
+    expect(m_zookeeperService.getServiceType()).andReturn("ZOOKEEPER").anyTimes();
+    expect(m_fooService.getServiceType()).andReturn("FOO_SERVICE").anyTimes();
     expect(m_zookeeperService.getServiceComponents()).andReturn(ZK_SERVICE_COMPONENTS).anyTimes();
     expect(m_fooService.getServiceComponents()).andReturn(FOO_SERVICE_COMPONENTS).anyTimes();
 
@@ -351,4 +353,4 @@ public class ComponentExistsInRepoCheckTest extends EasyMockSupport {
     Assert.assertTrue(check.getFailedOn().contains("FOO_COMPONENT"));
   }
 
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/bcbacf0c/ambari-server/src/test/java/org/apache/ambari/server/configuration/RecoveryConfigHelperTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/configuration/RecoveryConfigHelperTest.java b/ambari-server/src/test/java/org/apache/ambari/server/configuration/RecoveryConfigHelperTest.java
index 040b571..06d773e 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/configuration/RecoveryConfigHelperTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/configuration/RecoveryConfigHelperTest.java
@@ -45,6 +45,7 @@ import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Config;
 import org.apache.ambari.server.state.MaintenanceState;
 import org.apache.ambari.server.state.Service;
+import org.apache.ambari.server.state.ServiceGroup;
 import org.apache.ambari.server.state.StackId;
 import org.apache.ambari.server.state.State;
 import org.apache.ambari.server.utils.EventBusSynchronizer;
@@ -147,7 +148,8 @@ public class RecoveryConfigHelperTest {
     Cluster cluster = heartbeatTestHelper.getDummyCluster();
 
     RepositoryVersionEntity repositoryVersion = helper.getOrCreateRepositoryVersion(cluster);
-    Service hdfs = cluster.addService(null, HDFS, "", repositoryVersion);
+    ServiceGroup serviceGroup = cluster.addServiceGroup("CORE");
+    Service hdfs = cluster.addService(serviceGroup, HDFS, HDFS, repositoryVersion);
 
     hdfs.addServiceComponent(DATANODE).setRecoveryEnabled(true);
     hdfs.getServiceComponent(DATANODE).addServiceComponentHost(DummyHostname1);
@@ -181,7 +183,8 @@ public class RecoveryConfigHelperTest {
       throws Exception {
     Cluster cluster = heartbeatTestHelper.getDummyCluster();
     RepositoryVersionEntity repositoryVersion = helper.getOrCreateRepositoryVersion(cluster);
-    Service hdfs = cluster.addService(null, HDFS, "", repositoryVersion);
+    ServiceGroup serviceGroup = cluster.addServiceGroup("CORE");
+    Service hdfs = cluster.addService(serviceGroup, HDFS, HDFS, repositoryVersion);
 
     hdfs.addServiceComponent(DATANODE).setRecoveryEnabled(true);
     hdfs.getServiceComponent(DATANODE).addServiceComponentHost(DummyHostname1);
@@ -217,7 +220,8 @@ public class RecoveryConfigHelperTest {
       throws Exception {
     Cluster cluster = heartbeatTestHelper.getDummyCluster();
     RepositoryVersionEntity repositoryVersion = helper.getOrCreateRepositoryVersion(cluster);
-    Service hdfs = cluster.addService(null, HDFS, "", repositoryVersion);
+    ServiceGroup serviceGroup = cluster.addServiceGroup("CORE");
+    Service hdfs = cluster.addService(serviceGroup, HDFS, HDFS, repositoryVersion);
 
     hdfs.addServiceComponent(DATANODE).setRecoveryEnabled(true);
     hdfs.getServiceComponent(DATANODE).addServiceComponentHost(DummyHostname1);
@@ -257,7 +261,8 @@ public class RecoveryConfigHelperTest {
       throws Exception {
     Cluster cluster = heartbeatTestHelper.getDummyCluster();
     RepositoryVersionEntity repositoryVersion = helper.getOrCreateRepositoryVersion(cluster);
-    Service hdfs = cluster.addService(null, HDFS, "", repositoryVersion);
+    ServiceGroup serviceGroup = cluster.addServiceGroup("CORE");
+    Service hdfs = cluster.addService(serviceGroup, HDFS, HDFS, repositoryVersion);
 
     hdfs.addServiceComponent(DATANODE).setRecoveryEnabled(true);
     hdfs.getServiceComponent(DATANODE).addServiceComponentHost(DummyHostname1);
@@ -292,7 +297,8 @@ public class RecoveryConfigHelperTest {
       throws Exception {
     Cluster cluster = heartbeatTestHelper.getDummyCluster();
     RepositoryVersionEntity repositoryVersion = helper.getOrCreateRepositoryVersion(cluster);
-    Service hdfs = cluster.addService(null, HDFS, "", repositoryVersion);
+    ServiceGroup serviceGroup = cluster.addServiceGroup("CORE");
+    Service hdfs = cluster.addService(serviceGroup, HDFS, HDFS, repositoryVersion);
 
     hdfs.addServiceComponent(DATANODE).setRecoveryEnabled(true);
     hdfs.getServiceComponent(DATANODE).addServiceComponentHost(DummyHostname1);
@@ -335,7 +341,8 @@ public class RecoveryConfigHelperTest {
     RepositoryVersionEntity repositoryVersion = helper.getOrCreateRepositoryVersion(cluster);
 
     // Add HDFS service with DATANODE component to the cluster
-    Service hdfs = cluster.addService(null, HDFS, "", repositoryVersion);
+    ServiceGroup serviceGroup = cluster.addServiceGroup("CORE");
+    Service hdfs = cluster.addService(serviceGroup, HDFS, HDFS, repositoryVersion);
 
     hdfs.addServiceComponent(DATANODE).setRecoveryEnabled(true);
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/bcbacf0c/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java
index 21cf518..db5df10 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java
@@ -350,8 +350,9 @@ public class AmbariManagementControllerImplTest {
     StackId stackId = createNiceMock(StackId.class);
     ServiceComponent component = createNiceMock(ServiceComponent.class);
 
-    expect(service.getName()).andReturn("service");
+    expect(service.getServiceType()).andReturn("service");
     expect(service.getServiceComponent("component")).andReturn(component);
+    expect(service.getServiceComponents()).andReturn(Collections.singletonMap("component", component)).anyTimes();
     expect(service.getDesiredStackId()).andReturn(stackId);
     expect(stackId.getStackName()).andReturn("stack");
     expect(stackId.getStackVersion()).andReturn("1.0");
@@ -360,7 +361,7 @@ public class AmbariManagementControllerImplTest {
     ComponentInfo compInfo = createNiceMock(ComponentInfo.class);
     expect(serviceInfo.getClientComponent()).andReturn(compInfo);
     expect(compInfo.getName()).andReturn("component");
-    expect(component.getServiceComponentHosts()).andReturn(new HashMap<String, ServiceComponentHost>());
+    expect(component.getServiceComponentHosts()).andReturn(Collections.singletonMap("host", null)).anyTimes();
     expect(ambariMetaInfo.getService("stack", "1.0", "service")).andReturn(serviceInfo);
 
     replay(injector, cluster, service, component, serviceInfo, compInfo, ambariMetaInfo, stackId);
@@ -383,7 +384,7 @@ public class AmbariManagementControllerImplTest {
     ServiceComponent component1 = createNiceMock(ServiceComponent.class);
     ServiceComponent component2 = createNiceMock(ServiceComponent.class);
 
-    expect(service.getName()).andReturn("service");
+    expect(service.getServiceType()).andReturn("service");
     expect(service.getServiceComponent("component")).andThrow(
       new ServiceComponentNotFoundException("cluster", "service", "component", "", ""));
     expect(service.getDesiredStackId()).andReturn(stackId);
@@ -394,8 +395,7 @@ public class AmbariManagementControllerImplTest {
     componentsMap.put("component2", component2);
     expect(service.getServiceComponents()).andReturn(componentsMap);
     expect(component1.getServiceComponentHosts()).andReturn(Collections.emptyMap());
-    expect(component2.getServiceComponentHosts()).andReturn(
-      new HashMap<String, ServiceComponentHost>());
+    expect(component2.getServiceComponentHosts()).andReturn(Collections.singletonMap("host", null)).anyTimes();
 
     ServiceInfo serviceInfo = createNiceMock(ServiceInfo.class);
     ComponentInfo compInfo = createNiceMock(ComponentInfo.class);
@@ -423,7 +423,7 @@ public class AmbariManagementControllerImplTest {
     ServiceComponent component1 = createNiceMock(ServiceComponent.class);
     ServiceComponent component2 = createNiceMock(ServiceComponent.class);
 
-    expect(service.getName()).andReturn("service");
+    expect(service.getServiceType()).andReturn("service");
     expect(service.getDesiredStackId()).andReturn(stackId);
     expect(stackId.getStackName()).andReturn("stack");
     expect(stackId.getStackVersion()).andReturn("1.0");
@@ -432,8 +432,7 @@ public class AmbariManagementControllerImplTest {
     componentsMap.put("component2", component2);
     expect(service.getServiceComponents()).andReturn(componentsMap);
     expect(component1.getServiceComponentHosts()).andReturn(Collections.emptyMap());
-    expect(component2.getServiceComponentHosts()).andReturn(
-      new HashMap<String, ServiceComponentHost>());
+    expect(component2.getServiceComponentHosts()).andReturn(Collections.singletonMap("host", null)).anyTimes();
 
     ServiceInfo serviceInfo = createNiceMock(ServiceInfo.class);
     expect(serviceInfo.getClientComponent()).andReturn(null);
@@ -1044,7 +1043,7 @@ public class AmbariManagementControllerImplTest {
 
     // requests
     ServiceComponentHostRequest request1 = new ServiceComponentHostRequest(
-        "cluster1", null, "component1", "host1", null, null);
+        "cluster1", "CORE", "service1", "component1", "host1", null);
 
     Set<ServiceComponentHostRequest> setRequests = new HashSet<>();
     setRequests.add(request1);
@@ -1066,9 +1065,9 @@ public class AmbariManagementControllerImplTest {
         }}).anyTimes();
 
     expect(cluster.getService("service1")).andReturn(service);
-    expect(cluster.getServiceByComponentName("component1")).andReturn(service);
+    expect(cluster.getServiceByComponentName("component1")).andReturn(service).anyTimes();
+    expect(service.getName()).andReturn("service1").anyTimes();
     expect(service.getServiceComponent("component1")).andReturn(component);
-    expect(service.getName()).andReturn("service1");
     expect(component.getName()).andReturn("component1");
     expect(component.getServiceComponentHosts()).andReturn(
         new HashMap<String, ServiceComponentHost>() {{
@@ -1111,7 +1110,7 @@ public class AmbariManagementControllerImplTest {
 
     // requests
     ServiceComponentHostRequest request1 = new ServiceComponentHostRequest(
-        "cluster1", null, "component1", "host1", null, null);
+        "cluster1", "CORE", "service1", "component1", "host1", null);
 
 
     Set<ServiceComponentHostRequest> setRequests = new HashSet<>();
@@ -1133,10 +1132,9 @@ public class AmbariManagementControllerImplTest {
 //    expect(stack.getStackVersion()).andReturn("stackVersion");
 //
 //    expect(ambariMetaInfo.getComponentToService("stackName", "stackVersion", "component1")).andReturn("service1");
-    expect(cluster.getService("service1")).andReturn(service);
-    expect(cluster.getServiceByComponentName("component1")).andReturn(service);
-    expect(service.getServiceComponent("component1")).andReturn(component);
-    expect(service.getName()).andReturn("service1");
+//    expect(cluster.getService("service1")).andReturn(service);
+    expect(cluster.getServiceByComponentName("component1")).andReturn(service).anyTimes();
+//    expect(service.getServiceComponent("component1")).andReturn(component);
     expect(component.getName()).andReturn("component1").anyTimes();
     expect(component.getServiceComponentHosts()).andReturn(null);
 
@@ -1177,7 +1175,7 @@ public class AmbariManagementControllerImplTest {
 
     // requests
     ServiceComponentHostRequest request1 = new ServiceComponentHostRequest(
-        "cluster1", null, "component1", "host1", null, null);
+        "cluster1", "CORE", "service1", "component1", "host1", null);
     request1.setState("INSTALLED");
 
 
@@ -1209,9 +1207,9 @@ public class AmbariManagementControllerImplTest {
 //    expect(ambariMetaInfo.getComponentToService("stackName", "stackVersion", "component1")).andReturn("service1");
     expect(cluster.getClusterName()).andReturn("cl1");
     expect(cluster.getService("service1")).andReturn(service);
-    expect(cluster.getServiceByComponentName("component1")).andReturn(service);
+    expect(cluster.getServiceByComponentName("component1")).andReturn(service).anyTimes();
     expect(service.getServiceComponent("component1")).andReturn(component);
-    expect(service.getName()).andReturn("service1");
+    expect(service.getName()).andReturn("service1").anyTimes();
     expect(component.getName()).andReturn("component1").anyTimes();
     expect(component.getServiceComponentHosts()).andReturn(new HashMap<String, ServiceComponentHost>() {{
       put("host1", componentHost1);
@@ -1254,7 +1252,7 @@ public class AmbariManagementControllerImplTest {
 
     // requests
     ServiceComponentHostRequest request1 = new ServiceComponentHostRequest(
-        "cluster1", null, "component1", "host1", null, null);
+        "cluster1", "CORE", "service1", "component1", "host1", null);
     request1.setMaintenanceState("ON");
 
 
@@ -1281,9 +1279,9 @@ public class AmbariManagementControllerImplTest {
 
     expect(cluster.getClusterName()).andReturn("cl1");
     expect(cluster.getService("service1")).andReturn(service);
-    expect(cluster.getServiceByComponentName("component1")).andReturn(service);
+    expect(cluster.getServiceByComponentName("component1")).andReturn(service).anyTimes();
     expect(service.getServiceComponent("component1")).andReturn(component);
-    expect(service.getName()).andReturn("service1");
+    expect(service.getName()).andReturn("service1").anyTimes();
     expect(component.getName()).andReturn("component1").anyTimes();
     expect(component.getServiceComponentHosts()).andReturn(new HashMap<String, ServiceComponentHost>() {{
       put("host1", componentHost1);
@@ -1338,13 +1336,13 @@ public class AmbariManagementControllerImplTest {
 
     // requests
     ServiceComponentHostRequest request1 = new ServiceComponentHostRequest(
-        "cluster1", null, "component1", "host1", null, null);
+        "cluster1", "CORE", "service1", "component1", "host1", null);
 
     ServiceComponentHostRequest request2 = new ServiceComponentHostRequest(
-        "cluster1", null, "component2", "host1", null, null);
+        "cluster1", "CORE", "service1", "component2", "host1", null);
 
     ServiceComponentHostRequest request3 = new ServiceComponentHostRequest(
-        "cluster1", null, "component3", "host1", null, null);
+        "cluster1", "CORE", "service1", "component3", "host1", null);
 
 
     Set<ServiceComponentHostRequest> setRequests = new HashSet<>();
@@ -1365,7 +1363,7 @@ public class AmbariManagementControllerImplTest {
     expect(clusters.getClustersForHost("host1")).andReturn(Collections.singleton(cluster)).anyTimes();
     expect(cluster.getService("service1")).andReturn(service).times(3);
 
-    expect(cluster.getServiceByComponentName("component1")).andReturn(service);
+    expect(cluster.getServiceByComponentName("component1")).andReturn(service).anyTimes();
     expect(service.getServiceComponent("component1")).andReturn(component1);
     expect(service.getName()).andReturn("service1").anyTimes();
     expect(component1.getName()).andReturn("component1");
@@ -1376,13 +1374,13 @@ public class AmbariManagementControllerImplTest {
     expect(componentHost1.convertToResponse(null)).andReturn(response1);
     expect(componentHost1.getHostName()).andReturn("host1");
 
-    expect(cluster.getServiceByComponentName("component2")).andReturn(service);
+    expect(cluster.getServiceByComponentName("component2")).andReturn(service).anyTimes();
     expect(service.getServiceComponent("component2")).andReturn(component2);
     expect(component2.getName()).andReturn("component2");
     expect(component2.getServiceComponentHosts()).andReturn(null);
     expect(componentHost2.getHostName()).andReturn("host1");
 
-    expect(cluster.getServiceByComponentName("component3")).andReturn(service);
+    expect(cluster.getServiceByComponentName("component3")).andReturn(service).anyTimes();
     expect(service.getServiceComponent("component3")).andReturn(component3);
     expect(component3.getName()).andReturn("component3");
     expect(component3.getServiceComponentHosts()).andReturn(
@@ -1437,13 +1435,13 @@ public class AmbariManagementControllerImplTest {
 
     // requests
     ServiceComponentHostRequest request1 = new ServiceComponentHostRequest(
-        "cluster1", null, "component1", "host1", null, null);
+        "cluster1", "CORE", "service1", "component1", "host1", null);
 
     ServiceComponentHostRequest request2 = new ServiceComponentHostRequest(
-        "cluster1", null, "component2", "host1", null, null);
+        "cluster1", "CORE", "service2", "component2", "host1", null);
 
     ServiceComponentHostRequest request3 = new ServiceComponentHostRequest(
-        "cluster1", null, "component3", "host1", null, null);
+        "cluster1", "CORE", "service1", "component3", "host1", null);
 
 
     Set<ServiceComponentHostRequest> setRequests = new HashSet<>();
@@ -1471,8 +1469,7 @@ public class AmbariManagementControllerImplTest {
 
 //    expect(ambariMetaInfo.getComponentToService("stackName", "stackVersion", "component1")).andReturn("service1");
     expect(cluster.getService("service1")).andReturn(service);
-    expect(cluster.getServiceByComponentName("component1")).andReturn(service);
-    expect(service.getName()).andReturn("service1").atLeastOnce();
+    expect(cluster.getServiceByComponentName("component1")).andReturn(service).anyTimes();
     expect(service.getServiceComponent("component1")).andReturn(component1);
     expect(component1.getName()).andReturn("component1");
     expect(component1.getServiceComponentHosts()).andReturn(new
@@ -1482,10 +1479,11 @@ public class AmbariManagementControllerImplTest {
     expect(componentHost1.convertToResponse(null)).andReturn(response1);
     expect(componentHost1.getHostName()).andReturn("host1");
 
-    expect(cluster.getServiceByComponentName("component2")).andThrow(new ServiceNotFoundException("cluster1", "service2"));
+    expect(cluster.getService("service2")).andThrow(new ServiceNotFoundException("cluster1", "service2"));
 
     expect(cluster.getService("service1")).andReturn(service);
-    expect(cluster.getServiceByComponentName("component3")).andReturn(service);
+    expect(service.getName()).andReturn("service1").anyTimes();
+    expect(cluster.getServiceByComponentName("component3")).andReturn(service).anyTimes();
     expect(service.getServiceComponent("component3")).andReturn(component3);
     expect(component3.getName()).andReturn("component3");
     expect(component3.getServiceComponentHosts()).andReturn(new
@@ -1543,13 +1541,13 @@ public class AmbariManagementControllerImplTest {
 
     // requests
     ServiceComponentHostRequest request1 = new ServiceComponentHostRequest(
-        "cluster1", null, "component1", "host1", null, null);
+        "cluster1", "CORE", "service1", "component1", "host1", null);
 
     ServiceComponentHostRequest request2 = new ServiceComponentHostRequest(
-        "cluster1", null, "component2", "host1", null, null);
+        "cluster1", "CORE", "service2", "component2", "host1", null);
 
     ServiceComponentHostRequest request3 = new ServiceComponentHostRequest(
-        "cluster1", null, "component3", "host1", null, null);
+        "cluster1", "CORE", "service1", "component3", "host1", null);
 
 
     Set<ServiceComponentHostRequest> setRequests = new HashSet<>();
@@ -1577,9 +1575,8 @@ public class AmbariManagementControllerImplTest {
 
 //    expect(ambariMetaInfo.getComponentToService("stackName", "stackVersion", "component1")).andReturn("service1");
     expect(cluster.getService("service1")).andReturn(service);
-    expect(cluster.getServiceByComponentName("component1")).andReturn(service);
+    expect(cluster.getServiceByComponentName("component1")).andReturn(service).anyTimes();
     expect(service.getServiceComponent("component1")).andReturn(component);
-    expect(service.getName()).andReturn("service1").anyTimes();
     expect(component.getName()).andReturn("component1");
     expect(component.getServiceComponentHosts()).andReturn(ImmutableMap.<String, ServiceComponentHost>builder()
         .put("host1", componentHost1)
@@ -1589,14 +1586,13 @@ public class AmbariManagementControllerImplTest {
 
 //    expect(ambariMetaInfo.getComponentToService("stackName", "stackVersion", "component2")).andReturn("service2");
     expect(cluster.getService("service2")).andReturn(service2);
-    expect(cluster.getServiceByComponentName("component2")).andReturn(service2);
-    expect(service2.getName()).andReturn("service2");
+    expect(cluster.getServiceByComponentName("component2")).andReturn(service2).anyTimes();
     expect(service2.getServiceComponent("component2")).
         andThrow(new ServiceComponentNotFoundException("cluster1", "service2", "component2", "", ""));
 
 //    expect(ambariMetaInfo.getComponentToService("stackName", "stackVersion", "component3")).andReturn("service1");
     expect(cluster.getService("service1")).andReturn(service);
-    expect(cluster.getServiceByComponentName("component3")).andReturn(service);
+    expect(cluster.getServiceByComponentName("component3")).andReturn(service).anyTimes();
     expect(service.getServiceComponent("component3")).andReturn(component3);
 
     expect(component3.getName()).andReturn("component3");
@@ -1653,13 +1649,13 @@ public class AmbariManagementControllerImplTest {
 
     // requests
     ServiceComponentHostRequest request1 = new ServiceComponentHostRequest(
-        "cluster1", null, "component1", null, null, null);
+        "cluster1", "CORE", "service1", "component1", null, null);
 
     ServiceComponentHostRequest request2 = new ServiceComponentHostRequest(
-        "cluster1", null, "component2", "host2", null, null);
+        "cluster1", "CORE", "service1", "component2", "host2", null);
 
     ServiceComponentHostRequest request3 = new ServiceComponentHostRequest(
-        "cluster1", null, "component3", null, null, null);
+        "cluster1", "CORE", "service1", "component3", null, null);
 
 
     Set<ServiceComponentHostRequest> setRequests = new HashSet<>();
@@ -1686,7 +1682,7 @@ public class AmbariManagementControllerImplTest {
     expect(stack.getStackVersion()).andReturn("stackVersion").anyTimes();
 
     expect(cluster.getService("service1")).andReturn(service);
-    expect(cluster.getServiceByComponentName("component1")).andReturn(service);
+    expect(cluster.getServiceByComponentName("component1")).andReturn(service).anyTimes();
     expect(service.getServiceComponent("component1")).andReturn(component);
     expect(service.getName()).andReturn("service1").anyTimes();
     expect(component.getName()).andReturn("component1");
@@ -1697,7 +1693,7 @@ public class AmbariManagementControllerImplTest {
     expect(clusters.getClustersForHost("host2")).andThrow(new HostNotFoundException("host2"));
 
     expect(cluster.getService("service1")).andReturn(service);
-    expect(cluster.getServiceByComponentName("component3")).andReturn(service);
+    expect(cluster.getServiceByComponentName("component3")).andReturn(service).anyTimes();
     expect(service.getServiceComponent("component3")).andReturn(component3);
     expect(component3.getName()).andReturn("component3");
     expect(component3.getServiceComponentHosts()).andReturn(Collections.singletonMap("foo", componentHost2));
@@ -1738,13 +1734,13 @@ public class AmbariManagementControllerImplTest {
 
     // requests
     ServiceComponentHostRequest request1 = new ServiceComponentHostRequest(
-        "cluster1", null, "component1", "host1", null, null);
+        "cluster1", "CORE", "service1", "component1", "host1", null);
 
     ServiceComponentHostRequest request2 = new ServiceComponentHostRequest(
-        "cluster1", null, "component2", "host1", null, null);
+        "cluster1", "CORE", "service1", "component2", "host1", null);
 
     ServiceComponentHostRequest request3 = new ServiceComponentHostRequest(
-        "cluster1", null, "component3", "host1", null, null);
+        "cluster1", "CORE", "service1", "component3", "host1", null);
 
 
     Set<ServiceComponentHostRequest> setRequests = new HashSet<>();
@@ -1793,13 +1789,13 @@ public class AmbariManagementControllerImplTest {
 
     // requests
     ServiceComponentHostRequest request1 = new ServiceComponentHostRequest(
-        "cluster1", null, "component1", "host1", null, null);
+        "cluster1", "CORE", "service1", "component1", "host1", null);
 
     ServiceComponentHostRequest request2 = new ServiceComponentHostRequest(
-        "cluster1", null, "component2", "host2", null, null);
+        "cluster1", "CORE", "service1", "component2", "host2", null);
 
     ServiceComponentHostRequest request3 = new ServiceComponentHostRequest(
-        "cluster1", null, "component3", "host1", null, null);
+        "cluster1", "CORE", "service1", "component3", "host1", null);
 
 
     Set<ServiceComponentHostRequest> setRequests = new HashSet<>();
@@ -1858,7 +1854,7 @@ public class AmbariManagementControllerImplTest {
 
     // requests
     ServiceComponentHostRequest request1 = new ServiceComponentHostRequest(
-        "cluster1", null, "component1", null, null, null);
+        "cluster1", "CORE", "service1", "component1", null, null);
 
 
     Set<ServiceComponentHostRequest> setRequests = new HashSet<>();
@@ -1884,10 +1880,10 @@ public class AmbariManagementControllerImplTest {
         }}).anyTimes();
 
     expect(cluster.getService("service1")).andReturn(service);
+    expect(service.getName()).andReturn("service1").anyTimes();
     expect(component.getName()).andReturn("component1").anyTimes();
-    expect(cluster.getServiceByComponentName("component1")).andReturn(service);
+    expect(cluster.getServiceByComponentName("component1")).andReturn(service).anyTimes();
     expect(service.getServiceComponent("component1")).andReturn(component);
-    expect(service.getName()).andReturn("service1");
     expect(component.getServiceComponentHosts()).andReturn(mapHostComponents);
     expect(componentHost1.convertToResponse(null)).andReturn(response1);
     expect(componentHost2.convertToResponse(null)).andReturn(response2);
@@ -1938,7 +1934,7 @@ public class AmbariManagementControllerImplTest {
 
     // requests
     ServiceComponentHostRequest request1 = new ServiceComponentHostRequest(
-        "cluster1", null, null, null, null, null);
+        "cluster1", "CORE", null, null, null, null);
 
 
     Set<ServiceComponentHostRequest> setRequests = new HashSet<>();

http://git-wip-us.apache.org/repos/asf/ambari/blob/bcbacf0c/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
index 5c6f374..e584322 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
@@ -136,6 +136,7 @@ import org.apache.ambari.server.state.ServiceComponentFactory;
 import org.apache.ambari.server.state.ServiceComponentHost;
 import org.apache.ambari.server.state.ServiceComponentHostFactory;
 import org.apache.ambari.server.state.ServiceFactory;
+import org.apache.ambari.server.state.ServiceGroup;
 import org.apache.ambari.server.state.ServiceInfo;
 import org.apache.ambari.server.state.ServiceOsSpecific;
 import org.apache.ambari.server.state.StackId;
@@ -3925,8 +3926,9 @@ public class AmbariManagementControllerTest {
 
     RepositoryVersionEntity repositoryVersion = repositoryVersion206;
 
-    Service hdfs = cluster.addService(null, "HDFS", "", repositoryVersion);
-    Service mapred = cluster.addService(null, "YARN", "", repositoryVersion);
+    ServiceGroup serviceGroup = cluster.addServiceGroup("CORE");
+    Service hdfs = cluster.addService(serviceGroup, "HDFS", "HDFS", repositoryVersion);
+    Service mapred = cluster.addService(serviceGroup, "YARN", "YARN", repositoryVersion);
 
     hdfs.addServiceComponent(Role.HDFS_CLIENT.name());
     hdfs.addServiceComponent(Role.NAMENODE.name());
@@ -4088,7 +4090,8 @@ public class AmbariManagementControllerTest {
 
     RepositoryVersionEntity repositoryVersion = repositoryVersion207;
 
-    Service hdfs = cluster.addService(null, "HDFS", "", repositoryVersion);
+    ServiceGroup serviceGroup = cluster.addServiceGroup("CORE");
+    Service hdfs = cluster.addService(serviceGroup, "HDFS", "HDFS", repositoryVersion);
 
     hdfs.addServiceComponent(Role.HDFS_CLIENT.name());
     hdfs.addServiceComponent(Role.NAMENODE.name());
@@ -4195,8 +4198,9 @@ public class AmbariManagementControllerTest {
     cluster.addDesiredConfig("_test", Collections.singleton(config1));
     cluster.addDesiredConfig("_test", Collections.singleton(config2));
 
-    Service hdfs = cluster.addService(null, "HDFS", "", repositoryVersion);
-    Service hive = cluster.addService(null, "HIVE", "", repositoryVersion);
+    ServiceGroup serviceGroup = cluster.addServiceGroup("CORE");
+    Service hdfs = cluster.addService(serviceGroup, "HDFS", "HDFS", repositoryVersion);
+    Service hive = cluster.addService(serviceGroup, "HIVE", "HIVE", repositoryVersion);
 
     hdfs.addServiceComponent(Role.HDFS_CLIENT.name());
     hdfs.addServiceComponent(Role.NAMENODE.name());
@@ -4467,8 +4471,9 @@ public class AmbariManagementControllerTest {
     cluster.addDesiredConfig("_test", Collections.singleton(config1));
     cluster.addDesiredConfig("_test", Collections.singleton(config2));
 
-    Service hdfs = cluster.addService(null, "HDFS", "", repositoryVersion);
-    Service mapReduce = cluster.addService(null, "MAPREDUCE", "", repositoryVersion);
+    ServiceGroup serviceGroup = cluster.addServiceGroup("CORE");
+    Service hdfs = cluster.addService(serviceGroup, "HDFS", "HDFS", repositoryVersion);
+    Service mapReduce = cluster.addService(serviceGroup, "MAPREDUCE", "MAPREDUCE", repositoryVersion);
 
     hdfs.addServiceComponent(Role.HDFS_CLIENT.name());
     mapReduce.addServiceComponent(Role.MAPREDUCE_CLIENT.name());
@@ -6131,8 +6136,9 @@ public class AmbariManagementControllerTest {
         put("key1", "value1");
       }}, new HashMap<>());
 
-    Service hdfs = cluster.addService(null, "HDFS", "", repositoryVersion);
-    Service mapred = cluster.addService(null, "YARN", "",  repositoryVersion);
+    ServiceGroup serviceGroup = cluster.addServiceGroup("CORE");
+    Service hdfs = cluster.addService(serviceGroup, "HDFS", "HDFS", repositoryVersion);
+    Service mapred = cluster.addService(serviceGroup, "YARN", "YARN",  repositoryVersion);
 
     hdfs.addServiceComponent(Role.HDFS_CLIENT.name());
     hdfs.addServiceComponent(Role.NAMENODE.name());
@@ -6234,8 +6240,9 @@ public class AmbariManagementControllerTest {
         put("key1", "value1");
       }}, new HashMap<>());
 
-    Service hdfs = cluster.addService(null, "HDFS", "", repositoryVersion);
-    Service mapred = cluster.addService(null, "YARN", "", repositoryVersion);
+    ServiceGroup serviceGroup = cluster.addServiceGroup("CORE");
+    Service hdfs = cluster.addService(serviceGroup, "HDFS", "HDFS", repositoryVersion);
+    Service mapred = cluster.addService(serviceGroup, "YARN", "YARN", repositoryVersion);
 
     hdfs.addServiceComponent(Role.HDFS_CLIENT.name());
     hdfs.addServiceComponent(Role.NAMENODE.name());
@@ -9163,7 +9170,8 @@ public class AmbariManagementControllerTest {
 
     RepositoryVersionEntity repositoryVersion = repositoryVersion120;
 
-    Service hdfs = c1.addService(null, "HDFS", "", repositoryVersion);
+    ServiceGroup serviceGroup = c1.addServiceGroup("CORE");
+    Service hdfs = c1.addService(serviceGroup, "HDFS", "HDFS", repositoryVersion);
     createServiceComponent(cluster1, "HDFS", "NAMENODE", State.INIT);
     createServiceComponent(cluster1, "HDFS", "DATANODE", State.INIT);
     createServiceComponent(cluster1, "HDFS", "HDFS_CLIENT", State.INIT);

http://git-wip-us.apache.org/repos/asf/ambari/blob/bcbacf0c/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/StackDefinedPropertyProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/StackDefinedPropertyProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/StackDefinedPropertyProviderTest.java
index aee1952..d94810c 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/StackDefinedPropertyProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/StackDefinedPropertyProviderTest.java
@@ -64,6 +64,7 @@ import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Clusters;
 import org.apache.ambari.server.state.Host;
 import org.apache.ambari.server.state.Service;
+import org.apache.ambari.server.state.ServiceGroup;
 import org.apache.ambari.server.state.StackId;
 import org.apache.ambari.server.state.services.MetricsRetrievalService;
 import org.apache.ambari.server.state.stack.Metric;
@@ -139,22 +140,23 @@ public class StackDefinedPropertyProviderTest {
 
     cluster.setDesiredStackVersion(stackId);
     RepositoryVersionEntity repositoryVersion = helper.getOrCreateRepositoryVersion(stackId, stackId.getStackVersion());
-    Service service = cluster.addService(null, "HDFS", "", repositoryVersion);
+    ServiceGroup serviceGroup = cluster.addServiceGroup("CORE");
+    Service service = cluster.addService(serviceGroup, "HDFS", "HDFS", repositoryVersion);
     service.addServiceComponent("NAMENODE");
     service.addServiceComponent("DATANODE");
     service.addServiceComponent("JOURNALNODE");
 
-    service = cluster.addService(null, "YARN", "", repositoryVersion);
+    service = cluster.addService(serviceGroup, "YARN", "YARN", repositoryVersion);
     service.addServiceComponent("RESOURCEMANAGER");
 
-    service = cluster.addService(null, "HBASE", "", repositoryVersion);
+    service = cluster.addService(serviceGroup, "HBASE", "HBASE", repositoryVersion);
     service.addServiceComponent("HBASE_MASTER");
     service.addServiceComponent("HBASE_REGIONSERVER");
 
     stackId = new StackId("HDP-2.1.1");
     repositoryVersion = helper.getOrCreateRepositoryVersion(stackId, stackId.getStackVersion());
 
-    service = cluster.addService(null, "STORM", "", repositoryVersion);
+    service = cluster.addService(serviceGroup, "STORM", "STORM", repositoryVersion);
     service.addServiceComponent("STORM_REST_API");
 
     clusters.addHost("h1");

http://git-wip-us.apache.org/repos/asf/ambari/blob/bcbacf0c/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderTest.java
index 9e6b98b..dcd7ccd 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderTest.java
@@ -99,6 +99,7 @@ import org.apache.ambari.server.state.RepositoryType;
 import org.apache.ambari.server.state.Service;
 import org.apache.ambari.server.state.ServiceComponent;
 import org.apache.ambari.server.state.ServiceComponentHost;
+import org.apache.ambari.server.state.ServiceGroup;
 import org.apache.ambari.server.state.StackId;
 import org.apache.ambari.server.state.UpgradeContext;
 import org.apache.ambari.server.state.UpgradeHelper;
@@ -262,7 +263,8 @@ public class UpgradeResourceProviderTest extends EasyMockSupport {
     clusters.mapHostToCluster("h1", "c1");
 
     // add a single ZK server and client on 2.1.1.0
-    Service service = cluster.addService(null, "ZOOKEEPER", "", repoVersionEntity2110);
+    ServiceGroup serviceGroup = cluster.addServiceGroup("CORE");
+    Service service = cluster.addService(serviceGroup, "ZOOKEEPER", "ZOOKEEPER", repoVersionEntity2110);
     ServiceComponent component = service.addServiceComponent("ZOOKEEPER_SERVER");
     ServiceComponentHost sch = component.addServiceComponentHost("h1");
     sch.setVersion("2.1.1.0");
@@ -782,7 +784,8 @@ public class UpgradeResourceProviderTest extends EasyMockSupport {
     Cluster cluster = clusters.getCluster("c1");
 
     // add additional service for the test
-    Service service = cluster.addService(null, "HIVE", "", repoVersionEntity2110);
+    ServiceGroup serviceGroup = cluster.addServiceGroup("CORE");
+    Service service = cluster.addService(serviceGroup, "HIVE", "HIVE", repoVersionEntity2110);
 
     ServiceComponent component = service.addServiceComponent("HIVE_SERVER");
     ServiceComponentHost sch = component.addServiceComponentHost("h1");
@@ -1465,7 +1468,8 @@ public class UpgradeResourceProviderTest extends EasyMockSupport {
   @Test
   public void testCreateUpgradeDowngradeCycleAdvertisingVersion() throws Exception {
     Cluster cluster = clusters.getCluster("c1");
-    Service service = cluster.addService(null, "STORM", "", repoVersionEntity2110);
+    ServiceGroup serviceGroup = cluster.addServiceGroup("CORE");
+    Service service = cluster.addService(serviceGroup, "STORM", "STORM", repoVersionEntity2110);
 
     ServiceComponent component = service.addServiceComponent("DRPC_SERVER");
     ServiceComponentHost sch = component.addServiceComponentHost("h1");
@@ -1648,7 +1652,8 @@ public class UpgradeResourceProviderTest extends EasyMockSupport {
     Cluster cluster = clusters.getCluster("c1");
 
     // add a single ZK server and client on 2.1.1.0
-    Service service = cluster.addService(null, "HBASE", "", repoVersionEntity2110);
+    ServiceGroup serviceGroup = cluster.addServiceGroup("CORE");
+    Service service = cluster.addService(serviceGroup, "HBASE", "HBASE", repoVersionEntity2110);
     ServiceComponent component = service.addServiceComponent("HBASE_MASTER");
     ServiceComponentHost sch = component.addServiceComponentHost("h1");
     sch.setVersion("2.1.1.0");
@@ -1735,7 +1740,8 @@ public class UpgradeResourceProviderTest extends EasyMockSupport {
     Cluster cluster = clusters.getCluster("c1");
 
     // add a single ZK server and client on 2.1.1.0
-    Service service = cluster.addService(null, "HBASE", "", repoVersionEntity2110);
+    ServiceGroup serviceGroup = cluster.addServiceGroup("CORE");
+    Service service = cluster.addService(serviceGroup, "HBASE", "HBASE", repoVersionEntity2110);
     ServiceComponent component = service.addServiceComponent("HBASE_MASTER");
     ServiceComponentHost sch = component.addServiceComponentHost("h1");
     sch.setVersion("2.1.1.0");

http://git-wip-us.apache.org/repos/asf/ambari/blob/bcbacf0c/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeSummaryResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeSummaryResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeSummaryResourceProviderTest.java
index 387fa45..a0272cf 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeSummaryResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeSummaryResourceProviderTest.java
@@ -71,6 +71,7 @@ import org.apache.ambari.server.state.HostState;
 import org.apache.ambari.server.state.Service;
 import org.apache.ambari.server.state.ServiceComponent;
 import org.apache.ambari.server.state.ServiceComponentHost;
+import org.apache.ambari.server.state.ServiceGroup;
 import org.apache.ambari.server.state.StackId;
 import org.apache.ambari.server.state.UpgradeHelper;
 import org.apache.ambari.server.state.stack.upgrade.Direction;
@@ -173,7 +174,8 @@ public class UpgradeSummaryResourceProviderTest {
     clusters.mapHostToCluster("h1", "c1");
 
     // add a single ZOOKEEPER server
-    Service service = cluster.addService(null, "ZOOKEEPER", "", repoVersionEntity);
+    ServiceGroup serviceGroup = cluster.addServiceGroup("CORE");
+    Service service = cluster.addService(serviceGroup, "ZOOKEEPER", "ZOOKEEPER", repoVersionEntity);
 
     ServiceComponent component = service.addServiceComponent("ZOOKEEPER_SERVER");
     ServiceComponentHost sch = component.addServiceComponentHost("h1");

http://git-wip-us.apache.org/repos/asf/ambari/blob/bcbacf0c/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/VersionDefinitionResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/VersionDefinitionResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/VersionDefinitionResourceProviderTest.java
index 8e968cc..5bf586f 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/VersionDefinitionResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/VersionDefinitionResourceProviderTest.java
@@ -50,6 +50,7 @@ import org.apache.ambari.server.security.TestAuthenticationFactory;
 import org.apache.ambari.server.stack.StackManager;
 import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Clusters;
+import org.apache.ambari.server.state.ServiceGroup;
 import org.apache.ambari.server.state.repository.VersionDefinitionXml;
 import org.apache.commons.codec.binary.Base64;
 import org.apache.commons.io.IOUtils;
@@ -695,7 +696,8 @@ public class VersionDefinitionResourceProviderTest {
       cluster = clusters.getCluster("c1");
     }
 
-    cluster.addService(null, serviceName, "", serviceRepo);
+    ServiceGroup serviceGroup = cluster.addServiceGroup("CORE");
+    cluster.addService(serviceGroup, serviceName, serviceName, serviceRepo);
   }
 
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/bcbacf0c/ambari-server/src/test/java/org/apache/ambari/server/controller/utilities/state/GeneralServiceCalculatedStateTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/utilities/state/GeneralServiceCalculatedStateTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/utilities/state/GeneralServiceCalculatedStateTest.java
index 0b6c3f3..720a1f8 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/utilities/state/GeneralServiceCalculatedStateTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/utilities/state/GeneralServiceCalculatedStateTest.java
@@ -33,6 +33,7 @@ import org.apache.ambari.server.state.Clusters;
 import org.apache.ambari.server.state.Service;
 import org.apache.ambari.server.state.ServiceComponent;
 import org.apache.ambari.server.state.ServiceComponentHost;
+import org.apache.ambari.server.state.ServiceGroup;
 import org.apache.ambari.server.state.StackId;
 import org.apache.ambari.server.state.State;
 import org.apache.ambari.server.topology.TopologyManager;
@@ -86,7 +87,8 @@ public abstract class GeneralServiceCalculatedStateTest {
     clusters.addCluster(clusterName, stack211);
     cluster = clusters.getCluster(clusterName);
 
-    service = cluster.addService(null, getServiceName(), "", repositoryVersion);
+    ServiceGroup serviceGroup = cluster.addServiceGroup("CORE");
+    service = cluster.addService(serviceGroup, getServiceName(), getServiceName(), repositoryVersion);
 
     createComponentsAndHosts();
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/bcbacf0c/ambari-server/src/test/java/org/apache/ambari/server/events/listeners/upgrade/HostVersionOutOfSyncListenerTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/events/listeners/upgrade/HostVersionOutOfSyncListenerTest.java b/ambari-server/src/test/java/org/apache/ambari/server/events/listeners/upgrade/HostVersionOutOfSyncListenerTest.java
index a86d125..970b7cc 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/events/listeners/upgrade/HostVersionOutOfSyncListenerTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/events/listeners/upgrade/HostVersionOutOfSyncListenerTest.java
@@ -53,6 +53,7 @@ import org.apache.ambari.server.state.Service;
 import org.apache.ambari.server.state.ServiceComponent;
 import org.apache.ambari.server.state.ServiceComponentHost;
 import org.apache.ambari.server.state.ServiceComponentHostFactory;
+import org.apache.ambari.server.state.ServiceGroup;
 import org.apache.ambari.server.state.StackId;
 import org.apache.ambari.server.utils.EventBusSynchronizer;
 import org.junit.After;
@@ -548,7 +549,8 @@ public class HostVersionOutOfSyncListenerTest {
       String serviceName, RepositoryVersionEntity repositoryVersionEntity) throws AmbariException {
     StackId stackIdObj = new StackId(stackId);
     cl.setDesiredStackVersion(stackIdObj);
-    cl.addService(null, serviceName, "", repositoryVersionEntity);
+    ServiceGroup serviceGroup = cl.addServiceGroup("CORE");
+    cl.addService(serviceGroup, serviceName, serviceName, repositoryVersionEntity);
 
     for (Map.Entry<String, List<Integer>> component : topology.entrySet()) {
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/bcbacf0c/ambari-server/src/test/java/org/apache/ambari/server/orm/OrmTestHelper.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/orm/OrmTestHelper.java b/ambari-server/src/test/java/org/apache/ambari/server/orm/OrmTestHelper.java
index a03d7cc..dafc5e8 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/orm/OrmTestHelper.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/orm/OrmTestHelper.java
@@ -328,6 +328,22 @@ public class OrmTestHelper {
     return stackEntity;
   }
 
+  //TODO this is hack which should be removed during merge with BP branch
+  @Transactional
+  public StackEntity createStackWithRepoVersion(StackId stackId, String repoVersion) throws AmbariException {
+    StackEntity stackEntity = stackDAO.find(stackId.getStackName(), stackId.getStackVersion());
+
+    if (null == stackEntity) {
+      stackEntity = new StackEntity();
+      stackEntity.setStackName(stackId.getStackName());
+      stackEntity.setStackVersion(stackId.getStackVersion());
+      stackEntity.setRepoVersion(repoVersion);
+      stackDAO.create(stackEntity);
+    }
+
+    return stackEntity;
+  }
+
   /**
    * Creates an empty cluster with an ID.
    *
@@ -659,7 +675,7 @@ public class OrmTestHelper {
       String version) {
     StackEntity stackEntity = null;
     try {
-      stackEntity = createStack(stackId);
+      stackEntity = createStackWithRepoVersion(stackId, version);
     } catch (Exception e) {
       LOG.error("Expected successful repository", e);
     }

http://git-wip-us.apache.org/repos/asf/ambari/blob/bcbacf0c/ambari-server/src/test/java/org/apache/ambari/server/state/ConfigHelperTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/ConfigHelperTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/ConfigHelperTest.java
index 158c47d..faba98f 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/ConfigHelperTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/state/ConfigHelperTest.java
@@ -55,6 +55,7 @@ import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
 import org.apache.ambari.server.orm.OrmTestHelper;
 import org.apache.ambari.server.orm.dao.HostRoleCommandDAO;
 import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
+import org.apache.ambari.server.resources.RootLevelSettingsManagerFactory;
 import org.apache.ambari.server.security.SecurityHelper;
 import org.apache.ambari.server.security.TestAuthenticationFactory;
 import org.apache.ambari.server.stack.StackManagerFactory;
@@ -158,9 +159,10 @@ public class ConfigHelperTest {
       cr2.setType("flume-conf");
       cr2.setVersionTag("version1");
 
-      cluster.addService(null, "", "FLUME", repositoryVersion);
-      cluster.addService(null, "", "OOZIE", repositoryVersion);
-      cluster.addService(null, "", "HDFS", repositoryVersion);
+      ServiceGroup serviceGroup = cluster.addServiceGroup("CORE");
+      cluster.addService(serviceGroup, "FLUME", "FLUME", repositoryVersion);
+      cluster.addService(serviceGroup, "OOZIE", "OOZIE", repositoryVersion);
+      cluster.addService(serviceGroup, "HDFS", "HDFS", repositoryVersion);
 
       final ClusterRequest clusterRequest2 =
           new ClusterRequest(cluster.getClusterId(), clusterName,
@@ -984,8 +986,9 @@ public class ConfigHelperTest {
       expect(sch.getHostName()).andReturn("h1").anyTimes();
       expect(sch.getClusterId()).andReturn(cluster.getClusterId()).anyTimes();
       expect(sch.getServiceName()).andReturn("FLUME").anyTimes();
+      expect(sch.getServiceType()).andReturn("FLUME").anyTimes();
       expect(sch.getServiceComponentName()).andReturn("FLUME_HANDLER").anyTimes();
-      expect(sch.getServiceComponent()).andReturn(sc).anyTimes();
+      expect(sch.getServiceComponent()).andReturn(sc).anyTimes(); //
 
       replay(sc, sch);
       // Cluster level config changes
@@ -1059,6 +1062,7 @@ public class ConfigHelperTest {
     expect(sch.getHostName()).andReturn("h1").anyTimes();
     expect(sch.getClusterId()).andReturn(cluster.getClusterId()).anyTimes();
     expect(sch.getServiceName()).andReturn("HDFS").anyTimes();
+    expect(sch.getServiceType()).andReturn("HDFS").anyTimes();
     expect(sch.getServiceComponentName()).andReturn("NAMENODE").anyTimes();
     expect(sch.getServiceComponent()).andReturn(sc).anyTimes();
 
@@ -1102,6 +1106,7 @@ public class ConfigHelperTest {
           bind(HostRoleCommandFactory.class).toInstance(createNiceMock(HostRoleCommandFactory.class));
           bind(HostRoleCommandDAO.class).toInstance(createNiceMock(HostRoleCommandDAO.class));
           bind(MpackManagerFactory.class).toInstance(createNiceMock(MpackManagerFactory.class));
+          bind(RootLevelSettingsManagerFactory.class).toInstance(createNiceMock(RootLevelSettingsManagerFactory.class));
         }
       });
 
@@ -1131,6 +1136,7 @@ public class ConfigHelperTest {
 
       expect(mockCluster.getService("SERVICE")).andReturn(mockService).once();
       expect(mockService.getDesiredStackId()).andReturn(mockStackVersion).once();
+      expect(mockService.getServiceType()).andReturn("SERVICE").once();
       expect(mockStackVersion.getStackName()).andReturn("HDP").once();
       expect(mockStackVersion.getStackVersion()).andReturn("2.2").once();
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/bcbacf0c/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceTest.java
index 4e1c139..6c66c5a 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceTest.java
@@ -24,10 +24,12 @@ import static org.junit.Assert.fail;
 import java.sql.SQLException;
 import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Map;
 
 import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.H2DatabaseCleaner;
+import org.apache.ambari.server.api.services.ServiceGroupKey;
 import org.apache.ambari.server.api.services.ServiceKey;
 import org.apache.ambari.server.controller.ServiceResponse;
 import org.apache.ambari.server.orm.GuiceJpaInitializer;
@@ -52,6 +54,7 @@ public class ServiceTest {
   private String clusterName;
   private Injector injector;
   private ServiceFactory serviceFactory;
+  private ServiceGroupFactory serviceGroupFactory;
   private ServiceComponentFactory serviceComponentFactory;
   private ServiceComponentHostFactory serviceComponentHostFactory;
   private OrmTestHelper ormTestHelper;
@@ -66,6 +69,7 @@ public class ServiceTest {
     injector = Guice.createInjector(new InMemoryDefaultTestModule());
     injector.getInstance(GuiceJpaInitializer.class);
     clusters = injector.getInstance(Clusters.class);
+    serviceGroupFactory = injector.getInstance(ServiceGroupFactory.class);
     serviceFactory = injector.getInstance(ServiceFactory.class);
     serviceComponentFactory = injector.getInstance(ServiceComponentFactory.class);
     serviceComponentHostFactory = injector.getInstance(ServiceComponentHostFactory.class);
@@ -86,7 +90,8 @@ public class ServiceTest {
 
   @Test
   public void testCanBeRemoved() throws Exception{
-    Service service = cluster.addService(null, "HDFS", "", repositoryVersion);
+    ServiceGroup serviceGroup = cluster.addServiceGroup("CORE");
+    Service service = cluster.addService(serviceGroup, "HDFS", "HDFS", repositoryVersion);
 
     for (State state : State.values()) {
       service.setDesiredState(state);
@@ -128,7 +133,8 @@ public class ServiceTest {
   @Test
   public void testGetAndSetServiceInfo() throws AmbariException {
     String serviceName = "HDFS";
-    Service s = serviceFactory.createNew(cluster, null, new ArrayList<ServiceKey>(), serviceName, "", repositoryVersion);
+    ServiceGroup serviceGroup = serviceGroupFactory.createNew(cluster, "service_group", new HashSet<ServiceGroupKey>());
+    Service s = serviceFactory.createNew(cluster, serviceGroup, new ArrayList<ServiceKey>(), serviceName, serviceName, repositoryVersion);
     cluster.addService(s);
 
     Service service = cluster.getService(serviceName);
@@ -154,7 +160,8 @@ public class ServiceTest {
   @Test
   public void testAddGetDeleteServiceComponents() throws AmbariException {
     String serviceName = "HDFS";
-    Service s = serviceFactory.createNew(cluster, null, new ArrayList<ServiceKey>(), serviceName, "", repositoryVersion);
+    ServiceGroup serviceGroup = serviceGroupFactory.createNew(cluster, "service_group", new HashSet<ServiceGroupKey>());
+    Service s = serviceFactory.createNew(cluster, serviceGroup, new ArrayList<ServiceKey>(), serviceName, serviceName, repositoryVersion);
     cluster.addService(s);
 
     Service service = cluster.getService(serviceName);
@@ -236,7 +243,8 @@ public class ServiceTest {
   @Test
   public void testConvertToResponse() throws AmbariException {
     String serviceName = "HDFS";
-    Service s = serviceFactory.createNew(cluster, null, new ArrayList<ServiceKey>(), serviceName, "", repositoryVersion);
+    ServiceGroup serviceGroup = serviceGroupFactory.createNew(cluster, "service_group", new HashSet<ServiceGroupKey>());
+    Service s = serviceFactory.createNew(cluster, serviceGroup, new ArrayList<ServiceKey>(), serviceName, serviceName, repositoryVersion);
     cluster.addService(s);
     Service service = cluster.getService(serviceName);
     Assert.assertNotNull(service);
@@ -272,14 +280,15 @@ public class ServiceTest {
   @Test
   public void testServiceMaintenance() throws Exception {
     String serviceName = "HDFS";
-    Service s = serviceFactory.createNew(cluster, null, new ArrayList<ServiceKey>(), serviceName, "", repositoryVersion);
+    ServiceGroup serviceGroup = serviceGroupFactory.createNew(cluster, "service_group", new HashSet<ServiceGroupKey>());
+    Service s = serviceFactory.createNew(cluster, serviceGroup, new ArrayList<ServiceKey>(), serviceName, serviceName, repositoryVersion);
     cluster.addService(s);
 
     Service service = cluster.getService(serviceName);
     Assert.assertNotNull(service);
 
     ClusterServiceDAO dao = injector.getInstance(ClusterServiceDAO.class);
-    ClusterServiceEntity entity = null;//dao.findByClusterAndServiceNames(clusterName, serviceName);
+    ClusterServiceEntity entity = dao.findByName(clusterName, "service_group", serviceName);
     Assert.assertNotNull(entity);
     Assert.assertEquals(MaintenanceState.OFF, entity.getServiceDesiredStateEntity().getMaintenanceState());
     Assert.assertEquals(MaintenanceState.OFF, service.getMaintenanceState());
@@ -287,7 +296,7 @@ public class ServiceTest {
     service.setMaintenanceState(MaintenanceState.ON);
     Assert.assertEquals(MaintenanceState.ON, service.getMaintenanceState());
 
-    entity = null;//dao.findByClusterAndServiceNames(clusterName, serviceName);
+    entity = dao.findByName(clusterName, "service_group", serviceName);
     Assert.assertNotNull(entity);
     Assert.assertEquals(MaintenanceState.ON, entity.getServiceDesiredStateEntity().getMaintenanceState());
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/bcbacf0c/ambari-server/src/test/java/org/apache/ambari/server/state/UpgradeHelperTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/UpgradeHelperTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/UpgradeHelperTest.java
index 5e5395a..3bb7c1b 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/UpgradeHelperTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/state/UpgradeHelperTest.java
@@ -46,6 +46,7 @@ import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.H2DatabaseCleaner;
 import org.apache.ambari.server.actionmanager.HostRoleCommandFactory;
 import org.apache.ambari.server.api.services.AmbariMetaInfo;
+import org.apache.ambari.server.api.services.ServiceGroupKey;
 import org.apache.ambari.server.api.services.ServiceKey;
 import org.apache.ambari.server.controller.AmbariManagementController;
 import org.apache.ambari.server.controller.ClusterRequest;
@@ -1227,6 +1228,7 @@ public class UpgradeHelperTest extends EasyMockSupport {
   private Cluster makeCluster(boolean clean, Set<String> additionalServices) throws AmbariException, AuthorizationException {
     Clusters clusters = injector.getInstance(Clusters.class);
     ServiceFactory serviceFactory = injector.getInstance(ServiceFactory.class);
+    ServiceGroupFactory serviceGroupFactory = injector.getInstance(ServiceGroupFactory.class);
 
     String clusterName = "c1";
 
@@ -1258,11 +1260,12 @@ public class UpgradeHelperTest extends EasyMockSupport {
     }
 
     // !!! add services
-    c.addService(serviceFactory.createNew(c, null, new ArrayList<ServiceKey>(), "HDFS", "", repositoryVersion));
-    c.addService(serviceFactory.createNew(c, null, new ArrayList<ServiceKey>(), "YARN", "", repositoryVersion));
-    c.addService(serviceFactory.createNew(c, null, new ArrayList<ServiceKey>(), "ZOOKEEPER", "", repositoryVersion));
-    c.addService(serviceFactory.createNew(c, null, new ArrayList<ServiceKey>(), "HIVE", "", repositoryVersion));
-    c.addService(serviceFactory.createNew(c, null, new ArrayList<ServiceKey>(), "OOZIE", "", repositoryVersion));
+    ServiceGroup serviceGroup = serviceGroupFactory.createNew(c, "service_group", new HashSet<ServiceGroupKey>());
+    c.addService(serviceFactory.createNew(c, serviceGroup, new ArrayList<ServiceKey>(), "HDFS", "HDFS", repositoryVersion));
+    c.addService(serviceFactory.createNew(c, serviceGroup, new ArrayList<ServiceKey>(), "YARN", "YARN", repositoryVersion));
+    c.addService(serviceFactory.createNew(c, serviceGroup, new ArrayList<ServiceKey>(), "ZOOKEEPER", "ZOOKEEPER", repositoryVersion));
+    c.addService(serviceFactory.createNew(c, serviceGroup, new ArrayList<ServiceKey>(), "HIVE", "HIVE", repositoryVersion));
+    c.addService(serviceFactory.createNew(c, serviceGroup, new ArrayList<ServiceKey>(), "OOZIE", "OOZIE", repositoryVersion));
 
     Service s = c.getService("HDFS");
     ServiceComponent sc = s.addServiceComponent("NAMENODE");
@@ -1366,7 +1369,7 @@ public class UpgradeHelperTest extends EasyMockSupport {
     expect(m_masterHostResolver.getCluster()).andReturn(c).anyTimes();
 
     for(String service : additionalServices) {
-      c.addService(null, service, "", repositoryVersion);
+      c.addService(serviceGroup, service, service, repositoryVersion);
       if (service.equals("HBASE")) {
         type = new HostsType();
         type.hosts.addAll(Arrays.asList("h1", "h2"));
@@ -1453,6 +1456,7 @@ public class UpgradeHelperTest extends EasyMockSupport {
 
     Clusters clusters = injector.getInstance(Clusters.class);
     ServiceFactory serviceFactory = injector.getInstance(ServiceFactory.class);
+    ServiceGroupFactory serviceGroupFactory = injector.getInstance(ServiceGroupFactory.class);
 
     String clusterName = "c1";
 
@@ -1478,7 +1482,8 @@ public class UpgradeHelperTest extends EasyMockSupport {
     }
 
     // !!! add services
-    c.addService(serviceFactory.createNew(c, null, new ArrayList<ServiceKey>(), "HDFS", "", repositoryVersion));
+    ServiceGroup serviceGroup = serviceGroupFactory.createNew(c, "service_group", new HashSet<ServiceGroupKey>());
+    c.addService(serviceFactory.createNew(c, serviceGroup, new ArrayList<ServiceKey>(), "HDFS", "HDFS", repositoryVersion));
 
     Service s = c.getService("HDFS");
     ServiceComponent sc = s.addServiceComponent("NAMENODE");
@@ -1528,6 +1533,7 @@ public class UpgradeHelperTest extends EasyMockSupport {
   public void testResolverWithFailedUpgrade() throws Exception {
     Clusters clusters = injector.getInstance(Clusters.class);
     ServiceFactory serviceFactory = injector.getInstance(ServiceFactory.class);
+    ServiceGroupFactory serviceGroupFactory = injector.getInstance(ServiceGroupFactory.class);
 
     String clusterName = "c1";
 
@@ -1550,7 +1556,8 @@ public class UpgradeHelperTest extends EasyMockSupport {
     }
 
     // !!! add services
-    c.addService(serviceFactory.createNew(c, null, new ArrayList<ServiceKey>(), "ZOOKEEPER", "", repositoryVersion2110));
+    ServiceGroup serviceGroup = serviceGroupFactory.createNew(c, "service_group", new HashSet<ServiceGroupKey>());
+    c.addService(serviceFactory.createNew(c, serviceGroup, new ArrayList<ServiceKey>(), "ZOOKEEPER", "ZOOKEEPER", repositoryVersion2110));
 
     Service s = c.getService("ZOOKEEPER");
     ServiceComponent sc = s.addServiceComponent("ZOOKEEPER_SERVER");
@@ -1591,6 +1598,7 @@ public class UpgradeHelperTest extends EasyMockSupport {
   public void testResolverCaseInsensitive() throws Exception {
     Clusters clusters = injector.getInstance(Clusters.class);
     ServiceFactory serviceFactory = injector.getInstance(ServiceFactory.class);
+    ServiceGroupFactory serviceGroupFactory = injector.getInstance(ServiceGroupFactory.class);
 
     String clusterName = "c1";
     String version = "2.1.1.0-1234";
@@ -1617,7 +1625,8 @@ public class UpgradeHelperTest extends EasyMockSupport {
     }
 
     // Add services
-    c.addService(serviceFactory.createNew(c, null, new ArrayList<ServiceKey>(), "HDFS", "", repositoryVersion211));
+    ServiceGroup serviceGroup = serviceGroupFactory.createNew(c, "service_group", new HashSet<ServiceGroupKey>());
+    c.addService(serviceFactory.createNew(c, serviceGroup, new ArrayList<ServiceKey>(), "HDFS", "HDFS", repositoryVersion211));
 
     Service s = c.getService("HDFS");
     ServiceComponent sc = s.addServiceComponent("NAMENODE");
@@ -1661,6 +1670,7 @@ public class UpgradeHelperTest extends EasyMockSupport {
   public void testResolverBadJmx() throws Exception {
     Clusters clusters = injector.getInstance(Clusters.class);
     ServiceFactory serviceFactory = injector.getInstance(ServiceFactory.class);
+    ServiceGroupFactory serviceGroupFactory = injector.getInstance(ServiceGroupFactory.class);
 
     String clusterName = "c1";
     String version = "2.1.1.0-1234";
@@ -1686,7 +1696,8 @@ public class UpgradeHelperTest extends EasyMockSupport {
     }
 
     // Add services
-    c.addService(serviceFactory.createNew(c, null, new ArrayList<ServiceKey>(), "HDFS", "", repositoryVersion211));
+    ServiceGroup serviceGroup = serviceGroupFactory.createNew(c, "service_group", new HashSet<ServiceGroupKey>());
+    c.addService(serviceFactory.createNew(c, serviceGroup, new ArrayList<ServiceKey>(), "HDFS", "HDFS", repositoryVersion211));
 
     Service s = c.getService("HDFS");
     ServiceComponent sc = s.addServiceComponent("NAMENODE");
@@ -1777,6 +1788,7 @@ public class UpgradeHelperTest extends EasyMockSupport {
   public void testOrchestrationNoServerSideOnDowngrade() throws Exception {
     Clusters clusters = injector.getInstance(Clusters.class);
     ServiceFactory serviceFactory = injector.getInstance(ServiceFactory.class);
+    ServiceGroupFactory serviceGroupFactory = injector.getInstance(ServiceGroupFactory.class);
 
     String clusterName = "c1";
 
@@ -1806,7 +1818,8 @@ public class UpgradeHelperTest extends EasyMockSupport {
     }
 
     // !!! add storm
-    c.addService(serviceFactory.createNew(c, null, new ArrayList<ServiceKey>(), "STORM", "", repoVersion211));
+    ServiceGroup serviceGroup = serviceGroupFactory.createNew(c, "service_group", new HashSet<ServiceGroupKey>());
+    c.addService(serviceFactory.createNew(c, serviceGroup, new ArrayList<ServiceKey>(), "STORM", "STORM", repoVersion211));
 
     Service s = c.getService("STORM");
     ServiceComponent sc = s.addServiceComponent("NIMBUS");
@@ -1880,6 +1893,7 @@ public class UpgradeHelperTest extends EasyMockSupport {
     // !!! make a two node cluster with just ZK
     Clusters clusters = injector.getInstance(Clusters.class);
     ServiceFactory serviceFactory = injector.getInstance(ServiceFactory.class);
+    ServiceGroupFactory serviceGroupFactory = injector.getInstance(ServiceGroupFactory.class);
 
     String clusterName = "c1";
 
@@ -1911,7 +1925,8 @@ public class UpgradeHelperTest extends EasyMockSupport {
     }
 
     // !!! add services
-    c.addService(serviceFactory.createNew(c, null, new ArrayList<ServiceKey>(), "ZOOKEEPER", "", repositoryVersion));
+    ServiceGroup serviceGroup = serviceGroupFactory.createNew(c, "service_group", new HashSet<ServiceGroupKey>());
+    c.addService(serviceFactory.createNew(c, serviceGroup, new ArrayList<ServiceKey>(), "ZOOKEEPER", "ZOOKEEPER", repositoryVersion));
 
     Service s = c.getService("ZOOKEEPER");
     ServiceComponent sc = s.addServiceComponent("ZOOKEEPER_SERVER");
@@ -2066,6 +2081,7 @@ public class UpgradeHelperTest extends EasyMockSupport {
   public void testHostGroupingOrchestration() throws Exception {
     Clusters clusters = injector.getInstance(Clusters.class);
     ServiceFactory serviceFactory = injector.getInstance(ServiceFactory.class);
+    ServiceGroupFactory serviceGroupFactory = injector.getInstance(ServiceGroupFactory.class);
 
     String clusterName = "c1";
 
@@ -2096,8 +2112,9 @@ public class UpgradeHelperTest extends EasyMockSupport {
 
     // add ZK Server to both hosts, and then Nimbus to only 1 - this will test
     // how the HOU breaks out dependencies into stages
-    c.addService(serviceFactory.createNew(c, null, new ArrayList<ServiceKey>(), "ZOOKEEPER", "", repoVersion211));
-    c.addService(serviceFactory.createNew(c, null, new ArrayList<ServiceKey>(), "HBASE", "", repoVersion211));
+    ServiceGroup serviceGroup = serviceGroupFactory.createNew(c, "service_group", new HashSet<ServiceGroupKey>());
+    c.addService(serviceFactory.createNew(c, serviceGroup, new ArrayList<ServiceKey>(), "ZOOKEEPER", "ZOOKEEPER", repoVersion211));
+    c.addService(serviceFactory.createNew(c, serviceGroup, new ArrayList<ServiceKey>(), "HBASE", "HBASE", repoVersion211));
     Service zookeeper = c.getService("ZOOKEEPER");
     Service hbase = c.getService("HBASE");
     ServiceComponent zookeeperServer = zookeeper.addServiceComponent("ZOOKEEPER_SERVER");


Mime
View raw message