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;
}
});
}
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));
}
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;
});
}
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);
}
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();
}
}
Aggregations