Search in sources :

Example 1 with ClientJobState

use of org.ow2.proactive.scheduler.job.ClientJobState in project scheduling by ow2-proactive.

the class DozerMappingTest method createJobState.

private JobState createJobState() {
    return new ClientJobState(new JobState() {

        @Override
        public void update(TaskInfo taskInfo) {
        }

        @Override
        public void update(JobInfo jobInfo) {
        }

        @Override
        public JobInfo getJobInfo() {
            return new JobInfoImpl();
        }

        @Override
        public ArrayList<TaskState> getTasks() {
            return new ArrayList<>(getHMTasks().values());
        }

        @Override
        public Map<TaskId, TaskState> getHMTasks() {
            TaskId taskId = TaskIdImpl.createTaskId(new JobIdImpl(42, "job"), "remoteVisuTask", 1);
            TaskState value = new ClientTaskState(new TaskState() {

                @Override
                public void update(TaskInfo taskInfo) {
                }

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

                @Override
                public TaskInfo getTaskInfo() {
                    TaskInfoImpl taskInfo = new TaskInfoImpl();
                    taskInfo.setTaskId(TaskIdImpl.createTaskId(new JobIdImpl(42, "job"), "remoteVisuTask", 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 Collections.singletonMap(taskId, value);
        }

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

        @Override
        public JobType getType() {
            return null;
        }
    });
}
Also used : TaskId(org.ow2.proactive.scheduler.common.task.TaskId) ArrayList(java.util.ArrayList) TaskInfoImpl(org.ow2.proactive.scheduler.task.TaskInfoImpl) ClientTaskState(org.ow2.proactive.scheduler.task.ClientTaskState) TaskInfo(org.ow2.proactive.scheduler.common.task.TaskInfo) JobType(org.ow2.proactive.scheduler.common.job.JobType) JobInfo(org.ow2.proactive.scheduler.common.job.JobInfo) ClientJobState(org.ow2.proactive.scheduler.job.ClientJobState) JobState(org.ow2.proactive.scheduler.common.job.JobState) ClientJobState(org.ow2.proactive.scheduler.job.ClientJobState) JobIdImpl(org.ow2.proactive.scheduler.job.JobIdImpl) JobInfoImpl(org.ow2.proactive.scheduler.job.JobInfoImpl) Map(java.util.Map) TaskState(org.ow2.proactive.scheduler.common.task.TaskState) ClientTaskState(org.ow2.proactive.scheduler.task.ClientTaskState)

Example 2 with ClientJobState

use of org.ow2.proactive.scheduler.job.ClientJobState 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 3 with ClientJobState

use of org.ow2.proactive.scheduler.job.ClientJobState in project scheduling by ow2-proactive.

the class SchedulerFrontendState method getJobState.

JobState getJobState(JobId jobId) throws NotConnectedException, UnknownJobException, PermissionException {
    checkPermissions("getJobState", getIdentifiedJob(jobId), YOU_DO_NOT_HAVE_PERMISSION_TO_GET_THE_STATE_OF_THIS_JOB);
    return Lambda.withLock(stateReadLock, () -> {
        ClientJobState jobState = getClientJobState(jobId);
        ClientJobState jobStateCopy;
        if (jobState == null) {
            throw new UnknownJobException(jobId);
        }
        try {
            jobState.readLock();
            try {
                jobStateCopy = (ClientJobState) ProActiveMakeDeepCopy.WithProActiveObjectStream.makeDeepCopy(jobState);
            } catch (Exception e) {
                logger.error("Error when copying job state", e);
                throw new IllegalStateException(e);
            }
        } finally {
            jobState.readUnlock();
        }
        return jobStateCopy;
    });
}
Also used : UnknownJobException(org.ow2.proactive.scheduler.common.exception.UnknownJobException) ClientJobState(org.ow2.proactive.scheduler.job.ClientJobState) UnknownJobException(org.ow2.proactive.scheduler.common.exception.UnknownJobException) JobAlreadyFinishedException(org.ow2.proactive.scheduler.common.exception.JobAlreadyFinishedException) SubmissionClosedException(org.ow2.proactive.scheduler.common.exception.SubmissionClosedException) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) AlreadyConnectedException(org.ow2.proactive.scheduler.common.exception.AlreadyConnectedException) UnknownTaskException(org.ow2.proactive.scheduler.common.exception.UnknownTaskException) SchedulerException(org.ow2.proactive.scheduler.common.exception.SchedulerException)

Example 4 with ClientJobState

use of org.ow2.proactive.scheduler.job.ClientJobState in project scheduling by ow2-proactive.

the class SchedulerFrontendState method getTaskState.

TaskState getTaskState(JobId jobId, TaskId taskId) throws NotConnectedException, UnknownJobException, UnknownTaskException, PermissionException {
    checkPermissions("getJobState", getIdentifiedJob(jobId), YOU_DO_NOT_HAVE_PERMISSION_TO_GET_THE_STATE_OF_THIS_TASK);
    return Lambda.withLockException2(stateReadLock, () -> {
        ClientJobState jobState = getClientJobState(jobId);
        if (jobState == null) {
            throw new UnknownJobException(jobId);
        }
        try {
            jobState.readLock();
            TaskState ts = jobState.getHMTasks().get(taskId);
            if (ts == null) {
                throw new UnknownTaskException(taskId, jobId);
            }
            return ts;
        } finally {
            jobState.readUnlock();
        }
    }, UnknownJobException.class, UnknownTaskException.class);
}
Also used : UnknownTaskException(org.ow2.proactive.scheduler.common.exception.UnknownTaskException) UnknownJobException(org.ow2.proactive.scheduler.common.exception.UnknownJobException) ClientJobState(org.ow2.proactive.scheduler.job.ClientJobState)

Example 5 with ClientJobState

use of org.ow2.proactive.scheduler.job.ClientJobState in project scheduling by ow2-proactive.

the class SchedulerFrontendState method getTaskPaginated.

public TaskStatesPage getTaskPaginated(JobId jobId, String statusFilter, int offset, int limit) throws UnknownJobException, NotConnectedException, PermissionException {
    checkPermissions("getJobState", getIdentifiedJob(jobId), YOU_DO_NOT_HAVE_PERMISSION_TO_GET_THE_STATE_OF_THIS_JOB);
    ClientJobState jobState = getClientJobState(jobId);
    if (jobState == null) {
        throw new UnknownJobException(jobId);
    }
    try {
        jobState.readLock();
        try {
            final TaskStatesPage tasksPaginated = jobState.getTasksPaginated(statusFilter, offset, limit);
            final List<TaskState> taskStatesCopy = (List<TaskState>) ProActiveMakeDeepCopy.WithProActiveObjectStream.makeDeepCopy(new ArrayList<>(tasksPaginated.getTaskStates()));
            return new TaskStatesPage(taskStatesCopy, tasksPaginated.getSize());
        } catch (Exception e) {
            logger.error("Error when copying tasks page", e);
            throw new IllegalStateException(e);
        }
    } finally {
        jobState.readUnlock();
    }
}
Also used : UnknownJobException(org.ow2.proactive.scheduler.common.exception.UnknownJobException) ClientJobState(org.ow2.proactive.scheduler.job.ClientJobState) UnknownJobException(org.ow2.proactive.scheduler.common.exception.UnknownJobException) JobAlreadyFinishedException(org.ow2.proactive.scheduler.common.exception.JobAlreadyFinishedException) SubmissionClosedException(org.ow2.proactive.scheduler.common.exception.SubmissionClosedException) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) AlreadyConnectedException(org.ow2.proactive.scheduler.common.exception.AlreadyConnectedException) UnknownTaskException(org.ow2.proactive.scheduler.common.exception.UnknownTaskException) SchedulerException(org.ow2.proactive.scheduler.common.exception.SchedulerException)

Aggregations

ClientJobState (org.ow2.proactive.scheduler.job.ClientJobState)19 UnknownJobException (org.ow2.proactive.scheduler.common.exception.UnknownJobException)6 Test (org.junit.Test)5 UnknownTaskException (org.ow2.proactive.scheduler.common.exception.UnknownTaskException)5 AlreadyConnectedException (org.ow2.proactive.scheduler.common.exception.AlreadyConnectedException)3 JobAlreadyFinishedException (org.ow2.proactive.scheduler.common.exception.JobAlreadyFinishedException)3 JobCreationException (org.ow2.proactive.scheduler.common.exception.JobCreationException)3 NotConnectedException (org.ow2.proactive.scheduler.common.exception.NotConnectedException)3 PermissionException (org.ow2.proactive.scheduler.common.exception.PermissionException)3 SchedulerException (org.ow2.proactive.scheduler.common.exception.SchedulerException)3 SubmissionClosedException (org.ow2.proactive.scheduler.common.exception.SubmissionClosedException)3 SchedulerJMXHelper (org.ow2.proactive.scheduler.core.jmx.SchedulerJMXHelper)3 RuntimeDataMBeanImpl (org.ow2.proactive.scheduler.core.jmx.mbean.RuntimeDataMBeanImpl)3 InternalJob (org.ow2.proactive.scheduler.job.InternalJob)3 JobIdImpl (org.ow2.proactive.scheduler.job.JobIdImpl)3 JobInfoImpl (org.ow2.proactive.scheduler.job.JobInfoImpl)3 Vector (java.util.Vector)2 JobInfo (org.ow2.proactive.scheduler.common.job.JobInfo)2 JobState (org.ow2.proactive.scheduler.common.job.JobState)2 TaskState (org.ow2.proactive.scheduler.common.task.TaskState)2