ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jonathanhur...@apache.org
Subject [31/50] [abbrv] ambari git commit: AMBARI-21059. Reduce Dependency on Cluster Desired Stack ID (ncole)
Date Wed, 31 May 2017 20:13:02 GMT
http://git-wip-us.apache.org/repos/asf/ambari/blob/a45f5427/ambari-server/src/test/java/org/apache/ambari/server/controller/KerberosHelperTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/KerberosHelperTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/KerberosHelperTest.java
index 8cfe258..4045ad3 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/KerberosHelperTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/KerberosHelperTest.java
@@ -341,11 +341,6 @@ public class KerberosHelperTest extends EasyMockSupport {
   }
 
   @Test
-  public void testEnableKerberos_UpgradeFromAmbari170KerberizedCluster() throws Exception {
-    testEnableKerberos_UpgradeFromAmbari170KerberizedCluster(new PrincipalKeyCredential("principal", "password"), "mit-kdc", "true");
-  }
-
-  @Test
   public void testEnableKerberos_ManageIdentitiesFalseKdcNone() throws Exception {
     testEnableKerberos(new PrincipalKeyCredential("principal", "password"), "none", "false");
   }
@@ -957,197 +952,12 @@ public class KerberosHelperTest extends EasyMockSupport {
     }
   }
 
-
-  private void testEnableKerberos_UpgradeFromAmbari170KerberizedCluster(final PrincipalKeyCredential PrincipalKeyCredential,
-                                                                        String kdcType,
-                                                                        String manageIdentities) throws Exception {
-
-    KerberosHelper kerberosHelper = injector.getInstance(KerberosHelper.class);
-    boolean identitiesManaged = (manageIdentities == null) || !"false".equalsIgnoreCase(manageIdentities);
-
-    final ServiceComponentHost schKerberosClient = createMock(ServiceComponentHost.class);
-    expect(schKerberosClient.getServiceName()).andReturn(Service.Type.KERBEROS.name()).anyTimes();
-    expect(schKerberosClient.getServiceComponentName()).andReturn(Role.KERBEROS_CLIENT.name()).anyTimes();
-    expect(schKerberosClient.getSecurityState()).andReturn(SecurityState.UNSECURED).anyTimes();
-    expect(schKerberosClient.getDesiredSecurityState()).andReturn(SecurityState.UNSECURED).anyTimes();
-    expect(schKerberosClient.getHostName()).andReturn("host1").anyTimes();
-    expect(schKerberosClient.getState()).andReturn(State.INSTALLED).anyTimes();
-
-    final ServiceComponentHost sch1 = createMock(ServiceComponentHost.class);
-    expect(sch1.getServiceName()).andReturn("SERVICE1").anyTimes();
-    expect(sch1.getServiceComponentName()).andReturn("COMPONENT1").anyTimes();
-    expect(sch1.getSecurityState()).andReturn(SecurityState.SECURED_KERBEROS).anyTimes();
-    expect(sch1.getDesiredSecurityState()).andReturn(SecurityState.SECURED_KERBEROS).anyTimes();
-    expect(sch1.getHostName()).andReturn("host1").anyTimes();
-    expect(sch1.getState()).andReturn(State.INSTALLED).anyTimes();
-
-    sch1.setDesiredSecurityState(SecurityState.SECURED_KERBEROS);
-    expect(expectLastCall()).once();
-    sch1.setSecurityState(SecurityState.SECURING);
-    expect(expectLastCall()).once();
-
-    final ServiceComponentHost sch2 = createMock(ServiceComponentHost.class);
-    expect(sch2.getServiceName()).andReturn("SERVICE2").anyTimes();
-    expect(sch2.getServiceComponentName()).andReturn("COMPONENT2").anyTimes();
-    expect(sch2.getSecurityState()).andReturn(SecurityState.SECURED_KERBEROS).anyTimes();
-    expect(sch2.getDesiredSecurityState()).andReturn(SecurityState.SECURED_KERBEROS).anyTimes();
-    expect(sch2.getHostName()).andReturn("host1").anyTimes();
-    expect(sch2.getState()).andReturn(State.INSTALLED).anyTimes();
-
-    sch2.setDesiredSecurityState(SecurityState.SECURED_KERBEROS);
-    expect(expectLastCall()).once();
-    sch2.setSecurityState(SecurityState.SECURING);
-    expect(expectLastCall()).once();
-
-    final Host host = createMockHost("host1");
-
-    final ServiceComponent serviceComponentKerberosClient = createNiceMock(ServiceComponent.class);
-    expect(serviceComponentKerberosClient.getName()).andReturn(Role.KERBEROS_CLIENT.name()).anyTimes();
-    expect(serviceComponentKerberosClient.getServiceComponentHosts()).andReturn(Collections.singletonMap("host1", schKerberosClient)).anyTimes();
-
-    final Service serviceKerberos = createStrictMock(Service.class);
-    expect(serviceKerberos.getName()).andReturn(Service.Type.KERBEROS.name()).anyTimes();
-    expect(serviceKerberos.getServiceComponents())
-        .andReturn(Collections.singletonMap(Role.KERBEROS_CLIENT.name(), serviceComponentKerberosClient))
-        .times(1);
-    serviceKerberos.setSecurityState(SecurityState.SECURED_KERBEROS);
-    expectLastCall().once();
-
-    final Service service1 = createStrictMock(Service.class);
-    expect(service1.getName()).andReturn("SERVICE1").anyTimes();
-    expect(service1.getServiceComponents())
-        .andReturn(Collections.<String, ServiceComponent>emptyMap())
-        .times(1);
-    service1.setSecurityState(SecurityState.SECURED_KERBEROS);
-    expectLastCall().once();
-
-    final Service service2 = createStrictMock(Service.class);
-    expect(service2.getName()).andReturn("SERVICE2").anyTimes();
-    expect(service2.getServiceComponents())
-        .andReturn(Collections.<String, ServiceComponent>emptyMap())
-        .times(1);
-    service2.setSecurityState(SecurityState.SECURED_KERBEROS);
-    expectLastCall().once();
-
-    final Map<String, String> kerberosEnvProperties = createMock(Map.class);
-    expect(kerberosEnvProperties.get("kdc_type")).andReturn(kdcType).anyTimes();
-    expect(kerberosEnvProperties.get("manage_identities")).andReturn(manageIdentities).anyTimes();
-    expect(kerberosEnvProperties.get("realm")).andReturn("FOOBAR.COM").anyTimes();
-    expect(kerberosEnvProperties.get("create_ambari_principal")).andReturn("false").anyTimes();
-
-    final Config kerberosEnvConfig = createMock(Config.class);
-    expect(kerberosEnvConfig.getProperties()).andReturn(kerberosEnvProperties).anyTimes();
-
-    final Map<String, String> krb5ConfProperties = createMock(Map.class);
-
-    final Config krb5ConfConfig = createMock(Config.class);
-    expect(krb5ConfConfig.getProperties()).andReturn(krb5ConfProperties).anyTimes();
-
-    final Cluster cluster = createMockCluster("c1", Collections.singleton(host), SecurityType.KERBEROS, krb5ConfConfig, kerberosEnvConfig);
-    expect(cluster.getServices())
-        .andReturn(new HashMap<String, Service>() {
-          {
-            put(Service.Type.KERBEROS.name(), serviceKerberos);
-            put("SERVICE1", service1);
-            put("SERVICE2", service2);
-          }
-        })
-        .anyTimes();
-    expect(cluster.getServiceComponentHosts("host1"))
-        .andReturn(new ArrayList<ServiceComponentHost>() {
-          {
-            add(schKerberosClient);
-            add(sch1);
-            add(sch2);
-          }
-        })
-        .once();
-
-    if (identitiesManaged) {
-      final Clusters clusters = injector.getInstance(Clusters.class);
-      expect(clusters.getHost("host1"))
-          .andReturn(host)
-          .once();
-    }
-    expect(cluster.getServiceComponentHosts("KERBEROS", "KERBEROS_CLIENT"))
-        .andReturn(Collections.singletonList(schKerberosClient))
-        .once();
-
-    final AmbariManagementController ambariManagementController = injector.getInstance(AmbariManagementController.class);
-    expect(ambariManagementController.findConfigurationTagsWithOverrides(cluster, null))
-        .andReturn(Collections.<String, Map<String, String>>emptyMap())
-        .once();
-    expect(ambariManagementController.getRoleCommandOrder(cluster))
-        .andReturn(createMock(RoleCommandOrder.class))
-        .once();
-
-    final KerberosServiceDescriptor serviceDescriptor1 = createMock(KerberosServiceDescriptor.class);
-
-    final KerberosServiceDescriptor serviceDescriptor2 = createMock(KerberosServiceDescriptor.class);
-
-    final KerberosDescriptor kerberosDescriptor = createMock(KerberosDescriptor.class);
-    expect(kerberosDescriptor.getService("KERBEROS")).andReturn(null).once();
-    expect(kerberosDescriptor.getService("SERVICE1")).andReturn(serviceDescriptor1).once();
-    expect(kerberosDescriptor.getService("SERVICE2")).andReturn(serviceDescriptor2).once();
-
-    setupKerberosDescriptor(kerberosDescriptor, 1);
-    setupStageFactory();
-
-    // This is a STRICT mock to help ensure that the end result is what we want.
-    final RequestStageContainer requestStageContainer = createStrictMock(RequestStageContainer.class);
-    // Create Preparation Stage
-    expect(requestStageContainer.getLastStageId()).andReturn(-1L).anyTimes();
-    expect(requestStageContainer.getId()).andReturn(1L).once();
-    requestStageContainer.addStages(EasyMock.<List<Stage>>anyObject());
-    expectLastCall().once();
-
-    if (identitiesManaged) {
-      // Create Principals Stage
-      expect(requestStageContainer.getLastStageId()).andReturn(-1L).anyTimes();
-      expect(requestStageContainer.getId()).andReturn(1L).once();
-      requestStageContainer.addStages(EasyMock.<List<Stage>>anyObject());
-      expectLastCall().once();
-      // Create Keytabs Stage
-      expect(requestStageContainer.getLastStageId()).andReturn(0L).anyTimes();
-      expect(requestStageContainer.getId()).andReturn(1L).once();
-      requestStageContainer.addStages(EasyMock.<List<Stage>>anyObject());
-      expectLastCall().once();
-      // Distribute Keytabs Stage
-      expect(requestStageContainer.getLastStageId()).andReturn(1L).anyTimes();
-      expect(requestStageContainer.getId()).andReturn(1L).once();
-      requestStageContainer.addStages(EasyMock.<List<Stage>>anyObject());
-      expectLastCall().once();
-    }
-    // Update Configs Stage
-    expect(requestStageContainer.getLastStageId()).andReturn(2L).anyTimes();
-    expect(requestStageContainer.getId()).andReturn(1L).once();
-    requestStageContainer.addStages(EasyMock.<List<Stage>>anyObject());
-    expectLastCall().once();
-    // TODO: Add more of these when more stages are added.
-    // Clean-up/Finalize Stage
-    expect(requestStageContainer.getLastStageId()).andReturn(3L).anyTimes();
-    expect(requestStageContainer.getId()).andReturn(1L).once();
-    requestStageContainer.addStages(EasyMock.<List<Stage>>anyObject());
-    expectLastCall().once();
-
-    replayAll();
-
-    // Needed by infrastructure
-    metaInfo.init();
-
-    CredentialStoreService credentialStoreService = injector.getInstance(CredentialStoreService.class);
-    credentialStoreService.setCredential(cluster.getClusterName(), KerberosHelper.KDC_ADMINISTRATOR_CREDENTIAL_ALIAS,
-        PrincipalKeyCredential, CredentialStoreType.TEMPORARY);
-
-    kerberosHelper.toggleKerberos(cluster, SecurityType.KERBEROS, requestStageContainer, null);
-
-    verifyAll();
-  }
-
   private void testEnableKerberos(final PrincipalKeyCredential PrincipalKeyCredential,
                                   String kdcType,
                                   String manageIdentities) throws Exception {
 
+    StackId stackId = new StackId("HDP", "2.2");
+
     KerberosHelper kerberosHelper = injector.getInstance(KerberosHelper.class);
     boolean identitiesManaged = (manageIdentities == null) || !"false".equalsIgnoreCase(manageIdentities);
 
@@ -1192,6 +1002,7 @@ public class KerberosHelperTest extends EasyMockSupport {
     expect(serviceComponentKerberosClient.getServiceComponentHosts()).andReturn(Collections.singletonMap("host1", schKerberosClient)).anyTimes();
 
     final Service serviceKerberos = createStrictMock(Service.class);
+    expect(serviceKerberos.getDesiredStackId()).andReturn(stackId).anyTimes();
     expect(serviceKerberos.getName()).andReturn(Service.Type.KERBEROS.name()).anyTimes();
     expect(serviceKerberos.getServiceComponents())
         .andReturn(Collections.singletonMap(Role.KERBEROS_CLIENT.name(), serviceComponentKerberosClient))
@@ -1200,6 +1011,7 @@ public class KerberosHelperTest extends EasyMockSupport {
     expectLastCall().once();
 
     final Service service1 = createStrictMock(Service.class);
+    expect(service1.getDesiredStackId()).andReturn(stackId).anyTimes();
     expect(service1.getName()).andReturn("SERVICE1").anyTimes();
     expect(service1.getServiceComponents())
         .andReturn(Collections.<String, ServiceComponent>emptyMap())
@@ -1209,6 +1021,7 @@ public class KerberosHelperTest extends EasyMockSupport {
 
     final Service service2 = createStrictMock(Service.class);
     expect(service2.getName()).andReturn("SERVICE2").anyTimes();
+    expect(service2.getDesiredStackId()).andReturn(stackId).anyTimes();
     expect(service2.getServiceComponents())
         .andReturn(Collections.<String, ServiceComponent>emptyMap())
         .times(1);
@@ -1375,6 +1188,7 @@ public class KerberosHelperTest extends EasyMockSupport {
     expect(serviceComponentKerberosClient.getServiceComponentHosts()).andReturn(Collections.singletonMap("host1", schKerberosClient)).anyTimes();
 
     final Service serviceKerberos = createNiceMock(Service.class);
+    expect(serviceKerberos.getDesiredStackId()).andReturn(new StackId("HDP-2.2"));
     expect(serviceKerberos.getName()).andReturn(Service.Type.KERBEROS.name()).anyTimes();
     expect(serviceKerberos.getServiceComponents())
         .andReturn(Collections.singletonMap(Role.KERBEROS_CLIENT.name(), serviceComponentKerberosClient))
@@ -1383,6 +1197,7 @@ public class KerberosHelperTest extends EasyMockSupport {
     expectLastCall().once();
 
     final Service service1 = createNiceMock(Service.class);
+    expect(service1.getDesiredStackId()).andReturn(new StackId("HDP-2.2"));
     expect(service1.getName()).andReturn("SERVICE1").anyTimes();
     expect(service1.getServiceComponents())
         .andReturn(Collections.<String, ServiceComponent>emptyMap())
@@ -1391,6 +1206,7 @@ public class KerberosHelperTest extends EasyMockSupport {
     expectLastCall().once();
 
     final Service service2 = createNiceMock(Service.class);
+    expect(service2.getDesiredStackId()).andReturn(new StackId("HDP-2.2"));
     expect(service2.getName()).andReturn("SERVICE2").anyTimes();
     expect(service2.getServiceComponents())
         .andReturn(Collections.<String, ServiceComponent>emptyMap())
@@ -1578,18 +1394,21 @@ public class KerberosHelperTest extends EasyMockSupport {
     expect(serviceComponentKerberosClient.getServiceComponentHosts()).andReturn(map).anyTimes();
 
     final Service serviceKerberos = createStrictMock(Service.class);
+    expect(serviceKerberos.getDesiredStackId()).andReturn(new StackId("HDP-2.2"));
     expect(serviceKerberos.getName()).andReturn(Service.Type.KERBEROS.name()).anyTimes();
     expect(serviceKerberos.getServiceComponents())
         .andReturn(Collections.singletonMap(Role.KERBEROS_CLIENT.name(), serviceComponentKerberosClient))
         .times(1);
 
     final Service service1 = createStrictMock(Service.class);
+    expect(service1.getDesiredStackId()).andReturn(new StackId("HDP-2.2"));
     expect(service1.getName()).andReturn("SERVICE1").anyTimes();
     expect(service1.getServiceComponents())
         .andReturn(Collections.<String, ServiceComponent>emptyMap())
         .times(1);
 
     final Service service2 = createStrictMock(Service.class);
+    expect(service2.getDesiredStackId()).andReturn(new StackId("HDP-2.2"));
     expect(service2.getName()).andReturn("SERVICE2").anyTimes();
     expect(service2.getServiceComponents())
         .andReturn(Collections.<String, ServiceComponent>emptyMap())
@@ -2282,6 +2101,9 @@ public class KerberosHelperTest extends EasyMockSupport {
 
     final Cluster cluster = createMockCluster("c1", hosts, SecurityType.KERBEROS, krb5ConfConfig, kerberosEnvConfig);
     expect(cluster.getServices()).andReturn(services).anyTimes();
+    expect(cluster.getService("SERVICE1")).andReturn(service1).atLeastOnce();
+    expect(cluster.getService("SERVICE2")).andReturn(service2).atLeastOnce();
+    expect(cluster.getService("SERVICE3")).andReturn(service3).atLeastOnce();
     expect(cluster.getServiceComponentHostMap(EasyMock.<Set<String>>anyObject(), EasyMock.<Set<String>>anyObject())).andReturn(serviceComponentHostMap).anyTimes();
 
     final Map<String, Map<String, String>> existingConfigurations = new HashMap<String, Map<String, String>>() {
@@ -2521,7 +2343,7 @@ public class KerberosHelperTest extends EasyMockSupport {
     servicesMap.put("SERVICE2", service2);
 
     Cluster cluster = createMockCluster(clusterName, Arrays.asList(host1, host2, host3), SecurityType.KERBEROS, configKrb5Conf, configKerberosEnv);
-    expect(cluster.getServices()).andReturn(servicesMap).times(1);
+    expect(cluster.getServices()).andReturn(servicesMap).times(2);
 
     Map<String, String> kerberosDescriptorProperties = new HashMap<>();
     kerberosDescriptorProperties.put("additional_realms", "");
@@ -2728,7 +2550,7 @@ public class KerberosHelperTest extends EasyMockSupport {
     servicesMap.put("SERVICE1", service1);
 
     Cluster cluster = createMockCluster("c1", Arrays.asList(host1), SecurityType.KERBEROS, configKrb5Conf, configKerberosEnv);
-    expect(cluster.getServices()).andReturn(servicesMap).times(1);
+    expect(cluster.getServices()).andReturn(servicesMap).times(2);
 
     Map<String, String> kerberosDescriptorProperties = new HashMap<>();
     kerberosDescriptorProperties.put("additional_realms", "");
@@ -2869,18 +2691,21 @@ public class KerberosHelperTest extends EasyMockSupport {
     ).anyTimes();
 
     final Service serviceKerberos = createStrictMock(Service.class);
+    expect(serviceKerberos.getDesiredStackId()).andReturn(new StackId("HDP-2.2"));
     expect(serviceKerberos.getName()).andReturn(Service.Type.KERBEROS.name()).anyTimes();
     expect(serviceKerberos.getServiceComponents())
         .andReturn(Collections.singletonMap(Role.KERBEROS_CLIENT.name(), serviceComponentKerberosClient))
         .times(1);
 
     final Service service1 = createStrictMock(Service.class);
+    expect(service1.getDesiredStackId()).andReturn(new StackId("HDP-2.2"));
     expect(service1.getName()).andReturn("SERVICE1").anyTimes();
     expect(service1.getServiceComponents())
         .andReturn(Collections.<String, ServiceComponent>emptyMap())
         .times(1);
 
     final Service service2 = createStrictMock(Service.class);
+    expect(service2.getDesiredStackId()).andReturn(new StackId("HDP-2.2"));
     expect(service2.getName()).andReturn("SERVICE2").anyTimes();
     expect(service2.getServiceComponents())
         .andReturn(Collections.<String, ServiceComponent>emptyMap())
@@ -3114,18 +2939,21 @@ public class KerberosHelperTest extends EasyMockSupport {
     expect(serviceComponentKerberosClient.getServiceComponentHosts()).andReturn(Collections.singletonMap("host1", schKerberosClient)).anyTimes();
 
     final Service serviceKerberos = createStrictMock(Service.class);
+    expect(serviceKerberos.getDesiredStackId()).andReturn(new StackId("HDP-2.2"));
     expect(serviceKerberos.getName()).andReturn(Service.Type.KERBEROS.name()).anyTimes();
     expect(serviceKerberos.getServiceComponents())
         .andReturn(Collections.singletonMap(Role.KERBEROS_CLIENT.name(), serviceComponentKerberosClient))
         .times(1);
 
     final Service service1 = createStrictMock(Service.class);
+    expect(service1.getDesiredStackId()).andReturn(new StackId("HDP-2.2"));
     expect(service1.getName()).andReturn("SERVICE1").anyTimes();
     expect(service1.getServiceComponents())
         .andReturn(Collections.<String, ServiceComponent>emptyMap())
         .times(1);
 
     final Service service2 = createStrictMock(Service.class);
+    expect(service2.getDesiredStackId()).andReturn(new StackId("HDP-2.2"));
     expect(service2.getName()).andReturn("SERVICE2").anyTimes();
     expect(service2.getServiceComponents())
         .andReturn(Collections.<String, ServiceComponent>emptyMap())
@@ -3317,18 +3145,21 @@ public class KerberosHelperTest extends EasyMockSupport {
       expect(serviceComponentKerberosClient.getServiceComponentHosts()).andReturn(Collections.singletonMap("host1", schKerberosClient)).anyTimes();
 
       final Service serviceKerberos = createStrictMock(Service.class);
+      expect(serviceKerberos.getDesiredStackId()).andReturn(new StackId("HDP-2.2"));
       expect(serviceKerberos.getName()).andReturn(Service.Type.KERBEROS.name()).anyTimes();
       expect(serviceKerberos.getServiceComponents())
           .andReturn(Collections.singletonMap(Role.KERBEROS_CLIENT.name(), serviceComponentKerberosClient))
           .times(2);
 
       final Service service1 = createStrictMock(Service.class);
+      expect(service1.getDesiredStackId()).andReturn(new StackId("HDP-2.2"));
       expect(service1.getName()).andReturn("SERVICE1").anyTimes();
       expect(service1.getServiceComponents())
           .andReturn(Collections.<String, ServiceComponent>emptyMap())
           .times(2);
 
       final Service service2 = createStrictMock(Service.class);
+      expect(service2.getDesiredStackId()).andReturn(new StackId("HDP-2.2"));
       expect(service2.getName()).andReturn("SERVICE2").anyTimes();
       expect(service2.getServiceComponents())
           .andReturn(Collections.<String, ServiceComponent>emptyMap())
@@ -3477,18 +3308,21 @@ public class KerberosHelperTest extends EasyMockSupport {
     expect(serviceComponentKerberosClient.getServiceComponentHosts()).andReturn(Collections.singletonMap("host1", schKerberosClient)).anyTimes();
 
     final Service serviceKerberos = createStrictMock(Service.class);
+    expect(serviceKerberos.getDesiredStackId()).andReturn(new StackId("HDP-2.2"));
     expect(serviceKerberos.getName()).andReturn(Service.Type.KERBEROS.name()).anyTimes();
     expect(serviceKerberos.getServiceComponents())
         .andReturn(Collections.singletonMap(Role.KERBEROS_CLIENT.name(), serviceComponentKerberosClient))
         .times(2);
 
     final Service service1 = createStrictMock(Service.class);
+    expect(service1.getDesiredStackId()).andReturn(new StackId("HDP-2.2"));
     expect(service1.getName()).andReturn("SERVICE1").anyTimes();
     expect(service1.getServiceComponents())
         .andReturn(Collections.<String, ServiceComponent>emptyMap())
         .times(2);
 
     final Service service2 = createStrictMock(Service.class);
+    expect(service2.getDesiredStackId()).andReturn(new StackId("HDP-2.2"));
     expect(service2.getName()).andReturn("SERVICE2").anyTimes();
     expect(service2.getServiceComponents())
         .andReturn(Collections.<String, ServiceComponent>emptyMap())
@@ -3639,18 +3473,21 @@ public class KerberosHelperTest extends EasyMockSupport {
     expect(serviceComponentKerberosClient.getServiceComponentHosts()).andReturn(Collections.singletonMap("host1", schKerberosClient1)).anyTimes();
 
     final Service serviceKerberos = createStrictMock(Service.class);
+    expect(serviceKerberos.getDesiredStackId()).andReturn(new StackId("HDP-2.2"));
     expect(serviceKerberos.getName()).andReturn(Service.Type.KERBEROS.name()).anyTimes();
     expect(serviceKerberos.getServiceComponents())
         .andReturn(Collections.singletonMap(Role.KERBEROS_CLIENT.name(), serviceComponentKerberosClient))
         .anyTimes();
 
     final Service service1 = createStrictMock(Service.class);
+    expect(service1.getDesiredStackId()).andReturn(new StackId("HDP-2.2"));
     expect(service1.getName()).andReturn("SERVICE1").anyTimes();
     expect(service1.getServiceComponents())
         .andReturn(Collections.<String, ServiceComponent>emptyMap())
         .anyTimes();
 
     final Service service2 = createStrictMock(Service.class);
+    expect(service2.getDesiredStackId()).andReturn(new StackId("HDP-2.2"));
     expect(service2.getName()).andReturn("SERVICE2").anyTimes();
     expect(service2.getServiceComponents())
         .andReturn(Collections.<String, ServiceComponent>emptyMap())
@@ -4006,6 +3843,7 @@ public class KerberosHelperTest extends EasyMockSupport {
 
   private Service createMockService(String serviceName, Map<String, ServiceComponent> componentMap) {
     Service service = createMock(Service.class);
+    expect(service.getDesiredStackId()).andReturn(new StackId("HDP-2.2")).anyTimes();
     expect(service.getName()).andReturn(serviceName).anyTimes();
     expect(service.getServiceComponents()).andReturn(componentMap).anyTimes();
     return service;

http://git-wip-us.apache.org/repos/asf/ambari/blob/a45f5427/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClientConfigResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClientConfigResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClientConfigResourceProviderTest.java
index 7b3837e..92a79ce 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClientConfigResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClientConfigResourceProviderTest.java
@@ -283,7 +283,6 @@ public class ClientConfigResourceProviderTest {
     expect(configHelper.getEffectiveDesiredTags(cluster, null)).andReturn(allConfigTags);
     expect(cluster.getClusterName()).andReturn(clusterName);
     expect(managementController.getHostComponents(EasyMock.<Set<ServiceComponentHostRequest>>anyObject())).andReturn(responses).anyTimes();
-    expect(cluster.getCurrentStackVersion()).andReturn(stackId);
 
     PowerMock.mockStaticPartial(StageUtils.class, "getClusterHostInfo");
     Map<String, Set<String>> clusterHostInfo = new HashMap<>();
@@ -319,6 +318,10 @@ public class ClientConfigResourceProviderTest {
     expect(cluster.getDesiredConfigs()).andReturn(desiredConfigMap);
     expect(clusters.getHost(hostName)).andReturn(host);
 
+    expect(cluster.getService(serviceName)).andReturn(service).atLeastOnce();
+    expect(service.getServiceComponent(componentName)).andReturn(serviceComponent).atLeastOnce();
+    expect(serviceComponent.getDesiredStackId()).andReturn(stackId).atLeastOnce();
+
     HashMap<String, String> rcaParams = new HashMap<>();
     rcaParams.put("key","value");
     expect(managementController.getRcaParameters()).andReturn(rcaParams).anyTimes();
@@ -534,7 +537,6 @@ public class ClientConfigResourceProviderTest {
     expect(configHelper.getEffectiveDesiredTags(cluster, null)).andReturn(allConfigTags);
     expect(cluster.getClusterName()).andReturn(clusterName);
     expect(managementController.getHostComponents(EasyMock.<Set<ServiceComponentHostRequest>>anyObject())).andReturn(responses).anyTimes();
-    expect(cluster.getCurrentStackVersion()).andReturn(stackId);
 
     PowerMock.mockStaticPartial(StageUtils.class, "getClusterHostInfo");
     Map<String, Set<String>> clusterHostInfo = new HashMap<>();
@@ -570,6 +572,10 @@ public class ClientConfigResourceProviderTest {
     expect(cluster.getDesiredConfigs()).andReturn(desiredConfigMap);
     expect(clusters.getHost(hostName)).andReturn(host);
 
+    expect(cluster.getService(serviceName)).andReturn(service).atLeastOnce();
+    expect(service.getServiceComponent(componentName)).andReturn(serviceComponent).atLeastOnce();
+    expect(serviceComponent.getDesiredStackId()).andReturn(stackId).atLeastOnce();
+
     HashMap<String, String> rcaParams = new HashMap<>();
     rcaParams.put("key","value");
     expect(managementController.getRcaParameters()).andReturn(rcaParams).anyTimes();

http://git-wip-us.apache.org/repos/asf/ambari/blob/a45f5427/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ComponentResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ComponentResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ComponentResourceProviderTest.java
index 03e3e66..647206e 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ComponentResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ComponentResourceProviderTest.java
@@ -231,10 +231,12 @@ public class ComponentResourceProviderTest {
     expect(managementController.getClusters()).andReturn(clusters);
     expect(managementController.getAmbariMetaInfo()).andReturn(ambariMetaInfo);
     expect(clusters.getCluster("Cluster100")).andReturn(cluster).anyTimes();
-    expect(cluster.getDesiredStackVersion()).andReturn(stackId);
     expect(serviceComponent1.getName()).andReturn("Component100");
+    expect(serviceComponent1.getDesiredStackId()).andReturn(stackId).anyTimes();
     expect(serviceComponent2.getName()).andReturn("Component101");
+    expect(serviceComponent2.getDesiredStackId()).andReturn(stackId).anyTimes();
     expect(serviceComponent3.getName()).andReturn("Component102");
+    expect(serviceComponent3.getDesiredStackId()).andReturn(stackId).anyTimes();
 
     expect(cluster.getServices()).andReturn(Collections.singletonMap("Service100", service)).anyTimes();
 
@@ -389,7 +391,6 @@ public class ComponentResourceProviderTest {
         capture(EasyMock.<ServiceComponentHost>newCapture()))).andReturn(MaintenanceState.OFF).anyTimes();
 
     expect(clusters.getCluster("Cluster100")).andReturn(cluster).anyTimes();
-    expect(cluster.getDesiredStackVersion()).andReturn(stackId);
 
     expect(cluster.getService("Service100")).andReturn(service).anyTimes();
     expect(service.getName()).andReturn("Service100").anyTimes();
@@ -398,8 +399,11 @@ public class ComponentResourceProviderTest {
     expect(service.getServiceComponent("Component103")).andReturn(serviceComponent2).anyTimes();
 
     expect(serviceComponent1.getName()).andReturn("Component101").anyTimes();
+    expect(serviceComponent1.getDesiredStackId()).andReturn(stackId).anyTimes();
     expect(serviceComponent2.getName()).andReturn("Component102").anyTimes();
+    expect(serviceComponent2.getDesiredStackId()).andReturn(stackId).anyTimes();
     expect(serviceComponent3.getName()).andReturn("Component103").anyTimes();
+    expect(serviceComponent3.getDesiredStackId()).andReturn(stackId).anyTimes();
 
     expect(cluster.getServices()).andReturn(Collections.singletonMap("Service100", service)).anyTimes();
     expect(cluster.getClusterId()).andReturn(2L).anyTimes();
@@ -701,7 +705,6 @@ public class ComponentResourceProviderTest {
 
     expect(clusters.getCluster("Cluster100")).andReturn(cluster).anyTimes();
 
-    expect(cluster.getDesiredStackVersion()).andReturn(stackId);
     expect(cluster.getResourceId()).andReturn(4l).atLeastOnce();
     expect(cluster.getServices()).andReturn(Collections.singletonMap("Service100", service)).anyTimes();
     expect(cluster.getClusterId()).andReturn(2L).anyTimes();
@@ -712,6 +715,7 @@ public class ComponentResourceProviderTest {
 
     expect(serviceComponent1.getName()).andReturn("Component101").atLeastOnce();
     expect(serviceComponent1.isRecoveryEnabled()).andReturn(false).atLeastOnce();
+    expect(serviceComponent1.getDesiredStackId()).andReturn(stackId).anyTimes();
     serviceComponent1.setRecoveryEnabled(true);
     expectLastCall().once();
 
@@ -805,13 +809,13 @@ public class ComponentResourceProviderTest {
     // getComponents
     expect(clusters.getCluster("cluster1")).andReturn(cluster);
     expect(cluster.getService("service1")).andReturn(service);
-    expect(cluster.getDesiredStackVersion()).andReturn(stackId).anyTimes();
     expect(service.getName()).andReturn("service1").anyTimes();
     expect(service.getServiceComponent("component1")).andReturn(component);
 
     expect(ambariMetaInfo.getComponent("stackName", "1", "service1", "component1")).andReturn(componentInfo);
     expect(componentInfo.getCategory()).andReturn(null);
 
+    expect(component.getDesiredStackId()).andReturn(stackId).anyTimes();
     expect(component.convertToResponse()).andReturn(response);
     // replay mocks
     replay(clusters, cluster, service, componentInfo, component, response, ambariMetaInfo, stackId, managementController);
@@ -893,7 +897,9 @@ public class ComponentResourceProviderTest {
     expect(service.getServiceComponent("component4")).andReturn(component2);
 
     expect(component1.convertToResponse()).andReturn(response1);
+    expect(component1.getDesiredStackId()).andReturn(stackId).anyTimes();
     expect(component2.convertToResponse()).andReturn(response2);
+    expect(component2.getDesiredStackId()).andReturn(stackId).anyTimes();
     // replay mocks
     replay(clusters, cluster, service, component3Info, component4Info, component1,  component2, response1,
         response2, ambariMetaInfo, stackId, managementController);

http://git-wip-us.apache.org/repos/asf/ambari/blob/a45f5427/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 b075b71..4138e3e 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;
 
@@ -1319,8 +1320,12 @@ public class HostResourceProviderTest extends EasyMockSupport {
       Map<String, Object> requestProperties = new HashMap<>();
       requestProperties.put(HostResourceProvider.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()));
   }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/a45f5427/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ServiceResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ServiceResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ServiceResourceProviderTest.java
index c82c884..49a3009 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ServiceResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ServiceResourceProviderTest.java
@@ -152,6 +152,7 @@ public class ServiceResourceProviderTest {
     properties.put(ServiceResourceProvider.SERVICE_CLUSTER_NAME_PROPERTY_ID, "Cluster100");
     properties.put(ServiceResourceProvider.SERVICE_SERVICE_NAME_PROPERTY_ID, "Service100");
     properties.put(ServiceResourceProvider.SERVICE_SERVICE_STATE_PROPERTY_ID, "INIT");
+    properties.put(ServiceResourceProvider.SERVICE_DESIRED_STACK_PROPERTY_ID, "HDP-1.1");
 
     propertySet.add(properties);
 
@@ -1157,6 +1158,8 @@ public class ServiceResourceProviderTest {
       RepositoryVersionEntity repositoryVersion = createNiceMock(RepositoryVersionEntity.class);
       expect(repositoryVersionDAO.findByStack(EasyMock.anyObject(StackId.class))).andReturn(
           Collections.singletonList(repositoryVersion)).atLeastOnce();
+      expect(repositoryVersion.getStackId()).andReturn(new StackId("HDP-2.2")).anyTimes();
+      replay(repositoryVersion);
     }
 
     replay(maintenanceStateHelperMock, repositoryVersionDAO);

http://git-wip-us.apache.org/repos/asf/ambari/blob/a45f5427/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/StackDefinedPropertyProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/StackDefinedPropertyProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/StackDefinedPropertyProviderTest.java
index 4d44576..ba24839 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/StackDefinedPropertyProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/StackDefinedPropertyProviderTest.java
@@ -57,11 +57,13 @@ import org.apache.ambari.server.events.publishers.AmbariEventPublisher;
 import org.apache.ambari.server.orm.GuiceJpaInitializer;
 import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
 import org.apache.ambari.server.orm.OrmTestHelper;
+import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
 import org.apache.ambari.server.security.TestAuthenticationFactory;
 import org.apache.ambari.server.security.authorization.AuthorizationException;
 import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Clusters;
 import org.apache.ambari.server.state.Host;
+import org.apache.ambari.server.state.Service;
 import org.apache.ambari.server.state.StackId;
 import org.apache.ambari.server.state.services.MetricsRetrievalService;
 import org.apache.ambari.server.state.stack.Metric;
@@ -136,7 +138,24 @@ public class StackDefinedPropertyProviderTest {
     Cluster cluster = clusters.getCluster("c2");
 
     cluster.setDesiredStackVersion(stackId);
-    helper.getOrCreateRepositoryVersion(stackId, stackId.getStackVersion());
+    RepositoryVersionEntity repositoryVersion = helper.getOrCreateRepositoryVersion(stackId, stackId.getStackVersion());
+    Service service = cluster.addService("HDFS", repositoryVersion);
+    service.addServiceComponent("NAMENODE");
+    service.addServiceComponent("DATANODE");
+    service.addServiceComponent("JOURNALNODE");
+
+    service = cluster.addService("YARN", repositoryVersion);
+    service.addServiceComponent("RESOURCEMANAGER");
+
+    service = cluster.addService("HBASE", repositoryVersion);
+    service.addServiceComponent("HBASE_MASTER");
+    service.addServiceComponent("HBASE_REGIONSERVER");
+
+    stackId = new StackId("HDP-2.1.1");
+    repositoryVersion = helper.getOrCreateRepositoryVersion(stackId, stackId.getStackVersion());
+
+    service = cluster.addService("STORM", repositoryVersion);
+    service.addServiceComponent("STORM_REST_API");
 
     clusters.addHost("h1");
     Host host = clusters.getHost("h1");

http://git-wip-us.apache.org/repos/asf/ambari/blob/a45f5427/ambari-server/src/test/java/org/apache/ambari/server/controller/logging/LoggingSearchPropertyProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/logging/LoggingSearchPropertyProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/logging/LoggingSearchPropertyProviderTest.java
index 1f2322c..1d19632 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/logging/LoggingSearchPropertyProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/logging/LoggingSearchPropertyProviderTest.java
@@ -44,6 +44,7 @@ import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Clusters;
 import org.apache.ambari.server.state.ComponentInfo;
 import org.apache.ambari.server.state.LogDefinition;
+import org.apache.ambari.server.state.Service;
 import org.apache.ambari.server.state.StackId;
 import org.easymock.Capture;
 import org.easymock.EasyMockSupport;
@@ -196,14 +197,17 @@ public class LoggingSearchPropertyProviderTest {
       LogDefinition logDefinitionMock =
           mockSupport.createMock(LogDefinition.class);
 
+      Service serviceMock = mockSupport.createNiceMock(Service.class);
+      expect(controllerMock.findServiceName(clusterMock, expectedComponentName)).andReturn(expectedServiceName).atLeastOnce();
+      expect(clusterMock.getService(expectedServiceName)).andReturn(serviceMock).anyTimes();
+      expect(serviceMock.getDesiredStackId()).andReturn(stackIdMock).anyTimes();
+
       expect(controllerMock.getAmbariServerURI(expectedSearchEnginePath)).
           andReturn(expectedAmbariURL + expectedSearchEnginePath).atLeastOnce();
       expect(controllerMock.getAmbariMetaInfo()).andReturn(metaInfoMock).atLeastOnce();
-      expect(metaInfoMock.getComponentToService(expectedStackName, expectedStackVersion, expectedComponentName)).andReturn(expectedServiceName).atLeastOnce();
       expect(metaInfoMock.getComponent(expectedStackName, expectedStackVersion, expectedServiceName, expectedComponentName)).andReturn(componentInfoMock).atLeastOnce();
       expect(stackIdMock.getStackName()).andReturn(expectedStackName).atLeastOnce();
       expect(stackIdMock.getStackVersion()).andReturn(expectedStackVersion).atLeastOnce();
-      expect(clusterMock.getCurrentStackVersion()).andReturn(stackIdMock).atLeastOnce();
 
       expect(componentInfoMock.getLogs()).andReturn(Collections.singletonList(logDefinitionMock)).atLeastOnce();
       expect(logDefinitionMock.getLogId()).andReturn(expectedLogSearchComponentName).atLeastOnce();
@@ -401,6 +405,11 @@ public class LoggingSearchPropertyProviderTest {
       LoggingRequestHelper loggingRequestHelperMock =
           mockSupport.createMock(LoggingRequestHelper.class);
 
+      Service serviceMock = mockSupport.createNiceMock(Service.class);
+      expect(controllerMock.findServiceName(clusterMock, expectedComponentName)).andReturn(expectedServiceName).atLeastOnce();
+      expect(clusterMock.getService(expectedServiceName)).andReturn(serviceMock).anyTimes();
+      expect(serviceMock.getDesiredStackId()).andReturn(stackIdMock).anyTimes();
+
       expect(dataRetrievalServiceMock.getLogFileNames(expectedLogSearchComponentName, "c6401.ambari.apache.org", "clusterone")).andReturn(Collections.singleton(expectedLogFilePath)).atLeastOnce();
       // return null, to simulate the case when the LogSearch service goes down, and the helper object
       // is not available to continue servicing the request.
@@ -413,7 +422,6 @@ public class LoggingSearchPropertyProviderTest {
           andReturn(expectedAmbariURL + expectedSearchEnginePath).atLeastOnce();
       expect(controllerMock.getAmbariMetaInfo()).andReturn(metaInfoMock).atLeastOnce();
 
-      expect(metaInfoMock.getComponentToService(expectedStackName, expectedStackVersion, expectedComponentName)).andReturn(expectedServiceName).atLeastOnce();
       expect(metaInfoMock.getComponent(expectedStackName, expectedStackVersion, expectedServiceName, expectedComponentName)).andReturn(componentInfoMock).atLeastOnce();
 
       expect(componentInfoMock.getLogs()).andReturn(Collections.singletonList(logDefinitionMock)).atLeastOnce();
@@ -421,9 +429,8 @@ public class LoggingSearchPropertyProviderTest {
 
       expect(stackIdMock.getStackName()).andReturn(expectedStackName).atLeastOnce();
       expect(stackIdMock.getStackVersion()).andReturn(expectedStackVersion).atLeastOnce();
-      expect(clusterMock.getCurrentStackVersion()).andReturn(stackIdMock).atLeastOnce();
     }
-    
+
     expect(controllerMock.getClusters()).andReturn(clustersMock).atLeastOnce();
     expect(clustersMock.getCluster("clusterone")).andReturn(clusterMock).atLeastOnce();
     expect(clusterMock.getResourceId()).andReturn(4L).atLeastOnce();
@@ -502,7 +509,7 @@ public class LoggingSearchPropertyProviderTest {
   public void testCheckWhenLogSearchNotAvailableAsClusterUser() throws Exception {
     testCheckWhenLogSearchNotAvailable(TestAuthenticationFactory.createClusterUser(), false);
   }
-  
+
   /**
    * Verifies that this property provider implementation will
    * properly handle the case of LogSearch not being deployed in
@@ -565,12 +572,16 @@ public class LoggingSearchPropertyProviderTest {
       LoggingRequestHelper loggingRequestHelperMock =
           mockSupport.createMock(LoggingRequestHelper.class);
 
+      Service serviceMock = mockSupport.createNiceMock(Service.class);
+      expect(controllerMock.findServiceName(clusterMock, expectedComponentName)).andReturn(expectedServiceName).atLeastOnce();
+      expect(clusterMock.getService(expectedServiceName)).andReturn(serviceMock).anyTimes();
+      expect(serviceMock.getDesiredStackId()).andReturn(stackIdMock).anyTimes();
+
+
       expect(controllerMock.getAmbariMetaInfo()).andReturn(metaInfoMock).atLeastOnce();
       expect(stackIdMock.getStackName()).andReturn(expectedStackName).atLeastOnce();
       expect(stackIdMock.getStackVersion()).andReturn(expectedStackVersion).atLeastOnce();
-      expect(clusterMock.getCurrentStackVersion()).andReturn(stackIdMock).atLeastOnce();
 
-      expect(metaInfoMock.getComponentToService(expectedStackName, expectedStackVersion, expectedComponentName)).andReturn(expectedServiceName).atLeastOnce();
       expect(metaInfoMock.getComponent(expectedStackName, expectedStackVersion, expectedServiceName, expectedComponentName)).andReturn(componentInfoMock).atLeastOnce();
 
       // simulate the case when LogSearch is not deployed, or is not available for some reason

http://git-wip-us.apache.org/repos/asf/ambari/blob/a45f5427/ambari-server/src/test/java/org/apache/ambari/server/controller/metrics/RestMetricsPropertyProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/metrics/RestMetricsPropertyProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/metrics/RestMetricsPropertyProviderTest.java
index 66e62a0..0587fa0 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/metrics/RestMetricsPropertyProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/metrics/RestMetricsPropertyProviderTest.java
@@ -52,6 +52,8 @@ import org.apache.ambari.server.controller.utilities.StreamProvider;
 import org.apache.ambari.server.events.publishers.AmbariEventPublisher;
 import org.apache.ambari.server.orm.GuiceJpaInitializer;
 import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
+import org.apache.ambari.server.orm.dao.StackDAO;
+import org.apache.ambari.server.orm.entities.StackEntity;
 import org.apache.ambari.server.security.TestAuthenticationFactory;
 import org.apache.ambari.server.security.authorization.AuthorizationException;
 import org.apache.ambari.server.state.Cluster;
@@ -115,9 +117,21 @@ public class RestMetricsPropertyProviderTest {
     injector = Guice.createInjector(new InMemoryDefaultTestModule());
     injector.getInstance(GuiceJpaInitializer.class);
     clusters = injector.getInstance(Clusters.class);
+    StackDAO stackDAO = injector.getInstance(StackDAO.class);
+
+
+    StackEntity stackEntity = new StackEntity();
+    stackEntity.setStackName("HDP");
+    stackEntity.setStackVersion("2.1.1");
+    stackDAO.create(stackEntity);
+
+
     clusters.addCluster("c1", new StackId("HDP-2.1.1"));
     c1 = clusters.getCluster("c1");
 
+
+
+
     // disable request TTL for these tests
     Configuration configuration = injector.getInstance(Configuration.class);
     configuration.setProperty(Configuration.METRIC_RETRIEVAL_SERVICE_REQUEST_TTL_ENABLED.getKey(),

http://git-wip-us.apache.org/repos/asf/ambari/blob/a45f5427/ambari-server/src/test/java/org/apache/ambari/server/controller/metrics/timeline/AMSPropertyProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/metrics/timeline/AMSPropertyProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/metrics/timeline/AMSPropertyProviderTest.java
index 24fd47b..258c774 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/metrics/timeline/AMSPropertyProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/metrics/timeline/AMSPropertyProviderTest.java
@@ -17,7 +17,6 @@
  */
 package org.apache.ambari.server.controller.metrics.timeline;
 
-import static org.apache.ambari.server.controller.metrics.MetricsServiceProvider.MetricsService;
 import static org.easymock.EasyMock.anyObject;
 import static org.easymock.EasyMock.createNiceMock;
 import static org.easymock.EasyMock.expect;
@@ -51,6 +50,7 @@ import org.apache.ambari.server.controller.internal.ResourceImpl;
 import org.apache.ambari.server.controller.internal.TemporalInfoImpl;
 import org.apache.ambari.server.controller.internal.URLStreamProvider;
 import org.apache.ambari.server.controller.metrics.MetricHostProvider;
+import org.apache.ambari.server.controller.metrics.MetricsServiceProvider.MetricsService;
 import org.apache.ambari.server.controller.metrics.ganglia.TestStreamProvider;
 import org.apache.ambari.server.controller.metrics.timeline.cache.TimelineMetricCache;
 import org.apache.ambari.server.controller.metrics.timeline.cache.TimelineMetricCacheEntryFactory;
@@ -66,6 +66,7 @@ import org.apache.ambari.server.security.authorization.internal.InternalAuthenti
 import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Clusters;
 import org.apache.ambari.server.state.ComponentInfo;
+import org.apache.ambari.server.state.Service;
 import org.apache.ambari.server.state.StackId;
 import org.apache.http.client.utils.URIBuilder;
 import org.easymock.EasyMock;
@@ -535,14 +536,14 @@ public class AMSPropertyProviderTest {
 
   @Test
   public void testPopulateMetricsForEmbeddedHBase() throws Exception {
-    AmbariManagementController ams = createNiceMock(AmbariManagementController.class);
+    AmbariManagementController amc = createNiceMock(AmbariManagementController.class);
     PowerMock.mockStatic(AmbariServer.class);
-    expect(AmbariServer.getController()).andReturn(ams).anyTimes();
+    expect(AmbariServer.getController()).andReturn(amc).anyTimes();
     AmbariMetaInfo ambariMetaInfo = createNiceMock(AmbariMetaInfo.class);
     Clusters clusters = createNiceMock(Clusters.class);
     Cluster cluster = createNiceMock(Cluster.class);
     ComponentInfo componentInfo = createNiceMock(ComponentInfo.class);
-    expect(ams.getClusters()).andReturn(clusters).anyTimes();
+    expect(amc.getClusters()).andReturn(clusters).anyTimes();
     expect(clusters.getCluster("HostRoles/cluster_name")).andReturn(cluster).anyTimes();
     expect(cluster.getResourceId()).andReturn(2L).anyTimes();
 
@@ -552,13 +553,19 @@ public class AMSPropertyProviderTest {
     } catch (AmbariException e) {
       e.printStackTrace();
     }
+
+    Service amsService = createNiceMock(Service.class);
+    expect(amsService.getDesiredStackId()).andReturn(stackId);
+    expect(amsService.getName()).andReturn("AMS");
+    expect(cluster.getServiceByComponentName("METRICS_COLLECTOR")).andReturn(amsService);
+
     expect(cluster.getCurrentStackVersion()).andReturn(stackId).anyTimes();
-    expect(ams.getAmbariMetaInfo()).andReturn(ambariMetaInfo).anyTimes();
+    expect(amc.getAmbariMetaInfo()).andReturn(ambariMetaInfo).anyTimes();
     expect(ambariMetaInfo.getComponentToService("HDP", "2.2", "METRICS_COLLECTOR")).andReturn("AMS").anyTimes();
     expect(ambariMetaInfo.getComponent("HDP", "2.2", "AMS", "METRICS_COLLECTOR"))
       .andReturn(componentInfo).anyTimes();
     expect(componentInfo.getTimelineAppid()).andReturn("AMS-HBASE");
-    replay(ams, clusters, cluster, ambariMetaInfo, componentInfo);
+    replay(amc, clusters, cluster, amsService, ambariMetaInfo, componentInfo);
     PowerMock.replayAll();
 
     TestStreamProvider streamProvider = new TestStreamProvider(EMBEDDED_METRICS_FILE_PATH);
@@ -609,15 +616,15 @@ public class AMSPropertyProviderTest {
 
   @Test
   public void testAggregateFunctionForComponentMetrics() throws Exception {
-    AmbariManagementController ams = createNiceMock(AmbariManagementController.class);
+    AmbariManagementController amc = createNiceMock(AmbariManagementController.class);
     PowerMock.mockStatic(AmbariServer.class);
-    expect(AmbariServer.getController()).andReturn(ams).anyTimes();
+    expect(AmbariServer.getController()).andReturn(amc).anyTimes();
     AmbariMetaInfo ambariMetaInfo = createNiceMock(AmbariMetaInfo.class);
     Clusters clusters = createNiceMock(Clusters.class);
     Cluster cluster = createNiceMock(Cluster.class);
     ComponentInfo componentInfo = createNiceMock(ComponentInfo.class);
     StackId stackId = new StackId("HDP", "2.2");
-    expect(ams.getClusters()).andReturn(clusters).anyTimes();
+    expect(amc.getClusters()).andReturn(clusters).anyTimes();
     expect(clusters.getCluster("HostRoles/cluster_name")).andReturn(cluster).anyTimes();
     expect(cluster.getResourceId()).andReturn(2L).anyTimes();
 
@@ -626,13 +633,20 @@ public class AMSPropertyProviderTest {
     } catch (AmbariException e) {
       e.printStackTrace();
     }
+
+    Service hbaseService = createNiceMock(Service.class);
+    expect(hbaseService.getDesiredStackId()).andReturn(stackId);
+    expect(hbaseService.getName()).andReturn("HBASE");
+    expect(cluster.getServiceByComponentName("HBASE_REGIONSERVER")).andReturn(hbaseService);
+
+
     expect(cluster.getCurrentStackVersion()).andReturn(stackId).anyTimes();
-    expect(ams.getAmbariMetaInfo()).andReturn(ambariMetaInfo).anyTimes();
+    expect(amc.getAmbariMetaInfo()).andReturn(ambariMetaInfo).anyTimes();
     expect(ambariMetaInfo.getComponentToService("HDP", "2.2", "HBASE_REGIONSERVER")).andReturn("HBASE").anyTimes();
     expect(ambariMetaInfo.getComponent("HDP", "2.2", "HBASE", "HBASE_REGIONSERVER"))
       .andReturn(componentInfo).anyTimes();
     expect(componentInfo.getTimelineAppid()).andReturn("HBASE");
-    replay(ams, clusters, cluster, ambariMetaInfo, componentInfo);
+    replay(amc, clusters, cluster, hbaseService, ambariMetaInfo, componentInfo);
     PowerMock.replayAll();
 
     TestStreamProvider streamProvider = new TestStreamProvider(AGGREGATE_METRICS_FILE_PATH);

http://git-wip-us.apache.org/repos/asf/ambari/blob/a45f5427/ambari-server/src/test/java/org/apache/ambari/server/events/EventsTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/events/EventsTest.java b/ambari-server/src/test/java/org/apache/ambari/server/events/EventsTest.java
index 710e4e7..c37ecfe 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/events/EventsTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/events/EventsTest.java
@@ -106,6 +106,7 @@ public class EventsTest {
 
     m_clusterName = "foo";
     StackId stackId = new StackId("HDP", STACK_VERSION);
+    m_helper.createStack(stackId);
 
     m_clusters.addCluster(m_clusterName, stackId);
     m_clusters.addHost(HOSTNAME);

http://git-wip-us.apache.org/repos/asf/ambari/blob/a45f5427/ambari-server/src/test/java/org/apache/ambari/server/events/listeners/upgrade/HostVersionOutOfSyncListenerTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/events/listeners/upgrade/HostVersionOutOfSyncListenerTest.java b/ambari-server/src/test/java/org/apache/ambari/server/events/listeners/upgrade/HostVersionOutOfSyncListenerTest.java
index 4ca2070..3ee3299 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/events/listeners/upgrade/HostVersionOutOfSyncListenerTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/events/listeners/upgrade/HostVersionOutOfSyncListenerTest.java
@@ -99,6 +99,9 @@ public class HostVersionOutOfSyncListenerTest {
     injector.injectMembers(this);
 
     StackId stackId = new StackId(this.stackId);
+
+    helper.createStack(stackId);
+
     clusters.addCluster("c1", stackId);
     c1 = clusters.getCluster("c1");
     addHost("h1");

http://git-wip-us.apache.org/repos/asf/ambari/blob/a45f5427/ambari-server/src/test/java/org/apache/ambari/server/metadata/RoleCommandOrderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/metadata/RoleCommandOrderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/metadata/RoleCommandOrderTest.java
index d2cc345..0e5254f 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/metadata/RoleCommandOrderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/metadata/RoleCommandOrderTest.java
@@ -60,6 +60,7 @@ import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 
+import com.google.common.collect.ImmutableMap;
 import com.google.inject.Guice;
 import com.google.inject.Injector;
 
@@ -92,21 +93,26 @@ public class RoleCommandOrderTest {
   @Test
   public void testInitializeAtGLUSTERFSCluster() throws AmbariException {
 
-
+    StackId stackId = new StackId("HDP", "2.0.6");
     ClusterImpl cluster = createMock(ClusterImpl.class);
     Service service = createMock(Service.class);
+    expect(service.getDesiredStackId()).andReturn(stackId);
     expect(cluster.getClusterId()).andReturn(1L);
-    expect(cluster.getCurrentStackVersion()).andReturn(new StackId("HDP", "2.0.6"));
     expect(cluster.getService("GLUSTERFS")).andReturn(service);
     expect(cluster.getService("HDFS")).andReturn(null);
     expect(cluster.getService("YARN")).andReturn(null);
-    replay(cluster);
+
+    expect(cluster.getServices()).andReturn(ImmutableMap.<String, Service>builder()
+        .put("GLUSTERFS", service)
+        .build()).atLeastOnce();
+
+    replay(cluster, service);
 
     RoleCommandOrder rco = roleCommandOrderProvider.getRoleCommandOrder(cluster);
 
     Map<RoleCommandPair, Set<RoleCommandPair>> deps = rco.getDependencies();
     assertTrue("Dependencies are loaded after initialization", deps.size() > 0);
-    verify(cluster);
+    verify(cluster, service);
 	// Check that HDFS components are not present in dependencies
     // Checking blocked roles
     assertFalse(dependenciesContainBlockedRole(deps, Role.DATANODE));
@@ -144,10 +150,13 @@ public class RoleCommandOrderTest {
     expect(cluster.getService("HDFS")).andReturn(hdfsService).atLeastOnce();
     expect(cluster.getService("YARN")).andReturn(null).atLeastOnce();
     expect(hdfsService.getServiceComponent("JOURNALNODE")).andReturn(null);
-    expect(cluster.getCurrentStackVersion()).andReturn(new StackId("HDP", "2.0.6"));
+    expect(hdfsService.getDesiredStackId()).andReturn(new StackId("HDP", "2.0.6"));
+//    expect(cluster.getCurrentStackVersion()).andReturn(new StackId("HDP", "2.0.6"));
+    expect(cluster.getServices()).andReturn(ImmutableMap.<String, Service>builder()
+        .put("HDFS", hdfsService)
+        .build()).anyTimes();
 
-    replay(cluster);
-    replay(hdfsService);
+    replay(cluster, hdfsService);
 
     RoleCommandOrder rco = roleCommandOrderProvider.getRoleCommandOrder(cluster);
     Map<RoleCommandPair, Set<RoleCommandPair>> deps = rco.getDependencies();
@@ -188,10 +197,13 @@ public class RoleCommandOrderTest {
     expect(cluster.getService("HDFS")).andReturn(hdfsService).atLeastOnce();
     expect(cluster.getService("YARN")).andReturn(null);
     expect(hdfsService.getServiceComponent("JOURNALNODE")).andReturn(journalnodeSC);
-    expect(cluster.getCurrentStackVersion()).andReturn(new StackId("HDP", "2.0.6"));
+    expect(hdfsService.getDesiredStackId()).andReturn(new StackId("HDP", "2.0.6"));
+//    expect(cluster.getCurrentStackVersion()).andReturn(new StackId("HDP", "2.0.6"));
+    expect(cluster.getServices()).andReturn(ImmutableMap.<String, Service>builder()
+        .put("HDFS", hdfsService)
+        .build()).anyTimes();
 
-    replay(cluster);
-    replay(hdfsService);
+    replay(cluster, hdfsService);
 
     RoleCommandOrder rco = roleCommandOrderProvider.getRoleCommandOrder(cluster);
     Map<RoleCommandPair, Set<RoleCommandPair>> deps = rco.getDependencies();
@@ -235,7 +247,11 @@ public class RoleCommandOrderTest {
     expect(cluster.getService("HDFS")).andReturn(null);
     expect(yarnService.getServiceComponent("RESOURCEMANAGER")).andReturn(resourcemanagerSC).anyTimes();
     expect(resourcemanagerSC.getServiceComponentHosts()).andReturn(hostComponents).anyTimes();
-    expect(cluster.getCurrentStackVersion()).andReturn(new StackId("HDP", "2.0.6"));
+//    expect(cluster.getCurrentStackVersion()).andReturn(new StackId("HDP", "2.0.6"));
+    expect(yarnService.getDesiredStackId()).andReturn(new StackId("HDP", "2.0.6"));
+    expect(cluster.getServices()).andReturn(ImmutableMap.<String, Service>builder()
+        .put("YARN", yarnService)
+        .build()).anyTimes();
 
     replay(cluster, yarnService, sch1, sch2, resourcemanagerSC);
 
@@ -286,8 +302,12 @@ public class RoleCommandOrderTest {
     expect(cluster.getService("YARN")).andReturn(yarnService).atLeastOnce();
     expect(cluster.getService("HDFS")).andReturn(null);
     expect(yarnService.getServiceComponent("RESOURCEMANAGER")).andReturn(resourcemanagerSC).anyTimes();
+    expect(yarnService.getDesiredStackId()).andReturn(new StackId("HDP", "2.0.6")).anyTimes();
     expect(resourcemanagerSC.getServiceComponentHosts()).andReturn(hostComponents).anyTimes();
-    expect(cluster.getCurrentStackVersion()).andReturn(new StackId("HDP", "2.0.6"));
+//    expect(cluster.getCurrentStackVersion()).andReturn(new StackId("HDP", "2.0.6"));
+    expect(cluster.getServices()).andReturn(ImmutableMap.<String, Service>builder()
+        .put("YARN", yarnService)
+        .build()).anyTimes();
 
     replay(cluster, yarnService, sch1, sch2, resourcemanagerSC);
 
@@ -380,7 +400,11 @@ public class RoleCommandOrderTest {
     expect(cluster.getService("YARN")).andReturn(null);
     expect(hdfsService.getServiceComponent("JOURNALNODE")).andReturn(null);
     //There is no rco file in this stack, should use default
-    expect(cluster.getCurrentStackVersion()).andReturn(new StackId("HDP", "2.0.5"));
+//    expect(cluster.getCurrentStackVersion()).andReturn(new StackId("HDP", "2.0.5"));
+    expect(hdfsService.getDesiredStackId()).andReturn(new StackId("HDP", "2.0.5"));
+    expect(cluster.getServices()).andReturn(ImmutableMap.<String, Service>builder()
+        .put("HDFS", hdfsService)
+        .build()).anyTimes();
 
     replay(cluster);
     replay(hdfsService);
@@ -420,12 +444,13 @@ public class RoleCommandOrderTest {
     installedServices.put("HBASE", hbaseService);
     expect(cluster.getServices()).andReturn(installedServices).atLeastOnce();
 
-
     expect(cluster.getService("HDFS")).andReturn(hdfsService).atLeastOnce();
     expect(cluster.getService("GLUSTERFS")).andReturn(null);
     expect(cluster.getService("YARN")).andReturn(null);
     expect(hdfsService.getServiceComponent("JOURNALNODE")).andReturn(null);
-    expect(cluster.getCurrentStackVersion()).andReturn(new StackId("HDP", "2.0.5"));
+//    expect(cluster.getCurrentStackVersion()).andReturn(new StackId("HDP", "2.0.5"));
+    expect(hdfsService.getDesiredStackId()).andReturn(new StackId("HDP", "2.0.5"));
+    expect(hbaseService.getDesiredStackId()).andReturn(new StackId("HDP", "2.0.5"));
 
     //replay
     replay(cluster, hdfsService, hbaseService, hbaseMaster, namenode);
@@ -466,12 +491,15 @@ public class RoleCommandOrderTest {
     expect(cluster.getService("HDFS")).andReturn(hdfsService).atLeastOnce();
     expect(cluster.getService("YARN")).andReturn(null).atLeastOnce();
     expect(hdfsService.getServiceComponent("JOURNALNODE")).andReturn(null);
+    expect(hdfsService.getDesiredStackId()).andReturn(new StackId("HDP", "2.2.0")).anyTimes();
+    expect(cluster.getServices()).andReturn(ImmutableMap.<String, Service>builder()
+        .put("HDFS", hdfsService)
+        .build()).anyTimes();
 
     // There is no rco file in this stack, should use default
-    expect(cluster.getCurrentStackVersion()).andReturn(new StackId("HDP", "2.2.0")).atLeastOnce();
+//    expect(cluster.getCurrentStackVersion()).andReturn(new StackId("HDP", "2.2.0")).atLeastOnce();
 
-    replay(cluster);
-    replay(hdfsService);
+    replay(cluster, hdfsService);
 
     RoleCommandOrder rco = roleCommandOrderProvider.getRoleCommandOrder(cluster);
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/a45f5427/ambari-server/src/test/java/org/apache/ambari/server/metadata/RoleGraphTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/metadata/RoleGraphTest.java b/ambari-server/src/test/java/org/apache/ambari/server/metadata/RoleGraphTest.java
index 303ee89..7659357 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/metadata/RoleGraphTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/metadata/RoleGraphTest.java
@@ -46,6 +46,7 @@ import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 
+import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Lists;
 import com.google.inject.Guice;
 import com.google.inject.Injector;
@@ -79,6 +80,12 @@ public class RoleGraphTest {
     when(cluster.getCurrentStackVersion()).thenReturn(new StackId("HDP-2.0.6"));
     when(cluster.getClusterId()).thenReturn(1L);
 
+    Service hdfsService = mock(Service.class);
+    when(hdfsService.getDesiredStackId()).thenReturn(new StackId("HDP-2.0.6"));
+    when (cluster.getServices()).thenReturn(ImmutableMap.<String, Service>builder()
+        .put("HDFS", hdfsService)
+        .build());
+
     RoleCommandOrder rco = roleCommandOrderProvider.getRoleCommandOrder(cluster);
 
     RoleGraphNode datanode_upgrade = new RoleGraphNode(Role.DATANODE, RoleCommand.UPGRADE);
@@ -166,6 +173,22 @@ public class RoleGraphTest {
     when(cluster.getCurrentStackVersion()).thenReturn(new StackId("HDP-2.0.6"));
     when(cluster.getClusterId()).thenReturn(1L);
 
+    Service hdfsService = mock(Service.class);
+    when(hdfsService.getDesiredStackId()).thenReturn(new StackId("HDP-2.0.6"));
+
+    Service zkService = mock(Service.class);
+    when(zkService.getDesiredStackId()).thenReturn(new StackId("HDP-2.0.6"));
+
+    Service hbaseService = mock(Service.class);
+    when(hbaseService.getDesiredStackId()).thenReturn(new StackId("HDP-2.0.6"));
+
+    when(cluster.getServices()).thenReturn(ImmutableMap.<String, Service>builder()
+        .put("HDFS", hdfsService)
+        .put("ZOOKEEPER", zkService)
+        .put("HBASE", hbaseService)
+        .build());
+
+
     RoleCommandOrder rco = roleCommandOrderProvider.getRoleCommandOrder(cluster);
     RoleGraph roleGraph = roleGraphFactory.createNew(rco);
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/a45f5427/ambari-server/src/test/java/org/apache/ambari/server/orm/OrmTestHelper.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/orm/OrmTestHelper.java b/ambari-server/src/test/java/org/apache/ambari/server/orm/OrmTestHelper.java
index 469e8c8..2fc2752 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/orm/OrmTestHelper.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/orm/OrmTestHelper.java
@@ -313,6 +313,20 @@ public class OrmTestHelper {
     hostDAO.merge(host2);
   }
 
+  @Transactional
+  public StackEntity createStack(StackId stackId) throws AmbariException {
+    StackEntity stackEntity = stackDAO.find(stackId.getStackName(), stackId.getStackVersion());
+
+    if (null == stackEntity) {
+      stackEntity = new StackEntity();
+      stackEntity.setStackName(stackId.getStackName());
+      stackEntity.setStackVersion(stackId.getStackVersion());
+      stackDAO.create(stackEntity);
+    }
+
+    return stackEntity;
+  }
+
   /**
    * Creates an empty cluster with an ID.
    *
@@ -386,6 +400,8 @@ public class OrmTestHelper {
     String clusterName = "cluster-" + System.currentTimeMillis();
     StackId stackId = new StackId("HDP", "2.0.6");
 
+    createStack(stackId);
+
     clusters.addCluster(clusterName, stackId);
     Cluster cluster = clusters.getCluster(clusterName);
     cluster = initializeClusterWithStack(cluster);
@@ -642,9 +658,12 @@ public class OrmTestHelper {
    */
   public RepositoryVersionEntity getOrCreateRepositoryVersion(StackId stackId,
       String version) {
-    StackDAO stackDAO = injector.getInstance(StackDAO.class);
-    StackEntity stackEntity = stackDAO.find(stackId.getStackName(),
-        stackId.getStackVersion());
+    StackEntity stackEntity = null;
+    try {
+      stackEntity = createStack(stackId);
+    } catch (Exception e) {
+      LOG.error("Expected successful repository", e);
+    }
 
     assertNotNull(stackEntity);
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/a45f5427/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/AutoSkipFailedSummaryActionTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/AutoSkipFailedSummaryActionTest.java b/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/AutoSkipFailedSummaryActionTest.java
index fbad1b1..60e76db 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/AutoSkipFailedSummaryActionTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/AutoSkipFailedSummaryActionTest.java
@@ -58,9 +58,11 @@ import org.apache.ambari.server.orm.entities.UpgradeItemEntity;
 import org.apache.ambari.server.serveraction.AbstractServerAction;
 import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Clusters;
+import org.apache.ambari.server.state.Service;
 import org.apache.ambari.server.state.ServiceComponentHostEvent;
 import org.apache.ambari.server.state.StackId;
 import org.apache.ambari.server.state.svccomphost.ServiceComponentHostOpInProgressEvent;
+import org.easymock.EasyMock;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -203,6 +205,18 @@ public class AutoSkipFailedSummaryActionTest {
     AutoSkipFailedSummaryAction action = new AutoSkipFailedSummaryAction();
     m_injector.injectMembers(action);
 
+    EasyMock.reset(clusterMock);
+
+    Service hdfsService = createNiceMock(Service.class);
+    expect(hdfsService.getName()).andReturn("HDFS").anyTimes();
+    expect(clusterMock.getServiceByComponentName("DATANODE")).andReturn(hdfsService).anyTimes();
+
+    Service zkService = createNiceMock(Service.class);
+    expect(zkService.getName()).andReturn("ZOOKEEPER").anyTimes();
+    expect(clusterMock.getServiceByComponentName("ZOOKEEPER_CLIENT")).andReturn(zkService).anyTimes();
+
+    replay(clusterMock, hdfsService, zkService);
+
     ServiceComponentHostEvent event = createNiceMock(ServiceComponentHostEvent.class);
 
     // Set mock for parent's getHostRoleCommand()
@@ -269,6 +283,7 @@ public class AutoSkipFailedSummaryActionTest {
     assertEquals("There were 3 skipped failure(s) that must be addressed " +
       "before you can proceed. Please resolve each failure before continuing with the upgrade.",
       result.getStdOut());
+
     assertEquals("{\"failures\":" +
         "{\"service_check\":[\"ZOOKEEPER\"]," +
         "\"host_component\":{" +
@@ -363,6 +378,15 @@ public class AutoSkipFailedSummaryActionTest {
     AutoSkipFailedSummaryAction action = new AutoSkipFailedSummaryAction();
     m_injector.injectMembers(action);
 
+    EasyMock.reset(clusterMock);
+
+    Service hdfsService = createNiceMock(Service.class);
+    expect(hdfsService.getName()).andReturn("HDFS").anyTimes();
+    expect(clusterMock.getServiceByComponentName("DATANODE")).andReturn(hdfsService).anyTimes();
+
+    replay(clusterMock, hdfsService);
+
+
     ServiceComponentHostEvent event = createNiceMock(ServiceComponentHostEvent.class);
 
     // Set mock for parent's getHostRoleCommand()

http://git-wip-us.apache.org/repos/asf/ambari/blob/a45f5427/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/ComponentVersionCheckActionTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/ComponentVersionCheckActionTest.java b/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/ComponentVersionCheckActionTest.java
index b06117b..941c424 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/ComponentVersionCheckActionTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/ComponentVersionCheckActionTest.java
@@ -137,6 +137,8 @@ public class ComponentVersionCheckActionTest {
     String clusterName = "c1";
     String hostName = "h1";
 
+    m_helper.createStack(sourceStack);
+
     Clusters clusters = m_injector.getInstance(Clusters.class);
     clusters.addCluster(clusterName, sourceStack);
 
@@ -206,6 +208,9 @@ public class ComponentVersionCheckActionTest {
   private void makeCrossStackUpgradeCluster(StackId sourceStack, String sourceRepo, StackId targetStack,
                                             String targetRepo, String clusterName, String hostName) throws Exception {
 
+    m_helper.createStack(sourceStack);
+    m_helper.createStack(targetStack);
+
     Clusters clusters = m_injector.getInstance(Clusters.class);
     clusters.addCluster(clusterName, sourceStack);
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/a45f5427/ambari-server/src/test/java/org/apache/ambari/server/stageplanner/TestStagePlanner.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/stageplanner/TestStagePlanner.java b/ambari-server/src/test/java/org/apache/ambari/server/stageplanner/TestStagePlanner.java
index 7063147..3a67b6c 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/stageplanner/TestStagePlanner.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/stageplanner/TestStagePlanner.java
@@ -35,6 +35,7 @@ import org.apache.ambari.server.metadata.RoleCommandOrder;
 import org.apache.ambari.server.metadata.RoleCommandOrderProvider;
 import org.apache.ambari.server.orm.GuiceJpaInitializer;
 import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
+import org.apache.ambari.server.state.Service;
 import org.apache.ambari.server.state.StackId;
 import org.apache.ambari.server.state.cluster.ClusterImpl;
 import org.apache.ambari.server.state.svccomphost.ServiceComponentHostServerActionEvent;
@@ -44,6 +45,7 @@ import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 
+import com.google.common.collect.ImmutableMap;
 import com.google.inject.Guice;
 import com.google.inject.Inject;
 import com.google.inject.Injector;
@@ -97,6 +99,18 @@ public class TestStagePlanner {
   public void testMultiStagePlan() {
     ClusterImpl cluster = mock(ClusterImpl.class);
     when(cluster.getCurrentStackVersion()).thenReturn(new StackId("HDP-2.0.6"));
+
+    Service hbaseService = mock(Service.class);
+    when(hbaseService.getDesiredStackId()).thenReturn(new StackId("HDP-2.0.6"));
+    Service zkService = mock(Service.class);
+    when(zkService.getDesiredStackId()).thenReturn(new StackId("HDP-2.0.6"));
+
+    when(cluster.getServices()).thenReturn(ImmutableMap.<String, Service>builder()
+        .put("HBASE", hbaseService)
+        .put("ZOOKEEPER", zkService)
+        .build());
+
+
     RoleCommandOrder rco = roleCommandOrderProvider.getRoleCommandOrder(cluster);
     RoleGraph rg = roleGraphFactory.createNew(rco);
     long now = System.currentTimeMillis();
@@ -122,9 +136,17 @@ public class TestStagePlanner {
   public void testRestartStagePlan() {
     ClusterImpl cluster = mock(ClusterImpl.class);
     when(cluster.getCurrentStackVersion()).thenReturn(new StackId("HDP-2.0.6"));
+
+    Service hiveService = mock(Service.class);
+    when(hiveService.getDesiredStackId()).thenReturn(new StackId("HDP-2.0.6"));
+
+    when(cluster.getServices()).thenReturn(ImmutableMap.<String, Service>builder()
+        .put("HIVE", hiveService)
+        .build());
+
     RoleCommandOrder rco = roleCommandOrderProvider.getRoleCommandOrder(cluster);
     RoleGraph rg = roleGraphFactory.createNew(rco);
-    long now = System.currentTimeMillis();
+
     Stage stage = stageFactory.createNew(1, "/tmp", "cluster1", 1L, "execution command wrapper test",
       "clusterHostInfo", "commandParamsStage", "hostParamsStage");
     stage.setStageId(1);
@@ -151,6 +173,39 @@ public class TestStagePlanner {
   public void testManyStages() {
     ClusterImpl cluster = mock(ClusterImpl.class);
     when(cluster.getCurrentStackVersion()).thenReturn(new StackId("HDP-2.0.6"));
+
+    Service hdfsService = mock(Service.class);
+    when(hdfsService.getDesiredStackId()).thenReturn(new StackId("HDP-2.0.6"));
+
+    Service hbaseService = mock(Service.class);
+    when(hbaseService.getDesiredStackId()).thenReturn(new StackId("HDP-2.0.6"));
+
+    Service zkService = mock(Service.class);
+    when(zkService.getDesiredStackId()).thenReturn(new StackId("HDP-2.0.6"));
+
+    Service mrService = mock(Service.class);
+    when(mrService.getDesiredStackId()).thenReturn(new StackId("HDP-2.0.6"));
+
+    Service oozieService = mock(Service.class);
+    when(oozieService.getDesiredStackId()).thenReturn(new StackId("HDP-2.0.6"));
+
+    Service webhcatService = mock(Service.class);
+    when(webhcatService.getDesiredStackId()).thenReturn(new StackId("HDP-2.0.6"));
+
+    Service gangliaService = mock(Service.class);
+    when(gangliaService.getDesiredStackId()).thenReturn(new StackId("HDP-2.0.6"));
+
+    when(cluster.getServices()).thenReturn(ImmutableMap.<String, Service>builder()
+        .put("HDFS", hdfsService)
+        .put("HBASE", hbaseService)
+        .put("ZOOKEEPER", zkService)
+        .put("MAPREDUCE", mrService)
+        .put("OOZIE", oozieService)
+        .put("WEBHCAT", webhcatService)
+        .put("GANGLIA", gangliaService)
+        .build());
+
+
     RoleCommandOrder rco = roleCommandOrderProvider.getRoleCommandOrder(cluster);
     RoleGraph rg = roleGraphFactory.createNew(rco);
     long now = System.currentTimeMillis();
@@ -188,6 +243,7 @@ public class TestStagePlanner {
     stage.addHostRoleExecutionCommand("host9", Role.GANGLIA_SERVER,
       RoleCommand.START, new ServiceComponentHostStartEvent("GANGLIA_SERVER",
         "host9", now), "cluster1", "GANGLIA", false, false);
+
     System.out.println(stage.toString());
     rg.build(stage);
     System.out.println(rg.stringifyGraph());

http://git-wip-us.apache.org/repos/asf/ambari/blob/a45f5427/ambari-server/src/test/java/org/apache/ambari/server/state/ConfigGroupTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/ConfigGroupTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/ConfigGroupTest.java
index 4437e60..f43dbd8 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/ConfigGroupTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/state/ConfigGroupTest.java
@@ -26,6 +26,7 @@ import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.H2DatabaseCleaner;
 import org.apache.ambari.server.orm.GuiceJpaInitializer;
 import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
+import org.apache.ambari.server.orm.OrmTestHelper;
 import org.apache.ambari.server.orm.dao.ConfigGroupDAO;
 import org.apache.ambari.server.orm.dao.ConfigGroupHostMappingDAO;
 import org.apache.ambari.server.orm.entities.ConfigGroupConfigMappingEntity;
@@ -65,8 +66,12 @@ public class ConfigGroupTest {
     configGroupHostMappingDAO = injector.getInstance
       (ConfigGroupHostMappingDAO.class);
 
+    StackId stackId = new StackId("HDP-0.1");
+    OrmTestHelper helper = injector.getInstance(OrmTestHelper.class);
+    helper.createStack(stackId);
+
     clusterName = "foo";
-    clusters.addCluster(clusterName, new StackId("HDP-0.1"));
+    clusters.addCluster(clusterName, stackId);
     cluster = clusters.getCluster(clusterName);
     Assert.assertNotNull(cluster);
     clusters.addHost("h1");

http://git-wip-us.apache.org/repos/asf/ambari/blob/a45f5427/ambari-server/src/test/java/org/apache/ambari/server/state/ConfigHelperTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/ConfigHelperTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/ConfigHelperTest.java
index 1709da8..dd0a840 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/ConfigHelperTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/state/ConfigHelperTest.java
@@ -49,7 +49,9 @@ import org.apache.ambari.server.controller.spi.ClusterController;
 import org.apache.ambari.server.orm.DBAccessor;
 import org.apache.ambari.server.orm.GuiceJpaInitializer;
 import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
+import org.apache.ambari.server.orm.OrmTestHelper;
 import org.apache.ambari.server.orm.dao.HostRoleCommandDAO;
+import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
 import org.apache.ambari.server.security.SecurityHelper;
 import org.apache.ambari.server.security.TestAuthenticationFactory;
 import org.apache.ambari.server.stack.StackManagerFactory;
@@ -104,8 +106,14 @@ public class ConfigHelperTest {
       metaInfo = injector.getInstance(AmbariMetaInfo.class);
       configFactory = injector.getInstance(ConfigFactory.class);
 
+      StackId stackId = new StackId("HDP-2.0.6");
+      OrmTestHelper helper = injector.getInstance(OrmTestHelper.class);
+      helper.createStack(stackId);
+
+      RepositoryVersionEntity repositoryVersion = helper.getOrCreateRepositoryVersion(stackId, "2.0.6");
+
       clusterName = "c1";
-      clusters.addCluster(clusterName, new StackId("HDP-2.0.6"));
+      clusters.addCluster(clusterName, stackId);
       cluster = clusters.getCluster(clusterName);
       Assert.assertNotNull(cluster);
       clusters.addHost("h1");
@@ -147,6 +155,8 @@ public class ConfigHelperTest {
       cr2.setType("flume-conf");
       cr2.setVersionTag("version1");
 
+      cluster.addService("FLUME", repositoryVersion);
+      cluster.addService("OOZIE", repositoryVersion);
 
       final ClusterRequest clusterRequest2 =
           new ClusterRequest(cluster.getClusterId(), clusterName,
@@ -893,15 +903,21 @@ public class ConfigHelperTest {
       hc.setDefaultVersionTag("version2");
       schReturn.put("flume-conf", hc);
 
+      ServiceComponent sc = createNiceMock(ServiceComponent.class);
+
       // set up mocks
       ServiceComponentHost sch = createNiceMock(ServiceComponentHost.class);
+      expect(sc.getDesiredStackId()).andReturn(cluster.getDesiredStackVersion()).anyTimes();
+
       // set up expectations
       expect(sch.getActualConfigs()).andReturn(schReturn).times(6);
       expect(sch.getHostName()).andReturn("h1").anyTimes();
       expect(sch.getClusterId()).andReturn(cluster.getClusterId()).anyTimes();
       expect(sch.getServiceName()).andReturn("FLUME").anyTimes();
       expect(sch.getServiceComponentName()).andReturn("FLUME_HANDLER").anyTimes();
-      replay(sch);
+      expect(sch.getServiceComponent()).andReturn(sc).anyTimes();
+
+      replay(sc, sch);
       // Cluster level config changes
       Assert.assertTrue(configHelper.isStaleConfigs(sch, null));
 
@@ -1002,6 +1018,7 @@ public class ConfigHelperTest {
       Cluster mockCluster = createStrictMock(Cluster.class);
       StackId mockStackVersion = createStrictMock(StackId.class);
       AmbariMetaInfo mockAmbariMetaInfo = injector.getInstance(AmbariMetaInfo.class);
+      Service mockService = createStrictMock(Service.class);
       ServiceInfo mockServiceInfo = createStrictMock(ServiceInfo.class);
 
       PropertyInfo mockPropertyInfo1 = createStrictMock(PropertyInfo.class);
@@ -1009,8 +1026,8 @@ public class ConfigHelperTest {
 
       List<PropertyInfo> serviceProperties = Arrays.asList(mockPropertyInfo1, mockPropertyInfo2);
 
-      expect(mockCluster.getCurrentStackVersion()).andReturn(mockStackVersion).once();
-
+      expect(mockCluster.getService("SERVICE")).andReturn(mockService).once();
+      expect(mockService.getDesiredStackId()).andReturn(mockStackVersion).once();
       expect(mockStackVersion.getStackName()).andReturn("HDP").once();
       expect(mockStackVersion.getStackVersion()).andReturn("2.2").once();
 
@@ -1018,7 +1035,7 @@ public class ConfigHelperTest {
 
       expect(mockServiceInfo.getProperties()).andReturn(serviceProperties).once();
 
-      replay(mockAmbariMetaInfo, mockCluster, mockStackVersion, mockServiceInfo, mockPropertyInfo1, mockPropertyInfo2);
+      replay(mockAmbariMetaInfo, mockCluster, mockService, mockStackVersion, mockServiceInfo, mockPropertyInfo1, mockPropertyInfo2);
 
       mockAmbariMetaInfo.init();
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/a45f5427/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceComponentTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceComponentTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceComponentTest.java
index 4c9ffcc..1aea85a 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceComponentTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/state/ServiceComponentTest.java
@@ -86,6 +86,9 @@ public class ServiceComponentTest {
     serviceName = "HDFS";
 
     StackId stackId = new StackId("HDP-0.1");
+
+    helper.createStack(stackId);
+
     clusters.addCluster(clusterName, stackId);
     cluster = clusters.getCluster(clusterName);
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/a45f5427/ambari-server/src/test/java/org/apache/ambari/server/state/alerts/AlertEventPublisherTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/alerts/AlertEventPublisherTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/alerts/AlertEventPublisherTest.java
index f5f4e10..f6e66e5 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/alerts/AlertEventPublisherTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/state/alerts/AlertEventPublisherTest.java
@@ -99,7 +99,10 @@ public class AlertEventPublisherTest {
     aggregateMapping = injector.getInstance(AggregateDefinitionMapping.class);
 
     clusterName = "foo";
-    clusters.addCluster(clusterName, new StackId("HDP", STACK_VERSION));
+    StackId stackId = new StackId("HDP", STACK_VERSION);
+    ormHelper.createStack(stackId);
+
+    clusters.addCluster(clusterName, stackId);
     cluster = clusters.getCluster(clusterName);
     Assert.assertNotNull(cluster);
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/a45f5427/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterDeadlockTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterDeadlockTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterDeadlockTest.java
index e7516e6..fbe610c 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterDeadlockTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/state/cluster/ClusterDeadlockTest.java
@@ -120,6 +120,9 @@ public class ClusterDeadlockTest {
 
     injector.getInstance(GuiceJpaInitializer.class);
     injector.injectMembers(this);
+
+    helper.createStack(stackId);
+
     clusters.addCluster("c1", stackId);
     cluster = clusters.getCluster("c1");
     helper.getOrCreateRepositoryVersion(stackId, stackId.getStackVersion());


Mime
View raw message