ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nc...@apache.org
Subject [14/37] ambari git commit: AMBARI-21450. Initial cherry-picking for feature branch (ncole)
Date Thu, 13 Jul 2017 19:14:32 GMT
http://git-wip-us.apache.org/repos/asf/ambari/blob/48f7fb22/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 7018245..32a5358 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
@@ -1,4 +1,4 @@
- /**
+/*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
  * distributed with this work for additional information
@@ -31,7 +31,6 @@ import static org.easymock.EasyMock.verify;
 
 import java.io.File;
 import java.io.FileInputStream;
-import java.lang.reflect.Field;
 import java.sql.SQLException;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -54,7 +53,6 @@ import org.apache.ambari.server.actionmanager.ExecutionCommandWrapper;
 import org.apache.ambari.server.actionmanager.HostRoleCommand;
 import org.apache.ambari.server.actionmanager.Stage;
 import org.apache.ambari.server.actionmanager.StageFactory;
-import org.apache.ambari.server.agent.CommandReport;
 import org.apache.ambari.server.agent.ExecutionCommand;
 import org.apache.ambari.server.agent.ExecutionCommand.KeyNames;
 import org.apache.ambari.server.api.services.AmbariMetaInfo;
@@ -70,24 +68,16 @@ 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.ResourceEntity;
-import org.apache.ambari.server.orm.entities.ResourceTypeEntity;
 import org.apache.ambari.server.orm.entities.StackEntity;
 import org.apache.ambari.server.orm.entities.UpgradeEntity;
 import org.apache.ambari.server.security.TestAuthenticationFactory;
 import org.apache.ambari.server.security.authorization.AuthorizationException;
-import org.apache.ambari.server.security.authorization.ResourceType;
-import org.apache.ambari.server.serveraction.upgrades.FinalizeUpgradeAction;
 import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Clusters;
 import org.apache.ambari.server.state.ConfigHelper;
@@ -102,17 +92,18 @@ import org.apache.ambari.server.state.ServiceInfo;
 import org.apache.ambari.server.state.ServiceOsSpecific;
 import org.apache.ambari.server.state.StackId;
 import org.apache.ambari.server.state.cluster.ClusterImpl;
+import org.apache.ambari.server.state.repository.VersionDefinitionXml;
 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.commons.io.IOUtils;
+import org.apache.commons.lang.StringUtils;
 import org.easymock.Capture;
 import org.easymock.EasyMock;
 import org.easymock.IAnswer;
 import org.junit.After;
 import org.junit.Assert;
 import org.junit.Before;
-import org.junit.Ignore;
 import org.junit.Test;
 import org.springframework.security.core.Authentication;
 import org.springframework.security.core.context.SecurityContextHolder;
@@ -135,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;
@@ -177,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
@@ -218,10 +203,18 @@ public class ClusterStackVersionResourceProviderTest {
     Map<String, String> hostLevelParams = new HashMap<>();
     StackId stackId = new StackId("HDP", "2.0.1");
 
+    StackEntity stackEntity = new StackEntity();
+    stackEntity.setStackName("HDP");
+    stackEntity.setStackVersion("2.1.1");
+
     RepositoryVersionEntity repoVersion = new RepositoryVersionEntity();
     repoVersion.setId(1l);
     repoVersion.setOperatingSystems(OS_JSON);
+    repoVersion.setStack(stackEntity);
 
+    final String hostWithoutVersionableComponents = "host2";
+
+    List<Host> hostsNeedingInstallCommands = new ArrayList<>();
     Map<String, Host> hostsForCluster = new HashMap<>();
     int hostCount = 10;
     for (int i = 0; i < hostCount; i++) {
@@ -236,6 +229,10 @@ public class ClusterStackVersionResourceProviderTest {
 
       replay(host);
       hostsForCluster.put(hostname, host);
+
+      if (!StringUtils.equals(hostWithoutVersionableComponents, hostname)) {
+        hostsNeedingInstallCommands.add(host);
+      }
     }
 
     final ServiceComponentHost schDatanode = createMock(ServiceComponentHost.class);
@@ -280,11 +277,11 @@ public class ClusterStackVersionResourceProviderTest {
     expect(managementController.getActionManager()).andReturn(actionManager).anyTimes();
     expect(managementController.getJdkResourceUrl()).andReturn("/JdkResourceUrl").anyTimes();
     expect(managementController.getPackagesForServiceHost(anyObject(ServiceInfo.class),
-            (Map<String, String>) anyObject(List.class), anyObject(String.class))).
+            EasyMock.<Map<String, String>>anyObject(), anyObject(String.class))).
             andReturn(packages).times((hostCount - 1) * 2); // 1 host has no versionable components, other hosts have 2 services
 //            // that's why we don't send commands to it
 
-    expect(resourceProviderFactory.getHostResourceProvider(anyObject(Set.class), anyObject(Map.class),
+    expect(resourceProviderFactory.getHostResourceProvider(EasyMock.<Set<String>>anyObject(), EasyMock.<Map<Resource.Type, String>>anyObject(),
             eq(managementController))).andReturn(csvResourceProvider).anyTimes();
 
     expect(clusters.getCluster(anyObject(String.class))).andReturn(cluster);
@@ -300,7 +297,7 @@ public class ClusterStackVersionResourceProviderTest {
       @Override
       public List<ServiceComponentHost> answer() throws Throwable {
         String hostname = (String) EasyMock.getCurrentArguments()[0];
-        if (hostname.equals("host2")) {
+            if (hostname.equals(hostWithoutVersionableComponents)) {
           return schsH2;
         } else {
           return schsH1;
@@ -308,6 +305,10 @@ public class ClusterStackVersionResourceProviderTest {
       }
     }).anyTimes();
 
+    expect(cluster.transitionHostsToInstalling(
+        anyObject(RepositoryVersionEntity.class), anyObject(VersionDefinitionXml.class),
+        eq(false))).andReturn(hostsNeedingInstallCommands).atLeastOnce();
+
     ExecutionCommand executionCommand = createNiceMock(ExecutionCommand.class);
     ExecutionCommandWrapper executionCommandWrapper = createNiceMock(ExecutionCommandWrapper.class);
 
@@ -339,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,
@@ -392,7 +387,6 @@ public class ClusterStackVersionResourceProviderTest {
   }
 
   @Experimental(feature=ExperimentalFeature.PATCH_UPGRADES)
-  @Ignore
   public void testCreateResourcesForPatch() throws Exception {
     Resource.Type type = Resource.Type.ClusterStackVersion;
 
@@ -433,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();
@@ -478,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);
@@ -500,10 +482,10 @@ public class ClusterStackVersionResourceProviderTest {
     expect(managementController.getActionManager()).andReturn(actionManager).anyTimes();
     expect(managementController.getJdkResourceUrl()).andReturn("/JdkResourceUrl").anyTimes();
     expect(managementController.getPackagesForServiceHost(anyObject(ServiceInfo.class),
-            (Map<String, String>) anyObject(List.class), anyObject(String.class))).
+            EasyMock.<Map<String, String>>anyObject(), anyObject(String.class))).
             andReturn(packages).times(1); // only one host has the versionable component
 
-    expect(resourceProviderFactory.getHostResourceProvider(anyObject(Set.class), anyObject(Map.class),
+    expect(resourceProviderFactory.getHostResourceProvider(EasyMock.<Set<String>>anyObject(), EasyMock.<Map<Resource.Type, String>>anyObject(),
             eq(managementController))).andReturn(csvResourceProvider).anyTimes();
 
     expect(clusters.getCluster(anyObject(String.class))).andReturn(cluster);
@@ -563,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);
@@ -574,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,
@@ -636,16 +614,22 @@ public class ClusterStackVersionResourceProviderTest {
 
     File f = new File("src/test/resources/hbase_version_test.xml");
 
+    StackEntity stackEntity = new StackEntity();
+    stackEntity.setStackName("HDP");
+    stackEntity.setStackVersion("2.1.1");
+
     RepositoryVersionEntity repoVersion = new RepositoryVersionEntity();
     repoVersion.setId(1l);
     repoVersion.setOperatingSystems(OS_JSON);
     repoVersion.setVersionXml(IOUtils.toString(new FileInputStream(f)));
     repoVersion.setVersionXsd("version_definition.xsd");
     repoVersion.setType(RepositoryType.STANDARD);
+    repoVersion.setStack(stackEntity);
 
     ambariMetaInfo.getComponent("HDP", "2.1.1", "HBASE", "HBASE_MASTER").setVersionAdvertised(true);
 
-
+    final String hostWithoutVersionableComponents = "host3";
+    List<Host> hostsNeedingInstallCommands = new ArrayList<>();
     Map<String, Host> hostsForCluster = new HashMap<>();
     int hostCount = 10;
     for (int i = 0; i < hostCount; i++) {
@@ -660,6 +644,11 @@ public class ClusterStackVersionResourceProviderTest {
 
       replay(host);
       hostsForCluster.put(hostname, host);
+
+
+      if (!StringUtils.equals(hostWithoutVersionableComponents, hostname)) {
+        hostsNeedingInstallCommands.add(host);
+      }
     }
 
     Service hdfsService = createNiceMock(Service.class);
@@ -717,10 +706,10 @@ public class ClusterStackVersionResourceProviderTest {
     expect(managementController.getActionManager()).andReturn(actionManager).anyTimes();
     expect(managementController.getJdkResourceUrl()).andReturn("/JdkResourceUrl").anyTimes();
     expect(managementController.getPackagesForServiceHost(anyObject(ServiceInfo.class),
-            (Map<String, String>) anyObject(List.class), anyObject(String.class))).
+            EasyMock.<Map<String, String>>anyObject(), anyObject(String.class))).
             andReturn(packages).anyTimes(); // only one host has the versionable component
 
-    expect(resourceProviderFactory.getHostResourceProvider(anyObject(Set.class), anyObject(Map.class),
+    expect(resourceProviderFactory.getHostResourceProvider(EasyMock.<Set<String>>anyObject(), EasyMock.<Map<Resource.Type, String>>anyObject(),
             eq(managementController))).andReturn(csvResourceProvider).anyTimes();
 
     expect(clusters.getCluster(anyObject(String.class))).andReturn(cluster);
@@ -736,7 +725,7 @@ public class ClusterStackVersionResourceProviderTest {
       @Override
       public List<ServiceComponentHost> answer() throws Throwable {
         String hostname = (String) EasyMock.getCurrentArguments()[0];
-        if (hostname.equals("host2")) {
+            if (hostname.equals("host2")) {
           return schsH2;
         } else if (hostname.equals("host3")) {
           return schsH3;
@@ -746,6 +735,9 @@ public class ClusterStackVersionResourceProviderTest {
       }
     }).anyTimes();
 
+    expect(cluster.transitionHostsToInstalling(anyObject(RepositoryVersionEntity.class),
+        anyObject(VersionDefinitionXml.class), eq(false))).andReturn(hostsNeedingInstallCommands).atLeastOnce();
+
 //    ExecutionCommand executionCommand = createNiceMock(ExecutionCommand.class);
     ExecutionCommand executionCommand = new ExecutionCommand();
     ExecutionCommandWrapper executionCommandWrapper = createNiceMock(ExecutionCommandWrapper.class);
@@ -772,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();
 
@@ -784,10 +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));
@@ -795,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,
@@ -868,15 +854,23 @@ public class ClusterStackVersionResourceProviderTest {
 
     File f = new File("src/test/resources/hbase_version_test.xml");
 
+    StackEntity stackEntity = new StackEntity();
+    stackEntity.setStackName("HDP");
+    stackEntity.setStackVersion("2.1.1");
+
     RepositoryVersionEntity repoVersion = new RepositoryVersionEntity();
     repoVersion.setId(1l);
     repoVersion.setOperatingSystems(os_json);
     repoVersion.setVersionXml(IOUtils.toString(new FileInputStream(f)));
     repoVersion.setVersionXsd("version_definition.xsd");
     repoVersion.setType(RepositoryType.STANDARD);
+    repoVersion.setStack(stackEntity);
 
     ambariMetaInfo.getComponent("HDP", "2.1.1", "HBASE", "HBASE_MASTER").setVersionAdvertised(true);
 
+    final String hostWithoutVersionableComponents = "host3";
+    List<Host> hostsNeedingInstallCommands = new ArrayList<>();
+
     Map<String, Host> hostsForCluster = new HashMap<>();
     int hostCount = 10;
     for (int i = 0; i < hostCount; i++) {
@@ -891,6 +885,10 @@ public class ClusterStackVersionResourceProviderTest {
 
       replay(host);
       hostsForCluster.put(hostname, host);
+
+      if (!StringUtils.equals(hostWithoutVersionableComponents, hostname)) {
+        hostsNeedingInstallCommands.add(host);
+      }
     }
 
     Service hdfsService = createNiceMock(Service.class);
@@ -948,10 +946,10 @@ public class ClusterStackVersionResourceProviderTest {
     expect(managementController.getActionManager()).andReturn(actionManager).anyTimes();
     expect(managementController.getJdkResourceUrl()).andReturn("/JdkResourceUrl").anyTimes();
     expect(managementController.getPackagesForServiceHost(anyObject(ServiceInfo.class),
-            (Map<String, String>) anyObject(List.class), anyObject(String.class))).
+            EasyMock.<Map<String, String>>anyObject(), anyObject(String.class))).
             andReturn(packages).anyTimes(); // only one host has the versionable component
 
-    expect(resourceProviderFactory.getHostResourceProvider(anyObject(Set.class), anyObject(Map.class),
+    expect(resourceProviderFactory.getHostResourceProvider(EasyMock.<Set<String>>anyObject(), EasyMock.<Map<Resource.Type, String>>anyObject(),
             eq(managementController))).andReturn(csvResourceProvider).anyTimes();
 
     expect(clusters.getCluster(anyObject(String.class))).andReturn(cluster);
@@ -977,6 +975,9 @@ public class ClusterStackVersionResourceProviderTest {
       }
     }).anyTimes();
 
+    expect(cluster.transitionHostsToInstalling(anyObject(RepositoryVersionEntity.class),
+        anyObject(VersionDefinitionXml.class), eq(false))).andReturn(hostsNeedingInstallCommands).atLeastOnce();
+
 //    ExecutionCommand executionCommand = createNiceMock(ExecutionCommand.class);
     ExecutionCommand executionCommand = new ExecutionCommand();
     ExecutionCommandWrapper executionCommandWrapper = createNiceMock(ExecutionCommandWrapper.class);
@@ -998,10 +999,8 @@ public class ClusterStackVersionResourceProviderTest {
             anyObject(String.class))).andReturn(stage).
             times((int) Math.ceil(hostCount / MAX_TASKS_PER_STAGE));
 
-    expect(
-            repositoryVersionDAOMock.findByStackAndVersion(
-                    anyObject(StackId.class),
-                    anyObject(String.class))).andReturn(repoVersion);
+    expect(repositoryVersionDAOMock.findByStackAndVersion(anyObject(StackId.class),
+        anyObject(String.class))).andReturn(repoVersion);
 
     Capture<org.apache.ambari.server.actionmanager.Request> c = Capture.newInstance();
     Capture<ExecuteActionRequest> ear = Capture.newInstance();
@@ -1013,21 +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);
 
-    TopologyManager topologyManager = injector.getInstance(TopologyManager.class);
-    StageUtils.setTopologyManager(topologyManager);
+    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,
@@ -1066,321 +1058,8 @@ public class ClusterStackVersionResourceProviderTest {
     Assert.assertEquals(Float.valueOf(0.85f), successFactor);
 
     Assert.assertTrue(executionCommand.getRoleParams().containsKey(KeyNames.PACKAGE_VERSION));
-    Assert.assertTrue(executionCommand.getRoleParams().containsKey("base_urls"));
-    Assert.assertEquals("[]", executionCommand.getRoleParams().get("base_urls"));
-  }
-
-   @Test
-   public void testUpdateResourcesAsAdministrator() throws Exception {
-     testUpdateResources(TestAuthenticationFactory.createAdministrator());
-   }
-
-   @Test
-   public void testUpdateResourcesAsClusterAdministrator() throws Exception {
-     testUpdateResources(TestAuthenticationFactory.createClusterAdministrator());
-   }
-
-   @Test(expected = AuthorizationException.class)
-   public void testUpdateResourcesAsClusterOperator() throws Exception {
-     testUpdateResources(TestAuthenticationFactory.createClusterOperator());
-   }
-
-   private void testUpdateResources(Authentication authentication) throws Exception {
-    Resource.Type type = Resource.Type.ClusterStackVersion;
-    String clusterName = "Cluster100";
-
-    AmbariManagementController managementController = createMock(AmbariManagementController.class);
-
-    StackId stackId = new StackId("HDP", "2.0.1");
-    StackEntity stackEntity = stackDAO.find(stackId.getStackName(), stackId.getStackVersion());
-    Assert.assertNotNull(stackEntity);
-
-    ResourceTypeEntity resourceTypeEntity = resourceTypeDAO.findById(ResourceType.CLUSTER.getId());
-    if (resourceTypeEntity == null) {
-      resourceTypeEntity = new ResourceTypeEntity();
-      resourceTypeEntity.setId(ResourceType.CLUSTER.getId());
-      resourceTypeEntity.setName(ResourceType.CLUSTER.name());
-      resourceTypeEntity = resourceTypeDAO.merge(resourceTypeEntity);
-    }
-    ResourceEntity resourceEntity = new ResourceEntity();
-    resourceEntity.setResourceType(resourceTypeEntity);
-
-    final Host host1 = createNiceMock("host1", Host.class);
-    final Host host2 = createNiceMock("host2", Host.class);
-
-    expect(host1.getHostName()).andReturn("host1").anyTimes();
-    expect(host2.getHostName()).andReturn("host2").anyTimes();
-    replay(host1, host2);
-
-    ServiceComponentHost sch = createMock(ServiceComponentHost.class);
-    List<ServiceComponentHost> schs = Collections.singletonList(sch);
-
-    Cluster cluster = createNiceMock(Cluster.class);
-    cluster.setClusterName(clusterName);
-
-    ArrayList<Host> hosts = new ArrayList<Host>() {{
-      add(host1);
-      add(host2);
-    }};
-
-    Clusters clusters = createNiceMock(Clusters.class);
-    expect(clusters.getCluster(anyObject(String.class))).andReturn(cluster);
-
-    RepositoryVersionEntity repoVersion = new RepositoryVersionEntity();
-    repoVersion.setOperatingSystems(OS_JSON);
-    StackEntity newDesiredStack = stackDAO.find("HDP", "2.0.1");
-    repoVersion.setStack(newDesiredStack);
-
-    final ServiceOsSpecific.Package hivePackage = new ServiceOsSpecific.Package();
-    hivePackage.setName("hive");
-    final ServiceOsSpecific.Package mysqlPackage = new ServiceOsSpecific.Package();
-    mysqlPackage.setName("mysql");
-    mysqlPackage.setSkipUpgrade(Boolean.TRUE);
-    List<ServiceOsSpecific.Package> packages = new ArrayList<ServiceOsSpecific.Package>() {{
-      add(hivePackage);
-      add(mysqlPackage);
-    }};
-
-    ActionManager actionManager = createNiceMock(ActionManager.class);
-
-    RequestStatusResponse response = createNiceMock(RequestStatusResponse.class);
-    ResourceProviderFactory resourceProviderFactory = createNiceMock(ResourceProviderFactory.class);
-    ResourceProvider csvResourceProvider = createNiceMock(ClusterStackVersionResourceProvider.class);
-
-    CommandReport report = createNiceMock(CommandReport.class);
-    FinalizeUpgradeAction finalizeUpgradeAction = createNiceMock(FinalizeUpgradeAction.class);
-
-    AbstractControllerResourceProvider.init(resourceProviderFactory);
-
-    Map<String, Map<String, String>> hostConfigTags = new HashMap<>();
-    expect(configHelper.getEffectiveDesiredTags(anyObject(ClusterImpl.class), anyObject(String.class))).andReturn(hostConfigTags);
-
-    expect(managementController.getClusters()).andReturn(clusters).anyTimes();
-    expect(managementController.getAmbariMetaInfo()).andReturn(ambariMetaInfo).anyTimes();
-    expect(managementController.getAuthName()).andReturn("admin").anyTimes();
-    expect(managementController.getActionManager()).andReturn(actionManager).anyTimes();
-    expect(managementController.getJdkResourceUrl()).andReturn("/JdkResourceUrl").anyTimes();
-    expect(managementController.getPackagesForServiceHost(anyObject(ServiceInfo.class),
-            (Map<String, String>) anyObject(List.class), anyObject(String.class))).andReturn(packages).anyTimes();
-
-    expect(resourceProviderFactory.getHostResourceProvider(anyObject(Set.class), anyObject(Map.class),
-            eq(managementController))).andReturn(csvResourceProvider).anyTimes();
-
-    expect(cluster.getCurrentStackVersion()).andReturn(stackId);
-    expect(cluster.getServiceComponentHosts(anyObject(String.class))).andReturn(schs).anyTimes();
-
-    Capture<StackId> capturedStackId = new Capture<>();
-    cluster.setDesiredStackVersion(capture(capturedStackId));
-      expectLastCall().once();
-    expect(cluster.getHosts()).andReturn(hosts).anyTimes();
-
-
-    expect(sch.getServiceName()).andReturn("HIVE").anyTimes();
-
-    expect(repositoryVersionDAOMock.findByDisplayName(anyObject(String.class))).andReturn(repoVersion);
-
-    expect(actionManager.getRequestTasks(anyLong())).andReturn(Collections.<HostRoleCommand>emptyList()).anyTimes();
-
-    expect(finalizeUpgradeAction.execute(null)).andReturn(report);
-
-    expect(report.getStdOut()).andReturn("Dummy stdout");
-    expect(report.getStdErr()).andReturn("Dummy stderr");
-    expect(report.getStatus()).andReturn("COMPLETED");
-
-    // replay
-    replay(managementController, response, clusters, resourceProviderFactory, csvResourceProvider,
-            cluster, repositoryVersionDAOMock, configHelper, sch, actionManager, finalizeUpgradeAction, report,
-            stageFactory);
-
-    ResourceProvider provider = AbstractControllerResourceProvider.getResourceProvider(
-            type,
-            PropertyHelper.getPropertyIds(type),
-            PropertyHelper.getKeyPropertyIds(type),
-            managementController);
-
-    injector.injectMembers(provider);
-
-    // Have to inject instance manually because injection via DI fails
-    Field field = ClusterStackVersionResourceProvider.class.getDeclaredField("finalizeUpgradeAction");
-    field.setAccessible(true);
-    field.set(provider, finalizeUpgradeAction);
-
-    // add the property map to a set for the request.  add more maps for multiple creates
-    Map<String, Object> properties = new LinkedHashMap<>();
-
-    // add properties to the request map
-    properties.put(ClusterStackVersionResourceProvider.CLUSTER_STACK_VERSION_CLUSTER_NAME_PROPERTY_ID, clusterName);
-    properties.put(ClusterStackVersionResourceProvider.CLUSTER_STACK_VERSION_STATE_PROPERTY_ID, "CURRENT");
-    properties.put(ClusterStackVersionResourceProvider.CLUSTER_STACK_VERSION_REPOSITORY_VERSION_PROPERTY_ID, "HDP-2.2.2.0-2561");
-
-    // create the request
-    Request request = PropertyHelper.getUpdateRequest(properties, null);
-
-    SecurityContextHolder.getContext().setAuthentication(authentication);
-
-    provider.updateResources(request, null);
-
-    // verify
-    verify(managementController, response);
-    Assert.assertEquals(capturedStackId.getValue(),
-            new StackId(newDesiredStack.getStackName(), newDesiredStack.getStackVersion()));
-  }
-
-   @Test
-   public void testUpdateResourcesWithForceAsAdministrator() throws Exception {
-     testUpdateResourcesWithForce(TestAuthenticationFactory.createAdministrator());
-   }
-
-   @Test
-   public void testUpdateResourcesWithForceAsClusterAdministrator() throws Exception {
-     testUpdateResourcesWithForce(TestAuthenticationFactory.createClusterAdministrator());
-   }
-
-   @Test(expected = AuthorizationException.class)
-   public void testUpdateResourcesWithForceAsClusterOperator() throws Exception {
-     testUpdateResourcesWithForce(TestAuthenticationFactory.createClusterOperator());
-   }
-
-   private void testUpdateResourcesWithForce(Authentication authentication) throws Exception {
-    Resource.Type type = Resource.Type.ClusterStackVersion;
-    String clusterName = "Cluster100";
-
-    AmbariManagementController managementController = createMock(AmbariManagementController.class);
-
-    StackId stackId = new StackId("HDP", "2.0.1");
-    StackEntity stackEntity = stackDAO.find(stackId.getStackName(), stackId.getStackVersion());
-    Assert.assertNotNull(stackEntity);
-
-    ResourceTypeEntity resourceTypeEntity = resourceTypeDAO.findById(ResourceType.CLUSTER.getId());
-    if (resourceTypeEntity == null) {
-      resourceTypeEntity = new ResourceTypeEntity();
-      resourceTypeEntity.setId(ResourceType.CLUSTER.getId());
-      resourceTypeEntity.setName(ResourceType.CLUSTER.name());
-      resourceTypeEntity = resourceTypeDAO.merge(resourceTypeEntity);
-    }
-    ResourceEntity resourceEntity = new ResourceEntity();
-    resourceEntity.setResourceType(resourceTypeEntity);
-
-    final Host host1 = createNiceMock("host1", Host.class);
-    final Host host2 = createNiceMock("host2", Host.class);
-
-    expect(host1.getHostName()).andReturn("host1").anyTimes();
-    expect(host2.getHostName()).andReturn("host2").anyTimes();
-    replay(host1, host2);
-
-    ServiceComponentHost sch = createMock(ServiceComponentHost.class);
-    List<ServiceComponentHost> schs = Collections.singletonList(sch);
-
-    Cluster cluster = createNiceMock(Cluster.class);
-    cluster.setClusterName(clusterName);
-
-    ArrayList<Host> hosts = new ArrayList<Host>() {{
-      add(host1);
-      add(host2);
-    }};
-
-    Clusters clusters = createNiceMock(Clusters.class);
-    expect(clusters.getCluster(anyObject(String.class))).andReturn(cluster);
-
-    RepositoryVersionEntity repoVersion = new RepositoryVersionEntity();
-    repoVersion.setOperatingSystems(OS_JSON);
-    StackEntity newDesiredStack = stackDAO.find("HDP", "2.0.1");
-    repoVersion.setStack(newDesiredStack);
-
-    final ServiceOsSpecific.Package hivePackage = new ServiceOsSpecific.Package();
-    hivePackage.setName("hive");
-    final ServiceOsSpecific.Package mysqlPackage = new ServiceOsSpecific.Package();
-    mysqlPackage.setName("mysql");
-    mysqlPackage.setSkipUpgrade(Boolean.TRUE);
-    List<ServiceOsSpecific.Package> packages = new ArrayList<ServiceOsSpecific.Package>() {{
-      add(hivePackage);
-      add(mysqlPackage);
-    }};
-
-    ActionManager actionManager = createNiceMock(ActionManager.class);
-
-    RequestStatusResponse response = createNiceMock(RequestStatusResponse.class);
-    ResourceProviderFactory resourceProviderFactory = createNiceMock(ResourceProviderFactory.class);
-    ResourceProvider csvResourceProvider = createNiceMock(ClusterStackVersionResourceProvider.class);
-
-    AbstractControllerResourceProvider.init(resourceProviderFactory);
-
-    Map<String, Map<String, String>> hostConfigTags = new HashMap<>();
-    expect(configHelper.getEffectiveDesiredTags(anyObject(ClusterImpl.class), anyObject(String.class))).andReturn(hostConfigTags);
-
-    expect(managementController.getClusters()).andReturn(clusters).anyTimes();
-    expect(managementController.getAmbariMetaInfo()).andReturn(ambariMetaInfo).anyTimes();
-    expect(managementController.getAuthName()).andReturn("admin").anyTimes();
-    expect(managementController.getActionManager()).andReturn(actionManager).anyTimes();
-    expect(managementController.getJdkResourceUrl()).andReturn("/JdkResourceUrl").anyTimes();
-    expect(managementController.getPackagesForServiceHost(anyObject(ServiceInfo.class),
-            (Map<String, String>) anyObject(List.class), anyObject(String.class))).andReturn(packages).anyTimes();
-
-    expect(resourceProviderFactory.getHostResourceProvider(anyObject(Set.class), anyObject(Map.class),
-            eq(managementController))).andReturn(csvResourceProvider).anyTimes();
-
-    expect(cluster.getCurrentStackVersion()).andReturn(stackId);
-    expect(cluster.getServiceComponentHosts(anyObject(String.class))).andReturn(schs).anyTimes();
-
-    RepositoryVersionEntity currentRepo = new RepositoryVersionEntity();
-    currentRepo.setVersion("2.2.2.0-2122");
-    ClusterVersionEntity current = new ClusterVersionEntity();
-    current.setRepositoryVersion(currentRepo);
-
-    Capture<StackId> capturedStackId = new Capture<>();
-    cluster.setDesiredStackVersion(capture(capturedStackId));
-      expectLastCall().once();
-    expect(cluster.getHosts()).andReturn(hosts).anyTimes();
-    expect(cluster.getCurrentClusterVersion()).andReturn(current).anyTimes();
-
-    expect(sch.getServiceName()).andReturn("HIVE").anyTimes();
-
-    expect(repositoryVersionDAOMock.findByDisplayName(anyObject(String.class))).andReturn(repoVersion);
-
-    clusterVersionDAO.updateVersions((Long) anyObject(),
-        (RepositoryVersionEntity) anyObject(), (RepositoryVersionEntity) anyObject());
-    expectLastCall().once();
-
-    hostVersionDAO.updateVersions((RepositoryVersionEntity) anyObject(), (RepositoryVersionEntity) anyObject());
-    expectLastCall().once();
-
-    hostComponentStateDAO.updateVersions((String) anyObject());
-    expectLastCall().once();
-
-    // replay
-    replay(managementController, response, clusters, resourceProviderFactory, csvResourceProvider,
-            cluster, repositoryVersionDAOMock, configHelper, sch, actionManager, clusterVersionDAO,
-            hostVersionDAO, hostComponentStateDAO);
-
-    ResourceProvider provider = AbstractControllerResourceProvider.getResourceProvider(
-            type,
-            PropertyHelper.getPropertyIds(type),
-            PropertyHelper.getKeyPropertyIds(type),
-            managementController);
-
-    injector.injectMembers(provider);
-
-
-    // add the property map to a set for the request.  add more maps for multiple creates
-    Map<String, Object> properties = new LinkedHashMap<>();
-
-    // add properties to the request map
-    properties.put(ClusterStackVersionResourceProvider.CLUSTER_STACK_VERSION_CLUSTER_NAME_PROPERTY_ID, clusterName);
-    properties.put(ClusterStackVersionResourceProvider.CLUSTER_STACK_VERSION_STATE_PROPERTY_ID, "CURRENT");
-    properties.put(ClusterStackVersionResourceProvider.CLUSTER_STACK_VERSION_REPOSITORY_VERSION_PROPERTY_ID, "HDP-2.2.2.0-2561");
-    properties.put(ClusterStackVersionResourceProvider.CLUSTER_STACK_VERSION_FORCE, "true");
-
-    // create the request
-    Request request = PropertyHelper.getUpdateRequest(properties, null);
-
-    SecurityContextHolder.getContext().setAuthentication(authentication);
-
-    provider.updateResources(request, null);
-
-    // verify
-    verify(managementController, response, clusterVersionDAO, hostVersionDAO, hostComponentStateDAO);
-    Assert.assertEquals(capturedStackId.getValue(),
-            new StackId(newDesiredStack.getStackName(), newDesiredStack.getStackVersion()));
+    Assert.assertNotNull(executionCommand.getRepositoryFile());
+    Assert.assertEquals(0, executionCommand.getRepositoryFile().getRepositories().size());
   }
 
    @Test
@@ -1428,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);
     }
 
@@ -1482,11 +1178,11 @@ public class ClusterStackVersionResourceProviderTest {
     expect(managementController.getActionManager()).andReturn(actionManager).anyTimes();
     expect(managementController.getJdkResourceUrl()).andReturn("/JdkResourceUrl").anyTimes();
     expect(managementController.getPackagesForServiceHost(anyObject(ServiceInfo.class),
-            (Map<String, String>) anyObject(List.class), anyObject(String.class))).
+            EasyMock.<Map<String, String>>anyObject(), anyObject(String.class))).
             andReturn(packages).times((hostCount - 1) * 2); // 1 host has no versionable components, other hosts have 2 services
 //            // that's why we don't send commands to it
 
-    expect(resourceProviderFactory.getHostResourceProvider(anyObject(Set.class), anyObject(Map.class),
+    expect(resourceProviderFactory.getHostResourceProvider(EasyMock.<Set<String>>anyObject(), EasyMock.<Map<Resource.Type, String>>anyObject(),
             eq(managementController))).andReturn(csvResourceProvider).anyTimes();
 
     expect(clusters.getCluster(anyObject(String.class))).andReturn(cluster);
@@ -1510,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);
 
@@ -1539,27 +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);
 
-    StageUtils.setTopologyManager(injector.getInstance(TopologyManager.class));
+    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.<ClusterVersionEntity>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,
@@ -1629,13 +1321,20 @@ 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);
     repoVersionEntity.setVersionXml(IOUtils.toString(new FileInputStream(f)));
     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<>();
     List<HostVersionEntity> hostVersionEntitiesMergedWithNotRequired = new ArrayList<>();
     int hostCount = 10;
@@ -1651,6 +1350,8 @@ public class ClusterStackVersionResourceProviderTest {
       // transition correct into the not required state
       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();
 
@@ -1699,11 +1400,11 @@ public class ClusterStackVersionResourceProviderTest {
     expect(managementController.getAuthName()).andReturn("admin").anyTimes();
     expect(managementController.getJdkResourceUrl()).andReturn("/JdkResourceUrl").anyTimes();
     expect(managementController.getPackagesForServiceHost(anyObject(ServiceInfo.class),
-        (Map<String, String>) anyObject(List.class), anyObject(String.class))).andReturn(
+        EasyMock.<Map<String, String>>anyObject(), anyObject(String.class))).andReturn(
             packages).anyTimes(); // only one host has the versionable component
 
-    expect(resourceProviderFactory.getHostResourceProvider(anyObject(Set.class),
-        anyObject(Map.class), eq(managementController))).andReturn(csvResourceProvider).anyTimes();
+    expect(resourceProviderFactory.getHostResourceProvider(EasyMock.<Set<String>>anyObject(),
+        EasyMock.<Map<Resource.Type, String>>anyObject(), eq(managementController))).andReturn(csvResourceProvider).anyTimes();
 
     expect(clusters.getCluster(anyObject(String.class))).andReturn(cluster);
     expect(clusters.getHostsForCluster(anyObject(String.class))).andReturn(
@@ -1711,43 +1412,29 @@ 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(serviceComponentHosts).anyTimes();
-    expect(cluster.getCurrentStackVersion()).andReturn(stackId).atLeastOnce();
+    expect(cluster.getServiceComponentHosts(anyObject(String.class))).andReturn(
+        serviceComponentHosts).anyTimes();
 
     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(clusterVersionDAO.findByClusterAndStackAndVersion(anyObject(String.class),
-        anyObject(StackId.class), anyObject(String.class))).andReturn(cve).once();
 
     // now the important expectations - that the cluster transition methods were
     // called correctly
-    cluster.transitionHosts(cve, RepositoryVersionState.INSTALLED);
-    for (HostVersionEntity hostVersionEntity : hostVersionEntitiesMergedWithNotRequired) {
-      expect(hostVersionDAO.merge(hostVersionEntity)).andReturn(hostVersionEntity).once();
-    }
+    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),
@@ -1861,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/48f7fb22/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 b9b8d2a..a4cc6fc 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
@@ -37,6 +37,7 @@ import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.UUID;
 
 import javax.persistence.EntityManager;
 
@@ -73,9 +74,11 @@ import org.apache.ambari.server.state.Host;
 import org.apache.ambari.server.state.HostConfig;
 import org.apache.ambari.server.state.HostHealthStatus;
 import org.apache.ambari.server.state.HostHealthStatus.HealthStatus;
+import org.apache.ambari.server.state.HostState;
 import org.apache.ambari.server.state.MaintenanceState;
 import org.apache.ambari.server.state.ServiceComponentHost;
 import org.apache.ambari.server.state.stack.OsFamily;
+import org.apache.ambari.server.topology.LogicalRequest;
 import org.apache.ambari.server.topology.TopologyManager;
 import org.easymock.EasyMock;
 import org.easymock.EasyMockSupport;
@@ -130,8 +133,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();
@@ -155,13 +156,13 @@ public class HostResourceProviderTest extends EasyMockSupport {
         managementController);
 
     // add the property map to a set for the request.  add more maps for multiple creates
-    Set<Map<String, Object>> propertySet = new LinkedHashSet<Map<String, Object>>();
+    Set<Map<String, Object>> propertySet = new LinkedHashSet<>();
 
-    Map<String, Object> properties = new LinkedHashMap<String, Object>();
+    Map<String, Object> properties = new LinkedHashMap<>();
 
     // add properties to the request map
     properties.put(HostResourceProvider.HOST_CLUSTER_NAME_PROPERTY_ID, "Cluster100");
-    properties.put(HostResourceProvider.HOST_NAME_PROPERTY_ID, "Host100");
+    properties.put(HostResourceProvider.HOST_HOST_NAME_PROPERTY_ID, "Host100");
 
     propertySet.add(properties);
 
@@ -206,12 +207,12 @@ public class HostResourceProviderTest extends EasyMockSupport {
 
     AbstractControllerResourceProvider.init(resourceProviderFactory);
 
-    List<Host> hosts = new LinkedList<Host>();
+    List<Host> hosts = new LinkedList<>();
     hosts.add(host100);
     hosts.add(host101);
     hosts.add(host102);
 
-    Set<Cluster> clusterSet = new HashSet<Cluster>();
+    Set<Cluster> clusterSet = new HashSet<>();
     clusterSet.add(cluster);
 
     // set expectations
@@ -240,10 +241,10 @@ public class HostResourceProviderTest extends EasyMockSupport {
     expect(healthStatus.getHealthStatus()).andReturn(HostHealthStatus.HealthStatus.HEALTHY).anyTimes();
     expect(healthStatus.getHealthReport()).andReturn("HEALTHY").anyTimes();
 
-    Set<String> propertyIds = new HashSet<String>();
+    Set<String> propertyIds = new HashSet<>();
 
     propertyIds.add(HostResourceProvider.HOST_CLUSTER_NAME_PROPERTY_ID);
-    propertyIds.add(HostResourceProvider.HOST_NAME_PROPERTY_ID);
+    propertyIds.add(HostResourceProvider.HOST_HOST_NAME_PROPERTY_ID);
     propertyIds.add(HostResourceProvider.HOST_MAINTENANCE_STATE_PROPERTY_ID);
 
     Predicate predicate = buildPredicate("Cluster100", null);
@@ -296,17 +297,17 @@ public class HostResourceProviderTest extends EasyMockSupport {
 
     AbstractControllerResourceProvider.init(resourceProviderFactory);
 
-    Set<Cluster> clusterSet = new HashSet<Cluster>();
+    Set<Cluster> clusterSet = new HashSet<>();
     clusterSet.add(cluster);
 
     ServiceComponentHostResponse shr1 = new ServiceComponentHostResponse("Cluster100", "Service100", "Component100", "Component 100",
-        "Host100", "Host100", "STARTED", "", null, null, null);
+        "Host100", "Host100", "STARTED", "", null, null, null, null);
     ServiceComponentHostResponse shr2 = new ServiceComponentHostResponse("Cluster100", "Service100", "Component102", "Component 102",
-        "Host100", "Host100", "STARTED", "", null, null, null);
+        "Host100", "Host100", "STARTED", "", null, null, null, null);
     ServiceComponentHostResponse shr3 = new ServiceComponentHostResponse("Cluster100", "Service100", "Component103", "Component 103",
-        "Host100", "Host100", "STARTED", "", null, null, null);
+        "Host100", "Host100", "STARTED", "", null, null, null, null);
 
-    Set<ServiceComponentHostResponse> responses = new HashSet<ServiceComponentHostResponse>();
+    Set<ServiceComponentHostResponse> responses = new HashSet<>();
     responses.add(shr1);
     responses.add(shr2);
     responses.add(shr3);
@@ -328,11 +329,8 @@ public class HostResourceProviderTest extends EasyMockSupport {
 
     expect(hostResponse1.getClusterName()).andReturn("").anyTimes();
     expect(hostResponse1.getHostname()).andReturn("Host100").anyTimes();
-    expect(hostResponse1.getHealthStatus()).andReturn(healthStatus).anyTimes();
     expect(hostResponse1.getStatus()).andReturn(HealthStatus.HEALTHY.name()).anyTimes();
-
-    expect(healthStatus.getHealthStatus()).andReturn(HostHealthStatus.HealthStatus.HEALTHY).anyTimes();
-    expect(healthStatus.getHealthReport()).andReturn("HEALTHY").anyTimes();
+    expect(hostResponse1.getHealthReport()).andReturn("HEALTHY").anyTimes();
 
 
     expect(ambariMetaInfo.getComponent((String) anyObject(), (String) anyObject(),
@@ -344,10 +342,10 @@ public class HostResourceProviderTest extends EasyMockSupport {
         EasyMock.<Map<Resource.Type, String>>anyObject(),
         eq(managementController))).andReturn(hostResourceProvider).anyTimes();
 
-    Set<String> propertyIds = new HashSet<String>();
+    Set<String> propertyIds = new HashSet<>();
 
     propertyIds.add(HostResourceProvider.HOST_CLUSTER_NAME_PROPERTY_ID);
-    propertyIds.add(HostResourceProvider.HOST_NAME_PROPERTY_ID);
+    propertyIds.add(HostResourceProvider.HOST_HOST_NAME_PROPERTY_ID);
     propertyIds.add(HostResourceProvider.HOST_HOST_STATUS_PROPERTY_ID);
 
     Predicate predicate = buildPredicate("Cluster100", null);
@@ -397,17 +395,17 @@ public class HostResourceProviderTest extends EasyMockSupport {
 
     AbstractControllerResourceProvider.init(resourceProviderFactory);
 
-    Set<Cluster> clusterSet = new HashSet<Cluster>();
+    Set<Cluster> clusterSet = new HashSet<>();
     clusterSet.add(cluster);
 
     ServiceComponentHostResponse shr1 = new ServiceComponentHostResponse("Cluster100", "Service100", "Component100", "Component 100",
-        "Host100", "Host100", "STARTED", "", null, null, null);
+        "Host100", "Host100", "STARTED", "", null, null, null, null);
     ServiceComponentHostResponse shr2 = new ServiceComponentHostResponse("Cluster100", "Service100", "Component102", "Component 102",
-        "Host100", "Host100", "STARTED", "", null, null, null);
+        "Host100", "Host100", "STARTED", "", null, null, null, null);
     ServiceComponentHostResponse shr3 = new ServiceComponentHostResponse("Cluster100", "Service100", "Component103", "Component 103",
-        "Host100", "Host100", "STARTED", "", null, null, null);
+        "Host100", "Host100", "STARTED", "", null, null, null, null);
 
-    Set<ServiceComponentHostResponse> responses = new HashSet<ServiceComponentHostResponse>();
+    Set<ServiceComponentHostResponse> responses = new HashSet<>();
     responses.add(shr1);
     responses.add(shr2);
     responses.add(shr3);
@@ -439,10 +437,10 @@ public class HostResourceProviderTest extends EasyMockSupport {
         EasyMock.<Map<Resource.Type, String>>anyObject(),
         eq(managementController))).andReturn(hostResourceProvider).anyTimes();
 
-    Set<String> propertyIds = new HashSet<String>();
+    Set<String> propertyIds = new HashSet<>();
 
     propertyIds.add(HostResourceProvider.HOST_CLUSTER_NAME_PROPERTY_ID);
-    propertyIds.add(HostResourceProvider.HOST_NAME_PROPERTY_ID);
+    propertyIds.add(HostResourceProvider.HOST_HOST_NAME_PROPERTY_ID);
     propertyIds.add(HostResourceProvider.HOST_HOST_STATUS_PROPERTY_ID);
 
     Predicate predicate = buildPredicate("Cluster100", null);
@@ -482,7 +480,6 @@ public class HostResourceProviderTest extends EasyMockSupport {
     AmbariManagementController managementController = injector.getInstance(AmbariManagementController.class);
     Clusters clusters = injector.getInstance(Clusters.class);
     Cluster cluster = createMock(Cluster.class);
-    HostHealthStatus healthStatus = createNiceMock(HostHealthStatus.class);
     AmbariMetaInfo ambariMetaInfo = createNiceMock(AmbariMetaInfo.class);
     ComponentInfo componentInfo = createNiceMock(ComponentInfo.class);
     HostResponse hostResponse1 = createNiceMock(HostResponse.class);
@@ -493,17 +490,17 @@ public class HostResourceProviderTest extends EasyMockSupport {
 
     AbstractControllerResourceProvider.init(resourceProviderFactory);
 
-    Set<Cluster> clusterSet = new HashSet<Cluster>();
+    Set<Cluster> clusterSet = new HashSet<>();
     clusterSet.add(cluster);
 
     ServiceComponentHostResponse shr1 = new ServiceComponentHostResponse("Cluster100", "Service100", "Component100", "Component 100",
-        "Host100", "Host100", "STARTED", "", null, null, null);
+        "Host100", "Host100", "STARTED", "", null, null, null, null);
     ServiceComponentHostResponse shr2 = new ServiceComponentHostResponse("Cluster100", "Service100", "Component102", "Component 102",
-        "Host100", "Host100", "INSTALLED", "", null, null, null);
+        "Host100", "Host100", "INSTALLED", "", null, null, null, null);
     ServiceComponentHostResponse shr3 = new ServiceComponentHostResponse("Cluster100", "Service100", "Component103", "Component 103",
-        "Host100", "Host100", "STARTED", "", null, null, null);
+        "Host100", "Host100", "STARTED", "", null, null, null, null);
 
-    Set<ServiceComponentHostResponse> responses = new HashSet<ServiceComponentHostResponse>();
+    Set<ServiceComponentHostResponse> responses = new HashSet<>();
     responses.add(shr1);
     responses.add(shr2);
     responses.add(shr3);
@@ -525,11 +522,8 @@ public class HostResourceProviderTest extends EasyMockSupport {
 
     expect(hostResponse1.getClusterName()).andReturn("Cluster100").anyTimes();
     expect(hostResponse1.getHostname()).andReturn("Host100").anyTimes();
-    expect(hostResponse1.getHealthStatus()).andReturn(healthStatus).anyTimes();
     expect(hostResponse1.getStatus()).andReturn(HealthStatus.UNHEALTHY.name()).anyTimes();
-
-    expect(healthStatus.getHealthStatus()).andReturn(HostHealthStatus.HealthStatus.HEALTHY).anyTimes();
-    expect(healthStatus.getHealthReport()).andReturn("HEALTHY").anyTimes();
+    expect(hostResponse1.getHealthReport()).andReturn("HEALTHY").anyTimes();
 
     expect(ambariMetaInfo.getComponent((String) anyObject(), (String) anyObject(),
         (String) anyObject(), (String) anyObject())).andReturn(componentInfo).anyTimes();
@@ -540,10 +534,10 @@ public class HostResourceProviderTest extends EasyMockSupport {
         EasyMock.<Map<Resource.Type, String>>anyObject(),
         eq(managementController))).andReturn(hostResourceProvider).anyTimes();
 
-    Set<String> propertyIds = new HashSet<String>();
+    Set<String> propertyIds = new HashSet<>();
 
     propertyIds.add(HostResourceProvider.HOST_CLUSTER_NAME_PROPERTY_ID);
-    propertyIds.add(HostResourceProvider.HOST_NAME_PROPERTY_ID);
+    propertyIds.add(HostResourceProvider.HOST_HOST_NAME_PROPERTY_ID);
     propertyIds.add(HostResourceProvider.HOST_HOST_STATUS_PROPERTY_ID);
 
     Predicate predicate = buildPredicate("Cluster100", null);
@@ -582,7 +576,6 @@ public class HostResourceProviderTest extends EasyMockSupport {
     AmbariManagementController managementController = injector.getInstance(AmbariManagementController.class);
     Clusters clusters = injector.getInstance(Clusters.class);
     Cluster cluster = createMock(Cluster.class);
-    HostHealthStatus healthStatus = createNiceMock(HostHealthStatus.class);
     AmbariMetaInfo ambariMetaInfo = createNiceMock(AmbariMetaInfo.class);
     HostResponse hostResponse1 = createNiceMock(HostResponse.class);
     ResourceProviderFactory resourceProviderFactory = createNiceMock(ResourceProviderFactory.class);
@@ -609,19 +602,16 @@ public class HostResourceProviderTest extends EasyMockSupport {
 
     expect(hostResponse1.getClusterName()).andReturn("Cluster100").anyTimes();
     expect(hostResponse1.getHostname()).andReturn("Host100").anyTimes();
-    expect(hostResponse1.getHealthStatus()).andReturn(healthStatus).anyTimes();
     expect(hostResponse1.getStatus()).andReturn(HealthStatus.UNKNOWN.name()).anyTimes();
-
-    expect(healthStatus.getHealthStatus()).andReturn(HostHealthStatus.HealthStatus.UNKNOWN).anyTimes();
-    expect(healthStatus.getHealthReport()).andReturn("UNKNOWN").anyTimes();
+    expect(hostResponse1.getHealthReport()).andReturn("UNKNOWN").anyTimes();
     expect(resourceProviderFactory.getHostResourceProvider(EasyMock.<Set<String>>anyObject(),
         EasyMock.<Map<Resource.Type, String>>anyObject(),
         eq(managementController))).andReturn(hostResourceProvider).anyTimes();
 
-    Set<String> propertyIds = new HashSet<String>();
+    Set<String> propertyIds = new HashSet<>();
 
     propertyIds.add(HostResourceProvider.HOST_CLUSTER_NAME_PROPERTY_ID);
-    propertyIds.add(HostResourceProvider.HOST_NAME_PROPERTY_ID);
+    propertyIds.add(HostResourceProvider.HOST_HOST_NAME_PROPERTY_ID);
     propertyIds.add(HostResourceProvider.HOST_HOST_STATUS_PROPERTY_ID);
 
     Predicate predicate = buildPredicate("Cluster100", null);
@@ -681,7 +671,7 @@ public class HostResourceProviderTest extends EasyMockSupport {
 
     RecoveryReport rr = new RecoveryReport();
     rr.setSummary("RECOVERABLE");
-    List<ComponentRecoveryReport> compRecReports = new ArrayList<ComponentRecoveryReport>();
+    List<ComponentRecoveryReport> compRecReports = new ArrayList<>();
     ComponentRecoveryReport compRecReport = new ComponentRecoveryReport();
     compRecReport.setLimitReached(Boolean.FALSE);
     compRecReport.setName("DATANODE");
@@ -693,13 +683,13 @@ public class HostResourceProviderTest extends EasyMockSupport {
 
     AbstractControllerResourceProvider.init(resourceProviderFactory);
 
-    Set<Cluster> clusterSet = new HashSet<Cluster>();
+    Set<Cluster> clusterSet = new HashSet<>();
     clusterSet.add(cluster);
 
     ServiceComponentHostResponse shr1 = new ServiceComponentHostResponse("Cluster100", "Service100", "Component100", "Component 100",
-        "Host100", "Host100", "STARTED", "", null, null, null);
+        "Host100", "Host100", "STARTED", "", null, null, null, null);
 
-    Set<ServiceComponentHostResponse> responses = new HashSet<ServiceComponentHostResponse>();
+    Set<ServiceComponentHostResponse> responses = new HashSet<>();
     responses.add(shr1);
 
     // set expectations
@@ -723,10 +713,10 @@ public class HostResourceProviderTest extends EasyMockSupport {
         eq(managementController))).andReturn(hostResourceProvider).anyTimes();
 
 
-    Set<String> propertyIds = new HashSet<String>();
+    Set<String> propertyIds = new HashSet<>();
 
     propertyIds.add(HostResourceProvider.HOST_CLUSTER_NAME_PROPERTY_ID);
-    propertyIds.add(HostResourceProvider.HOST_NAME_PROPERTY_ID);
+    propertyIds.add(HostResourceProvider.HOST_HOST_NAME_PROPERTY_ID);
     propertyIds.add(HostResourceProvider.HOST_RECOVERY_REPORT_PROPERTY_ID);
     propertyIds.add(HostResourceProvider.HOST_RECOVERY_SUMMARY_PROPERTY_ID);
 
@@ -780,17 +770,17 @@ public class HostResourceProviderTest extends EasyMockSupport {
     Host host100 = createMockHost("Host100", "Cluster100", null, "ALERT", "RECOVERABLE", null);
 
     AbstractControllerResourceProvider.init(resourceProviderFactory);
-    Set<Cluster> clusterSet = new HashSet<Cluster>();
+    Set<Cluster> clusterSet = new HashSet<>();
     clusterSet.add(cluster);
 
     ServiceComponentHostResponse shr1 = new ServiceComponentHostResponse("Cluster100", "Service100", "Component100", "Component 100",
-        "Host100", "Host100", "STARTED", "", null, null, null);
+        "Host100", "Host100", "STARTED", "", null, null, null, null);
     ServiceComponentHostResponse shr2 = new ServiceComponentHostResponse("Cluster100", "Service100", "Component102", "Component 102",
-        "Host100", "Host100", "INSTALLED", "", null, null, null);
+        "Host100", "Host100", "INSTALLED", "", null, null, null, null);
     ServiceComponentHostResponse shr3 = new ServiceComponentHostResponse("Cluster100", "Service100", "Component103", "Component 103",
-        "Host100", "Host100", "STARTED", "", null, null, null);
+        "Host100", "Host100", "STARTED", "", null, null, null, null);
 
-    Set<ServiceComponentHostResponse> responses = new HashSet<ServiceComponentHostResponse>();
+    Set<ServiceComponentHostResponse> responses = new HashSet<>();
     responses.add(shr1);
     responses.add(shr2);
     responses.add(shr3);
@@ -809,10 +799,8 @@ public class HostResourceProviderTest extends EasyMockSupport {
     expect(cluster.getDesiredConfigs()).andReturn(new HashMap<String, DesiredConfig>()).anyTimes();
     expect(hostResponse1.getClusterName()).andReturn("Cluster100").anyTimes();
     expect(hostResponse1.getHostname()).andReturn("Host100").anyTimes();
-    expect(hostResponse1.getHealthStatus()).andReturn(healthStatus).anyTimes();
     expect(hostResponse1.getStatus()).andReturn(HealthStatus.ALERT.name()).anyTimes();
-    expect(healthStatus.getHealthStatus()).andReturn(HostHealthStatus.HealthStatus.HEALTHY).anyTimes();
-    expect(healthStatus.getHealthReport()).andReturn("HEALTHY").anyTimes();
+    expect(hostResponse1.getHealthReport()).andReturn("HEALTHY").anyTimes();
     expect(ambariMetaInfo.getComponent((String) anyObject(), (String) anyObject(),
         (String) anyObject(), (String) anyObject())).andReturn(componentInfo).anyTimes();
     expect(componentInfo.getCategory()).andReturn("SLAVE").anyTimes();
@@ -821,10 +809,10 @@ public class HostResourceProviderTest extends EasyMockSupport {
         eq(managementController))).andReturn(hostResourceProvider).anyTimes();
 
 
-    Set<String> propertyIds = new HashSet<String>();
+    Set<String> propertyIds = new HashSet<>();
 
     propertyIds.add(HostResourceProvider.HOST_CLUSTER_NAME_PROPERTY_ID);
-    propertyIds.add(HostResourceProvider.HOST_NAME_PROPERTY_ID);
+    propertyIds.add(HostResourceProvider.HOST_HOST_NAME_PROPERTY_ID);
     propertyIds.add(HostResourceProvider.HOST_HOST_STATUS_PROPERTY_ID);
 
     Predicate predicate = buildPredicate("Cluster100", null);
@@ -882,7 +870,6 @@ public class HostResourceProviderTest extends EasyMockSupport {
     AmbariManagementController managementController = injector.getInstance(AmbariManagementController.class);
     Clusters clusters = injector.getInstance(Clusters.class);
     Cluster cluster = createMock(Cluster.class);
-    HostHealthStatus healthStatus = createNiceMock(HostHealthStatus.class);
     AmbariMetaInfo ambariMetaInfo = createNiceMock(AmbariMetaInfo.class);
     HostResponse hostResponse1 = createNiceMock(HostResponse.class);
     ResourceProviderFactory resourceProviderFactory = createNiceMock(ResourceProviderFactory.class);
@@ -907,16 +894,12 @@ 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();
     expect(hostResponse1.getClusterName()).andReturn("Cluster100").anyTimes();
     expect(hostResponse1.getHostname()).andReturn("Host100").anyTimes();
-    expect(hostResponse1.getHealthStatus()).andReturn(healthStatus).anyTimes();
-    expect(healthStatus.getHealthStatus()).andReturn(HostHealthStatus.HealthStatus.HEALTHY).anyTimes();
-    expect(healthStatus.getHealthReport()).andReturn("HEALTHY").anyTimes();
+    expect(hostResponse1.getHealthReport()).andReturn("HEALTHY").anyTimes();
     expect(resourceProviderFactory.getHostResourceProvider(EasyMock.<Set<String>>anyObject(),
         EasyMock.<Map<Resource.Type, String>>anyObject(),
         eq(managementController))).andReturn(hostResourceProvider).anyTimes();
@@ -926,10 +909,10 @@ public class HostResourceProviderTest extends EasyMockSupport {
 
     SecurityContextHolder.getContext().setAuthentication(authentication);
 
-    Map<String, Object> properties = new LinkedHashMap<String, Object>();
+    Map<String, Object> properties = new LinkedHashMap<>();
 
     properties.put(HostResourceProvider.HOST_CLUSTER_NAME_PROPERTY_ID, "Cluster100");
-    properties.put(HostResourceProvider.HOST_NAME_PROPERTY_ID, "Host100");
+    properties.put(HostResourceProvider.HOST_HOST_NAME_PROPERTY_ID, "Host100");
     properties.put(PropertyHelper.getPropertyId("Hosts.desired_config", "type"), "global");
     properties.put(PropertyHelper.getPropertyId("Hosts.desired_config", "tag"), "version1");
     properties.put(PropertyHelper.getPropertyId("Hosts.desired_config.properties", "a"), "b");
@@ -974,7 +957,6 @@ public class HostResourceProviderTest extends EasyMockSupport {
     AmbariManagementController managementController = injector.getInstance(AmbariManagementController.class);
     Clusters clusters = injector.getInstance(Clusters.class);
     Cluster cluster = createMock(Cluster.class);
-    HostHealthStatus healthStatus = createNiceMock(HostHealthStatus.class);
     AmbariMetaInfo ambariMetaInfo = createNiceMock(AmbariMetaInfo.class);
     HostResponse hostResponse1 = createNiceMock(HostResponse.class);
     ResourceProviderFactory resourceProviderFactory = createNiceMock(ResourceProviderFactory.class);
@@ -982,7 +964,7 @@ public class HostResourceProviderTest extends EasyMockSupport {
 
     AbstractControllerResourceProvider.init(resourceProviderFactory);
 
-    Set<Cluster> clusterSet = new HashSet<Cluster>();
+    Set<Cluster> clusterSet = new HashSet<>();
     clusterSet.add(cluster);
 
     Host host100 = createMockHost("Host100", "Cluster100", null, "HEALTHY", "RECOVERABLE", null);
@@ -1000,16 +982,12 @@ 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();
     expect(hostResponse1.getClusterName()).andReturn("Cluster100").anyTimes();
     expect(hostResponse1.getHostname()).andReturn("Host100").anyTimes();
-    expect(hostResponse1.getHealthStatus()).andReturn(healthStatus).anyTimes();
-    expect(healthStatus.getHealthStatus()).andReturn(HostHealthStatus.HealthStatus.HEALTHY).anyTimes();
-    expect(healthStatus.getHealthReport()).andReturn("HEALTHY").anyTimes();
+    expect(hostResponse1.getHealthReport()).andReturn("HEALTHY").anyTimes();
     expect(resourceProviderFactory.getHostResourceProvider(EasyMock.<Set<String>>anyObject(),
         EasyMock.<Map<Resource.Type, String>>anyObject(),
         eq(managementController))).andReturn(hostResourceProvider).anyTimes();
@@ -1026,7 +1004,7 @@ public class HostResourceProviderTest extends EasyMockSupport {
         managementController);
 
     // add the property map to a set for the request.
-    Map<String, Object> properties = new LinkedHashMap<String, Object>();
+    Map<String, Object> properties = new LinkedHashMap<>();
 
     properties.put(HostResourceProvider.HOST_RACK_INFO_PROPERTY_ID, "rack info");
 
@@ -1075,16 +1053,15 @@ public class HostResourceProviderTest extends EasyMockSupport {
     expect(clusters.getHost("Host100")).andReturn(host1).anyTimes();
     expect(clusters.getCluster("Cluster100")).andReturn(cluster).anyTimes();
     expect(clusters.getClustersForHost("Host100")).andReturn(clusterSet).anyTimes();
-    expect(cluster.getServiceComponentHosts("Host100")).andReturn(Collections.EMPTY_LIST);
+    expect(cluster.getServiceComponentHosts("Host100")).andReturn(Collections.<ServiceComponentHost>emptyList());
     expect(cluster.getClusterId()).andReturn(100L).anyTimes();
     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();
-    expect(topologyManager.getRequests(Collections.EMPTY_LIST)).andReturn(Collections.EMPTY_LIST).anyTimes();
+    expect(topologyManager.getRequests(Collections.<Long>emptyList())).andReturn(Collections.<LogicalRequest>emptyList()).anyTimes();
 
     // replay
     replayAll();
@@ -1144,9 +1121,11 @@ public class HostResourceProviderTest extends EasyMockSupport {
     HostResponse response = createNiceMock(HostResponse.class);
 
     Set<Cluster> setCluster = Collections.singleton(cluster);
+    Map<String, DesiredConfig> desiredConfigs = new HashMap<>();
+    Map<String, HostConfig> desiredHostConfigs = new HashMap<>();
 
     // requests
-    HostRequest request1 = new HostRequest("host1", "cluster1", Collections.<String, String>emptyMap());
+    HostRequest request1 = new HostRequest("host1", "cluster1");
 
     Set<HostRequest> setRequests = new HashSet<>();
     setRequests.add(request1);
@@ -1159,7 +1138,8 @@ public class HostResourceProviderTest extends EasyMockSupport {
     expect(clusters.getClustersForHost("host1")).andReturn(setCluster);
     expect(clusters.getCluster("Cluster100")).andReturn(cluster).anyTimes();
     expect(cluster.getClusterId()).andReturn(2L).anyTimes();
-    expect(cluster.getDesiredConfigs()).andReturn(new HashMap<String, DesiredConfig>()).anyTimes();
+    expect(cluster.getDesiredConfigs()).andReturn(desiredConfigs);
+    expect(host.getDesiredHostConfigs(cluster, desiredConfigs)).andReturn(desiredHostConfigs);
     expect(host.getHostName()).andReturn("host1").anyTimes();
     expect(host.convertToResponse()).andReturn(response);
     response.setClusterName("cluster1");
@@ -1192,7 +1172,7 @@ public class HostResourceProviderTest extends EasyMockSupport {
     Cluster cluster = createMock(Cluster.class);
 
     // requests
-    HostRequest request1 = new HostRequest("host1", "cluster1", Collections.<String, String>emptyMap());
+    HostRequest request1 = new HostRequest("host1", "cluster1");
     Set<HostRequest> setRequests = Collections.singleton(request1);
 
     // expectations
@@ -1223,7 +1203,7 @@ public class HostResourceProviderTest extends EasyMockSupport {
     Host host = createNiceMock(Host.class);
 
     // requests
-    HostRequest request1 = new HostRequest("host1", "cluster1", Collections.<String, String>emptyMap());
+    HostRequest request1 = new HostRequest("host1", "cluster1");
     Set<HostRequest> setRequests = Collections.singleton(request1);
 
     // expectations
@@ -1263,12 +1243,12 @@ public class HostResourceProviderTest extends EasyMockSupport {
     HostResponse response2 = createNiceMock(HostResponse.class);
 
     // requests
-    HostRequest request1 = new HostRequest("host1", "cluster1", Collections.<String, String>emptyMap());
-    HostRequest request2 = new HostRequest("host2", "cluster1", Collections.<String, String>emptyMap());
-    HostRequest request3 = new HostRequest("host3", "cluster1", Collections.<String, String>emptyMap());
-    HostRequest request4 = new HostRequest("host4", "cluster1", Collections.<String, String>emptyMap());
+    HostRequest request1 = new HostRequest("host1", "cluster1");
+    HostRequest request2 = new HostRequest("host2", "cluster1");
+    HostRequest request3 = new HostRequest("host3", "cluster1");
+    HostRequest request4 = new HostRequest("host4", "cluster1");
 
-    Set<HostRequest> setRequests = new HashSet<HostRequest>();
+    Set<HostRequest> setRequests = new HashSet<>();
     setRequests.add(request1);
     setRequests.add(request2);
     setRequests.add(request3);
@@ -1316,14 +1296,18 @@ public class HostResourceProviderTest extends EasyMockSupport {
 
   public static void createHosts(AmbariManagementController controller, Set<HostRequest> requests) throws AmbariException {
     HostResourceProvider provider = getHostProvider(controller);
-    Set<Map<String, Object>> properties = new HashSet<Map<String, Object>>();
+    Set<Map<String, Object>> properties = new HashSet<>();
 
     for (HostRequest request : requests) {
-      Map<String, Object> requestProperties = new HashMap<String, Object>();
-      requestProperties.put(HostResourceProvider.HOST_NAME_PROPERTY_ID, request.getHostname());
+      Map<String, Object> requestProperties = new HashMap<>();
+      requestProperties.put(HostResourceProvider.HOST_HOST_NAME_PROPERTY_ID, request.getHostname());
       requestProperties.put(HostResourceProvider.HOST_CLUSTER_NAME_PROPERTY_ID, request.getClusterName());
+      if (null != request.getRackInfo()) {
+        requestProperties.put(HostResourceProvider.HOST_RACK_INFO_PROPERTY_ID, UUID.randomUUID().toString());
+      }
       properties.add(requestProperties);
     }
+
     provider.createHosts(PropertyHelper.getCreateRequest(properties, Collections.<String, String>emptyMap()));
   }
 
@@ -1336,7 +1320,7 @@ public class HostResourceProviderTest extends EasyMockSupport {
   public static void deleteHosts(AmbariManagementController controller, Set<HostRequest> requests)
       throws AmbariException {
     TopologyManager topologyManager = EasyMock.createNiceMock(TopologyManager.class);
-    expect(topologyManager.getRequests(Collections.EMPTY_LIST)).andReturn(Collections.EMPTY_LIST).anyTimes();
+    expect(topologyManager.getRequests(Collections.<Long>emptyList())).andReturn(Collections.<LogicalRequest>emptyList()).anyTimes();
 
     replay(topologyManager);
 
@@ -1349,7 +1333,7 @@ public class HostResourceProviderTest extends EasyMockSupport {
                                                  Set<HostRequest> requests, boolean dryRun, boolean forceDelete)
       throws AmbariException {
     TopologyManager topologyManager = EasyMock.createNiceMock(TopologyManager.class);
-    expect(topologyManager.getRequests(Collections.EMPTY_LIST)).andReturn(Collections.EMPTY_LIST).anyTimes();
+    expect(topologyManager.getRequests(Collections.<Long>emptyList())).andReturn(Collections.<LogicalRequest>emptyList()).anyTimes();
 
     replay(topologyManager);
 
@@ -1408,8 +1392,8 @@ public class HostResourceProviderTest extends EasyMockSupport {
                               String status, String recoverySummary, RecoveryReport recoveryReport) {
     Host host = createMock(Host.class);
     HostHealthStatus hostHealthStatus = new HostHealthStatus(HealthStatus.HEALTHY, "");
-    HostResponse hostResponse = new HostResponse(hostName, clusterName, null, null, 1, 1, null,
-        "centos6", null, 1024, 1024, null, 1, 1, null, null, null, hostHealthStatus, "HEALTHY", status);
+    HostResponse hostResponse = new HostResponse(hostName, clusterName, null, 1, 1, null,
+        "centos6", 1024, null, 1, 1, null, null, null, hostHealthStatus, HostState.HEALTHY, status);
 
     hostResponse.setRecoverySummary(recoverySummary);
     hostResponse.setRecoveryReport(recoveryReport);
@@ -1417,7 +1401,7 @@ public class HostResourceProviderTest extends EasyMockSupport {
 
     try {
       expect(host.getDesiredHostConfigs(EasyMock.<Cluster> anyObject(),
-          EasyMock.<Map> anyObject())).andReturn(desiredConfigs).anyTimes();
+          EasyMock.<Map<String, DesiredConfig>> anyObject())).andReturn(desiredConfigs).anyTimes();
 
     } catch (AmbariException e) {
       Assert.fail(e.getMessage());
@@ -1433,11 +1417,11 @@ public class HostResourceProviderTest extends EasyMockSupport {
     PredicateBuilder builder = new PredicateBuilder();
     if (clusterName != null && hostName != null) {
       return builder.property(HostResourceProvider.HOST_CLUSTER_NAME_PROPERTY_ID).equals(clusterName)
-      .and().property(HostResourceProvider.HOST_NAME_PROPERTY_ID).equals(hostName).toPredicate();
+      .and().property(HostResourceProvider.HOST_HOST_NAME_PROPERTY_ID).equals(hostName).toPredicate();
     }
 
     return clusterName != null ?
             builder.property(HostResourceProvider.HOST_CLUSTER_NAME_PROPERTY_ID).equals(clusterName).toPredicate() :
-            builder.property(HostResourceProvider.HOST_NAME_PROPERTY_ID).equals(hostName).toPredicate();
+            builder.property(HostResourceProvider.HOST_HOST_NAME_PROPERTY_ID).equals(hostName).toPredicate();
   }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/48f7fb22/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HostStackVersionResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HostStackVersionResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HostStackVersionResourceProviderTest.java
index 42b9632..26b89d3 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HostStackVersionResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/HostStackVersionResourceProviderTest.java
@@ -1,4 +1,4 @@
-/**
+/*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
  * distributed with this work for additional information
@@ -79,6 +79,7 @@ import org.apache.ambari.server.state.cluster.ClusterImpl;
 import org.apache.ambari.server.topology.TopologyManager;
 import org.apache.ambari.server.utils.StageUtils;
 import org.easymock.Capture;
+import org.easymock.EasyMock;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -153,9 +154,10 @@ public class HostStackVersionResourceProviderTest {
 
     StackEntity stack = new StackEntity();
     stack.setStackName("HDP");
-    stack.setStackVersion("2.2");
+    stack.setStackVersion("2.0.1");
     repoVersion.setStack(stack);
     repoVersion.setVersion("2.2");
+    repoVersion.setId(1L);
   }
 
   @After
@@ -232,9 +234,9 @@ public class HostStackVersionResourceProviderTest {
     expect(managementController.getActionManager()).andReturn(actionManager).anyTimes();
     expect(managementController.getJdkResourceUrl()).andReturn("/JdkResourceUrl").anyTimes();
     expect(managementController.getPackagesForServiceHost(anyObject(ServiceInfo.class),
-            anyObject(Map.class), anyObject(String.class))).andReturn(packages).anyTimes();
+            EasyMock.<Map<String, String>>anyObject(), anyObject(String.class))).andReturn(packages).anyTimes();
 
-    expect(resourceProviderFactory.getHostResourceProvider(anyObject(Set.class), anyObject(Map.class),
+    expect(resourceProviderFactory.getHostResourceProvider(EasyMock.<Set<String>>anyObject(), EasyMock.<Map<Resource.Type, String>>anyObject(),
         eq(managementController))).andReturn(csvResourceProvider).anyTimes();
 
     expect(clusters.getCluster(anyObject(String.class))).andReturn(cluster);
@@ -426,9 +428,9 @@ public class HostStackVersionResourceProviderTest {
     expect(managementController.getActionManager()).andReturn(actionManager).anyTimes();
     expect(managementController.getJdkResourceUrl()).andReturn("/JdkResourceUrl").anyTimes();
     expect(managementController.getPackagesForServiceHost(anyObject(ServiceInfo.class),
-            anyObject(Map.class), anyObject(String.class))).andReturn(packages).anyTimes();
+            EasyMock.<Map<String, String>>anyObject(), anyObject(String.class))).andReturn(packages).anyTimes();
 
-    expect(resourceProviderFactory.getHostResourceProvider(anyObject(Set.class), anyObject(Map.class),
+    expect(resourceProviderFactory.getHostResourceProvider(EasyMock.<Set<String>>anyObject(), EasyMock.<Map<Resource.Type, String>>anyObject(),
             eq(managementController))).andReturn(csvResourceProvider).anyTimes();
 
     expect(clusters.getCluster(anyObject(String.class))).andReturn(cluster);


Mime
View raw message