ActionDBAccessorImpl implements ActionDBAccessor { @Override public List<Long> getRequestsByStatus(RequestStatus status, int maxResults, boolean ascOrder) { if (null == status) { return requestDAO.findAllRequestIds(maxResults, ascOrder); } EnumSet<HostRoleStatus> taskStatuses = null; switch( status ){ case IN_PROGRESS: taskStatuses = HostRoleStatus.IN_PROGRESS_STATUSES; break; case FAILED: taskStatuses = HostRoleStatus.FAILED_STATUSES; break; case COMPLETED: return hostRoleCommandDAO.getCompletedRequests(maxResults, ascOrder); } return hostRoleCommandDAO.getRequestsByTaskStatus(taskStatuses, maxResults, ascOrder); } @Inject  ActionDBAccessorImpl(@Named("executionCommandCacheSize") long cacheLimit,
                              AmbariEventPublisher eventPublisher); @Override Stage getStage(String actionId); @Override List<Stage> getAllStages(long requestId); @Override RequestEntity getRequestEntity(long requestId); @Override Request getRequest(long requestId); @Override Collection<HostRoleCommandEntity> abortOperation(long requestId); @Override void timeoutHostRole(String host, long requestId, long stageId,
                              String role); @Override void timeoutHostRole(String host, long requestId, long stageId, String role,
                              boolean skipSupported, boolean hostUnknownState); @Override @Experimental(feature = ExperimentalFeature.PARALLEL_PROCESSING) List<Stage> getStagesInProgressForRequest(Long requestId); @Override @Experimental(feature = ExperimentalFeature.PARALLEL_PROCESSING) List<Stage> getStagesInProgress(); @Override int getCommandsInProgressCount(); @Override @Transactional @TransactionalLock(lockArea = LockArea.HRC_STATUS_CACHE, lockType = LockType.WRITE) void persistActions(Request request); @Override @Transactional void startRequest(long requestId); @Override @Transactional void endRequest(long requestId); void endRequestIfCompleted(long requestId); @Override @Transactional void setSourceScheduleForRequest(long requestId, long scheduleId); @Override void updateHostRoleStates(Collection<CommandReport> reports); @Override void updateHostRoleState(String hostname, long requestId,
                                  long stageId, String role, CommandReport report); @Override void abortHostRole(String host, long requestId, long stageId, String role); @Override void abortHostRole(String host, long requestId, long stageId, String role, String reason); @Override long getLastPersistedRequestIdWhenInitialized(); @Override @Transactional void bulkHostRoleScheduled(Stage s, List<ExecutionCommand> commands); @Override @Transactional void bulkAbortHostRole(Stage s, Map<ExecutionCommand, String> commands); @Override @Transactional void hostRoleScheduled(Stage s, String hostname, String roleStr); @Override List<HostRoleCommand> getRequestTasks(long requestId); @Override List<HostRoleCommand> getAllTasksByRequestIds(Collection<Long> requestIds); @Override List<HostRoleCommand> getTasks(Collection<Long> taskIds); @Override List<HostRoleCommand> getTasksByHostRoleAndStatus(String hostname, String role, HostRoleStatus status); @Override List<HostRoleCommand> getTasksByRoleAndStatus(String role, HostRoleStatus status); @Override HostRoleCommand getTask(long taskId); @Override List<Long> getRequestsByStatus(RequestStatus status, int maxResults,
    boolean ascOrder); @Override Map<Long, String> getRequestContext(List<Long> requestIds); @Override String getRequestContext(long requestId); @Override List<Request> getRequests(Collection<Long> requestIds); @Override void resubmitTasks(List<Long> taskIds); @Subscribe void invalidateCommandCacheOnHostRemove(HostsRemovedEvent event);  }
@Test public void testGetRequestsByStatus() throws AmbariException { List<Long> requestIds = new ArrayList<Long>(); requestIds.add(requestId + 1); requestIds.add(requestId); populateActionDB(db, hostName, requestId, stageId); clusters.addHost("host2"); populateActionDB(db, hostName, requestId + 1, stageId); List<Long> requestIdsResult = db.getRequestsByStatus(null, BaseRequest.DEFAULT_PAGE_SIZE, false); assertNotNull("List of request IDs is null", requestIdsResult); assertEquals("Request IDs not matches", requestIds, requestIdsResult); }
@Test public void testGetCompletedRequests() throws AmbariException { List<Long> requestIds = new ArrayList<Long>(); requestIds.add(requestId); requestIds.add(requestId + 1); populateActionDBWithCompletedRequest(db, hostName, requestId, stageId); List<Long> requestIdsResult = db.getRequestsByStatus(RequestStatus.COMPLETED, BaseRequest.DEFAULT_PAGE_SIZE, false); assertEquals(1, requestIdsResult.size()); assertTrue(requestIdsResult.contains(requestId)); populateActionDBWithPartiallyCompletedRequest(db, hostName, requestId + 1, stageId); requestIdsResult = db.getRequestsByStatus(RequestStatus.COMPLETED, BaseRequest.DEFAULT_PAGE_SIZE, false); assertEquals(1, requestIdsResult.size()); assertTrue(requestIdsResult.contains(requestId)); }
@Test public void testGetRequestsByStatusWithParams() throws AmbariException { List<Long> ids = new ArrayList<Long>(); for (long l = 1; l <= 10; l++) { ids.add(l); } for (Long id : ids) { populateActionDB(db, hostName, id, stageId); } List<Long> expected = null; List<Long> actual = null; actual = db.getRequestsByStatus(null, BaseRequest.DEFAULT_PAGE_SIZE, false); expected = reverse(new ArrayList<Long>(ids)); assertEquals("Request IDs not matches", expected, actual); actual = db.getRequestsByStatus(null, 4, false); expected = reverse(new ArrayList<Long>(ids.subList(ids.size() - 4, ids.size()))); assertEquals("Request IDs not matches", expected, actual); actual = db.getRequestsByStatus(null, 7, true); expected = new ArrayList<Long>(ids.subList(0, 7)); assertEquals("Request IDs not matches", expected, actual); }