@Test public void testGetResourcesWithRequestInfo() throws Exception { Resource.Type type = Resource.Type.Request; expect(requestDAO.findByPks(Collections.<Long> emptyList(), true)).andReturn(Collections.<RequestEntity>emptyList()).anyTimes(); ActionManager actionManager = createNiceMock(ActionManager.class); Cluster cluster = createNiceMock(Cluster.class); expect(cluster.getClusterId()).andReturn(1L).anyTimes(); expect(cluster.getResourceId()).andReturn(4L).anyTimes(); Clusters clusters = createNiceMock(Clusters.class); expect(clusters.getCluster("foo_cluster")).andReturn(cluster).anyTimes(); AmbariManagementController managementController = createMock(AmbariManagementController.class); expect(managementController.getActionManager()).andReturn(actionManager).anyTimes(); expect(managementController.getClusters()).andReturn(clusters).anyTimes(); replay(managementController, clusters, cluster); ResourceProvider provider = AbstractControllerResourceProvider.getResourceProvider(type, PropertyHelper.getPropertyIds(type), PropertyHelper.getKeyPropertyIds(type), managementController); Map<String, String> requestInfoProperties = new HashMap<String, String>(); Request request; Predicate predicate = new PredicateBuilder() .property(RequestResourceProvider.REQUEST_CLUSTER_NAME_PROPERTY_ID) .equals("foo_cluster") .and().property(RequestResourceProvider.REQUEST_ID_PROPERTY_ID) .equals(null) .and().property(RequestResourceProvider.REQUEST_STATUS_PROPERTY_ID) .equals(null) .toPredicate(); request = PropertyHelper.getReadRequest(new HashSet<String>(), requestInfoProperties, null, null, null); expect(requestDAO.findAllRequestIds(BaseRequest.DEFAULT_PAGE_SIZE, false, 1L)).andReturn(Collections.<Long> emptyList()).anyTimes(); replay(requestDAO); provider.getResources(request, predicate); verify(requestDAO); requestInfoProperties.put(BaseRequest.PAGE_SIZE_PROPERTY_KEY, "20"); request = PropertyHelper.getReadRequest(new HashSet<String>(), requestInfoProperties, null, null, null); provider.getResources(request, predicate); verify(requestDAO); reset(requestDAO); requestInfoProperties.put(BaseRequest.ASC_ORDER_PROPERTY_KEY, "true"); request = PropertyHelper.getReadRequest(new HashSet<String>(), requestInfoProperties, null, null, null); expect(requestDAO.findByPks(Collections.<Long> emptyList(), true)).andReturn(Collections.<RequestEntity>emptyList()).anyTimes(); expect(requestDAO.findAllRequestIds(BaseRequest.DEFAULT_PAGE_SIZE, true, 1L)).andReturn(Collections.<Long> emptyList()).anyTimes(); replay(requestDAO); provider.getResources(request, predicate); verify(requestDAO); }
@Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { Set<String> requestedIds = getRequestPropertyIds(request, predicate); Set<Resource> resources = new HashSet<Resource>(); String maxResultsRaw = request.getRequestInfoProperties().get(BaseRequest.PAGE_SIZE_PROPERTY_KEY); String ascOrderRaw = request.getRequestInfoProperties().get(BaseRequest.ASC_ORDER_PROPERTY_KEY); Integer maxResults = (maxResultsRaw == null ? null : Integer.parseInt(maxResultsRaw)); Boolean ascOrder = (ascOrderRaw == null ? null : Boolean.parseBoolean(ascOrderRaw)); if (null == predicate) { resources.addAll( getRequestResources(null, null, null, maxResults, ascOrder, requestedIds)); } else { for (Map<String, Object> properties : getPropertyMaps(predicate)) { String clusterName = (String) properties.get(REQUEST_CLUSTER_NAME_PROPERTY_ID); Long requestId = null; if (properties.get(REQUEST_ID_PROPERTY_ID) != null) { requestId = Long.valueOf((String) properties.get(REQUEST_ID_PROPERTY_ID)); } String requestStatus = null; if (properties.get(REQUEST_STATUS_PROPERTY_ID) != null) { requestStatus = (String) properties.get(REQUEST_STATUS_PROPERTY_ID); } resources.addAll(getRequestResources(clusterName, requestId, requestStatus, maxResults, ascOrder, requestedIds)); } } return resources; }
RequestResourceProvider extends AbstractControllerResourceProvider { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { Set<String> requestedIds = getRequestPropertyIds(request, predicate); Set<Resource> resources = new HashSet<Resource>(); String maxResultsRaw = request.getRequestInfoProperties().get(BaseRequest.PAGE_SIZE_PROPERTY_KEY); String ascOrderRaw = request.getRequestInfoProperties().get(BaseRequest.ASC_ORDER_PROPERTY_KEY); Integer maxResults = (maxResultsRaw == null ? null : Integer.parseInt(maxResultsRaw)); Boolean ascOrder = (ascOrderRaw == null ? null : Boolean.parseBoolean(ascOrderRaw)); if (null == predicate) { resources.addAll( getRequestResources(null, null, null, maxResults, ascOrder, requestedIds)); } else { for (Map<String, Object> properties : getPropertyMaps(predicate)) { String clusterName = (String) properties.get(REQUEST_CLUSTER_NAME_PROPERTY_ID); Long requestId = null; if (properties.get(REQUEST_ID_PROPERTY_ID) != null) { requestId = Long.valueOf((String) properties.get(REQUEST_ID_PROPERTY_ID)); } String requestStatus = null; if (properties.get(REQUEST_STATUS_PROPERTY_ID) != null) { requestStatus = (String) properties.get(REQUEST_STATUS_PROPERTY_ID); } resources.addAll(getRequestResources(clusterName, requestId, requestStatus, maxResults, ascOrder, requestedIds)); } } return resources; } }
RequestResourceProvider extends AbstractControllerResourceProvider { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { Set<String> requestedIds = getRequestPropertyIds(request, predicate); Set<Resource> resources = new HashSet<Resource>(); String maxResultsRaw = request.getRequestInfoProperties().get(BaseRequest.PAGE_SIZE_PROPERTY_KEY); String ascOrderRaw = request.getRequestInfoProperties().get(BaseRequest.ASC_ORDER_PROPERTY_KEY); Integer maxResults = (maxResultsRaw == null ? null : Integer.parseInt(maxResultsRaw)); Boolean ascOrder = (ascOrderRaw == null ? null : Boolean.parseBoolean(ascOrderRaw)); if (null == predicate) { resources.addAll( getRequestResources(null, null, null, maxResults, ascOrder, requestedIds)); } else { for (Map<String, Object> properties : getPropertyMaps(predicate)) { String clusterName = (String) properties.get(REQUEST_CLUSTER_NAME_PROPERTY_ID); Long requestId = null; if (properties.get(REQUEST_ID_PROPERTY_ID) != null) { requestId = Long.valueOf((String) properties.get(REQUEST_ID_PROPERTY_ID)); } String requestStatus = null; if (properties.get(REQUEST_STATUS_PROPERTY_ID) != null) { requestStatus = (String) properties.get(REQUEST_STATUS_PROPERTY_ID); } resources.addAll(getRequestResources(clusterName, requestId, requestStatus, maxResults, ascOrder, requestedIds)); } } return resources; } RequestResourceProvider(Set<String> propertyIds,
                          Map<Resource.Type, String> keyPropertyIds,
                          AmbariManagementController managementController); }
RequestResourceProvider extends AbstractControllerResourceProvider { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { Set<String> requestedIds = getRequestPropertyIds(request, predicate); Set<Resource> resources = new HashSet<Resource>(); String maxResultsRaw = request.getRequestInfoProperties().get(BaseRequest.PAGE_SIZE_PROPERTY_KEY); String ascOrderRaw = request.getRequestInfoProperties().get(BaseRequest.ASC_ORDER_PROPERTY_KEY); Integer maxResults = (maxResultsRaw == null ? null : Integer.parseInt(maxResultsRaw)); Boolean ascOrder = (ascOrderRaw == null ? null : Boolean.parseBoolean(ascOrderRaw)); if (null == predicate) { resources.addAll( getRequestResources(null, null, null, maxResults, ascOrder, requestedIds)); } else { for (Map<String, Object> properties : getPropertyMaps(predicate)) { String clusterName = (String) properties.get(REQUEST_CLUSTER_NAME_PROPERTY_ID); Long requestId = null; if (properties.get(REQUEST_ID_PROPERTY_ID) != null) { requestId = Long.valueOf((String) properties.get(REQUEST_ID_PROPERTY_ID)); } String requestStatus = null; if (properties.get(REQUEST_STATUS_PROPERTY_ID) != null) { requestStatus = (String) properties.get(REQUEST_STATUS_PROPERTY_ID); } resources.addAll(getRequestResources(clusterName, requestId, requestStatus, maxResults, ascOrder, requestedIds)); } } return resources; } RequestResourceProvider(Set<String> propertyIds,
                          Map<Resource.Type, String> keyPropertyIds,
                          AmbariManagementController managementController); @Override RequestStatus createResources(Request request); @Override Set<Resource> getResources(Request request, Predicate predicate); @Override RequestStatus updateResources(Request requestInfo, Predicate predicate); @Override RequestStatus deleteResources(Request request, Predicate predicate); }
RequestResourceProvider extends AbstractControllerResourceProvider { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { Set<String> requestedIds = getRequestPropertyIds(request, predicate); Set<Resource> resources = new HashSet<Resource>(); String maxResultsRaw = request.getRequestInfoProperties().get(BaseRequest.PAGE_SIZE_PROPERTY_KEY); String ascOrderRaw = request.getRequestInfoProperties().get(BaseRequest.ASC_ORDER_PROPERTY_KEY); Integer maxResults = (maxResultsRaw == null ? null : Integer.parseInt(maxResultsRaw)); Boolean ascOrder = (ascOrderRaw == null ? null : Boolean.parseBoolean(ascOrderRaw)); if (null == predicate) { resources.addAll( getRequestResources(null, null, null, maxResults, ascOrder, requestedIds)); } else { for (Map<String, Object> properties : getPropertyMaps(predicate)) { String clusterName = (String) properties.get(REQUEST_CLUSTER_NAME_PROPERTY_ID); Long requestId = null; if (properties.get(REQUEST_ID_PROPERTY_ID) != null) { requestId = Long.valueOf((String) properties.get(REQUEST_ID_PROPERTY_ID)); } String requestStatus = null; if (properties.get(REQUEST_STATUS_PROPERTY_ID) != null) { requestStatus = (String) properties.get(REQUEST_STATUS_PROPERTY_ID); } resources.addAll(getRequestResources(clusterName, requestId, requestStatus, maxResults, ascOrder, requestedIds)); } } return resources; } RequestResourceProvider(Set<String> propertyIds,
                          Map<Resource.Type, String> keyPropertyIds,
                          AmbariManagementController managementController); @Override RequestStatus createResources(Request request); @Override Set<Resource> getResources(Request request, Predicate predicate); @Override RequestStatus updateResources(Request requestInfo, Predicate predicate); @Override RequestStatus deleteResources(Request request, Predicate predicate); static final String REQUEST_CLUSTER_NAME_PROPERTY_ID; static final String REQUEST_CLUSTER_ID_PROPERTY_ID; static final String REQUEST_ID_PROPERTY_ID; static final String REQUEST_SOURCE_SCHEDULE; static final String REQUEST_SOURCE_SCHEDULE_ID; static final String REQUEST_SOURCE_SCHEDULE_HREF; }