@Test public void testGetResources() throws Exception { StageResourceProvider provider = new StageResourceProvider(managementController); Request request = createNiceMock(Request.class); Predicate predicate = createNiceMock(Predicate.class); List<StageEntity> entities = getStageEntities(HostRoleStatus.COMPLETED); expect(dao.findAll(request, predicate)).andReturn(entities); expect(clusters.getClusterById(anyLong())).andReturn(cluster).anyTimes(); expect(cluster.getClusterName()).andReturn("c1").anyTimes(); replay(dao, clusters, cluster, request, predicate); Set<Resource> resources = provider.getResources(request, predicate); Assert.assertEquals(1, resources.size()); Resource resource = resources.iterator().next(); Assert.assertEquals(100.0, resource.getPropertyValue(StageResourceProvider.STAGE_PROGRESS_PERCENT)); Assert.assertEquals(HostRoleStatus.COMPLETED, resource.getPropertyValue(StageResourceProvider.STAGE_STATUS)); Assert.assertEquals(HostRoleStatus.COMPLETED, resource.getPropertyValue(StageResourceProvider.STAGE_DISPLAY_STATUS)); Assert.assertEquals(1000L, resource.getPropertyValue(StageResourceProvider.STAGE_START_TIME)); Assert.assertEquals(2500L, resource.getPropertyValue(StageResourceProvider.STAGE_END_TIME)); verify(dao, clusters, cluster); }
@Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { Set<Resource> results = new LinkedHashSet<Resource>(); Set<String> propertyIds = getRequestPropertyIds(request, predicate); Map<Long, Map<Long, HostRoleCommandStatusSummaryDTO>> cache = new HashMap<Long, Map<Long, HostRoleCommandStatusSummaryDTO>>(); List<StageEntity> entities = dao.findAll(request, predicate); for (StageEntity entity : entities) { results.add(toResource(cache, entity, propertyIds)); } cache.clear(); Map<String, Object> map = PredicateHelper.getProperties(predicate); if (map.containsKey(STAGE_REQUEST_ID)) { Long requestId = NumberUtils.toLong(map.get(STAGE_REQUEST_ID).toString()); LogicalRequest lr = topologyManager.getRequest(requestId); if (null != lr) { Collection<StageEntity> topologyManagerStages = lr.getStageEntities(); for (StageEntity entity : topologyManagerStages) { Resource stageResource = toResource(entity, propertyIds); if (predicate.evaluate(stageResource)) { results.add(stageResource); } } } } else { Collection<StageEntity> topologyManagerStages = topologyManager.getStages(); for (StageEntity entity : topologyManagerStages) { Resource stageResource = toResource(entity, propertyIds); if (predicate.evaluate(stageResource)) { results.add(stageResource); } } } return results; }
StageResourceProvider extends AbstractControllerResourceProvider implements ExtendedResourceProvider { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { Set<Resource> results = new LinkedHashSet<Resource>(); Set<String> propertyIds = getRequestPropertyIds(request, predicate); Map<Long, Map<Long, HostRoleCommandStatusSummaryDTO>> cache = new HashMap<Long, Map<Long, HostRoleCommandStatusSummaryDTO>>(); List<StageEntity> entities = dao.findAll(request, predicate); for (StageEntity entity : entities) { results.add(toResource(cache, entity, propertyIds)); } cache.clear(); Map<String, Object> map = PredicateHelper.getProperties(predicate); if (map.containsKey(STAGE_REQUEST_ID)) { Long requestId = NumberUtils.toLong(map.get(STAGE_REQUEST_ID).toString()); LogicalRequest lr = topologyManager.getRequest(requestId); if (null != lr) { Collection<StageEntity> topologyManagerStages = lr.getStageEntities(); for (StageEntity entity : topologyManagerStages) { Resource stageResource = toResource(entity, propertyIds); if (predicate.evaluate(stageResource)) { results.add(stageResource); } } } } else { Collection<StageEntity> topologyManagerStages = topologyManager.getStages(); for (StageEntity entity : topologyManagerStages) { Resource stageResource = toResource(entity, propertyIds); if (predicate.evaluate(stageResource)) { results.add(stageResource); } } } return results; } }
StageResourceProvider extends AbstractControllerResourceProvider implements ExtendedResourceProvider { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { Set<Resource> results = new LinkedHashSet<Resource>(); Set<String> propertyIds = getRequestPropertyIds(request, predicate); Map<Long, Map<Long, HostRoleCommandStatusSummaryDTO>> cache = new HashMap<Long, Map<Long, HostRoleCommandStatusSummaryDTO>>(); List<StageEntity> entities = dao.findAll(request, predicate); for (StageEntity entity : entities) { results.add(toResource(cache, entity, propertyIds)); } cache.clear(); Map<String, Object> map = PredicateHelper.getProperties(predicate); if (map.containsKey(STAGE_REQUEST_ID)) { Long requestId = NumberUtils.toLong(map.get(STAGE_REQUEST_ID).toString()); LogicalRequest lr = topologyManager.getRequest(requestId); if (null != lr) { Collection<StageEntity> topologyManagerStages = lr.getStageEntities(); for (StageEntity entity : topologyManagerStages) { Resource stageResource = toResource(entity, propertyIds); if (predicate.evaluate(stageResource)) { results.add(stageResource); } } } } else { Collection<StageEntity> topologyManagerStages = topologyManager.getStages(); for (StageEntity entity : topologyManagerStages) { Resource stageResource = toResource(entity, propertyIds); if (predicate.evaluate(stageResource)) { results.add(stageResource); } } } return results; } StageResourceProvider(AmbariManagementController managementController); }
StageResourceProvider extends AbstractControllerResourceProvider implements ExtendedResourceProvider { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { Set<Resource> results = new LinkedHashSet<Resource>(); Set<String> propertyIds = getRequestPropertyIds(request, predicate); Map<Long, Map<Long, HostRoleCommandStatusSummaryDTO>> cache = new HashMap<Long, Map<Long, HostRoleCommandStatusSummaryDTO>>(); List<StageEntity> entities = dao.findAll(request, predicate); for (StageEntity entity : entities) { results.add(toResource(cache, entity, propertyIds)); } cache.clear(); Map<String, Object> map = PredicateHelper.getProperties(predicate); if (map.containsKey(STAGE_REQUEST_ID)) { Long requestId = NumberUtils.toLong(map.get(STAGE_REQUEST_ID).toString()); LogicalRequest lr = topologyManager.getRequest(requestId); if (null != lr) { Collection<StageEntity> topologyManagerStages = lr.getStageEntities(); for (StageEntity entity : topologyManagerStages) { Resource stageResource = toResource(entity, propertyIds); if (predicate.evaluate(stageResource)) { results.add(stageResource); } } } } else { Collection<StageEntity> topologyManagerStages = topologyManager.getStages(); for (StageEntity entity : topologyManagerStages) { Resource stageResource = toResource(entity, propertyIds); if (predicate.evaluate(stageResource)) { results.add(stageResource); } } } return results; } StageResourceProvider(AmbariManagementController managementController); @Override RequestStatus createResources(Request request); @Override RequestStatus updateResources(Request request, Predicate predicate); @Override RequestStatus deleteResources(Request request, Predicate predicate); @Override Set<Resource> getResources(Request request, Predicate predicate); @Override QueryResponse queryForResources(Request request, Predicate predicate); }
StageResourceProvider extends AbstractControllerResourceProvider implements ExtendedResourceProvider { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { Set<Resource> results = new LinkedHashSet<Resource>(); Set<String> propertyIds = getRequestPropertyIds(request, predicate); Map<Long, Map<Long, HostRoleCommandStatusSummaryDTO>> cache = new HashMap<Long, Map<Long, HostRoleCommandStatusSummaryDTO>>(); List<StageEntity> entities = dao.findAll(request, predicate); for (StageEntity entity : entities) { results.add(toResource(cache, entity, propertyIds)); } cache.clear(); Map<String, Object> map = PredicateHelper.getProperties(predicate); if (map.containsKey(STAGE_REQUEST_ID)) { Long requestId = NumberUtils.toLong(map.get(STAGE_REQUEST_ID).toString()); LogicalRequest lr = topologyManager.getRequest(requestId); if (null != lr) { Collection<StageEntity> topologyManagerStages = lr.getStageEntities(); for (StageEntity entity : topologyManagerStages) { Resource stageResource = toResource(entity, propertyIds); if (predicate.evaluate(stageResource)) { results.add(stageResource); } } } } else { Collection<StageEntity> topologyManagerStages = topologyManager.getStages(); for (StageEntity entity : topologyManagerStages) { Resource stageResource = toResource(entity, propertyIds); if (predicate.evaluate(stageResource)) { results.add(stageResource); } } } return results; } StageResourceProvider(AmbariManagementController managementController); @Override RequestStatus createResources(Request request); @Override RequestStatus updateResources(Request request, Predicate predicate); @Override RequestStatus deleteResources(Request request, Predicate predicate); @Override Set<Resource> getResources(Request request, Predicate predicate); @Override QueryResponse queryForResources(Request request, Predicate predicate); static final String STAGE_STAGE_ID; static final String STAGE_CLUSTER_NAME; static final String STAGE_REQUEST_ID; static final String STAGE_LOG_INFO; static final String STAGE_CONTEXT; static final String STAGE_CLUSTER_HOST_INFO; static final String STAGE_COMMAND_PARAMS; static final String STAGE_HOST_PARAMS; static final String STAGE_SKIPPABLE; static final String STAGE_PROGRESS_PERCENT; static final String STAGE_STATUS; static final String STAGE_DISPLAY_STATUS; static final String STAGE_START_TIME; static final String STAGE_END_TIME; }