Search in sources :

Example 46 with TaskState

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

the class SchedulerClientTest method testJobResult.

@Test(timeout = MAX_WAIT_TIME)
public void testJobResult() throws Throwable {
    ISchedulerClient client = clientInstance();
    Job job = createJobManyTasks("JobResult", SimpleJob.class, ErrorTask.class, LogTask.class, VariableTask.class, MetadataTask.class, RawTask.class);
    JobId jobId = submitJob(job, client);
    JobResult result = client.waitForJob(jobId, TimeUnit.MINUTES.toMillis(3));
    // job result
    Assert.assertNotNull(result.getJobId());
    Assert.assertNotNull(result.getJobInfo());
    Assert.assertEquals(JobStatus.FINISHED, result.getJobInfo().getStatus());
    // the following check cannot work because of the way the job id is created on the client side.
    // Assert.assertEquals(job.getName(), result.getName());
    Assert.assertTrue(result.hadException());
    Assert.assertEquals(1, result.getExceptionResults().size());
    // job info
    checkJobInfo(result.getJobInfo());
    checkJobInfo(client.getJobInfo(jobId.value()));
    JobState jobState = client.getJobState(jobId.value());
    JobStatus status = jobState.getStatus();
    Assert.assertFalse(status.isJobAlive());
    Assert.assertEquals(JobStatus.FINISHED, status);
    checkJobInfo(jobState.getJobInfo());
    TaskState errorTaskState = findTask(getTaskNameForClass(ErrorTask.class), jobState.getHMTasks());
    Assert.assertNotNull(errorTaskState);
    TaskState simpleTaskState = findTask(getTaskNameForClass(SimpleJob.class), jobState.getHMTasks());
    Assert.assertNotNull(simpleTaskState);
    Assert.assertEquals(TaskStatus.FAULTY, errorTaskState.getStatus());
    Assert.assertEquals(TaskStatus.FINISHED, simpleTaskState.getStatus());
    // task result simple
    TaskResult tResSimple = result.getResult(getTaskNameForClass(SimpleJob.class));
    Assert.assertNotNull(tResSimple.value());
    Assert.assertNotNull(tResSimple.getSerializedValue());
    Assert.assertEquals(new StringWrapper(TEST_JOB), tResSimple.value());
    Assert.assertEquals(new StringWrapper(TEST_JOB), ObjectByteConverter.byteArrayToObject(tResSimple.getSerializedValue()));
    // task result with error
    TaskResult tResError = result.getResult(getTaskNameForClass(ErrorTask.class));
    Assert.assertNotNull(tResError);
    Assert.assertTrue(tResError.hadException());
    Assert.assertNotNull(tResError.getException());
    Assert.assertTrue(tResError.getException() instanceof TaskException);
    // task result with logs
    TaskResult tResLog = result.getResult(getTaskNameForClass(LogTask.class));
    Assert.assertNotNull(tResLog);
    Assert.assertNotNull(tResLog.getOutput());
    System.err.println(tResLog.getOutput().getStdoutLogs(false));
    Assert.assertTrue(tResLog.getOutput().getStdoutLogs(false).contains(LogTask.HELLO_WORLD));
    // task result with variables
    TaskResult tResVar = result.getResult(getTaskNameForClass(VariableTask.class));
    Assert.assertNotNull(tResVar.getPropagatedVariables());
    Map<String, Serializable> vars = tResVar.getVariables();
    System.out.println(vars);
    Assert.assertTrue(tResVar.getPropagatedVariables().containsKey(VariableTask.MYVAR));
    Assert.assertEquals("myvalue", vars.get(VariableTask.MYVAR));
    // task result with metadata
    TaskResult tMetaVar = result.getResult(getTaskNameForClass(MetadataTask.class));
    Assert.assertNotNull(tMetaVar.getMetadata());
    Assert.assertTrue(tMetaVar.getMetadata().containsKey(MetadataTask.MYVAR));
    // task result with raw result
    TaskResult tResRaw = result.getResult(getTaskNameForClass(RawTask.class));
    Assert.assertNotNull(tResRaw.value());
    Assert.assertNotNull(tResRaw.getSerializedValue());
    Assert.assertArrayEquals(TEST_JOB.getBytes(), (byte[]) tResRaw.value());
    Assert.assertArrayEquals(TEST_JOB.getBytes(), tResRaw.getSerializedValue());
}
Also used : StringWrapper(org.objectweb.proactive.core.util.wrapper.StringWrapper) Serializable(java.io.Serializable) JobResult(org.ow2.proactive.scheduler.common.job.JobResult) JobStatus(org.ow2.proactive.scheduler.common.job.JobStatus) VariableTask(functionaltests.jobs.VariableTask) TaskException(org.ow2.proactive.scheduler.task.exceptions.TaskException) RawTask(functionaltests.jobs.RawTask) MetadataTask(functionaltests.jobs.MetadataTask) ISchedulerClient(org.ow2.proactive.scheduler.rest.ISchedulerClient) JobState(org.ow2.proactive.scheduler.common.job.JobState) SimpleJob(functionaltests.jobs.SimpleJob) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) ErrorTask(functionaltests.jobs.ErrorTask) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) SimpleJob(functionaltests.jobs.SimpleJob) Job(org.ow2.proactive.scheduler.common.job.Job) NonTerminatingJob(functionaltests.jobs.NonTerminatingJob) TaskState(org.ow2.proactive.scheduler.common.task.TaskState) JobId(org.ow2.proactive.scheduler.common.job.JobId) LogTask(functionaltests.jobs.LogTask) Test(org.junit.Test)

Example 47 with TaskState

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

the class StringUtility method taskStatesAsString.

public static String taskStatesAsString(Collection<TaskStateData> tasks, boolean displayTags) {
    // create formatter
    ObjectArrayFormatter formatter = new ObjectArrayFormatter();
    formatter.setMaxColumnLength(80);
    // space between column
    formatter.setSpace(4);
    // title line
    List<String> list = new ArrayList<>();
    list.add("ID");
    list.add("NAME");
    if (displayTags) {
        list.add("TAG");
    }
    list.add("ITER");
    list.add("DUP");
    list.add("STATUS");
    list.add("HOSTNAME");
    list.add("EXEC DURATION");
    list.add("TOT DURATION");
    list.add("#NODES USED");
    list.add("#EXECUTIONS");
    list.add("#NODES KILLED");
    formatter.setTitle(list);
    formatter.addEmptyLine();
    for (TaskStateData taskState : tasks) {
        list = new ArrayList<>();
        TaskInfoData taskInfo = taskState.getTaskInfo();
        TaskIdData taskId = taskInfo.getTaskId();
        list.add(String.valueOf(taskId.getId()));
        list.add(taskId.getReadableName());
        if (displayTags) {
            list.add(toStringNullable(taskState.getTag()));
        }
        list.add((taskState.getIterationIndex() > 0) ? "" + taskState.getIterationIndex() : "");
        list.add((taskState.getReplicationIndex() > 0) ? "" + taskState.getReplicationIndex() : "");
        list.add(taskInfo.getTaskStatus().toString());
        list.add(toStringNullable(taskInfo.getExecutionHostName(), "unknown"));
        if (taskInfo.getTaskStatus() == TaskStatusData.IN_ERROR) {
            list.add(Tools.getFormattedDuration(taskInfo.getInErrorTime(), taskInfo.getStartTime()));
        } else {
            list.add(Tools.getFormattedDuration(0, taskInfo.getExecutionDuration()));
        }
        list.add(Tools.getFormattedDuration(taskInfo.getFinishedTime(), taskInfo.getStartTime()));
        list.add("" + taskState.getNumberOfNodesNeeded());
        list.add((taskState.getMaxNumberOfExecution() - taskInfo.getNumberOfExecutionLeft()) + "/" + taskState.getMaxNumberOfExecution());
        list.add((taskState.getMaxNumberOfExecutionOnFailure() - taskInfo.getNumberOfExecutionOnFailureLeft()) + "/" + taskState.getMaxNumberOfExecutionOnFailure());
        formatter.addLine(list);
    }
    return Tools.getStringAsArray(formatter);
}
Also used : TaskStateData(org.ow2.proactive_grid_cloud_portal.scheduler.dto.TaskStateData) TaskInfoData(org.ow2.proactive_grid_cloud_portal.scheduler.dto.TaskInfoData) TaskIdData(org.ow2.proactive_grid_cloud_portal.scheduler.dto.TaskIdData) ArrayList(java.util.ArrayList) ObjectArrayFormatter(org.ow2.proactive.utils.ObjectArrayFormatter)

Example 48 with TaskState

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

the class SchedulerTHelper method testJobSubmission.

/**
 * Creates and submit a job from an XML job descriptor, and check, with assertions,
 * event related to this job submission :
 * 1/ job submitted event
 * 2/ job passing from pending to running (with state set to running).
 * 3/ job passing from running to finished (with state set to finished).
 * 4/ every task finished with or without error (configurable)
 * <p>
 * Then returns.
 * <p>
 * This is the simplest events sequence of a job submission. If you need to test
 * specific events or task states (failures, rescheduling etc, you must not use this
 * helper and check events sequence with waitForEvent**() functions.
 *
 * @param userInt         scheduler interface
 * @param jobToSubmit     job object to schedule.
 * @param acceptSkipped   if true then skipped task will not fail the test
 * @param failIfTaskError if true then the test will fail if a task was in error
 * @return JobId, the job's identifier.
 * @throws Exception if an error occurs at job submission, or during
 *                   verification of events sequence.
 */
public JobId testJobSubmission(Scheduler userInt, Job jobToSubmit, boolean acceptSkipped, boolean failIfTaskError) throws Exception {
    JobId id = userInt.submit(jobToSubmit);
    log("Job submitted, id " + id.toString());
    log("Waiting for jobSubmitted");
    JobState receivedState = waitForEventJobSubmitted(id);
    Assert.assertEquals(id, receivedState.getId());
    log("Waiting for job running");
    JobInfo jInfo = waitForEventJobRunning(id);
    Assert.assertEquals(jInfo.getJobId(), id);
    Assert.assertEquals("Job " + jInfo.getJobId(), JobStatus.RUNNING, jInfo.getStatus());
    log("Waiting for job finished");
    jInfo = waitForEventJobFinished(userInt, id);
    Assert.assertEquals("Job " + jInfo.getJobId(), JobStatus.FINISHED, jInfo.getStatus());
    log("Job finished");
    boolean taskError = false;
    String message = "";
    if (jobToSubmit instanceof TaskFlowJob) {
        JobState jobState = userInt.getJobState(id);
        for (TaskState t : jobState.getTasks()) {
            log("Looking at the result of task : " + t.getName());
            if (t.getStatus() == TaskStatus.FAULTY) {
                TaskResult tres = userInt.getTaskResult(jInfo.getJobId(), t.getName());
                if (tres == null) {
                    message = "Task result of " + t.getName() + " should not be null.";
                    taskError = true;
                    break;
                }
                if (tres.getOutput() != null) {
                    System.err.println("Output of failing task (" + t.getName() + ") :");
                    System.err.println(tres.getOutput().getAllLogs(true));
                }
                if (tres.hadException()) {
                    System.err.println("Exception occurred in task (" + t.getName() + ") :");
                    tres.getException().printStackTrace(System.err);
                    message = "Exception occurred in task (" + t.getName() + ")";
                    taskError = true;
                    break;
                }
            } else if (acceptSkipped && t.getStatus() == TaskStatus.SKIPPED) {
            // do nothing
            } else if (t.getStatus() != TaskStatus.FINISHED) {
                message = "Invalid task status for task " + t.getName() + " : " + t.getStatus();
                taskError = true;
                break;
            } else {
                TaskResult tres = userInt.getTaskResult(jInfo.getJobId(), t.getName());
                System.out.println("Output of task (" + t.getName() + ") :");
                System.out.println(tres.getOutput().getAllLogs(true));
            }
        }
    }
    if (taskError && failIfTaskError) {
        fail(message);
    }
    return id;
}
Also used : TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) TaskState(org.ow2.proactive.scheduler.common.task.TaskState)

Example 49 with TaskState

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

the class TRepJobs method testJobs.

public void testJobs(TRepCase... testCases) throws Throwable {
    for (TRepCase tcase : testCases) {
        String path = new File(TWorkflowJobs.class.getResource(tcase.jobPath).toURI()).getAbsolutePath();
        Job job = JobFactory.getFactory().createJob(path);
        JobId id = schedulerHelper.submitJob(job);
        SchedulerTHelper.log("Job submitted, id " + id.toString());
        JobState receivedstate = schedulerHelper.waitForEventJobSubmitted(id);
        Assert.assertEquals(id, receivedstate.getId());
        JobInfo jInfo = schedulerHelper.waitForEventJobRunning(id);
        Assert.assertEquals(jInfo.getJobId(), id);
        Assert.assertEquals(JobStatus.RUNNING, jInfo.getStatus());
        jInfo = schedulerHelper.waitForEventJobFinished(id);
        Assert.assertEquals(JobStatus.FINISHED, jInfo.getStatus());
        SchedulerTHelper.log("Job finished");
        JobResult res = schedulerHelper.getJobResult(id);
        Assert.assertFalse(schedulerHelper.getJobResult(id).hadException());
        JobState js = schedulerHelper.getSchedulerInterface().getJobState(id);
        // final number of tasks
        Assert.assertEquals(tcase.total, js.getTasks().size());
        // to be checked against this.tasks
        HashMap<String, Long> finalTaskCount = new HashMap<>();
        // to be checked against this.results
        HashMap<String, Long> finalResSum = new HashMap<>();
        for (TaskState ts : js.getTasks()) {
            String baseName = InternalTask.getInitialName(ts.getName());
            long count = 0;
            long sum = 0;
            if (finalTaskCount.containsKey(baseName)) {
                count = finalTaskCount.get(baseName);
                sum = finalResSum.get(baseName);
            }
            finalTaskCount.put(baseName, count + 1);
            long tr = 0;
            if (ts.getStatus().equals(TaskStatus.SKIPPED)) {
                tr = -1;
            } else {
                Serializable sr = res.getAllResults().get(ts.getName()).value();
                if (sr instanceof Long) {
                    tr = ((Long) sr).longValue();
                }
            }
            finalResSum.put(baseName, sum + tr);
        }
        Assert.assertEquals(tcase.tasks.size(), finalTaskCount.size());
        Assert.assertEquals(tcase.results.size(), finalResSum.size());
        Assert.assertEquals(finalTaskCount.size(), finalResSum.size());
        for (Entry<String, Long> entry : finalTaskCount.entrySet()) {
            Assert.assertTrue(tcase.tasks.containsKey(entry.getKey()));
            long val = tcase.tasks.get(entry.getKey());
            Assert.assertEquals(val, entry.getValue().longValue());
        }
        for (Entry<String, Long> entry : finalResSum.entrySet()) {
            Assert.assertTrue(tcase.results.containsKey(entry.getKey()));
            long val = tcase.results.get(entry.getKey());
            Assert.assertEquals(val, entry.getValue().longValue());
        }
        schedulerHelper.removeJob(id);
        schedulerHelper.waitForEventJobRemoved(id);
    }
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) File(java.io.File) TaskState(org.ow2.proactive.scheduler.common.task.TaskState)

Example 50 with TaskState

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

the class InternalTask method replicate.

/**
 * {@inheritDoc}
 */
@Override
public TaskState replicate() throws ExecutableCreationException {
    /*
         * this implementation deep copies everything using serialization. however the new
         * InternalTask cannot be strictly identical and we have to handle the following special
         * cases:
         *
         * - ExecutableContainer is transient and not copied during serialization. It needs to be
         * manually copied, and added to the InternalTask replica
         *
         * - Using the TaskInfo of _this_ gives us a FINISHED task, need to explicitely create a new
         * clean one.
         *
         * - InternalTask dependencies need to be nulled as they contain references to other
         * InternalTasks, and will be rewritten later anyway
         *
         * - Most of the objects down the object graph contain Hibernate @Id fields. If all those
         * fields are not set to 0 when inserting the object in DB, insertion will fail.
         *
         * - Collections are mapped to specific Hibernate internal collections at runtime, which
         * contain references to the @Id fields mentionned above. They need to be reset too.
         */
    InternalTask replicatedTask = null;
    // ExecutableContainer replicatedContainer = null;
    try {
        // Deep copy of the InternalTask using proactive serialization
        replicatedTask = (InternalTask) ProActiveMakeDeepCopy.WithProActiveObjectStream.makeDeepCopy(this);
    } catch (Throwable t) {
        throw new ExecutableCreationException("Failed to serialize task", t);
    }
    replicatedTask.internalJob = internalJob;
    // internalTasksDependencies contain references to other InternalTasks, it needs to be removed.
    // anyway, dependencies for the new task will not be the same as the original
    replicatedTask.internalTasksDependencies = null;
    // the taskinfo needs to be cleaned so that we don't tag this task as finished
    TaskId repId = replicatedTask.taskInfo.getTaskId();
    replicatedTask.taskInfo = new TaskInfoImpl();
    // we only need this id for the HashSet comparisons...
    replicatedTask.taskInfo.setTaskId(repId);
    replicatedTask.taskInfo.setNumberOfExecutionLeft(getMaxNumberOfExecution());
    replicatedTask.taskInfo.setNumberOfExecutionOnFailureLeft(getMaxNumberOfExecutionOnFailure());
    replicatedTask.setReplicatedFrom(this);
    // The next DB.update(InternalJob) will take care of it
    return replicatedTask;
}
Also used : ExecutableCreationException(org.ow2.proactive.scheduler.common.exception.ExecutableCreationException) TaskId(org.ow2.proactive.scheduler.common.task.TaskId) TaskInfoImpl(org.ow2.proactive.scheduler.task.TaskInfoImpl)

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