@Test public void testGetRequestSchedule() throws Exception { AmbariManagementController managementController = createMock(AmbariManagementController.class); RequestStatusResponse response = createNiceMock(RequestStatusResponse.class); Clusters clusters = createNiceMock(Clusters.class); Cluster cluster = createNiceMock(Cluster.class); final RequestExecution requestExecution = createNiceMock(RequestExecution.class); RequestScheduleResponse requestScheduleResponse = createNiceMock (RequestScheduleResponse.class); expect(managementController.getClusters()).andReturn(clusters).anyTimes(); expect(clusters.getCluster("Cluster100")).andReturn(cluster).anyTimes(); expect(managementController.getAuthName()).andReturn("admin").anyTimes(); expect(requestExecution.getId()).andReturn(25L).anyTimes(); expect(requestExecution.getStatus()).andReturn(RequestExecution.Status .SCHEDULED.name()).anyTimes(); expect(requestExecution.convertToResponse()).andReturn (requestScheduleResponse).anyTimes(); expect(requestExecution.convertToResponseWithBody()).andReturn (requestScheduleResponse).anyTimes(); expect(requestScheduleResponse.getId()).andReturn(25L).anyTimes(); expect(requestScheduleResponse.getClusterName()).andReturn("Cluster100") .anyTimes(); expect(cluster.getAllRequestExecutions()).andStubAnswer(new IAnswer<Map<Long, RequestExecution>>() { @Override public Map<Long, RequestExecution> answer() throws Throwable { Map<Long, RequestExecution> requestExecutionMap = new HashMap<Long, RequestExecution>(); requestExecutionMap.put(requestExecution.getId(), requestExecution); return requestExecutionMap; } }); replay(managementController, clusters, cluster, requestExecution, response, requestScheduleResponse); RequestScheduleResourceProvider resourceProvider = getResourceProvider (managementController); Map<String, Object> properties = new LinkedHashMap<String, Object>(); properties.put(RequestScheduleResourceProvider .REQUEST_SCHEDULE_CLUSTER_NAME_PROPERTY_ID, "Cluster100"); properties.put(RequestScheduleResourceProvider .REQUEST_SCHEDULE_DESC_PROPERTY_ID, "some description"); Set<String> propertyIds = new HashSet<String>(); propertyIds.add(RequestScheduleResourceProvider .REQUEST_SCHEDULE_CLUSTER_NAME_PROPERTY_ID); propertyIds.add(RequestScheduleResourceProvider .REQUEST_SCHEDULE_ID_PROPERTY_ID); Request request = PropertyHelper.getReadRequest(propertyIds); Predicate predicate = new PredicateBuilder().property (RequestScheduleResourceProvider.REQUEST_SCHEDULE_CLUSTER_NAME_PROPERTY_ID) .equals("Cluster100").and().property(RequestScheduleResourceProvider .REQUEST_SCHEDULE_ID_PROPERTY_ID).equals(25L).toPredicate(); Set<Resource> resources = resourceProvider.getResources(request, predicate); Assert.assertEquals(1, resources.size()); Assert.assertEquals(25L, resources.iterator().next().getPropertyValue (RequestScheduleResourceProvider.REQUEST_SCHEDULE_ID_PROPERTY_ID)); predicate = new PredicateBuilder().property (RequestScheduleResourceProvider.REQUEST_SCHEDULE_CLUSTER_NAME_PROPERTY_ID) .equals("Cluster100").toPredicate(); resources = resourceProvider.getResources(request, predicate); Assert.assertEquals(1, resources.size()); Assert.assertEquals(25L, resources.iterator().next().getPropertyValue (RequestScheduleResourceProvider.REQUEST_SCHEDULE_ID_PROPERTY_ID)); verify(managementController, clusters, cluster, requestExecution, response, requestScheduleResponse); }
@Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { final Set<RequestScheduleRequest> requests = new HashSet<RequestScheduleRequest>(); for (Map<String, Object> propertyMap : getPropertyMaps(predicate)) { requests.add(getRequestScheduleRequest(propertyMap)); } Set<RequestScheduleResponse> responses = getResources(new Command<Set<RequestScheduleResponse>>() { @Override public Set<RequestScheduleResponse> invoke() throws AmbariException { return getRequestSchedules(requests); } }); Set<String> requestedIds = getRequestPropertyIds(request, predicate); Set<Resource> resources = new HashSet<Resource>(); for (RequestScheduleResponse response : responses) { Resource resource = new ResourceImpl(Resource.Type.RequestSchedule); setResourceProperty(resource, REQUEST_SCHEDULE_ID_PROPERTY_ID, response.getId(), requestedIds); setResourceProperty(resource, REQUEST_SCHEDULE_CLUSTER_NAME_PROPERTY_ID, response.getClusterName(), requestedIds); setResourceProperty(resource, REQUEST_SCHEDULE_DESC_PROPERTY_ID, response.getDescription(), requestedIds); setResourceProperty(resource, REQUEST_SCHEDULE_STATUS_PROPERTY_ID, response.getStatus(), requestedIds); setResourceProperty(resource, REQUEST_SCHEDULE_LAST_STATUS_PROPERTY_ID, response.getLastExecutionStatus(), requestedIds); setResourceProperty(resource, REQUEST_SCHEDULE_BATCH_PROPERTY_ID, response.getBatch(), requestedIds); setResourceProperty(resource, REQUEST_SCHEDULE_SCHEDULE_PROPERTY_ID, response.getSchedule(), requestedIds); setResourceProperty(resource, REQUEST_SCHEDULE_CREATE_USER_PROPERTY_ID, response.getCreateUser(), requestedIds); setResourceProperty(resource, REQUEST_SCHEDULE_AUTHENTICATED_USER_PROPERTY_ID, response.getAuthenticatedUserId(), requestedIds); setResourceProperty(resource, REQUEST_SCHEDULE_CREATE_TIME_PROPERTY_ID, response.getCreateTime(), requestedIds); setResourceProperty(resource, REQUEST_SCHEDULE_UPDATE_USER_PROPERTY_ID, response.getUpdateUser(), requestedIds); setResourceProperty(resource, REQUEST_SCHEDULE_UPDATE_TIME_PROPERTY_ID, response.getUpdateTime(), requestedIds); resources.add(resource); } return resources; }
RequestScheduleResourceProvider extends AbstractControllerResourceProvider { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { final Set<RequestScheduleRequest> requests = new HashSet<RequestScheduleRequest>(); for (Map<String, Object> propertyMap : getPropertyMaps(predicate)) { requests.add(getRequestScheduleRequest(propertyMap)); } Set<RequestScheduleResponse> responses = getResources(new Command<Set<RequestScheduleResponse>>() { @Override public Set<RequestScheduleResponse> invoke() throws AmbariException { return getRequestSchedules(requests); } }); Set<String> requestedIds = getRequestPropertyIds(request, predicate); Set<Resource> resources = new HashSet<Resource>(); for (RequestScheduleResponse response : responses) { Resource resource = new ResourceImpl(Resource.Type.RequestSchedule); setResourceProperty(resource, REQUEST_SCHEDULE_ID_PROPERTY_ID, response.getId(), requestedIds); setResourceProperty(resource, REQUEST_SCHEDULE_CLUSTER_NAME_PROPERTY_ID, response.getClusterName(), requestedIds); setResourceProperty(resource, REQUEST_SCHEDULE_DESC_PROPERTY_ID, response.getDescription(), requestedIds); setResourceProperty(resource, REQUEST_SCHEDULE_STATUS_PROPERTY_ID, response.getStatus(), requestedIds); setResourceProperty(resource, REQUEST_SCHEDULE_LAST_STATUS_PROPERTY_ID, response.getLastExecutionStatus(), requestedIds); setResourceProperty(resource, REQUEST_SCHEDULE_BATCH_PROPERTY_ID, response.getBatch(), requestedIds); setResourceProperty(resource, REQUEST_SCHEDULE_SCHEDULE_PROPERTY_ID, response.getSchedule(), requestedIds); setResourceProperty(resource, REQUEST_SCHEDULE_CREATE_USER_PROPERTY_ID, response.getCreateUser(), requestedIds); setResourceProperty(resource, REQUEST_SCHEDULE_AUTHENTICATED_USER_PROPERTY_ID, response.getAuthenticatedUserId(), requestedIds); setResourceProperty(resource, REQUEST_SCHEDULE_CREATE_TIME_PROPERTY_ID, response.getCreateTime(), requestedIds); setResourceProperty(resource, REQUEST_SCHEDULE_UPDATE_USER_PROPERTY_ID, response.getUpdateUser(), requestedIds); setResourceProperty(resource, REQUEST_SCHEDULE_UPDATE_TIME_PROPERTY_ID, response.getUpdateTime(), requestedIds); resources.add(resource); } return resources; } }
RequestScheduleResourceProvider extends AbstractControllerResourceProvider { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { final Set<RequestScheduleRequest> requests = new HashSet<RequestScheduleRequest>(); for (Map<String, Object> propertyMap : getPropertyMaps(predicate)) { requests.add(getRequestScheduleRequest(propertyMap)); } Set<RequestScheduleResponse> responses = getResources(new Command<Set<RequestScheduleResponse>>() { @Override public Set<RequestScheduleResponse> invoke() throws AmbariException { return getRequestSchedules(requests); } }); Set<String> requestedIds = getRequestPropertyIds(request, predicate); Set<Resource> resources = new HashSet<Resource>(); for (RequestScheduleResponse response : responses) { Resource resource = new ResourceImpl(Resource.Type.RequestSchedule); setResourceProperty(resource, REQUEST_SCHEDULE_ID_PROPERTY_ID, response.getId(), requestedIds); setResourceProperty(resource, REQUEST_SCHEDULE_CLUSTER_NAME_PROPERTY_ID, response.getClusterName(), requestedIds); setResourceProperty(resource, REQUEST_SCHEDULE_DESC_PROPERTY_ID, response.getDescription(), requestedIds); setResourceProperty(resource, REQUEST_SCHEDULE_STATUS_PROPERTY_ID, response.getStatus(), requestedIds); setResourceProperty(resource, REQUEST_SCHEDULE_LAST_STATUS_PROPERTY_ID, response.getLastExecutionStatus(), requestedIds); setResourceProperty(resource, REQUEST_SCHEDULE_BATCH_PROPERTY_ID, response.getBatch(), requestedIds); setResourceProperty(resource, REQUEST_SCHEDULE_SCHEDULE_PROPERTY_ID, response.getSchedule(), requestedIds); setResourceProperty(resource, REQUEST_SCHEDULE_CREATE_USER_PROPERTY_ID, response.getCreateUser(), requestedIds); setResourceProperty(resource, REQUEST_SCHEDULE_AUTHENTICATED_USER_PROPERTY_ID, response.getAuthenticatedUserId(), requestedIds); setResourceProperty(resource, REQUEST_SCHEDULE_CREATE_TIME_PROPERTY_ID, response.getCreateTime(), requestedIds); setResourceProperty(resource, REQUEST_SCHEDULE_UPDATE_USER_PROPERTY_ID, response.getUpdateUser(), requestedIds); setResourceProperty(resource, REQUEST_SCHEDULE_UPDATE_TIME_PROPERTY_ID, response.getUpdateTime(), requestedIds); resources.add(resource); } return resources; } protected  RequestScheduleResourceProvider(Set<String> propertyIds,
      Map<Resource.Type, String> keyPropertyIds,
        AmbariManagementController managementController); }
RequestScheduleResourceProvider extends AbstractControllerResourceProvider { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { final Set<RequestScheduleRequest> requests = new HashSet<RequestScheduleRequest>(); for (Map<String, Object> propertyMap : getPropertyMaps(predicate)) { requests.add(getRequestScheduleRequest(propertyMap)); } Set<RequestScheduleResponse> responses = getResources(new Command<Set<RequestScheduleResponse>>() { @Override public Set<RequestScheduleResponse> invoke() throws AmbariException { return getRequestSchedules(requests); } }); Set<String> requestedIds = getRequestPropertyIds(request, predicate); Set<Resource> resources = new HashSet<Resource>(); for (RequestScheduleResponse response : responses) { Resource resource = new ResourceImpl(Resource.Type.RequestSchedule); setResourceProperty(resource, REQUEST_SCHEDULE_ID_PROPERTY_ID, response.getId(), requestedIds); setResourceProperty(resource, REQUEST_SCHEDULE_CLUSTER_NAME_PROPERTY_ID, response.getClusterName(), requestedIds); setResourceProperty(resource, REQUEST_SCHEDULE_DESC_PROPERTY_ID, response.getDescription(), requestedIds); setResourceProperty(resource, REQUEST_SCHEDULE_STATUS_PROPERTY_ID, response.getStatus(), requestedIds); setResourceProperty(resource, REQUEST_SCHEDULE_LAST_STATUS_PROPERTY_ID, response.getLastExecutionStatus(), requestedIds); setResourceProperty(resource, REQUEST_SCHEDULE_BATCH_PROPERTY_ID, response.getBatch(), requestedIds); setResourceProperty(resource, REQUEST_SCHEDULE_SCHEDULE_PROPERTY_ID, response.getSchedule(), requestedIds); setResourceProperty(resource, REQUEST_SCHEDULE_CREATE_USER_PROPERTY_ID, response.getCreateUser(), requestedIds); setResourceProperty(resource, REQUEST_SCHEDULE_AUTHENTICATED_USER_PROPERTY_ID, response.getAuthenticatedUserId(), requestedIds); setResourceProperty(resource, REQUEST_SCHEDULE_CREATE_TIME_PROPERTY_ID, response.getCreateTime(), requestedIds); setResourceProperty(resource, REQUEST_SCHEDULE_UPDATE_USER_PROPERTY_ID, response.getUpdateUser(), requestedIds); setResourceProperty(resource, REQUEST_SCHEDULE_UPDATE_TIME_PROPERTY_ID, response.getUpdateTime(), requestedIds); resources.add(resource); } return resources; } protected  RequestScheduleResourceProvider(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 request, Predicate predicate); @Override RequestStatus deleteResources(Request request, Predicate predicate); }
RequestScheduleResourceProvider extends AbstractControllerResourceProvider { @Override public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException { final Set<RequestScheduleRequest> requests = new HashSet<RequestScheduleRequest>(); for (Map<String, Object> propertyMap : getPropertyMaps(predicate)) { requests.add(getRequestScheduleRequest(propertyMap)); } Set<RequestScheduleResponse> responses = getResources(new Command<Set<RequestScheduleResponse>>() { @Override public Set<RequestScheduleResponse> invoke() throws AmbariException { return getRequestSchedules(requests); } }); Set<String> requestedIds = getRequestPropertyIds(request, predicate); Set<Resource> resources = new HashSet<Resource>(); for (RequestScheduleResponse response : responses) { Resource resource = new ResourceImpl(Resource.Type.RequestSchedule); setResourceProperty(resource, REQUEST_SCHEDULE_ID_PROPERTY_ID, response.getId(), requestedIds); setResourceProperty(resource, REQUEST_SCHEDULE_CLUSTER_NAME_PROPERTY_ID, response.getClusterName(), requestedIds); setResourceProperty(resource, REQUEST_SCHEDULE_DESC_PROPERTY_ID, response.getDescription(), requestedIds); setResourceProperty(resource, REQUEST_SCHEDULE_STATUS_PROPERTY_ID, response.getStatus(), requestedIds); setResourceProperty(resource, REQUEST_SCHEDULE_LAST_STATUS_PROPERTY_ID, response.getLastExecutionStatus(), requestedIds); setResourceProperty(resource, REQUEST_SCHEDULE_BATCH_PROPERTY_ID, response.getBatch(), requestedIds); setResourceProperty(resource, REQUEST_SCHEDULE_SCHEDULE_PROPERTY_ID, response.getSchedule(), requestedIds); setResourceProperty(resource, REQUEST_SCHEDULE_CREATE_USER_PROPERTY_ID, response.getCreateUser(), requestedIds); setResourceProperty(resource, REQUEST_SCHEDULE_AUTHENTICATED_USER_PROPERTY_ID, response.getAuthenticatedUserId(), requestedIds); setResourceProperty(resource, REQUEST_SCHEDULE_CREATE_TIME_PROPERTY_ID, response.getCreateTime(), requestedIds); setResourceProperty(resource, REQUEST_SCHEDULE_UPDATE_USER_PROPERTY_ID, response.getUpdateUser(), requestedIds); setResourceProperty(resource, REQUEST_SCHEDULE_UPDATE_TIME_PROPERTY_ID, response.getUpdateTime(), requestedIds); resources.add(resource); } return resources; } protected  RequestScheduleResourceProvider(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 request, Predicate predicate); @Override RequestStatus deleteResources(Request request, Predicate predicate);  }