ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tbeerbo...@apache.org
Subject [1/4] AMBARI-3577 - Move service related code in AmbariManagementController to ServiceResourceProvider
Date Tue, 22 Oct 2013 18:50:11 GMT
Updated Branches:
  refs/heads/trunk f8cf601c1 -> 1aad6407b


http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/1aad6407/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 74431cc..b7bcbeb 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
@@ -18,7 +18,8 @@
 
 package org.apache.ambari.server.controller.internal;
 
-import org.apache.ambari.server.actionmanager.Stage;
+import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.api.services.AmbariMetaInfo;
 import org.apache.ambari.server.controller.AmbariManagementController;
 import org.apache.ambari.server.controller.RequestStatusResponse;
 import org.apache.ambari.server.controller.ServiceRequest;
@@ -29,10 +30,19 @@ import org.apache.ambari.server.controller.spi.Resource;
 import org.apache.ambari.server.controller.spi.ResourceProvider;
 import org.apache.ambari.server.controller.utilities.PredicateBuilder;
 import org.apache.ambari.server.controller.utilities.PropertyHelper;
-import org.easymock.*;
+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.ServiceComponent;
+import org.apache.ambari.server.state.ServiceComponentHost;
+import org.apache.ambari.server.state.ServiceFactory;
+import org.apache.ambari.server.state.StackId;
+import org.apache.ambari.server.state.State;
+import org.easymock.Capture;
 import org.junit.Assert;
 import org.junit.Test;
 
+import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -42,14 +52,13 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
-import static junit.framework.Assert.assertEquals;
-import static junit.framework.Assert.assertNull;
+import static org.easymock.EasyMock.anyBoolean;
+import static org.easymock.EasyMock.anyObject;
 import static org.easymock.EasyMock.capture;
 import static org.easymock.EasyMock.createMock;
 import static org.easymock.EasyMock.createNiceMock;
 import static org.easymock.EasyMock.expect;
 import static org.easymock.EasyMock.replay;
-import static org.easymock.EasyMock.eq;
 import static org.easymock.EasyMock.verify;
 
 /**
@@ -59,21 +68,31 @@ public class ServiceResourceProviderTest {
 
   @Test
   public void testCreateResources() throws Exception{
-    Resource.Type type = Resource.Type.Service;
+    AmbariManagementController managementController = createNiceMock(AmbariManagementController.class);
+    Clusters clusters = createNiceMock(Clusters.class);
+    Cluster cluster = createNiceMock(Cluster.class);
+    Service service = createNiceMock(Service.class);
+    StackId stackId = createNiceMock(StackId.class);
+    ServiceFactory serviceFactory = createNiceMock(ServiceFactory.class);
+    AmbariMetaInfo ambariMetaInfo = createNiceMock(AmbariMetaInfo.class);
 
-    AmbariManagementController managementController = createMock(AmbariManagementController.class);
-    RequestStatusResponse response = createNiceMock(RequestStatusResponse.class);
+    expect(managementController.getClusters()).andReturn(clusters);
+    expect(managementController.getAmbariMetaInfo()).andReturn(ambariMetaInfo);
+    expect(managementController.getServiceFactory()).andReturn(serviceFactory);
+
+    expect(serviceFactory.createNew(cluster, "Service100")).andReturn(service);
+
+    expect(clusters.getCluster("Cluster100")).andReturn(cluster).anyTimes();
+
+    expect(cluster.getService("Service100")).andReturn(null);
+    expect(cluster.getDesiredStackVersion()).andReturn(stackId);
 
-    managementController.createServices(AbstractResourceProviderTest.Matcher.getServiceRequestSet("Cluster100",
"Service100", null, "DEPLOYED"));
+    expect(ambariMetaInfo.isValidService( (String) anyObject(), (String) anyObject(), (String)
anyObject())).andReturn(true);
 
     // replay
-    replay(managementController, response);
+    replay(managementController, clusters, cluster, service, ambariMetaInfo, stackId, serviceFactory);
 
-    ResourceProvider provider = AbstractControllerResourceProvider.getResourceProvider(
-        type,
-        PropertyHelper.getPropertyIds(type),
-        PropertyHelper.getKeyPropertyIds(type),
-        managementController);
+    ResourceProvider provider = getServiceProvider(managementController);
 
     // add the property map to a set for the request.  add more maps for multiple creates
     Set<Map<String, Object>> propertySet = new LinkedHashSet<Map<String,
Object>>();
@@ -84,7 +103,7 @@ public class ServiceResourceProviderTest {
     // add properties to the request map
     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, "DEPLOYED");
+    properties.put(ServiceResourceProvider.SERVICE_SERVICE_STATE_PROPERTY_ID, "INIT");
 
     propertySet.add(properties);
 
@@ -94,43 +113,82 @@ public class ServiceResourceProviderTest {
     provider.createResources(request);
 
     // verify
-    verify(managementController, response);
+    verify(managementController, clusters, cluster, service, ambariMetaInfo, stackId, serviceFactory);
   }
 
   @Test
   public void testGetResources() throws Exception{
-    Resource.Type type = Resource.Type.Service;
-
     AmbariManagementController managementController = createMock(AmbariManagementController.class);
-
-    Set<ServiceResponse> allResponse = new HashSet<ServiceResponse>();
-    allResponse.add(new ServiceResponse(100L, "Cluster100", "Service100", null, "HDP-0.1",
"DEPLOYED"));
-    allResponse.add(new ServiceResponse(100L, "Cluster100", "Service101", null, "HDP-0.1",
"DEPLOYED"));
-    allResponse.add(new ServiceResponse(100L, "Cluster100", "Service102", null, "HDP-0.1",
"DEPLOYED"));
-    allResponse.add(new ServiceResponse(100L, "Cluster100", "Service103", null, "HDP-0.1",
"DEPLOYED"));
-    allResponse.add(new ServiceResponse(100L, "Cluster100", "Service104", null, "HDP-0.1",
"DEPLOYED"));
-
-    Set<ServiceResponse> nameResponse = new HashSet<ServiceResponse>();
-    nameResponse.add(new ServiceResponse(100L, "Cluster100", "Service102", null, "HDP-0.1",
"DEPLOYED"));
-
-    Set<ServiceResponse> stateResponse = new HashSet<ServiceResponse>();
-    stateResponse.add(new ServiceResponse(100L, "Cluster100", "Service100", null, "HDP-0.1",
"DEPLOYED"));
-    stateResponse.add(new ServiceResponse(100L, "Cluster100", "Service102", null, "HDP-0.1",
"DEPLOYED"));
-    stateResponse.add(new ServiceResponse(100L, "Cluster100", "Service104", null, "HDP-0.1",
"DEPLOYED"));
+    Clusters clusters = createNiceMock(Clusters.class);
+    Cluster cluster = createNiceMock(Cluster.class);
+    Service service0 = createNiceMock(Service.class);
+    Service service1 = createNiceMock(Service.class);
+    Service service2 = createNiceMock(Service.class);
+    Service service3 = createNiceMock(Service.class);
+    Service service4 = createNiceMock(Service.class);
+    ServiceResponse serviceResponse0 = createNiceMock(ServiceResponse.class);
+    ServiceResponse serviceResponse1 = createNiceMock(ServiceResponse.class);
+    ServiceResponse serviceResponse2 = createNiceMock(ServiceResponse.class);
+    ServiceResponse serviceResponse3 = createNiceMock(ServiceResponse.class);
+    ServiceResponse serviceResponse4 = createNiceMock(ServiceResponse.class);
+
+    StackId stackId = createNiceMock(StackId.class);
+    ServiceFactory serviceFactory = createNiceMock(ServiceFactory.class);
+    AmbariMetaInfo ambariMetaInfo = createNiceMock(AmbariMetaInfo.class);
+
+    Map<String, Service> allResponseMap = new HashMap<String, Service>();
+    allResponseMap.put("Service100", service0);
+    allResponseMap.put("Service101", service1);
+    allResponseMap.put("Service102", service2);
+    allResponseMap.put("Service103", service3);
+    allResponseMap.put("Service104", service4);
 
     // set expectations
-    expect(managementController.getServices(EasyMock.<Set<ServiceRequest>>anyObject())).andReturn(allResponse).once();
-    expect(managementController.getServices(EasyMock.<Set<ServiceRequest>>anyObject())).andReturn(nameResponse).once();
-    expect(managementController.getServices(EasyMock.<Set<ServiceRequest>>anyObject())).andReturn(stateResponse).once();
+    expect(managementController.getClusters()).andReturn(clusters).anyTimes();
+    expect(managementController.getAmbariMetaInfo()).andReturn(ambariMetaInfo).anyTimes();
+    expect(managementController.getServiceFactory()).andReturn(serviceFactory).anyTimes();
+
+    expect(clusters.getCluster("Cluster100")).andReturn(cluster).anyTimes();
+
+    expect(cluster.getServices()).andReturn(allResponseMap).anyTimes();
+    expect(cluster.getService("Service102")).andReturn(service2);
+
+    expect(service0.convertToResponse()).andReturn(serviceResponse0).anyTimes();
+    expect(service1.convertToResponse()).andReturn(serviceResponse1).anyTimes();
+    expect(service2.convertToResponse()).andReturn(serviceResponse2).anyTimes();
+    expect(service3.convertToResponse()).andReturn(serviceResponse3).anyTimes();
+    expect(service4.convertToResponse()).andReturn(serviceResponse4).anyTimes();
+
+    expect(service0.getName()).andReturn("Service100").anyTimes();
+    expect(service1.getName()).andReturn("Service101").anyTimes();
+    expect(service2.getName()).andReturn("Service102").anyTimes();
+    expect(service3.getName()).andReturn("Service103").anyTimes();
+    expect(service4.getName()).andReturn("Service104").anyTimes();
+
+    expect(service0.getDesiredState()).andReturn(State.INIT);
+    expect(service1.getDesiredState()).andReturn(State.INSTALLED);
+    expect(service2.getDesiredState()).andReturn(State.INIT);
+    expect(service3.getDesiredState()).andReturn(State.INSTALLED);
+    expect(service4.getDesiredState()).andReturn(State.INIT);
+
+    expect(serviceResponse0.getClusterName()).andReturn("Cluster100").anyTimes();
+    expect(serviceResponse0.getServiceName()).andReturn("Service100").anyTimes();
+    expect(serviceResponse1.getClusterName()).andReturn("Cluster100").anyTimes();
+    expect(serviceResponse1.getServiceName()).andReturn("Service101").anyTimes();
+    expect(serviceResponse2.getClusterName()).andReturn("Cluster100").anyTimes();
+    expect(serviceResponse2.getServiceName()).andReturn("Service102").anyTimes();
+    expect(serviceResponse3.getClusterName()).andReturn("Cluster100").anyTimes();
+    expect(serviceResponse3.getServiceName()).andReturn("Service103").anyTimes();
+    expect(serviceResponse4.getClusterName()).andReturn("Cluster100").anyTimes();
+    expect(serviceResponse4.getServiceName()).andReturn("Service104").anyTimes();
 
     // replay
-    replay(managementController);
+    replay(managementController, clusters, cluster,
+        service0, service1, service2, service3, service4,
+        serviceResponse0, serviceResponse1, serviceResponse2, serviceResponse3, serviceResponse4,
+        ambariMetaInfo, stackId, serviceFactory);
 
-    ResourceProvider provider = AbstractControllerResourceProvider.getResourceProvider(
-        type,
-        PropertyHelper.getPropertyIds(type),
-        PropertyHelper.getKeyPropertyIds(type),
-        managementController);
+    ResourceProvider provider = getServiceProvider(managementController);
 
     Set<String> propertyIds = new HashSet<String>();
 
@@ -138,9 +196,9 @@ public class ServiceResourceProviderTest {
     propertyIds.add(ServiceResourceProvider.SERVICE_SERVICE_NAME_PROPERTY_ID);
 
     // create the request
-    Request request = PropertyHelper.getReadRequest(propertyIds);
-    // get all ... no predicate
-    Set<Resource> resources = provider.getResources(request, null);
+    Predicate predicate = new PredicateBuilder().property(ServiceResourceProvider.SERVICE_CLUSTER_NAME_PROPERTY_ID).equals("Cluster100").toPredicate();
+    Request request = PropertyHelper.getReadRequest("ServiceInfo");
+    Set<Resource> resources = provider.getResources(request, predicate);
 
     Assert.assertEquals(5, resources.size());
     Set<String> names = new HashSet<String>();
@@ -150,20 +208,22 @@ public class ServiceResourceProviderTest {
       names.add((String) resource.getPropertyValue(ServiceResourceProvider.SERVICE_SERVICE_NAME_PROPERTY_ID));
     }
     // Make sure that all of the response objects got moved into resources
-    for (ServiceResponse serviceResponse : allResponse ) {
-      Assert.assertTrue(names.contains(serviceResponse.getServiceName()));
+    for (Service service : allResponseMap.values() ) {
+      Assert.assertTrue(names.contains(service.getName()));
     }
 
     // get service named Service102
-    Predicate predicate = new PredicateBuilder().property(ServiceResourceProvider.SERVICE_SERVICE_NAME_PROPERTY_ID).equals("Service102").toPredicate();
+    predicate = new PredicateBuilder().property(ServiceResourceProvider.SERVICE_CLUSTER_NAME_PROPERTY_ID).equals("Cluster100").and().
+        property(ServiceResourceProvider.SERVICE_SERVICE_NAME_PROPERTY_ID).equals("Service102").toPredicate();
     request = PropertyHelper.getReadRequest("ServiceInfo");
     resources = provider.getResources(request, predicate);
 
     Assert.assertEquals(1, resources.size());
     Assert.assertEquals("Service102", resources.iterator().next().getPropertyValue(ServiceResourceProvider.SERVICE_SERVICE_NAME_PROPERTY_ID));
 
-    // get services where state == "DEPLOYED"
-    predicate = new PredicateBuilder().property(ServiceResourceProvider.SERVICE_SERVICE_STATE_PROPERTY_ID).equals("DEPLOYED").toPredicate();
+    // get services where state == "INIT"
+    predicate = new PredicateBuilder().property(ServiceResourceProvider.SERVICE_CLUSTER_NAME_PROPERTY_ID).equals("Cluster100").and().
+        property(ServiceResourceProvider.SERVICE_SERVICE_STATE_PROPERTY_ID).equals("INIT").toPredicate();
     request = PropertyHelper.getReadRequest(propertyIds);
     resources = provider.getResources(request, predicate);
 
@@ -174,43 +234,60 @@ public class ServiceResourceProviderTest {
       Assert.assertEquals("Cluster100", clusterName);
       names.add((String) resource.getPropertyValue(ServiceResourceProvider.SERVICE_SERVICE_NAME_PROPERTY_ID));
     }
-    // Make sure that all of the response objects got moved into resources
-    for (ServiceResponse serviceResponse : stateResponse ) {
-      Assert.assertTrue(names.contains(serviceResponse.getServiceName()));
-    }
 
     // verify
-    verify(managementController);
+    verify(managementController, clusters, cluster,
+        service0, service1, service2, service3, service4,
+        serviceResponse0, serviceResponse1, serviceResponse2, serviceResponse3, serviceResponse4,
+        ambariMetaInfo, stackId, serviceFactory);
   }
 
   @Test
   public void testUpdateResources() throws Exception{
-    Resource.Type type = Resource.Type.Service;
-
     AmbariManagementController managementController = createMock(AmbariManagementController.class);
-    RequestStatusResponse response = createNiceMock(RequestStatusResponse.class);
-    Capture<Set<ServiceRequest>> requestsCapture = new Capture<Set<ServiceRequest>>();
+    Clusters clusters = createNiceMock(Clusters.class);
+    Cluster cluster = createNiceMock(Cluster.class);
+    Service service0 = createNiceMock(Service.class);
+    ServiceFactory serviceFactory = createNiceMock(ServiceFactory.class);
+    AmbariMetaInfo ambariMetaInfo = createNiceMock(AmbariMetaInfo.class);
+    RequestStatusResponse requestStatusResponse = createNiceMock(RequestStatusResponse.class);
 
     Map<String, String> mapRequestProps = new HashMap<String, String>();
     mapRequestProps.put("context", "Called from a test");
 
     // set expectations
-    expect(managementController.updateServices(capture(requestsCapture),
-      eq(mapRequestProps), eq(false), eq(true))).andReturn(response).once();
+    expect(managementController.getClusters()).andReturn(clusters).anyTimes();
+    expect(managementController.getAmbariMetaInfo()).andReturn(ambariMetaInfo).anyTimes();
+    expect(managementController.getServiceFactory()).andReturn(serviceFactory).anyTimes();
+
+    expect(clusters.getCluster("Cluster100")).andReturn(cluster).anyTimes();
+
+    expect(cluster.getService("Service102")).andReturn(service0);
+
+    expect(service0.getDesiredState()).andReturn(State.INSTALLED).anyTimes();
+    expect(service0.getServiceComponents()).andReturn(Collections.<String, ServiceComponent>emptyMap()).anyTimes();
+
+    Capture<Map<String, String>> requestPropertiesCapture = new Capture<Map<String,
String>>();
+    Capture<Map<State, List<Service>>> changedServicesCapture = new Capture<Map<State,
List<Service>>>();
+    Capture<Map<State, List<ServiceComponent>>> changedCompsCapture = new
Capture<Map<State, List<ServiceComponent>>>();
+    Capture<Map<String, Map<State, List<ServiceComponentHost>>>>
changedScHostsCapture = new Capture<Map<String, Map<State, List<ServiceComponentHost>>>>();
+    Capture<Map<String, String>> requestParametersCapture = new Capture<Map<String,
String>>();
+    Capture<Collection<ServiceComponentHost>> ignoredScHostsCapture = new Capture<Collection<ServiceComponentHost>>();
+    Capture<Cluster> clusterCapture = new Capture<Cluster>();
+
+    expect(managementController.createStages(capture(clusterCapture), capture(requestPropertiesCapture),
capture(requestParametersCapture), capture(changedServicesCapture), capture(changedCompsCapture),
capture(changedScHostsCapture), capture(ignoredScHostsCapture), anyBoolean(), anyBoolean()
+    )).andReturn(requestStatusResponse);
 
     // replay
-    replay(managementController, response);
+    replay(managementController, clusters, cluster,
+        service0, serviceFactory, ambariMetaInfo, requestStatusResponse);
 
-    ResourceProvider provider = AbstractControllerResourceProvider.getResourceProvider(
-        type,
-        PropertyHelper.getPropertyIds(type),
-        PropertyHelper.getKeyPropertyIds(type),
-        managementController);
+    ResourceProvider provider = getServiceProvider(managementController);
 
     // add the property map to a set for the request.
     Map<String, Object> properties = new LinkedHashMap<String, Object>();
 
-    properties.put(ServiceResourceProvider.SERVICE_SERVICE_STATE_PROPERTY_ID, "DEPLOYED");
+    properties.put(ServiceResourceProvider.SERVICE_SERVICE_STATE_PROPERTY_ID, "STARTED");
 
     // create the request
     Request request = PropertyHelper.getUpdateRequest(properties, mapRequestProps);
@@ -221,63 +298,67 @@ public class ServiceResourceProviderTest {
     provider.updateResources(request, predicate);
 
     // verify
-    verify(managementController, response);
-
-    Set<ServiceRequest> setRequests = requestsCapture.getValue();
-    assertEquals(1, setRequests.size());
-    ServiceRequest sr = setRequests.iterator().next();
-    assertEquals("Cluster100", sr.getClusterName());
-    assertEquals("Service102", sr.getServiceName());
-    assertEquals("DEPLOYED", sr.getDesiredState());
-    assertNull(sr.getConfigVersions());
+    verify(managementController, clusters, cluster,
+        service0, serviceFactory, ambariMetaInfo, requestStatusResponse);
   }
 
   @Test
   public void testReconfigureClientsFlag() throws Exception {
-    Resource.Type type = Resource.Type.Service;
-
     AmbariManagementController managementController1 = createMock(AmbariManagementController.class);
     AmbariManagementController managementController2 = createMock
-      (AmbariManagementController.class);
+        (AmbariManagementController.class);
+    Clusters clusters = createNiceMock(Clusters.class);
+    Cluster cluster = createNiceMock(Cluster.class);
+    Service service0 = createNiceMock(Service.class);
+    ServiceResponse serviceResponse0 = createNiceMock(ServiceResponse.class);
+    AmbariMetaInfo ambariMetaInfo = createNiceMock(AmbariMetaInfo.class);
 
     RequestStatusResponse response1 = createNiceMock(RequestStatusResponse.class);
     RequestStatusResponse response2 = createNiceMock(RequestStatusResponse
       .class);
-    Capture<Set<ServiceRequest>> requestsCapture = new Capture<Set<ServiceRequest>>();
 
     Map<String, String> mapRequestProps = new HashMap<String, String>();
     mapRequestProps.put("context", "Called from a test");
 
-    Set<ServiceResponse> nameResponse = new HashSet<ServiceResponse>();
-    nameResponse.add(new ServiceResponse(100L, "Cluster100", "Service102", null, "HDP-0.1",
"DEPLOYED"));
-
     // set expectations
-    expect(managementController1.getServices(EasyMock.<Set<ServiceRequest>>anyObject())).andReturn(nameResponse).once();
-    expect(managementController2.getServices(EasyMock.<Set<ServiceRequest>>anyObject())).andReturn(nameResponse).once();
+    expect(clusters.getCluster("Cluster100")).andReturn(cluster).anyTimes();
 
-    // set expectations
-    expect(managementController1.updateServices(capture(requestsCapture),
-      eq(mapRequestProps), eq(false), eq(true))).andReturn(response1).once();
+    expect(managementController1.getClusters()).andReturn(clusters).anyTimes();
+    expect(managementController1.getAmbariMetaInfo()).andReturn(ambariMetaInfo).anyTimes();
+
+    expect(managementController2.getClusters()).andReturn(clusters).anyTimes();
+    expect(managementController2.getAmbariMetaInfo()).andReturn(ambariMetaInfo).anyTimes();
+
+    expect(cluster.getService("Service102")).andReturn(service0).anyTimes();
+
+    expect(service0.convertToResponse()).andReturn(serviceResponse0).anyTimes();
+    expect(service0.getDesiredState()).andReturn(State.INSTALLED).anyTimes();
+    expect(service0.getServiceComponents()).andReturn(Collections.<String, ServiceComponent>emptyMap()).anyTimes();
 
-    expect(managementController2.updateServices(capture(requestsCapture),
-      eq(mapRequestProps), eq(false), eq(false))).andReturn(response2).once();
+    expect(serviceResponse0.getClusterName()).andReturn("Cluster100").anyTimes();
+    expect(serviceResponse0.getServiceName()).andReturn("Service102").anyTimes();
+
+    Capture<Map<String, String>> requestPropertiesCapture = new Capture<Map<String,
String>>();
+    Capture<Map<State, List<Service>>> changedServicesCapture = new Capture<Map<State,
List<Service>>>();
+    Capture<Map<State, List<ServiceComponent>>> changedCompsCapture = new
Capture<Map<State, List<ServiceComponent>>>();
+    Capture<Map<String, Map<State, List<ServiceComponentHost>>>>
changedScHostsCapture = new Capture<Map<String, Map<State, List<ServiceComponentHost>>>>();
+    Capture<Map<String, String>> requestParametersCapture = new Capture<Map<String,
String>>();
+    Capture<Collection<ServiceComponentHost>> ignoredScHostsCapture = new Capture<Collection<ServiceComponentHost>>();
+    Capture<Cluster> clusterCapture = new Capture<Cluster>();
+
+    expect(managementController1.createStages(capture(clusterCapture), capture(requestPropertiesCapture),
capture(requestParametersCapture), capture(changedServicesCapture), capture(changedCompsCapture),
capture(changedScHostsCapture), capture(ignoredScHostsCapture), anyBoolean(), anyBoolean()
+    )).andReturn(response1);
+
+    expect(managementController2.createStages(capture(clusterCapture), capture(requestPropertiesCapture),
capture(requestParametersCapture), capture(changedServicesCapture), capture(changedCompsCapture),
capture(changedScHostsCapture), capture(ignoredScHostsCapture), anyBoolean(), anyBoolean()
+    )).andReturn(response2);
 
     // replay
-    replay(managementController1, response1);
-    replay(managementController2, response2);
-
-    ResourceProvider provider1 = AbstractControllerResourceProvider.getResourceProvider(
-      type,
-      PropertyHelper.getPropertyIds(type),
-      PropertyHelper.getKeyPropertyIds(type),
-      managementController1);
-
-    ResourceProvider provider2 = AbstractControllerResourceProvider
-      .getResourceProvider(
-      type,
-      PropertyHelper.getPropertyIds(type),
-      PropertyHelper.getKeyPropertyIds(type),
-      managementController2);
+    replay(managementController1, response1, managementController2, response2,
+        clusters, cluster, service0, serviceResponse0, ambariMetaInfo);
+
+    ResourceProvider provider1 = getServiceProvider(managementController1);
+
+    ResourceProvider provider2 = getServiceProvider(managementController2);
 
     // add the property map to a set for the request.
     Map<String, Object> properties = new LinkedHashMap<String, Object>();
@@ -305,35 +386,33 @@ public class ServiceResourceProviderTest {
     provider2.updateResources(request, predicate2);
 
     // verify
-    verify(managementController1, response1);
-    verify(managementController2, response2);
+    verify(managementController1, response1, managementController2, response2,
+        clusters, cluster, service0, serviceResponse0, ambariMetaInfo);
   }
 
   @Test
   public void testDeleteResources() throws Exception{
-    Resource.Type type = Resource.Type.Service;
-
     AmbariManagementController managementController = createMock(AmbariManagementController.class);
-    RequestStatusResponse response = createNiceMock(RequestStatusResponse.class);
+    Clusters clusters = createNiceMock(Clusters.class);
+    Cluster cluster = createNiceMock(Cluster.class);
 
     // set expectations
-    expect(managementController.deleteServices(AbstractResourceProviderTest.Matcher.getServiceRequestSet(null,
"Service100", null, null))).andReturn(response);
+    expect(managementController.getClusters()).andReturn(clusters).anyTimes();
+    expect(clusters.getCluster("Cluster100")).andReturn(cluster).anyTimes();
+    cluster.deleteService("Service100");
 
     // replay
-    replay(managementController, response);
+    replay(managementController, clusters, cluster);
 
-    ResourceProvider provider = AbstractControllerResourceProvider.getResourceProvider(
-        type,
-        PropertyHelper.getPropertyIds(type),
-        PropertyHelper.getKeyPropertyIds(type),
-        managementController);
+    ResourceProvider provider = getServiceProvider(managementController);
 
     AbstractResourceProviderTest.TestObserver observer = new AbstractResourceProviderTest.TestObserver();
 
     ((ObservableResourceProvider)provider).addObserver(observer);
 
     // delete the service named Service100
-    Predicate  predicate = new PredicateBuilder().property(ServiceResourceProvider.SERVICE_SERVICE_NAME_PROPERTY_ID).equals("Service100").toPredicate();
+    Predicate  predicate = new PredicateBuilder().property(ServiceResourceProvider.SERVICE_CLUSTER_NAME_PROPERTY_ID).equals("Cluster100").and()
+        .property(ServiceResourceProvider.SERVICE_SERVICE_NAME_PROPERTY_ID).equals("Service100").toPredicate();
     provider.deleteResources(predicate);
 
 
@@ -345,7 +424,7 @@ public class ServiceResourceProviderTest {
     Assert.assertNull(lastEvent.getRequest());
 
     // verify
-    verify(managementController, response);
+    verify(managementController, clusters, cluster);
   }
 
   @Test
@@ -393,4 +472,41 @@ public class ServiceResourceProviderTest {
     unsupported = provider.checkPropertyIds(Collections.singleton("config/unknown_property"));
     Assert.assertTrue(unsupported.isEmpty());
   }
+
+  public static ServiceResourceProvider getServiceProvider(AmbariManagementController managementController)
{
+    Resource.Type type = Resource.Type.Service;
+
+    return (ServiceResourceProvider) AbstractControllerResourceProvider.getResourceProvider(
+        type,
+        PropertyHelper.getPropertyIds(type),
+        PropertyHelper.getKeyPropertyIds(type),
+        managementController);
+  }
+
+  public static void createServices(AmbariManagementController controller, Set<ServiceRequest>
requests) throws AmbariException {
+    ServiceResourceProvider provider = getServiceProvider(controller);
+    provider.createServices(requests);
+  }
+
+  public static Set<ServiceResponse> getServices(AmbariManagementController controller,
+                                                 Set<ServiceRequest> requests) throws
AmbariException {
+    ServiceResourceProvider provider = getServiceProvider(controller);
+    return provider.getServices(requests);
+  }
+
+  public static RequestStatusResponse updateServices(AmbariManagementController controller,
+                                                     Set<ServiceRequest> requests,
+                                                     Map<String, String> requestProperties,
boolean runSmokeTest,
+                                                     boolean reconfigureClients) throws AmbariException
+  {
+    ServiceResourceProvider provider = getServiceProvider(controller);
+    return provider.updateServices(requests, requestProperties, runSmokeTest, reconfigureClients);
+  }
+
+  public static RequestStatusResponse deleteServices(AmbariManagementController controller,
Set<ServiceRequest> requests)
+      throws AmbariException {
+    ServiceResourceProvider provider = getServiceProvider(controller);
+    return provider.deleteServices(requests);
+  }
+
 }


Mime
View raw message