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