@Test public void testGetResources() throws Exception{ Resource.Type type = Resource.Type.RootServiceComponent; AmbariManagementController managementController = createMock(AmbariManagementController.class); Set<RootServiceComponentResponse> allResponse = new HashSet<RootServiceComponentResponse>(); allResponse.add(new RootServiceComponentResponse("component1", "1.1.1", Collections.<String,String>emptyMap())); allResponse.add(new RootServiceComponentResponse("component2", "1.1.1", Collections.<String,String>emptyMap())); allResponse.add(new RootServiceComponentResponse("component3", "1.1.1", Collections.<String,String>emptyMap())); allResponse.add(new RootServiceComponentResponse(RootServiceResponseFactory.Components.AMBARI_SERVER.name(), "1.1.1", Collections.<String,String>emptyMap())); Set<RootServiceComponentResponse> nameResponse = new HashSet<RootServiceComponentResponse>(); nameResponse.add(new RootServiceComponentResponse("component4", "1.1.1", Collections.<String,String>emptyMap())); expect(managementController.getRootServiceComponents(EasyMock.<Set<RootServiceComponentRequest>>anyObject())).andReturn(allResponse).once(); expect(managementController.getRootServiceComponents(EasyMock.<Set<RootServiceComponentRequest>>anyObject())).andReturn(nameResponse).once(); replay(managementController); ResourceProvider provider = AbstractControllerResourceProvider.getResourceProvider( type, PropertyHelper.getPropertyIds(type), PropertyHelper.getKeyPropertyIds(type), managementController); Set<String> propertyIds = new HashSet<String>(); propertyIds.add(RootServiceComponentResourceProvider.SERVICE_NAME_PROPERTY_ID); propertyIds.add(RootServiceComponentResourceProvider.COMPONENT_NAME_PROPERTY_ID); propertyIds.add(RootServiceComponentResourceProvider.PROPERTIES_PROPERTY_ID); propertyIds.add(RootServiceComponentResourceProvider.COMPONENT_VERSION_PROPERTY_ID); propertyIds.add(RootServiceComponentResourceProvider.PROPERTIES_SERVER_CLOCK); Request request = PropertyHelper.getReadRequest(propertyIds); Set<Resource> resources = provider.getResources(request, null); Assert.assertEquals(allResponse.size(), resources.size()); for (Resource resource : resources) { String componentName = (String) resource.getPropertyValue(RootServiceComponentResourceProvider.COMPONENT_NAME_PROPERTY_ID); String componentVersion = (String) resource.getPropertyValue(RootServiceComponentResourceProvider.COMPONENT_VERSION_PROPERTY_ID); Long server_clock = (Long) resource.getPropertyValue(RootServiceComponentResourceProvider.PROPERTIES_SERVER_CLOCK); if (componentName.equals(RootServiceResponseFactory.Components.AMBARI_SERVER.name())){ Assert.assertNotNull(server_clock); } else { Assert.assertNull(server_clock); } Assert.assertTrue(allResponse.contains(new RootServiceComponentResponse(componentName, componentVersion, Collections.<String,String>emptyMap()))); } Predicate predicate = new PredicateBuilder().property(RootServiceComponentResourceProvider.COMPONENT_NAME_PROPERTY_ID). equals("component4").toPredicate(); resources = provider.getResources(request, predicate); Assert.assertEquals(1, resources.size()); Assert.assertEquals("component4", resources.iterator().next(). getPropertyValue(RootServiceComponentResourceProvider.COMPONENT_NAME_PROPERTY_ID)); verify(managementController); }
@Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { final Set<RootServiceComponentRequest> requests = new HashSet<RootServiceComponentRequest>(); 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<RootServiceComponentResponse> responses = getResources(new Command<Set<RootServiceComponentResponse>>() { @Override public Set<RootServiceComponentResponse> invoke() throws AmbariException { return getManagementController().getRootServiceComponents(requests); } }); Set<Resource> resources = new HashSet<Resource>(); for (RootServiceComponentResponse response : responses) { Resource resource = new ResourceImpl(Resource.Type.RootServiceComponent); setResourceProperty(resource, SERVICE_NAME_PROPERTY_ID, response.getServiceName(), requestedIds); setResourceProperty(resource, COMPONENT_NAME_PROPERTY_ID, response.getComponentName(), requestedIds); setResourceProperty(resource, PROPERTIES_PROPERTY_ID, response.getProperties(), requestedIds); setResourceProperty(resource, COMPONENT_VERSION_PROPERTY_ID, response.getComponentVersion(), requestedIds); if(response.getComponentName().equals(Components.AMBARI_SERVER.name())){ setResourceProperty(resource, PROPERTIES_SERVER_CLOCK, System.currentTimeMillis() / 1000L, requestedIds); } resources.add(resource); } return resources; }
RootServiceComponentResourceProvider extends
    ReadOnlyResourceProvider { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { final Set<RootServiceComponentRequest> requests = new HashSet<RootServiceComponentRequest>(); 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<RootServiceComponentResponse> responses = getResources(new Command<Set<RootServiceComponentResponse>>() { @Override public Set<RootServiceComponentResponse> invoke() throws AmbariException { return getManagementController().getRootServiceComponents(requests); } }); Set<Resource> resources = new HashSet<Resource>(); for (RootServiceComponentResponse response : responses) { Resource resource = new ResourceImpl(Resource.Type.RootServiceComponent); setResourceProperty(resource, SERVICE_NAME_PROPERTY_ID, response.getServiceName(), requestedIds); setResourceProperty(resource, COMPONENT_NAME_PROPERTY_ID, response.getComponentName(), requestedIds); setResourceProperty(resource, PROPERTIES_PROPERTY_ID, response.getProperties(), requestedIds); setResourceProperty(resource, COMPONENT_VERSION_PROPERTY_ID, response.getComponentVersion(), requestedIds); if(response.getComponentName().equals(Components.AMBARI_SERVER.name())){ setResourceProperty(resource, PROPERTIES_SERVER_CLOCK, System.currentTimeMillis() / 1000L, requestedIds); } resources.add(resource); } return resources; } }
RootServiceComponentResourceProvider extends
    ReadOnlyResourceProvider { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { final Set<RootServiceComponentRequest> requests = new HashSet<RootServiceComponentRequest>(); 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<RootServiceComponentResponse> responses = getResources(new Command<Set<RootServiceComponentResponse>>() { @Override public Set<RootServiceComponentResponse> invoke() throws AmbariException { return getManagementController().getRootServiceComponents(requests); } }); Set<Resource> resources = new HashSet<Resource>(); for (RootServiceComponentResponse response : responses) { Resource resource = new ResourceImpl(Resource.Type.RootServiceComponent); setResourceProperty(resource, SERVICE_NAME_PROPERTY_ID, response.getServiceName(), requestedIds); setResourceProperty(resource, COMPONENT_NAME_PROPERTY_ID, response.getComponentName(), requestedIds); setResourceProperty(resource, PROPERTIES_PROPERTY_ID, response.getProperties(), requestedIds); setResourceProperty(resource, COMPONENT_VERSION_PROPERTY_ID, response.getComponentVersion(), requestedIds); if(response.getComponentName().equals(Components.AMBARI_SERVER.name())){ setResourceProperty(resource, PROPERTIES_SERVER_CLOCK, System.currentTimeMillis() / 1000L, requestedIds); } resources.add(resource); } return resources; } protected  RootServiceComponentResourceProvider(Set<String> propertyIds,
      Map<Type, String> keyPropertyIds,
      AmbariManagementController managementController); }
RootServiceComponentResourceProvider extends
    ReadOnlyResourceProvider { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { final Set<RootServiceComponentRequest> requests = new HashSet<RootServiceComponentRequest>(); 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<RootServiceComponentResponse> responses = getResources(new Command<Set<RootServiceComponentResponse>>() { @Override public Set<RootServiceComponentResponse> invoke() throws AmbariException { return getManagementController().getRootServiceComponents(requests); } }); Set<Resource> resources = new HashSet<Resource>(); for (RootServiceComponentResponse response : responses) { Resource resource = new ResourceImpl(Resource.Type.RootServiceComponent); setResourceProperty(resource, SERVICE_NAME_PROPERTY_ID, response.getServiceName(), requestedIds); setResourceProperty(resource, COMPONENT_NAME_PROPERTY_ID, response.getComponentName(), requestedIds); setResourceProperty(resource, PROPERTIES_PROPERTY_ID, response.getProperties(), requestedIds); setResourceProperty(resource, COMPONENT_VERSION_PROPERTY_ID, response.getComponentVersion(), requestedIds); if(response.getComponentName().equals(Components.AMBARI_SERVER.name())){ setResourceProperty(resource, PROPERTIES_SERVER_CLOCK, System.currentTimeMillis() / 1000L, requestedIds); } resources.add(resource); } return resources; } protected  RootServiceComponentResourceProvider(Set<String> propertyIds,
      Map<Type, String> keyPropertyIds,
      AmbariManagementController managementController); @Override Set<Resource> getResources(Request request, Predicate predicate); }
RootServiceComponentResourceProvider extends
    ReadOnlyResourceProvider { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { final Set<RootServiceComponentRequest> requests = new HashSet<RootServiceComponentRequest>(); 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<RootServiceComponentResponse> responses = getResources(new Command<Set<RootServiceComponentResponse>>() { @Override public Set<RootServiceComponentResponse> invoke() throws AmbariException { return getManagementController().getRootServiceComponents(requests); } }); Set<Resource> resources = new HashSet<Resource>(); for (RootServiceComponentResponse response : responses) { Resource resource = new ResourceImpl(Resource.Type.RootServiceComponent); setResourceProperty(resource, SERVICE_NAME_PROPERTY_ID, response.getServiceName(), requestedIds); setResourceProperty(resource, COMPONENT_NAME_PROPERTY_ID, response.getComponentName(), requestedIds); setResourceProperty(resource, PROPERTIES_PROPERTY_ID, response.getProperties(), requestedIds); setResourceProperty(resource, COMPONENT_VERSION_PROPERTY_ID, response.getComponentVersion(), requestedIds); if(response.getComponentName().equals(Components.AMBARI_SERVER.name())){ setResourceProperty(resource, PROPERTIES_SERVER_CLOCK, System.currentTimeMillis() / 1000L, requestedIds); } resources.add(resource); } return resources; } protected  RootServiceComponentResourceProvider(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 COMPONENT_NAME_PROPERTY_ID; static final String COMPONENT_VERSION_PROPERTY_ID; static final String PROPERTIES_PROPERTY_ID; static final String PROPERTIES_SERVER_CLOCK; }