Search in sources :

Example 1 with InternalScriptTask

use of org.ow2.proactive.scheduler.task.internal.InternalScriptTask in project scheduling by ow2-proactive.

the class SchedulerStateRestJobLogsTest method job_full_logs_finished.

@Test
public void job_full_logs_finished() throws Exception {
    InternalTaskFlowJob jobState = new InternalTaskFlowJob();
    InternalScriptTask task = new InternalScriptTask(jobState);
    task.setPreciousLogs(true);
    jobState.addTask(task);
    File logFolder = tempFolder.newFolder("0");
    File logFile = new File(logFolder, "TaskLogs-0-0.log");
    FileUtils.write(logFile, "logs", Charset.defaultCharset());
    when(mockScheduler.getJobState("0")).thenReturn(jobState);
    when(mockScheduler.getUserSpaceURIs()).thenReturn(Collections.singletonList(logFolder.getParent()));
    when(mockScheduler.getGlobalSpaceURIs()).thenReturn(Collections.singletonList(logFolder.getParent()));
    InputStream fullLogs = restScheduler.jobFullLogs(validSessionId, "0", validSessionId);
    assertEquals("logs", IOUtils.toString(fullLogs, Charset.defaultCharset()));
}
Also used : InternalScriptTask(org.ow2.proactive.scheduler.task.internal.InternalScriptTask) InputStream(java.io.InputStream) InternalTaskFlowJob(org.ow2.proactive.scheduler.job.InternalTaskFlowJob) File(java.io.File) Test(org.junit.Test)

Example 2 with InternalScriptTask

use of org.ow2.proactive.scheduler.task.internal.InternalScriptTask in project scheduling by ow2-proactive.

the class SchedulerStateRestJobLogsTest method addTask.

private static void addTask(InternalTaskFlowJob jobState, long finishedTime, long id) {
    InternalScriptTask task = new InternalScriptTask(jobState);
    task.setPreciousLogs(true);
    task.setFinishedTime(finishedTime);
    jobState.addTask(task);
    task.setId(TaskIdImpl.createTaskId(new JobIdImpl(123, "job"), "task", id));
}
Also used : InternalScriptTask(org.ow2.proactive.scheduler.task.internal.InternalScriptTask) JobIdImpl(org.ow2.proactive.scheduler.job.JobIdImpl)

Example 3 with InternalScriptTask

use of org.ow2.proactive.scheduler.task.internal.InternalScriptTask in project scheduling by ow2-proactive.

the class TaskData method toInternalTask.

InternalTask toInternalTask(InternalJob internalJob, boolean loadFullState) throws InvalidScriptException {
    TaskId taskId = createTaskId(internalJob);
    InternalTask internalTask;
    if (taskType.equals(SCRIPT_TASK)) {
        internalTask = new InternalScriptTask(internalJob);
    } else if (taskType.equals(FORKED_SCRIPT_TASK)) {
        internalTask = new InternalForkedScriptTask(internalJob);
    } else {
        throw new IllegalStateException("Unexpected stored task type: " + taskType);
    }
    internalTask.setId(taskId);
    internalTask.setDescription(getDescription());
    internalTask.setTag(this.getTag());
    internalTask.setStatus(getTaskStatus());
    internalTask.setJobInfo(internalJob.getJobInfo());
    internalTask.setName(getTaskName());
    internalTask.setExecutionDuration(getExecutionDuration());
    internalTask.setFinishedTime(getFinishedTime());
    internalTask.setInErrorTime(getInErrorTime());
    internalTask.setStartTime(getStartTime());
    internalTask.setScheduledTime(getScheduledTime());
    internalTask.setExecutionHostName(getExecutionHostName());
    internalTask.setOnTaskError(OnTaskError.getInstance(this.onTaskErrorString));
    internalTask.setPreciousLogs(isPreciousLogs());
    internalTask.setPreciousResult(isPreciousResult());
    internalTask.setRunAsMe(isRunAsMe());
    internalTask.setWallTime(getWallTime());
    internalTask.setMaxNumberOfExecution(getMaxNumberOfExecution());
    internalTask.setNumberOfExecutionLeft(getNumberOfExecutionLeft());
    internalTask.setNumberOfExecutionOnFailureLeft(getNumberOfExecutionOnFailureLeft());
    internalTask.setRestartTaskOnError(getRestartMode());
    internalTask.setFlowBlock(getFlowBlock());
    internalTask.setIterationIndex(getIteration());
    internalTask.setReplicationIndex(getReplication());
    internalTask.setMatchingBlock(getMatchingBlock());
    internalTask.setVariables(variablesToTaskVariables());
    if (hasAliveTaskLauncher() && getExecuterInformationData() != null) {
        internalTask.setExecuterInformation(getExecuterInformationData().toExecuterInformation(loadFullState));
    }
    ForkEnvironment forkEnv = createForkEnvironment();
    internalTask.setForkEnvironment(forkEnv);
    return internalTask;
}
Also used : InternalScriptTask(org.ow2.proactive.scheduler.task.internal.InternalScriptTask) TaskId(org.ow2.proactive.scheduler.common.task.TaskId) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) InternalForkedScriptTask(org.ow2.proactive.scheduler.task.internal.InternalForkedScriptTask) ForkEnvironment(org.ow2.proactive.scheduler.common.task.ForkEnvironment)

Example 4 with InternalScriptTask

use of org.ow2.proactive.scheduler.task.internal.InternalScriptTask in project scheduling by ow2-proactive.

the class InternalJobFactory method createTask.

/**
 * Create an internal native Task with the given native task (user)
 *
 * @param task the user native task that will be used to create the internal native task.
 * @return the created internal task.
 * @throws JobCreationException an exception if the factory cannot create the given task.
 */
private static InternalTask createTask(Job userJob, InternalJob internalJob, NativeTask task) throws JobCreationException {
    if (((task.getCommandLine() == null) || (task.getCommandLine().length == 0))) {
        String msg = "The command line is null or empty and not generated !";
        logger.info(msg);
        throw new JobCreationException(msg);
    }
    try {
        String commandAndArguments = "\"" + Joiner.on("\" \"").join(task.getCommandLine()) + "\"";
        InternalTask scriptTask;
        if (isForkingTask()) {
            scriptTask = new InternalForkedScriptTask(new ScriptExecutableContainer(new TaskScript(new SimpleScript(commandAndArguments, "native"))), internalJob);
            configureRunAsMe(task);
        } else {
            scriptTask = new InternalScriptTask(new ScriptExecutableContainer(new TaskScript(new SimpleScript(commandAndArguments, "native"))), internalJob);
        }
        ForkEnvironment forkEnvironment = new ForkEnvironment();
        scriptTask.setForkEnvironment(forkEnvironment);
        // set task common properties
        setTaskCommonProperties(userJob, task, scriptTask);
        return scriptTask;
    } catch (Exception e) {
        throw new JobCreationException(e);
    }
}
Also used : InternalScriptTask(org.ow2.proactive.scheduler.task.internal.InternalScriptTask) TaskScript(org.ow2.proactive.scripting.TaskScript) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) InternalForkedScriptTask(org.ow2.proactive.scheduler.task.internal.InternalForkedScriptTask) SimpleScript(org.ow2.proactive.scripting.SimpleScript) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) ScriptExecutableContainer(org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer) ForkEnvironment(org.ow2.proactive.scheduler.common.task.ForkEnvironment) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) InvalidScriptException(org.ow2.proactive.scripting.InvalidScriptException) InternalException(org.ow2.proactive.scheduler.common.exception.InternalException)

Example 5 with InternalScriptTask

use of org.ow2.proactive.scheduler.task.internal.InternalScriptTask in project scheduling by ow2-proactive.

the class InternalJobFactory method createTask.

/**
 * Create an internal java Task with the given java task (user)
 *
 * @param task the user java task that will be used to create the internal java task.
 * @return the created internal task.
 * @throws JobCreationException an exception if the factory cannot create the given task.
 */
@SuppressWarnings("unchecked")
private static InternalTask createTask(Job userJob, InternalJob internalJob, JavaTask task) throws JobCreationException {
    InternalTask javaTask;
    if (task.getExecutableClassName() != null) {
        HashMap<String, byte[]> args = task.getSerializedArguments();
        try {
            if (isForkingTask()) {
                javaTask = new InternalForkedScriptTask(new ScriptExecutableContainer(new TaskScript(new SimpleScript(task.getExecutableClassName(), JavaClassScriptEngineFactory.JAVA_CLASS_SCRIPT_ENGINE_NAME, new Serializable[] { args }))), internalJob);
                javaTask.setForkEnvironment(task.getForkEnvironment());
                configureRunAsMe(task);
            } else {
                javaTask = new InternalScriptTask(new ScriptExecutableContainer(new TaskScript(new SimpleScript(task.getExecutableClassName(), JavaClassScriptEngineFactory.JAVA_CLASS_SCRIPT_ENGINE_NAME, new Serializable[] { args }))), internalJob);
            }
        } catch (InvalidScriptException e) {
            throw new JobCreationException(e);
        }
    } else {
        String msg = "You must specify your own executable task class to be launched (in every task)!";
        logger.info(msg);
        throw new JobCreationException(msg);
    }
    // set task common properties
    try {
        setTaskCommonProperties(userJob, task, javaTask);
    } catch (Exception e) {
        throw new JobCreationException(e);
    }
    return javaTask;
}
Also used : InternalScriptTask(org.ow2.proactive.scheduler.task.internal.InternalScriptTask) TaskScript(org.ow2.proactive.scripting.TaskScript) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) InternalForkedScriptTask(org.ow2.proactive.scheduler.task.internal.InternalForkedScriptTask) InvalidScriptException(org.ow2.proactive.scripting.InvalidScriptException) SimpleScript(org.ow2.proactive.scripting.SimpleScript) ScriptExecutableContainer(org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) InvalidScriptException(org.ow2.proactive.scripting.InvalidScriptException) InternalException(org.ow2.proactive.scheduler.common.exception.InternalException)

Aggregations

InternalScriptTask (org.ow2.proactive.scheduler.task.internal.InternalScriptTask)43 InternalTask (org.ow2.proactive.scheduler.task.internal.InternalTask)33 InternalTaskFlowJob (org.ow2.proactive.scheduler.job.InternalTaskFlowJob)32 Test (org.junit.Test)28 InternalJob (org.ow2.proactive.scheduler.job.InternalJob)28 JobIdImpl (org.ow2.proactive.scheduler.job.JobIdImpl)25 JobId (org.ow2.proactive.scheduler.common.job.JobId)20 ArrayList (java.util.ArrayList)18 ExecuterInformation (org.ow2.proactive.scheduler.task.internal.ExecuterInformation)14 TaskId (org.ow2.proactive.scheduler.common.task.TaskId)11 UnknownJobException (org.ow2.proactive.scheduler.common.exception.UnknownJobException)5 UnknownTaskException (org.ow2.proactive.scheduler.common.exception.UnknownTaskException)5 TaskInfoImpl (org.ow2.proactive.scheduler.task.TaskInfoImpl)5 TaskResultImpl (org.ow2.proactive.scheduler.task.TaskResultImpl)5 ScriptExecutableContainer (org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer)4 InternalForkedScriptTask (org.ow2.proactive.scheduler.task.internal.InternalForkedScriptTask)4 ProActiveTest (org.ow2.tests.ProActiveTest)4 InternalException (org.ow2.proactive.scheduler.common.exception.InternalException)3 JobCreationException (org.ow2.proactive.scheduler.common.exception.JobCreationException)3 ForkEnvironment (org.ow2.proactive.scheduler.common.task.ForkEnvironment)3