use of org.ow2.proactive_grid_cloud_portal.studio.Script in project scheduling by ow2-proactive.
the class InternalTask method loadAuthorizedScriptsSignatures.
private static void loadAuthorizedScriptsSignatures(TaskId id, File folder) {
authorizedSelectionScripts = new HashSet<>();
for (File file : folder.listFiles()) {
if (file.isFile()) {
try {
String script = Script.readFile(file);
logger.debug(id, "Adding authorized script " + file.getAbsolutePath());
authorizedSelectionScripts.add(Script.digest(script.trim()));
} catch (Exception e) {
logger.error(id, e.getMessage(), e);
}
}
}
}
use of org.ow2.proactive_grid_cloud_portal.studio.Script in project scheduling by ow2-proactive.
the class InternalTask method getDefaultTaskLauncherInitializer.
/**
* Prepare and return the default task launcher initializer (ie the one that works for every launcher)<br>
* Concrete launcher may have to add values to the created initializer to bring more information to the launcher.
*
* @return the default created task launcher initializer
*/
protected TaskLauncherInitializer getDefaultTaskLauncherInitializer() {
TaskLauncherInitializer tli = new TaskLauncherInitializer();
tli.setTaskId(getId());
tli.setJobOwner(internalJob.getJobInfo().getJobOwner());
tli.setSchedulerRestUrl(PASchedulerProperties.SCHEDULER_REST_URL.getValueAsStringOrNull());
tli.setCatalogRestUrl(PASchedulerProperties.CATALOG_REST_URL.getValueAsStringOrNull());
tli.setPreScript(getPreScript());
tli.setPostScript(getPostScript());
tli.setControlFlowScript(getFlowScript());
tli.setTaskInputFiles(getInputFilesList());
tli.setTaskOutputFiles(getOutputFilesList());
tli.setNamingService(internalJob.getTaskDataSpaceApplications().get(getId().longValue()).getNamingServiceStub());
tli.setIterationIndex(getIterationIndex());
tli.setReplicationIndex(getReplicationIndex());
Map<String, String> gInfo = getRuntimeGenericInformation();
tli.setGenericInformation(gInfo);
ForkEnvironment environment = getForkEnvironment();
if (environment != null) {
Script environmentScript = environment.getEnvScript();
if ((environmentScript != null) && !isScriptAuthorized(getId(), environmentScript)) {
tli.setAuthorizedForkEnvironmentScript(false);
}
}
tli.setForkEnvironment(getForkEnvironment());
if (isWallTimeSet()) {
tli.setWalltime(wallTime);
}
tli.setPreciousLogs(isPreciousLogs());
tli.setJobVariables(internalJob.getVariables());
tli.setTaskVariables(getVariables());
tli.setPingPeriod(PASchedulerProperties.SCHEDULER_NODE_PING_FREQUENCY.getValueAsInt());
tli.setPingAttempts(PASchedulerProperties.SCHEDULER_NODE_PING_ATTEMPTS.getValueAsInt());
return tli;
}
use of org.ow2.proactive_grid_cloud_portal.studio.Script 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_grid_cloud_portal.studio.Script in project scheduling by ow2-proactive.
the class TestTaskAttributes method testScripts.
@Test
public void testScripts() throws Exception {
TaskFlowJob jobDef = new TaskFlowJob();
JavaTask task1 = createDefaultTask("task1");
task1.addSelectionScript(new SelectionScript("selection1", "js", new String[] { "param1", "param2" }, true));
task1.addSelectionScript(new SelectionScript("selection2", "js", new String[] { "param3" }, false));
task1.addSelectionScript(new SelectionScript("selection3", "js"));
task1.setCleaningScript(new SimpleScript("cleanscript", "js", new String[] { "p1", "p2" }));
task1.setPreScript(new SimpleScript("prescript", "js", new String[] { "p1", "p2" }));
task1.setPostScript(new SimpleScript("postscript", "js", new String[] { "p1", "p2" }));
task1.setFlowScript(FlowScript.createContinueFlowScript());
jobDef.addTask(task1);
InternalJob job = defaultSubmitJobAndLoadInternal(true, jobDef);
InternalTask task = job.getTask("task1");
Assert.assertEquals("cleanscript", task.getCleaningScript().getScript());
Assert.assertArrayEquals(new String[] { "p1", "p2" }, task.getCleaningScript().getParameters());
Assert.assertEquals("prescript", task.getPreScript().getScript());
Assert.assertArrayEquals(new String[] { "p1", "p2" }, task.getPreScript().getParameters());
Assert.assertEquals("postscript", task.getPostScript().getScript());
Assert.assertArrayEquals(new String[] { "p1", "p2" }, task.getPostScript().getParameters());
Assert.assertEquals(FlowActionType.CONTINUE.toString(), task.getFlowScript().getActionType());
Assert.assertEquals(3, task.getSelectionScripts().size());
Set<String> scripts = new HashSet<>();
for (SelectionScript script : task.getSelectionScripts()) {
scripts.add(script.getScript());
if (script.getScript().equals("selection1")) {
Assert.assertArrayEquals(new String[] { "param1", "param2" }, script.getParameters());
}
if (script.getScript().equals("selection2")) {
Assert.assertArrayEquals(new String[] { "param3" }, script.getParameters());
}
if (script.getScript().equals("selection3")) {
Assert.assertArrayEquals(new String[] {}, script.getParameters());
}
}
Set<String> expected = new HashSet<>();
expected.add("selection1");
expected.add("selection2");
expected.add("selection3");
Assert.assertEquals(expected, scripts);
}
use of org.ow2.proactive_grid_cloud_portal.studio.Script in project scheduling by ow2-proactive.
the class TestKillTaskWhileExecutingScripts method javaTaskKillEndlessPreScript.
public void javaTaskKillEndlessPreScript() throws Throwable {
log("Test Java Task : killing an Endless PreScript ...");
String tname = "javaTaskKillEndlessPreScript";
// pre script interruption
TaskFlowJob job = new TaskFlowJob();
job.setName(this.getClass().getSimpleName() + "_" + tname);
JavaTask task1 = new JavaTask();
task1.setName(tname);
task1.setExecutableClassName(EmptyExecutable.class.getName());
task1.setPreScript(endlessScript);
job.addTask(task1);
submitAndCheckJob(job, tname);
}
Aggregations