|
@@ -23,11 +23,12 @@ import org.apache.ambari.server.controller.AmbariManagementController;
|
|
|
import org.apache.ambari.server.controller.ClusterRequest;
|
|
|
import org.apache.ambari.server.controller.ConfigurationRequest;
|
|
|
import org.apache.ambari.server.controller.HostRequest;
|
|
|
+import org.apache.ambari.server.controller.RequestStatusResponse;
|
|
|
import org.apache.ambari.server.controller.ServiceComponentHostRequest;
|
|
|
-import org.apache.ambari.server.controller.ServiceComponentRequest;
|
|
|
import org.apache.ambari.server.controller.StackConfigurationRequest;
|
|
|
import org.apache.ambari.server.controller.TaskStatusRequest;
|
|
|
import org.apache.ambari.server.controller.UserRequest;
|
|
|
+import org.apache.ambari.server.controller.spi.RequestStatus;
|
|
|
import org.apache.ambari.server.controller.spi.Resource;
|
|
|
import org.easymock.EasyMock;
|
|
|
import org.easymock.IArgumentMatcher;
|
|
@@ -113,6 +114,50 @@ public class AbstractResourceProviderTest {
|
|
|
Assert.assertTrue(supportedPropertyIds.containsAll(propertyIds));
|
|
|
}
|
|
|
|
|
|
+ @Test
|
|
|
+ public void testGetRequestStatus() {
|
|
|
+ Set<String> propertyIds = new HashSet<String>();
|
|
|
+ Map<Resource.Type, String> keyPropertyIds = new HashMap<Resource.Type, String>();
|
|
|
+ AmbariManagementController managementController = createMock(AmbariManagementController.class);
|
|
|
+
|
|
|
+ AbstractResourceProvider provider =
|
|
|
+ (AbstractResourceProvider) AbstractControllerResourceProvider.getResourceProvider(
|
|
|
+ Resource.Type.Service,
|
|
|
+ propertyIds,
|
|
|
+ keyPropertyIds,
|
|
|
+ managementController);
|
|
|
+
|
|
|
+ RequestStatus status = provider.getRequestStatus(null);
|
|
|
+
|
|
|
+ Assert.assertNull(status.getRequestResource());
|
|
|
+ Assert.assertEquals(Collections.emptySet(), status.getAssociatedResources());
|
|
|
+
|
|
|
+ RequestStatusResponse response = new RequestStatusResponse(99L);
|
|
|
+
|
|
|
+ status = provider.getRequestStatus(response);
|
|
|
+ Resource resource = status.getRequestResource();
|
|
|
+
|
|
|
+ Assert.assertEquals(99L, resource.getPropertyValue("Requests/id"));
|
|
|
+ Assert.assertEquals(Collections.emptySet(), status.getAssociatedResources());
|
|
|
+
|
|
|
+
|
|
|
+ status = provider.getRequestStatus(response, null);
|
|
|
+ resource = status.getRequestResource();
|
|
|
+
|
|
|
+ Assert.assertEquals(99L, resource.getPropertyValue("Requests/id"));
|
|
|
+ Assert.assertEquals(Collections.emptySet(), status.getAssociatedResources());
|
|
|
+
|
|
|
+
|
|
|
+ Resource associatedResource = new ResourceImpl(Resource.Type.Service);
|
|
|
+
|
|
|
+ Set<Resource> associatedResources = Collections.singleton(associatedResource);
|
|
|
+ status = provider.getRequestStatus(response, associatedResources);
|
|
|
+ resource = status.getRequestResource();
|
|
|
+
|
|
|
+ Assert.assertEquals(99L, resource.getPropertyValue("Requests/id"));
|
|
|
+ Assert.assertEquals(associatedResources, status.getAssociatedResources());
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
// ----- helper methods ----------------------------------------------------
|
|
|
|
|
@@ -163,15 +208,6 @@ public class AbstractResourceProviderTest {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
- public static Set<ServiceComponentRequest> getComponentRequestSet(String clusterName, String serviceName,
|
|
|
- String componentName,
|
|
|
- Map<String, String> configVersions,
|
|
|
- String desiredState)
|
|
|
- {
|
|
|
- EasyMock.reportMatcher(new ComponentRequestSetMatcher(clusterName, serviceName, componentName,
|
|
|
- configVersions, desiredState));
|
|
|
- return null;
|
|
|
- }
|
|
|
|
|
|
public static Set<HostRequest> getHostRequestSet(String hostname, String clusterName,
|
|
|
Map<String, String> hostAttributes)
|
|
@@ -331,48 +367,6 @@ public class AbstractResourceProviderTest {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Matcher for a ServiceComponentRequest set containing a single request.
|
|
|
- */
|
|
|
- public static class ComponentRequestSetMatcher extends HashSet<ServiceComponentRequest> implements IArgumentMatcher {
|
|
|
-
|
|
|
- private final ServiceComponentRequest serviceComponentRequest;
|
|
|
-
|
|
|
- public ComponentRequestSetMatcher(String clusterName, String serviceName, String componentName,
|
|
|
- Map<String, String> configVersions, String desiredState) {
|
|
|
- this.serviceComponentRequest =
|
|
|
- new ServiceComponentRequest(clusterName, serviceName, componentName, configVersions, desiredState);
|
|
|
- add(this.serviceComponentRequest);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public boolean matches(Object o) {
|
|
|
-
|
|
|
- if (!(o instanceof Set)) {
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- Set set = (Set) o;
|
|
|
-
|
|
|
- if (set.size() != 1) {
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- Object request = set.iterator().next();
|
|
|
-
|
|
|
- return request instanceof ServiceComponentRequest &&
|
|
|
- eq(((ServiceComponentRequest) request).getClusterName(), serviceComponentRequest.getClusterName()) &&
|
|
|
- eq(((ServiceComponentRequest) request).getServiceName(), serviceComponentRequest.getServiceName()) &&
|
|
|
- eq(((ServiceComponentRequest) request).getComponentName(), serviceComponentRequest.getComponentName()) &&
|
|
|
- eq(((ServiceComponentRequest) request).getConfigVersions(), serviceComponentRequest.getConfigVersions()) &&
|
|
|
- eq(((ServiceComponentRequest) request).getDesiredState(), serviceComponentRequest.getDesiredState());
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void appendTo(StringBuffer stringBuffer) {
|
|
|
- stringBuffer.append("ComponentRequestSetMatcher(").append(serviceComponentRequest).append(")");
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
/**
|
|
|
* Matcher for a HostRequest set containing a single request.
|