use of org.ow2.proactive.scripting.TaskScript in project scheduling by ow2-proactive.
the class InProcessTaskExecutorTest method taskWithFlowScript.
@Test
public void taskWithFlowScript() throws Exception {
TestTaskOutput taskOutput = new TestTaskOutput();
TaskLauncherInitializer initializer = new TaskLauncherInitializer();
initializer.setControlFlowScript(FlowScript.createReplicateFlowScript("print('flow'); runs=5", "groovy"));
initializer.setTaskId(TaskIdImpl.createTaskId(JobIdImpl.makeJobId("1000"), "job", 1000L));
TaskResultImpl result = new InProcessTaskExecutor().execute(new TaskContext(new ScriptExecutableContainer(new TaskScript(new SimpleScript("print('hello'); result='hello'", "groovy"))), initializer, null, new NodeDataSpacesURIs("", "", "", "", "", ""), "", ""), taskOutput.outputStream, taskOutput.error);
assertEquals(FlowActionType.REPLICATE, result.getAction().getType());
assertEquals("helloflow", taskOutput.output());
}
use of org.ow2.proactive.scripting.TaskScript 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.scripting.TaskScript 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;
}
use of org.ow2.proactive.scripting.TaskScript in project scheduling by ow2-proactive.
the class TestThirdPartyCredentialsDefined method createAndSubmitTaskPrintingCredentials.
public String createAndSubmitTaskPrintingCredentials() throws Exception {
ScriptTask scriptTask = new ScriptTask();
scriptTask.setName("task");
scriptTask.setScript(new TaskScript(new SimpleScript("print credentials", "python")));
TaskFlowJob job = new TaskFlowJob();
job.addTask(scriptTask);
JobId id = schedulerHelper.submitJob(job);
schedulerHelper.waitForEventJobFinished(id);
JobResult jobResult = schedulerHelper.getJobResult(id);
TaskResult result = jobResult.getResult(scriptTask.getName());
return result.getOutput().getStdoutLogs(false).replaceAll("\n|\r", "");
}
use of org.ow2.proactive.scripting.TaskScript in project scheduling by ow2-proactive.
the class TestDataspaceConcurrentTransfer method createJobWithFileTransfers.
public Job createJobWithFileTransfers() throws UserException, InvalidScriptException {
TaskFlowJob job = new TaskFlowJob();
job.setName(JOB_NAME);
job.setOnTaskError(OnTaskError.CONTINUE_JOB_EXECUTION);
for (int i = 0; i < NB_TASKS; i++) {
ScriptTask st1 = new ScriptTask();
st1.setName(TASK_NAME_CREATE + i);
st1.setScript(new TaskScript(new SimpleScript("org.apache.commons.io.FileUtils.touch(new File(localspace, \"" + FOLDER_IN_NAME + i + "/" + FILE_NAME + i + FILE_EXT_IN + "\"));", "groovy")));
st1.addOutputFiles("**/*" + FILE_EXT_IN, OutputAccessMode.TransferToGlobalSpace);
job.addTask(st1);
ScriptTask st2 = new ScriptTask();
st2.setName(TASK_NAME_PROCESS + i);
st2.setScript(new TaskScript(new SimpleScript("org.apache.commons.io.FileUtils.copyFile(new File(localspace, \"" + FOLDER_IN_NAME + i + "/" + FILE_NAME + i + FILE_EXT_IN + "\"), new File(localspace, \"" + FOLDER_OUT_NAME + i + "/" + FILE_NAME + i + FILE_EXT_OUT + "\"));", "groovy")));
st2.addInputFiles(FOLDER_IN_NAME + i + "/" + FILE_NAME + i + FILE_EXT_IN, InputAccessMode.TransferFromGlobalSpace);
st2.addOutputFiles("**/*" + FILE_EXT_OUT, OutputAccessMode.TransferToGlobalSpace);
st2.addDependence(st1);
job.addTask(st2);
}
return job;
}
Aggregations