use of org.ow2.proactive.scripting.SimpleScript 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.SimpleScript 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.SimpleScript in project scheduling by ow2-proactive.
the class SchedulerStarter method executeStartScripts.
private static void executeStartScripts() throws InvalidScriptException, IOException {
// Nothing to do if no script path is specified
if (!PASchedulerProperties.SCHEDULER_STARTSCRIPTS_PATHS.isSet())
return;
// Retrieve the start scripts paths
List<String> scriptsPaths = PASchedulerProperties.SCHEDULER_STARTSCRIPTS_PATHS.getValueAsList(";");
// Scripts binding
ScriptHandler scriptHandler = ScriptLoader.createLocalHandler();
scriptHandler.addBindings(PASchedulerProperties.getPropertiesAsHashMap());
scriptHandler.addBindings(PAResourceManagerProperties.getPropertiesAsHashMap());
scriptHandler.addBindings(WebProperties.getPropertiesAsHashMap());
// Execute all the listed scripts
ByteArrayOutputStream os = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(os, true);
ScriptResult scriptResult;
File scriptFile;
for (String scriptPath : scriptsPaths) {
scriptFile = new File(PASchedulerProperties.getAbsolutePath(scriptPath));
if (scriptFile.exists()) {
LOGGER.info("Executing " + scriptPath);
scriptResult = scriptHandler.handle(new SimpleScript(scriptFile, new String[0]), ps, ps);
if (scriptResult.errorOccured()) {
// Close streams before throwing
os.close();
ps.close();
throw new InvalidScriptException("Failed to execute script: " + scriptResult.getException().getMessage(), scriptResult.getException());
}
LOGGER.info(os.toString());
os.reset();
} else
LOGGER.warn("Start script " + scriptPath + " not found");
}
// Close streams
os.close();
ps.close();
}
use of org.ow2.proactive.scripting.SimpleScript 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.SimpleScript 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