ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nc...@apache.org
Subject [2/6] ambari git commit: AMBARI-21059. Reduce Dependency on Cluster Desired Stack ID (ncole)
Date Tue, 23 May 2017 19:39:20 GMT
http://git-wip-us.apache.org/repos/asf/ambari/blob/a45f5427/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterImplTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterImplTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterImplTest.java
index ec5eef0..1a26ca6 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterImplTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterImplTest.java
@@ -213,8 +213,10 @@ public class ClusterImplTest {
 
     String stackVersion = "HDP-2.1.1";
     String repoVersion = "2.1.1-1234";
+    StackId stackId = new StackId(stackVersion);
+    ormTestHelper.createStack(stackId);
 
-    clusters.addCluster(clusterName, new StackId(stackVersion));
+    clusters.addCluster(clusterName, stackId);
     Cluster cluster = clusters.getCluster(clusterName);
 
     RepositoryVersionEntity repositoryVersion = ormTestHelper.getOrCreateRepositoryVersion(
@@ -268,13 +270,13 @@ public class ClusterImplTest {
   @Test
   public void testDeleteHost() throws Exception {
     // Given
-
-
     String clusterName = "TEST_DELETE_HOST";
     String hostName1 = "HOSTNAME1", hostName2 = "HOSTNAME2";
     String hostToDelete = hostName2;
+    StackId stackId = new StackId("HDP-2.1.1");
 
-    clusters.addCluster(clusterName, new StackId("HDP-2.1.1"));
+    ormTestHelper.createStack(stackId);
+    clusters.addCluster(clusterName, stackId);
 
     Cluster cluster = clusters.getCluster(clusterName);
 
@@ -305,8 +307,6 @@ public class ClusterImplTest {
     catch(HostNotFoundException e){
 
     }
-
-
   }
 
   @Test
@@ -314,7 +314,9 @@ public class ClusterImplTest {
     // Given
     String clusterName = "TEST_CLUSTER_SIZE";
     String hostName1 = "host1", hostName2 = "host2";
-    clusters.addCluster(clusterName, new StackId("HDP-2.1.1"));
+    StackId stackId = new StackId("HDP", "2.1.1");
+    ormTestHelper.createStack(stackId);
+    clusters.addCluster(clusterName, stackId);
 
     Cluster cluster = clusters.getCluster(clusterName);
     clusters.addHost(hostName1);

http://git-wip-us.apache.org/repos/asf/ambari/blob/a45f5427/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersDeadlockTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersDeadlockTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersDeadlockTest.java
index 022cf1f..f45bfa9 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersDeadlockTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersDeadlockTest.java
@@ -107,6 +107,8 @@ public class ClustersDeadlockTest {
     injector.injectMembers(this);
 
     StackId stackId = new StackId("HDP-0.1");
+    helper.createStack(stackId);
+
     clusters.addCluster(CLUSTER_NAME, stackId);
 
     cluster = clusters.getCluster(CLUSTER_NAME);

http://git-wip-us.apache.org/repos/asf/ambari/blob/a45f5427/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersTest.java
index d59d1d5..1cae4df 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClustersTest.java
@@ -50,12 +50,10 @@ import org.apache.ambari.server.orm.GuiceJpaInitializer;
 import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
 import org.apache.ambari.server.orm.OrmTestHelper;
 import org.apache.ambari.server.orm.dao.ClusterServiceDAO;
-import org.apache.ambari.server.orm.dao.ClusterStateDAO;
 import org.apache.ambari.server.orm.dao.HostComponentDesiredStateDAO;
 import org.apache.ambari.server.orm.dao.HostComponentStateDAO;
 import org.apache.ambari.server.orm.dao.HostDAO;
 import org.apache.ambari.server.orm.dao.TopologyRequestDAO;
-import org.apache.ambari.server.orm.entities.ClusterStateEntity;
 import org.apache.ambari.server.orm.entities.HostEntity;
 import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
 import org.apache.ambari.server.state.AgentVersion;
@@ -142,9 +140,10 @@ public class ClustersTest {
 
   @Test
   public void testAddAndGetCluster() throws AmbariException {
-
     StackId stackId = new StackId("HDP-2.1.1");
 
+    helper.createStack(stackId);
+
     String c1 = "foo";
     String c2 = "foo";
     clusters.addCluster(c1, stackId);
@@ -197,6 +196,8 @@ public class ClustersTest {
   public void testAddAndGetClusterWithSecurityType() throws AmbariException {
     StackId stackId = new StackId("HDP-2.1.1");
 
+    helper.createStack(stackId);
+
     String c1 = "foo";
     SecurityType securityType = SecurityType.KERBEROS;
     clusters.addCluster(c1, stackId, securityType);
@@ -262,6 +263,8 @@ public class ClustersTest {
 
     StackId stackId = new StackId("HDP-0.1");
 
+    helper.createStack(stackId);
+
     clusters.addCluster(c1, stackId);
     clusters.addCluster(c2, stackId);
 
@@ -346,6 +349,8 @@ public class ClustersTest {
 
     StackId stackId = new StackId("HDP-0.1");
 
+    helper.createStack(stackId);
+
     clusters.addCluster(c1, stackId);
     clusters.addCluster(c2, stackId);
     Cluster cluster1 = clusters.getCluster(c1);
@@ -376,6 +381,9 @@ public class ClustersTest {
     final String h2 = "h2";
 
     StackId stackId = new StackId("HDP-0.1");
+
+    helper.createStack(stackId);
+
     clusters.addCluster(c1, stackId);
 
     Cluster cluster = clusters.getCluster(c1);
@@ -491,58 +499,6 @@ public class ClustersTest {
   }
 
   @Test
-  public void testSetCurrentStackVersion() throws AmbariException {
-    String c1 = "foo3";
-
-    try
-    {
-      clusters.setCurrentStackVersion("", null);
-      fail("Exception should be thrown on invalid set");
-    }
-      catch (AmbariException e) {
-      // Expected
-    }
-
-    try
-    {
-      clusters.setCurrentStackVersion(c1, null);
-      fail("Exception should be thrown on invalid set");
-    }
-    catch (AmbariException e) {
-      // Expected
-    }
-
-    StackId stackId = new StackId("HDP-0.1");
-
-    try
-    {
-      clusters.setCurrentStackVersion(c1, stackId);
-      fail("Exception should be thrown on invalid set");
-    }
-    catch (AmbariException e) {
-      // Expected
-      Assert.assertTrue(e.getMessage().contains("Cluster not found"));
-    }
-
-    clusters.addCluster(c1, stackId);
-    clusters.setCurrentStackVersion(c1, stackId);
-
-    Assert.assertNotNull(clusters.getCluster(c1));
-    ClusterStateEntity entity = injector.getInstance(ClusterStateDAO.class).findByPK(clusters.getCluster(c1).getClusterId());
-    Assert.assertNotNull(entity);
-
-    Assert.assertTrue(entity.getCurrentStack().getStackName().equals(
-        stackId.getStackName())
-        && entity.getCurrentStack().getStackVersion().equals(
-            stackId.getStackVersion()));
-
-    Assert.assertTrue(clusters.getCluster(c1).getCurrentStackVersion().getStackName().equals(stackId.getStackName()));
-    Assert.assertTrue(
-        clusters.getCluster(c1).getCurrentStackVersion().getStackVersion().equals(stackId.getStackVersion()));
-  }
-
-
-  @Test
   public void testNullHostNamesInTopologyRequests() throws AmbariException {
     final String hostName = "myhost";
     final String clusterName = "mycluster";
@@ -674,6 +630,9 @@ public class ClustersTest {
 
   private Cluster createCluster(String clusterName) throws AmbariException {
     StackId stackId = new StackId("HDP-0.1");
+
+    helper.createStack(stackId);
+
     clusters.addCluster(clusterName, stackId);
 
     return clusters.getCluster(clusterName);

http://git-wip-us.apache.org/repos/asf/ambari/blob/a45f5427/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ConcurrentServiceConfigVersionTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ConcurrentServiceConfigVersionTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ConcurrentServiceConfigVersionTest.java
index c643b2f..84ba3dc 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ConcurrentServiceConfigVersionTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ConcurrentServiceConfigVersionTest.java
@@ -109,6 +109,7 @@ public class ConcurrentServiceConfigVersionTest {
 
     injector.getInstance(GuiceJpaInitializer.class);
     injector.injectMembers(this);
+    helper.createStack(stackId);
     clusters.addCluster("c1", stackId);
     cluster = clusters.getCluster("c1");
     repositoryVersion = helper.getOrCreateRepositoryVersion(stackId, stackId.getStackVersion());
@@ -181,8 +182,6 @@ public class ConcurrentServiceConfigVersionTest {
           ServiceConfigVersionResponse response = cluster.createServiceConfigVersion(
               "HDFS", null, getName() + "-serviceConfig" + i, null);
 
-          System.out.println("**** " + response.getVersion());
-
           Thread.sleep(100);
         }
       } catch (Exception exception) {

http://git-wip-us.apache.org/repos/asf/ambari/blob/a45f5427/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ServiceComponentHostConcurrentWriteDeadlockTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ServiceComponentHostConcurrentWriteDeadlockTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ServiceComponentHostConcurrentWriteDeadlockTest.java
index 0678a71..b73b332 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ServiceComponentHostConcurrentWriteDeadlockTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ServiceComponentHostConcurrentWriteDeadlockTest.java
@@ -111,6 +111,10 @@ public class ServiceComponentHostConcurrentWriteDeadlockTest {
 
     injector.getInstance(GuiceJpaInitializer.class);
     injector.injectMembers(this);
+
+    OrmTestHelper helper = injector.getInstance(OrmTestHelper.class);
+    helper.createStack(stackId);
+
     clusters.addCluster("c1", stackId);
     cluster = clusters.getCluster("c1");
     m_repositoryVersion = helper.getOrCreateRepositoryVersion(stackId, REPO_VERSION);

http://git-wip-us.apache.org/repos/asf/ambari/blob/a45f5427/ambari-server/src/test/java/org/apache/ambari/server/state/services/RetryUpgradeActionServiceTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/services/RetryUpgradeActionServiceTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/services/RetryUpgradeActionServiceTest.java
index f996aac..de3b89c 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/services/RetryUpgradeActionServiceTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/state/services/RetryUpgradeActionServiceTest.java
@@ -33,7 +33,6 @@ import org.apache.ambari.server.orm.OrmTestHelper;
 import org.apache.ambari.server.orm.dao.HostRoleCommandDAO;
 import org.apache.ambari.server.orm.dao.RepositoryVersionDAO;
 import org.apache.ambari.server.orm.dao.RequestDAO;
-import org.apache.ambari.server.orm.dao.StackDAO;
 import org.apache.ambari.server.orm.dao.StageDAO;
 import org.apache.ambari.server.orm.dao.UpgradeDAO;
 import org.apache.ambari.server.orm.entities.HostRoleCommandEntity;
@@ -63,7 +62,6 @@ public class RetryUpgradeActionServiceTest {
 
   private Injector injector;
 
-  private StackDAO stackDAO;
   private Clusters clusters;
   private RepositoryVersionDAO repoVersionDAO;
   private UpgradeDAO upgradeDAO;
@@ -75,17 +73,16 @@ public class RetryUpgradeActionServiceTest {
   // Instance variables shared by all tests
   String clusterName = "c1";
   Cluster cluster;
+  StackId stack220 = new StackId("HDP-2.2.0");
   StackEntity stackEntity220;
-  StackId stack220;
   Long upgradeRequestId = 1L;
   Long stageId = 1L;
 
   @Before
-  public void before() throws NoSuchFieldException, IllegalAccessException {
+  public void before() throws Exception {
     injector = Guice.createInjector(new InMemoryDefaultTestModule());
     injector.getInstance(GuiceJpaInitializer.class);
 
-    stackDAO = injector.getInstance(StackDAO.class);
     clusters = injector.getInstance(Clusters.class);
     repoVersionDAO = injector.getInstance(RepositoryVersionDAO.class);
     upgradeDAO = injector.getInstance(UpgradeDAO.class);
@@ -93,6 +90,7 @@ public class RetryUpgradeActionServiceTest {
     stageDAO = injector.getInstance(StageDAO.class);
     hostRoleCommandDAO = injector.getInstance(HostRoleCommandDAO.class);
     helper = injector.getInstance(OrmTestHelper.class);
+    stackEntity220 = helper.createStack(stack220);
   }
 
   @After
@@ -234,8 +232,6 @@ public class RetryUpgradeActionServiceTest {
    * @throws AmbariException
    */
   private void createCluster() throws AmbariException {
-    stackEntity220 = stackDAO.find("HDP", "2.2.0");
-    stack220 = new StackId("HDP-2.2.0");
 
     clusters.addCluster(clusterName, stack220);
     cluster = clusters.getCluster("c1");

http://git-wip-us.apache.org/repos/asf/ambari/blob/a45f5427/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostTest.java
index d5c1b1a..b8c0e7c 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/state/svccomphost/ServiceComponentHostTest.java
@@ -134,6 +134,7 @@ public class ServiceComponentHostTest {
   }
 
   private ClusterEntity createCluster(StackId stackId, String clusterName) throws AmbariException {
+    helper.createStack(stackId);
     clusters.addCluster(clusterName, stackId);
     ClusterEntity clusterEntity = clusterDAO.findByName(clusterName);
     Assert.assertNotNull(clusterEntity);

http://git-wip-us.apache.org/repos/asf/ambari/blob/a45f5427/ambari-server/src/test/java/org/apache/ambari/server/upgrade/AbstractUpgradeCatalogTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/AbstractUpgradeCatalogTest.java b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/AbstractUpgradeCatalogTest.java
index 4dd7fd9..26df0d2 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/AbstractUpgradeCatalogTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/AbstractUpgradeCatalogTest.java
@@ -17,6 +17,7 @@
  */
 package org.apache.ambari.server.upgrade;
 
+import static org.easymock.EasyMock.anyObject;
 import static org.easymock.EasyMock.anyString;
 import static org.easymock.EasyMock.createNiceMock;
 import static org.easymock.EasyMock.createStrictMock;
@@ -41,6 +42,7 @@ import org.apache.ambari.server.state.PropertyInfo;
 import org.apache.ambari.server.state.PropertyUpgradeBehavior;
 import org.apache.ambari.server.state.Service;
 import org.apache.ambari.server.state.ServiceInfo;
+import org.apache.ambari.server.state.StackId;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -129,7 +131,7 @@ public class AbstractUpgradeCatalogTest {
     mergedProperties.put("prop1", "v1-old");
     mergedProperties.put("prop4", "v4");
 
-    expect(amc.createConfig(eq(cluster), eq("hdfs-site"), eq(mergedProperties), anyString(), eq(tags))).andReturn(null);
+    expect(amc.createConfig(anyObject(StackId.class), eq(cluster), eq("hdfs-site"), eq(mergedProperties), anyString(), eq(tags))).andReturn(null);
 
     replay(injector, configHelper, amc, cluster, clusters, serviceInfo, oldConfig);
 
@@ -151,7 +153,7 @@ public class AbstractUpgradeCatalogTest {
     mergedProperties.put("prop2", "v2");
     mergedProperties.put("prop3", "v3-old");
 
-    expect(amc.createConfig(eq(cluster), eq("hdfs-site"), eq(mergedProperties), anyString(), eq(tags))).andReturn(null);
+    expect(amc.createConfig(anyObject(StackId.class), eq(cluster), eq("hdfs-site"), eq(mergedProperties), anyString(), eq(tags))).andReturn(null);
 
     replay(injector, configHelper, amc, cluster, clusters, serviceInfo, oldConfig);
 
@@ -170,7 +172,7 @@ public class AbstractUpgradeCatalogTest {
     Map<String, String> mergedProperties = new HashMap<>();
     mergedProperties.put("prop1", "v1-old");
 
-    expect(amc.createConfig(eq(cluster), eq("hdfs-site"), eq(mergedProperties), anyString(), eq(tags))).andReturn(null);
+    expect(amc.createConfig(anyObject(StackId.class), eq(cluster), eq("hdfs-site"), eq(mergedProperties), anyString(), eq(tags))).andReturn(null);
 
     replay(injector, configHelper, amc, cluster, clusters, serviceInfo, oldConfig);
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/a45f5427/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog200Test.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog200Test.java b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog200Test.java
index 1649078..e993f96 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog200Test.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog200Test.java
@@ -84,7 +84,6 @@ import org.apache.ambari.server.state.RepositoryInfo;
 import org.apache.ambari.server.state.SecurityState;
 import org.apache.ambari.server.state.SecurityType;
 import org.apache.ambari.server.state.StackId;
-import org.apache.ambari.server.state.StackInfo;
 import org.apache.ambari.server.state.stack.OsFamily;
 import org.easymock.Capture;
 import org.easymock.EasyMock;
@@ -459,8 +458,6 @@ public class UpgradeCatalog200Test {
   public void testPersistHDPRepo() throws Exception {
     EasyMockSupport easyMockSupport = new EasyMockSupport();
     final AmbariManagementController  mockAmbariManagementController = easyMockSupport.createStrictMock(AmbariManagementController.class);
-    final AmbariMetaInfo mockAmbariMetaInfo = easyMockSupport.createNiceMock(AmbariMetaInfo.class);
-    final StackInfo mockStackInfo = easyMockSupport.createNiceMock(StackInfo.class);
     final Clusters mockClusters = easyMockSupport.createStrictMock(Clusters.class);
     final Cluster mockCluster = easyMockSupport.createStrictMock(Cluster.class);
     final Map<String, Cluster> clusterMap = new HashMap<>();
@@ -468,8 +465,6 @@ public class UpgradeCatalog200Test {
     OperatingSystemInfo osi = new OperatingSystemInfo("redhat6");
     HashSet<OperatingSystemInfo> osiSet = new HashSet<>();
     osiSet.add(osi);
-    StackId stackId = new StackId("HDP","2.2");
-    final RepositoryInfo mockRepositoryInfo = easyMockSupport.createNiceMock(RepositoryInfo.class);
 
     final Injector mockInjector = Guice.createInjector(new AbstractModule() {
       @Override
@@ -482,20 +477,7 @@ public class UpgradeCatalog200Test {
       }
     });
 
-    expect(mockAmbariManagementController.getAmbariMetaInfo()).andReturn(mockAmbariMetaInfo);
-    expect(mockAmbariManagementController.getClusters()).andReturn(mockClusters).once();
-    expect(mockClusters.getClusters()).andReturn(clusterMap).once();
-    expect(mockCluster.getCurrentStackVersion()).andReturn(stackId).once();
     expect(mockCluster.getClusterName()).andReturn("cc").anyTimes();
-    expect(mockAmbariMetaInfo.getOperatingSystems("HDP", "2.2")).andReturn(osiSet).once();
-    expect(mockAmbariMetaInfo.getRepository("HDP", "2.2", "redhat6", "HDP-2.2")).andReturn(mockRepositoryInfo).once();
-    expect(mockAmbariMetaInfo.getStack("HDP", "2.2")).andReturn(mockStackInfo);
-    expect(mockStackInfo.getRepositories()).andReturn(new ArrayList<RepositoryInfo>() {{
-      add(mockRepositoryInfo);
-    }});
-    expect(mockRepositoryInfo.getDefaultBaseUrl()).andReturn("http://baseurl").once();
-    mockAmbariMetaInfo.updateRepo("HDP", "2.2", "redhat6", "HDP-2.2", "http://baseurl", null);
-    expectLastCall().once();
 
     easyMockSupport.replayAll();
     mockInjector.getInstance(UpgradeCatalog200.class).persistHDPRepo();
@@ -643,7 +625,7 @@ public class UpgradeCatalog200Test {
         clusterEntity, HOST_NAME);
 
     upgradeCatalogHelper.addComponent(injector, clusterEntity,
-        clusterServiceEntityNagios, hostEntity, "NAGIOS_SERVER", repositoryVersion);
+        clusterServiceEntityNagios, hostEntity, "NAGIOS_SERVER", stackEntity, repositoryVersion);
 
     ServiceComponentDesiredStateEntity serviceComponentDesiredStateEntity = serviceComponentDesiredStateDAO.findByName(
         clusterEntity.getClusterId(), "NAGIOS", "NAGIOS_SERVER");

http://git-wip-us.apache.org/repos/asf/ambari/blob/a45f5427/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog210Test.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog210Test.java b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog210Test.java
index 6c2e9f7..a8f5f62 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog210Test.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog210Test.java
@@ -61,11 +61,11 @@ import org.apache.ambari.server.orm.DBAccessor;
 import org.apache.ambari.server.orm.DBAccessor.DBColumnInfo;
 import org.apache.ambari.server.orm.GuiceJpaInitializer;
 import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
+import org.apache.ambari.server.orm.OrmTestHelper;
 import org.apache.ambari.server.orm.dao.ArtifactDAO;
 import org.apache.ambari.server.orm.dao.ClusterDAO;
 import org.apache.ambari.server.orm.dao.ClusterStateDAO;
 import org.apache.ambari.server.orm.dao.HostComponentDesiredStateDAO;
-import org.apache.ambari.server.orm.dao.RepositoryVersionDAO;
 import org.apache.ambari.server.orm.dao.ServiceComponentDesiredStateDAO;
 import org.apache.ambari.server.orm.dao.StackDAO;
 import org.apache.ambari.server.orm.entities.ArtifactEntity;
@@ -84,6 +84,7 @@ import org.apache.ambari.server.state.ConfigHelper;
 import org.apache.ambari.server.state.Host;
 import org.apache.ambari.server.state.HostComponentAdminState;
 import org.apache.ambari.server.state.Service;
+import org.apache.ambari.server.state.StackId;
 import org.apache.ambari.server.state.kerberos.KerberosDescriptor;
 import org.apache.ambari.server.state.kerberos.KerberosDescriptorFactory;
 import org.apache.ambari.server.state.kerberos.KerberosServiceDescriptor;
@@ -516,7 +517,7 @@ public class UpgradeCatalog210Test {
     expect(mockClusterExpected.getDesiredConfigByType("hive-site")).andReturn(mockHiveSite).atLeastOnce();
     expect(mockHiveSite.getProperties()).andReturn(propertiesExpectedHiveSite).anyTimes();
     expect(mockClusterExpected.getServices()).andReturn(servicesExpected).atLeastOnce();
-    expect(mockAmbariManagementController.createConfig((Cluster)anyObject(),
+    expect(mockAmbariManagementController.createConfig(anyObject(StackId.class), (Cluster)anyObject(),
       anyString(),
       capture(configCreation),
       anyString(),
@@ -600,7 +601,7 @@ public class UpgradeCatalog210Test {
     expect(mockHiveSite.getProperties()).andReturn(propertiesExpectedHiveSite).anyTimes();
     expect(mockHivePluginProperies.getProperties()).andReturn(propertiesExpectedPluginProperies).anyTimes();
     expect(mockClusterExpected.getServices()).andReturn(servicesExpected).atLeastOnce();
-    expect(mockAmbariManagementController.createConfig((Cluster) anyObject(),
+    expect(mockAmbariManagementController.createConfig(anyObject(StackId.class), (Cluster) anyObject(),
         anyString(),
         capture(configCreation),
         anyString(),
@@ -807,9 +808,15 @@ public class UpgradeCatalog210Test {
   @Test
   public void testDeleteStormRestApiServiceComponent() throws Exception {
     initData();
+
     ClusterEntity clusterEntity = upgradeCatalogHelper.createCluster(injector,
         "c1", desiredStackEntity, desiredRepositoryVersion);
 
+    OrmTestHelper helper = injector.getInstance(OrmTestHelper.class);
+    RepositoryVersionEntity repositoryVersion = helper.getOrCreateRepositoryVersion(
+        new StackId(desiredStackEntity.getStackName(), desiredStackEntity.getStackVersion()),
+        desiredRepositoryVersion);
+
     ClusterServiceEntity clusterServiceEntity = upgradeCatalogHelper.createService(
         injector, clusterEntity, "STORM");
 
@@ -827,10 +834,6 @@ public class UpgradeCatalog210Test {
     clusterEntity.setClusterStateEntity(clusterStateEntity);
     clusterDAO.merge(clusterEntity);
 
-    RepositoryVersionDAO repositoryVersionDAO = injector.getInstance(RepositoryVersionDAO.class);
-    RepositoryVersionEntity repositoryVersion = repositoryVersionDAO.findByStackAndVersion(
-        desiredStackEntity, desiredRepositoryVersion);
-
     ServiceComponentDesiredStateEntity componentDesiredStateEntity = new ServiceComponentDesiredStateEntity();
     componentDesiredStateEntity.setClusterId(clusterEntity.getClusterId());
     componentDesiredStateEntity.setServiceName(clusterServiceEntity.getServiceName());

http://git-wip-us.apache.org/repos/asf/ambari/blob/a45f5427/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog211Test.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog211Test.java b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog211Test.java
index c705d89..f2e9974 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog211Test.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog211Test.java
@@ -48,6 +48,7 @@ import org.apache.ambari.server.orm.dao.StackDAO;
 import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Clusters;
 import org.apache.ambari.server.state.Config;
+import org.apache.ambari.server.state.StackId;
 import org.apache.ambari.server.state.stack.OsFamily;
 import org.easymock.Capture;
 import org.easymock.EasyMock;
@@ -268,7 +269,7 @@ public class UpgradeCatalog211Test extends EasyMockSupport {
     Capture<Map<String, Map<String, String>>> attributesCapture = newCapture();
 
 
-    expect(controller.createConfig(capture(clusterCapture), capture(typeCapture),
+    expect(controller.createConfig(anyObject(StackId.class), capture(clusterCapture), capture(typeCapture),
         capture(propertiesCapture), capture(tagCapture), capture(attributesCapture) ))
         .andReturn(createNiceMock(Config.class))
         .once();

http://git-wip-us.apache.org/repos/asf/ambari/blob/a45f5427/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog212Test.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog212Test.java b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog212Test.java
index 896602b..ed14a01 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog212Test.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog212Test.java
@@ -56,6 +56,7 @@ import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Clusters;
 import org.apache.ambari.server.state.Config;
 import org.apache.ambari.server.state.ConfigHelper;
+import org.apache.ambari.server.state.Service;
 import org.apache.ambari.server.state.StackId;
 import org.apache.ambari.server.state.stack.OsFamily;
 import org.easymock.Capture;
@@ -71,6 +72,7 @@ import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 
+import com.google.common.collect.ImmutableMap;
 import com.google.inject.AbstractModule;
 import com.google.inject.Binder;
 import com.google.inject.Guice;
@@ -457,17 +459,22 @@ public class UpgradeCatalog212Test {
       }
     });
 
+    StackId stackId = new StackId("HDP-2.2");
+
+    Service hiveService = easyMockSupport.createNiceMock(Service.class);
+    expect(hiveService.getDesiredStackId()).andReturn(stackId);
+
     expect(mockAmbariManagementController.getClusters()).andReturn(mockClusters).once();
     expect(mockClusters.getClusters()).andReturn(new HashMap<String, Cluster>() {{
       put("normal", mockClusterExpected);
     }}).once();
 
+    expect(mockClusterExpected.getServices()).andReturn(ImmutableMap.<String, Service>builder()
+        .put("HIVE", hiveService)
+        .build());
     expect(mockClusterExpected.getDesiredConfigByType("hive-site")).andReturn(mockHiveSite).atLeastOnce();
     expect(mockHiveSite.getProperties()).andReturn(propertiesExpectedHiveSite).atLeastOnce();
 
-    StackId stackId = new StackId("HDP-2.2");
-    expect(mockClusterExpected.getCurrentStackVersion()).andReturn(stackId).atLeastOnce();
-
     easyMockSupport.replayAll();
     mockInjector.getInstance(UpgradeCatalog212.class).updateHiveConfigs();
     easyMockSupport.verifyAll();

http://git-wip-us.apache.org/repos/asf/ambari/blob/a45f5427/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog220Test.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog220Test.java b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog220Test.java
index fc754a0..4c9f661 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog220Test.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog220Test.java
@@ -92,6 +92,7 @@ import org.junit.Assert;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
+import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Maps;
 import com.google.gson.Gson;
 import com.google.inject.AbstractModule;
@@ -473,10 +474,11 @@ public class UpgradeCatalog220Test {
     expect(mockClusters.getClusters()).andReturn(new HashMap<String, Cluster>() {{
       put("normal", mockClusterExpected);
     }}).atLeastOnce();
-    expect(mockClusterExpected.getCurrentStackVersion()).andReturn(new StackId("HDP", "2.2"));
-
+    expect(mockClusterExpected.getServices()).andReturn(ImmutableMap.<String, Service>builder()
+        .put("HBASE", easyMockSupport.createNiceMock(Service.class))
+        .build());
     expect(mockClusterExpected.getDesiredConfigByType("hbase-env")).andReturn(mockHbaseEnv).atLeastOnce();
-    expect(mockHbaseEnv.getProperties()).andReturn(propertiesHbaseEnv).atLeastOnce();
+    expect(mockHbaseEnv.getProperties()).andReturn(propertiesHbaseEnv).anyTimes();
 
     easyMockSupport.replayAll();
     mockInjector.getInstance(UpgradeCatalog220.class).updateHbaseEnvConfig();
@@ -603,7 +605,7 @@ public class UpgradeCatalog220Test {
 
     expect(injector2.getInstance(AmbariManagementController.class)).andReturn(controller).anyTimes();
     expect(controller.getClusters()).andReturn(clusters).anyTimes();
-    expect(controller.createConfig(anyObject(Cluster.class), anyString(), capture(propertiesCapture), anyString(),
+    expect(controller.createConfig(anyObject(StackId.class), anyObject(Cluster.class), anyString(), capture(propertiesCapture), anyString(),
         EasyMock.<Map<String, Map<String, String>>>anyObject())).andReturn(createNiceMock(Config.class)).once();
 
     replay(controller, injector2);
@@ -664,7 +666,7 @@ public class UpgradeCatalog220Test {
 
     expect(injector2.getInstance(AmbariManagementController.class)).andReturn(controller).anyTimes();
     expect(controller.getClusters()).andReturn(clusters).anyTimes();
-    expect(controller.createConfig(anyObject(Cluster.class), anyString(), capture(propertiesCapture), anyString(),
+    expect(controller.createConfig(anyObject(StackId.class), anyObject(Cluster.class), anyString(), capture(propertiesCapture), anyString(),
         EasyMock.<Map<String, Map<String, String>>>anyObject())).andReturn(createNiceMock(Config.class)).once();
 
     replay(controller, injector2);
@@ -1209,7 +1211,9 @@ public class UpgradeCatalog220Test {
     }}).atLeastOnce();
     expect(mockClusterExpected.getDesiredConfigByType("hive-site")).andReturn(hiveSiteConf).atLeastOnce();
     expect(mockClusterExpected.getDesiredConfigByType("hive-env")).andReturn(hiveEnvConf).atLeastOnce();
-
+    expect(mockClusterExpected.getServices()).andReturn(ImmutableMap.<String, Service>builder()
+        .put("HIVE", easyMockSupport.createNiceMock(Service.class))
+        .build());
     expect(hiveSiteConf.getProperties()).andReturn(propertiesHiveSite).once();
     expect(hiveEnvConf.getProperties()).andReturn(propertiesHiveEnv).once();
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/a45f5427/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog221Test.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog221Test.java b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog221Test.java
index f4b3897..102c629 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog221Test.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog221Test.java
@@ -455,7 +455,7 @@ public class UpgradeCatalog221Test {
 
     expect(injector2.getInstance(AmbariManagementController.class)).andReturn(controller).anyTimes();
     expect(controller.getClusters()).andReturn(clusters).anyTimes();
-    expect(controller.createConfig(anyObject(Cluster.class), anyString(), capture(propertiesCapture), anyString(),
+    expect(controller.createConfig(anyObject(StackId.class), anyObject(Cluster.class), anyString(), capture(propertiesCapture), anyString(),
       EasyMock.<Map<String, Map<String, String>>>anyObject())).andReturn(createNiceMock(Config.class)).anyTimes();
 
     replay(controller, injector2);
@@ -511,7 +511,7 @@ public class UpgradeCatalog221Test {
 
     expect(injector2.getInstance(AmbariManagementController.class)).andReturn(controller).anyTimes();
     expect(controller.getClusters()).andReturn(clusters).anyTimes();
-    expect(controller.createConfig(anyObject(Cluster.class), anyString(), capture(propertiesCapture), anyString(),
+    expect(controller.createConfig(anyObject(StackId.class), anyObject(Cluster.class), anyString(), capture(propertiesCapture), anyString(),
       EasyMock.<Map<String, Map<String, String>>>anyObject())).andReturn(createNiceMock(Config.class)).once();
 
     replay(controller, injector2);

http://git-wip-us.apache.org/repos/asf/ambari/blob/a45f5427/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog222Test.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog222Test.java b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog222Test.java
index 82ba149..ba2cf79 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog222Test.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog222Test.java
@@ -84,6 +84,7 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 
+import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Maps;
 import com.google.gson.Gson;
 import com.google.inject.AbstractModule;
@@ -271,15 +272,19 @@ public class UpgradeCatalog222Test {
       }
     });
 
-    expect(mockClusterExpected.getCurrentStackVersion()).andReturn(stackId).once();
+//    expect(mockClusterExpected.getCurrentStackVersion()).andReturn(stackId).once();
     expect(mockClusterExpected.getServiceComponentHosts("ATLAS", "ATLAS_SERVER")).andReturn(atlasHosts).once();
-    expect(atlasHost.getHostName()).andReturn("c6401").once();
+//    expect(atlasHost.getHostName()).andReturn("c6401").once();
     expect(mockAmbariManagementController.getClusters()).andReturn(mockClusters).once();
     expect(mockClusters.getClusters()).andReturn(new HashMap<String, Cluster>() {{
       put("normal", mockClusterExpected);
     }}).atLeastOnce();
     expect(mockClusterExpected.getDesiredConfigByType("hive-site")).andReturn(hiveSiteConfigs).atLeastOnce();
     expect(mockClusterExpected.getDesiredConfigByType("application-properties")).andReturn(AtlasSiteConfigs).anyTimes();
+    expect(mockClusterExpected.getServices()).andReturn(ImmutableMap.<String, Service>builder()
+        .put("ATLAS", easyMockSupport.createNiceMock(Service.class))
+        .build());
+
     expect(AtlasSiteConfigs.getProperties()).andReturn(propertiesAtlasSiteConfigs).anyTimes();
 
     UpgradeCatalog222 upgradeCatalog222 = createMockBuilder(UpgradeCatalog222.class)
@@ -401,10 +406,16 @@ public class UpgradeCatalog222Test {
       .createStrictMock();
 
     // CASE 1 - Ranger enabled, Cluster version is 2.2
-    expect(mockClusterExpected.getCurrentStackVersion()).andReturn(new StackId("HDP", "2.2")).atLeastOnce();
+    Service hbaseService = easyMockSupport.createNiceMock(Service.class);
+    expect(hbaseService.getDesiredStackId()).andReturn(new StackId("HDP", "2.2")).anyTimes();
+
+//    expect(mockClusterExpected.getCurrentStackVersion()).andReturn(new StackId("HDP", "2.2")).atLeastOnce();
     expect(mockClusterExpected.getDesiredConfigByType("hbase-site")).andReturn(hbaseSite).atLeastOnce();
     expect(mockClusterExpected.getDesiredConfigByType(AbstractUpgradeCatalog.CONFIGURATION_TYPE_RANGER_HBASE_PLUGIN_PROPERTIES)).
       andReturn(rangerHbasePluginProperties).once();
+    expect(mockClusterExpected.getServices()).andReturn(ImmutableMap.<String, Service>builder()
+        .put("HBASE", hbaseService)
+        .build());
 
     Map<String, String> expectedUpdates = new HashMap<>();
     expectedUpdates.put(UpgradeCatalog222.HBASE_SITE_HBASE_COPROCESSOR_MASTER_CLASSES, "com.xasecure.authorization.hbase.XaSecureAuthorizationCoprocessor");
@@ -422,11 +433,17 @@ public class UpgradeCatalog222Test {
     easyMockSupport.verifyAll();
 
     // CASE 2 - Ranger enabled, Cluster version is 2.3
-    reset(mockClusterExpected, upgradeCatalog222);
-    expect(mockClusterExpected.getCurrentStackVersion()).andReturn(new StackId("HDP", "2.3")).atLeastOnce();
+    reset(mockClusterExpected, upgradeCatalog222, hbaseService);
+
+
+    expect(hbaseService.getDesiredStackId()).andReturn(new StackId("HDP-2.3"));
+//    expect(mockClusterExpected.getCurrentStackVersion()).andReturn(new StackId("HDP", "2.3")).atLeastOnce();
     expect(mockClusterExpected.getDesiredConfigByType("hbase-site")).andReturn(hbaseSite).atLeastOnce();
     expect(mockClusterExpected.getDesiredConfigByType(AbstractUpgradeCatalog.CONFIGURATION_TYPE_RANGER_HBASE_PLUGIN_PROPERTIES)).
       andReturn(rangerHbasePluginProperties).once();
+    expect(mockClusterExpected.getServices()).andReturn(ImmutableMap.<String, Service>builder()
+        .put("HBASE", hbaseService)
+        .build());
 
     expectedUpdates = new HashMap<>();
     expectedUpdates.put(UpgradeCatalog222.HBASE_SITE_HBASE_COPROCESSOR_MASTER_CLASSES, "org.apache.ranger.authorization.hbase.RangerAuthorizationCoprocessor ");
@@ -439,23 +456,31 @@ public class UpgradeCatalog222Test {
       true, false);
     expectLastCall().once();
 
-    replay(mockClusterExpected, upgradeCatalog222);
+    replay(mockClusterExpected, upgradeCatalog222, hbaseService);
     upgradeCatalog222.updateHBASEConfigs();
     easyMockSupport.verifyAll();
 
     // CASE 3 - Ranger enabled, Cluster version is 2.1
-    reset(mockClusterExpected, upgradeCatalog222);
-    expect(mockClusterExpected.getCurrentStackVersion()).andReturn(new StackId("HDP", "2.1")).atLeastOnce();
+    reset(mockClusterExpected, upgradeCatalog222, hbaseService);
+    expect(hbaseService.getDesiredStackId()).andReturn(new StackId("HDP-2.1"));
+//    expect(mockClusterExpected.getCurrentStackVersion()).andReturn(new StackId("HDP", "2.1")).atLeastOnce();
     expect(mockClusterExpected.getDesiredConfigByType("hbase-site")).andReturn(hbaseSite).atLeastOnce();
     expect(mockClusterExpected.getDesiredConfigByType(AbstractUpgradeCatalog.CONFIGURATION_TYPE_RANGER_HBASE_PLUGIN_PROPERTIES)).
       andReturn(rangerHbasePluginProperties).once();
+    expect(mockClusterExpected.getServices()).andReturn(ImmutableMap.<String, Service>builder()
+        .put("HBASE", hbaseService)
+        .build());
 
-    replay(mockClusterExpected, upgradeCatalog222);
+
+    replay(mockClusterExpected, upgradeCatalog222, hbaseService);
     upgradeCatalog222.updateHBASEConfigs();
     easyMockSupport.verifyAll();
 
     // CASE 4 - Ranger disabled
     reset(mockClusterExpected, upgradeCatalog222);
+    expect(mockClusterExpected.getServices()).andReturn(ImmutableMap.<String, Service>builder()
+        .put("HBASE", hbaseService)
+        .build());
     expect(mockClusterExpected.getDesiredConfigByType("hbase-site")).andReturn(hbaseSite).atLeastOnce();
     expect(mockClusterExpected.getDesiredConfigByType(AbstractUpgradeCatalog.CONFIGURATION_TYPE_RANGER_HBASE_PLUGIN_PROPERTIES)).
       andReturn(null).once();
@@ -528,7 +553,7 @@ public class UpgradeCatalog222Test {
 
     expect(injector2.getInstance(AmbariManagementController.class)).andReturn(controller).anyTimes();
     expect(controller.getClusters()).andReturn(clusters).anyTimes();
-    expect(controller.createConfig(anyObject(Cluster.class), anyString(), capture(propertiesCapture), anyString(),
+    expect(controller.createConfig(anyObject(StackId.class), anyObject(Cluster.class), anyString(), capture(propertiesCapture), anyString(),
       EasyMock.<Map<String, Map<String, String>>>anyObject())).andReturn(createNiceMock(Config.class)).once();
 
     replay(controller, injector2);
@@ -587,7 +612,7 @@ public class UpgradeCatalog222Test {
 
     expect(injector2.getInstance(AmbariManagementController.class)).andReturn(controller).anyTimes();
     expect(controller.getClusters()).andReturn(clusters).anyTimes();
-    expect(controller.createConfig(anyObject(Cluster.class), anyString(), capture(propertiesCapture), anyString(),
+    expect(controller.createConfig(anyObject(StackId.class), anyObject(Cluster.class), anyString(), capture(propertiesCapture), anyString(),
       EasyMock.<Map<String, Map<String, String>>>anyObject())).andReturn(createNiceMock(Config.class)).once();
 
     replay(controller, injector2);
@@ -629,16 +654,24 @@ public class UpgradeCatalog222Test {
         bind(AmbariMetaInfo.class).toInstance(metaInfo);
       }
     });
+
     expect(controller.getClusters()).andReturn(clusters).anyTimes();
     expect(clusters.getClusters()).andReturn(new HashMap<String, Cluster>() {{
       put("normal", cluster);
     }}).anyTimes();
+
+    Service hdfsService = createNiceMock(Service.class);
+    expect(hdfsService.getDesiredStackId()).andReturn(stackId).anyTimes();
+
+    expect(cluster.getServices()).andReturn(ImmutableMap.<String, Service> builder()
+        .put("HDFS", hdfsService)
+        .build()).anyTimes();
     expect(cluster.getClusterId()).andReturn(1L).anyTimes();
     expect(stackInfo.getService("HDFS")).andReturn(null);
     expect(cluster.getDesiredStackVersion()).andReturn(stackId);
     expect(metaInfo.getStack("HDP", "2.0.0")).andReturn(stackInfo);
 
-    replay(clusters, cluster, controller, widgetDAO, metaInfo, stackInfo);
+    replay(clusters, cluster, hdfsService, controller, widgetDAO, metaInfo, stackInfo);
 
     UpgradeCatalog222 upgradeCatalog222 = createMockBuilder(UpgradeCatalog222.class)
             .withConstructor(Injector.class)
@@ -709,6 +742,13 @@ public class UpgradeCatalog222Test {
         bind(AmbariMetaInfo.class).toInstance(metaInfo);
       }
     });
+
+    Service hdfsService = createNiceMock(Service.class);
+    expect(hdfsService.getDesiredStackId()).andReturn(stackId).anyTimes();
+    expect(cluster.getServices()).andReturn(ImmutableMap.<String, Service>builder()
+        .put("HDFS", hdfsService)
+        .build()).anyTimes();
+
     expect(controller.getClusters()).andReturn(clusters).anyTimes();
     expect(clusters.getClusters()).andReturn(new HashMap<String, Cluster>() {{
       put("normal", cluster);
@@ -729,7 +769,7 @@ public class UpgradeCatalog222Test {
     expect(widgetDAO.merge(widgetEntity2)).andReturn(null);
     expect(widgetEntity2.getWidgetName()).andReturn("HDFS Bytes Read").anyTimes();
 
-    replay(clusters, cluster, controller, widgetDAO, metaInfo, widgetEntity, widgetEntity2, stackInfo, serviceInfo);
+    replay(clusters, cluster, hdfsService, controller, widgetDAO, metaInfo, widgetEntity, widgetEntity2, stackInfo, serviceInfo);
 
     mockInjector.getInstance(UpgradeCatalog222.class).updateHDFSWidgetDefinition();
 
@@ -797,6 +837,13 @@ public class UpgradeCatalog222Test {
         bind(AmbariMetaInfo.class).toInstance(metaInfo);
       }
     });
+
+    Service yarnService = createNiceMock(Service.class);
+    expect(yarnService.getDesiredStackId()).andReturn(stackId);
+    expect(cluster.getServices()).andReturn(ImmutableMap.<String, Service>builder()
+        .put("YARN", yarnService)
+        .build());
+
     expect(controller.getClusters()).andReturn(clusters).anyTimes();
     expect(clusters.getClusters()).andReturn(new HashMap<String, Cluster>() {{
       put("normal", cluster);
@@ -817,7 +864,7 @@ public class UpgradeCatalog222Test {
     expect(widgetDAO.merge(widgetEntity2)).andReturn(null);
     expect(widgetEntity2.getWidgetName()).andReturn("Container Failures").anyTimes();
 
-    replay(clusters, cluster, controller, widgetDAO, metaInfo, widgetEntity, widgetEntity2, stackInfo, serviceInfo);
+    replay(clusters, cluster, yarnService, controller, widgetDAO, metaInfo, widgetEntity, widgetEntity2, stackInfo, serviceInfo);
 
     mockInjector.getInstance(UpgradeCatalog222.class).updateYARNWidgetDefinition();
 
@@ -873,6 +920,13 @@ public class UpgradeCatalog222Test {
         bind(AmbariMetaInfo.class).toInstance(metaInfo);
       }
     });
+
+    Service hbaseService = createNiceMock(Service.class);
+    expect(hbaseService.getDesiredStackId()).andReturn(stackId);
+    expect(cluster.getServices()).andReturn(ImmutableMap.<String, Service>builder()
+        .put("HBASE", hbaseService)
+        .build());
+
     expect(controller.getClusters()).andReturn(clusters).anyTimes();
     expect(clusters.getClusters()).andReturn(new HashMap<String, Cluster>() {{
       put("normal", cluster);
@@ -888,7 +942,7 @@ public class UpgradeCatalog222Test {
     expect(widgetDAO.merge(widgetEntity)).andReturn(null);
     expect(widgetEntity.getWidgetName()).andReturn("Blocked Updates").anyTimes();
 
-    replay(clusters, cluster, controller, widgetDAO, metaInfo, widgetEntity, stackInfo, serviceInfo);
+    replay(clusters, cluster, hbaseService, controller, widgetDAO, metaInfo, widgetEntity, stackInfo, serviceInfo);
 
     mockInjector.getInstance(UpgradeCatalog222.class).updateHBASEWidgetDefinition();
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/a45f5427/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog240Test.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog240Test.java b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog240Test.java
index 70673f8..f4903fe 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog240Test.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog240Test.java
@@ -128,6 +128,7 @@ import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 import org.springframework.security.crypto.password.PasswordEncoder;
 
+import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Maps;
 import com.google.gson.Gson;
 import com.google.inject.AbstractModule;
@@ -764,9 +765,9 @@ public class UpgradeCatalog240Test {
 
     Capture<Map<String, String>> oozieCapture =  newCapture();
     Capture<Map<String, String>> hiveCapture =  newCapture();
-    expect(mockAmbariManagementController.createConfig(eq(mockClusterExpected), eq("oozie-env"),
+    expect(mockAmbariManagementController.createConfig(anyObject(StackId.class), eq(mockClusterExpected), eq("oozie-env"),
         capture(oozieCapture), anyString(), EasyMock.<Map<String, Map<String, String>>>anyObject())).andReturn(null).once();
-    expect(mockAmbariManagementController.createConfig(eq(mockClusterExpected), eq("hive-env"),
+    expect(mockAmbariManagementController.createConfig(anyObject(StackId.class), eq(mockClusterExpected), eq("hive-env"),
             capture(hiveCapture), anyString(), EasyMock.<Map<String, Map<String, String>>>anyObject())).andReturn(null).once();
 
     easyMockSupport.replayAll();
@@ -848,15 +849,15 @@ public class UpgradeCatalog240Test {
     expect(falconStartupConfig.getProperties()).andReturn(falconStartupConfigProperties).anyTimes();
 
     Capture<Map<String, String>> falconCapture =  newCapture();
-    expect(mockAmbariManagementController.createConfig(eq(mockClusterExpected), eq("falcon-env"),
+    expect(mockAmbariManagementController.createConfig(anyObject(StackId.class), eq(mockClusterExpected), eq("falcon-env"),
         capture(falconCapture), anyString(), EasyMock.<Map<String, Map<String, String>>>anyObject())).andReturn(null).once();
 
     Capture<Map<String, String>> falconCapture2 =  newCapture();
-    expect(mockAmbariManagementController.createConfig(eq(mockClusterExpected), eq("falcon-env"),
+    expect(mockAmbariManagementController.createConfig(anyObject(StackId.class), eq(mockClusterExpected), eq("falcon-env"),
         capture(falconCapture2), anyString(), EasyMock.<Map<String, Map<String, String>>>anyObject())).andReturn(null).once();
 
     Capture<Map<String, String>> falconStartupCapture =  newCapture();
-    expect(mockAmbariManagementController.createConfig(eq(mockClusterExpected), eq("falcon-startup.properties"),
+    expect(mockAmbariManagementController.createConfig(anyObject(StackId.class), eq(mockClusterExpected), eq("falcon-startup.properties"),
         capture(falconStartupCapture), anyString(), EasyMock.<Map<String, Map<String, String>>>anyObject())).andReturn(null).once();
 
     easyMockSupport.replayAll();
@@ -911,7 +912,10 @@ public class UpgradeCatalog240Test {
       put("normal", mockCluster);
     }}).anyTimes();
 
-    expect(mockCluster.getServices()).andReturn(new HashMap<String, Service>(){{put("HBASE",null);}}).anyTimes();
+    final Service hbaseService = createNiceMock(Service.class);
+    expect(hbaseService.getDesiredStackId()).andReturn(new StackId("HDP-2.4"));
+
+    expect(mockCluster.getServices()).andReturn(new HashMap<String, Service>(){{put("HBASE",hbaseService);}}).anyTimes();
     expect(mockCluster.getSecurityType()).andReturn(SecurityType.KERBEROS).anyTimes();
 
     final Config mockHbaseSiteConfigs = easyMockSupport.createNiceMock(Config.class);
@@ -934,10 +938,8 @@ public class UpgradeCatalog240Test {
     }}).anyTimes();
 
 
-
-
     Capture<Map<String, String>> hbaseCapture =  newCapture();
-    expect(mockAmbariManagementController.createConfig(eq(mockCluster), eq("hbase-site"),
+    expect(mockAmbariManagementController.createConfig(anyObject(StackId.class), eq(mockCluster), eq("hbase-site"),
         capture(hbaseCapture), anyString(), EasyMock.<Map<String, Map<String, String>>>anyObject())).andReturn(null).once();
 
     easyMockSupport.replayAll();
@@ -1023,7 +1025,7 @@ public class UpgradeCatalog240Test {
 
     expect(injector2.getInstance(AmbariManagementController.class)).andReturn(controller).anyTimes();
     expect(controller.getClusters()).andReturn(clusters).anyTimes();
-    expect(controller.createConfig(anyObject(Cluster.class), anyString(), capture(propertiesCapture), anyString(),
+    expect(controller.createConfig(anyObject(StackId.class), anyObject(Cluster.class), anyString(), capture(propertiesCapture), anyString(),
                                    EasyMock.<Map<String, Map<String, String>>>anyObject())).andReturn(createNiceMock(Config.class)).once();
 
     replay(controller, injector2);
@@ -1099,9 +1101,9 @@ public class UpgradeCatalog240Test {
 
     expect(injector2.getInstance(AmbariManagementController.class)).andReturn(controller).anyTimes();
     expect(controller.getClusters()).andReturn(clusters).anyTimes();
-    expect(controller.createConfig(anyObject(Cluster.class), eq("hdfs-site"), capture(propertiesCaptureHdfsSite), anyString(),
+    expect(controller.createConfig(anyObject(StackId.class), anyObject(Cluster.class), eq("hdfs-site"), capture(propertiesCaptureHdfsSite), anyString(),
                                    EasyMock.<Map<String, Map<String, String>>>anyObject())).andReturn(createNiceMock(Config.class)).once();
-    expect(controller.createConfig(anyObject(Cluster.class), eq("hadoop-env"), capture(propertiesCaptureHadoopEnv), anyString(),
+    expect(controller.createConfig(anyObject(StackId.class), anyObject(Cluster.class), eq("hadoop-env"), capture(propertiesCaptureHadoopEnv), anyString(),
         EasyMock.<Map<String, Map<String, String>>>anyObject())).andReturn(createNiceMock(Config.class)).once();
 
     replay(controller, injector2);
@@ -1167,7 +1169,7 @@ public class UpgradeCatalog240Test {
 
     expect(injector2.getInstance(AmbariManagementController.class)).andReturn(controller).anyTimes();
     expect(controller.getClusters()).andReturn(clusters).anyTimes();
-    expect(controller.createConfig(anyObject(Cluster.class), anyString(), capture(propertiesCapture), anyString(),
+    expect(controller.createConfig(anyObject(StackId.class), anyObject(Cluster.class), anyString(), capture(propertiesCapture), anyString(),
             EasyMock.<Map<String, Map<String, String>>>anyObject())).andReturn(createNiceMock(Config.class)).once();
 
     replay(controller, injector2);
@@ -1299,9 +1301,9 @@ public class UpgradeCatalog240Test {
 
     expect(injector2.getInstance(AmbariManagementController.class)).andReturn(controller).anyTimes();
     expect(controller.getClusters()).andReturn(clusters).anyTimes();
-    expect(controller.createConfig(anyObject(Cluster.class), eq("spark-defaults"), capture(propertiesSparkDefaultsCapture), anyString(),
+    expect(controller.createConfig(anyObject(StackId.class), anyObject(Cluster.class), eq("spark-defaults"), capture(propertiesSparkDefaultsCapture), anyString(),
         EasyMock.<Map<String, Map<String, String>>>anyObject())).andReturn(createNiceMock(Config.class)).once();
-    expect(controller.createConfig(anyObject(Cluster.class), eq("spark-javaopts-properties"), capture(propertiesSparkJavaOptsCapture), anyString(),
+    expect(controller.createConfig(anyObject(StackId.class), anyObject(Cluster.class), eq("spark-javaopts-properties"), capture(propertiesSparkJavaOptsCapture), anyString(),
         EasyMock.<Map<String, Map<String, String>>>anyObject())).andReturn(createNiceMock(Config.class)).once();
 
     replay(controller, injector2);
@@ -1360,7 +1362,7 @@ public class UpgradeCatalog240Test {
 
     expect(injector2.getInstance(AmbariManagementController.class)).andReturn(controller).anyTimes();
     expect(controller.getClusters()).andReturn(clusters).anyTimes();
-    expect(controller.createConfig(anyObject(Cluster.class), anyString(), capture(propertiesCapture), anyString(),
+    expect(controller.createConfig(anyObject(StackId.class), anyObject(Cluster.class), anyString(), capture(propertiesCapture), anyString(),
       EasyMock.<Map<String, Map<String, String>>>anyObject())).andReturn(createNiceMock(Config.class)).once();
 
     replay(controller, injector2);
@@ -1419,7 +1421,7 @@ public class UpgradeCatalog240Test {
 
     expect(injector2.getInstance(AmbariManagementController.class)).andReturn(controller).anyTimes();
     expect(controller.getClusters()).andReturn(clusters).anyTimes();
-    expect(controller.createConfig(anyObject(Cluster.class), anyString(), capture(propertiesCapture), anyString(),
+    expect(controller.createConfig(anyObject(StackId.class), anyObject(Cluster.class), anyString(), capture(propertiesCapture), anyString(),
       EasyMock.<Map<String, Map<String, String>>>anyObject())).andReturn(createNiceMock(Config.class)).once();
 
     replay(controller, injector2);
@@ -1476,7 +1478,7 @@ public class UpgradeCatalog240Test {
 
     expect(injector2.getInstance(AmbariManagementController.class)).andReturn(controller).anyTimes();
     expect(controller.getClusters()).andReturn(clusters).anyTimes();
-    expect(controller.createConfig(anyObject(Cluster.class), anyString(), capture(propertiesCapture), anyString(),
+    expect(controller.createConfig(anyObject(StackId.class), anyObject(Cluster.class), anyString(), capture(propertiesCapture), anyString(),
       EasyMock.<Map<String, Map<String, String>>>anyObject())).andReturn(createNiceMock(Config.class)).once();
 
     replay(controller, injector2);
@@ -1551,11 +1553,17 @@ public class UpgradeCatalog240Test {
 
     final StackId currentStackVersion = new StackId("HDP", "2.4.2");
 
+    final Service kerbService = createNiceMock(Service.class);
+    expect(kerbService.getDesiredStackId()).andReturn(currentStackVersion);
+
     final Cluster cluster = createNiceMock(Cluster.class);
     expect(cluster.getClusterName()).andReturn("c1").anyTimes();
     expect(cluster.getDesiredConfigByType("kerberos-env")).andReturn(configKerberosEnv).anyTimes();
     expect(cluster.getDesiredConfigByType("krb5-conf")).andReturn(configKrb5Conf).anyTimes();
-    expect(cluster.getCurrentStackVersion()).andReturn(currentStackVersion).once();
+
+    expect(cluster.getServices()).andReturn(ImmutableMap.<String, Service>builder()
+        .put("KERBEROS", kerbService)
+        .build());
 
     expect(cluster.getConfigsByType("kerberos-env"))
         .andReturn(Collections.singletonMap("tag1", configKerberosEnv))
@@ -1575,26 +1583,25 @@ public class UpgradeCatalog240Test {
     Capture<String> tagCapture = newCapture(CaptureType.ALL);
     Capture<Map<String, Map<String, String>>> attributesCapture = newCapture(CaptureType.ALL);
 
-    expect(controller.createConfig(capture(clusterCapture), capture(typeCapture),
+    expect(controller.createConfig(anyObject(StackId.class), capture(clusterCapture), capture(typeCapture),
         capture(propertiesCapture), capture(tagCapture), capture(attributesCapture) ))
         .andReturn(createNiceMock(Config.class))
         .anyTimes();
     expect(controller.getAmbariMetaInfo()).andReturn(metaInfo).once();
 
     expect(metaInfo.getStack(currentStackVersion.getStackName(), currentStackVersion.getStackVersion()))
-        .andReturn(stackInfo)
-        .once();
+        .andReturn(stackInfo).atLeastOnce();
 
-    expect(stackInfo.getService("KERBEROS")).andReturn(serviceInfo).once();
+    expect(stackInfo.getService("KERBEROS")).andReturn(serviceInfo).atLeastOnce();
 
     final PropertyInfo propertyInfo = new PropertyInfo();
     propertyInfo.setFilename("krb5-conf.xml");
     propertyInfo.setName("content");
     propertyInfo.setValue("new content template");
 
-    expect(serviceInfo.getProperties()).andReturn(Collections.singletonList(propertyInfo)).once();
+    expect(serviceInfo.getProperties()).andReturn(Collections.singletonList(propertyInfo)).atLeastOnce();
 
-    replay(controller, metaInfo, stackInfo, serviceInfo, dbAccessor, osFamily, cluster, configKerberosEnv, configKrb5Conf, clusters);
+    replay(controller, metaInfo, stackInfo, serviceInfo, dbAccessor, osFamily, cluster, configKerberosEnv, configKrb5Conf, clusters, kerbService);
 
     final Injector injector = Guice.createInjector(new AbstractModule() {
       @Override
@@ -1611,7 +1618,7 @@ public class UpgradeCatalog240Test {
 
     injector.getInstance(UpgradeCatalog240.class).updateKerberosConfigs();
 
-    verify(controller, metaInfo, stackInfo, serviceInfo, dbAccessor, osFamily, cluster, configKerberosEnv, configKrb5Conf, clusters);
+    verify(controller, metaInfo, stackInfo, serviceInfo, dbAccessor, osFamily, cluster, configKerberosEnv, configKrb5Conf, clusters, kerbService);
 
     List<String> typeCaptureValues = typeCapture.getValues();
     Assert.assertEquals(2, typeCaptureValues.size());
@@ -1697,6 +1704,12 @@ public class UpgradeCatalog240Test {
 
     final StackId currentStackVersion = new StackId("HDP", "2.4.2");
 
+    final Service kerbService = createNiceMock(Service.class);
+    expect(kerbService.getDesiredStackId()).andReturn(currentStackVersion);
+    expect(cluster.getServices()).andReturn(ImmutableMap.<String, Service>builder()
+        .put("KERBEROS", kerbService)
+        .build());
+
     expect(metaInfo.getStack(currentStackVersion.getStackName(), currentStackVersion.getStackVersion()))
         .andReturn(stackInfo)
         .once();
@@ -1712,13 +1725,13 @@ public class UpgradeCatalog240Test {
 
     expect(cluster.getConfigsByType("kerberos-env"))
         .andReturn(Collections.singletonMap("tag1", configKerberosEnv))
-        .once();
+        .atLeastOnce();
 
     expect(cluster.getDesiredConfigByType("kerberos-env"))
         .andReturn(configKerberosEnv)
-        .once();
+        .atLeastOnce();
 
-    expect(cluster.getCurrentStackVersion()).andReturn(currentStackVersion).once();
+//    expect(cluster.getCurrentStackVersion()).andReturn(currentStackVersion).once();
 
     Capture<Cluster> clusterCapture = newCapture(CaptureType.ALL);
     Capture<String> typeCapture = newCapture(CaptureType.ALL);
@@ -1726,13 +1739,12 @@ public class UpgradeCatalog240Test {
     Capture<String> tagCapture = newCapture(CaptureType.ALL);
     Capture<Map<String, Map<String, String>>> attributesCapture = newCapture(CaptureType.ALL);
 
-
-    expect(controller.createConfig(capture(clusterCapture), capture(typeCapture),
+    expect(controller.createConfig(anyObject(StackId.class), capture(clusterCapture), capture(typeCapture),
         capture(propertiesCapture), capture(tagCapture), capture(attributesCapture)))
         .andReturn(createNiceMock(Config.class))
         .anyTimes();
 
-    replay(controller, metaInfo, stackInfo, serviceInfo, dbAccessor, osFamily, cluster, configKerberosEnv, configKrb5Conf, clusters);
+    replay(controller, metaInfo, stackInfo, serviceInfo, dbAccessor, osFamily, cluster, configKerberosEnv, configKrb5Conf, clusters, kerbService);
 
     final Injector injector = Guice.createInjector(new AbstractModule() {
       @Override
@@ -1749,7 +1761,7 @@ public class UpgradeCatalog240Test {
 
     injector.getInstance(UpgradeCatalog240.class).updateKerberosConfigs();
 
-    verify(controller, metaInfo, stackInfo, serviceInfo, dbAccessor, osFamily, cluster, configKerberosEnv, configKrb5Conf, clusters);
+    verify(controller, metaInfo, stackInfo, serviceInfo, dbAccessor, osFamily, cluster, configKerberosEnv, configKrb5Conf, clusters, kerbService);
 
     List<String> typeCaptureValues = typeCapture.getValues();
     Assert.assertEquals(1, typeCaptureValues.size());
@@ -2144,16 +2156,23 @@ public class UpgradeCatalog240Test {
     expect(metaInfo.getStack("HDP", "2.0.0")).andReturn(stackInfo).anyTimes();
     expect(serviceInfo.getWidgetsDescriptorFile()).andReturn(file).anyTimes();
 
+    Service hdfsService = createNiceMock(Service.class);
+    expect(hdfsService.getDesiredStackId()).andReturn(stackId);
+
+    expect(cluster.getServices()).andReturn(ImmutableMap.<String, Service>builder()
+        .put("HDFS", hdfsService)
+        .build());
+
     expect(widgetDAO.findByName(1L, "NameNode Operations", "ambari", "HDFS_SUMMARY"))
       .andReturn(Collections.singletonList(widgetEntity));
     expect(widgetDAO.merge(widgetEntity)).andReturn(null);
     expect(widgetEntity.getWidgetName()).andReturn("Namenode Operations").anyTimes();
 
-    replay(clusters, cluster, controller, widgetDAO, metaInfo, widgetEntity, stackInfo, serviceInfo);
+    replay(clusters, cluster, controller, widgetDAO, metaInfo, widgetEntity, stackInfo, serviceInfo, hdfsService);
 
     mockInjector.getInstance(UpgradeCatalog240.class).updateHDFSWidgetDefinition();
 
-    verify(clusters, cluster, controller, widgetDAO, widgetEntity, stackInfo, serviceInfo);
+    verify(clusters, cluster, controller, widgetDAO, widgetEntity, stackInfo, serviceInfo, hdfsService);
   }
 
   @Test
@@ -2255,15 +2274,22 @@ public class UpgradeCatalog240Test {
     Clusters clusters = easyMockSupport.createNiceMock(Clusters.class);
     final Cluster cluster = easyMockSupport.createNiceMock(Cluster.class);
     Config mockHbaseSite = easyMockSupport.createNiceMock(Config.class);
+
+
+    final StackId stackId = new StackId("HDP-2.5");
+
+    Service hbaseService = easyMockSupport.createNiceMock(Service.class);
+    expect(hbaseService.getDesiredStackId()).andReturn(stackId);
+
+
     // HBase and Kerberos are both "installed"
     final Map<String, Service> mockServices = new HashMap<>();
-    mockServices.put("HBASE", null);
-    final StackId stackId = new StackId("HDP-2.5");
+    mockServices.put("HBASE", hbaseService);
 
     expect(controller.getClusters()).andReturn(clusters).once();
     expect(clusters.getClusters()).andReturn(Collections.singletonMap("normal", cluster)).once();
-    expect(cluster.getCurrentStackVersion()).andReturn(stackId);
-    expect(cluster.getServices()).andReturn(mockServices).once();
+//    expect(cluster.getCurrentStackVersion()).andReturn(stackId);
+    expect(cluster.getServices()).andReturn(mockServices).atLeastOnce();
     expect(cluster.getSecurityType()).andReturn(SecurityType.KERBEROS).anyTimes();
     expect(cluster.getDesiredConfigByType(UpgradeCatalog240.HBASE_SITE_CONFIG)).andReturn(mockHbaseSite).atLeastOnce();
     expect(mockHbaseSite.getProperties()).andReturn(oldPqsProperties).anyTimes();
@@ -2405,14 +2431,18 @@ public class UpgradeCatalog240Test {
     Clusters clusters = easyMockSupport.createNiceMock(Clusters.class);
     final Cluster cluster = easyMockSupport.createNiceMock(Cluster.class);
     Config mockHbaseSite = easyMockSupport.createNiceMock(Config.class);
+
+    final StackId stackId = new StackId("HDP-2.5");
+
+    Service hbaseService = easyMockSupport.createNiceMock(Service.class);
+    expect(hbaseService.getDesiredStackId()).andReturn(stackId);
+
     // HBase and Kerberos are both "installed"
     final Map<String, Service> mockServices = new HashMap<>();
-    mockServices.put("HBASE", null);
-    final StackId stackId = new StackId("HDP-2.5");
+    mockServices.put("HBASE", hbaseService);
 
     expect(controller.getClusters()).andReturn(clusters).once();
     expect(clusters.getClusters()).andReturn(Collections.singletonMap("normal", cluster)).once();
-    expect(cluster.getCurrentStackVersion()).andReturn(stackId);
     expect(cluster.getServices()).andReturn(mockServices).once();
     expect(cluster.getSecurityType()).andReturn(SecurityType.KERBEROS).anyTimes();
     expect(cluster.getDesiredConfigByType(UpgradeCatalog240.HBASE_SITE_CONFIG)).andReturn(mockHbaseSite).atLeastOnce();
@@ -2556,7 +2586,7 @@ public class UpgradeCatalog240Test {
 
     expect(injector2.getInstance(AmbariManagementController.class)).andReturn(controller).anyTimes();
     expect(controller.getClusters()).andReturn(clusters).anyTimes();
-    expect(controller.createConfig(anyObject(Cluster.class), anyString(), capture(propertiesCapture), anyString(),
+    expect(controller.createConfig(anyObject(StackId.class), anyObject(Cluster.class), anyString(), capture(propertiesCapture), anyString(),
             EasyMock.<Map<String, Map<String, String>>>anyObject())).andReturn(createNiceMock(Config.class)).once();
 
     replay(controller, injector2);

http://git-wip-us.apache.org/repos/asf/ambari/blob/a45f5427/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog250Test.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog250Test.java b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog250Test.java
index 3cb2c47..118d5f1 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog250Test.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog250Test.java
@@ -70,6 +70,7 @@ import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Clusters;
 import org.apache.ambari.server.state.Config;
 import org.apache.ambari.server.state.Service;
+import org.apache.ambari.server.state.StackId;
 import org.apache.ambari.server.state.kerberos.AbstractKerberosDescriptorContainer;
 import org.apache.ambari.server.state.kerberos.KerberosComponentDescriptor;
 import org.apache.ambari.server.state.kerberos.KerberosDescriptor;
@@ -95,7 +96,6 @@ import org.junit.runner.RunWith;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Maps;
 import com.google.gson.Gson;
-
 import com.google.gson.JsonObject;
 import com.google.gson.JsonParser;
 import com.google.gson.JsonPrimitive;
@@ -737,7 +737,7 @@ public class UpgradeCatalog250Test {
 
     expect(injector2.getInstance(AmbariManagementController.class)).andReturn(controller).anyTimes();
     expect(controller.getClusters()).andReturn(clusters).anyTimes();
-    expect(controller.createConfig(anyObject(Cluster.class), anyString(), capture(propertiesCapture), anyString(),
+    expect(controller.createConfig(anyObject(StackId.class), anyObject(Cluster.class), anyString(), capture(propertiesCapture), anyString(),
         EasyMock.<Map<String, Map<String, String>>>anyObject())).andReturn(config).once();
 
     replay(controller, injector2);
@@ -824,7 +824,7 @@ public class UpgradeCatalog250Test {
 
     expect(injector2.getInstance(AmbariManagementController.class)).andReturn(controller).anyTimes();
     expect(controller.getClusters()).andReturn(clusters).anyTimes();
-    expect(controller.createConfig(anyObject(Cluster.class), anyString(), capture(propertiesCapture), anyString(),
+    expect(controller.createConfig(anyObject(StackId.class), anyObject(Cluster.class), anyString(), capture(propertiesCapture), anyString(),
       EasyMock.<Map<String, Map<String, String>>>anyObject())).andReturn(config).once();
 
     replay(controller, injector2);
@@ -905,7 +905,7 @@ public class UpgradeCatalog250Test {
 
     expect(injector2.getInstance(AmbariManagementController.class)).andReturn(controller).anyTimes();
     expect(controller.getClusters()).andReturn(clusters).anyTimes();
-    expect(controller.createConfig(anyObject(Cluster.class), anyString(), capture(propertiesCapture), anyString(),
+    expect(controller.createConfig(anyObject(StackId.class), anyObject(Cluster.class), anyString(), capture(propertiesCapture), anyString(),
         EasyMock.<Map<String, Map<String, String>>>anyObject())).andReturn(config).times(2);
 
     replay(controller, injector2);
@@ -959,7 +959,7 @@ public class UpgradeCatalog250Test {
 
     expect(injector2.getInstance(AmbariManagementController.class)).andReturn(controller).anyTimes();
     expect(controller.getClusters()).andReturn(clusters).anyTimes();
-    expect(controller.createConfig(anyObject(Cluster.class), anyString(), capture(propertiesCapture), anyString(),
+    expect(controller.createConfig(anyObject(StackId.class), anyObject(Cluster.class), anyString(), capture(propertiesCapture), anyString(),
         EasyMock.<Map<String, Map<String, String>>>anyObject())).andReturn(config).once();
 
     replay(controller, injector2);
@@ -1064,7 +1064,7 @@ public class UpgradeCatalog250Test {
     expect(cluster.getDesiredConfigByType("ams-log4j")).andReturn(mockAmsLog4j).atLeastOnce();
     expect(mockAmsLog4j.getProperties()).andReturn(oldAmsLog4j).anyTimes();
     Capture<Map<String, String>> AmsLog4jCapture = EasyMock.newCapture();
-    expect(controller.createConfig(anyObject(Cluster.class), anyString(), capture(AmsLog4jCapture), anyString(),
+    expect(controller.createConfig(anyObject(StackId.class), anyObject(Cluster.class), anyString(), capture(AmsLog4jCapture), anyString(),
         anyObject(Map.class))).andReturn(config).once();
 
     Map<String, String> oldAmsHbaseLog4j = ImmutableMap.of(
@@ -1299,7 +1299,7 @@ public class UpgradeCatalog250Test {
     expect(cluster.getDesiredConfigByType("ams-hbase-log4j")).andReturn(mockAmsHbaseLog4j).atLeastOnce();
     expect(mockAmsHbaseLog4j.getProperties()).andReturn(oldAmsHbaseLog4j).anyTimes();
     Capture<Map<String, String>> AmsHbaseLog4jCapture = EasyMock.newCapture();
-    expect(controller.createConfig(anyObject(Cluster.class), anyString(), capture(AmsHbaseLog4jCapture), anyString(),
+    expect(controller.createConfig(anyObject(StackId.class), anyObject(Cluster.class), anyString(), capture(AmsHbaseLog4jCapture), anyString(),
         anyObject(Map.class))).andReturn(config).once();
 
     replay(clusters, cluster);
@@ -1348,7 +1348,7 @@ public class UpgradeCatalog250Test {
     expect(cluster.getDesiredConfigByType("logsearch-properties")).andReturn(mockLogSearchProperties).atLeastOnce();
     expect(mockLogSearchProperties.getProperties()).andReturn(oldLogSearchProperties).anyTimes();
     Capture<Map<String, String>> logSearchPropertiesCapture = EasyMock.newCapture();
-    expect(controller.createConfig(anyObject(Cluster.class), anyString(), capture(logSearchPropertiesCapture), anyString(),
+    expect(controller.createConfig(anyObject(StackId.class), anyObject(Cluster.class), anyString(), capture(logSearchPropertiesCapture), anyString(),
         EasyMock.<Map<String, Map<String, String>>>anyObject())).andReturn(config).once();
 
     Map<String, String> oldLogFeederEnv = ImmutableMap.of(
@@ -1361,7 +1361,7 @@ public class UpgradeCatalog250Test {
     expect(cluster.getDesiredConfigByType("logfeeder-env")).andReturn(mockLogFeederEnv).atLeastOnce();
     expect(mockLogFeederEnv.getProperties()).andReturn(oldLogFeederEnv).anyTimes();
     Capture<Map<String, String>> logFeederEnvCapture = EasyMock.newCapture();
-    expect(controller.createConfig(anyObject(Cluster.class), anyString(), capture(logFeederEnvCapture), anyString(),
+    expect(controller.createConfig(anyObject(StackId.class), anyObject(Cluster.class), anyString(), capture(logFeederEnvCapture), anyString(),
         EasyMock.<Map<String, Map<String, String>>>anyObject())).andReturn(config).once();
 
     Map<String, String> oldLogSearchEnv = new HashMap<>();
@@ -1383,7 +1383,7 @@ public class UpgradeCatalog250Test {
     expect(cluster.getDesiredConfigByType("logsearch-env")).andReturn(mockLogSearchEnv).atLeastOnce();
     expect(mockLogSearchEnv.getProperties()).andReturn(oldLogSearchEnv).anyTimes();
     Capture<Map<String, String>> logSearchEnvCapture = EasyMock.newCapture();
-    expect(controller.createConfig(anyObject(Cluster.class), anyString(), capture(logSearchEnvCapture), anyString(),
+    expect(controller.createConfig(anyObject(StackId.class), anyObject(Cluster.class), anyString(), capture(logSearchEnvCapture), anyString(),
         EasyMock.<Map<String, Map<String, String>>>anyObject())).andReturn(config).once();
 
     Map<String, String> oldLogFeederLog4j = ImmutableMap.of(
@@ -1436,7 +1436,7 @@ public class UpgradeCatalog250Test {
     expect(cluster.getDesiredConfigByType("logfeeder-log4j")).andReturn(mockLogFeederLog4j).atLeastOnce();
     expect(mockLogFeederLog4j.getProperties()).andReturn(oldLogFeederLog4j).anyTimes();
     Capture<Map<String, String>> logFeederLog4jCapture = EasyMock.newCapture();
-    expect(controller.createConfig(anyObject(Cluster.class), anyString(), capture(logFeederLog4jCapture), anyString(),
+    expect(controller.createConfig(anyObject(StackId.class), anyObject(Cluster.class), anyString(), capture(logFeederLog4jCapture), anyString(),
         EasyMock.<Map<String, Map<String, String>>>anyObject())).andReturn(config).once();
 
     Map<String, String> oldLogSearchLog4j = ImmutableMap.of(
@@ -1554,7 +1554,7 @@ public class UpgradeCatalog250Test {
     expect(cluster.getDesiredConfigByType("logsearch-log4j")).andReturn(mockLogSearchLog4j).atLeastOnce();
     expect(mockLogSearchLog4j.getProperties()).andReturn(oldLogSearchLog4j).anyTimes();
     Capture<Map<String, String>> logSearchLog4jCapture = EasyMock.newCapture();
-    expect(controller.createConfig(anyObject(Cluster.class), anyString(), capture(logSearchLog4jCapture), anyString(),
+    expect(controller.createConfig(anyObject(StackId.class), anyObject(Cluster.class), anyString(), capture(logSearchLog4jCapture), anyString(),
         EasyMock.<Map<String, Map<String, String>>>anyObject())).andReturn(config).once();
 
     replay(clusters, cluster);
@@ -1613,7 +1613,7 @@ public class UpgradeCatalog250Test {
     expect(cluster.getDesiredConfigByType("infra-solr-env")).andReturn(mockInfraSolrEnv).atLeastOnce();
     expect(mockInfraSolrEnv.getProperties()).andReturn(oldInfraSolrEnv).anyTimes();
     Capture<Map<String, String>> infraSolrEnvCapture = EasyMock.newCapture();
-    expect(controller.createConfig(anyObject(Cluster.class), anyString(), capture(infraSolrEnvCapture), anyString(),
+    expect(controller.createConfig(anyObject(StackId.class), anyObject(Cluster.class), anyString(), capture(infraSolrEnvCapture), anyString(),
         EasyMock.<Map<String, Map<String, String>>>anyObject())).andReturn(config).once();
 
     Map<String, String> oldInfraSolrLog4j = ImmutableMap.of(
@@ -1630,7 +1630,7 @@ public class UpgradeCatalog250Test {
     expect(cluster.getDesiredConfigByType("infra-solr-log4j")).andReturn(mockInfraSolrLog4j).atLeastOnce();
     expect(mockInfraSolrLog4j.getProperties()).andReturn(oldInfraSolrLog4j).anyTimes();
     Capture<Map<String, String>> infraSolrLog4jCapture = EasyMock.newCapture();
-    expect(controller.createConfig(anyObject(Cluster.class), anyString(), capture(infraSolrLog4jCapture), anyString(),
+    expect(controller.createConfig(anyObject(StackId.class), anyObject(Cluster.class), anyString(), capture(infraSolrLog4jCapture), anyString(),
         EasyMock.<Map<String, Map<String, String>>>anyObject())).andReturn(config).once();
 
     Map<String, String> oldInfraSolrClientLog4j = ImmutableMap.of(
@@ -1649,7 +1649,7 @@ public class UpgradeCatalog250Test {
     expect(cluster.getDesiredConfigByType("infra-solr-client-log4j")).andReturn(mockInfraSolrClientLog4j).atLeastOnce();
     expect(mockInfraSolrClientLog4j.getProperties()).andReturn(oldInfraSolrClientLog4j).anyTimes();
     Capture<Map<String, String>> infraSolrClientLog4jCapture = EasyMock.newCapture();
-    expect(controller.createConfig(anyObject(Cluster.class), anyString(), capture(infraSolrClientLog4jCapture), anyString(),
+    expect(controller.createConfig(anyObject(StackId.class), anyObject(Cluster.class), anyString(), capture(infraSolrClientLog4jCapture), anyString(),
         EasyMock.<Map<String, Map<String, String>>>anyObject())).andReturn(config).once();
 
     replay(clusters, cluster);
@@ -1708,7 +1708,7 @@ public class UpgradeCatalog250Test {
     expect(cluster.getDesiredConfigByType("hive-interactive-env")).andReturn(mockHsiEnv).atLeastOnce();
     expect(mockHsiEnv.getProperties()).andReturn(oldHsiEnv).anyTimes();
     Capture<Map<String, String>> hsiEnvCapture = EasyMock.newCapture();
-    expect(controller.createConfig(anyObject(Cluster.class), anyString(), capture(hsiEnvCapture), anyString(),
+    expect(controller.createConfig(anyObject(StackId.class), anyObject(Cluster.class), anyString(), capture(hsiEnvCapture), anyString(),
         EasyMock.<Map<String, Map<String, String>>>anyObject())).andReturn(config).once();
 
     replay(clusters, cluster);
@@ -1789,7 +1789,7 @@ public class UpgradeCatalog250Test {
 
     expect(injector2.getInstance(AmbariManagementController.class)).andReturn(controller).anyTimes();
     expect(controller.getClusters()).andReturn(clusters).anyTimes();
-    expect(controller.createConfig(anyObject(Cluster.class), anyString(), capture(propertiesCapture), anyString(),
+    expect(controller.createConfig(anyObject(StackId.class), anyObject(Cluster.class), anyString(), capture(propertiesCapture), anyString(),
         EasyMock.<Map<String, Map<String, String>>>anyObject())).andReturn(config).once();
 
     replay(controller, injector2);
@@ -2076,7 +2076,7 @@ public class UpgradeCatalog250Test {
 
     expect(injector2.getInstance(AmbariManagementController.class)).andReturn(controller).anyTimes();
     expect(controller.getClusters()).andReturn(clusters).anyTimes();
-    expect(controller.createConfig(anyObject(Cluster.class), anyString(), capture(propertiesCapture), anyString(),
+    expect(controller.createConfig(anyObject(StackId.class), anyObject(Cluster.class), anyString(), capture(propertiesCapture), anyString(),
         EasyMock.<Map<String, Map<String, String>>>anyObject())).andReturn(config).once();
 
     replay(controller, injector2);

http://git-wip-us.apache.org/repos/asf/ambari/blob/a45f5427/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog300Test.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog300Test.java b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog300Test.java
index c949ca2..b5f0e09 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog300Test.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog300Test.java
@@ -55,6 +55,7 @@ import org.apache.ambari.server.orm.DBAccessor;
 import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Clusters;
 import org.apache.ambari.server.state.Config;
+import org.apache.ambari.server.state.StackId;
 import org.apache.ambari.server.state.stack.OsFamily;
 import org.easymock.Capture;
 import org.easymock.CaptureType;
@@ -258,7 +259,7 @@ public class UpgradeCatalog300Test {
 
     verify(dbAccessor, entityManager, emFactory, emCache);
   }
-  
+
   @Test
   public void testLogSearchUpdateConfigs() throws Exception {
     reset(clusters, cluster);
@@ -285,21 +286,21 @@ public class UpgradeCatalog300Test {
     expect(confLogSearchConf1.getType()).andReturn("service-1-logsearch-conf");
     Config confLogSearchConf2 = easyMockSupport.createNiceMock(Config.class);
     expect(confLogSearchConf2.getType()).andReturn("service-2-logsearch-conf");
-    
+
     Map<String, String> oldLogSearchConf = ImmutableMap.of(
         "service_name", "Service",
         "component_mappings", "Component Mappings",
         "content", "Content");
 
     Collection<Config> configs = Arrays.asList(confSomethingElse1, confLogSearchConf1, confSomethingElse2, confLogSearchConf2);
-    
+
     expect(cluster.getAllConfigs()).andReturn(configs).atLeastOnce();
     expect(cluster.getDesiredConfigByType("service-1-logsearch-conf")).andReturn(confLogSearchConf1).once();
     expect(cluster.getDesiredConfigByType("service-2-logsearch-conf")).andReturn(confLogSearchConf2).once();
     expect(confLogSearchConf1.getProperties()).andReturn(oldLogSearchConf).once();
     expect(confLogSearchConf2.getProperties()).andReturn(oldLogSearchConf).once();
     Capture<Map<String, String>> logSearchConfCapture = EasyMock.newCapture(CaptureType.ALL);
-    expect(controller.createConfig(anyObject(Cluster.class), anyString(), capture(logSearchConfCapture), anyString(),
+    expect(controller.createConfig(anyObject(StackId.class), anyObject(Cluster.class), anyString(), capture(logSearchConfCapture), anyString(),
         EasyMock.<Map<String, Map<String, String>>>anyObject())).andReturn(config).times(2);
 
     Map<String, String> oldLogSearchProperties = ImmutableMap.of(
@@ -314,14 +315,14 @@ public class UpgradeCatalog300Test {
     expect(cluster.getDesiredConfigByType("logfeeder-properties")).andReturn(logFeederPropertiesConf).times(2);
     expect(logFeederPropertiesConf.getProperties()).andReturn(Collections.<String, String> emptyMap()).once();
     Capture<Map<String, String>> logFeederPropertiesCapture = EasyMock.newCapture();
-    expect(controller.createConfig(anyObject(Cluster.class), eq("logfeeder-properties"), capture(logFeederPropertiesCapture),
+    expect(controller.createConfig(anyObject(StackId.class), anyObject(Cluster.class), eq("logfeeder-properties"), capture(logFeederPropertiesCapture),
         anyString(), EasyMock.<Map<String, Map<String, String>>>anyObject())).andReturn(config).once();
 
     Config logSearchPropertiesConf = easyMockSupport.createNiceMock(Config.class);
     expect(cluster.getDesiredConfigByType("logsearch-properties")).andReturn(logSearchPropertiesConf).times(2);
     expect(logSearchPropertiesConf.getProperties()).andReturn(oldLogSearchProperties).times(2);
     Capture<Map<String, String>> logSearchPropertiesCapture = EasyMock.newCapture();
-    expect(controller.createConfig(anyObject(Cluster.class), eq("logsearch-properties"), capture(logSearchPropertiesCapture),
+    expect(controller.createConfig(anyObject(StackId.class), anyObject(Cluster.class), eq("logsearch-properties"), capture(logSearchPropertiesCapture),
         anyString(), EasyMock.<Map<String, Map<String, String>>>anyObject())).andReturn(config).once();
 
     replay(clusters, cluster);
@@ -336,10 +337,10 @@ public class UpgradeCatalog300Test {
     for (Map<String, String> updatedLogSearchConf : updatedLogSearchConfs) {
       assertTrue(Maps.difference(Collections.<String, String> emptyMap(), updatedLogSearchConf).areEqual());
     }
-    
+
     Map<String,String> newLogFeederProperties = logFeederPropertiesCapture.getValue();
     assertTrue(Maps.difference(expectedLogFeederProperties, newLogFeederProperties).areEqual());
-    
+
     Map<String,String> newLogSearchProperties = logSearchPropertiesCapture.getValue();
     assertTrue(Maps.difference(Collections.<String, String> emptyMap(), newLogSearchProperties).areEqual());
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/a45f5427/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalogHelper.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalogHelper.java b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalogHelper.java
index 6b28846..784f4d4 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalogHelper.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalogHelper.java
@@ -179,7 +179,7 @@ public class UpgradeCatalogHelper {
   @Transactional
   protected void addComponent(Injector injector, ClusterEntity clusterEntity,
       ClusterServiceEntity clusterServiceEntity, HostEntity hostEntity,
-      String componentName, RepositoryVersionEntity repositoryversion) {
+      String componentName, StackEntity desiredStackEntity, RepositoryVersionEntity desiredRepositoryVersion) {
     ServiceComponentDesiredStateDAO serviceComponentDesiredStateDAO = injector.getInstance(
         ServiceComponentDesiredStateDAO.class);
 
@@ -189,7 +189,8 @@ public class UpgradeCatalogHelper {
     componentDesiredStateEntity.setServiceName(clusterServiceEntity.getServiceName());
     componentDesiredStateEntity.setClusterServiceEntity(clusterServiceEntity);
     componentDesiredStateEntity.setClusterId(clusterServiceEntity.getClusterId());
-    componentDesiredStateEntity.setDesiredRepositoryVersion(repositoryversion);
+    componentDesiredStateEntity.setDesiredRepositoryVersion(desiredRepositoryVersion);
+
     serviceComponentDesiredStateDAO.create(componentDesiredStateEntity);
 
     HostComponentDesiredStateDAO hostComponentDesiredStateDAO = injector.getInstance(HostComponentDesiredStateDAO.class);


Mime
View raw message