@Test public void testGetResources() throws Exception{ Resource.Type type = Resource.Type.RootServiceHostComponent; AmbariManagementController managementController = createMock(AmbariManagementController.class); Clusters clusters = createNiceMock(Clusters.class); Cluster cluster = createNiceMock(Cluster.class); Host host1 = createNiceMock(Host.class); HostHealthStatus healthStatus = createNiceMock(HostHealthStatus.class); HostResponse hostResponse1 = createNiceMock(HostResponse.class); RootServiceHostComponentResponse response = createNiceMock(RootServiceHostComponentResponse.class); AbstractRootServiceResponseFactory factory = createNiceMock(AbstractRootServiceResponseFactory.class); List<Host> hosts = new LinkedList<Host>(); hosts.add(host1); Set<Cluster> clusterSet = new HashSet<Cluster>(); clusterSet.add(cluster); Set<RootServiceHostComponentResponse> responseSet = new HashSet<RootServiceHostComponentResponse>(); responseSet.add(response); expect(managementController.getRootServiceResponseFactory()).andReturn(factory).anyTimes(); expect(managementController.getClusters()).andReturn(clusters).anyTimes(); expect(clusters.getHosts()).andReturn(hosts).anyTimes(); expect(factory.getRootServiceHostComponent((RootServiceHostComponentRequest) anyObject(), EasyMock.<Set<HostResponse>>anyObject())). andReturn(responseSet).anyTimes(); expect(clusters.getCluster("Cluster100")).andReturn(cluster).anyTimes(); expect(clusters.getClustersForHost("Host100")).andReturn(clusterSet).anyTimes(); expect(host1.getHostName()).andReturn("Host100").anyTimes(); expect(host1.convertToResponse()).andReturn(hostResponse1).anyTimes(); expect(hostResponse1.getClusterName()).andReturn("Cluster100").anyTimes(); expect(hostResponse1.getHostname()).andReturn("Host100").anyTimes(); expect(hostResponse1.getHealthStatus()).andReturn(healthStatus).anyTimes(); expect(healthStatus.getHealthStatus()).andReturn(HostHealthStatus.HealthStatus.HEALTHY).anyTimes(); expect(healthStatus.getHealthReport()).andReturn("HEALTHY").anyTimes(); replay(managementController, clusters, cluster, host1, hostResponse1, healthStatus, factory, response); ResourceProvider provider = AbstractControllerResourceProvider.getResourceProvider( type, PropertyHelper.getPropertyIds(type), PropertyHelper.getKeyPropertyIds(type), managementController); Set<String> propertyIds = new HashSet<String>(); propertyIds.add(RootServiceHostComponentResourceProvider.SERVICE_NAME_PROPERTY_ID); propertyIds.add(RootServiceHostComponentResourceProvider.HOST_NAME_PROPERTY_ID); propertyIds.add(RootServiceHostComponentResourceProvider.COMPONENT_NAME_PROPERTY_ID); propertyIds.add(RootServiceHostComponentResourceProvider.COMPONENT_STATE_PROPERTY_ID); propertyIds.add(RootServiceHostComponentResourceProvider.PROPERTIES_PROPERTY_ID); propertyIds.add(RootServiceHostComponentResourceProvider.COMPONENT_VERSION_PROPERTY_ID); Request request = PropertyHelper.getReadRequest(propertyIds); provider.getResources(request, null); verify(managementController, clusters, cluster, host1, hostResponse1, healthStatus, factory, response); }
@Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { final Set<RootServiceHostComponentRequest> requests = new HashSet<RootServiceHostComponentRequest>(); if (predicate == null) { requests.add(getRequest(Collections.<String, Object>emptyMap())); } else { for (Map<String, Object> propertyMap : getPropertyMaps(predicate)) { requests.add(getRequest(propertyMap)); } } Set<String> requestedIds = getRequestPropertyIds(request, predicate); Set<RootServiceHostComponentResponse> responses = getResources(new Command<Set<RootServiceHostComponentResponse>>() { @Override public Set<RootServiceHostComponentResponse> invoke() throws AmbariException { return getRootServiceHostComponents(requests); } }); Set<Resource> resources = new HashSet<Resource>(); for (RootServiceHostComponentResponse response : responses) { Resource resource = new ResourceImpl(Resource.Type.RootServiceHostComponent); setResourceProperty(resource, SERVICE_NAME_PROPERTY_ID, response.getServiceName(), requestedIds); setResourceProperty(resource, HOST_NAME_PROPERTY_ID, response.getHostName(), requestedIds); setResourceProperty(resource, COMPONENT_NAME_PROPERTY_ID, response.getComponentName(), requestedIds); setResourceProperty(resource, COMPONENT_STATE_PROPERTY_ID, response.getComponentState(), requestedIds); setResourceProperty(resource, COMPONENT_VERSION_PROPERTY_ID, response.getComponentVersion(), requestedIds); setResourceProperty(resource, PROPERTIES_PROPERTY_ID, response.getProperties(), requestedIds); resources.add(resource); } return resources; }
RootServiceHostComponentResourceProvider extends
    ReadOnlyResourceProvider { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { final Set<RootServiceHostComponentRequest> requests = new HashSet<RootServiceHostComponentRequest>(); if (predicate == null) { requests.add(getRequest(Collections.<String, Object>emptyMap())); } else { for (Map<String, Object> propertyMap : getPropertyMaps(predicate)) { requests.add(getRequest(propertyMap)); } } Set<String> requestedIds = getRequestPropertyIds(request, predicate); Set<RootServiceHostComponentResponse> responses = getResources(new Command<Set<RootServiceHostComponentResponse>>() { @Override public Set<RootServiceHostComponentResponse> invoke() throws AmbariException { return getRootServiceHostComponents(requests); } }); Set<Resource> resources = new HashSet<Resource>(); for (RootServiceHostComponentResponse response : responses) { Resource resource = new ResourceImpl(Resource.Type.RootServiceHostComponent); setResourceProperty(resource, SERVICE_NAME_PROPERTY_ID, response.getServiceName(), requestedIds); setResourceProperty(resource, HOST_NAME_PROPERTY_ID, response.getHostName(), requestedIds); setResourceProperty(resource, COMPONENT_NAME_PROPERTY_ID, response.getComponentName(), requestedIds); setResourceProperty(resource, COMPONENT_STATE_PROPERTY_ID, response.getComponentState(), requestedIds); setResourceProperty(resource, COMPONENT_VERSION_PROPERTY_ID, response.getComponentVersion(), requestedIds); setResourceProperty(resource, PROPERTIES_PROPERTY_ID, response.getProperties(), requestedIds); resources.add(resource); } return resources; } }
RootServiceHostComponentResourceProvider extends
    ReadOnlyResourceProvider { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { final Set<RootServiceHostComponentRequest> requests = new HashSet<RootServiceHostComponentRequest>(); if (predicate == null) { requests.add(getRequest(Collections.<String, Object>emptyMap())); } else { for (Map<String, Object> propertyMap : getPropertyMaps(predicate)) { requests.add(getRequest(propertyMap)); } } Set<String> requestedIds = getRequestPropertyIds(request, predicate); Set<RootServiceHostComponentResponse> responses = getResources(new Command<Set<RootServiceHostComponentResponse>>() { @Override public Set<RootServiceHostComponentResponse> invoke() throws AmbariException { return getRootServiceHostComponents(requests); } }); Set<Resource> resources = new HashSet<Resource>(); for (RootServiceHostComponentResponse response : responses) { Resource resource = new ResourceImpl(Resource.Type.RootServiceHostComponent); setResourceProperty(resource, SERVICE_NAME_PROPERTY_ID, response.getServiceName(), requestedIds); setResourceProperty(resource, HOST_NAME_PROPERTY_ID, response.getHostName(), requestedIds); setResourceProperty(resource, COMPONENT_NAME_PROPERTY_ID, response.getComponentName(), requestedIds); setResourceProperty(resource, COMPONENT_STATE_PROPERTY_ID, response.getComponentState(), requestedIds); setResourceProperty(resource, COMPONENT_VERSION_PROPERTY_ID, response.getComponentVersion(), requestedIds); setResourceProperty(resource, PROPERTIES_PROPERTY_ID, response.getProperties(), requestedIds); resources.add(resource); } return resources; } RootServiceHostComponentResourceProvider(Set<String> propertyIds,
      Map<Type, String> keyPropertyIds,
      AmbariManagementController managementController); }
RootServiceHostComponentResourceProvider extends
    ReadOnlyResourceProvider { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { final Set<RootServiceHostComponentRequest> requests = new HashSet<RootServiceHostComponentRequest>(); if (predicate == null) { requests.add(getRequest(Collections.<String, Object>emptyMap())); } else { for (Map<String, Object> propertyMap : getPropertyMaps(predicate)) { requests.add(getRequest(propertyMap)); } } Set<String> requestedIds = getRequestPropertyIds(request, predicate); Set<RootServiceHostComponentResponse> responses = getResources(new Command<Set<RootServiceHostComponentResponse>>() { @Override public Set<RootServiceHostComponentResponse> invoke() throws AmbariException { return getRootServiceHostComponents(requests); } }); Set<Resource> resources = new HashSet<Resource>(); for (RootServiceHostComponentResponse response : responses) { Resource resource = new ResourceImpl(Resource.Type.RootServiceHostComponent); setResourceProperty(resource, SERVICE_NAME_PROPERTY_ID, response.getServiceName(), requestedIds); setResourceProperty(resource, HOST_NAME_PROPERTY_ID, response.getHostName(), requestedIds); setResourceProperty(resource, COMPONENT_NAME_PROPERTY_ID, response.getComponentName(), requestedIds); setResourceProperty(resource, COMPONENT_STATE_PROPERTY_ID, response.getComponentState(), requestedIds); setResourceProperty(resource, COMPONENT_VERSION_PROPERTY_ID, response.getComponentVersion(), requestedIds); setResourceProperty(resource, PROPERTIES_PROPERTY_ID, response.getProperties(), requestedIds); resources.add(resource); } return resources; } RootServiceHostComponentResourceProvider(Set<String> propertyIds,
      Map<Type, String> keyPropertyIds,
      AmbariManagementController managementController); @Override Set<Resource> getResources(Request request, Predicate predicate); }
RootServiceHostComponentResourceProvider extends
    ReadOnlyResourceProvider { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { final Set<RootServiceHostComponentRequest> requests = new HashSet<RootServiceHostComponentRequest>(); if (predicate == null) { requests.add(getRequest(Collections.<String, Object>emptyMap())); } else { for (Map<String, Object> propertyMap : getPropertyMaps(predicate)) { requests.add(getRequest(propertyMap)); } } Set<String> requestedIds = getRequestPropertyIds(request, predicate); Set<RootServiceHostComponentResponse> responses = getResources(new Command<Set<RootServiceHostComponentResponse>>() { @Override public Set<RootServiceHostComponentResponse> invoke() throws AmbariException { return getRootServiceHostComponents(requests); } }); Set<Resource> resources = new HashSet<Resource>(); for (RootServiceHostComponentResponse response : responses) { Resource resource = new ResourceImpl(Resource.Type.RootServiceHostComponent); setResourceProperty(resource, SERVICE_NAME_PROPERTY_ID, response.getServiceName(), requestedIds); setResourceProperty(resource, HOST_NAME_PROPERTY_ID, response.getHostName(), requestedIds); setResourceProperty(resource, COMPONENT_NAME_PROPERTY_ID, response.getComponentName(), requestedIds); setResourceProperty(resource, COMPONENT_STATE_PROPERTY_ID, response.getComponentState(), requestedIds); setResourceProperty(resource, COMPONENT_VERSION_PROPERTY_ID, response.getComponentVersion(), requestedIds); setResourceProperty(resource, PROPERTIES_PROPERTY_ID, response.getProperties(), requestedIds); resources.add(resource); } return resources; } RootServiceHostComponentResourceProvider(Set<String> propertyIds,
      Map<Type, String> keyPropertyIds,
      AmbariManagementController managementController); @Override Set<Resource> getResources(Request request, Predicate predicate); static final String SERVICE_NAME_PROPERTY_ID; static final String HOST_NAME_PROPERTY_ID; static final String COMPONENT_NAME_PROPERTY_ID; static final String COMPONENT_VERSION_PROPERTY_ID; static final String COMPONENT_STATE_PROPERTY_ID; static final String PROPERTIES_PROPERTY_ID; }