Search in sources :

Example 11 with TaskState

use of org.ow2.proactive.scheduler.common.task.TaskState in project scheduling by ow2-proactive.

the class SchedulerClient method getTaskResultsByTag.

@Override
public List<TaskResult> getTaskResultsByTag(JobId jobId, String taskTag) throws NotConnectedException, UnknownJobException, PermissionException {
    List<TaskState> taskStates = getJobState(jobId).getTasksByTag(taskTag);
    ArrayList<TaskResult> results = new ArrayList<TaskResult>(taskStates.size());
    for (TaskState currentState : taskStates) {
        String taskName = currentState.getTaskInfo().getName();
        try {
            TaskResult currentResult = getTaskResult(jobId, taskName);
            results.add(currentResult);
        } catch (UnknownTaskException ex) {
            // never occurs because tasks are filtered by tag so they cannot
            // be unknown.
            logger.warn("Unknown task.", ex);
        }
    }
    return results;
}
Also used : UnknownTaskException(org.ow2.proactive.scheduler.common.exception.UnknownTaskException) ArrayList(java.util.ArrayList) DataUtility.toTaskResult(org.ow2.proactive.scheduler.rest.data.DataUtility.toTaskResult) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) TaskState(org.ow2.proactive.scheduler.common.task.TaskState)

Example 12 with TaskState

use of org.ow2.proactive.scheduler.common.task.TaskState in project scheduling by ow2-proactive.

the class SchedulerClient method getTaskStates.

@Override
public Page<TaskState> getTaskStates(String taskTag, long from, long to, boolean mytasks, boolean running, boolean pending, boolean finished, int offset, int limit, SortSpecifierContainer sortParams) throws NotConnectedException, PermissionException {
    RestPage<TaskStateData> page = null;
    SortSpecifierContainer sortContainer = new SortSpecifierContainer(sortParams.toString());
    try {
        page = restApi().getTaskStates(sid, from, to, mytasks, running, pending, finished, offset, limit, sortContainer);
    } catch (NotConnectedRestException e) {
        throw new NotConnectedException(e);
    } catch (PermissionRestException e) {
        throw new PermissionException(e);
    }
    List<TaskState> lTaskStates = new ArrayList<TaskState>(page.getList().size());
    for (TaskStateData taskStateData : page.getList()) {
        lTaskStates.add(new TaskStateImpl(taskStateData));
    }
    return new Page<TaskState>(lTaskStates, page.getSize());
}
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) ArrayList(java.util.ArrayList) TaskStateImpl(org.ow2.proactive.scheduler.rest.data.TaskStateImpl) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException) Page(org.ow2.proactive.scheduler.common.Page) RestPage(org.ow2.proactive_grid_cloud_portal.scheduler.dto.RestPage) TaskState(org.ow2.proactive.scheduler.common.task.TaskState)

Example 13 with TaskState

use of org.ow2.proactive.scheduler.common.task.TaskState in project scheduling by ow2-proactive.

the class JobStateImpl method getHMTasks.

@Override
public Map<TaskId, TaskState> getHMTasks() {
    Map<String, TaskStateData> taskStateDataMap = jobStateData.getTasks();
    Map<TaskId, TaskState> taskStateMap = new HashMap<>();
    for (TaskStateData taskStateData : taskStateDataMap.values()) {
        TaskIdData taskIdData = taskStateData.getTaskInfo().getTaskId();
        taskStateMap.put(DataUtility.taskId(DataUtility.jobId(jobStateData.getJobInfo().getJobId()), taskIdData), DataUtility.taskState(taskStateData));
    }
    return taskStateMap;
}
Also used : TaskId(org.ow2.proactive.scheduler.common.task.TaskId) TaskStateData(org.ow2.proactive_grid_cloud_portal.scheduler.dto.TaskStateData) HashMap(java.util.HashMap) TaskIdData(org.ow2.proactive_grid_cloud_portal.scheduler.dto.TaskIdData) TaskState(org.ow2.proactive.scheduler.common.task.TaskState)

Example 14 with TaskState

use of org.ow2.proactive.scheduler.common.task.TaskState in project scheduling by ow2-proactive.

the class ClientJobStateSerializationTest method JobStateSerializationRestoresAllDependenciesFromClientTaskSates.

@Test
public void JobStateSerializationRestoresAllDependenciesFromClientTaskSates() {
    // Task1 depends on task2
    ClientTaskState clientTaskState1 = new ClientTaskState(new TestTaskState(1L));
    ClientTaskState clientTaskState2 = new ClientTaskState(new TestTaskState(2L));
    clientTaskState2.getDependences().add(clientTaskState1);
    // Create JClientJobState which contains task1 and task2
    TestJobState testJobState = new TestJobState(1);
    testJobState.getHMTasks().put(clientTaskState1.getId(), clientTaskState1);
    testJobState.getHMTasks().put(clientTaskState2.getId(), clientTaskState2);
    ClientJobState clientJobState = new ClientJobState(testJobState);
    // Serialize and de-serialize the ClientJobState instance
    ClientJobState deserializedClientJobState = null;
    try {
        ByteArrayOutputStream output = new ByteArrayOutputStream();
        new ObjectOutputStream(output).writeObject(clientJobState);
        deserializedClientJobState = (ClientJobState) new ObjectInputStream(new ByteArrayInputStream(output.toByteArray())).readObject();
    } catch (Exception e) {
        e.printStackTrace();
        fail("Serialization must not fail with exception. " + e.getMessage());
    }
    List<TaskState> listWithOneElement = deserializedClientJobState.getHMTasks().get(clientTaskState2.getId()).getDependences();
    assertThat(listWithOneElement.size(), is(1));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ClientJobState(org.ow2.proactive.scheduler.job.ClientJobState) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) TaskState(org.ow2.proactive.scheduler.common.task.TaskState) ClientTaskState(org.ow2.proactive.scheduler.task.ClientTaskState) ClientTaskState(org.ow2.proactive.scheduler.task.ClientTaskState) ObjectInputStream(java.io.ObjectInputStream) Test(org.junit.Test)

Example 15 with TaskState

use of org.ow2.proactive.scheduler.common.task.TaskState in project scheduling by ow2-proactive.

the class ClientJobStateTest method createJobState.

private JobState createJobState(final JobInfoImpl jobInfo) {
    return new JobState() {

        @Override
        public void update(TaskInfo info) {
        }

        @Override
        public void update(JobInfo jobInfo) {
        }

        @Override
        public JobInfo getJobInfo() {
            return jobInfo;
        }

        @Override
        public List<TaskState> getTasks() {
            List<TaskState> tasks = new ArrayList<>(0);
            tasks.add(new TaskState() {

                @Override
                public void update(TaskInfo taskInfo) {
                }

                @Override
                public List<TaskState> getDependences() {
                    return null;
                }

                @Override
                public TaskInfo getTaskInfo() {
                    TaskInfoImpl taskInfo = new TaskInfoImpl();
                    taskInfo.setJobInfo(jobInfo);
                    taskInfo.setTaskId(TaskIdImpl.createTaskId(jobInfo.getJobId(), "task", 1));
                    return taskInfo;
                }

                @Override
                public int getMaxNumberOfExecutionOnFailure() {
                    return 0;
                }

                @Override
                public TaskState replicate() throws Exception {
                    return null;
                }

                @Override
                public int getIterationIndex() {
                    return 0;
                }

                @Override
                public int getReplicationIndex() {
                    return 0;
                }
            });
            return tasks;
        }

        @Override
        public Map<TaskId, TaskState> getHMTasks() {
            return null;
        }

        @Override
        public String getOwner() {
            return null;
        }

        @Override
        public JobType getType() {
            return null;
        }
    };
}
Also used : TaskInfo(org.ow2.proactive.scheduler.common.task.TaskInfo) TaskId(org.ow2.proactive.scheduler.common.task.TaskId) JobInfo(org.ow2.proactive.scheduler.common.job.JobInfo) ArrayList(java.util.ArrayList) JobState(org.ow2.proactive.scheduler.common.job.JobState) TaskInfoImpl(org.ow2.proactive.scheduler.task.TaskInfoImpl) ArrayList(java.util.ArrayList) List(java.util.List) TaskState(org.ow2.proactive.scheduler.common.task.TaskState) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

TaskState (org.ow2.proactive.scheduler.common.task.TaskState)54 JobState (org.ow2.proactive.scheduler.common.job.JobState)23 ArrayList (java.util.ArrayList)15 Test (org.junit.Test)14 Scheduler (org.ow2.proactive.scheduler.common.Scheduler)13 TaskStateData (org.ow2.proactive_grid_cloud_portal.scheduler.dto.TaskStateData)13 UnknownJobException (org.ow2.proactive.scheduler.common.exception.UnknownJobException)12 NotConnectedException (org.ow2.proactive.scheduler.common.exception.NotConnectedException)11 PermissionException (org.ow2.proactive.scheduler.common.exception.PermissionException)11 JobId (org.ow2.proactive.scheduler.common.job.JobId)10 NotConnectedRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException)10 PermissionRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException)10 UnknownTaskException (org.ow2.proactive.scheduler.common.exception.UnknownTaskException)9 TaskId (org.ow2.proactive.scheduler.common.task.TaskId)9 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)8 TaskStatesPage (org.ow2.proactive.scheduler.common.task.TaskStatesPage)8 UnknownJobRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.UnknownJobRestException)8 GET (javax.ws.rs.GET)7 Path (javax.ws.rs.Path)7 Produces (javax.ws.rs.Produces)7