Search in sources :

Example 1 with PageBoundaries

use of org.ow2.proactive.scheduler.common.util.PageBoundaries in project scheduling by ow2-proactive.

the class SchedulerStateRest method getTaskStatesByTag.

@Override
public RestPage<TaskStateData> getTaskStatesByTag(String sessionId, String taskTag, long from, long to, boolean mytasks, boolean running, boolean pending, boolean finished, int offset, int limit, SortSpecifierContainer sortParams) throws NotConnectedRestException, PermissionRestException {
    Scheduler s = checkAccess(sessionId, "tasks/tag/" + taskTag);
    PageBoundaries boundaries = Pagination.getTasksPageBoundaries(offset, limit, TASKS_PAGE_SIZE);
    Page<TaskState> page = null;
    // sortParams will be null
    if (sortParams == null) {
        sortParams = new SortSpecifierContainer();
    }
    try {
        page = s.getTaskStates(taskTag, from, to, mytasks, running, pending, finished, boundaries.getOffset(), boundaries.getLimit(), sortParams);
        List<TaskStateData> tasks = map(page.getList(), TaskStateData.class);
        return new RestPage<TaskStateData>(tasks, page.getSize());
    } catch (NotConnectedException e) {
        throw new NotConnectedRestException(e);
    } catch (PermissionException e) {
        throw new PermissionRestException(e);
    }
}
Also used : PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) SortSpecifierContainer(org.ow2.proactive.scheduler.common.SortSpecifierContainer) TaskStateData(org.ow2.proactive_grid_cloud_portal.scheduler.dto.TaskStateData) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) PermissionRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException) Scheduler(org.ow2.proactive.scheduler.common.Scheduler) RestPage(org.ow2.proactive_grid_cloud_portal.scheduler.dto.RestPage) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException) PageBoundaries(org.ow2.proactive.scheduler.common.util.PageBoundaries) TaskState(org.ow2.proactive.scheduler.common.task.TaskState)

Example 2 with PageBoundaries

use of org.ow2.proactive.scheduler.common.util.PageBoundaries in project scheduling by ow2-proactive.

the class JobState method getTaskStatesPage.

private TaskStatesPage getTaskStatesPage(int offset, int limit, List<TaskState> tasks) {
    PageBoundaries pageBoundaries = Pagination.getTasksPageBoundaries(offset, limit, PASchedulerProperties.TASKS_PAGE_SIZE.getValueAsInt());
    int nbTasks = tasks.size();
    int indexLastItemToReturn = pageBoundaries.getOffset() + pageBoundaries.getLimit();
    offset = pageBoundaries.getOffset();
    if (offset >= nbTasks) {
        offset = 0;
    }
    if (indexLastItemToReturn >= nbTasks) {
        indexLastItemToReturn = nbTasks;
    }
    return new TaskStatesPage(tasks.subList(offset, indexLastItemToReturn), nbTasks);
}
Also used : PageBoundaries(org.ow2.proactive.scheduler.common.util.PageBoundaries) TaskStatesPage(org.ow2.proactive.scheduler.common.task.TaskStatesPage)

Example 3 with PageBoundaries

use of org.ow2.proactive.scheduler.common.util.PageBoundaries in project scheduling by ow2-proactive.

the class SchedulerStateRest method getTaskIdsByTag.

@Override
public RestPage<String> getTaskIdsByTag(String sessionId, String taskTag, long from, long to, boolean mytasks, boolean running, boolean pending, boolean finished, int offset, int limit) throws NotConnectedRestException, PermissionRestException {
    Scheduler s = checkAccess(sessionId, "tasks");
    PageBoundaries boundaries = Pagination.getTasksPageBoundaries(offset, limit, TASKS_PAGE_SIZE);
    Page<TaskId> page = null;
    try {
        page = s.getTaskIds(taskTag, from, to, mytasks, running, pending, finished, boundaries.getOffset(), boundaries.getLimit());
        List<TaskId> taskIds = page.getList();
        List<String> taskNames = new ArrayList<>(taskIds.size());
        for (TaskId taskId : taskIds) {
            taskNames.add(taskId.getReadableName());
        }
        return new RestPage<String>(taskNames, page.getSize());
    } catch (NotConnectedException e) {
        throw new NotConnectedRestException(e);
    } catch (PermissionException e) {
        throw new PermissionRestException(e);
    }
}
Also used : PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) TaskId(org.ow2.proactive.scheduler.common.task.TaskId) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) Scheduler(org.ow2.proactive.scheduler.common.Scheduler) ArrayList(java.util.ArrayList) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException) PermissionRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException) RestPage(org.ow2.proactive_grid_cloud_portal.scheduler.dto.RestPage) PageBoundaries(org.ow2.proactive.scheduler.common.util.PageBoundaries)

Aggregations

PageBoundaries (org.ow2.proactive.scheduler.common.util.PageBoundaries)3 Scheduler (org.ow2.proactive.scheduler.common.Scheduler)2 NotConnectedException (org.ow2.proactive.scheduler.common.exception.NotConnectedException)2 PermissionException (org.ow2.proactive.scheduler.common.exception.PermissionException)2 RestPage (org.ow2.proactive_grid_cloud_portal.scheduler.dto.RestPage)2 NotConnectedRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException)2 PermissionRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException)2 ArrayList (java.util.ArrayList)1 SortSpecifierContainer (org.ow2.proactive.scheduler.common.SortSpecifierContainer)1 TaskId (org.ow2.proactive.scheduler.common.task.TaskId)1 TaskState (org.ow2.proactive.scheduler.common.task.TaskState)1 TaskStatesPage (org.ow2.proactive.scheduler.common.task.TaskStatesPage)1 TaskStateData (org.ow2.proactive_grid_cloud_portal.scheduler.dto.TaskStateData)1