ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jonathanhur...@apache.org
Subject [07/50] [abbrv] ambari git commit: AMBARI-20957. Remove cluster_version use (ncole)
Date Wed, 31 May 2017 20:12:38 GMT
http://git-wip-us.apache.org/repos/asf/ambari/blob/aaa821cc/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterStackVersionResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterStackVersionResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterStackVersionResourceProviderTest.java
index caf7210..1da5a90 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterStackVersionResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterStackVersionResourceProviderTest.java
@@ -68,14 +68,10 @@ import org.apache.ambari.server.controller.spi.ResourceProvider;
 import org.apache.ambari.server.controller.utilities.PropertyHelper;
 import org.apache.ambari.server.orm.GuiceJpaInitializer;
 import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
-import org.apache.ambari.server.orm.dao.ClusterVersionDAO;
 import org.apache.ambari.server.orm.dao.HostComponentStateDAO;
 import org.apache.ambari.server.orm.dao.HostVersionDAO;
 import org.apache.ambari.server.orm.dao.RepositoryVersionDAO;
-import org.apache.ambari.server.orm.dao.ResourceTypeDAO;
-import org.apache.ambari.server.orm.dao.StackDAO;
 import org.apache.ambari.server.orm.entities.ClusterEntity;
-import org.apache.ambari.server.orm.entities.ClusterVersionEntity;
 import org.apache.ambari.server.orm.entities.HostVersionEntity;
 import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
 import org.apache.ambari.server.orm.entities.StackEntity;
@@ -130,9 +126,6 @@ public class ClusterStackVersionResourceProviderTest {
   private Injector injector;
   private AmbariMetaInfo ambariMetaInfo;
   private RepositoryVersionDAO repositoryVersionDAOMock;
-  private ResourceTypeDAO resourceTypeDAO;
-  private StackDAO stackDAO;
-  private ClusterVersionDAO clusterVersionDAO;
   private ConfigHelper configHelper;
   private Configuration configuration;
   private StageFactory stageFactory;
@@ -172,14 +165,11 @@ public class ClusterStackVersionResourceProviderTest {
             String.valueOf(MAX_TASKS_PER_STAGE));
     configuration = new Configuration(properties);
     stageFactory = createNiceMock(StageFactory.class);
-    clusterVersionDAO = createNiceMock(ClusterVersionDAO.class);
 
     // Initialize injector
     injector = Guice.createInjector(Modules.override(inMemoryModule).with(new MockModule()));
     injector.getInstance(GuiceJpaInitializer.class);
     ambariMetaInfo = injector.getInstance(AmbariMetaInfo.class);
-    resourceTypeDAO = injector.getInstance(ResourceTypeDAO.class);
-    stackDAO = injector.getInstance(StackDAO.class);
   }
 
   @After
@@ -315,7 +305,7 @@ public class ClusterStackVersionResourceProviderTest {
       }
     }).anyTimes();
 
-    expect(cluster.transitionHostsToInstalling(anyObject(ClusterVersionEntity.class),
+    expect(cluster.transitionHostsToInstalling(
         anyObject(RepositoryVersionEntity.class), anyObject(VersionDefinitionXml.class),
         eq(false))).andReturn(hostsNeedingInstallCommands).atLeastOnce();
 
@@ -350,20 +340,14 @@ public class ClusterStackVersionResourceProviderTest {
     ClusterEntity clusterEntity = new ClusterEntity();
     clusterEntity.setClusterId(1l);
     clusterEntity.setClusterName(clusterName);
-    ClusterVersionEntity cve = new ClusterVersionEntity(clusterEntity,
-            repoVersion, RepositoryVersionState.INSTALL_FAILED, 0, "");
-    expect(clusterVersionDAO.findByClusterAndStackAndVersion(anyObject(String.class),
-            anyObject(StackId.class), anyObject(String.class))).andReturn(cve);
 
     StageUtils.setTopologyManager(injector.getInstance(TopologyManager.class));
     StageUtils.setConfiguration(injector.getInstance(Configuration.class));
 
-    expect(clusterVersionDAO.findByCluster(anyObject(String.class))).andReturn(Collections.<ClusterVersionEntity>emptyList()).once();
-
     // replay
     replay(managementController, response, clusters, resourceProviderFactory, csvResourceProvider,
             cluster, repositoryVersionDAOMock, configHelper, schDatanode, schNamenode, schAMS, actionManager,
-            executionCommand, executionCommandWrapper,stage, stageFactory, clusterVersionDAO);
+            executionCommand, executionCommandWrapper,stage, stageFactory);
 
     ResourceProvider provider = AbstractControllerResourceProvider.getResourceProvider(
         type,
@@ -443,23 +427,14 @@ public class ClusterStackVersionResourceProviderTest {
     Service hbaseService = createNiceMock(Service.class);
     expect(hdfsService.getName()).andReturn("HDFS").anyTimes();
     expect(hbaseService.getName()).andReturn("HBASE").anyTimes();
-//    Service metricsService = createNiceMock(Service.class);
-
-    ServiceComponent scNameNode = createNiceMock(ServiceComponent.class);
-    ServiceComponent scDataNode = createNiceMock(ServiceComponent.class);
-    ServiceComponent scHBaseMaster = createNiceMock(ServiceComponent.class);
-    ServiceComponent scMetricCollector = createNiceMock(ServiceComponent.class);
 
     expect(hdfsService.getServiceComponents()).andReturn(new HashMap<String, ServiceComponent>());
     expect(hbaseService.getServiceComponents()).andReturn(new HashMap<String, ServiceComponent>());
-//    expect(metricsService.getServiceComponents()).andReturn(new HashMap<String, ServiceComponent>());
-
 
     Map<String, Service> serviceMap = new HashMap<>();
     serviceMap.put("HDFS", hdfsService);
     serviceMap.put("HBASE", hbaseService);
 
-
     final ServiceComponentHost schDatanode = createMock(ServiceComponentHost.class);
     expect(schDatanode.getServiceName()).andReturn("HDFS").anyTimes();
     expect(schDatanode.getServiceComponentName()).andReturn("DATANODE").anyTimes();
@@ -488,9 +463,6 @@ public class ClusterStackVersionResourceProviderTest {
     ServiceOsSpecific.Package hdfsPackage = new ServiceOsSpecific.Package();
     hdfsPackage.setName("hdfs");
 
-//    ServiceOsSpecific.Package hbasePackage = new ServiceOsSpecific.Package();
-//    hbasePackage.setName("hbase");
-
     List<ServiceOsSpecific.Package> packages = Collections.singletonList(hdfsPackage);
 
     ActionManager actionManager = createNiceMock(ActionManager.class);
@@ -573,10 +545,6 @@ public class ClusterStackVersionResourceProviderTest {
     ClusterEntity clusterEntity = new ClusterEntity();
     clusterEntity.setClusterId(1l);
     clusterEntity.setClusterName(clusterName);
-    ClusterVersionEntity cve = new ClusterVersionEntity(clusterEntity,
-            repoVersion, RepositoryVersionState.INSTALL_FAILED, 0, "");
-    expect(clusterVersionDAO.findByClusterAndStackAndVersion(anyObject(String.class),
-            anyObject(StackId.class), anyObject(String.class))).andReturn(cve);
 
     TopologyManager topologyManager = injector.getInstance(TopologyManager.class);
     StageUtils.setTopologyManager(topologyManager);
@@ -584,7 +552,7 @@ public class ClusterStackVersionResourceProviderTest {
     // replay
     replay(managementController, response, clusters, hdfsService, hbaseService, resourceProviderFactory, csvResourceProvider,
             cluster, repositoryVersionDAOMock, configHelper, schDatanode, schNamenode, schAMS, schHBM, actionManager,
-            executionCommand, executionCommandWrapper,stage, stageFactory, clusterVersionDAO);
+            executionCommand, executionCommandWrapper,stage, stageFactory);
 
     ResourceProvider provider = AbstractControllerResourceProvider.getResourceProvider(
         type,
@@ -767,9 +735,8 @@ public class ClusterStackVersionResourceProviderTest {
       }
     }).anyTimes();
 
-    expect(cluster.transitionHostsToInstalling(anyObject(ClusterVersionEntity.class),
-        anyObject(RepositoryVersionEntity.class), anyObject(VersionDefinitionXml.class),
-        eq(false))).andReturn(hostsNeedingInstallCommands).atLeastOnce();
+    expect(cluster.transitionHostsToInstalling(anyObject(RepositoryVersionEntity.class),
+        anyObject(VersionDefinitionXml.class), eq(false))).andReturn(hostsNeedingInstallCommands).atLeastOnce();
 
 //    ExecutionCommand executionCommand = createNiceMock(ExecutionCommand.class);
     ExecutionCommand executionCommand = new ExecutionCommand();
@@ -797,8 +764,6 @@ public class ClusterStackVersionResourceProviderTest {
                     anyObject(StackId.class),
                     anyObject(String.class))).andReturn(repoVersion);
 
-    expect(clusterVersionDAO.findByCluster(anyObject(String.class))).andReturn(Collections.<ClusterVersionEntity>emptyList()).once();
-
     Capture<org.apache.ambari.server.actionmanager.Request> c = Capture.newInstance();
     Capture<ExecuteActionRequest> ear = Capture.newInstance();
 
@@ -809,11 +774,6 @@ public class ClusterStackVersionResourceProviderTest {
     ClusterEntity clusterEntity = new ClusterEntity();
     clusterEntity.setClusterId(1l);
     clusterEntity.setClusterName(clusterName);
-    ClusterVersionEntity cve = new ClusterVersionEntity(clusterEntity,
-            repoVersion, RepositoryVersionState.INSTALL_FAILED, 0, "");
-    expect(clusterVersionDAO.findByClusterAndStackAndVersion(anyObject(String.class),
-            anyObject(StackId.class), anyObject(String.class))).andReturn(cve);
-
 
     StageUtils.setTopologyManager(injector.getInstance(TopologyManager.class));
     StageUtils.setConfiguration(injector.getInstance(Configuration.class));
@@ -821,7 +781,7 @@ public class ClusterStackVersionResourceProviderTest {
     // replay
     replay(managementController, response, clusters, hdfsService, hbaseService, resourceProviderFactory, csvResourceProvider,
             cluster, repositoryVersionDAOMock, configHelper, schDatanode, schNamenode, schHBM, actionManager,
-            executionCommandWrapper,stage, stageFactory, clusterVersionDAO);
+            executionCommandWrapper,stage, stageFactory);
 
     ResourceProvider provider = AbstractControllerResourceProvider.getResourceProvider(
         type,
@@ -1015,9 +975,8 @@ public class ClusterStackVersionResourceProviderTest {
       }
     }).anyTimes();
 
-    expect(cluster.transitionHostsToInstalling(anyObject(ClusterVersionEntity.class),
-        anyObject(RepositoryVersionEntity.class), anyObject(VersionDefinitionXml.class),
-        eq(false))).andReturn(hostsNeedingInstallCommands).atLeastOnce();
+    expect(cluster.transitionHostsToInstalling(anyObject(RepositoryVersionEntity.class),
+        anyObject(VersionDefinitionXml.class), eq(false))).andReturn(hostsNeedingInstallCommands).atLeastOnce();
 
 //    ExecutionCommand executionCommand = createNiceMock(ExecutionCommand.class);
     ExecutionCommand executionCommand = new ExecutionCommand();
@@ -1053,20 +1012,14 @@ public class ClusterStackVersionResourceProviderTest {
     ClusterEntity clusterEntity = new ClusterEntity();
     clusterEntity.setClusterId(1l);
     clusterEntity.setClusterName(clusterName);
-    ClusterVersionEntity cve = new ClusterVersionEntity(clusterEntity,
-            repoVersion, RepositoryVersionState.INSTALL_FAILED, 0, "");
-    expect(clusterVersionDAO.findByClusterAndStackAndVersion(anyObject(String.class),
-            anyObject(StackId.class), anyObject(String.class))).andReturn(cve);
 
     StageUtils.setTopologyManager(injector.getInstance(TopologyManager.class));
     StageUtils.setConfiguration(injector.getInstance(Configuration.class));
 
-    expect(clusterVersionDAO.findByCluster(anyObject(String.class))).andReturn(Collections.<ClusterVersionEntity>emptyList()).once();
-
     // replay
     replay(managementController, response, clusters, hdfsService, hbaseService, resourceProviderFactory, csvResourceProvider,
             cluster, repositoryVersionDAOMock, configHelper, schDatanode, schNamenode, schHBM, actionManager,
-            executionCommandWrapper,stage, stageFactory, clusterVersionDAO);
+            executionCommandWrapper,stage, stageFactory);
 
     ResourceProvider provider = AbstractControllerResourceProvider.getResourceProvider(
         type,
@@ -1154,15 +1107,32 @@ public class ClusterStackVersionResourceProviderTest {
     int hostCount = 10;
     for (int i = 0; i < hostCount; i++) {
       String hostname = "host" + i;
+
+      List<HostVersionEntity> hostVersions = new ArrayList<>();
+
+      HostVersionEntity hostVersion = createNiceMock(HostVersionEntity.class);
+      expect(hostVersion.getRepositoryVersion()).andReturn(repoVersion);
+
+      hostVersions.add(hostVersion);
+      if (i == 2) {
+        // !!! make it look like there is already a versioned installed that is less than the one being installed
+        RepositoryVersionEntity badRve = new RepositoryVersionEntity();
+        badRve.setStack(stack);
+        badRve.setVersion("2.2.1.0-1000");
+
+        HostVersionEntity badHostVersion = createNiceMock(HostVersionEntity.class);
+        expect(badHostVersion.getRepositoryVersion()).andReturn(badRve);
+        hostVersions.add(badHostVersion);
+        replay(badHostVersion);
+      }
       Host host = createNiceMock(hostname, Host.class);
       expect(host.getHostName()).andReturn(hostname).anyTimes();
       expect(host.getOsFamily()).andReturn("redhat6").anyTimes();
       expect(host.getMaintenanceState(EasyMock.anyLong())).andReturn(
           MaintenanceState.OFF).anyTimes();
-      expect(host.getAllHostVersions()).andReturn(
-          Collections.<HostVersionEntity>emptyList()).anyTimes();
+      expect(host.getAllHostVersions()).andReturn(hostVersions).anyTimes();
 
-      replay(host);
+      replay(host, hostVersion);
       hostsForCluster.put(hostname, host);
     }
 
@@ -1236,6 +1206,12 @@ public class ClusterStackVersionResourceProviderTest {
       }
     }).anyTimes();
 
+    // now the important expectations - that the cluster transition methods were
+    // called correctly
+    expect(cluster.transitionHostsToInstalling(anyObject(RepositoryVersionEntity.class),
+        anyObject(VersionDefinitionXml.class), eq(false))).andReturn(Collections.<Host>emptyList()).anyTimes();
+
+
     ExecutionCommand executionCommand = createNiceMock(ExecutionCommand.class);
     ExecutionCommandWrapper executionCommandWrapper = createNiceMock(ExecutionCommandWrapper.class);
 
@@ -1265,29 +1241,17 @@ public class ClusterStackVersionResourceProviderTest {
     ClusterEntity clusterEntity = new ClusterEntity();
     clusterEntity.setClusterId(1l);
     clusterEntity.setClusterName(clusterName);
-    ClusterVersionEntity cve = new ClusterVersionEntity(clusterEntity,
-            repoVersion, RepositoryVersionState.INSTALL_FAILED, 0, "");
-    expect(clusterVersionDAO.findByClusterAndStackAndVersion(anyObject(String.class),
-            anyObject(StackId.class), anyObject(String.class))).andReturn(cve);
 
     TopologyManager topologyManager = injector.getInstance(TopologyManager.class);
     StageUtils.setTopologyManager(topologyManager);
     StageUtils.setConfiguration(injector.getInstance(Configuration.class));
 
 
-    // !!! make it look like there is already a versioned installed that is less than the one being installed
-    ClusterVersionEntity bad = new ClusterVersionEntity();
-    RepositoryVersionEntity badRve = new RepositoryVersionEntity();
-    badRve.setStack(stack);
-    badRve.setVersion("2.2.1.0-1000");
-    bad.setRepositoryVersion(badRve);
-
-    expect(clusterVersionDAO.findByCluster(anyObject(String.class))).andReturn(Collections.singletonList(bad)).once();
 
     // replay
     replay(managementController, response, clusters, resourceProviderFactory, csvResourceProvider,
             cluster, repositoryVersionDAOMock, configHelper, schDatanode, schNamenode, schAMS, actionManager,
-            executionCommand, executionCommandWrapper,stage, stageFactory, clusterVersionDAO);
+            executionCommand, executionCommandWrapper,stage, stageFactory);
 
     ResourceProvider provider = AbstractControllerResourceProvider.getResourceProvider(
         type,
@@ -1357,6 +1321,10 @@ public class ClusterStackVersionResourceProviderTest {
 
     File f = new File("src/test/resources/hbase_version_test.xml");
 
+    StackEntity stackEntity = new StackEntity();
+    stackEntity.setStackName(stackId.getStackName());
+    stackEntity.setStackVersion(stackId.getStackVersion());
+
     RepositoryVersionEntity repoVersionEntity = new RepositoryVersionEntity();
     repoVersionEntity.setId(1l);
     repoVersionEntity.setOperatingSystems(OS_JSON);
@@ -1364,6 +1332,7 @@ public class ClusterStackVersionResourceProviderTest {
     repoVersionEntity.setVersionXsd("version_definition.xsd");
     repoVersionEntity.setType(RepositoryType.STANDARD);
     repoVersionEntity.setVersion(repoVersion);
+    repoVersionEntity.setStack(stackEntity);
 
     List<Host> hostsNeedingInstallCommands = new ArrayList<>();
     Map<String, Host> hostsForCluster = new HashMap<>();
@@ -1382,6 +1351,7 @@ public class ClusterStackVersionResourceProviderTest {
       if (i < hostCount - 2) {
         expect(host.hasComponentsAdvertisingVersions(eq(stackId))).andReturn(true).atLeastOnce();
         hostsNeedingInstallCommands.add(host);
+        expect(host.getAllHostVersions()).andReturn(Collections.<HostVersionEntity>emptyList()).anyTimes();
       } else {
         expect(host.hasComponentsAdvertisingVersions(eq(stackId))).andReturn(false).atLeastOnce();
 
@@ -1392,8 +1362,7 @@ public class ClusterStackVersionResourceProviderTest {
         replay(hostVersionEntity);
 
         hostVersionEntitiesMergedWithNotRequired.add(hostVersionEntity);
-        expect(host.getAllHostVersions()).andReturn(
-            hostVersionEntitiesMergedWithNotRequired).anyTimes();
+        expect(host.getAllHostVersions()).andReturn(hostVersionEntitiesMergedWithNotRequired).anyTimes();
       }
 
       replay(host);
@@ -1443,7 +1412,6 @@ public class ClusterStackVersionResourceProviderTest {
 
     String clusterName = "Cluster100";
     expect(cluster.getClusterId()).andReturn(1L).anyTimes();
-    expect(cluster.getClusterName()).andReturn(clusterName).atLeastOnce();
     expect(cluster.getHosts()).andReturn(hostsForCluster.values()).atLeastOnce();
     expect(cluster.getServices()).andReturn(serviceMap).anyTimes();
     expect(cluster.getServiceComponentHosts(anyObject(String.class))).andReturn(
@@ -1452,34 +1420,21 @@ public class ClusterStackVersionResourceProviderTest {
     expect(repositoryVersionDAOMock.findByStackAndVersion(anyObject(StackId.class),
         anyObject(String.class))).andReturn(repoVersionEntity);
 
-    expect(clusterVersionDAO.findByCluster(anyObject(String.class))).andReturn(
-        Collections.<ClusterVersionEntity> emptyList()).once();
-
     ClusterEntity clusterEntity = new ClusterEntity();
     clusterEntity.setClusterId(1l);
     clusterEntity.setClusterName(clusterName);
 
-    ClusterVersionEntity cve = new ClusterVersionEntity(clusterEntity, repoVersionEntity,
-        RepositoryVersionState.INSTALL_FAILED, 0, "");
-
-    // first expect back a null to make the code think it needs to create one,
-    // then return the real one it's going to use
-    expect(clusterVersionDAO.findByClusterAndStackAndVersion(anyObject(String.class),
-        anyObject(StackId.class), anyObject(String.class))).andReturn(null).once();
-
-    expect(cluster.createClusterVersion(anyObject(StackId.class), eq(repoVersion),
-        EasyMock.anyString(), eq(RepositoryVersionState.INSTALLED))).andReturn(cve).once();
 
     // now the important expectations - that the cluster transition methods were
     // called correctly
-    expect(cluster.transitionHostsToInstalling(cve, repoVersionEntity,
+    expect(cluster.transitionHostsToInstalling(repoVersionEntity,
         repoVersionEntity.getRepositoryXml(), true)).andReturn(
             hostsNeedingInstallCommands).once();
 
     // replay
     replay(managementController, response, clusters, hdfsService, resourceProviderFactory,
         csvResourceProvider, cluster, repositoryVersionDAOMock, configHelper, schDatanode,
-        stageFactory, clusterVersionDAO, hostVersionDAO);
+        stageFactory, hostVersionDAO);
 
     ResourceProvider provider = AbstractControllerResourceProvider.getResourceProvider(type,
         PropertyHelper.getPropertyIds(type), PropertyHelper.getKeyPropertyIds(type),
@@ -1593,7 +1548,6 @@ public class ClusterStackVersionResourceProviderTest {
       bind(ConfigHelper.class).toInstance(configHelper);
       bind(Configuration.class).toInstance(configuration);
       bind(StageFactory.class).toInstance(stageFactory);
-      bind(ClusterVersionDAO.class).toInstance(clusterVersionDAO);
       bind(HostVersionDAO.class).toInstance(hostVersionDAO);
       bind(HostComponentStateDAO.class).toInstance(hostComponentStateDAO);
     }

http://git-wip-us.apache.org/repos/asf/ambari/blob/aaa821cc/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/CompatibleRepositoryVersionResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/CompatibleRepositoryVersionResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/CompatibleRepositoryVersionResourceProviderTest.java
index 528bd40..6a751a9 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/CompatibleRepositoryVersionResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/CompatibleRepositoryVersionResourceProviderTest.java
@@ -49,7 +49,6 @@ import org.apache.ambari.server.controller.utilities.PredicateBuilder;
 import org.apache.ambari.server.controller.utilities.PropertyHelper;
 import org.apache.ambari.server.orm.GuiceJpaInitializer;
 import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
-import org.apache.ambari.server.orm.dao.ClusterVersionDAO;
 import org.apache.ambari.server.orm.dao.RepositoryVersionDAO;
 import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
 import org.apache.ambari.server.orm.entities.StackEntity;
@@ -84,7 +83,6 @@ public class CompatibleRepositoryVersionResourceProviderTest {
   @Before
   public void before() throws Exception {
     final AmbariMetaInfo ambariMetaInfo = EasyMock.createMock(AmbariMetaInfo.class);
-    final ClusterVersionDAO clusterVersionDAO = EasyMock.createMock(ClusterVersionDAO.class);
 
     StackEntity hdp11Stack = new StackEntity();
     hdp11Stack.setStackName("HDP");
@@ -221,7 +219,6 @@ public class CompatibleRepositoryVersionResourceProviderTest {
       protected void configure() {
         super.configure();
         bind(AmbariMetaInfo.class).toInstance(ambariMetaInfo);
-        bind(ClusterVersionDAO.class).toInstance(clusterVersionDAO);
         bind(RepositoryVersionDAO.class).toInstance(repoVersionDAO);
         requestStaticInjection(CompatibleRepositoryVersionResourceProvider.class);
       }

http://git-wip-us.apache.org/repos/asf/ambari/blob/aaa821cc/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HostResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HostResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HostResourceProviderTest.java
index d1a4a1a..b075b71 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HostResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HostResourceProviderTest.java
@@ -131,8 +131,6 @@ public class HostResourceProviderTest extends EasyMockSupport {
 
     expect(cluster.getClusterId()).andReturn(2L).anyTimes();
     expect(cluster.getDesiredConfigs()).andReturn(new HashMap<String, DesiredConfig>()).anyTimes();
-    cluster.recalculateAllClusterVersionStates();
-    EasyMock.expectLastCall().once();
 
     expect(clusters.getCluster("Cluster100")).andReturn(cluster).atLeastOnce();
     expect(clusters.getHost("Host100")).andReturn(null).atLeastOnce();
@@ -908,8 +906,6 @@ public class HostResourceProviderTest extends EasyMockSupport {
     expect(clusters.getHost("Host100")).andReturn(host100).anyTimes();
     clusters.mapAndPublishHostsToCluster(Collections.singleton("Host100"), "Cluster100");
     expectLastCall().anyTimes();
-    cluster.recalculateAllClusterVersionStates();
-    expectLastCall().anyTimes();
     expect(cluster.getClusterId()).andReturn(2L).anyTimes();
     expect(cluster.getResourceId()).andReturn(4L).anyTimes();
     expect(cluster.getDesiredConfigs()).andReturn(new HashMap<String, DesiredConfig>()).anyTimes();
@@ -1001,8 +997,6 @@ public class HostResourceProviderTest extends EasyMockSupport {
     expect(clusters.getHostsForCluster("Cluster100")).andReturn(Collections.singletonMap("Host100", host100)).anyTimes();
     clusters.mapAndPublishHostsToCluster(Collections.singleton("Host100"), "Cluster100");
     expectLastCall().anyTimes();
-    cluster.recalculateAllClusterVersionStates();
-    expectLastCall().anyTimes();
     expect(cluster.getClusterId()).andReturn(2L).anyTimes();
     expect(cluster.getResourceId()).andReturn(4L).anyTimes();
     expect(cluster.getDesiredConfigs()).andReturn(new HashMap<String, DesiredConfig>()).anyTimes();
@@ -1081,7 +1075,6 @@ public class HostResourceProviderTest extends EasyMockSupport {
     expect(cluster.getDesiredConfigs()).andReturn(new HashMap<String, DesiredConfig>()).anyTimes();
     clusters.deleteHost("Host100");
     clusters.publishHostsDeletion(Collections.EMPTY_SET, Collections.singleton("Host100"));
-    cluster.recalculateAllClusterVersionStates();
     expect(host1.getHostName()).andReturn("Host100").anyTimes();
     expect(healthStatus.getHealthStatus()).andReturn(HostHealthStatus.HealthStatus.HEALTHY).anyTimes();
     expect(healthStatus.getHealthReport()).andReturn("HEALTHY").anyTimes();

http://git-wip-us.apache.org/repos/asf/ambari/blob/aaa821cc/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/RepositoryVersionResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/RepositoryVersionResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/RepositoryVersionResourceProviderTest.java
index 21f9383..2d64287 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/RepositoryVersionResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/RepositoryVersionResourceProviderTest.java
@@ -19,7 +19,6 @@
 package org.apache.ambari.server.controller.internal;
 
 import java.sql.SQLException;
-import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.LinkedHashMap;
@@ -40,11 +39,8 @@ import org.apache.ambari.server.controller.utilities.PredicateBuilder;
 import org.apache.ambari.server.controller.utilities.PropertyHelper;
 import org.apache.ambari.server.orm.GuiceJpaInitializer;
 import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
-import org.apache.ambari.server.orm.dao.ClusterVersionDAO;
 import org.apache.ambari.server.orm.dao.RepositoryVersionDAO;
 import org.apache.ambari.server.orm.dao.StackDAO;
-import org.apache.ambari.server.orm.entities.ClusterEntity;
-import org.apache.ambari.server.orm.entities.ClusterVersionEntity;
 import org.apache.ambari.server.orm.entities.OperatingSystemEntity;
 import org.apache.ambari.server.orm.entities.RepositoryEntity;
 import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
@@ -54,13 +50,13 @@ import org.apache.ambari.server.security.authorization.AuthorizationException;
 import org.apache.ambari.server.state.Clusters;
 import org.apache.ambari.server.state.OperatingSystemInfo;
 import org.apache.ambari.server.state.RepositoryInfo;
-import org.apache.ambari.server.state.RepositoryVersionState;
 import org.apache.ambari.server.state.ServiceInfo;
 import org.apache.ambari.server.state.StackId;
 import org.apache.ambari.server.state.StackInfo;
 import org.apache.ambari.server.state.stack.UpgradePack;
 import org.apache.ambari.server.state.stack.upgrade.RepositoryVersionHelper;
 import org.junit.After;
+import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 import org.mockito.Mockito;
@@ -73,57 +69,28 @@ import com.google.common.collect.Sets;
 import com.google.gson.Gson;
 import com.google.inject.Guice;
 import com.google.inject.Injector;
-
-import junit.framework.Assert;
-
 /**
  * RepositoryVersionResourceProvider tests.
  */
 public class RepositoryVersionResourceProviderTest {
 
-  private ClusterVersionDAO clusterVersionDAO;
-
   private static Injector injector;
 
   private static String jsonStringRedhat6 = "[{\"OperatingSystems\":{\"os_type\":\"redhat6\"},\"repositories\":[]}]";
   private static String jsonStringRedhat7 = "[{\"OperatingSystems\":{\"os_type\":\"redhat7\"},\"repositories\":[]}]";
 
-  private List<ClusterVersionEntity> getNoClusterVersions() {
-    final List<ClusterVersionEntity> emptyList = new ArrayList<>();
-    return emptyList;
-  }
-
-  private List<ClusterVersionEntity> getInstallFailedClusterVersions() {
-    ClusterEntity cluster = new ClusterEntity();
-    cluster.setClusterName("c1");
-    cluster.setClusterId(1L);
-
-    final List<ClusterVersionEntity> clusterVersions = new ArrayList<>();
-    final RepositoryVersionEntity repositoryVersion = new RepositoryVersionEntity();
-    repositoryVersion.setId(1L);
-    final ClusterVersionEntity installFailedVersion = new ClusterVersionEntity();
-    installFailedVersion.setState(RepositoryVersionState.INSTALL_FAILED);
-    installFailedVersion.setRepositoryVersion(repositoryVersion);
-    installFailedVersion.setClusterEntity(cluster);
-    clusterVersions.add(installFailedVersion);
-    cluster.setClusterVersionEntities(clusterVersions);
-    return clusterVersions;
-  }
-
   @Before
   public void before() throws Exception {
     final Set<String> validVersions = Sets.newHashSet("1.1", "1.1-17", "1.1.1.1", "1.1.343432.2", "1.1.343432.2-234234324");
     final Set<StackInfo> stacks = new HashSet<>();
 
     final AmbariMetaInfo ambariMetaInfo = Mockito.mock(AmbariMetaInfo.class);
-    clusterVersionDAO = Mockito.mock(ClusterVersionDAO.class);
 
     final InMemoryDefaultTestModule injectorModule = new InMemoryDefaultTestModule() {
       @Override
       protected void configure() {
         super.configure();
         bind(AmbariMetaInfo.class).toInstance(ambariMetaInfo);
-        bind(ClusterVersionDAO.class).toInstance(clusterVersionDAO);
       };
     };
     injector = Guice.createInjector(injectorModule);
@@ -212,21 +179,6 @@ public class RepositoryVersionResourceProviderTest {
       }
     });
 
-    Mockito.when(clusterVersionDAO.findByStackAndVersion(Mockito.anyString(), Mockito.anyString(), Mockito.anyString())).thenAnswer(
-        new Answer<List<ClusterVersionEntity>>() {
-      @Override
-      public List<ClusterVersionEntity> answer(InvocationOnMock invocation) throws Throwable {
-        final String stack = invocation.getArguments()[0].toString();
-        final String version = invocation.getArguments()[1].toString();
-
-        if (stack.equals("HDP-1.1") && version.equals("1.1.1.1")) {
-          return getNoClusterVersions();
-        } else {
-          return getInstallFailedClusterVersions();
-        }
-      }
-    });
-
     H2DatabaseCleaner.resetSequences(injector);
     injector.getInstance(GuiceJpaInitializer.class);
 
@@ -461,14 +413,6 @@ public class RepositoryVersionResourceProviderTest {
 
     final ResourceProvider provider = injector.getInstance(ResourceProviderFactory.class).getRepositoryVersionResourceProvider();
 
-    Mockito.when(clusterVersionDAO.findByStackAndVersion(Mockito.anyString(), Mockito.anyString(), Mockito.anyString())).thenAnswer(
-        new Answer<List<ClusterVersionEntity>>() {
-          @Override
-          public List<ClusterVersionEntity> answer(InvocationOnMock invocation) throws Throwable {
-            return getNoClusterVersions();
-          }
-        });
-
     final Set<Map<String, Object>> propertySet = new LinkedHashSet<>();
     final Map<String, Object> properties = new LinkedHashMap<>();
     properties.put(RepositoryVersionResourceProvider.REPOSITORY_VERSION_DISPLAY_NAME_PROPERTY_ID, "name");
@@ -521,14 +465,6 @@ public class RepositoryVersionResourceProviderTest {
 
     properties.put(RepositoryVersionResourceProvider.SUBRESOURCE_OPERATING_SYSTEMS_PROPERTY_ID, new Gson().fromJson("[{\"OperatingSystems/os_type\":\"redhat6\",\"repositories\":[{\"Repositories/repo_id\":\"2\",\"Repositories/repo_name\":\"2\",\"Repositories/base_url\":\"2\",\"Repositories/unique\":\"true\"}]}]", Object.class));
     provider.updateResources(updateRequest, new AndPredicate(predicateStackName, predicateStackVersion));
-    // Now, insert a cluster version whose state is INSTALL_FAILED, so the operation will not be permitted.
-    Mockito.when(clusterVersionDAO.findByStackAndVersion(Mockito.anyString(), Mockito.anyString(), Mockito.anyString())).thenAnswer(
-      new Answer<List<ClusterVersionEntity>>() {
-        @Override
-        public List<ClusterVersionEntity> answer(InvocationOnMock invocation) throws Throwable {
-          return getInstallFailedClusterVersions();
-        }
-      });
 
     try {
       provider.updateResources(updateRequest, new AndPredicate(predicateStackName, predicateStackVersion));
@@ -545,14 +481,6 @@ public class RepositoryVersionResourceProviderTest {
 
     final ResourceProvider provider = injector.getInstance(ResourceProviderFactory.class).getRepositoryVersionResourceProvider();
 
-    Mockito.when(clusterVersionDAO.findByStackAndVersion(Mockito.anyString(), Mockito.anyString(), Mockito.anyString())).thenAnswer(
-        new Answer<List<ClusterVersionEntity>>() {
-          @Override
-          public List<ClusterVersionEntity> answer(InvocationOnMock invocation) throws Throwable {
-            return getNoClusterVersions();
-          }
-        });
-
     final Set<Map<String, Object>> propertySet = new LinkedHashSet<>();
     final Map<String, Object> properties = new LinkedHashMap<>();
     properties.put(RepositoryVersionResourceProvider.REPOSITORY_VERSION_DISPLAY_NAME_PROPERTY_ID, "name");

http://git-wip-us.apache.org/repos/asf/ambari/blob/aaa821cc/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ServiceResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ServiceResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ServiceResourceProviderTest.java
index 91b00ab..c82c884 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ServiceResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ServiceResourceProviderTest.java
@@ -63,7 +63,6 @@ import org.apache.ambari.server.controller.utilities.PredicateBuilder;
 import org.apache.ambari.server.controller.utilities.PropertyHelper;
 import org.apache.ambari.server.metadata.RoleCommandOrder;
 import org.apache.ambari.server.orm.dao.RepositoryVersionDAO;
-import org.apache.ambari.server.orm.entities.ClusterVersionEntity;
 import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
 import org.apache.ambari.server.security.TestAuthenticationFactory;
 import org.apache.ambari.server.security.authorization.AuthorizationException;
@@ -115,20 +114,14 @@ public class ServiceResourceProviderTest {
     Clusters clusters = createNiceMock(Clusters.class);
     Cluster cluster = createNiceMock(Cluster.class);
     Service service = createNiceMock(Service.class);
-    StackId stackId = createNiceMock(StackId.class);
+    StackId stackId = new StackId("HDP-2.5");
     ServiceFactory serviceFactory = createNiceMock(ServiceFactory.class);
     AmbariMetaInfo ambariMetaInfo = createNiceMock(AmbariMetaInfo.class);
     ServiceInfo serviceInfo = createNiceMock(ServiceInfo.class);
 
-    ClusterVersionEntity clusterVersion = createNiceMock(ClusterVersionEntity.class);
-    RepositoryVersionEntity repositoryVersion = createNiceMock(RepositoryVersionEntity.class);
-    expect(clusterVersion.getRepositoryVersion()).andReturn(repositoryVersion).atLeastOnce();
-
     expect(managementController.getClusters()).andReturn(clusters).anyTimes();
     expect(managementController.getAmbariMetaInfo()).andReturn(ambariMetaInfo).anyTimes();
 
-    expect(cluster.getCurrentClusterVersion()).andReturn(clusterVersion).atLeastOnce();
-
     expect(cluster.addService(eq("Service100"),
         EasyMock.anyObject(RepositoryVersionEntity.class))).andReturn(service);
 
@@ -138,19 +131,16 @@ public class ServiceResourceProviderTest {
     expect(cluster.getDesiredStackVersion()).andReturn(stackId).anyTimes();
     expect(cluster.getClusterId()).andReturn(2L).anyTimes();
 
-    expect(stackId.getStackName()).andReturn("HDP").anyTimes();
-    expect(stackId.getStackVersion()).andReturn("2.5").anyTimes();
-
     expect(ambariMetaInfo.isValidService( (String) anyObject(), (String) anyObject(), (String) anyObject())).andReturn(true);
     expect(ambariMetaInfo.getService((String)anyObject(), (String)anyObject(), (String)anyObject())).andReturn(serviceInfo).anyTimes();
 
     // replay
-    replay(managementController, clusters, cluster, clusterVersion, repositoryVersion, service,
-        ambariMetaInfo, stackId, serviceFactory, serviceInfo);
+    replay(managementController, clusters, cluster, service,
+        ambariMetaInfo, serviceFactory, serviceInfo);
 
     SecurityContextHolder.getContext().setAuthentication(authentication);
 
-    ResourceProvider provider = getServiceProvider(managementController);
+    ResourceProvider provider = getServiceProvider(managementController, true);
 
     // add the property map to a set for the request.  add more maps for multiple creates
     Set<Map<String, Object>> propertySet = new LinkedHashSet<>();
@@ -171,8 +161,8 @@ public class ServiceResourceProviderTest {
     provider.createResources(request);
 
     // verify
-    verify(managementController, clusters, cluster, clusterVersion, repositoryVersion, service,
-        ambariMetaInfo, stackId, serviceFactory, serviceInfo);
+    verify(managementController, clusters, cluster, service,
+        ambariMetaInfo, serviceFactory, serviceInfo);
   }
 
   @Test
@@ -1157,20 +1147,31 @@ public class ServiceResourceProviderTest {
     }
   }
 
-  /**
-   * This factory method creates default MaintenanceStateHelper mock.
-   * It's useful in most cases (when we don't care about Maintenance State)
-   */
-  public static ServiceResourceProvider getServiceProvider(AmbariManagementController managementController) throws  AmbariException {
+  private static ServiceResourceProvider getServiceProvider(AmbariManagementController managementController, boolean mockFindByStack) throws  AmbariException {
     MaintenanceStateHelper maintenanceStateHelperMock = createNiceMock(MaintenanceStateHelper.class);
     RepositoryVersionDAO repositoryVersionDAO = createNiceMock(RepositoryVersionDAO.class);
     expect(maintenanceStateHelperMock.isOperationAllowed(anyObject(Resource.Type.class), anyObject(Service.class))).andReturn(true).anyTimes();
     expect(maintenanceStateHelperMock.isOperationAllowed(anyObject(Resource.Type.class), anyObject(ServiceComponentHost.class))).andReturn(true).anyTimes();
+
+    if (mockFindByStack) {
+      RepositoryVersionEntity repositoryVersion = createNiceMock(RepositoryVersionEntity.class);
+      expect(repositoryVersionDAO.findByStack(EasyMock.anyObject(StackId.class))).andReturn(
+          Collections.singletonList(repositoryVersion)).atLeastOnce();
+    }
+
     replay(maintenanceStateHelperMock, repositoryVersionDAO);
     return getServiceProvider(managementController, maintenanceStateHelperMock, repositoryVersionDAO);
   }
 
   /**
+   * This factory method creates default MaintenanceStateHelper mock.
+   * It's useful in most cases (when we don't care about Maintenance State)
+   */
+  public static ServiceResourceProvider getServiceProvider(AmbariManagementController managementController) throws  AmbariException {
+    return getServiceProvider(managementController, false);
+  }
+
+  /**
    * This factory method allows to define custom MaintenanceStateHelper mock.
    */
   public static ServiceResourceProvider getServiceProvider(

http://git-wip-us.apache.org/repos/asf/ambari/blob/aaa821cc/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/StackDefinedPropertyProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/StackDefinedPropertyProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/StackDefinedPropertyProviderTest.java
index 74cf0bf..4d44576 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/StackDefinedPropertyProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/StackDefinedPropertyProviderTest.java
@@ -62,7 +62,6 @@ import org.apache.ambari.server.security.authorization.AuthorizationException;
 import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Clusters;
 import org.apache.ambari.server.state.Host;
-import org.apache.ambari.server.state.RepositoryVersionState;
 import org.apache.ambari.server.state.StackId;
 import org.apache.ambari.server.state.services.MetricsRetrievalService;
 import org.apache.ambari.server.state.stack.Metric;
@@ -138,8 +137,6 @@ public class StackDefinedPropertyProviderTest {
 
     cluster.setDesiredStackVersion(stackId);
     helper.getOrCreateRepositoryVersion(stackId, stackId.getStackVersion());
-    cluster.createClusterVersion(stackId, stackId.getStackVersion(), "admin",
-      RepositoryVersionState.INSTALLING);
 
     clusters.addHost("h1");
     Host host = clusters.getHost("h1");

http://git-wip-us.apache.org/repos/asf/ambari/blob/aaa821cc/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderHDP22Test.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderHDP22Test.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderHDP22Test.java
deleted file mode 100644
index 30e5c4c..0000000
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderHDP22Test.java
+++ /dev/null
@@ -1,318 +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.controller.internal;
-
-import static org.easymock.EasyMock.createNiceMock;
-import static org.easymock.EasyMock.replay;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-import java.lang.reflect.Field;
-import java.sql.SQLException;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.ambari.server.AmbariException;
-import org.apache.ambari.server.H2DatabaseCleaner;
-import org.apache.ambari.server.actionmanager.ActionManager;
-import org.apache.ambari.server.actionmanager.ExecutionCommandWrapper;
-import org.apache.ambari.server.actionmanager.ExecutionCommandWrapperFactory;
-import org.apache.ambari.server.agent.ExecutionCommand;
-import org.apache.ambari.server.agent.ExecutionCommand.KeyNames;
-import org.apache.ambari.server.configuration.Configuration;
-import org.apache.ambari.server.controller.AmbariManagementController;
-import org.apache.ambari.server.controller.AmbariServer;
-import org.apache.ambari.server.controller.spi.Request;
-import org.apache.ambari.server.controller.spi.ResourceProvider;
-import org.apache.ambari.server.controller.utilities.PropertyHelper;
-import org.apache.ambari.server.events.publishers.AmbariEventPublisher;
-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.ExecutionCommandDAO;
-import org.apache.ambari.server.orm.dao.RepositoryVersionDAO;
-import org.apache.ambari.server.orm.dao.StackDAO;
-import org.apache.ambari.server.orm.dao.UpgradeDAO;
-import org.apache.ambari.server.orm.entities.ExecutionCommandEntity;
-import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
-import org.apache.ambari.server.orm.entities.StackEntity;
-import org.apache.ambari.server.orm.entities.UpgradeEntity;
-import org.apache.ambari.server.orm.entities.UpgradeGroupEntity;
-import org.apache.ambari.server.orm.entities.UpgradeItemEntity;
-import org.apache.ambari.server.security.TestAuthenticationFactory;
-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.ConfigFactory;
-import org.apache.ambari.server.state.Host;
-import org.apache.ambari.server.state.HostState;
-import org.apache.ambari.server.state.RepositoryVersionState;
-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.StackId;
-import org.apache.ambari.server.state.stack.upgrade.Direction;
-import org.apache.ambari.server.topology.TopologyManager;
-import org.apache.ambari.server.utils.StageUtils;
-import org.apache.ambari.server.view.ViewRegistry;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.springframework.security.core.context.SecurityContextHolder;
-
-import com.google.common.collect.ImmutableMap;
-import com.google.gson.Gson;
-import com.google.inject.Guice;
-import com.google.inject.Injector;
-
-/**
- * UpgradeResourceDefinition tests.
- */
-public class UpgradeResourceProviderHDP22Test {
-
-  private UpgradeDAO upgradeDao = null;
-  private RepositoryVersionDAO repoVersionDao = null;
-  private Injector injector;
-  private Clusters clusters;
-  private OrmTestHelper helper;
-  private AmbariManagementController amc;
-  private StackDAO stackDAO;
-  private TopologyManager topologyManager;
-  private ConfigFactory configFactory;
-
-  private static final String configTagVersion1 = "version1";
-  private static final String configTagVersion2 = "version2";
-
-  private static final Map<String, String> configTagVersion1Properties = new ImmutableMap.Builder<String, String>().put(
-      "hive.server2.thrift.port", "10000").build();
-
-  private static final Map<String, String> configTagVersion2Properties = new ImmutableMap.Builder<String, String>().put(
-      "hive.server2.thrift.port", "10010").build();
-
-  @Before
-  public void before() throws Exception {
-    SecurityContextHolder.getContext().setAuthentication(
-        TestAuthenticationFactory.createAdministrator());
-
-    // create an injector which will inject the mocks
-    injector = Guice.createInjector(new InMemoryDefaultTestModule());
-
-    injector.getInstance(GuiceJpaInitializer.class);
-
-    helper = injector.getInstance(OrmTestHelper.class);
-
-    amc = injector.getInstance(AmbariManagementController.class);
-
-    Field field = AmbariServer.class.getDeclaredField("clusterController");
-    field.setAccessible(true);
-    field.set(null, amc);
-
-    stackDAO = injector.getInstance(StackDAO.class);
-    upgradeDao = injector.getInstance(UpgradeDAO.class);
-    repoVersionDao = injector.getInstance(RepositoryVersionDAO.class);
-    configFactory = injector.getInstance(ConfigFactory.class);
-
-    AmbariEventPublisher publisher = createNiceMock(AmbariEventPublisher.class);
-    replay(publisher);
-    ViewRegistry.initInstance(new ViewRegistry(publisher));
-
-    StackEntity stackEntity = stackDAO.find("HDP", "2.2.0");
-
-    RepositoryVersionEntity repoVersionEntity = new RepositoryVersionEntity();
-    repoVersionEntity.setDisplayName("For Stack Version 2.2.0");
-    repoVersionEntity.setOperatingSystems("");
-    repoVersionEntity.setStack(stackEntity);
-    repoVersionEntity.setVersion("2.2.0.0");
-    repoVersionDao.create(repoVersionEntity);
-
-    repoVersionEntity = new RepositoryVersionEntity();
-    repoVersionEntity.setDisplayName("For Stack Version 2.2.4.2");
-    repoVersionEntity.setOperatingSystems("");
-    repoVersionEntity.setStack(stackEntity);
-    repoVersionEntity.setVersion("2.2.4.2");
-    repoVersionDao.create(repoVersionEntity);
-
-    clusters = injector.getInstance(Clusters.class);
-
-    StackId stackId = new StackId("HDP-2.2.0");
-    clusters.addCluster("c1", stackId);
-    Cluster cluster = clusters.getCluster("c1");
-
-    RepositoryVersionEntity repositoryVersion = helper.getOrCreateRepositoryVersion(stackId,
-        stackId.getStackVersion());
-
-    cluster.createClusterVersion(stackId, stackId.getStackVersion(), "admin", RepositoryVersionState.INSTALLING);
-    cluster.transitionClusterVersion(stackId, stackId.getStackVersion(), RepositoryVersionState.CURRENT);
-
-    clusters.addHost("h1");
-    Host host = clusters.getHost("h1");
-    Map<String, String> hostAttributes = new HashMap<>();
-    hostAttributes.put("os_family", "redhat");
-    hostAttributes.put("os_release_version", "6.3");
-    host.setHostAttributes(hostAttributes);
-    host.setState(HostState.HEALTHY);
-
-    clusters.mapHostToCluster("h1", "c1");
-
-    // add a single HIVE server
-    Service service = cluster.addService("HIVE", repositoryVersion);
-
-    ServiceComponent component = service.addServiceComponent("HIVE_SERVER");
-    ServiceComponentHost sch = component.addServiceComponentHost("h1");
-    sch.setVersion("2.2.0.0");
-
-    component = service.addServiceComponent("HIVE_CLIENT");
-    sch = component.addServiceComponentHost("h1");
-    sch.setVersion("2.2.0.0");
-    topologyManager = injector.getInstance(TopologyManager.class);
-    StageUtils.setTopologyManager(topologyManager);
-    StageUtils.setConfiguration(injector.getInstance(Configuration.class));
-    ActionManager.setTopologyManager(topologyManager);
-  }
-
-  @After
-  public void after() throws AmbariException, SQLException {
-    H2DatabaseCleaner.clearDatabaseAndStopPersistenceService(injector);
-    injector = null;
-  }
-
-  /**
-   * Tests upgrades from HDP-2.2.x to HDP-2.2.y
-   *
-   * @throws Exception
-   */
-  @SuppressWarnings("serial")
-  @Test
-  public void testCreateIntraStackUpgrade() throws Exception {
-    // We want to use the HDP-2.2 'upgrade_test' catalog
-    // Create HDP-2.2 stack
-
-    Cluster cluster = clusters.getCluster("c1");
-    StackId oldStack = cluster.getDesiredStackVersion();
-
-    for (Service s : cluster.getServices().values()) {
-      assertEquals(oldStack, s.getDesiredStackId());
-
-      for (ServiceComponent sc : s.getServiceComponents().values()) {
-        assertEquals(oldStack, sc.getDesiredStackId());
-
-        for (ServiceComponentHost sch : sc.getServiceComponentHosts().values()) {
-          assertEquals("2.2.0.0", sch.getVersion());
-        }
-      }
-    }
-
-    Config config = configFactory.createNew(cluster, "hive-site", configTagVersion1, configTagVersion1Properties, null);
-    cluster.addDesiredConfig("admin", Collections.singleton(config));
-
-    Map<String, Object> requestProps = new HashMap<>();
-    requestProps.put(UpgradeResourceProvider.UPGRADE_CLUSTER_NAME, "c1");
-    requestProps.put(UpgradeResourceProvider.UPGRADE_VERSION, "2.2.4.2");
-    requestProps.put(UpgradeResourceProvider.UPGRADE_SKIP_PREREQUISITE_CHECKS, "true");
-    requestProps.put(UpgradeResourceProvider.UPGRADE_DIRECTION, Direction.UPGRADE.name());
-
-    ResourceProvider upgradeResourceProvider = createProvider(amc);
-
-    Request request = PropertyHelper.getCreateRequest(Collections.singleton(requestProps), null);
-    upgradeResourceProvider.createResources(request);
-
-    List<UpgradeEntity> upgrades = upgradeDao.findUpgrades(cluster.getClusterId());
-    assertEquals(1, upgrades.size());
-
-    UpgradeEntity upgrade = upgrades.get(0);
-    assertEquals("upgrade_test", upgrade.getUpgradePackage());
-    assertEquals(3, upgrade.getUpgradeGroups().size());
-
-    UpgradeGroupEntity group = upgrade.getUpgradeGroups().get(2);
-    assertEquals(3, group.getItems().size());
-
-    group = upgrade.getUpgradeGroups().get(0);
-    assertEquals(2, group.getItems().size());
-    UpgradeItemEntity item = group.getItems().get(1);
-    assertEquals("Value is set for the source stack upgrade pack", "[{\"message\":\"Goo\"}]", item.getText());
-
-    assertTrue(cluster.getDesiredConfigs().containsKey("hive-site"));
-
-    StackId newStack = cluster.getDesiredStackVersion();
-
-    assertTrue(oldStack.equals(newStack));
-
-    for (Service s : cluster.getServices().values()) {
-      assertEquals(newStack, s.getDesiredStackId());
-
-      for (ServiceComponent sc : s.getServiceComponents().values()) {
-        assertEquals(newStack, sc.getDesiredStackId());
-      }
-    }
-
-    // Hive service checks have generated the ExecutionCommands by now.
-    // Change the new desired config tag and verify execution command picks up new tag
-    assertEquals(configTagVersion1, cluster.getDesiredConfigByType("hive-site").getTag());
-    final Config newConfig = configFactory.createNew(cluster, "hive-site", configTagVersion2, configTagVersion2Properties, null);
-    Set<Config> desiredConfigs = new HashSet<Config>() {
-      {
-        add(newConfig);
-      }
-    };
-
-    cluster.addConfig(newConfig);
-    cluster.addDesiredConfig("admin", desiredConfigs);
-    assertEquals(configTagVersion2, cluster.getDesiredConfigByType("hive-site").getTag());
-    Gson gson = new Gson();
-
-    List<ExecutionCommandEntity> currentExecutionCommands = injector.getInstance(ExecutionCommandDAO.class).findAll();
-    for (ExecutionCommandEntity ece : currentExecutionCommands) {
-      String executionCommandJson = new String(ece.getCommand());
-      Map<String, Object> commandMap = gson.<Map<String, Object>> fromJson(executionCommandJson, Map.class);
-
-      // ensure that the latest tag is being used - this is absolutely required
-      // for upgrades
-      Set<String> roleCommandsThatMustHaveRefresh = new HashSet<>();
-      roleCommandsThatMustHaveRefresh.add("SERVICE_CHECK");
-      roleCommandsThatMustHaveRefresh.add("RESTART");
-      roleCommandsThatMustHaveRefresh.add("ACTIONEXECUTE");
-
-      String roleCommand = (String) commandMap.get("roleCommand");
-      if (roleCommandsThatMustHaveRefresh.contains(roleCommand)) {
-        assertTrue(commandMap.containsKey(KeyNames.REFRESH_CONFIG_TAGS_BEFORE_EXECUTION));
-        Object object = commandMap.get(KeyNames.REFRESH_CONFIG_TAGS_BEFORE_EXECUTION);
-        assertTrue(Boolean.valueOf(object.toString()));
-
-        ExecutionCommandWrapperFactory ecwFactory = injector.getInstance(ExecutionCommandWrapperFactory.class);
-        ExecutionCommandWrapper executionCommandWrapper = ecwFactory.createFromJson(executionCommandJson);
-        ExecutionCommand executionCommand = executionCommandWrapper.getExecutionCommand();
-        Map<String, Map<String, String>> configurationTags = executionCommand.getConfigurationTags();
-        assertEquals(configTagVersion2, configurationTags.get("hive-site").get("tag"));
-        Map<String, Map<String, String>> configurations = executionCommand.getConfigurations();
-        assertEquals("10010", configurations.get("hive-site").get("hive.server2.thrift.port"));
-      }
-    }
-  }
-
-  /**
-   * @param amc
-   * @return the provider
-   */
-  private UpgradeResourceProvider createProvider(AmbariManagementController amc) {
-    return new UpgradeResourceProvider(amc);
-  }
-}

http://git-wip-us.apache.org/repos/asf/ambari/blob/aaa821cc/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderTest.java
index d30d9e0..576f308 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderTest.java
@@ -90,7 +90,6 @@ import org.apache.ambari.server.state.ConfigHelper;
 import org.apache.ambari.server.state.DesiredConfig;
 import org.apache.ambari.server.state.Host;
 import org.apache.ambari.server.state.HostState;
-import org.apache.ambari.server.state.RepositoryVersionState;
 import org.apache.ambari.server.state.Service;
 import org.apache.ambari.server.state.ServiceComponent;
 import org.apache.ambari.server.state.ServiceComponentHost;
@@ -236,9 +235,6 @@ public class UpgradeResourceProviderTest {
     helper.getOrCreateRepositoryVersion(stack211, stack211.getStackVersion());
     helper.getOrCreateRepositoryVersion(stack220, stack220.getStackVersion());
 
-    cluster.createClusterVersion(stack211, stack211.getStackVersion(), "admin", RepositoryVersionState.INSTALLING);
-    cluster.transitionClusterVersion(stack211, stack211.getStackVersion(), RepositoryVersionState.CURRENT);
-
     clusters.addHost("h1");
     Host host = clusters.getHost("h1");
     Map<String, String> hostAttributes = new HashMap<>();
@@ -937,6 +933,7 @@ public class UpgradeResourceProviderTest {
     Cluster cluster = clusters.getCluster("c1");
 
     StackEntity stackEntity = stackDAO.find("HDP", "2.1.1");
+
     RepositoryVersionEntity repoVersionEntity = new RepositoryVersionEntity();
     repoVersionEntity.setDisplayName("My New Version 3");
     repoVersionEntity.setOperatingSystems("");
@@ -1173,7 +1170,7 @@ public class UpgradeResourceProviderTest {
     desiredConfigurations.put("baz-site", null);
 
     Cluster cluster = EasyMock.createNiceMock(Cluster.class);
-    expect(cluster.getCurrentStackVersion()).andReturn(stack211);
+    expect(cluster.getCurrentStackVersion()).andReturn(stack211).atLeastOnce();
     expect(cluster.getDesiredStackVersion()).andReturn(stack220);
     expect(cluster.getDesiredConfigs()).andReturn(desiredConfigurations);
     expect(cluster.getDesiredConfigByType("foo-site")).andReturn(fooConfig);
@@ -1209,6 +1206,7 @@ public class UpgradeResourceProviderTest {
 
     UpgradeContext upgradeContext = upgradeContextFactory.create(cluster, upgrade.getType(),
         Direction.UPGRADE, "2.2.0.0", new HashMap<String, Object>());
+    upgradeContext.setUpgradePack(upgrade);
 
     upgradeResourceProvider.applyStackAndProcessConfigurations(upgradeContext);
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/aaa821cc/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeSummaryResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeSummaryResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeSummaryResourceProviderTest.java
index 094706e..f4ac0b1 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeSummaryResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeSummaryResourceProviderTest.java
@@ -69,7 +69,6 @@ import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Clusters;
 import org.apache.ambari.server.state.Host;
 import org.apache.ambari.server.state.HostState;
-import org.apache.ambari.server.state.RepositoryVersionState;
 import org.apache.ambari.server.state.Service;
 import org.apache.ambari.server.state.ServiceComponent;
 import org.apache.ambari.server.state.ServiceComponentHost;
@@ -165,7 +164,6 @@ public class UpgradeSummaryResourceProviderTest {
     Cluster cluster = clusters.getCluster("c1");
 
     helper.getOrCreateRepositoryVersion(stackId, stackId.getStackVersion());
-    cluster.createClusterVersion(stackId, stackId.getStackVersion(), "admin", RepositoryVersionState.INSTALLING);
 
     clusters.addHost("h1");
     Host host = clusters.getHost("h1");

http://git-wip-us.apache.org/repos/asf/ambari/blob/aaa821cc/ambari-server/src/test/java/org/apache/ambari/server/events/EventsTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/events/EventsTest.java b/ambari-server/src/test/java/org/apache/ambari/server/events/EventsTest.java
index 9907153..710e4e7 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/events/EventsTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/events/EventsTest.java
@@ -39,7 +39,6 @@ import org.apache.ambari.server.state.Clusters;
 import org.apache.ambari.server.state.Host;
 import org.apache.ambari.server.state.HostState;
 import org.apache.ambari.server.state.MaintenanceState;
-import org.apache.ambari.server.state.RepositoryVersionState;
 import org.apache.ambari.server.state.Service;
 import org.apache.ambari.server.state.ServiceComponent;
 import org.apache.ambari.server.state.ServiceComponentFactory;
@@ -123,8 +122,6 @@ public class EventsTest {
 
     m_cluster.setDesiredStackVersion(stackId);
     m_repositoryVersion = m_helper.getOrCreateRepositoryVersion(stackId, REPO_VERSION);
-    m_cluster.createClusterVersion(stackId, REPO_VERSION, "admin",
-        RepositoryVersionState.INSTALLING);
 
     m_clusters.mapHostToCluster(HOSTNAME, m_clusterName);
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/aaa821cc/ambari-server/src/test/java/org/apache/ambari/server/events/listeners/upgrade/HostVersionOutOfSyncListenerTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/events/listeners/upgrade/HostVersionOutOfSyncListenerTest.java b/ambari-server/src/test/java/org/apache/ambari/server/events/listeners/upgrade/HostVersionOutOfSyncListenerTest.java
index 6184d6d..4ca2070 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/events/listeners/upgrade/HostVersionOutOfSyncListenerTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/events/listeners/upgrade/HostVersionOutOfSyncListenerTest.java
@@ -23,7 +23,6 @@ import static org.junit.Assert.assertEquals;
 import java.sql.SQLException;
 import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -42,7 +41,6 @@ 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.HostVersionDAO;
-import org.apache.ambari.server.orm.entities.ClusterVersionEntity;
 import org.apache.ambari.server.orm.entities.HostVersionEntity;
 import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
 import org.apache.ambari.server.state.Cluster;
@@ -106,8 +104,6 @@ public class HostVersionOutOfSyncListenerTest {
     addHost("h1");
 
     helper.getOrCreateRepositoryVersion(stackId, stackId.getStackVersion());
-    c1.createClusterVersion(stackId, stackId.getStackVersion(), "admin", RepositoryVersionState.INSTALLING);
-    c1.transitionClusterVersion(stackId, stackId.getStackVersion(), RepositoryVersionState.CURRENT);
     clusters.mapHostToCluster("h1", "c1");
   }
 
@@ -137,13 +133,10 @@ public class HostVersionOutOfSyncListenerTest {
     RepositoryVersionEntity repositoryVersionEntity = helper.getOrCreateRepositoryVersion(stackId,
         INSTALLED_VERSION);
 
-    c1.createClusterVersion(stackId, INSTALLED_VERSION, "admin", RepositoryVersionState.INSTALLING);
     c1.setCurrentStackVersion(stackId);
-    c1.recalculateAllClusterVersionStates();
-    assertRepoVersionState(stackId.getStackId(), INSTALLED_VERSION,
-        RepositoryVersionState.INSTALLING);
+    assertRepoVersionState(INSTALLED_VERSION, RepositoryVersionState.INSTALLING);
 
-    assertRepoVersionState(stackId.getStackId(), CURRENT_VERSION, RepositoryVersionState.CURRENT);
+    assertRepoVersionState(CURRENT_VERSION, RepositoryVersionState.CURRENT);
 
     // Add ZK service with only ZOOKEEPER_SERVER
     List<String> hostList = new ArrayList<>();
@@ -160,10 +153,8 @@ public class HostVersionOutOfSyncListenerTest {
     helper.createHostVersion("h2", repositoryVersionEntity, RepositoryVersionState.INSTALLED);
     helper.createHostVersion("h3", repositoryVersionEntity, RepositoryVersionState.INSTALLED);
 
-    c1.recalculateAllClusterVersionStates();
-
-    assertRepoVersionState(stackId.getStackId(), INSTALLED_VERSION, RepositoryVersionState.INSTALLED);
-    assertRepoVersionState(stackId.getStackId(), CURRENT_VERSION, RepositoryVersionState.CURRENT);
+    assertRepoVersionState(INSTALLED_VERSION, RepositoryVersionState.INSTALLED);
+    assertRepoVersionState(CURRENT_VERSION, RepositoryVersionState.CURRENT);
 
     // Add new host and verify that it has all host versions present
     List<HostVersionEntity> h2Versions = hostVersionDAO.findAll();
@@ -190,9 +181,7 @@ public class HostVersionOutOfSyncListenerTest {
     RepositoryVersionEntity repositoryVersionEntity = helper.getOrCreateRepositoryVersion(stackId,
             INSTALLED_VERSION);
     helper.createHostVersion("h1", repositoryVersionEntity, RepositoryVersionState.INSTALLED);
-    c1.recalculateAllClusterVersionStates();
-    assertRepoVersionState(stackId.getStackId(), INSTALLED_VERSION,
-        RepositoryVersionState.INSTALLED);
+    assertRepoVersionState(INSTALLED_VERSION, RepositoryVersionState.INSTALLED);
 
     // Add new host and verify that it has all host versions present
     List<HostVersionEntity> h2Versions = hostVersionDAO.findAll();
@@ -225,9 +214,9 @@ public class HostVersionOutOfSyncListenerTest {
     // register the new repo
     addRepoVersion(INSTALLED_VERSION_2, yaStackId);
 
-    assertRepoVersionState(stackId.getStackId(), INSTALLED_VERSION,RepositoryVersionState.INSTALLED);
-    assertRepoVersionState(yaStackId.getStackId(), INSTALLED_VERSION_2,RepositoryVersionState.INSTALLED);
-    assertRepoVersionState(yaStackId.getStackId(), CURRENT_VERSION, RepositoryVersionState.CURRENT);
+    assertRepoVersionState(INSTALLED_VERSION, RepositoryVersionState.INSTALLED);
+    assertRepoVersionState(INSTALLED_VERSION_2, RepositoryVersionState.INSTALLED);
+    assertRepoVersionState(CURRENT_VERSION, RepositoryVersionState.CURRENT);
 
     //Add HDFS service
     List<String> hostList = new ArrayList<>();
@@ -260,9 +249,9 @@ public class HostVersionOutOfSyncListenerTest {
     }
 
 
-    assertRepoVersionState(stackId.getStackId(), INSTALLED_VERSION,RepositoryVersionState.OUT_OF_SYNC);
-    assertRepoVersionState(yaStackId.getStackId(), INSTALLED_VERSION_2,RepositoryVersionState.OUT_OF_SYNC);
-    assertRepoVersionState(yaStackId.getStackId(), CURRENT_VERSION, RepositoryVersionState.CURRENT);
+    assertRepoVersionState(INSTALLED_VERSION, RepositoryVersionState.OUT_OF_SYNC);
+    assertRepoVersionState(INSTALLED_VERSION_2, RepositoryVersionState.OUT_OF_SYNC);
+    assertRepoVersionState(CURRENT_VERSION, RepositoryVersionState.CURRENT);
   }
 
 
@@ -298,8 +287,7 @@ public class HostVersionOutOfSyncListenerTest {
     List<HostVersionEntity> hostVersions = hostVersionDAO.findAll();
 
     // Host version should not transition to OUT_OF_SYNC state
-    assertRepoVersionState(stackId.getStackId(), INSTALLED_VERSION,
-        RepositoryVersionState.INSTALLED);
+    assertRepoVersionState(INSTALLED_VERSION, RepositoryVersionState.INSTALLED);
     for (HostVersionEntity hostVersionEntity : hostVersions) {
       if (hostVersionEntity.getRepositoryVersion().getVersion().equals(INSTALLED_VERSION)) {
         assertEquals(hostVersionEntity.getState(), RepositoryVersionState.INSTALLED);
@@ -322,8 +310,8 @@ public class HostVersionOutOfSyncListenerTest {
     createClusterAndHosts(INSTALLED_VERSION, stackId);
     addRepoVersion(INSTALLED_VERSION_2, yaStackId);
 
-    assertRepoVersionState(stackId.getStackId(), INSTALLED_VERSION, RepositoryVersionState.INSTALLED);
-    assertRepoVersionState(stackId.getStackId(), INSTALLED_VERSION_2, RepositoryVersionState.INSTALLED);
+    assertRepoVersionState(INSTALLED_VERSION, RepositoryVersionState.INSTALLED);
+    assertRepoVersionState(INSTALLED_VERSION_2, RepositoryVersionState.INSTALLED);
 
     //Add ZOOKEEPER_CLIENT component
     List<String> hostList = new ArrayList<>();
@@ -338,7 +326,7 @@ public class HostVersionOutOfSyncListenerTest {
     changedHosts.add("h2");
     changedHosts.add("h3");
 
-    assertRepoVersionState(stackId.getStackId(), INSTALLED_VERSION,RepositoryVersionState.OUT_OF_SYNC);
+    assertRepoVersionState(INSTALLED_VERSION, RepositoryVersionState.OUT_OF_SYNC);
 
     List<HostVersionEntity> hostVersions = hostVersionDAO.findAll();
 
@@ -369,18 +357,17 @@ public class HostVersionOutOfSyncListenerTest {
     StackId stackId = new StackId(this.stackId);
     RepositoryVersionEntity repositoryVersionEntity = helper.getOrCreateRepositoryVersion(stackId,"2.2.0-1000");
     RepositoryVersionEntity repositoryVersionEntity2 = helper.getOrCreateRepositoryVersion(stackId,"2.2.0-2000");
-    c1.createClusterVersion(stackId, "2.2.0-1000", "admin", RepositoryVersionState.INSTALLING);
     c1.setCurrentStackVersion(stackId);
-    c1.recalculateAllClusterVersionStates();
-    assertRepoVersionState(stackId.getStackId(), "2.2.0-1000", RepositoryVersionState.INSTALLING);
-    assertRepoVersionState(stackId.getStackId(), "2.2.0-2086", RepositoryVersionState.CURRENT);
+
+    assertRepoVersionState("2.2.0-1000", RepositoryVersionState.INSTALLING);
+    assertRepoVersionState("2.2.0-2086", RepositoryVersionState.CURRENT);
 
     helper.createHostVersion("h1", repositoryVersionEntity, RepositoryVersionState.INSTALLED);
     helper.createHostVersion("h1", repositoryVersionEntity2, RepositoryVersionState.INSTALLED);
-    c1.recalculateAllClusterVersionStates();
-    assertRepoVersionState(stackId.getStackId(), "2.2.0-1000", RepositoryVersionState.INSTALLED);
-    assertRepoVersionState(stackId.getStackId(), "2.2.0-2000", RepositoryVersionState.INSTALLED);
-    assertRepoVersionState(stackId.getStackId(), "2.2.0-2086", RepositoryVersionState.CURRENT);
+
+    assertRepoVersionState("2.2.0-1000", RepositoryVersionState.INSTALLED);
+    assertRepoVersionState("2.2.0-2000", RepositoryVersionState.INSTALLED);
+    assertRepoVersionState("2.2.0-2086", RepositoryVersionState.CURRENT);
 
     // Add new host and verify that it has all host versions present
     addHost("h2");
@@ -412,12 +399,10 @@ public class HostVersionOutOfSyncListenerTest {
     RepositoryVersionEntity repositoryVersionEntity = helper.getOrCreateRepositoryVersion(stackId,
         "2.2.9-9999");
 
-    c1.createClusterVersion(stackId, "2.2.9-9999", "admin", RepositoryVersionState.INSTALLING);
     c1.setCurrentStackVersion(stackId);
-    c1.recalculateAllClusterVersionStates();
 
-    assertRepoVersionState(stackId.getStackId(), "2.2.0", RepositoryVersionState.CURRENT);
-    assertRepoVersionState(stackId.getStackId(), "2.2.9-9999", RepositoryVersionState.INSTALLING);
+    assertRepoVersionState("2.2.0", RepositoryVersionState.CURRENT);
+    assertRepoVersionState("2.2.9-9999", RepositoryVersionState.INSTALLING);
 
     HostVersionEntity hv1 = helper.createHostVersion("h1", repositoryVersionEntity,
         RepositoryVersionState.INSTALLED);
@@ -425,9 +410,8 @@ public class HostVersionOutOfSyncListenerTest {
         RepositoryVersionState.INSTALLED);
 
     // do an initial calculate to make sure the new repo is installing
-    c1.recalculateAllClusterVersionStates();
-    assertRepoVersionState(stackId.getStackId(), "2.2.0", RepositoryVersionState.CURRENT);
-    assertRepoVersionState(stackId.getStackId(), "2.2.9-9999", RepositoryVersionState.INSTALLED);
+    assertRepoVersionState("2.2.0", RepositoryVersionState.CURRENT);
+    assertRepoVersionState("2.2.9-9999", RepositoryVersionState.INSTALLED);
 
     // make it seems like we upgraded, but 1 host still hasn't finished
     hv1.setState(RepositoryVersionState.INSTALLED);
@@ -436,9 +420,8 @@ public class HostVersionOutOfSyncListenerTest {
     hostVersionDAO.merge(hv2);
 
     // recalculate and ensure that the cluster is UPGRADING
-    c1.recalculateAllClusterVersionStates();
-    assertRepoVersionState(stackId.getStackId(), "2.2.0", RepositoryVersionState.CURRENT);
-    assertRepoVersionState(stackId.getStackId(), "2.2.9-9999", RepositoryVersionState.INSTALLING);
+    assertRepoVersionState("2.2.0", RepositoryVersionState.CURRENT);
+    assertRepoVersionState("2.2.9-9999", RepositoryVersionState.INSTALLING);
 
     // delete the host that was UPGRADING, and DON'T call recalculate; let the
     // event handle it
@@ -446,8 +429,8 @@ public class HostVersionOutOfSyncListenerTest {
     clusters.deleteHost("h2");
     clusters.publishHostsDeletion(Collections.singleton(c1), Collections.singleton("h2"));
     injector.getInstance(UnitOfWork.class).end();
-    assertRepoVersionState(stackId.getStackId(), "2.2.0", RepositoryVersionState.CURRENT);
-    assertRepoVersionState(stackId.getStackId(), "2.2.9-9999", RepositoryVersionState.INSTALLED);
+    assertRepoVersionState("2.2.0", RepositoryVersionState.CURRENT);
+    assertRepoVersionState("2.2.9-9999", RepositoryVersionState.INSTALLED);
   }
 
   @Test
@@ -469,7 +452,7 @@ public class HostVersionOutOfSyncListenerTest {
 
     // create repo version
     RepositoryVersionEntity repo = helper.getOrCreateRepositoryVersion(stackId, stackId.getStackVersion());
-    c1.createClusterVersion(stackId, stackId.getStackVersion(), "admin", RepositoryVersionState.INSTALLING);
+
     clusters.mapHostToCluster(host1, clusterName);
     clusters.mapHostToCluster(host2, clusterName);
     clusters.mapHostToCluster(host3, clusterName);
@@ -603,15 +586,15 @@ public class HostVersionOutOfSyncListenerTest {
     }
   }
 
-  private void assertRepoVersionState(String stack, String version, RepositoryVersionState state) {
-    StackId stackId = new StackId(stack);
-    Collection<ClusterVersionEntity> allClusterVersions = c1.getAllClusterVersions();
-    for (ClusterVersionEntity entity : allClusterVersions) {
-      StackId clusterVersionStackId = new StackId(entity.getRepositoryVersion().getStack());
-      if (clusterVersionStackId.equals(stackId)
-          && entity.getRepositoryVersion().getVersion().equals(version)) {
-        assertEquals(state, entity.getState());
+  private void assertRepoVersionState(String version, RepositoryVersionState state) {
+
+    for (Host host : c1.getHosts()) {
+      for (HostVersionEntity hostVersionEntity : host.getAllHostVersions()) {
+        if (hostVersionEntity.getRepositoryVersion().getVersion().equals("version")) {
+          assertEquals(state, hostVersionEntity.getState());
+        }
       }
     }
+
   }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/aaa821cc/ambari-server/src/test/java/org/apache/ambari/server/events/listeners/upgrade/StackVersionListenerTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/events/listeners/upgrade/StackVersionListenerTest.java b/ambari-server/src/test/java/org/apache/ambari/server/events/listeners/upgrade/StackVersionListenerTest.java
index d5b2d46..a74a1d2 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/events/listeners/upgrade/StackVersionListenerTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/events/listeners/upgrade/StackVersionListenerTest.java
@@ -140,8 +140,6 @@ public class StackVersionListenerTest extends EasyMockSupport {
     sch.setVersion(VALID_NEW_VERSION);
     expectLastCall().once();
     expect(sch.recalculateHostVersionState()).andReturn(DUMMY_REPOSITORY_VERSION_ENTITY).once();
-    cluster.recalculateClusterVersionState(DUMMY_REPOSITORY_VERSION_ENTITY);
-    expectLastCall().once();
 
     replayAll();
 
@@ -155,8 +153,6 @@ public class StackVersionListenerTest extends EasyMockSupport {
     sch.setVersion(VALID_NEW_VERSION);
     expectLastCall().once();
     expect(sch.recalculateHostVersionState()).andReturn(DUMMY_REPOSITORY_VERSION_ENTITY).once();
-    cluster.recalculateClusterVersionState(DUMMY_REPOSITORY_VERSION_ENTITY);
-    expectLastCall().once();
 
     replayAll();
 
@@ -187,8 +183,6 @@ public class StackVersionListenerTest extends EasyMockSupport {
     sch.setVersion(VALID_NEW_VERSION);
     expectLastCall().once();
     expect(sch.recalculateHostVersionState()).andReturn(DUMMY_REPOSITORY_VERSION_ENTITY).once();
-    cluster.recalculateClusterVersionState(DUMMY_REPOSITORY_VERSION_ENTITY);
-    expectLastCall().once();
 
     replayAll();
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/aaa821cc/ambari-server/src/test/java/org/apache/ambari/server/orm/OrmTestHelper.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/orm/OrmTestHelper.java b/ambari-server/src/test/java/org/apache/ambari/server/orm/OrmTestHelper.java
index e84e0f6..469e8c8 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/orm/OrmTestHelper.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/orm/OrmTestHelper.java
@@ -92,6 +92,7 @@ import org.apache.ambari.server.state.State;
 import org.apache.ambari.server.state.alert.Scope;
 import org.apache.ambari.server.state.alert.SourceType;
 import org.apache.ambari.server.state.cluster.ClustersImpl;
+import org.junit.Assert;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.security.crypto.password.PasswordEncoder;
@@ -102,8 +103,6 @@ import com.google.inject.Provider;
 import com.google.inject.Singleton;
 import com.google.inject.persist.Transactional;
 
-import junit.framework.Assert;
-
 @Singleton
 public class OrmTestHelper {
 
@@ -403,8 +402,6 @@ public class OrmTestHelper {
     StackId stackId = new StackId("HDP", "2.0.6");
     cluster.setDesiredStackVersion(stackId);
     getOrCreateRepositoryVersion(stackId, stackId.getStackVersion());
-    cluster.createClusterVersion(stackId,
-        stackId.getStackVersion(), "admin", RepositoryVersionState.INSTALLING);
     return cluster;
   }
 
@@ -436,7 +433,8 @@ public class OrmTestHelper {
       ServiceFactory serviceFactory, ServiceComponentFactory componentFactory,
       ServiceComponentHostFactory schFactory, String hostName) throws Exception {
 
-    RepositoryVersionEntity repositoryVersion = cluster.getCurrentClusterVersion().getRepositoryVersion();
+    RepositoryVersionEntity repositoryVersion = repositoryVersionDAO.findByStackAndVersion(cluster.getDesiredStackVersion(),
+        cluster.getDesiredStackVersion().getStackVersion());
 
     String serviceName = "HDFS";
     Service service = serviceFactory.createNew(cluster, serviceName, repositoryVersion);
@@ -469,7 +467,8 @@ public class OrmTestHelper {
       ServiceFactory serviceFactory, ServiceComponentFactory componentFactory,
       ServiceComponentHostFactory schFactory, String hostName) throws Exception {
 
-    RepositoryVersionEntity repositoryVersion = cluster.getCurrentClusterVersion().getRepositoryVersion();
+    RepositoryVersionEntity repositoryVersion = repositoryVersionDAO.findByStackAndVersion(cluster.getDesiredStackVersion(),
+        cluster.getDesiredStackVersion().getStackVersion());
 
     String serviceName = "YARN";
     Service service = serviceFactory.createNew(cluster, serviceName, repositoryVersion);
@@ -600,6 +599,41 @@ public class OrmTestHelper {
   }
 
   /**
+   * Convenient method to create or to get repository version for given cluster.  The repository
+   * version string is based on the cluster's stack version.
+   *
+   * @param stackId stack object
+   * @param version stack version
+   * @return repository version
+   */
+  public RepositoryVersionEntity getOrCreateRepositoryVersion(Cluster cluster) {
+    StackId stackId = cluster.getCurrentStackVersion();
+    String version = stackId.getStackVersion() + ".1";
+
+    StackDAO stackDAO = injector.getInstance(StackDAO.class);
+    StackEntity stackEntity = stackDAO.find(stackId.getStackName(),
+        stackId.getStackVersion());
+
+    assertNotNull(stackEntity);
+
+    RepositoryVersionEntity repositoryVersion = repositoryVersionDAO.findByStackAndVersion(
+        stackId, version);
+
+    if (repositoryVersion == null) {
+      try {
+        repositoryVersion = repositoryVersionDAO.create(stackEntity, version,
+            String.valueOf(System.currentTimeMillis()) + uniqueCounter.incrementAndGet(), "");
+      } catch (Exception ex) {
+        LOG.error("Caught exception", ex);
+        ex.printStackTrace();
+        Assert.fail(MessageFormat.format("Unable to create Repo Version for Stack {0} and version {1}",
+            stackEntity.getStackName() + "-" + stackEntity.getStackVersion(), version));
+      }
+    }
+    return repositoryVersion;
+  }
+
+  /**
    * Convenient method to create or to get repository version for given stack.
    *
    * @param stackId stack object
@@ -623,6 +657,7 @@ public class OrmTestHelper {
             String.valueOf(System.currentTimeMillis()) + uniqueCounter.incrementAndGet(), "");
       } catch (Exception ex) {
         LOG.error("Caught exception", ex);
+        ex.printStackTrace();
         Assert.fail(MessageFormat.format("Unable to create Repo Version for Stack {0} and version {1}",
             stackEntity.getStackName() + "-" + stackEntity.getStackVersion(), version));
       }


Mime
View raw message