@Test public void testGetResources_many() throws Exception { @SuppressWarnings("unchecked") ResourceProvider provider = init( new HashMap<String,String>() {{ put("status", "RUNNING"); put("name", "a"); }}, new HashMap<String,String>() {{ put("status", "RUNNING"); put("name", "b"); }}, new HashMap<String,String>() {{ put("status", "NOT_RUNNING"); put("name", "c"); }}); PredicateBuilder pb = new PredicateBuilder().property( HostComponentProcessResourceProvider.HC_PROCESS_CLUSTER_NAME_ID).equals("c1").and(); pb = pb.property( HostComponentProcessResourceProvider.HC_PROCESS_HOST_NAME_ID).equals("h1").and(); Predicate predicate = pb.property( HostComponentProcessResourceProvider.HC_PROCESS_COMPONENT_NAME_ID).equals("comp1").toPredicate(); Request request = PropertyHelper.getReadRequest(Collections.<String>emptySet()); Set<Resource> resources = provider.getResources(request, predicate); Assert.assertEquals(Integer.valueOf(3), Integer.valueOf(resources.size())); for (Resource r : resources) { Assert.assertNotNull(r.getPropertyValue(HostComponentProcessResourceProvider.HC_PROCESS_NAME_ID)); Assert.assertNotNull(r.getPropertyValue(HostComponentProcessResourceProvider.HC_PROCESS_STATUS_ID)); } }
@Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { final Set<Map<String, Object>> requestMaps = getPropertyMaps(predicate); Set<String> requestedIds = getRequestPropertyIds(request, predicate); Set<HostComponentProcessResponse> responses = getResources(new Command<Set<HostComponentProcessResponse>>() { @Override public Set<HostComponentProcessResponse> invoke() throws AmbariException { return getHostComponentProcesses(requestMaps); } }); Set<Resource> resources = new HashSet<Resource>(); for (HostComponentProcessResponse response : responses) { Resource r = new ResourceImpl(Resource.Type.HostComponentProcess); setResourceProperty(r, HC_PROCESS_CLUSTER_NAME_ID, response.getCluster(), requestedIds); setResourceProperty(r, HC_PROCESS_HOST_NAME_ID, response.getHost(), requestedIds); setResourceProperty(r, HC_PROCESS_COMPONENT_NAME_ID, response.getComponent(), requestedIds); setResourceProperty(r, HC_PROCESS_NAME_ID, response.getValueMap().get("name"), requestedIds); setResourceProperty(r, HC_PROCESS_STATUS_ID, response.getValueMap().get("status"), requestedIds); for (Entry<String, String> entry : response.getValueMap().entrySet()) { if (entry.getKey().equals("name") || entry.getKey().equals("status")) continue; setResourceProperty(r, "HostComponentProcess/" + entry.getKey(), entry.getValue(), requestedIds); } resources.add(r); } return resources; }
HostComponentProcessResourceProvider extends ReadOnlyResourceProvider { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { final Set<Map<String, Object>> requestMaps = getPropertyMaps(predicate); Set<String> requestedIds = getRequestPropertyIds(request, predicate); Set<HostComponentProcessResponse> responses = getResources(new Command<Set<HostComponentProcessResponse>>() { @Override public Set<HostComponentProcessResponse> invoke() throws AmbariException { return getHostComponentProcesses(requestMaps); } }); Set<Resource> resources = new HashSet<Resource>(); for (HostComponentProcessResponse response : responses) { Resource r = new ResourceImpl(Resource.Type.HostComponentProcess); setResourceProperty(r, HC_PROCESS_CLUSTER_NAME_ID, response.getCluster(), requestedIds); setResourceProperty(r, HC_PROCESS_HOST_NAME_ID, response.getHost(), requestedIds); setResourceProperty(r, HC_PROCESS_COMPONENT_NAME_ID, response.getComponent(), requestedIds); setResourceProperty(r, HC_PROCESS_NAME_ID, response.getValueMap().get("name"), requestedIds); setResourceProperty(r, HC_PROCESS_STATUS_ID, response.getValueMap().get("status"), requestedIds); for (Entry<String, String> entry : response.getValueMap().entrySet()) { if (entry.getKey().equals("name") || entry.getKey().equals("status")) continue; setResourceProperty(r, "HostComponentProcess/" + entry.getKey(), entry.getValue(), requestedIds); } resources.add(r); } return resources; } }
HostComponentProcessResourceProvider extends ReadOnlyResourceProvider { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { final Set<Map<String, Object>> requestMaps = getPropertyMaps(predicate); Set<String> requestedIds = getRequestPropertyIds(request, predicate); Set<HostComponentProcessResponse> responses = getResources(new Command<Set<HostComponentProcessResponse>>() { @Override public Set<HostComponentProcessResponse> invoke() throws AmbariException { return getHostComponentProcesses(requestMaps); } }); Set<Resource> resources = new HashSet<Resource>(); for (HostComponentProcessResponse response : responses) { Resource r = new ResourceImpl(Resource.Type.HostComponentProcess); setResourceProperty(r, HC_PROCESS_CLUSTER_NAME_ID, response.getCluster(), requestedIds); setResourceProperty(r, HC_PROCESS_HOST_NAME_ID, response.getHost(), requestedIds); setResourceProperty(r, HC_PROCESS_COMPONENT_NAME_ID, response.getComponent(), requestedIds); setResourceProperty(r, HC_PROCESS_NAME_ID, response.getValueMap().get("name"), requestedIds); setResourceProperty(r, HC_PROCESS_STATUS_ID, response.getValueMap().get("status"), requestedIds); for (Entry<String, String> entry : response.getValueMap().entrySet()) { if (entry.getKey().equals("name") || entry.getKey().equals("status")) continue; setResourceProperty(r, "HostComponentProcess/" + entry.getKey(), entry.getValue(), requestedIds); } resources.add(r); } return resources; } HostComponentProcessResourceProvider(Set<String> propertyIds,
      Map<Resource.Type, String> keyPropertyIds, AmbariManagementController amc); }
HostComponentProcessResourceProvider extends ReadOnlyResourceProvider { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { final Set<Map<String, Object>> requestMaps = getPropertyMaps(predicate); Set<String> requestedIds = getRequestPropertyIds(request, predicate); Set<HostComponentProcessResponse> responses = getResources(new Command<Set<HostComponentProcessResponse>>() { @Override public Set<HostComponentProcessResponse> invoke() throws AmbariException { return getHostComponentProcesses(requestMaps); } }); Set<Resource> resources = new HashSet<Resource>(); for (HostComponentProcessResponse response : responses) { Resource r = new ResourceImpl(Resource.Type.HostComponentProcess); setResourceProperty(r, HC_PROCESS_CLUSTER_NAME_ID, response.getCluster(), requestedIds); setResourceProperty(r, HC_PROCESS_HOST_NAME_ID, response.getHost(), requestedIds); setResourceProperty(r, HC_PROCESS_COMPONENT_NAME_ID, response.getComponent(), requestedIds); setResourceProperty(r, HC_PROCESS_NAME_ID, response.getValueMap().get("name"), requestedIds); setResourceProperty(r, HC_PROCESS_STATUS_ID, response.getValueMap().get("status"), requestedIds); for (Entry<String, String> entry : response.getValueMap().entrySet()) { if (entry.getKey().equals("name") || entry.getKey().equals("status")) continue; setResourceProperty(r, "HostComponentProcess/" + entry.getKey(), entry.getValue(), requestedIds); } resources.add(r); } return resources; } HostComponentProcessResourceProvider(Set<String> propertyIds,
      Map<Resource.Type, String> keyPropertyIds, AmbariManagementController amc); @Override Set<Resource> getResources(Request request, Predicate predicate); }
HostComponentProcessResourceProvider extends ReadOnlyResourceProvider { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { final Set<Map<String, Object>> requestMaps = getPropertyMaps(predicate); Set<String> requestedIds = getRequestPropertyIds(request, predicate); Set<HostComponentProcessResponse> responses = getResources(new Command<Set<HostComponentProcessResponse>>() { @Override public Set<HostComponentProcessResponse> invoke() throws AmbariException { return getHostComponentProcesses(requestMaps); } }); Set<Resource> resources = new HashSet<Resource>(); for (HostComponentProcessResponse response : responses) { Resource r = new ResourceImpl(Resource.Type.HostComponentProcess); setResourceProperty(r, HC_PROCESS_CLUSTER_NAME_ID, response.getCluster(), requestedIds); setResourceProperty(r, HC_PROCESS_HOST_NAME_ID, response.getHost(), requestedIds); setResourceProperty(r, HC_PROCESS_COMPONENT_NAME_ID, response.getComponent(), requestedIds); setResourceProperty(r, HC_PROCESS_NAME_ID, response.getValueMap().get("name"), requestedIds); setResourceProperty(r, HC_PROCESS_STATUS_ID, response.getValueMap().get("status"), requestedIds); for (Entry<String, String> entry : response.getValueMap().entrySet()) { if (entry.getKey().equals("name") || entry.getKey().equals("status")) continue; setResourceProperty(r, "HostComponentProcess/" + entry.getKey(), entry.getValue(), requestedIds); } resources.add(r); } return resources; } HostComponentProcessResourceProvider(Set<String> propertyIds,
      Map<Resource.Type, String> keyPropertyIds, AmbariManagementController amc); @Override Set<Resource> getResources(Request request, Predicate predicate); static final String HC_PROCESS_NAME_ID; static final String HC_PROCESS_STATUS_ID; static final String HC_PROCESS_CLUSTER_NAME_ID; static final String HC_PROCESS_HOST_NAME_ID; static final String HC_PROCESS_COMPONENT_NAME_ID; }