ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nc...@apache.org
Subject [1/2] ambari git commit: AMBARI-16082. Test Refresh Phase 1 (ncole)
Date Tue, 26 Apr 2016 13:19:02 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 071c175a1 -> 962be15c7


http://git-wip-us.apache.org/repos/asf/ambari/blob/962be15c/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
index 4ab9099..c9e14a1 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
@@ -48,6 +48,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Properties;
 import java.util.Set;
+import java.util.UUID;
 
 import javax.net.ssl.HostnameVerifier;
 import javax.net.ssl.HttpsURLConnection;
@@ -92,7 +93,6 @@ import org.apache.ambari.server.controller.spi.Resource;
 import org.apache.ambari.server.controller.utilities.PredicateBuilder;
 import org.apache.ambari.server.controller.utilities.PropertyHelper;
 import org.apache.ambari.server.customactions.ActionDefinition;
-import org.apache.ambari.server.events.publishers.AmbariEventPublisher;
 import org.apache.ambari.server.metadata.ActionMetadata;
 import org.apache.ambari.server.orm.GuiceJpaInitializer;
 import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
@@ -108,13 +108,13 @@ import org.apache.ambari.server.orm.dao.WidgetLayoutDAO;
 import org.apache.ambari.server.orm.entities.ExecutionCommandEntity;
 import org.apache.ambari.server.orm.entities.HostEntity;
 import org.apache.ambari.server.orm.entities.HostRoleCommandEntity;
+import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
 import org.apache.ambari.server.orm.entities.StackEntity;
 import org.apache.ambari.server.orm.entities.WidgetEntity;
 import org.apache.ambari.server.orm.entities.WidgetLayoutEntity;
 import org.apache.ambari.server.orm.entities.WidgetLayoutUserWidgetEntity;
 import org.apache.ambari.server.security.TestAuthenticationFactory;
 import org.apache.ambari.server.security.authorization.AuthorizationException;
-import org.apache.ambari.server.security.authorization.Users;
 import org.apache.ambari.server.serveraction.ServerAction;
 import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Clusters;
@@ -155,17 +155,18 @@ import org.apache.commons.collections.CollectionUtils;
 import org.easymock.Capture;
 import org.easymock.EasyMock;
 import org.junit.After;
+import org.junit.AfterClass;
 import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Ignore;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
-import org.powermock.api.mockito.PowerMockito;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.security.core.context.SecurityContextHolder;
 
+import com.google.common.collect.Lists;
 import com.google.gson.Gson;
 import com.google.gson.reflect.TypeToken;
 import com.google.inject.AbstractModule;
@@ -213,17 +214,16 @@ public class AmbariManagementControllerTest {
 
   private static final String CLUSTER_HOST_INFO = "clusterHostInfo";
 
-  private AmbariManagementController controller;
-  private Clusters clusters;
+  private static AmbariManagementController controller;
+  private static Clusters clusters;
   private ActionDBAccessor actionDB;
-  private Injector injector;
+  private static Injector injector;
   private ServiceFactory serviceFactory;
   private ServiceComponentFactory serviceComponentFactory;
   private ServiceComponentHostFactory serviceComponentHostFactory;
-  private AmbariMetaInfo ambariMetaInfo;
-  private Users users;
+  private static AmbariMetaInfo ambariMetaInfo;
   private EntityManager entityManager;
-  private Properties backingProperties;
+  private static Properties backingProperties;
   private Configuration configuration;
   private ConfigHelper configHelper;
   private ConfigGroupFactory configGroupFactory;
@@ -232,35 +232,36 @@ public class AmbariManagementControllerTest {
   private HostDAO hostDAO;
   private TopologyHostInfoDAO topologyHostInfoDAO;
   private HostRoleCommandDAO hostRoleCommandDAO;
-  private TopologyManager topologyManager;
 
   @Rule
   public ExpectedException expectedException = ExpectedException.none();
 
   @BeforeClass
-  public static void setupAuthentication() {
-    // Set authenticated user so that authorization checks will pass
+  public static void beforeClass() throws Exception {
+    InMemoryDefaultTestModule module = new InMemoryDefaultTestModule();
+    backingProperties = module.getProperties();
+    injector = Guice.createInjector(module);
+    injector.getInstance(GuiceJpaInitializer.class);
+    ambariMetaInfo = injector.getInstance(AmbariMetaInfo.class);
+    ambariMetaInfo.init();
+    clusters = injector.getInstance(Clusters.class);
+    controller = injector.getInstance(AmbariManagementController.class);
+    TopologyManager topologyManager = injector.getInstance(TopologyManager.class);
+    StageUtils.setTopologyManager(topologyManager);
+    ActionManager.setTopologyManager(topologyManager);
+
     SecurityContextHolder.getContext().setAuthentication(TestAuthenticationFactory.createAdministrator());
   }
 
   @Before
   public void setup() throws Exception {
-    InMemoryDefaultTestModule module = new InMemoryDefaultTestModule();
-    backingProperties = module.getProperties();
-    injector = Guice.createInjector(module);
-    injector.getInstance(GuiceJpaInitializer.class);
     entityManager = injector.getInstance(EntityManager.class);
-    clusters = injector.getInstance(Clusters.class);
     actionDB = injector.getInstance(ActionDBAccessor.class);
-    controller = injector.getInstance(AmbariManagementController.class);
     serviceFactory = injector.getInstance(ServiceFactory.class);
     serviceComponentFactory = injector.getInstance(
         ServiceComponentFactory.class);
     serviceComponentHostFactory = injector.getInstance(
         ServiceComponentHostFactory.class);
-    ambariMetaInfo = injector.getInstance(AmbariMetaInfo.class);
-    ambariMetaInfo.init();
-    users = injector.getInstance(Users.class);
     configuration = injector.getInstance(Configuration.class);
     configHelper = injector.getInstance(ConfigHelper.class);
     configGroupFactory = injector.getInstance(ConfigGroupFactory.class);
@@ -269,19 +270,25 @@ public class AmbariManagementControllerTest {
     hostDAO = injector.getInstance(HostDAO.class);
     topologyHostInfoDAO = injector.getInstance(TopologyHostInfoDAO.class);
     hostRoleCommandDAO = injector.getInstance(HostRoleCommandDAO.class);
-    topologyManager = injector.getInstance(TopologyManager.class);
-    StageUtils.setTopologyManager(topologyManager);
-    ActionManager.setTopologyManager(topologyManager);
     EasyMock.replay(injector.getInstance(AuditLogger.class));
   }
 
   @After
   public void teardown() {
-    injector.getInstance(PersistService.class).stop();
     actionDB = null;
     EasyMock.reset(injector.getInstance(AuditLogger.class));
   }
 
+  @AfterClass
+  public static void afterClass() throws Exception {
+    injector.getInstance(PersistService.class).stop();
+  }
+
+  private static String getUniqueName() {
+    return UUID.randomUUID().toString();
+  }
+
+
   private void setOsFamily(Host host, String osFamily, String osVersion) {
     Map<String, String> hostAttributes = new HashMap<String, String>();
     hostAttributes.put("os_family", osFamily);
@@ -295,10 +302,14 @@ public class AmbariManagementControllerTest {
   }
 
   private void addHostToCluster(String hostname, String clusterName) throws AmbariException {
-    clusters.addHost(hostname);
-    setOsFamily(clusters.getHost(hostname), "redhat", "6.3");
-    clusters.getHost(hostname).setState(HostState.HEALTHY);
-    clusters.getHost(hostname).persist();
+
+    if (!clusters.hostExists(hostname)) {
+      clusters.addHost(hostname);
+      setOsFamily(clusters.getHost(hostname), "redhat", "6.3");
+      clusters.getHost(hostname).setState(HostState.HEALTHY);
+      clusters.getHost(hostname).persist();
+    }
+
     if (null != clusterName) {
       clusters.mapHostToCluster(hostname, clusterName);
     }
@@ -514,13 +525,6 @@ public class AmbariManagementControllerTest {
     return installService(clusterName, serviceName, runSmokeTests, reconfigureClients, null, null);
   }
 
-  private long installService(String clusterName, String serviceName,
-                              boolean runSmokeTests, boolean reconfigureClients,
-                              Map<String, String> mapRequestPropsInput)
-      throws AmbariException, AuthorizationException {
-    return installService(clusterName, serviceName, runSmokeTests, reconfigureClients, null, mapRequestPropsInput);
-  }
-
 
   /**
    * Allows to set maintenanceStateHelper. For use when there is anything to test
@@ -531,15 +535,19 @@ public class AmbariManagementControllerTest {
                               MaintenanceStateHelper maintenanceStateHelper,
                               Map<String, String> mapRequestPropsInput)
       throws AmbariException, AuthorizationException {
+
     ServiceRequest r = new ServiceRequest(clusterName, serviceName,
         State.INSTALLED.toString());
+
     Set<ServiceRequest> requests = new HashSet<ServiceRequest>();
     requests.add(r);
+
     Map<String, String> mapRequestProps = new HashMap<String, String>();
     mapRequestProps.put("context", "Called from a test");
     if(mapRequestPropsInput != null) {
       mapRequestProps.putAll(mapRequestPropsInput);
     }
+
     RequestStatusResponse resp = ServiceResourceProviderTest.updateServices(controller, requests,
         mapRequestProps, runSmokeTests, reconfigureClients, maintenanceStateHelper);
 
@@ -567,17 +575,17 @@ public class AmbariManagementControllerTest {
 
   @Test
   public void testCreateClusterSimple() throws AmbariException, AuthorizationException {
-    String clusterName = "foo1";
-    createCluster(clusterName);
+    String cluster1 = getUniqueName();
+    createCluster(cluster1);
     Set<ClusterResponse> r =
         controller.getClusters(Collections.singleton(
-            new ClusterRequest(null, clusterName, null, null)));
+            new ClusterRequest(null, cluster1, null, null)));
     Assert.assertEquals(1, r.size());
     ClusterResponse c = r.iterator().next();
-    Assert.assertEquals(clusterName, c.getClusterName());
+    Assert.assertEquals(cluster1, c.getClusterName());
 
     try {
-      createCluster(clusterName);
+      createCluster(cluster1);
       fail("Duplicate cluster creation should fail");
     } catch (AmbariException e) {
       // Expected
@@ -585,16 +593,16 @@ public class AmbariManagementControllerTest {
   }
 
   @Test
-  public void testCreateClusterWithInvalidStack() {
-    // TODO implement test after meta data integration
-  }
-
-  @Test
   public void testCreateClusterWithHostMapping() throws AmbariException, AuthorizationException {
+    String cluster1 = getUniqueName();
+
+    String host1 = getUniqueName();
+    String host2 = getUniqueName();
+
     Set<String> hostNames = new HashSet<String>();
-    hostNames.add("h1");
-    hostNames.add("h2");
-    ClusterRequest r = new ClusterRequest(null, "c1", "HDP-0.1", hostNames);
+    hostNames.add(host1);
+    hostNames.add(host2);
+    ClusterRequest r = new ClusterRequest(null, cluster1, "HDP-0.1", hostNames);
 
     try {
       controller.createCluster(r);
@@ -604,21 +612,21 @@ public class AmbariManagementControllerTest {
     }
 
     try {
-      clusters.getCluster("c1");
+      clusters.getCluster(cluster1);
       fail("Expected to fail for non created cluster");
     } catch (ClusterNotFoundException e) {
       // Expected
     }
 
-    clusters.addHost("h1");
-    clusters.addHost("h2");
-    setOsFamily(clusters.getHost("h1"), "redhat", "6.3");
-    setOsFamily(clusters.getHost("h2"), "redhat", "6.3");
-    clusters.getHost("h1").persist();
-    clusters.getHost("h2").persist();
+    clusters.addHost(host1);
+    clusters.addHost(host2);
+    setOsFamily(clusters.getHost(host1), "redhat", "6.3");
+    setOsFamily(clusters.getHost(host2), "redhat", "6.3");
+    clusters.getHost(host1).persist();
+    clusters.getHost(host2).persist();
 
     controller.createCluster(r);
-    Assert.assertNotNull(clusters.getCluster("c1"));
+    Assert.assertNotNull(clusters.getCluster(cluster1));
   }
 
   @Test
@@ -647,7 +655,7 @@ public class AmbariManagementControllerTest {
     }
     r.setClusterId(null);
 
-    r.setClusterName("foo");
+    r.setClusterName(getUniqueName());
     try {
       controller.createCluster(r);
      fail("Expected create cluster for invalid request - no stack version");
@@ -669,27 +677,27 @@ public class AmbariManagementControllerTest {
 
   @Test
   public void testCreateServicesSimple() throws AmbariException, AuthorizationException {
-    String clusterName = "foo1";
-    createCluster(clusterName);
+    String cluster1 = getUniqueName();
+    createCluster(cluster1);
     String serviceName = "HDFS";
-    clusters.getCluster("foo1").setDesiredStackVersion(
+    clusters.getCluster(cluster1).setDesiredStackVersion(
         new StackId("HDP-0.1"));
-    createService(clusterName, serviceName, State.INIT);
+    createService(cluster1, serviceName, State.INIT);
 
     Service s =
-        clusters.getCluster(clusterName).getService(serviceName);
+        clusters.getCluster(cluster1).getService(serviceName);
     Assert.assertNotNull(s);
     Assert.assertEquals(serviceName, s.getName());
-    Assert.assertEquals(clusterName, s.getCluster().getClusterName());
+    Assert.assertEquals(cluster1, s.getCluster().getClusterName());
 
-    ServiceRequest req = new ServiceRequest(clusterName, serviceName, null);
+    ServiceRequest req = new ServiceRequest(cluster1, serviceName, null);
 
     Set<ServiceResponse> r =
         ServiceResourceProviderTest.getServices(controller, Collections.singleton(req));
     Assert.assertEquals(1, r.size());
     ServiceResponse resp = r.iterator().next();
     Assert.assertEquals(serviceName, resp.getServiceName());
-    Assert.assertEquals(clusterName, resp.getClusterName());
+    Assert.assertEquals(cluster1, resp.getClusterName());
     Assert.assertEquals(State.INIT.toString(),
         resp.getDesiredState());
     Assert.assertEquals("HDP-0.1", resp.getDesiredStackVersion());
@@ -736,13 +744,17 @@ public class AmbariManagementControllerTest {
       Assert.assertTrue(checkExceptionType(e, ClusterNotFoundException.class));
     }
 
-    clusters.addCluster("foo", new StackId("HDP-0.1"));
-    clusters.addCluster("bar", new StackId("HDP-0.1"));
+    String cluster1 = getUniqueName();
+    String cluster2 = getUniqueName();
+
+
+    clusters.addCluster(cluster1, new StackId("HDP-0.1"));
+    clusters.addCluster(cluster2, new StackId("HDP-0.1"));
 
     try {
       set1.clear();
-      ServiceRequest valid1 = new ServiceRequest("foo", "HDFS", null);
-      ServiceRequest valid2 = new ServiceRequest("foo", "HDFS", null);
+      ServiceRequest valid1 = new ServiceRequest(cluster1, "HDFS", null);
+      ServiceRequest valid2 = new ServiceRequest(cluster1, "HDFS", null);
       set1.add(valid1);
       set1.add(valid2);
       ServiceResourceProviderTest.createServices(controller, set1);
@@ -753,7 +765,7 @@ public class AmbariManagementControllerTest {
 
     try {
       set1.clear();
-      ServiceRequest valid1 = new ServiceRequest("foo", "bar", null);
+      ServiceRequest valid1 = new ServiceRequest(cluster1, "bar", null);
       set1.add(valid1);
       ServiceResourceProviderTest.createServices(controller, set1);
       fail("Expected failure for invalid service");
@@ -764,8 +776,8 @@ public class AmbariManagementControllerTest {
 
     try {
       set1.clear();
-      ServiceRequest valid1 = new ServiceRequest("foo", "HDFS", null);
-      ServiceRequest valid2 = new ServiceRequest("bar", "HDFS", null);
+      ServiceRequest valid1 = new ServiceRequest(cluster1, "HDFS", null);
+      ServiceRequest valid2 = new ServiceRequest(cluster2, "HDFS", null);
       set1.add(valid1);
       set1.add(valid2);
       ServiceResourceProviderTest.createServices(controller, set1);
@@ -774,18 +786,18 @@ public class AmbariManagementControllerTest {
       // Expected
     }
 
-    Assert.assertNotNull(clusters.getCluster("foo"));
-    Assert.assertEquals(0, clusters.getCluster("foo").getServices().size());
+    Assert.assertNotNull(clusters.getCluster(cluster1));
+    Assert.assertEquals(0, clusters.getCluster(cluster1).getServices().size());
 
     set1.clear();
-    ServiceRequest valid = new ServiceRequest("foo", "HDFS", null);
+    ServiceRequest valid = new ServiceRequest(cluster1, "HDFS", null);
     set1.add(valid);
     ServiceResourceProviderTest.createServices(controller, set1);
 
     try {
       set1.clear();
-      ServiceRequest valid1 = new ServiceRequest("foo", "HDFS", null);
-      ServiceRequest valid2 = new ServiceRequest("foo", "HDFS", null);
+      ServiceRequest valid1 = new ServiceRequest(cluster1, "HDFS", null);
+      ServiceRequest valid2 = new ServiceRequest(cluster1, "HDFS", null);
       set1.add(valid1);
       set1.add(valid2);
       ServiceResourceProviderTest.createServices(controller, set1);
@@ -794,40 +806,40 @@ public class AmbariManagementControllerTest {
       // Expected
     }
 
-    Assert.assertEquals(1, clusters.getCluster("foo").getServices().size());
+    Assert.assertEquals(1, clusters.getCluster(cluster1).getServices().size());
 
   }
 
   @Test
   public void testCreateServiceWithInvalidInfo() throws AmbariException, AuthorizationException {
-    String clusterName = "foo1";
-    createCluster(clusterName);
+    String cluster1 = getUniqueName();
+    createCluster(cluster1);
     String serviceName = "HDFS";
     try {
-      createService(clusterName, serviceName, State.INSTALLING);
+      createService(cluster1, serviceName, State.INSTALLING);
       fail("Service creation should fail for invalid state");
     } catch (Exception e) {
       // Expected
     }
     try {
-      clusters.getCluster(clusterName).getService(serviceName);
+      clusters.getCluster(cluster1).getService(serviceName);
       fail("Service creation should have failed");
     } catch (Exception e) {
       // Expected
     }
     try {
-      createService(clusterName, serviceName, State.INSTALLED);
+      createService(cluster1, serviceName, State.INSTALLED);
       fail("Service creation should fail for invalid initial state");
     } catch (Exception e) {
       // Expected
     }
 
-    createService(clusterName, serviceName, null);
+    createService(cluster1, serviceName, null);
 
     String serviceName2 = "MAPREDUCE";
-    createService(clusterName, serviceName2, State.INIT);
+    createService(cluster1, serviceName2, State.INIT);
 
-    ServiceRequest r = new ServiceRequest(clusterName, null, null);
+    ServiceRequest r = new ServiceRequest(cluster1, null, null);
     Set<ServiceResponse> response = ServiceResourceProviderTest.getServices(controller, Collections.singleton(r));
     Assert.assertEquals(2, response.size());
 
@@ -842,17 +854,20 @@ public class AmbariManagementControllerTest {
   @Test
   public void testCreateServicesMultiple() throws AmbariException, AuthorizationException {
     Set<ServiceRequest> set1 = new HashSet<ServiceRequest>();
-    clusters.addCluster("foo", new StackId("HDP-0.1"));
 
-    ServiceRequest valid1 = new ServiceRequest("foo", "HDFS", null);
-    ServiceRequest valid2 = new ServiceRequest("foo", "MAPREDUCE", null);
+    String cluster1 = getUniqueName();
+
+    clusters.addCluster(cluster1, new StackId("HDP-0.1"));
+
+    ServiceRequest valid1 = new ServiceRequest(cluster1, "HDFS", null);
+    ServiceRequest valid2 = new ServiceRequest(cluster1, "MAPREDUCE", null);
     set1.add(valid1);
     set1.add(valid2);
     ServiceResourceProviderTest.createServices(controller, set1);
 
     try {
-      valid1 = new ServiceRequest("foo", "PIG", null);
-      valid2 = new ServiceRequest("foo", "MAPREDUCE", null);
+      valid1 = new ServiceRequest(cluster1, "PIG", null);
+      valid2 = new ServiceRequest(cluster1, "MAPREDUCE", null);
       set1.add(valid1);
       set1.add(valid2);
       ServiceResourceProviderTest.createServices(controller, set1);
@@ -862,49 +877,49 @@ public class AmbariManagementControllerTest {
       Assert.assertTrue(checkExceptionType(e, DuplicateResourceException.class));
     }
 
-    Assert.assertNotNull(clusters.getCluster("foo"));
-    Assert.assertEquals(2, clusters.getCluster("foo").getServices().size());
-    Assert.assertNotNull(clusters.getCluster("foo").getService("HDFS"));
-    Assert.assertNotNull(clusters.getCluster("foo").getService("MAPREDUCE"));
+    Assert.assertNotNull(clusters.getCluster(cluster1));
+    Assert.assertEquals(2, clusters.getCluster(cluster1).getServices().size());
+    Assert.assertNotNull(clusters.getCluster(cluster1).getService("HDFS"));
+    Assert.assertNotNull(clusters.getCluster(cluster1).getService("MAPREDUCE"));
   }
 
   @Test
   public void testCreateServiceComponentSimple() throws AmbariException, AuthorizationException {
-    String clusterName = "foo1";
-    createCluster(clusterName);
+    String cluster1 = getUniqueName();
+    createCluster(cluster1);
     String serviceName = "HDFS";
-    createService(clusterName, serviceName, null);
+    createService(cluster1, serviceName, null);
 
     String componentName = "NAMENODE";
     try {
-      createServiceComponent(clusterName, serviceName, componentName,
+      createServiceComponent(cluster1, serviceName, componentName,
           State.INSTALLING);
       fail("ServiceComponent creation should fail for invalid state");
     } catch (Exception e) {
       // Expected
     }
     try {
-      clusters.getCluster(clusterName).getService(serviceName)
+      clusters.getCluster(cluster1).getService(serviceName)
           .getServiceComponent(componentName);
       fail("ServiceComponent creation should have failed");
     } catch (Exception e) {
       // Expected
     }
 
-    createServiceComponent(clusterName, serviceName, componentName,
+    createServiceComponent(cluster1, serviceName, componentName,
         State.INIT);
-    Assert.assertNotNull(clusters.getCluster(clusterName)
+    Assert.assertNotNull(clusters.getCluster(cluster1)
         .getService(serviceName).getServiceComponent(componentName));
 
     ServiceComponentRequest r =
-        new ServiceComponentRequest(clusterName, serviceName, null, null);
+        new ServiceComponentRequest(cluster1, serviceName, null, null);
     Set<ServiceComponentResponse> response = ComponentResourceProviderTest.getComponents(controller, Collections.singleton(r));
     Assert.assertEquals(1, response.size());
 
     ServiceComponentResponse sc = response.iterator().next();
     Assert.assertEquals(State.INIT.toString(), sc.getDesiredState());
     Assert.assertEquals(componentName, sc.getComponentName());
-    Assert.assertEquals(clusterName, sc.getClusterName());
+    Assert.assertEquals(cluster1, sc.getClusterName());
     Assert.assertEquals(serviceName, sc.getServiceName());
   }
 
@@ -917,6 +932,8 @@ public class AmbariManagementControllerTest {
     // invalid request params
     // invalid service
     // invalid cluster
+    String cluster1 = getUniqueName();
+    String cluster2 = getUniqueName();
 
     Set<ServiceComponentRequest> set1 = new HashSet<ServiceComponentRequest>();
 
@@ -934,7 +951,7 @@ public class AmbariManagementControllerTest {
     try {
       set1.clear();
       ServiceComponentRequest rInvalid =
-          new ServiceComponentRequest("c1", null, null, null);
+          new ServiceComponentRequest(cluster1, null, null, null);
       set1.add(rInvalid);
       ComponentResourceProviderTest.createComponents(controller, set1);
       fail("Expected failure for invalid requests");
@@ -945,7 +962,7 @@ public class AmbariManagementControllerTest {
     try {
       set1.clear();
       ServiceComponentRequest rInvalid =
-          new ServiceComponentRequest("c1", "s1", null, null);
+          new ServiceComponentRequest(cluster1, "s1", null, null);
       set1.add(rInvalid);
       ComponentResourceProviderTest.createComponents(controller, set1);
       fail("Expected failure for invalid requests");
@@ -956,7 +973,7 @@ public class AmbariManagementControllerTest {
     try {
       set1.clear();
       ServiceComponentRequest rInvalid =
-          new ServiceComponentRequest("c1", "s1", "sc1", null);
+          new ServiceComponentRequest(cluster1, "s1", "sc1", null);
       set1.add(rInvalid);
       ComponentResourceProviderTest.createComponents(controller, set1);
       fail("Expected failure for invalid cluster");
@@ -964,13 +981,13 @@ public class AmbariManagementControllerTest {
       // Expected
     }
 
-    clusters.addCluster("c1", new StackId("HDP-0.1"));
-    clusters.addCluster("c2", new StackId("HDP-0.1"));
+    clusters.addCluster(cluster1, new StackId("HDP-0.1"));
+    clusters.addCluster(cluster2, new StackId("HDP-0.1"));
 
     try {
       set1.clear();
       ServiceComponentRequest rInvalid =
-          new ServiceComponentRequest("c1", "HDFS", "NAMENODE", null);
+          new ServiceComponentRequest(cluster1, "HDFS", "NAMENODE", null);
       set1.add(rInvalid);
       ComponentResourceProviderTest.createComponents(controller, set1);
       fail("Expected failure for invalid service");
@@ -978,7 +995,7 @@ public class AmbariManagementControllerTest {
       // Expected
     }
 
-    Cluster c1 = clusters.getCluster("c1");
+    Cluster c1 = clusters.getCluster(cluster1);
     StackId stackId = new StackId("HDP-0.1");
     c1.setDesiredStackVersion(stackId);
     helper.getOrCreateRepositoryVersion(stackId, stackId.getStackVersion());
@@ -993,11 +1010,11 @@ public class AmbariManagementControllerTest {
 
     set1.clear();
     ServiceComponentRequest valid1 =
-        new ServiceComponentRequest("c1", "HDFS", "NAMENODE", null);
+        new ServiceComponentRequest(cluster1, "HDFS", "NAMENODE", null);
     ServiceComponentRequest valid2 =
-        new ServiceComponentRequest("c1", "MAPREDUCE", "JOBTRACKER", null);
+        new ServiceComponentRequest(cluster1, "MAPREDUCE", "JOBTRACKER", null);
     ServiceComponentRequest valid3 =
-        new ServiceComponentRequest("c1", "MAPREDUCE", "TASKTRACKER", null);
+        new ServiceComponentRequest(cluster1, "MAPREDUCE", "TASKTRACKER", null);
     set1.add(valid1);
     set1.add(valid2);
     set1.add(valid3);
@@ -1006,9 +1023,9 @@ public class AmbariManagementControllerTest {
     try {
       set1.clear();
       ServiceComponentRequest rInvalid1 =
-          new ServiceComponentRequest("c1", "HDFS", "HDFS_CLIENT", null);
+          new ServiceComponentRequest(cluster1, "HDFS", "HDFS_CLIENT", null);
       ServiceComponentRequest rInvalid2 =
-          new ServiceComponentRequest("c1", "HDFS", "HDFS_CLIENT", null);
+          new ServiceComponentRequest(cluster1, "HDFS", "HDFS_CLIENT", null);
       set1.add(rInvalid1);
       set1.add(rInvalid2);
       ComponentResourceProviderTest.createComponents(controller, set1);
@@ -1020,9 +1037,9 @@ public class AmbariManagementControllerTest {
     try {
       set1.clear();
       ServiceComponentRequest rInvalid1 =
-          new ServiceComponentRequest("c1", "HDFS", "HDFS_CLIENT", null);
+          new ServiceComponentRequest(cluster1, "HDFS", "HDFS_CLIENT", null);
       ServiceComponentRequest rInvalid2 =
-          new ServiceComponentRequest("c2", "HDFS", "HDFS_CLIENT", null);
+          new ServiceComponentRequest(cluster2, "HDFS", "HDFS_CLIENT", null);
       set1.add(rInvalid1);
       set1.add(rInvalid2);
       ComponentResourceProviderTest.createComponents(controller, set1);
@@ -1034,7 +1051,7 @@ public class AmbariManagementControllerTest {
     try {
       set1.clear();
       ServiceComponentRequest rInvalid =
-          new ServiceComponentRequest("c1", "HDFS", "NAMENODE", null);
+          new ServiceComponentRequest(cluster1, "HDFS", "NAMENODE", null);
       set1.add(rInvalid);
       ComponentResourceProviderTest.createComponents(controller, set1);
       fail("Expected failure for already existing component");
@@ -1057,28 +1074,28 @@ public class AmbariManagementControllerTest {
   //TODO this test becomes unstable after this patch, not reproducible locally but fails in apache jenkins jobs
   //investigate and reenable
   public void testGetExecutionCommandWithClusterEnvForRetry() throws Exception {
-    String clusterName = "foo1";
-    createCluster(clusterName);
-    Cluster cluster = clusters.getCluster(clusterName);
-    clusters.getCluster(clusterName)
+    String cluster1 = getUniqueName();
+    createCluster(cluster1);
+    Cluster cluster = clusters.getCluster(cluster1);
+    clusters.getCluster(cluster1)
         .setDesiredStackVersion(new StackId("HDP-0.1"));
     String serviceName = "HDFS";
-    createService(clusterName, serviceName, null);
+    createService(cluster1, serviceName, null);
     String componentName1 = "NAMENODE";
     String componentName2 = "DATANODE";
     String componentName3 = "HDFS_CLIENT";
-    createServiceComponent(clusterName, serviceName, componentName1,
+    createServiceComponent(cluster1, serviceName, componentName1,
                            State.INIT);
-    createServiceComponent(clusterName, serviceName, componentName2,
+    createServiceComponent(cluster1, serviceName, componentName2,
                            State.INIT);
-    createServiceComponent(clusterName, serviceName, componentName3,
+    createServiceComponent(cluster1, serviceName, componentName3,
                            State.INIT);
 
-    String host1 = "h1";
-    String host2 = "h2";
+    String host1 = getUniqueName();
+    String host2 = getUniqueName();
 
-    addHostToCluster(host1, clusterName);
-    addHostToCluster(host2, clusterName);
+    addHostToCluster(host1, cluster1);
+    addHostToCluster(host2, cluster1);
 
     Map<String, String> configs = new HashMap<String, String>();
     configs.put("a", "b");
@@ -1087,29 +1104,29 @@ public class AmbariManagementControllerTest {
     configs.put("commands_to_retry", "INSTALL");
 
     ConfigurationRequest cr1;
-    cr1 = new ConfigurationRequest(clusterName, "cluster-env","version1",
+    cr1 = new ConfigurationRequest(cluster1, "cluster-env","version1",
                                    configs, null);
 
-    ClusterRequest crReq = new ClusterRequest(cluster.getClusterId(), clusterName, null, null);
+    ClusterRequest crReq = new ClusterRequest(cluster.getClusterId(), cluster1, null, null);
     crReq.setDesiredConfig(Collections.singletonList(cr1));
     controller.updateClusters(Collections.singleton(crReq), null);
 
     Map<String, String> mapRequestProps = new HashMap<String, String>();
     mapRequestProps.put("context", "Called from a test");
 
-    createServiceComponentHost(clusterName, serviceName, componentName2,
+    createServiceComponentHost(cluster1, serviceName, componentName2,
                                host1, null);
-    createServiceComponentHost(clusterName, serviceName, componentName2,
+    createServiceComponentHost(cluster1, serviceName, componentName2,
                                host2, null);
-    createServiceComponentHost(clusterName, serviceName, componentName3,
+    createServiceComponentHost(cluster1, serviceName, componentName3,
                                host1, null);
-    createServiceComponentHost(clusterName, serviceName, componentName3,
+    createServiceComponentHost(cluster1, serviceName, componentName3,
                                host2, null);
 
     // issue an install command, expect retry is enabled
     ServiceComponentHostRequest
         schr =
-        new ServiceComponentHostRequest(clusterName, "HDFS", "DATANODE", host2, "INSTALLED");
+        new ServiceComponentHostRequest(cluster1, "HDFS", "DATANODE", host2, "INSTALLED");
     Map<String, String> requestProps = new HashMap<String, String>();
     requestProps.put("phase", "INITIAL_INSTALL");
     RequestStatusResponse rsr = updateHostComponents(Collections.singleton(schr), requestProps, false);
@@ -1130,12 +1147,12 @@ public class AmbariManagementControllerTest {
     assertTrue(ec.getCommandParams().containsKey("command_retry_enabled"));
     assertEquals("true", ec.getCommandParams().get("command_retry_enabled"));
 
-    for (ServiceComponentHost sch : clusters.getCluster(clusterName).getServiceComponentHosts(host2)) {
+    for (ServiceComponentHost sch : clusters.getCluster(cluster1).getServiceComponentHosts(host2)) {
       sch.setState(State.INSTALLED);
     }
 
     // issue an start command but no retry as phase is only INITIAL_INSTALL
-    schr = new ServiceComponentHostRequest(clusterName, "HDFS", "DATANODE", host2, "STARTED");
+    schr = new ServiceComponentHostRequest(cluster1, "HDFS", "DATANODE", host2, "STARTED");
     rsr = updateHostComponents(Collections.singleton(schr), requestProps, false);
     stages = actionDB.getAllStages(rsr.getRequestId());
     Assert.assertEquals(1, stages.size());
@@ -1157,15 +1174,15 @@ public class AmbariManagementControllerTest {
     configs.put("command_retry_max_time_in_sec", "12");
     configs.put("commands_to_retry", "START");
 
-    cr1 = new ConfigurationRequest(clusterName, "cluster-env","version2",
+    cr1 = new ConfigurationRequest(cluster1, "cluster-env","version2",
                                    configs, null);
-    crReq = new ClusterRequest(cluster.getClusterId(), clusterName, null, null);
+    crReq = new ClusterRequest(cluster.getClusterId(), cluster1, null, null);
     crReq.setDesiredConfig(Collections.singletonList(cr1));
     controller.updateClusters(Collections.singleton(crReq), null);
 
     // issue an start command and retry is expected
     requestProps.put("phase", "INITIAL_START");
-    schr = new ServiceComponentHostRequest(clusterName, "HDFS", "DATANODE", host2, "STARTED");
+    schr = new ServiceComponentHostRequest(cluster1, "HDFS", "DATANODE", host2, "STARTED");
     rsr = updateHostComponents(Collections.singleton(schr), requestProps, false);
     stages = actionDB.getAllStages(rsr.getRequestId());
     Assert.assertEquals(1, stages.size());
@@ -1188,14 +1205,14 @@ public class AmbariManagementControllerTest {
     configs.put("command_retry_max_time_in_sec", "-5");
     configs.put("commands_to_retry2", "START");
 
-    cr1 = new ConfigurationRequest(clusterName, "cluster-env","version3",
+    cr1 = new ConfigurationRequest(cluster1, "cluster-env","version3",
                                    configs, null);
-    crReq = new ClusterRequest(cluster.getClusterId(), clusterName, null, null);
+    crReq = new ClusterRequest(cluster.getClusterId(), cluster1, null, null);
     crReq.setDesiredConfig(Collections.singletonList(cr1));
     controller.updateClusters(Collections.singleton(crReq), null);
 
     requestProps.put("phase", "INITIAL_START");
-    schr = new ServiceComponentHostRequest(clusterName, "HDFS", "DATANODE", host2, "STARTED");
+    schr = new ServiceComponentHostRequest(cluster1, "HDFS", "DATANODE", host2, "STARTED");
     rsr = updateHostComponents(Collections.singleton(schr), requestProps, false);
     stages = actionDB.getAllStages(rsr.getRequestId());
     Assert.assertEquals(1, stages.size());
@@ -1217,12 +1234,14 @@ public class AmbariManagementControllerTest {
 
   @Test
   public void testGetExecutionCommand() throws Exception {
-    testCreateServiceComponentHostSimple();
+    String cluster1 = getUniqueName();
+    final String host1 = getUniqueName();
+
+    createServiceComponentHostSimple(cluster1, host1, getUniqueName());
 
-    String clusterName = "foo1";
     String serviceName = "HDFS";
 
-    Cluster cluster = clusters.getCluster(clusterName);
+    Cluster cluster = clusters.getCluster(cluster1);
     Service s1 = cluster.getService(serviceName);
 
     // Create and attach config
@@ -1230,26 +1249,28 @@ public class AmbariManagementControllerTest {
     configs.put("a", "b");
 
     ConfigurationRequest cr1,cr2;
-    cr1 = new ConfigurationRequest(clusterName, "core-site","version1",
+    cr1 = new ConfigurationRequest(cluster1, "core-site","version1",
                                    configs, null);
-    cr2 = new ConfigurationRequest(clusterName, "hdfs-site","version1",
+    cr2 = new ConfigurationRequest(cluster1, "hdfs-site","version1",
                                    configs, null);
 
-    ClusterRequest crReq = new ClusterRequest(cluster.getClusterId(), clusterName, null, null);
+    ClusterRequest crReq = new ClusterRequest(cluster.getClusterId(), cluster1, null, null);
     crReq.setDesiredConfig(Collections.singletonList(cr1));
     controller.updateClusters(Collections.singleton(crReq), null);
-    crReq = new ClusterRequest(cluster.getClusterId(), clusterName, null, null);
+    crReq = new ClusterRequest(cluster.getClusterId(), cluster1, null, null);
     crReq.setDesiredConfig(Collections.singletonList(cr2));
     controller.updateClusters(Collections.singleton(crReq), null);
 
+
+
     // Install
-    installService(clusterName, serviceName, false, false);
+    installService(cluster1, serviceName, false, false);
     ExecutionCommand ec =
         controller.getExecutionCommand(cluster,
-                                       s1.getServiceComponent("NAMENODE").getServiceComponentHost("h1"),
+                                       s1.getServiceComponent("NAMENODE").getServiceComponentHost(host1),
                                        RoleCommand.START);
     assertEquals("1-0", ec.getCommandId());
-    assertEquals("foo1", ec.getClusterName());
+    assertEquals(cluster1, ec.getClusterName());
     Map<String, Map<String, String>> configurations = ec.getConfigurations();
     assertNotNull(configurations);
     assertEquals(2, configurations.size());
@@ -1272,10 +1293,13 @@ public class AmbariManagementControllerTest {
 
   @Test
   public void testCreateServiceComponentMultiple() throws AmbariException, AuthorizationException {
-    clusters.addCluster("c1", new StackId("HDP-0.2"));
-    clusters.addCluster("c2", new StackId("HDP-0.2"));
+    String cluster1 = getUniqueName();
+    String cluster2 = getUniqueName();
+
+    clusters.addCluster(cluster1, new StackId("HDP-0.2"));
+    clusters.addCluster(cluster2, new StackId("HDP-0.2"));
 
-    Cluster c1 = clusters.getCluster("c1");
+    Cluster c1 = clusters.getCluster(cluster1);
     StackId stackId = new StackId("HDP-0.2");
 
     helper.getOrCreateRepositoryVersion(stackId, stackId.getStackVersion());
@@ -1291,11 +1315,11 @@ public class AmbariManagementControllerTest {
 
     Set<ServiceComponentRequest> set1 = new HashSet<ServiceComponentRequest>();
     ServiceComponentRequest valid1 =
-        new ServiceComponentRequest("c1", "HDFS", "NAMENODE", null);
+        new ServiceComponentRequest(cluster1, "HDFS", "NAMENODE", null);
     ServiceComponentRequest valid2 =
-        new ServiceComponentRequest("c1", "MAPREDUCE", "JOBTRACKER", null);
+        new ServiceComponentRequest(cluster1, "MAPREDUCE", "JOBTRACKER", null);
     ServiceComponentRequest valid3 =
-        new ServiceComponentRequest("c1", "MAPREDUCE", "TASKTRACKER", null);
+        new ServiceComponentRequest(cluster1, "MAPREDUCE", "TASKTRACKER", null);
     set1.add(valid1);
     set1.add(valid2);
     set1.add(valid3);
@@ -1312,8 +1336,15 @@ public class AmbariManagementControllerTest {
   }
 
   @Test
-  public void testCreateServiceComponentHostSimple() throws AmbariException, AuthorizationException {
-    String clusterName = "foo1";
+  public void testCreateServiceComponentHostSimple1() throws Exception {
+    String cluster1 = getUniqueName();
+    String host1 = getUniqueName();
+    String host2 = getUniqueName();
+    createServiceComponentHostSimple(cluster1, host1, host2);
+  }
+
+  private void createServiceComponentHostSimple(String clusterName, String host1,
+      String host2) throws AmbariException, AuthorizationException {
     createCluster(clusterName);
     clusters.getCluster(clusterName)
         .setDesiredStackVersion(new StackId("HDP-0.1"));
@@ -1329,9 +1360,6 @@ public class AmbariManagementControllerTest {
     createServiceComponent(clusterName, serviceName, componentName3,
         State.INIT);
 
-    String host1 = "h1";
-    String host2 = "h2";
-
     try {
       createServiceComponentHost(clusterName, serviceName, componentName1,
           host1, State.INIT);
@@ -1414,34 +1442,34 @@ public class AmbariManagementControllerTest {
   @Test
   public void testCreateServiceComponentHostMultiple()
       throws AmbariException, AuthorizationException {
-    String clusterName = "foo1";
-    createCluster(clusterName);
+    String cluster1 = getUniqueName();
+    createCluster(cluster1);
     String serviceName = "HDFS";
-    createService(clusterName, serviceName, null);
+    createService(cluster1, serviceName, null);
     String componentName1 = "NAMENODE";
     String componentName2 = "DATANODE";
-    createServiceComponent(clusterName, serviceName, componentName1,
+    createServiceComponent(cluster1, serviceName, componentName1,
         State.INIT);
-    createServiceComponent(clusterName, serviceName, componentName2,
+    createServiceComponent(cluster1, serviceName, componentName2,
         State.INIT);
-    String host1 = "h1";
-    String host2 = "h2";
-    addHostToCluster(host1, clusterName);
-    addHostToCluster(host2, clusterName);
+    String host1 = getUniqueName();
+    String host2 = getUniqueName();
+    addHostToCluster(host1, cluster1);
+    addHostToCluster(host2, cluster1);
 
     Set<ServiceComponentHostRequest> set1 =
         new HashSet<ServiceComponentHostRequest>();
     ServiceComponentHostRequest r1 =
-        new ServiceComponentHostRequest(clusterName, serviceName,
+        new ServiceComponentHostRequest(cluster1, serviceName,
             componentName1, host1, State.INIT.toString());
     ServiceComponentHostRequest r2 =
-        new ServiceComponentHostRequest(clusterName, serviceName,
+        new ServiceComponentHostRequest(cluster1, serviceName,
             componentName2, host1, State.INIT.toString());
     ServiceComponentHostRequest r3 =
-        new ServiceComponentHostRequest(clusterName, serviceName,
+        new ServiceComponentHostRequest(cluster1, serviceName,
             componentName1, host2, State.INIT.toString());
     ServiceComponentHostRequest r4 =
-        new ServiceComponentHostRequest(clusterName, serviceName,
+        new ServiceComponentHostRequest(cluster1, serviceName,
             componentName2, host2, State.INIT.toString());
 
     set1.add(r1);
@@ -1451,20 +1479,20 @@ public class AmbariManagementControllerTest {
     controller.createHostComponents(set1);
 
     Assert.assertEquals(2,
-      clusters.getCluster(clusterName).getServiceComponentHosts(host1).size());
+      clusters.getCluster(cluster1).getServiceComponentHosts(host1).size());
     Assert.assertEquals(2,
-      clusters.getCluster(clusterName).getServiceComponentHosts(host2).size());
+      clusters.getCluster(cluster1).getServiceComponentHosts(host2).size());
 
-    Assert.assertNotNull(clusters.getCluster(clusterName)
+    Assert.assertNotNull(clusters.getCluster(cluster1)
         .getService(serviceName).getServiceComponent(componentName1)
         .getServiceComponentHost(host1));
-    Assert.assertNotNull(clusters.getCluster(clusterName)
+    Assert.assertNotNull(clusters.getCluster(cluster1)
         .getService(serviceName).getServiceComponent(componentName1)
         .getServiceComponentHost(host2));
-    Assert.assertNotNull(clusters.getCluster(clusterName)
+    Assert.assertNotNull(clusters.getCluster(cluster1)
         .getService(serviceName).getServiceComponent(componentName2)
         .getServiceComponentHost(host1));
-    Assert.assertNotNull(clusters.getCluster(clusterName)
+    Assert.assertNotNull(clusters.getCluster(cluster1)
         .getService(serviceName).getServiceComponent(componentName2)
         .getServiceComponentHost(host2));
   }
@@ -1528,10 +1556,18 @@ public class AmbariManagementControllerTest {
       // Expected
     }
 
+    String host1 = getUniqueName();
+    String host2 = getUniqueName();
+    String host3 = getUniqueName();
+
+    String clusterFoo = getUniqueName();
+    String cluster1 = getUniqueName();
+    String cluster2 = getUniqueName();
+
     try {
       set1.clear();
       ServiceComponentHostRequest rInvalid =
-          new ServiceComponentHostRequest("foo", "HDFS", "NAMENODE", "h1", null);
+          new ServiceComponentHostRequest(clusterFoo, "HDFS", "NAMENODE", host1, null);
       set1.add(rInvalid);
       controller.createHostComponents(set1);
       fail("Expected failure for invalid cluster");
@@ -1539,12 +1575,15 @@ public class AmbariManagementControllerTest {
       // Expected
     }
 
-    clusters.addCluster("foo", new StackId("HDP-0.2"));
-    clusters.addCluster("c1", new StackId("HDP-0.2"));
-    clusters.addCluster("c2", new StackId("HDP-0.2"));
-    Cluster foo = clusters.getCluster("foo");
-    Cluster c1 = clusters.getCluster("c1");
-    Cluster c2 = clusters.getCluster("c2");
+    clusters.addCluster(clusterFoo, new StackId("HDP-0.2"));
+    clusters.addCluster(cluster1, new StackId("HDP-0.2"));
+    clusters.addCluster(cluster2, new StackId("HDP-0.2"));
+    Cluster foo = clusters.getCluster(clusterFoo);
+    Cluster c1 = clusters.getCluster(cluster1);
+    Cluster c2 = clusters.getCluster(cluster2);
+
+
+
 
     StackId stackId = new StackId("HDP-0.2");
     helper.getOrCreateRepositoryVersion(stackId, stackId.getStackVersion());
@@ -1572,7 +1611,7 @@ public class AmbariManagementControllerTest {
     try {
       set1.clear();
       ServiceComponentHostRequest rInvalid =
-          new ServiceComponentHostRequest("foo", "HDFS", "NAMENODE", "h1", null);
+          new ServiceComponentHostRequest(clusterFoo, "HDFS", "NAMENODE", host1, null);
       set1.add(rInvalid);
       controller.createHostComponents(set1);
       fail("Expected failure for invalid service");
@@ -1594,7 +1633,7 @@ public class AmbariManagementControllerTest {
     try {
       set1.clear();
       ServiceComponentHostRequest rInvalid =
-          new ServiceComponentHostRequest("foo", "HDFS", "NAMENODE", "h1", null);
+          new ServiceComponentHostRequest(clusterFoo, "HDFS", "NAMENODE", host1, null);
       set1.add(rInvalid);
       controller.createHostComponents(set1);
       fail("Expected failure for invalid service");
@@ -1616,7 +1655,7 @@ public class AmbariManagementControllerTest {
     try {
       set1.clear();
       ServiceComponentHostRequest rInvalid =
-          new ServiceComponentHostRequest("foo", "HDFS", "NAMENODE", "h1", null);
+          new ServiceComponentHostRequest(clusterFoo, "HDFS", "NAMENODE", host1, null);
       set1.add(rInvalid);
       controller.createHostComponents(set1);
       fail("Expected failure for invalid host");
@@ -1624,20 +1663,20 @@ public class AmbariManagementControllerTest {
       // Expected
     }
 
-    clusters.addHost("h1");
-    Host h1 = clusters.getHost("h1");
+    clusters.addHost(host1);
+    Host h1 = clusters.getHost(host1);
     h1.setIPv4("ipv41");
     h1.setIPv6("ipv61");
     setOsFamily(h1, "redhat", "6.3");
     h1.persist();
-    clusters.addHost("h2");
-    Host h2 = clusters.getHost("h2");
+    clusters.addHost(host2);
+    Host h2 = clusters.getHost(host2);
     h2.setIPv4("ipv42");
     h2.setIPv6("ipv62");
     setOsFamily(h2, "redhat", "6.3");
     h2.persist();
-    clusters.addHost("h3");
-    Host h3 = clusters.getHost("h3");
+    clusters.addHost(host3);
+    Host h3 = clusters.getHost(host3);
     h3.setIPv4("ipv43");
     h3.setIPv6("ipv63");
     setOsFamily(h3, "redhat", "6.3");
@@ -1646,7 +1685,7 @@ public class AmbariManagementControllerTest {
     try {
       set1.clear();
       ServiceComponentHostRequest rInvalid =
-          new ServiceComponentHostRequest("foo", "HDFS", "NAMENODE", "h1", null);
+          new ServiceComponentHostRequest(clusterFoo, "HDFS", "NAMENODE", host1, null);
       set1.add(rInvalid);
       controller.createHostComponents(set1);
       fail("Expected failure for invalid host cluster mapping");
@@ -1655,25 +1694,25 @@ public class AmbariManagementControllerTest {
     }
 
     Set<String> hostnames = new HashSet<String>();
-    hostnames.add("h1");
-    hostnames.add("h2");
-    hostnames.add("h3");
-    clusters.mapHostsToCluster(hostnames, "foo");
-    clusters.mapHostsToCluster(hostnames, "c1");
-    clusters.mapHostsToCluster(hostnames, "c2");
+    hostnames.add(host1);
+    hostnames.add(host2);
+    hostnames.add(host3);
+    clusters.mapHostsToCluster(hostnames, clusterFoo);
+    clusters.mapHostsToCluster(hostnames, cluster1);
+    clusters.mapHostsToCluster(hostnames, cluster2);
 
     set1.clear();
     ServiceComponentHostRequest valid =
-        new ServiceComponentHostRequest("foo", "HDFS", "NAMENODE", "h1", null);
+        new ServiceComponentHostRequest(clusterFoo, "HDFS", "NAMENODE", host1, null);
     set1.add(valid);
     controller.createHostComponents(set1);
 
     try {
       set1.clear();
       ServiceComponentHostRequest rInvalid1 =
-          new ServiceComponentHostRequest("foo", "HDFS", "NAMENODE", "h2", null);
+          new ServiceComponentHostRequest(clusterFoo, "HDFS", "NAMENODE", host2, null);
       ServiceComponentHostRequest rInvalid2 =
-          new ServiceComponentHostRequest("foo", "HDFS", "NAMENODE", "h2", null);
+          new ServiceComponentHostRequest(clusterFoo, "HDFS", "NAMENODE", host2, null);
       set1.add(rInvalid1);
       set1.add(rInvalid2);
       controller.createHostComponents(set1);
@@ -1685,10 +1724,10 @@ public class AmbariManagementControllerTest {
     try {
       set1.clear();
       ServiceComponentHostRequest rInvalid1 =
-          new ServiceComponentHostRequest("c1", "HDFS", "NAMENODE", "h2",
+          new ServiceComponentHostRequest(cluster1, "HDFS", "NAMENODE", host2,
               null);
       ServiceComponentHostRequest rInvalid2 =
-          new ServiceComponentHostRequest("c2", "HDFS", "NAMENODE", "h3",
+          new ServiceComponentHostRequest(cluster2, "HDFS", "NAMENODE", host3,
               null);
       set1.add(rInvalid1);
       set1.add(rInvalid2);
@@ -1701,10 +1740,10 @@ public class AmbariManagementControllerTest {
     try {
       set1.clear();
       ServiceComponentHostRequest rInvalid1 =
-          new ServiceComponentHostRequest("foo", "HDFS", "NAMENODE", "h1",
+          new ServiceComponentHostRequest(clusterFoo, "HDFS", "NAMENODE", host1,
               null);
       ServiceComponentHostRequest rInvalid2 =
-          new ServiceComponentHostRequest("foo", "HDFS", "NAMENODE", "h2",
+          new ServiceComponentHostRequest(clusterFoo, "HDFS", "NAMENODE", host2,
               null);
       set1.add(rInvalid1);
       set1.add(rInvalid2);
@@ -1714,35 +1753,39 @@ public class AmbariManagementControllerTest {
       // Expected
     }
 
-    Assert.assertEquals(1, foo.getServiceComponentHosts("h1").size());
-    Assert.assertEquals(0, foo.getServiceComponentHosts("h2").size());
-    Assert.assertEquals(0, foo.getServiceComponentHosts("h3").size());
+    Assert.assertEquals(1, foo.getServiceComponentHosts(host1).size());
+    Assert.assertEquals(0, foo.getServiceComponentHosts(host2).size());
+    Assert.assertEquals(0, foo.getServiceComponentHosts(host3).size());
 
     set1.clear();
     ServiceComponentHostRequest valid1 =
-        new ServiceComponentHostRequest("c1", "HDFS", "NAMENODE", "h1",
+        new ServiceComponentHostRequest(cluster1, "HDFS", "NAMENODE", host1,
             null);
     set1.add(valid1);
     controller.createHostComponents(set1);
 
     set1.clear();
     ServiceComponentHostRequest valid2 =
-        new ServiceComponentHostRequest("c2", "HDFS", "NAMENODE", "h1",
+        new ServiceComponentHostRequest(cluster2, "HDFS", "NAMENODE", host1,
             null);
     set1.add(valid2);
     controller.createHostComponents(set1);
 
-    Assert.assertEquals(1, foo.getServiceComponentHosts("h1").size());
-    Assert.assertEquals(1, c1.getServiceComponentHosts("h1").size());
-    Assert.assertEquals(1, c2.getServiceComponentHosts("h1").size());
+    Assert.assertEquals(1, foo.getServiceComponentHosts(host1).size());
+    Assert.assertEquals(1, c1.getServiceComponentHosts(host1).size());
+    Assert.assertEquals(1, c2.getServiceComponentHosts(host1).size());
 
   }
 
   @Test
   public void testCreateHostSimple() throws AmbariException {
+    String host1 = getUniqueName();
+    String host2 = getUniqueName();
+
+
     Map<String, String> hostAttributes = null;
 
-    HostRequest r1 = new HostRequest("h1", null, hostAttributes);
+    HostRequest r1 = new HostRequest(host1, null, hostAttributes);
     r1.toString();
 
     Set<HostRequest> requests = new HashSet<HostRequest>();
@@ -1754,14 +1797,14 @@ public class AmbariManagementControllerTest {
       // Expected
     }
 
-    clusters.addHost("h1");
-    clusters.addHost("h2");
-    setOsFamily(clusters.getHost("h1"), "redhat", "5.9");
-    setOsFamily(clusters.getHost("h2"), "redhat", "5.9");
-    clusters.getHost("h1").persist();
-    clusters.getHost("h2").persist();
+    clusters.addHost(host1);
+    clusters.addHost(host2);
+    setOsFamily(clusters.getHost(host1), "redhat", "5.9");
+    setOsFamily(clusters.getHost(host2), "redhat", "5.9");
+    clusters.getHost(host1).persist();
+    clusters.getHost(host2).persist();
 
-    requests.add(new HostRequest("h2", "foo", new HashMap<String, String>()));
+    requests.add(new HostRequest(host2, "foo", new HashMap<String, String>()));
 
     try {
       HostResourceProviderTest.createHosts(controller, requests);
@@ -1781,21 +1824,26 @@ public class AmbariManagementControllerTest {
 
     HostResourceProviderTest.createHosts(controller, requests);
 
-    Assert.assertNotNull(clusters.getHost("h1"));
-    Assert.assertNotNull(clusters.getHost("h2"));
+    Assert.assertNotNull(clusters.getHost(host1));
+    Assert.assertNotNull(clusters.getHost(host2));
 
-    Assert.assertEquals(0, clusters.getClustersForHost("h1").size());
-    Assert.assertEquals(1, clusters.getClustersForHost("h2").size());
+    Assert.assertEquals(0, clusters.getClustersForHost(host1).size());
+    Assert.assertEquals(1, clusters.getClustersForHost(host2).size());
 
   }
 
   @Test
   public void testCreateHostMultiple() throws AmbariException {
-    clusters.addHost("h1");
-    clusters.addHost("h2");
-    clusters.addHost("h3");
-    clusters.addCluster("c1", new StackId("HDP-0.1"));
-    Cluster c = clusters.getCluster("c1");
+    String host1 = getUniqueName();
+    String host2 = getUniqueName();
+    String host3 = getUniqueName();
+    String cluster1 = getUniqueName();
+
+    clusters.addHost(host1);
+    clusters.addHost(host2);
+    clusters.addHost(host3);
+    clusters.addCluster(cluster1, new StackId("HDP-0.1"));
+    Cluster c = clusters.getCluster(cluster1);
     StackId stackID = new StackId("HDP-0.1");
     c.setDesiredStackVersion(stackID);
     c.setCurrentStackVersion(stackID);
@@ -1803,18 +1851,16 @@ public class AmbariManagementControllerTest {
     c.createClusterVersion(stackID, stackID.getStackVersion(), "admin",
         RepositoryVersionState.INSTALLING);
 
-    setOsFamily(clusters.getHost("h1"), "redhat", "5.9");
-    setOsFamily(clusters.getHost("h2"), "redhat", "5.9");
-    setOsFamily(clusters.getHost("h3"), "redhat", "5.9");
-    clusters.getHost("h1").persist();
-    clusters.getHost("h2").persist();
-    clusters.getHost("h3").persist();
-
-   String clusterName = "c1";
+    setOsFamily(clusters.getHost(host1), "redhat", "5.9");
+    setOsFamily(clusters.getHost(host2), "redhat", "5.9");
+    setOsFamily(clusters.getHost(host3), "redhat", "5.9");
+    clusters.getHost(host1).persist();
+    clusters.getHost(host2).persist();
+    clusters.getHost(host3).persist();
 
-    HostRequest r1 = new HostRequest("h1", clusterName, null);
-    HostRequest r2 = new HostRequest("h2", clusterName, null);
-    HostRequest r3 = new HostRequest("h3", null, null);
+    HostRequest r1 = new HostRequest(host1, cluster1, null);
+    HostRequest r2 = new HostRequest(host2, cluster1, null);
+    HostRequest r3 = new HostRequest(host3, null, null);
 
     Set<HostRequest> set1 = new HashSet<HostRequest>();
     set1.add(r1);
@@ -1822,9 +1868,9 @@ public class AmbariManagementControllerTest {
     set1.add(r3);
     HostResourceProviderTest.createHosts(controller, set1);
 
-    Assert.assertEquals(1, clusters.getClustersForHost("h1").size());
-    Assert.assertEquals(1, clusters.getClustersForHost("h2").size());
-    Assert.assertEquals(0, clusters.getClustersForHost("h3").size());
+    Assert.assertEquals(1, clusters.getClustersForHost(host1).size());
+    Assert.assertEquals(1, clusters.getClustersForHost(host2).size());
+    Assert.assertEquals(0, clusters.getClustersForHost(host3).size());
   }
 
   @Test
@@ -1832,13 +1878,15 @@ public class AmbariManagementControllerTest {
     // unknown host
     // invalid clusters
     // duplicate host
+    String host1 = getUniqueName();
+    String cluster1 = getUniqueName();
 
     Set<HostRequest> set1 = new HashSet<HostRequest>();
 
     try {
       set1.clear();
       HostRequest rInvalid =
-          new HostRequest("h1", null, null);
+          new HostRequest(host1, null, null);
       set1.add(rInvalid);
       HostResourceProviderTest.createHosts(controller, set1);
       fail("Expected failure for invalid host");
@@ -1846,14 +1894,12 @@ public class AmbariManagementControllerTest {
       // Expected
     }
 
-    clusters.addHost("h1");
-
-    String clusterName = "c1";
+    clusters.addHost(host1);
 
     try {
       set1.clear();
       HostRequest rInvalid =
-          new HostRequest("h1", clusterName, null);
+          new HostRequest(host1, cluster1, null);
       set1.add(rInvalid);
       HostResourceProviderTest.createHosts(controller, set1);
       fail("Expected failure for invalid cluster");
@@ -1861,14 +1907,14 @@ public class AmbariManagementControllerTest {
       // Expected
     }
 
-    clusters.addCluster("c1", new StackId("HDP-0.1"));
+    clusters.addCluster(cluster1, new StackId("HDP-0.1"));
 
     try {
       set1.clear();
       HostRequest rInvalid1 =
-          new HostRequest("h1", clusterName, null);
+          new HostRequest(host1, cluster1, null);
       HostRequest rInvalid2 =
-          new HostRequest("h1", clusterName, null);
+          new HostRequest(host1, cluster1, null);
       set1.add(rInvalid1);
       set1.add(rInvalid2);
       HostResourceProviderTest.createHosts(controller, set1);
@@ -1884,12 +1930,13 @@ public class AmbariManagementControllerTest {
    * Create a cluster with a service, and verify that the request tasks have the correct output log and error log paths.
    */
   public void testRequestStatusLogs() throws Exception {
-    testCreateServiceComponentHostSimple();
+    String cluster1 = getUniqueName();
+
+    createServiceComponentHostSimple(cluster1, getUniqueName(), getUniqueName());
 
-    String clusterName = "foo1";
     String serviceName = "HDFS";
 
-    Cluster cluster = clusters.getCluster(clusterName);
+    Cluster cluster = clusters.getCluster(cluster1);
     for (Host h : clusters.getHosts()) {
       // Simulate each agent registering and setting the prefix path on its host
       h.setPrefix(Configuration.PREFIX_DIR);
@@ -1905,7 +1952,7 @@ public class AmbariManagementControllerTest {
     c1.persist();
     configs.put(c1.getType(), c1);
 
-    ServiceRequest r = new ServiceRequest(clusterName, serviceName, State.INSTALLED.toString());
+    ServiceRequest r = new ServiceRequest(cluster1, serviceName, State.INSTALLED.toString());
     Set<ServiceRequest> requests = new HashSet<ServiceRequest>();
     requests.add(r);
 
@@ -1925,12 +1972,15 @@ public class AmbariManagementControllerTest {
 
   @Test
   public void testInstallAndStartService() throws Exception {
-    testCreateServiceComponentHostSimple();
+    String cluster1 = getUniqueName();
+    String host1 = getUniqueName();
+    String host2 = getUniqueName();
+
+    createServiceComponentHostSimple(cluster1, host1, host2);
 
-    String clusterName = "foo1";
     String serviceName = "HDFS";
 
-    Cluster cluster = clusters.getCluster(clusterName);
+    Cluster cluster = clusters.getCluster(cluster1);
     Service s1 = cluster.getService(serviceName);
 
     Map<String, Config> configs = new HashMap<String, Config>();
@@ -1940,7 +1990,7 @@ public class AmbariManagementControllerTest {
     properties.put("b", "b1");
 
     Config c1 = new ConfigImpl(cluster, "hdfs-site", properties, propertiesAttributes, injector);
-    properties.put("c", "c1");
+    properties.put("c", cluster1);
     properties.put("d", "d1");
     Config c2 = new ConfigImpl(cluster, "core-site", properties, propertiesAttributes, injector);
     Config c3 = new ConfigImpl(cluster, "foo-site", properties, propertiesAttributes, injector);
@@ -1962,17 +2012,17 @@ public class AmbariManagementControllerTest {
     configs.put(c1.getType(), c1);
     configs.put(c2.getType(), c2);
 
-    ServiceRequest r = new ServiceRequest(clusterName, serviceName, State.INSTALLED.toString());
+    ServiceRequest r = new ServiceRequest(cluster1, serviceName, State.INSTALLED.toString());
     Set<ServiceRequest> requests = new HashSet<ServiceRequest>();
     requests.add(r);
 
     RequestStatusResponse trackAction =
         ServiceResourceProviderTest.updateServices(controller, requests, mapRequestProps, true, false);
     Assert.assertEquals(State.INSTALLED,
-        clusters.getCluster(clusterName).getService(serviceName)
+        clusters.getCluster(cluster1).getService(serviceName)
         .getDesiredState());
     for (ServiceComponent sc :
-      clusters.getCluster(clusterName).getService(serviceName)
+      clusters.getCluster(cluster1).getService(serviceName)
       .getServiceComponents().values()) {
       Assert.assertEquals(State.INSTALLED, sc.getDesiredState());
       for (ServiceComponentHost sch : sc.getServiceComponentHosts().values()) {
@@ -1997,7 +2047,7 @@ public class AmbariManagementControllerTest {
           taskStatus.getCommand());
       Assert.assertEquals(HostRoleStatus.PENDING.toString(),
           taskStatus.getStatus());
-      if (taskStatus.getHostName().equals("h1")) {
+      if (taskStatus.getHostName().equals(host1)) {
         if (Role.NAMENODE.toString().equals(taskStatus.getRole())) {
           foundH1NN = true;
         } else if (Role.DATANODE.toString().equals(taskStatus.getRole())) {
@@ -2007,7 +2057,7 @@ public class AmbariManagementControllerTest {
         } else {
           fail("Found invalid role for host h1");
         }
-      } else if (taskStatus.getHostName().equals("h2")) {
+      } else if (taskStatus.getHostName().equals(host2)) {
         if (Role.DATANODE.toString().equals(taskStatus.getRole())) {
           foundH2DN = true;
         } else if (Role.HDFS_CLIENT.toString().equals(taskStatus.getRole())) {
@@ -2051,34 +2101,36 @@ public class AmbariManagementControllerTest {
     List<HostRoleCommandEntity> entities = hostRoleCommandDAO.findAll(request, predicate);
     Assert.assertEquals(5, entities.size());
 
+    // !!! pick any entity to make sure a request brings back only one
+    Long taskId = entities.get(0).getTaskId();
     predicate = new PredicateBuilder().property(
         TaskResourceProvider.TASK_REQUEST_ID_PROPERTY_ID).equals(
             trackAction.getRequestId()).and().property(
-                TaskResourceProvider.TASK_ID_PROPERTY_ID).equals(1L).toPredicate();
+                TaskResourceProvider.TASK_ID_PROPERTY_ID).equals(taskId).toPredicate();
 
     entities = hostRoleCommandDAO.findAll(request, predicate);
     Assert.assertEquals(1, entities.size());
 
     // manually change live state to installed as no running action manager
     for (ServiceComponent sc :
-      clusters.getCluster(clusterName).getService(serviceName)
+      clusters.getCluster(cluster1).getService(serviceName)
       .getServiceComponents().values()) {
       for (ServiceComponentHost sch : sc.getServiceComponentHosts().values()) {
         sch.setState(State.INSTALLED);
       }
     }
 
-    r = new ServiceRequest(clusterName, serviceName, State.STARTED.toString());
+    r = new ServiceRequest(cluster1, serviceName, State.STARTED.toString());
     requests.clear();
     requests.add(r);
     trackAction = ServiceResourceProviderTest.updateServices(controller, requests, mapRequestProps, true,
       false);
 
     Assert.assertEquals(State.STARTED,
-        clusters.getCluster(clusterName).getService(serviceName)
+        clusters.getCluster(cluster1).getService(serviceName)
         .getDesiredState());
     for (ServiceComponent sc :
-      clusters.getCluster(clusterName).getService(serviceName)
+      clusters.getCluster(cluster1).getService(serviceName)
       .getServiceComponents().values()) {
       if (sc.getName().equals("HDFS_CLIENT")) {
         Assert.assertEquals(State.INSTALLED, sc.getDesiredState());
@@ -2103,7 +2155,7 @@ public class AmbariManagementControllerTest {
     LOG.info("Cluster Dump: " + sb.toString());
 
     for (ServiceComponent sc :
-      clusters.getCluster(clusterName).getService(serviceName)
+      clusters.getCluster(cluster1).getService(serviceName)
       .getServiceComponents().values()) {
       for (ServiceComponentHost sch : sc.getServiceComponentHosts().values()) {
         if (sc.isClientComponent()) {
@@ -2114,17 +2166,17 @@ public class AmbariManagementControllerTest {
       }
     }
 
-    r = new ServiceRequest(clusterName, serviceName, State.INSTALLED.toString());
+    r = new ServiceRequest(cluster1, serviceName, State.INSTALLED.toString());
     requests.clear();
     requests.add(r);
     trackAction = ServiceResourceProviderTest.updateServices(controller, requests, mapRequestProps, true,
       false);
 
     Assert.assertEquals(State.INSTALLED,
-        clusters.getCluster(clusterName).getService(serviceName)
+        clusters.getCluster(cluster1).getService(serviceName)
         .getDesiredState());
     for (ServiceComponent sc :
-      clusters.getCluster(clusterName).getService(serviceName)
+      clusters.getCluster(cluster1).getService(serviceName)
       .getServiceComponents().values()) {
       Assert.assertEquals(State.INSTALLED, sc.getDesiredState());
       for (ServiceComponentHost sch : sc.getServiceComponentHosts().values()) {
@@ -2141,9 +2193,11 @@ public class AmbariManagementControllerTest {
 
   @Test
   public void testGetClusters() throws AmbariException, AuthorizationException {
-    clusters.addCluster("c1", new StackId("HDP-0.1"));
+    String cluster1 = getUniqueName();
+
+    clusters.addCluster(cluster1, new StackId("HDP-0.1"));
 
-    Cluster c1 = clusters.getCluster("c1");
+    Cluster c1 = clusters.getCluster(cluster1);
 
     StackId stackId = new StackId("HDP-0.1");
     c1.setDesiredStackVersion(stackId);
@@ -2153,33 +2207,44 @@ public class AmbariManagementControllerTest {
 
     ClusterRequest r = new ClusterRequest(null, null, null, null);
     Set<ClusterResponse> resp = controller.getClusters(Collections.singleton(r));
-    Assert.assertEquals(1, resp.size());
 
-    ClusterResponse resp1 = resp.iterator().next();
+    // !!! many tests are creating clusters, just make sure we have at least one
+    Assert.assertFalse(resp.isEmpty());
 
-    Assert.assertEquals(c1.getClusterId(), resp1.getClusterId().longValue());
-    Assert.assertEquals(c1.getClusterName(), resp1.getClusterName());
-    Assert.assertEquals(c1.getDesiredStackVersion().getStackId(),
-        resp1.getDesiredStackVersion());
+    boolean found = false;
+    for (ClusterResponse cr : resp) {
+      if (cr.getClusterName().equals(cluster1)) {
+        Assert.assertEquals(c1.getClusterId(), cr.getClusterId().longValue());
+        Assert.assertEquals(c1.getDesiredStackVersion().getStackId(), cr.getDesiredStackVersion());
+        found = true;
+        break;
+      }
+    }
+
+    Assert.assertTrue(found);
   }
 
   @Test
   public void testGetClustersWithFilters() throws AmbariException, AuthorizationException {
-    clusters.addCluster("c1", new StackId("HDP-0.1"));
-    clusters.addCluster("c2", new StackId("HDP-0.1"));
-    clusters.addCluster("c3", new StackId("HDP-1.2.0"));
-    clusters.addCluster("c4", new StackId("HDP-0.1"));
+    String cluster1 = getUniqueName();
+    String cluster2 = getUniqueName();
+    String cluster3 = getUniqueName();
+    String cluster4 = getUniqueName();
+
+    clusters.addCluster(cluster1, new StackId("HDP-0.1"));
+    clusters.addCluster(cluster2, new StackId("HDP-0.1"));
+    clusters.addCluster(cluster3, new StackId("HDP-1.2.0"));
+    clusters.addCluster(cluster4, new StackId("HDP-0.1"));
 
-    Cluster c1 = clusters.getCluster("c1");
-    Cluster c2 = clusters.getCluster("c2");
-    Cluster c3 = clusters.getCluster("c3");
-    Cluster c4 = clusters.getCluster("c4");
+    Cluster c1 = clusters.getCluster(cluster1);
+    Cluster c2 = clusters.getCluster(cluster2);
+    Cluster c3 = clusters.getCluster(cluster3);
+    Cluster c4 = clusters.getCluster(cluster4);
 
     ClusterRequest r = new ClusterRequest(null, null, null, null);
     Set<ClusterResponse> resp = controller.getClusters(Collections.singleton(r));
-    Assert.assertEquals(4, resp.size());
 
-    r = new ClusterRequest(null, "c1", null, null);
+    r = new ClusterRequest(null, cluster1, null, null);
     resp = controller.getClusters(Collections.singleton(r));
     Assert.assertEquals(1, resp.size());
     Assert.assertEquals(c1.getClusterId(),
@@ -2187,7 +2252,7 @@ public class AmbariManagementControllerTest {
 
     r = new ClusterRequest(null, null, "HDP-0.1", null);
     resp = controller.getClusters(Collections.singleton(r));
-    Assert.assertEquals(3, resp.size());
+    Assert.assertTrue(resp.size() >= 3);
 
     r = new ClusterRequest(null, null, "", null);
     resp = controller.getClusters(Collections.singleton(r));
@@ -2196,8 +2261,10 @@ public class AmbariManagementControllerTest {
 
   @Test
   public void testGetServices() throws AmbariException {
-    clusters.addCluster("c1", new StackId("HDP-0.1"));
-    Cluster c1 = clusters.getCluster("c1");
+    String cluster1 = getUniqueName();
+
+    clusters.addCluster(cluster1, new StackId("HDP-0.1"));
+    Cluster c1 = clusters.getCluster(cluster1);
     Service s1 = serviceFactory.createNew(c1, "HDFS");
 
     c1.addService(s1);
@@ -2206,7 +2273,7 @@ public class AmbariManagementControllerTest {
 
     s1.persist();
 
-    ServiceRequest r = new ServiceRequest("c1", null, null);
+    ServiceRequest r = new ServiceRequest(cluster1, null, null);
     Set<ServiceResponse> resp = ServiceResourceProviderTest.getServices(controller, Collections.singleton(r));
 
     ServiceResponse resp1 = resp.iterator().next();
@@ -2224,10 +2291,13 @@ public class AmbariManagementControllerTest {
 
   @Test
   public void testGetServicesWithFilters() throws AmbariException {
-    clusters.addCluster("c1", new StackId("HDP-0.2"));
-    clusters.addCluster("c2", new StackId("HDP-0.2"));
-    Cluster c1 = clusters.getCluster("c1");
-    Cluster c2 = clusters.getCluster("c2");
+    String cluster1 = getUniqueName();
+    String cluster2 = getUniqueName();
+
+    clusters.addCluster(cluster1, new StackId("HDP-0.2"));
+    clusters.addCluster(cluster2, new StackId("HDP-0.2"));
+    Cluster c1 = clusters.getCluster(cluster1);
+    Cluster c2 = clusters.getCluster(cluster2);
     c1.setDesiredStackVersion(new StackId("HDP-0.2"));
     c2.setDesiredStackVersion(new StackId("HDP-0.2"));
 
@@ -2303,8 +2373,10 @@ public class AmbariManagementControllerTest {
 
   @Test
   public void testGetServiceComponents() throws AmbariException {
-    clusters.addCluster("c1", new StackId("HDP-0.2"));
-    Cluster c1 = clusters.getCluster("c1");
+    String cluster1 = getUniqueName();
+
+    clusters.addCluster(cluster1, new StackId("HDP-0.2"));
+    Cluster c1 = clusters.getCluster(cluster1);
     c1.setDesiredStackVersion(new StackId("HDP-0.2"));
     Service s1 = serviceFactory.createNew(c1, "HDFS");
     c1.addService(s1);
@@ -2316,7 +2388,7 @@ public class AmbariManagementControllerTest {
     sc1.setDesiredStackVersion(new StackId("HDP-0.1"));
     sc1.setDesiredState(State.UNINSTALLED);
 
-    ServiceComponentRequest r = new ServiceComponentRequest("c1",
+    ServiceComponentRequest r = new ServiceComponentRequest(cluster1,
        s1.getName(), sc1.getName(), null);
 
     Set<ServiceComponentResponse> resps = ComponentResourceProviderTest.getComponents(controller, Collections.singleton(r));
@@ -2337,10 +2409,13 @@ public class AmbariManagementControllerTest {
 
   @Test
   public void testGetServiceComponentsWithFilters() throws AmbariException {
-    clusters.addCluster("c1", new StackId("HDP-0.2"));
-    clusters.addCluster("c2", new StackId("HDP-0.2"));
-    Cluster c1 = clusters.getCluster("c1");
-    Cluster c2 = clusters.getCluster("c2");
+    String cluster1 = getUniqueName();
+    String cluster2 = getUniqueName();
+
+    clusters.addCluster(cluster1, new StackId("HDP-0.2"));
+    clusters.addCluster(cluster2, new StackId("HDP-0.2"));
+    Cluster c1 = clusters.getCluster(cluster1);
+    Cluster c2 = clusters.getCluster(cluster2);
 
     Service s1 = serviceFactory.createNew(c1, "HDFS");
     Service s2 = serviceFactory.createNew(c1, "MAPREDUCE");
@@ -2470,9 +2545,10 @@ public class AmbariManagementControllerTest {
 
   @Test
   public void testGetServiceComponentHosts() throws AmbariException, AuthorizationException {
-    Cluster c1 = setupClusterWithHosts("c1", "HDP-0.1", new ArrayList<String>() {{
-      add("h1");
-    }}, "centos5");
+    String cluster1 = getUniqueName();
+    String host1 = getUniqueName();
+
+    Cluster c1 = setupClusterWithHosts(cluster1, "HDP-0.1", Lists.newArrayList(host1), "centos5");
     Service s1 = serviceFactory.createNew(c1, "HDFS");
     c1.addService(s1);
     s1.persist();
@@ -2480,7 +2556,7 @@ public class AmbariManagementControllerTest {
     s1.addServiceComponent(sc1);
     sc1.setDesiredState(State.UNINSTALLED);
     sc1.persist();
-    ServiceComponentHost sch1 = serviceComponentHostFactory.createNew(sc1, "h1");
+    ServiceComponentHost sch1 = serviceComponentHostFactory.createNew(sc1, host1);
     sc1.addServiceComponentHost(sch1);
     sch1.setDesiredState(State.INSTALLED);
     sch1.setState(State.INSTALLING);
@@ -2520,56 +2596,57 @@ public class AmbariManagementControllerTest {
   @Test
   public void testGetServiceComponentHostsWithStaleConfigFilter() throws AmbariException, AuthorizationException {
 
-    final String host1 = "h1";
-    final String host2 = "h2";
-    Long clusterId = 1L;
-    String clusterName = "foo1";
-    setupClusterWithHosts(clusterName, "HDP-2.0.5",
+    final String host1 = getUniqueName();
+    final String host2 = getUniqueName();
+    String cluster1 = getUniqueName();
+    Cluster c = setupClusterWithHosts(cluster1, "HDP-2.0.5",
         new ArrayList<String>() {{
           add(host1);
           add(host2);
         }},
         "centos5");
+
+    Long clusterId = c.getClusterId();
     String serviceName = "HDFS";
-    createService(clusterName, serviceName, null);
+    createService(cluster1, serviceName, null);
     String componentName1 = "NAMENODE";
     String componentName2 = "DATANODE";
     String componentName3 = "HDFS_CLIENT";
 
-    createServiceComponent(clusterName, serviceName, componentName1,
+    createServiceComponent(cluster1, serviceName, componentName1,
         State.INIT);
-    createServiceComponent(clusterName, serviceName, componentName2,
+    createServiceComponent(cluster1, serviceName, componentName2,
         State.INIT);
-    createServiceComponent(clusterName, serviceName, componentName3,
+    createServiceComponent(cluster1, serviceName, componentName3,
         State.INIT);
 
-    createServiceComponentHost(clusterName, serviceName, componentName1,
+    createServiceComponentHost(cluster1, serviceName, componentName1,
         host1, null);
-    createServiceComponentHost(clusterName, serviceName, componentName2,
+    createServiceComponentHost(cluster1, serviceName, componentName2,
         host1, null);
-    createServiceComponentHost(clusterName, serviceName, componentName3,
+    createServiceComponentHost(cluster1, serviceName, componentName3,
         host1, null);
-    createServiceComponentHost(clusterName, serviceName, componentName2,
+    createServiceComponentHost(cluster1, serviceName, componentName2,
         host2, null);
-    createServiceComponentHost(clusterName, serviceName, componentName3,
+    createServiceComponentHost(cluster1, serviceName, componentName3,
         host2, null);
 
     // Install
-    installService(clusterName, serviceName, false, false);
+    installService(cluster1, serviceName, false, false);
 
     // Create and attach config
     Map<String, String> configs = new HashMap<String, String>();
     configs.put("a", "b");
 
     ConfigurationRequest cr1;
-    cr1 = new ConfigurationRequest(clusterName, "hdfs-site", "version1",
+    cr1 = new ConfigurationRequest(cluster1, "hdfs-site", "version1",
         configs, null);
-    ClusterRequest crReq = new ClusterRequest(clusterId, clusterName, null, null);
+    ClusterRequest crReq = new ClusterRequest(clusterId, cluster1, null, null);
     crReq.setDesiredConfig(Collections.singletonList(cr1));
     controller.updateClusters(Collections.singleton(crReq), null);
 
     // Start
-    startService(clusterName, serviceName, false, false);
+    startService(cluster1, serviceName, false, false);
 
     //Update actual config
     HashMap<String, Map<String, String>> actualConfig = new HashMap<String, Map<String, String>>() {{
@@ -2584,7 +2661,7 @@ public class AmbariManagementControllerTest {
           }});
         }};
 
-    Service s1 = clusters.getCluster(clusterName).getService(serviceName);
+    Service s1 = clusters.getCluster(cluster1).getService(serviceName);
     s1.getServiceComponent(componentName1).getServiceComponentHost(host1).updateActualConfigs(actualConfig);
     s1.getServiceComponent(componentName2).getServiceComponentHost(host1).updateActualConfigs(actualConfig);
     s1.getServiceComponent(componentName3).getServiceComponentHost(host1).updateActualConfigs(actualConfigOld);
@@ -2592,30 +2669,30 @@ public class AmbariManagementControllerTest {
     s1.getServiceComponent(componentName3).getServiceComponentHost(host2).updateActualConfigs(actualConfig);
 
     ServiceComponentHostRequest r =
-        new ServiceComponentHostRequest(clusterName, null, null, null, null);
+        new ServiceComponentHostRequest(cluster1, null, null, null, null);
     Set<ServiceComponentHostResponse> resps = controller.getHostComponents(Collections.singleton(r));
     Assert.assertEquals(5, resps.size());
 
     //Get all host components with stale config = true
-    r = new ServiceComponentHostRequest(clusterName, null, null, null, null);
+    r = new ServiceComponentHostRequest(cluster1, null, null, null, null);
     r.setStaleConfig("true");
     resps = controller.getHostComponents(Collections.singleton(r));
     Assert.assertEquals(2, resps.size());
 
     //Get all host components with stale config = false
-    r = new ServiceComponentHostRequest(clusterName, null, null, null, null);
+    r = new ServiceComponentHostRequest(cluster1, null, null, null, null);
     r.setStaleConfig("false");
     resps = controller.getHostComponents(Collections.singleton(r));
     Assert.assertEquals(3, resps.size());
 
     //Get all host components with stale config = false and hostname filter
-    r = new ServiceComponentHostRequest(clusterName, null, null, host1, null);
+    r = new ServiceComponentHostRequest(cluster1, null, null, host1, null);
     r.setStaleConfig("false");
     resps = controller.getHostComponents(Collections.singleton(r));
     Assert.assertEquals(2, resps.size());
 
     //Get all host components with stale config = false and hostname filter
-    r = new ServiceComponentHostRequest(clusterName, null, null, host2, null);
+    r = new ServiceComponentHostRequest(cluster1, null, null, host2, null);
     r.setStaleConfig("true");
     resps = controller.getHostComponents(Collections.singleton(r));
     Assert.assertEquals(1, resps.size());
@@ -2624,76 +2701,77 @@ public class AmbariManagementControllerTest {
   @Test
   public void testServiceComponentHostsWithDecommissioned() throws Exception {
 
-    final String host1 = "h1";
-    final String host2 = "h2";
-    String clusterName = "foo1";
-    setupClusterWithHosts(clusterName, "HDP-2.0.7",
+    final String host1 = getUniqueName();
+    final String host2 = getUniqueName();
+    String cluster1 = getUniqueName();
+
+    setupClusterWithHosts(cluster1, "HDP-2.0.7",
         new ArrayList<String>() {{
           add(host1);
           add(host2);
         }},
         "centos5");
     String serviceName = "HDFS";
-    createService(clusterName, serviceName, null);
+    createService(cluster1, serviceName, null);
     String componentName1 = "NAMENODE";
     String componentName2 = "DATANODE";
     String componentName3 = "HDFS_CLIENT";
 
-    createServiceComponent(clusterName, serviceName, componentName1,
+    createServiceComponent(cluster1, serviceName, componentName1,
         State.INIT);
-    createServiceComponent(clusterName, serviceName, componentName2,
+    createServiceComponent(cluster1, serviceName, componentName2,
         State.INIT);
-    createServiceComponent(clusterName, serviceName, componentName3,
+    createServiceComponent(cluster1, serviceName, componentName3,
         State.INIT);
 
-    createServiceComponentHost(clusterName, serviceName, componentName1,
+    createServiceComponentHost(cluster1, serviceName, componentName1,
         host1, null);
-    createServiceComponentHost(clusterName, serviceName, componentName2,
+    createServiceComponentHost(cluster1, serviceName, componentName2,
         host1, null);
-    createServiceComponentHost(clusterName, serviceName, componentName3,
+    createServiceComponentHost(cluster1, serviceName, componentName3,
         host1, null);
-    createServiceComponentHost(clusterName, serviceName, componentName2,
+    createServiceComponentHost(cluster1, serviceName, componentName2,
         host2, null);
-    createServiceComponentHost(clusterName, serviceName, componentName3,
+    createServiceComponentHost(cluster1, serviceName, componentName3,
         host2, null);
 
     // Install
-    installService(clusterName, serviceName, false, false);
+    installService(cluster1, serviceName, false, false);
 
     // Start
-    startService(clusterName, serviceName, false, false);
+    startService(cluster1, serviceName, false, false);
 
-    Service s1 = clusters.getCluster(clusterName).getService(serviceName);
+    Service s1 = clusters.getCluster(cluster1).getService(serviceName);
     s1.getServiceComponent(componentName2).getServiceComponentHost(host1).
         setComponentAdminState(HostComponentAdminState.DECOMMISSIONED);
     s1.getServiceComponent(componentName2).getServiceComponentHost(host2).
         setComponentAdminState(HostComponentAdminState.INSERVICE);
 
     ServiceComponentHostRequest r =
-        new ServiceComponentHostRequest(clusterName, null, null, null, null);
+        new ServiceComponentHostRequest(cluster1, null, null, null, null);
     Set<ServiceComponentHostResponse> resps = controller.getHostComponents(Collections.singleton(r));
     Assert.assertEquals(5, resps.size());
 
     //Get all host components with decommissiond = true
-    r = new ServiceComponentHostRequest(clusterName, null, null, null, null);
+    r = new ServiceComponentHostRequest(cluster1, null, null, null, null);
     r.setAdminState("DECOMMISSIONED");
     resps = controller.getHostComponents(Collections.singleton(r));
     Assert.assertEquals(1, resps.size());
 
     //Get all host components with decommissioned = false
-    r = new ServiceComponentHostRequest(clusterName, null, null, null, null);
+    r = new ServiceComponentHostRequest(cluster1, null, null, null, null);
     r.setAdminState("INSERVICE");
     resps = controller.getHostComponents(Collections.singleton(r));
     Assert.assertEquals(1, resps.size());
 
     //Get all host components with decommissioned = some random string
-    r = new ServiceComponentHostRequest(clusterName, null, null, null, null);
+    r = new ServiceComponentHostRequest(cluster1, null, null, null, null);
     r.setAdminState("INSTALLED");
     resps = controller.getHostComponents(Collections.singleton(r));
     Assert.assertEquals(0, resps.size());
 
     //Update adminState
-    r = new ServiceComponentHostRequest(clusterName, "HDFS", "DATANODE", host2, null);
+    r = new ServiceComponentHostRequest(cluster1, "HDFS", "DATANODE", host2, null);
     r.setAdminState("DECOMMISSIONED");
     try {
       updateHostComponents(Collections.singleton(r), new HashMap<String, String>(), false);
@@ -2705,60 +2783,60 @@ public class AmbariManagementControllerTest {
 
   @Test
   public void testHbaseDecommission() throws AmbariException, AuthorizationException {
-    String clusterName = "foo1";
-    createCluster(clusterName);
-    clusters.getCluster(clusterName)
+    String cluster1 = getUniqueName();
+    createCluster(cluster1);
+    clusters.getCluster(cluster1)
         .setDesiredStackVersion(new StackId("HDP-2.0.7"));
     String serviceName = "HBASE";
-    createService(clusterName, serviceName, null);
+    createService(cluster1, serviceName, null);
     String componentName1 = "HBASE_MASTER";
     String componentName2 = "HBASE_REGIONSERVER";
 
-    createServiceComponent(clusterName, serviceName, componentName1,
+    createServiceComponent(cluster1, serviceName, componentName1,
         State.INIT);
-    createServiceComponent(clusterName, serviceName, componentName2,
+    createServiceComponent(cluster1, serviceName, componentName2,
         State.INIT);
 
-    String host1 = "h1";
-    String host2 = "h2";
+    final String host1 = getUniqueName();
+    final String host2 = getUniqueName();
 
-    addHostToCluster(host1, clusterName);
-    addHostToCluster(host2, clusterName);
+    addHostToCluster(host1, cluster1);
+    addHostToCluster(host2, cluster1);
 
-    createServiceComponentHost(clusterName, serviceName, componentName1,
+    createServiceComponentHost(cluster1, serviceName, componentName1,
         host1, null);
-    createServiceComponentHost(clusterName, serviceName, componentName1,
+    createServiceComponentHost(cluster1, serviceName, componentName1,
         host2, null);
-    createServiceComponentHost(clusterName, serviceName, componentName2,
+    createServiceComponentHost(cluster1, serviceName, componentName2,
         host1, null);
-    createServiceComponentHost(clusterName, serviceName, componentName2,
+    createServiceComponentHost(cluster1, serviceName, componentName2,
         host2, null);
 
     RequestOperationLevel level = new RequestOperationLevel(
-            Resource.Type.HostComponent, clusterName, null, null, null);
+            Resource.Type.HostComponent, cluster1, null, null, null);
 
     // Install
-    installService(clusterName, serviceName, false, false);
+    installService(cluster1, serviceName, false, false);
 
     // Start
-    startService(clusterName, serviceName, false, false);
+    startService(cluster1, serviceName, false, false);
 
-    Cluster cluster = clusters.getCluster(clusterName);
+    Cluster cluster = clusters.getCluster(cluster1);
     Service s = cluster.getService(serviceName);
     Assert.assertEquals(State.STARTED, s.getDesiredState());
-    ServiceComponentHost scHost = s.getServiceComponent("HBASE_REGIONSERVER").getServiceComponentHost("h2");
+    ServiceComponentHost scHost = s.getServiceComponent("HBASE_REGIONSERVER").getServiceComponentHost(host2);
     Assert.assertEquals(HostComponentAdminState.INSERVICE, scHost.getComponentAdminState());
 
     // Decommission one RS
     Map<String, String> params = new HashMap<String, String>() {{
-      put("excluded_hosts", "h2");
+      put("excluded_hosts", host2);
       put("align_maintenance_state", "true");
     }};
     RequestResourceFilter resourceFilter = new RequestResourceFilter("HBASE", "HBASE_MASTER", null);
     List<RequestResourceFilter> resourceFilters = new ArrayList<RequestResourceFilter>();
     resourceFilters.add(resourceFilter);
 
-    ExecuteActionRequest request = new ExecuteActionRequest(clusterName,
+    ExecuteActionRequest request = new ExecuteActionRequest(cluster1,
       "DECOMMISSION", null, resourceFilters, level, params, false);
 
     Map<String, String> requestProperties = new HashMap<String, String>();
@@ -2775,8 +2853,8 @@ public class AmbariManagementControllerTest {
     Assert.assertEquals(HostComponentAdminState.DECOMMISSIONED, scHost.getComponentAdminState());
     Assert.assertEquals(MaintenanceState.ON, scHost.getMaintenanceState());
   

<TRUNCATED>

Mime
View raw message