Search in sources :

Example 36 with Script

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);
            }
        }
    }
}
Also used : File(java.io.File) ActiveObjectCreationException(org.objectweb.proactive.ActiveObjectCreationException) NodeException(org.objectweb.proactive.core.node.NodeException) ExecutableCreationException(org.ow2.proactive.scheduler.common.exception.ExecutableCreationException)

Example 37 with Script

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;
}
Also used : Script(org.ow2.proactive.scripting.Script) ForkEnvironment(org.ow2.proactive.scheduler.common.task.ForkEnvironment) TaskLauncherInitializer(org.ow2.proactive.scheduler.task.TaskLauncherInitializer)

Example 38 with Script

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();
}
Also used : ScriptResult(org.ow2.proactive.scripting.ScriptResult) PrintStream(java.io.PrintStream) InvalidScriptException(org.ow2.proactive.scripting.InvalidScriptException) SimpleScript(org.ow2.proactive.scripting.SimpleScript) ByteArrayOutputStream(java.io.ByteArrayOutputStream) File(java.io.File) ScriptHandler(org.ow2.proactive.scripting.ScriptHandler)

Example 39 with Script

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);
}
Also used : SelectionScript(org.ow2.proactive.scripting.SelectionScript) InternalJob(org.ow2.proactive.scheduler.job.InternalJob) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) SimpleScript(org.ow2.proactive.scripting.SimpleScript) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 40 with Script

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);
}
Also used : EmptyExecutable(functionaltests.executables.EmptyExecutable) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) JavaTask(org.ow2.proactive.scheduler.common.task.JavaTask)

Aggregations

Test (org.junit.Test)38 SelectionScript (org.ow2.proactive.scripting.SelectionScript)32 File (java.io.File)31 SimpleScript (org.ow2.proactive.scripting.SimpleScript)28 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)25 ArrayList (java.util.ArrayList)16 JavaTask (org.ow2.proactive.scheduler.common.task.JavaTask)15 Script (org.ow2.proactive.scripting.Script)15 ScriptResult (org.ow2.proactive.scripting.ScriptResult)15 FlowScript (org.ow2.proactive.scheduler.common.task.flow.FlowScript)13 HashMap (java.util.HashMap)12 RMNode (org.ow2.proactive.resourcemanager.rmnode.RMNode)11 IOException (java.io.IOException)10 JobId (org.ow2.proactive.scheduler.common.job.JobId)10 NodeSet (org.ow2.proactive.utils.NodeSet)10 RMFunctionalTest (functionaltests.utils.RMFunctionalTest)9 ResourceManager (org.ow2.proactive.resourcemanager.frontend.ResourceManager)9 Job (org.ow2.proactive.scheduler.common.job.Job)8 ForkEnvironment (org.ow2.proactive.scheduler.common.task.ForkEnvironment)8 Serializable (java.io.Serializable)7