ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jonathanhur...@apache.org
Subject [2/9] ambari git commit: AMBARI-20894 - Setting Desired Stack Ids to Correct Values During Service and Patch Upgrades (jonathanhurley)
Date Wed, 03 May 2017 15:13:49 GMT
http://git-wip-us.apache.org/repos/asf/ambari/blob/dcbd826c/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 3dc34e3..364b92c 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
@@ -49,6 +49,7 @@ import org.apache.ambari.server.controller.ConfigurationRequest;
 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.entities.RepositoryVersionEntity;
 import org.apache.ambari.server.security.TestAuthenticationFactory;
 import org.apache.ambari.server.security.authorization.AuthorizationException;
 import org.apache.ambari.server.stack.HostsType;
@@ -1245,21 +1246,21 @@ public class UpgradeHelperTest {
 
     String clusterName = "c1";
 
+    String repositoryVersionString = "2.1.1-1234";
     StackId stackId = new StackId("HDP-2.1.1");
     StackId stackId2 = new StackId("HDP-2.2.0");
 
     clusters.addCluster(clusterName, stackId);
     Cluster c = clusters.getCluster(clusterName);
 
-    helper.getOrCreateRepositoryVersion(stackId,
-        c.getDesiredStackVersion().getStackVersion());
+    RepositoryVersionEntity repositoryVersion = helper.getOrCreateRepositoryVersion(stackId,
+        repositoryVersionString);
 
     helper.getOrCreateRepositoryVersion(stackId2,"2.2.0");
 
     helper.getOrCreateRepositoryVersion(stackId2, UPGRADE_VERSION);
 
-    c.createClusterVersion(stackId,
-        c.getDesiredStackVersion().getStackVersion(), "admin",
+    c.createClusterVersion(stackId, repositoryVersionString, "admin",
         RepositoryVersionState.INSTALLING);
 
     for (int i = 0; i < 4; i++) {
@@ -1277,11 +1278,11 @@ public class UpgradeHelperTest {
     }
 
     // !!! add services
-    c.addService(serviceFactory.createNew(c, "HDFS"));
-    c.addService(serviceFactory.createNew(c, "YARN"));
-    c.addService(serviceFactory.createNew(c, "ZOOKEEPER"));
-    c.addService(serviceFactory.createNew(c, "HIVE"));
-    c.addService(serviceFactory.createNew(c, "OOZIE"));
+    c.addService(serviceFactory.createNew(c, "HDFS", repositoryVersion));
+    c.addService(serviceFactory.createNew(c, "YARN", repositoryVersion));
+    c.addService(serviceFactory.createNew(c, "ZOOKEEPER", repositoryVersion));
+    c.addService(serviceFactory.createNew(c, "HIVE", repositoryVersion));
+    c.addService(serviceFactory.createNew(c, "OOZIE", repositoryVersion));
 
     Service s = c.getService("HDFS");
     ServiceComponent sc = s.addServiceComponent("NAMENODE");
@@ -1385,7 +1386,7 @@ public class UpgradeHelperTest {
     expect(m_masterHostResolver.getCluster()).andReturn(c).anyTimes();
 
     for(String service : additionalServices) {
-      c.addService(service);
+      c.addService(service, repositoryVersion);
       if (service.equals("HBASE")) {
         type = new HostsType();
         type.hosts.addAll(Arrays.asList("h1", "h2"));
@@ -1477,16 +1478,14 @@ public class UpgradeHelperTest {
 
     String clusterName = "c1";
 
+    String version = "2.1.1.0-1234";
     StackId stackId = new StackId("HDP-2.1.1");
     clusters.addCluster(clusterName, stackId);
     Cluster c = clusters.getCluster(clusterName);
 
-    helper.getOrCreateRepositoryVersion(stackId,
-        c.getDesiredStackVersion().getStackVersion());
+    RepositoryVersionEntity repositoryVersion = helper.getOrCreateRepositoryVersion(stackId, version);
 
-    c.createClusterVersion(stackId,
-        c.getDesiredStackVersion().getStackVersion(), "admin",
-        RepositoryVersionState.INSTALLING);
+    c.createClusterVersion(stackId, version, "admin", RepositoryVersionState.INSTALLING);
 
     for (int i = 0; i < 2; i++) {
       String hostName = "h" + (i+1);
@@ -1503,7 +1502,7 @@ public class UpgradeHelperTest {
     }
 
     // !!! add services
-    c.addService(serviceFactory.createNew(c, "HDFS"));
+    c.addService(serviceFactory.createNew(c, "HDFS", repositoryVersion));
 
     Service s = c.getService("HDFS");
     ServiceComponent sc = s.addServiceComponent("NAMENODE");
@@ -1557,16 +1556,15 @@ public class UpgradeHelperTest {
 
     String clusterName = "c1";
 
+    String version = "2.1.1.0-1234";
     StackId stackId = new StackId("HDP-2.1.1");
     clusters.addCluster(clusterName, stackId);
     Cluster c = clusters.getCluster(clusterName);
 
-    helper.getOrCreateRepositoryVersion(stackId,
-        c.getDesiredStackVersion().getStackVersion());
+    RepositoryVersionEntity repositoryVersion = helper.getOrCreateRepositoryVersion(stackId,
+        version);
 
-    c.createClusterVersion(stackId,
-        c.getDesiredStackVersion().getStackVersion(), "admin",
-        RepositoryVersionState.INSTALLING);
+    c.createClusterVersion(stackId, version, "admin", RepositoryVersionState.INSTALLING);
 
     for (int i = 0; i < 2; i++) {
       String hostName = "h" + (i+1);
@@ -1583,7 +1581,7 @@ public class UpgradeHelperTest {
     }
 
     // !!! add services
-    c.addService(serviceFactory.createNew(c, "ZOOKEEPER"));
+    c.addService(serviceFactory.createNew(c, "ZOOKEEPER", repositoryVersion));
 
     Service s = c.getService("ZOOKEEPER");
     ServiceComponent sc = s.addServiceComponent("ZOOKEEPER_SERVER");
@@ -1626,12 +1624,10 @@ public class UpgradeHelperTest {
     clusters.addCluster(clusterName, stackId);
     Cluster c = clusters.getCluster(clusterName);
 
-    helper.getOrCreateRepositoryVersion(stackId,
-        c.getDesiredStackVersion().getStackVersion());
+    RepositoryVersionEntity repositoryVersion = helper.getOrCreateRepositoryVersion(stackId,
+        version);
 
-    c.createClusterVersion(stackId,
-        c.getDesiredStackVersion().getStackVersion(), "admin",
-        RepositoryVersionState.INSTALLING);
+    c.createClusterVersion(stackId, version, "admin", RepositoryVersionState.INSTALLING);
 
     for (int i = 0; i < 2; i++) {
       String hostName = "h" + (i+1);
@@ -1648,7 +1644,7 @@ public class UpgradeHelperTest {
     }
 
     // Add services
-    c.addService(serviceFactory.createNew(c, "HDFS"));
+    c.addService(serviceFactory.createNew(c, "HDFS", repositoryVersion));
 
     Service s = c.getService("HDFS");
     ServiceComponent sc = s.addServiceComponent("NAMENODE");
@@ -1692,12 +1688,10 @@ public class UpgradeHelperTest {
     clusters.addCluster(clusterName, stackId);
     Cluster c = clusters.getCluster(clusterName);
 
-    helper.getOrCreateRepositoryVersion(stackId,
-        c.getDesiredStackVersion().getStackVersion());
+    RepositoryVersionEntity repositoryVersion = helper.getOrCreateRepositoryVersion(stackId,
+        version);
 
-    c.createClusterVersion(stackId,
-        c.getDesiredStackVersion().getStackVersion(), "admin",
-        RepositoryVersionState.INSTALLING);
+    c.createClusterVersion(stackId, version, "admin", RepositoryVersionState.INSTALLING);
 
     for (int i = 0; i < 2; i++) {
       String hostName = "h" + (i+1);
@@ -1714,7 +1708,7 @@ public class UpgradeHelperTest {
     }
 
     // Add services
-    c.addService(serviceFactory.createNew(c, "HDFS"));
+    c.addService(serviceFactory.createNew(c, "HDFS", repositoryVersion));
 
     Service s = c.getService("HDFS");
     ServiceComponent sc = s.addServiceComponent("NAMENODE");
@@ -1806,18 +1800,18 @@ public class UpgradeHelperTest {
 
     String clusterName = "c1";
 
+    String version = "2.1.1.0-1234";
     StackId stackId = new StackId("HDP-2.1.1");
     StackId stackId2 = new StackId("HDP-2.2.0");
     clusters.addCluster(clusterName, stackId);
     Cluster c = clusters.getCluster(clusterName);
 
-    helper.getOrCreateRepositoryVersion(stackId,
-        c.getDesiredStackVersion().getStackVersion());
+    RepositoryVersionEntity repositoryVersion = helper.getOrCreateRepositoryVersion(stackId,
+        version);
+
     helper.getOrCreateRepositoryVersion(stackId2,"2.2.0");
 
-    c.createClusterVersion(stackId,
-        c.getDesiredStackVersion().getStackVersion(), "admin",
-        RepositoryVersionState.INSTALLING);
+    c.createClusterVersion(stackId, version, "admin", RepositoryVersionState.INSTALLING);
 
     for (int i = 0; i < 2; i++) {
       String hostName = "h" + (i+1);
@@ -1834,7 +1828,7 @@ public class UpgradeHelperTest {
     }
 
     // !!! add storm
-    c.addService(serviceFactory.createNew(c, "STORM"));
+    c.addService(serviceFactory.createNew(c, "STORM", repositoryVersion));
 
     Service s = c.getService("STORM");
     ServiceComponent sc = s.addServiceComponent("NIMBUS");
@@ -1904,22 +1898,21 @@ public class UpgradeHelperTest {
 
     String clusterName = "c1";
 
+    String version = "2.1.1.0-1234";
     StackId stackId = new StackId("HDP-2.1.1");
     StackId stackId2 = new StackId("HDP-2.2.0");
 
     clusters.addCluster(clusterName, stackId);
     Cluster c = clusters.getCluster(clusterName);
 
-    helper.getOrCreateRepositoryVersion(stackId,
-        c.getDesiredStackVersion().getStackVersion());
+    RepositoryVersionEntity repositoryVersion = helper.getOrCreateRepositoryVersion(stackId,
+        version);
 
     helper.getOrCreateRepositoryVersion(stackId2,"2.2.0");
 
     helper.getOrCreateRepositoryVersion(stackId2, UPGRADE_VERSION);
 
-    c.createClusterVersion(stackId,
-        c.getDesiredStackVersion().getStackVersion(), "admin",
-        RepositoryVersionState.INSTALLING);
+    c.createClusterVersion(stackId, version, "admin", RepositoryVersionState.INSTALLING);
 
     for (int i = 0; i < 2; i++) {
       String hostName = "h" + (i+1);
@@ -1935,7 +1928,7 @@ public class UpgradeHelperTest {
     }
 
     // !!! add services
-    c.addService(serviceFactory.createNew(c, "ZOOKEEPER"));
+    c.addService(serviceFactory.createNew(c, "ZOOKEEPER", repositoryVersion));
 
     Service s = c.getService("ZOOKEEPER");
     ServiceComponent sc = s.addServiceComponent("ZOOKEEPER_SERVER");
@@ -2094,18 +2087,17 @@ public class UpgradeHelperTest {
 
     String clusterName = "c1";
 
+    String version = "2.1.1.0-1234";
     StackId stackId = new StackId("HDP-2.1.1");
     StackId stackId2 = new StackId("HDP-2.2.0");
     clusters.addCluster(clusterName, stackId);
     Cluster c = clusters.getCluster(clusterName);
 
-    helper.getOrCreateRepositoryVersion(stackId,
-        c.getDesiredStackVersion().getStackVersion());
+    RepositoryVersionEntity repositoryVersion = helper.getOrCreateRepositoryVersion(stackId, version);
+
     helper.getOrCreateRepositoryVersion(stackId2, "2.2.0");
 
-    c.createClusterVersion(stackId,
-        c.getDesiredStackVersion().getStackVersion(), "admin",
-        RepositoryVersionState.INSTALLING);
+    c.createClusterVersion(stackId, version, "admin", RepositoryVersionState.INSTALLING);
 
     // create 2 hosts
     for (int i = 0; i < 2; i++) {
@@ -2124,8 +2116,8 @@ public class UpgradeHelperTest {
 
     // 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, "ZOOKEEPER"));
-    c.addService(serviceFactory.createNew(c, "HBASE"));
+    c.addService(serviceFactory.createNew(c, "ZOOKEEPER", repositoryVersion));
+    c.addService(serviceFactory.createNew(c, "HBASE", repositoryVersion));
     Service zookeeper = c.getService("ZOOKEEPER");
     Service hbase = c.getService("HBASE");
     ServiceComponent zookeeperServer = zookeeper.addServiceComponent("ZOOKEEPER_SERVER");

http://git-wip-us.apache.org/repos/asf/ambari/blob/dcbd826c/ambari-server/src/test/java/org/apache/ambari/server/state/alerts/AlertEventPublisherTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/alerts/AlertEventPublisherTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/alerts/AlertEventPublisherTest.java
index 8c23b69..f5f4e10 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/alerts/AlertEventPublisherTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/state/alerts/AlertEventPublisherTest.java
@@ -33,6 +33,7 @@ import org.apache.ambari.server.orm.entities.AlertCurrentEntity;
 import org.apache.ambari.server.orm.entities.AlertDefinitionEntity;
 import org.apache.ambari.server.orm.entities.AlertGroupEntity;
 import org.apache.ambari.server.orm.entities.AlertHistoryEntity;
+import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
 import org.apache.ambari.server.state.AlertState;
 import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Clusters;
@@ -76,6 +77,9 @@ public class AlertEventPublisherTest {
   private OrmTestHelper ormHelper;
   private AggregateDefinitionMapping aggregateMapping;
 
+  private final String STACK_VERSION = "2.0.6";
+  private final String REPO_VERSION = "2.0.6-1234";
+
   /**
    *
    */
@@ -95,7 +99,7 @@ public class AlertEventPublisherTest {
     aggregateMapping = injector.getInstance(AggregateDefinitionMapping.class);
 
     clusterName = "foo";
-    clusters.addCluster(clusterName, new StackId("HDP", "2.0.6"));
+    clusters.addCluster(clusterName, new StackId("HDP", STACK_VERSION));
     cluster = clusters.getCluster(clusterName);
     Assert.assertNotNull(cluster);
   }
@@ -301,8 +305,11 @@ public class AlertEventPublisherTest {
   }
 
   private void installHdfsService() throws Exception {
+    RepositoryVersionEntity repositoryVersion = ormHelper.getOrCreateRepositoryVersion(
+        cluster.getCurrentStackVersion(), REPO_VERSION);
+
     String serviceName = "HDFS";
-    Service service = serviceFactory.createNew(cluster, serviceName);
+    Service service = serviceFactory.createNew(cluster, serviceName, repositoryVersion);
     service = cluster.getService(serviceName);
 
     Assert.assertNotNull(service);

http://git-wip-us.apache.org/repos/asf/ambari/blob/dcbd826c/ambari-server/src/test/java/org/apache/ambari/server/state/alerts/InitialAlertEventTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/alerts/InitialAlertEventTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/alerts/InitialAlertEventTest.java
index 890464d..443b4f0 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/alerts/InitialAlertEventTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/state/alerts/InitialAlertEventTest.java
@@ -28,10 +28,12 @@ import org.apache.ambari.server.events.MockEventListener;
 import org.apache.ambari.server.events.publishers.AlertEventPublisher;
 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.AlertDefinitionDAO;
 import org.apache.ambari.server.orm.dao.AlertsDAO;
 import org.apache.ambari.server.orm.entities.AlertCurrentEntity;
 import org.apache.ambari.server.orm.entities.AlertDefinitionEntity;
+import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
 import org.apache.ambari.server.state.Alert;
 import org.apache.ambari.server.state.AlertFirmness;
 import org.apache.ambari.server.state.AlertState;
@@ -72,6 +74,13 @@ public class InitialAlertEventTest {
   private String m_clusterName;
   private ServiceFactory m_serviceFactory;
 
+  private OrmTestHelper m_helper;
+
+  private final String STACK_VERSION = "2.0.6";
+  private final String REPO_VERSION = "2.0.6-1234";
+  private final StackId STACK_ID = new StackId("HDP", STACK_VERSION);
+  private RepositoryVersionEntity m_repositoryVersion;
+
   /**
    *
    */
@@ -97,9 +106,12 @@ public class InitialAlertEventTest {
     m_serviceFactory = m_injector.getInstance(ServiceFactory.class);
 
     m_alertsDao = m_injector.getInstance(AlertsDAO.class);
+    m_helper = m_injector.getInstance(OrmTestHelper.class);
+
+    m_repositoryVersion = m_helper.getOrCreateRepositoryVersion(STACK_ID, REPO_VERSION);
 
     m_clusterName = "c1";
-    m_clusters.addCluster(m_clusterName, new StackId("HDP", "2.0.6"));
+    m_clusters.addCluster(m_clusterName, STACK_ID);
     m_cluster = m_clusters.getCluster(m_clusterName);
     Assert.assertNotNull(m_cluster);
 
@@ -175,7 +187,7 @@ public class InitialAlertEventTest {
 
   private void installHdfsService() throws Exception {
     String serviceName = "HDFS";
-    Service service = m_serviceFactory.createNew(m_cluster, serviceName);
+    Service service = m_serviceFactory.createNew(m_cluster, serviceName, m_repositoryVersion);
     service = m_cluster.getService(serviceName);
 
     Assert.assertNotNull(service);

http://git-wip-us.apache.org/repos/asf/ambari/blob/dcbd826c/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterDeadlockTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterDeadlockTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterDeadlockTest.java
index d479ca2..9c17e01 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterDeadlockTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterDeadlockTest.java
@@ -35,6 +35,7 @@ import org.apache.ambari.server.events.listeners.upgrade.HostVersionOutOfSyncLis
 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.entities.RepositoryVersionEntity;
 import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Clusters;
 import org.apache.ambari.server.state.Config;
@@ -96,6 +97,7 @@ public class ClusterDeadlockTest {
   private OrmTestHelper helper;
 
   private StackId stackId = new StackId("HDP-0.1");
+  private String REPO_VERSION = "0.1-1234";
 
   /**
    * The cluster.
@@ -577,8 +579,6 @@ public class ClusterDeadlockTest {
     sc.addServiceComponentHost(sch);
     sch.setDesiredState(State.INSTALLED);
     sch.setState(State.INSTALLED);
-    sch.setDesiredStackVersion(stackId);
-    sch.setStackVersion(stackId);
 
     return sch;
   }
@@ -586,10 +586,13 @@ public class ClusterDeadlockTest {
   private Service installService(String serviceName) throws AmbariException {
     Service service = null;
 
+    RepositoryVersionEntity repositoryVersion = helper.getOrCreateRepositoryVersion(
+        stackId, REPO_VERSION);
+
     try {
       service = cluster.getService(serviceName);
     } catch (ServiceNotFoundException e) {
-      service = serviceFactory.createNew(cluster, serviceName);
+      service = serviceFactory.createNew(cluster, serviceName, repositoryVersion);
       cluster.addService(service);
     }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/dcbd826c/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 76f9130..ec5eef0 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
@@ -40,6 +40,8 @@ import org.apache.ambari.server.HostNotFoundException;
 import org.apache.ambari.server.controller.AmbariSessionManager;
 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.entities.RepositoryVersionEntity;
 import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Clusters;
 import org.apache.ambari.server.state.Host;
@@ -60,12 +62,14 @@ public class ClusterImplTest {
 
   private static Injector injector;
   private static Clusters clusters;
+  private static OrmTestHelper ormTestHelper;
 
   @BeforeClass
   public static void setUpClass() throws Exception {
     injector = Guice.createInjector(new InMemoryDefaultTestModule());
     injector.getInstance(GuiceJpaInitializer.class);
     clusters = injector.getInstance(Clusters.class);
+    ormTestHelper = injector.getInstance(OrmTestHelper.class);
   }
 
   @AfterClass
@@ -207,10 +211,15 @@ public class ClusterImplTest {
     String clusterName = "TEST_CLUSTER";
     String hostName1 = "HOST1", hostName2 = "HOST2";
 
-    clusters.addCluster(clusterName, new StackId("HDP-2.1.1"));
+    String stackVersion = "HDP-2.1.1";
+    String repoVersion = "2.1.1-1234";
 
+    clusters.addCluster(clusterName, new StackId(stackVersion));
     Cluster cluster = clusters.getCluster(clusterName);
 
+    RepositoryVersionEntity repositoryVersion = ormTestHelper.getOrCreateRepositoryVersion(
+        new StackId(stackVersion), repoVersion);
+
     clusters.addHost(hostName1);
     clusters.addHost(hostName2);
 
@@ -222,7 +231,7 @@ public class ClusterImplTest {
 
     clusters.mapAndPublishHostsToCluster(Sets.newHashSet(hostName1, hostName2), clusterName);
 
-    Service hdfs = cluster.addService("HDFS");
+    Service hdfs = cluster.addService("HDFS", repositoryVersion);
 
     ServiceComponent nameNode = hdfs.addServiceComponent("NAMENODE");
     nameNode.addServiceComponentHost(hostName1);
@@ -235,7 +244,7 @@ public class ClusterImplTest {
     hdfsClient.addServiceComponentHost(hostName1);
     hdfsClient.addServiceComponentHost(hostName2);
 
-    Service tez = cluster.addService(serviceToDelete);
+    Service tez = cluster.addService(serviceToDelete, repositoryVersion);
 
     ServiceComponent tezClient = tez.addServiceComponent("TEZ_CLIENT");
     ServiceComponentHost tezClientHost1 =  tezClient.addServiceComponentHost(hostName1);

http://git-wip-us.apache.org/repos/asf/ambari/blob/dcbd826c/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterTest.java
index e5e2643..6471988 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterTest.java
@@ -344,20 +344,26 @@ public class ClusterTest {
   }
 
   /**
-   * For Rolling Upgrades, create a cluster with the following components
-   * HDFS: NameNode, DataNode, HDFS Client
-   * ZK: Zookeeper Server, Zookeeper Monitor
+   * For Rolling Upgrades, create a cluster with the following components HDFS:
+   * NameNode, DataNode, HDFS Client ZK: Zookeeper Server, Zookeeper Monitor
    * Ganglia: Ganglia Server, Ganglia Monitor
    *
-   * Further, 3 hosts will be added.
-   * Finally, verify that only the Ganglia components do not need to advertise a version.
-   * @param clusterName Cluster Name
-   * @param stackId Stack to set for the cluster
-   * @param hostAttributes Host attributes to use for 3 hosts (h-1, h-2, h-3)
+   * Further, 3 hosts will be added. Finally, verify that only the Ganglia
+   * components do not need to advertise a version.
+   *
+   * @param clusterName
+   *          Cluster Name
+   * @param repositoryVersion
+   *          the repository to use for new services being installed in the
+   *          cluster
+   * @param hostAttributes
+   *          Host attributes to use for 3 hosts (h-1, h-2, h-3)
    * @throws Exception
    * @return Cluster that was created
    */
-  private Cluster createClusterForRU(String clusterName, StackId stackId, Map<String, String> hostAttributes) throws Exception {
+  private Cluster createClusterForRU(String clusterName, RepositoryVersionEntity repositoryVersion,
+      Map<String, String> hostAttributes) throws Exception {
+    StackId stackId = repositoryVersion.getStackId();
     clusters.addCluster(clusterName, stackId);
     Cluster cluster = clusters.getCluster(clusterName);
     Assert.assertEquals(clusterName, cluster.getClusterName());
@@ -382,9 +388,9 @@ public class ClusterTest {
     }
 
     // Add Services
-    Service s1 = serviceFactory.createNew(cluster, "HDFS");
-    Service s2 = serviceFactory.createNew(cluster, "ZOOKEEPER");
-    Service s3 = serviceFactory.createNew(cluster, "GANGLIA");
+    Service s1 = serviceFactory.createNew(cluster, "HDFS", repositoryVersion);
+    Service s2 = serviceFactory.createNew(cluster, "ZOOKEEPER", repositoryVersion);
+    Service s3 = serviceFactory.createNew(cluster, "GANGLIA", repositoryVersion);
     cluster.addService(s1);
     cluster.addService(s2);
     cluster.addService(s3);
@@ -648,8 +654,10 @@ public class ClusterTest {
     // public Service getService(String serviceName) throws AmbariException;
     // public Map<String, Service> getServices();
 
-    Service s1 = serviceFactory.createNew(c1, "HDFS");
-    Service s2 = serviceFactory.createNew(c1, "MAPREDUCE");
+    RepositoryVersionEntity repositoryVersion = c1.getCurrentClusterVersion().getRepositoryVersion();
+
+    Service s1 = serviceFactory.createNew(c1, "HDFS", repositoryVersion);
+    Service s2 = serviceFactory.createNew(c1, "MAPREDUCE", repositoryVersion);
 
     Service s = c1.getService("HDFS");
     Assert.assertNotNull(s);
@@ -676,7 +684,9 @@ public class ClusterTest {
     // TODO write unit tests
     // public List<ServiceComponentHost> getServiceComponentHosts(String hostname);
 
-    Service s = serviceFactory.createNew(c1, "HDFS");
+    RepositoryVersionEntity repositoryVersion = c1.getCurrentClusterVersion().getRepositoryVersion();
+
+    Service s = serviceFactory.createNew(c1, "HDFS", repositoryVersion);
     c1.addService(s);
     ServiceComponent sc = serviceComponentFactory.createNew(s, "NAMENODE");
     s.addServiceComponent(sc);
@@ -694,7 +704,7 @@ public class ClusterTest {
     try {
       while (iterator.hasNext()) {
         iterator.next();
-        Service s1 = serviceFactory.createNew(c1, "PIG");
+        Service s1 = serviceFactory.createNew(c1, "PIG", repositoryVersion);
         c1.addService(s1);
         ServiceComponent sc1 = serviceComponentFactory.createNew(s1, "PIG");
         s1.addServiceComponent(sc1);
@@ -713,7 +723,9 @@ public class ClusterTest {
   public void testGetServiceComponentHosts_ForService() throws Exception {
     createDefaultCluster();
 
-    Service s = serviceFactory.createNew(c1, "HDFS");
+    RepositoryVersionEntity repositoryVersion = c1.getCurrentClusterVersion().getRepositoryVersion();
+
+    Service s = serviceFactory.createNew(c1, "HDFS", repositoryVersion);
     c1.addService(s);
 
     ServiceComponent scNN = serviceComponentFactory.createNew(s, "NAMENODE");
@@ -741,7 +753,9 @@ public class ClusterTest {
   public void testGetServiceComponentHosts_ForServiceComponent() throws Exception {
     createDefaultCluster();
 
-    Service s = serviceFactory.createNew(c1, "HDFS");
+    RepositoryVersionEntity repositoryVersion = c1.getCurrentClusterVersion().getRepositoryVersion();
+
+    Service s = serviceFactory.createNew(c1, "HDFS", repositoryVersion);
     c1.addService(s);
 
     ServiceComponent scNN = serviceComponentFactory.createNew(s, "NAMENODE");
@@ -775,7 +789,9 @@ public class ClusterTest {
   public void testGetServiceComponentHostMap() throws Exception {
     createDefaultCluster();
 
-    Service s = serviceFactory.createNew(c1, "HDFS");
+    RepositoryVersionEntity repositoryVersion = c1.getCurrentClusterVersion().getRepositoryVersion();
+
+    Service s = serviceFactory.createNew(c1, "HDFS", repositoryVersion);
     c1.addService(s);
 
     ServiceComponent scNN = serviceComponentFactory.createNew(s, "NAMENODE");
@@ -807,10 +823,12 @@ public class ClusterTest {
   public void testGetServiceComponentHostMap_ForService() throws Exception {
     createDefaultCluster();
 
-    Service sfHDFS = serviceFactory.createNew(c1, "HDFS");
+    RepositoryVersionEntity repositoryVersion = c1.getCurrentClusterVersion().getRepositoryVersion();
+
+    Service sfHDFS = serviceFactory.createNew(c1, "HDFS", repositoryVersion);
     c1.addService(sfHDFS);
 
-    Service sfMR = serviceFactory.createNew(c1, "MAPREDUCE");
+    Service sfMR = serviceFactory.createNew(c1, "MAPREDUCE", repositoryVersion);
     c1.addService(sfMR);
 
     ServiceComponent scNN = serviceComponentFactory.createNew(sfHDFS, "NAMENODE");
@@ -863,10 +881,12 @@ public class ClusterTest {
   public void testGetServiceComponentHostMap_ForHost() throws Exception {
     createDefaultCluster();
 
-    Service sfHDFS = serviceFactory.createNew(c1, "HDFS");
+    RepositoryVersionEntity repositoryVersion = c1.getCurrentClusterVersion().getRepositoryVersion();
+
+    Service sfHDFS = serviceFactory.createNew(c1, "HDFS", repositoryVersion);
     c1.addService(sfHDFS);
 
-    Service sfMR = serviceFactory.createNew(c1, "MAPREDUCE");
+    Service sfMR = serviceFactory.createNew(c1, "MAPREDUCE", repositoryVersion);
     c1.addService(sfMR);
 
     ServiceComponent scNN = serviceComponentFactory.createNew(sfHDFS, "NAMENODE");
@@ -920,10 +940,12 @@ public class ClusterTest {
   public void testGetServiceComponentHostMap_ForHostAndService() throws Exception {
     createDefaultCluster();
 
-    Service sfHDFS = serviceFactory.createNew(c1, "HDFS");
+    RepositoryVersionEntity repositoryVersion = c1.getCurrentClusterVersion().getRepositoryVersion();
+
+    Service sfHDFS = serviceFactory.createNew(c1, "HDFS", repositoryVersion);
     c1.addService(sfHDFS);
 
-    Service sfMR = serviceFactory.createNew(c1, "MAPREDUCE");
+    Service sfMR = serviceFactory.createNew(c1, "MAPREDUCE", repositoryVersion);
     c1.addService(sfMR);
 
     ServiceComponent scNN = serviceComponentFactory.createNew(sfHDFS, "NAMENODE");
@@ -1104,9 +1126,11 @@ public class ClusterTest {
   public void testDeleteService() throws Exception {
     createDefaultCluster();
 
-    c1.addService("MAPREDUCE");
+    RepositoryVersionEntity repositoryVersion = c1.getCurrentClusterVersion().getRepositoryVersion();
 
-    Service hdfs = c1.addService("HDFS");
+    c1.addService("MAPREDUCE", repositoryVersion);
+
+    Service hdfs = c1.addService("HDFS", repositoryVersion);
     ServiceComponent nameNode = hdfs.addServiceComponent("NAMENODE");
 
     assertEquals(2, c1.getServices().size());
@@ -1124,7 +1148,9 @@ public class ClusterTest {
   public void testDeleteServiceWithConfigHistory() throws Exception {
     createDefaultCluster();
 
-    c1.addService("HDFS");
+    RepositoryVersionEntity repositoryVersion = c1.getCurrentClusterVersion().getRepositoryVersion();
+
+    c1.addService("HDFS", repositoryVersion);
 
     Config config1 = configFactory.createNew(c1, "hdfs-site", "version1",
       new HashMap<String, String>() {{ put("a", "b"); }}, new HashMap<String, Map<String,String>>());
@@ -1694,8 +1720,10 @@ public class ClusterTest {
 
     assertTrue(checked);
 
+    RepositoryVersionEntity repositoryVersion = c1.getCurrentClusterVersion().getRepositoryVersion();
+
     // add some host components
-    Service hdfs = serviceFactory.createNew(c1, "HDFS");
+    Service hdfs = serviceFactory.createNew(c1, "HDFS", repositoryVersion);
     c1.addService(hdfs);
 
     // Add HDFS components
@@ -1997,7 +2025,7 @@ public class ClusterTest {
     hostAttributes.put("os_family", "redhat");
     hostAttributes.put("os_release_version", "6.4");
 
-    Cluster cluster = createClusterForRU(clusterName, stackId, hostAttributes);
+    Cluster cluster = createClusterForRU(clusterName, rv1, hostAttributes);
 
     // Begin install by starting to advertise versions
     // Set the version for the HostComponentState objects
@@ -2154,7 +2182,7 @@ public class ClusterTest {
     hostAttributes.put("os_family", "redhat");
     hostAttributes.put("os_release_version", "6.4");
 
-    Cluster cluster = createClusterForRU(clusterName, stackId, hostAttributes);
+    Cluster cluster = createClusterForRU(clusterName, rv1, hostAttributes);
 
     // Make one host unhealthy
     Host deadHost = cluster.getHosts().iterator().next();
@@ -2233,10 +2261,8 @@ public class ClusterTest {
     String v1 = "2.0.5-1";
     String v2 = "2.0.5-2";
     c1.setDesiredStackVersion(stackId);
-    RepositoryVersionEntity rve1 = helper.getOrCreateRepositoryVersion(stackId,
-        v1);
-    RepositoryVersionEntity rve2 = helper.getOrCreateRepositoryVersion(stackId,
-        v2);
+    RepositoryVersionEntity rve1 = helper.getOrCreateRepositoryVersion(stackId, v1);
+    RepositoryVersionEntity rve2 = helper.getOrCreateRepositoryVersion(stackId, v2);
 
     c1.setCurrentStackVersion(stackId);
     c1.createClusterVersion(stackId, v1, "admin",
@@ -2248,12 +2274,14 @@ public class ClusterTest {
     clusters.mapHostToCluster("h-3", clusterName);
     ClusterVersionDAOMock.failOnCurrentVersionState = false;
 
-    Service service = c1.addService("ZOOKEEPER");
+    RepositoryVersionEntity repositoryVersion = c1.getCurrentClusterVersion().getRepositoryVersion();
+
+    Service service = c1.addService("ZOOKEEPER", repositoryVersion);
     ServiceComponent sc = service.addServiceComponent("ZOOKEEPER_SERVER");
     sc.addServiceComponentHost("h-1");
     sc.addServiceComponentHost("h-2");
 
-    service = c1.addService("SQOOP");
+    service = c1.addService("SQOOP", repositoryVersion);
     sc = service.addServiceComponent("SQOOP");
     sc.addServiceComponentHost("h-3");
 
@@ -2317,7 +2345,9 @@ public class ClusterTest {
 
     ClusterVersionDAOMock.failOnCurrentVersionState = false;
 
-    Service service = c1.addService("ZOOKEEPER");
+    RepositoryVersionEntity repositoryVersion = c1.getCurrentClusterVersion().getRepositoryVersion();
+
+    Service service = c1.addService("ZOOKEEPER", repositoryVersion);
     ServiceComponent sc = service.addServiceComponent("ZOOKEEPER_SERVER");
     sc.addServiceComponentHost("h-1");
     sc.addServiceComponentHost("h-2");

http://git-wip-us.apache.org/repos/asf/ambari/blob/dcbd826c/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 1a112d6..801f3a7 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
@@ -34,6 +34,7 @@ import org.apache.ambari.server.events.listeners.upgrade.HostVersionOutOfSyncLis
 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.entities.RepositoryVersionEntity;
 import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Clusters;
 import org.apache.ambari.server.state.Host;
@@ -75,7 +76,8 @@ public class ClustersDeadlockTest {
   private CountDownLatch writerStoppedSignal;
   private CountDownLatch readerStoppedSignal;
 
-  private final StackId stackId = new StackId("HDP-0.1");
+  private StackId stackId = new StackId("HDP-0.1");
+  private String REPO_VERSION = "0.1-1234";
 
   @Inject
   private Injector injector;
@@ -381,10 +383,13 @@ public class ClustersDeadlockTest {
   private Service installService(String serviceName) throws AmbariException {
     Service service = null;
 
+    RepositoryVersionEntity repositoryVersion = helper.getOrCreateRepositoryVersion(
+        stackId, REPO_VERSION);
+
     try {
       service = cluster.getService(serviceName);
     } catch (ServiceNotFoundException e) {
-      service = serviceFactory.createNew(cluster, serviceName);
+      service = serviceFactory.createNew(cluster, serviceName, repositoryVersion);
       cluster.addService(service);
     }
 
@@ -418,8 +423,6 @@ public class ClustersDeadlockTest {
     sc.addServiceComponentHost(sch);
     sch.setDesiredState(State.INSTALLED);
     sch.setState(State.INSTALLED);
-    sch.setDesiredStackVersion(stackId);
-    sch.setStackVersion(stackId);
 
     return sch;
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/dcbd826c/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 c6cef26..43e9737 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
@@ -57,6 +57,7 @@ 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;
 import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Clusters;
@@ -399,9 +400,13 @@ public class ClustersTest {
 
     cluster.setDesiredStackVersion(stackId);
     cluster.setCurrentStackVersion(stackId);
-    helper.getOrCreateRepositoryVersion(stackId, stackId.getStackVersion());
+
+    RepositoryVersionEntity repositoryVersion = helper.getOrCreateRepositoryVersion(stackId,
+        stackId.getStackVersion());
+
     cluster.createClusterVersion(stackId, stackId.getStackVersion(), "admin",
         RepositoryVersionState.INSTALLING);
+
     cluster.transitionClusterVersion(stackId, stackId.getStackVersion(),
         RepositoryVersionState.CURRENT);
 
@@ -422,7 +427,7 @@ public class ClustersTest {
     clusters.addHost(h2);
 
     Host host1 = clusters.getHost(h1);
-    Host host2 = clusters.getHost(h2);
+
     setOsFamily(clusters.getHost(h1), "centos", "5.9");
     setOsFamily(clusters.getHost(h2), "centos", "5.9");
 
@@ -435,7 +440,7 @@ public class ClustersTest {
     // host config override
     host1.addDesiredConfig(cluster.getClusterId(), true, "_test", config2);
 
-    Service hdfs = cluster.addService("HDFS");
+    Service hdfs = cluster.addService("HDFS", repositoryVersion);
 
     Assert.assertNotNull(injector.getInstance(ClusterServiceDAO.class).findByClusterAndServiceNames(c1, "HDFS"));
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/dcbd826c/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 46a039d..4d06f60 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
@@ -34,6 +34,7 @@ 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.ServiceConfigDAO;
+import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
 import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Clusters;
 import org.apache.ambari.server.state.Host;
@@ -95,6 +96,8 @@ public class ConcurrentServiceConfigVersionTest {
    */
   private Cluster cluster;
 
+  private RepositoryVersionEntity repositoryVersion;
+
   /**
    * Creates a cluster and installs HDFS with NN and DN.
    *
@@ -109,7 +112,7 @@ public class ConcurrentServiceConfigVersionTest {
     injector.injectMembers(this);
     clusters.addCluster("c1", stackId);
     cluster = clusters.getCluster("c1");
-    helper.getOrCreateRepositoryVersion(stackId, stackId.getStackVersion());
+    repositoryVersion = helper.getOrCreateRepositoryVersion(stackId, stackId.getStackVersion());
     cluster.createClusterVersion(stackId,
         stackId.getStackVersion(), "admin", RepositoryVersionState.INSTALLING);
 
@@ -210,8 +213,6 @@ public class ConcurrentServiceConfigVersionTest {
     sc.addServiceComponentHost(sch);
     sch.setDesiredState(State.INSTALLED);
     sch.setState(State.INSTALLED);
-    sch.setDesiredStackVersion(stackId);
-    sch.setStackVersion(stackId);
 
     return sch;
   }
@@ -222,7 +223,7 @@ public class ConcurrentServiceConfigVersionTest {
     try {
       service = cluster.getService(serviceName);
     } catch (ServiceNotFoundException e) {
-      service = serviceFactory.createNew(cluster, serviceName);
+      service = serviceFactory.createNew(cluster, serviceName, repositoryVersion);
       cluster.addService(service);
     }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/dcbd826c/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 8f37ad7..8cd00ce 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
@@ -34,6 +34,7 @@ import org.apache.ambari.server.events.listeners.upgrade.HostVersionOutOfSyncLis
 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.entities.RepositoryVersionEntity;
 import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Clusters;
 import org.apache.ambari.server.state.Config;
@@ -91,6 +92,8 @@ public class ServiceComponentHostConcurrentWriteDeadlockTest {
   private OrmTestHelper helper;
 
   private StackId stackId = new StackId("HDP-0.1");
+  private final String REPO_VERSION = "0.1-1234";
+  private RepositoryVersionEntity m_repositoryVersion;
 
   /**
    * The cluster.
@@ -111,9 +114,8 @@ public class ServiceComponentHostConcurrentWriteDeadlockTest {
     injector.injectMembers(this);
     clusters.addCluster("c1", stackId);
     cluster = clusters.getCluster("c1");
-    helper.getOrCreateRepositoryVersion(stackId, stackId.getStackVersion());
-    cluster.createClusterVersion(stackId,
-        stackId.getStackVersion(), "admin", RepositoryVersionState.INSTALLING);
+    m_repositoryVersion = helper.getOrCreateRepositoryVersion(stackId, REPO_VERSION);
+    cluster.createClusterVersion(stackId, REPO_VERSION, "admin", RepositoryVersionState.INSTALLING);
 
     Config config1 = configFactory.createNew(cluster, "test-type1", null, new HashMap<String, String>(), new HashMap<String,
         Map<String, String>>());
@@ -224,14 +226,12 @@ public class ServiceComponentHostConcurrentWriteDeadlockTest {
     Service s = installService(svc);
     ServiceComponent sc = addServiceComponent(s, svcComponent);
 
-    ServiceComponentHost sch = serviceComponentHostFactory.createNew(sc,
-        hostName);
+    ServiceComponentHost sch = serviceComponentHostFactory.createNew(sc, hostName);
 
     sc.addServiceComponentHost(sch);
     sch.setDesiredState(State.INSTALLED);
     sch.setState(State.INSTALLED);
-    sch.setDesiredStackVersion(stackId);
-    sch.setStackVersion(stackId);
+    sch.setVersion(REPO_VERSION);
 
     return sch;
   }
@@ -242,7 +242,7 @@ public class ServiceComponentHostConcurrentWriteDeadlockTest {
     try {
       service = cluster.getService(serviceName);
     } catch (ServiceNotFoundException e) {
-      service = serviceFactory.createNew(cluster, serviceName);
+      service = serviceFactory.createNew(cluster, serviceName, m_repositoryVersion);
       cluster.addService(service);
     }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/dcbd826c/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 6db820b..3a80ca7 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
@@ -40,9 +40,11 @@ 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.entities.ClusterEntity;
+import org.apache.ambari.server.orm.entities.ClusterVersionEntity;
 import org.apache.ambari.server.orm.entities.HostComponentDesiredStateEntity;
 import org.apache.ambari.server.orm.entities.HostComponentStateEntity;
 import org.apache.ambari.server.orm.entities.HostEntity;
+import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
 import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Clusters;
 import org.apache.ambari.server.state.Config;
@@ -107,6 +109,7 @@ public class ServiceComponentHostTest {
   private String clusterName = "c1";
   private String hostName1 = "h1";
   private Map<String, String> hostAttributes = new HashMap<>();
+  private RepositoryVersionEntity repositoryVersion;
 
 
   @Before
@@ -115,7 +118,7 @@ public class ServiceComponentHostTest {
     injector.getInstance(GuiceJpaInitializer.class);
     injector.injectMembers(this);
 
-    StackId stackId = new StackId("HDP-0.1");
+    StackId stackId = new StackId("HDP-2.0.6");
     createCluster(stackId, clusterName);
     hostAttributes.put("os_family", "redhat");
     hostAttributes.put("os_release_version", "5.9");
@@ -126,8 +129,10 @@ public class ServiceComponentHostTest {
 
     Cluster c1 = clusters.getCluster(clusterName);
     helper.getOrCreateRepositoryVersion(stackId, stackId.getStackVersion());
-    c1.createClusterVersion(stackId, stackId.getStackVersion(), "admin",
-            RepositoryVersionState.INSTALLING);
+    ClusterVersionEntity clusterVersion = c1.createClusterVersion(stackId,
+        stackId.getStackVersion(), "admin", RepositoryVersionState.INSTALLING);
+
+    repositoryVersion = clusterVersion.getRepositoryVersion();
   }
 
   @After
@@ -180,7 +185,8 @@ public class ServiceComponentHostTest {
     } catch (ServiceNotFoundException e) {
       LOG.debug("Calling service create"
           + ", serviceName=" + svc);
-      s = serviceFactory.createNew(c, svc);
+
+      s = serviceFactory.createNew(c, svc, repositoryVersion);
       c.addService(s);
     }
 
@@ -207,10 +213,7 @@ public class ServiceComponentHostTest {
 
     Assert.assertNotNull(c.getServiceComponentHosts(hostName));
 
-    Assert.assertFalse(
-        impl.getDesiredStackVersion().getStackId().isEmpty());
-
-    Assert.assertFalse(impl.getStackVersion().getStackId().isEmpty());
+    Assert.assertNotNull(sc.getDesiredRepositoryVersion());
 
     return impl;
   }
@@ -229,7 +232,7 @@ public class ServiceComponentHostTest {
       case HOST_SVCCOMP_INSTALL:
         return new ServiceComponentHostInstallEvent(
             impl.getServiceComponentName(), impl.getHostName(), timestamp,
-            impl.getDesiredStackVersion().getStackId());
+            impl.getServiceComponent().getDesiredStackVersion().toString());
       case HOST_SVCCOMP_START:
         return new ServiceComponentHostStartEvent(
             impl.getServiceComponentName(), impl.getHostName(), timestamp);
@@ -289,9 +292,7 @@ public class ServiceComponentHostTest {
     Assert.assertEquals(inProgressState,
         impl.getState());
     if (checkStack) {
-      Assert.assertNotNull(impl.getStackVersion());
-      Assert.assertEquals(impl.getDesiredStackVersion().getStackId(),
-          impl.getStackVersion().getStackId());
+      Assert.assertNotNull(impl.getServiceComponent().getDesiredStackVersion());
     }
 
     ServiceComponentHostEvent installEvent2 = createEvent(impl, ++timestamp,
@@ -537,15 +538,9 @@ public class ServiceComponentHostTest {
     ServiceComponentHost sch = createNewServiceComponentHost(clusterName, "HDFS", "NAMENODE", hostName1, false);
     sch.setDesiredState(State.INSTALLED);
     sch.setState(State.INSTALLING);
-    sch.setStackVersion(new StackId("HDP-1.2.0"));
-    sch.setDesiredStackVersion(new StackId("HDP-1.2.0"));
 
     Assert.assertEquals(State.INSTALLING, sch.getState());
     Assert.assertEquals(State.INSTALLED, sch.getDesiredState());
-    Assert.assertEquals("HDP-1.2.0",
-        sch.getStackVersion().getStackId());
-    Assert.assertEquals("HDP-1.2.0",
-            sch.getDesiredStackVersion().getStackId());
   }
 
   @Test
@@ -553,8 +548,6 @@ public class ServiceComponentHostTest {
     ServiceComponentHost sch = createNewServiceComponentHost(clusterName, "HDFS", "NAMENODE", hostName1, false);
     sch.setDesiredState(State.INSTALLED);
     sch.setState(State.INSTALLING);
-    sch.setStackVersion(new StackId("HDP-1.2.0"));
-    sch.setDesiredStackVersion(new StackId("HDP-1.2.0"));
 
     Cluster cluster = clusters.getCluster(clusterName);
 
@@ -585,7 +578,6 @@ public class ServiceComponentHostTest {
     ServiceComponentHost sch = createNewServiceComponentHost(clusterName, "HDFS", "DATANODE", hostName1, false);
     sch.setDesiredState(State.INSTALLED);
     sch.setState(State.INSTALLING);
-    sch.setStackVersion(new StackId("HDP-1.2.0"));
     ServiceComponentHostResponse r = sch.convertToResponse(null);
     Assert.assertEquals("HDFS", r.getServiceName());
     Assert.assertEquals("DATANODE", r.getComponentName());
@@ -593,7 +585,7 @@ public class ServiceComponentHostTest {
     Assert.assertEquals(clusterName, r.getClusterName());
     Assert.assertEquals(State.INSTALLED.toString(), r.getDesiredState());
     Assert.assertEquals(State.INSTALLING.toString(), r.getLiveState());
-    Assert.assertEquals("HDP-1.2.0", r.getStackVersion());
+    Assert.assertEquals(repositoryVersion.getStackId().toString(), r.getDesiredStackVersion());
 
     Assert.assertFalse(r.isStaleConfig());
 
@@ -727,24 +719,25 @@ public class ServiceComponentHostTest {
     Assert.assertNotNull(cluster);
 
     helper.getOrCreateRepositoryVersion(stackId, stackId.getStackVersion());
-    cluster.createClusterVersion(stackId, stackId.getStackVersion(), "admin",
-        RepositoryVersionState.INSTALLING);
+    ClusterVersionEntity clusterVersion = cluster.createClusterVersion(stackId,
+        stackId.getStackVersion(), "admin", RepositoryVersionState.INSTALLING);
+
+    RepositoryVersionEntity repositoryVersion = clusterVersion.getRepositoryVersion();
 
     ServiceComponentHost sch1 = createNewServiceComponentHost(cluster, "HDFS", "NAMENODE", hostName);
     ServiceComponentHost sch2 = createNewServiceComponentHost(cluster, "HDFS", "DATANODE", hostName);
     ServiceComponentHost sch3 = createNewServiceComponentHost(cluster, "MAPREDUCE2", "HISTORYSERVER", hostName);
 
+    sch1.getServiceComponent().setDesiredRepositoryVersion(repositoryVersion);
+
     sch1.setDesiredState(State.INSTALLED);
     sch1.setState(State.INSTALLING);
-    sch1.setStackVersion(new StackId(stackVersion));
 
     sch2.setDesiredState(State.INSTALLED);
     sch2.setState(State.INSTALLING);
-    sch2.setStackVersion(new StackId(stackVersion));
 
     sch3.setDesiredState(State.INSTALLED);
     sch3.setState(State.INSTALLING);
-    sch3.setStackVersion(new StackId(stackVersion));
 
     Assert.assertFalse(sch1.convertToResponse(null).isStaleConfig());
     Assert.assertFalse(sch2.convertToResponse(null).isStaleConfig());
@@ -917,24 +910,26 @@ public class ServiceComponentHostTest {
     Cluster cluster = clusters.getCluster(clusterName);
 
     helper.getOrCreateRepositoryVersion(stackId, stackId.getStackVersion());
-    cluster.createClusterVersion(stackId, stackId.getStackVersion(), "admin",
+    ClusterVersionEntity clusterVersion = cluster.createClusterVersion(stackId,
+        stackId.getStackVersion(), "admin",
         RepositoryVersionState.INSTALLING);
 
+    RepositoryVersionEntity repositoryVersion = clusterVersion.getRepositoryVersion();
+
     ServiceComponentHost sch1 = createNewServiceComponentHost(cluster, "HDFS", "NAMENODE", hostName);
     ServiceComponentHost sch2 = createNewServiceComponentHost(cluster, "HDFS", "DATANODE", hostName);
     ServiceComponentHost sch3 = createNewServiceComponentHost(cluster, "MAPREDUCE2", "HISTORYSERVER", hostName);
 
+    sch1.getServiceComponent().setDesiredRepositoryVersion(repositoryVersion);
+
     sch1.setDesiredState(State.INSTALLED);
     sch1.setState(State.INSTALLING);
-    sch1.setStackVersion(new StackId(stackVersion));
 
     sch2.setDesiredState(State.INSTALLED);
     sch2.setState(State.INSTALLING);
-    sch2.setStackVersion(new StackId(stackVersion));
 
     sch3.setDesiredState(State.INSTALLED);
     sch3.setState(State.INSTALLING);
-    sch3.setStackVersion(new StackId(stackVersion));
 
     Assert.assertFalse(sch1.convertToResponse(null).isStaleConfig());
     Assert.assertFalse(sch2.convertToResponse(null).isStaleConfig());

http://git-wip-us.apache.org/repos/asf/ambari/blob/dcbd826c/ambari-server/src/test/java/org/apache/ambari/server/upgrade/StackUpgradeUtilTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/StackUpgradeUtilTest.java b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/StackUpgradeUtilTest.java
deleted file mode 100644
index 3ebf4e7..0000000
--- a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/StackUpgradeUtilTest.java
+++ /dev/null
@@ -1,145 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.ambari.server.upgrade;
-
-import java.util.Collection;
-import java.util.List;
-import java.util.Map.Entry;
-
-import org.apache.ambari.server.H2DatabaseCleaner;
-import org.apache.ambari.server.api.services.AmbariMetaInfo;
-import org.apache.ambari.server.orm.GuiceJpaInitializer;
-import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
-import org.apache.ambari.server.orm.dao.MetainfoDAO;
-import org.apache.ambari.server.orm.entities.MetainfoEntity;
-import org.apache.ambari.server.state.RepositoryInfo;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-
-import com.google.inject.Guice;
-import com.google.inject.Injector;
-
-/**
- * Tests the StackUpgradeHelper
- */
-public class StackUpgradeUtilTest {
-
-  private Injector injector;
-
-  @Before
-  public void setup() throws Exception {
-    injector = Guice.createInjector(new InMemoryDefaultTestModule());
-    injector.getInstance(GuiceJpaInitializer.class);
-  }
-
-  @After
-  public void teardown() throws Exception {
-    H2DatabaseCleaner.clearDatabaseAndStopPersistenceService(injector);
-  }
-
-  private void reset(String stackName, String stackVersion) throws Exception {
-    AmbariMetaInfo ami = injector.getInstance(AmbariMetaInfo.class);
-
-    for (Entry<String, List<RepositoryInfo>> entry : ami.getRepository(stackName, stackVersion).entrySet()) {
-      for (RepositoryInfo ri : entry.getValue()) {
-        if (-1 == ri.getRepoId().indexOf("epel")) {
-          ami.updateRepo(stackName, stackVersion,
-              ri.getOsType(), ri.getRepoId(), "", null);
-        }
-      }
-    }
-
-  }
-
-  @Test
-  public void testUpgradeStack() throws Exception {
-    StackUpgradeUtil stackUpgradeUtil = injector.getInstance(StackUpgradeUtil.class);
-
-    String stackName = "HDP";
-    String stackVersion = "1.3.0";
-    String localRepoUrl = "http://foo.bar";
-
-    // check updating all
-    stackUpgradeUtil.updateLocalRepo(stackName, stackVersion, localRepoUrl, null, null);
-
-    MetainfoDAO dao = injector.getInstance(MetainfoDAO.class);
-
-    Collection<MetainfoEntity> entities = dao.findAll();
-    Assert.assertTrue(entities.size() > 0);
-
-    for (MetainfoEntity entity : entities) {
-      Assert.assertTrue(entity.getMetainfoName().startsWith("repo:/HDP/1.3.0/"));
-      Assert.assertEquals(localRepoUrl, entity.getMetainfoValue());
-    }
-
-    reset (stackName, stackVersion);
-    entities = dao.findAll();
-    Assert.assertEquals(0, entities.size());
-
-    // check updating only centos6
-    stackUpgradeUtil.updateLocalRepo(stackName, stackVersion, localRepoUrl, "centos6", null);
-
-    entities = dao.findAll();
-    for (MetainfoEntity entity : entities) {
-      Assert.assertTrue(entity.getMetainfoName().startsWith("repo:/HDP/1.3.0/centos6") ||
-          entity.getMetainfoName().startsWith("repo:/HDP/1.3.0/redhat6"));
-      Assert.assertEquals(localRepoUrl, entity.getMetainfoValue());
-    }
-
-    reset (stackName, stackVersion);
-    entities = dao.findAll();
-    Assert.assertTrue(0 == entities.size());
-
-    // check updating only centos6 and centos5
-    stackUpgradeUtil.updateLocalRepo(stackName, stackVersion, localRepoUrl, "centos6,centos5", null);
-
-    entities = dao.findAll();
-    for (MetainfoEntity entity : entities) {
-      Assert.assertTrue(entity.getMetainfoName().startsWith("repo:/HDP/1.3.0/centos6") ||
-          entity.getMetainfoName().startsWith("repo:/HDP/1.3.0/redhat6") ||
-          entity.getMetainfoName().startsWith("repo:/HDP/1.3.0/redhat5") ||
-          entity.getMetainfoName().startsWith("repo:/HDP/1.3.0/centos5"));
-      Assert.assertEquals(localRepoUrl, entity.getMetainfoValue());
-    }
-
-    // verify that a change to centos6 also changes redhat6
-    localRepoUrl = "http://newfoo.bar";
-    stackUpgradeUtil.updateLocalRepo(stackName, stackVersion, localRepoUrl, "centos6", null);
-    entities = dao.findAll();
-    boolean foundCentos6 = false;
-    boolean foundRedhat6 = false;
-    for (MetainfoEntity entity : entities) {
-      if (-1 != entity.getMetainfoName().indexOf("centos6")) {
-        foundCentos6 = true;
-        Assert.assertEquals(localRepoUrl, entity.getMetainfoValue());
-      } else if (-1 != entity.getMetainfoName().indexOf("redhat6")) {
-        foundRedhat6 = true;
-        Assert.assertEquals(localRepoUrl, entity.getMetainfoValue());
-      } else {
-        Assert.assertFalse(localRepoUrl.equals(entity.getMetainfoValue()));
-      }
-    }
-    Assert.assertTrue(foundCentos6);
-    Assert.assertTrue(foundRedhat6);
-
-  }
-
-
-}

http://git-wip-us.apache.org/repos/asf/ambari/blob/dcbd826c/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 c209671..3d1cdfc 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
@@ -63,6 +63,7 @@ import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
 import org.apache.ambari.server.orm.dao.ClusterServiceDAO;
 import org.apache.ambari.server.orm.dao.HostComponentDesiredStateDAO;
 import org.apache.ambari.server.orm.dao.HostComponentStateDAO;
+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.ClusterEntity;
@@ -70,6 +71,7 @@ import org.apache.ambari.server.orm.entities.ClusterServiceEntity;
 import org.apache.ambari.server.orm.entities.HostComponentDesiredStateEntity;
 import org.apache.ambari.server.orm.entities.HostComponentStateEntity;
 import org.apache.ambari.server.orm.entities.HostEntity;
+import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
 import org.apache.ambari.server.orm.entities.ServiceComponentDesiredStateEntity;
 import org.apache.ambari.server.orm.entities.StackEntity;
 import org.apache.ambari.server.state.Cluster;
@@ -107,6 +109,7 @@ public class UpgradeCatalog200Test {
   private final String HOST_NAME = "h1";
 
   private final StackId DESIRED_STACK = new StackId("HDP", "2.0.6");
+  private final String DESIRED_REPO_VERSION = "2.0.6-1234";
 
   private Injector injector;
   private Provider<EntityManager> entityManagerProvider = createStrictMock(Provider.class);
@@ -627,10 +630,14 @@ public class UpgradeCatalog200Test {
     assertNotNull(stackEntity);
 
     final ClusterEntity clusterEntity = upgradeCatalogHelper.createCluster(
-        injector, CLUSTER_NAME, stackEntity);
+        injector, CLUSTER_NAME, stackEntity, DESIRED_REPO_VERSION);
+
+    RepositoryVersionDAO repositoryVersionDAO = injector.getInstance(RepositoryVersionDAO.class);
+    RepositoryVersionEntity repositoryVersion = repositoryVersionDAO.findByStackAndVersion(
+        stackEntity, DESIRED_REPO_VERSION);
 
     final ClusterServiceEntity clusterServiceEntityNagios = upgradeCatalogHelper.addService(
-        injector, clusterEntity, "NAGIOS", stackEntity);
+        injector, clusterEntity, "NAGIOS", repositoryVersion);
 
     final HostEntity hostEntity = upgradeCatalogHelper.createHost(injector,
         clusterEntity, HOST_NAME);

http://git-wip-us.apache.org/repos/asf/ambari/blob/dcbd826c/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 c40eac6..4ed7685 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
@@ -109,6 +109,7 @@ public class UpgradeCatalog210Test {
   private EntityManager entityManager = createNiceMock(EntityManager.class);
   private UpgradeCatalogHelper upgradeCatalogHelper;
   private StackEntity desiredStackEntity;
+  private String desiredRepositoryVersion = "2.2.0-1234";
 
   public void initData() {
     //reset(entityManagerProvider);
@@ -805,9 +806,11 @@ public class UpgradeCatalog210Test {
   public void testDeleteStormRestApiServiceComponent() throws Exception {
     initData();
     ClusterEntity clusterEntity = upgradeCatalogHelper.createCluster(injector,
-      "c1", desiredStackEntity);
+        "c1", desiredStackEntity, desiredRepositoryVersion);
+
     ClusterServiceEntity clusterServiceEntity = upgradeCatalogHelper.createService(
         injector, clusterEntity, "STORM");
+
     HostEntity hostEntity = upgradeCatalogHelper.createHost(injector,
         clusterEntity, "h1");
 
@@ -827,7 +830,6 @@ public class UpgradeCatalog210Test {
     componentDesiredStateEntity.setServiceName(clusterServiceEntity.getServiceName());
     componentDesiredStateEntity.setClusterServiceEntity(clusterServiceEntity);
     componentDesiredStateEntity.setComponentName("STORM_REST_API");
-    componentDesiredStateEntity.setDesiredStack(desiredStackEntity);
 
     ServiceComponentDesiredStateDAO componentDesiredStateDAO =
       injector.getInstance(ServiceComponentDesiredStateDAO.class);
@@ -845,7 +847,6 @@ public class UpgradeCatalog210Test {
     hostComponentDesiredStateEntity.setServiceName(clusterServiceEntity.getServiceName());
     hostComponentDesiredStateEntity.setServiceComponentDesiredStateEntity(componentDesiredStateEntity);
     hostComponentDesiredStateEntity.setHostEntity(hostEntity);
-    hostComponentDesiredStateEntity.setDesiredStack(desiredStackEntity);
 
     hostComponentDesiredStateDAO.create(hostComponentDesiredStateEntity);
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/dcbd826c/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 4413ca8..8b78479 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
@@ -1211,7 +1211,6 @@ public class UpgradeCatalog220Test {
     DBAccessor mockedDbAccessor = mocksControl.createMock(DBAccessor.class);
     DaoUtils mockedDaoUtils = mocksControl.createMock(DaoUtils.class);
     Configuration mockedConfiguration = mocksControl.createMock(Configuration.class);
-    StackUpgradeUtil mockedStackUpgradeUtil = mocksControl.createMock(StackUpgradeUtil.class);
 
     Capture<String> capturedTableName = EasyMock.newCapture();
     Capture<String> capturedPKColumn = EasyMock.newCapture();
@@ -1255,7 +1254,6 @@ public class UpgradeCatalog220Test {
     EasyMockSupport.injectMocks(testSubject);
 
     //todo refactor the DI approach, don't directly access these members!!!
-    testSubject.stackUpgradeUtil = mockedStackUpgradeUtil;
     testSubject.dbAccessor = mockedDbAccessor;
     testSubject.configuration = mockedConfiguration;
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/dcbd826c/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 4c11d10..2cf0321 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
@@ -19,6 +19,7 @@ package org.apache.ambari.server.upgrade;
 
 import java.util.Collections;
 
+import org.apache.ambari.server.orm.OrmTestHelper;
 import org.apache.ambari.server.orm.dao.ClusterDAO;
 import org.apache.ambari.server.orm.dao.ClusterServiceDAO;
 import org.apache.ambari.server.orm.dao.HostComponentDesiredStateDAO;
@@ -30,6 +31,7 @@ import org.apache.ambari.server.orm.entities.ClusterServiceEntity;
 import org.apache.ambari.server.orm.entities.HostComponentDesiredStateEntity;
 import org.apache.ambari.server.orm.entities.HostComponentStateEntity;
 import org.apache.ambari.server.orm.entities.HostEntity;
+import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
 import org.apache.ambari.server.orm.entities.ResourceEntity;
 import org.apache.ambari.server.orm.entities.ResourceTypeEntity;
 import org.apache.ambari.server.orm.entities.ServiceComponentDesiredStateEntity;
@@ -37,6 +39,7 @@ import org.apache.ambari.server.orm.entities.ServiceDesiredStateEntity;
 import org.apache.ambari.server.orm.entities.StackEntity;
 import org.apache.ambari.server.security.authorization.ResourceType;
 import org.apache.ambari.server.state.HostComponentAdminState;
+import org.apache.ambari.server.state.StackId;
 import org.apache.ambari.server.state.State;
 
 import com.google.inject.Injector;
@@ -49,7 +52,8 @@ import com.google.inject.persist.Transactional;
 public class UpgradeCatalogHelper {
 
   /**
-   * Creates a cluster with the specified name and stack.
+   * Creates a cluster with the specified name and stack as well as the
+   * repository version.
    *
    * @param injector
    * @param clusterName
@@ -57,7 +61,7 @@ public class UpgradeCatalogHelper {
    * @return
    */
   protected ClusterEntity createCluster(Injector injector, String clusterName,
-      StackEntity desiredStackEntity) {
+      StackEntity desiredStackEntity, String repositoryVersion) {
     ResourceTypeDAO resourceTypeDAO = injector.getInstance(ResourceTypeDAO.class);
 
     // create an admin resource to represent this cluster
@@ -81,6 +85,12 @@ public class UpgradeCatalogHelper {
     clusterEntity.setResource(resourceEntity);
 
     clusterDAO.create(clusterEntity);
+
+    OrmTestHelper ormTestHelper = injector.getInstance(OrmTestHelper.class);
+    ormTestHelper.getOrCreateRepositoryVersion(
+        new StackId(desiredStackEntity.getStackName(), desiredStackEntity.getStackVersion()),
+        repositoryVersion);
+
     return clusterEntity;
   }
 
@@ -110,19 +120,19 @@ public class UpgradeCatalogHelper {
    * @param injector
    * @param clusterEntity
    * @param serviceName
-   * @param desiredStackEntity
+   * @param desiredRepositoryVersion
    * @return
    */
   protected ClusterServiceEntity addService(Injector injector,
       ClusterEntity clusterEntity, String serviceName,
-      StackEntity desiredStackEntity) {
+      RepositoryVersionEntity desiredRepositoryVersion) {
     ClusterDAO clusterDAO = injector.getInstance(ClusterDAO.class);
 
     ClusterServiceEntity clusterServiceEntity = createService(injector,
         clusterEntity, serviceName);
 
     ServiceDesiredStateEntity serviceDesiredStateEntity = new ServiceDesiredStateEntity();
-    serviceDesiredStateEntity.setDesiredStack(desiredStackEntity);
+    serviceDesiredStateEntity.setDesiredRepositoryVersion(desiredRepositoryVersion);
     serviceDesiredStateEntity.setClusterId(1L);
     serviceDesiredStateEntity.setServiceName(serviceName);
     serviceDesiredStateEntity.setClusterServiceEntity(clusterServiceEntity);
@@ -177,7 +187,6 @@ public class UpgradeCatalogHelper {
     componentDesiredStateEntity.setClusterServiceEntity(clusterServiceEntity);
     componentDesiredStateEntity.setComponentName(componentName);
     componentDesiredStateEntity.setServiceName(clusterServiceEntity.getServiceName());
-    componentDesiredStateEntity.setDesiredStack(desiredStackEntity);
     componentDesiredStateEntity.setClusterServiceEntity(clusterServiceEntity);
     componentDesiredStateEntity.setClusterId(clusterServiceEntity.getClusterId());
     serviceComponentDesiredStateDAO.create(componentDesiredStateEntity);
@@ -190,7 +199,6 @@ public class UpgradeCatalogHelper {
     hostComponentDesiredStateEntity.setAdminState(HostComponentAdminState.INSERVICE);
     hostComponentDesiredStateEntity.setServiceComponentDesiredStateEntity(componentDesiredStateEntity);
     hostComponentDesiredStateEntity.setHostEntity(hostEntity);
-    hostComponentDesiredStateEntity.setDesiredStack(desiredStackEntity);
     hostComponentDesiredStateDAO.create(hostComponentDesiredStateEntity);
 
     HostComponentStateEntity hostComponentStateEntity = new HostComponentStateEntity();
@@ -198,9 +206,7 @@ public class UpgradeCatalogHelper {
     hostComponentStateEntity.setComponentName(componentName);
     hostComponentStateEntity.setServiceName(clusterServiceEntity.getServiceName());
     hostComponentStateEntity.setClusterId(clusterEntity.getClusterId());
-    hostComponentStateEntity.setCurrentStack(clusterEntity.getDesiredStack());
     hostComponentStateEntity.setServiceComponentDesiredStateEntity(componentDesiredStateEntity);
-    hostComponentStateEntity.setCurrentStack(desiredStackEntity);
 
     componentDesiredStateEntity.setHostComponentStateEntities(Collections.singletonList(hostComponentStateEntity));
     componentDesiredStateEntity.setHostComponentDesiredStateEntities(Collections.singletonList(hostComponentDesiredStateEntity));

http://git-wip-us.apache.org/repos/asf/ambari/blob/dcbd826c/ambari-server/src/test/java/org/apache/ambari/server/utils/StageUtilsTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/utils/StageUtilsTest.java b/ambari-server/src/test/java/org/apache/ambari/server/utils/StageUtilsTest.java
index e9bd27c..40bab1d 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/utils/StageUtilsTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/utils/StageUtilsTest.java
@@ -46,7 +46,6 @@ import java.util.TreeMap;
 import javax.persistence.EntityManager;
 import javax.xml.bind.JAXBException;
 
-import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.actionmanager.ExecutionCommandWrapper;
 import org.apache.ambari.server.actionmanager.ExecutionCommandWrapperFactory;
 import org.apache.ambari.server.actionmanager.HostRoleCommandFactory;
@@ -74,7 +73,6 @@ 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.StackId;
 import org.apache.ambari.server.state.cluster.ClusterFactory;
 import org.apache.ambari.server.state.host.HostFactory;
 import org.apache.ambari.server.state.stack.OsFamily;
@@ -140,29 +138,6 @@ public class StageUtilsTest extends EasyMockSupport {
     StageUtils.setConfiguration(injector.getInstance(Configuration.class));
   }
 
-
-  public static void addService(Cluster cl, List<String> hostList,
-                                Map<String, List<Integer>> topology, String serviceName,
-                                Injector injector) throws AmbariException {
-    ServiceComponentHostFactory serviceComponentHostFactory = injector.getInstance(ServiceComponentHostFactory.class);
-
-    cl.setDesiredStackVersion(new StackId(STACK_ID));
-    cl.addService(serviceName);
-
-    for (Entry<String, List<Integer>> component : topology.entrySet()) {
-      String componentName = component.getKey();
-      cl.getService(serviceName).addServiceComponent(componentName);
-
-      for (Integer hostIndex : component.getValue()) {
-        cl.getService(serviceName)
-            .getServiceComponent(componentName)
-            .addServiceComponentHost(
-                serviceComponentHostFactory.createNew(cl.getService(serviceName)
-                    .getServiceComponent(componentName), hostList.get(hostIndex)));
-      }
-    }
-  }
-
   @Test
   public void testGetATestStage() {
     StageUtils stageUtils = new StageUtils(injector.getInstance(StageFactory.class));


Mime
View raw message