Search in sources :

Example 26 with ForkEnvironment

use of org.ow2.proactive.scheduler.common.task.ForkEnvironment in project scheduling by ow2-proactive.

the class TestSmartProxy method createTestJob.

protected TaskFlowJob createTestJob(boolean isolateOutputs) throws Exception {
    TaskFlowJob job = new TaskFlowJob();
    job.setName(this.getClass().getSimpleName());
    ForkEnvironment forkEnvironment = new ForkEnvironment();
    forkEnvironment.addAdditionalClasspath(getClasspath(job));
    for (int i = 0; i < NB_TASKS; i++) {
        JavaTask testTask = new JavaTask();
        testTask.setName(TASK_NAME + i);
        testTask.setExecutableClassName(SimpleJavaExecutable.class.getName());
        testTask.setForkEnvironment(forkEnvironment);
        // testTask.
        // ------------- create an input File ------------
        File inputFile = new File(inputLocalFolder, inputFileBaseName + "_" + i + inputFileExt);
        String outputFileName = outputFileBaseName + "_" + i + outputFileExt;
        // delete files after the test is finished
        File outputFile = new File(outputLocalFolder, outputFileName);
        outputFile.deleteOnExit();
        inputFile.deleteOnExit();
        FileWriter fw = new FileWriter(inputFile);
        for (int j = 0; j <= Math.round(Math.random() * 100) + 1; j++) fw.write("Some random input");
        fw.close();
        // Add dummy input files, make sure no error happen
        testTask.addInputFiles("DUMMY", InputAccessMode.TransferFromInputSpace);
        testTask.addInputFiles(inputFile.getName(), InputAccessMode.TransferFromInputSpace);
        if (isolateOutputs) {
            testTask.addOutputFiles("*" + outputFileExt, OutputAccessMode.TransferToOutputSpace);
        } else {
            testTask.addOutputFiles(outputFileName, OutputAccessMode.TransferToOutputSpace);
        }
        job.addTask(testTask);
    }
    job.setInputSpace(dataServerURI);
    job.setOutputSpace(dataServerURI);
    return job;
}
Also used : TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) FileWriter(java.io.FileWriter) JavaTask(org.ow2.proactive.scheduler.common.task.JavaTask) ForkEnvironment(org.ow2.proactive.scheduler.common.task.ForkEnvironment) File(java.io.File)

Example 27 with ForkEnvironment

use of org.ow2.proactive.scheduler.common.task.ForkEnvironment in project scheduling by ow2-proactive.

the class TestProcessTreeKiller method createJavaExecutableJob.

public static TaskFlowJob createJavaExecutableJob(String name, boolean forked) throws UserException {
    TaskFlowJob job = new TaskFlowJob();
    job.setName(name);
    job.setDescription("A command that spawns processes");
    JavaTask task = new JavaTask();
    if (forked) {
        task.setForkEnvironment(new ForkEnvironment());
    }
    task.addArgument("sleep", 3);
    task.addArgument("tname", name);
    task.addArgument("home", PASchedulerProperties.SCHEDULER_HOME.getValueAsString());
    task.setName(name);
    task.setExecutableClassName(JavaSpawnExecutable.class.getName());
    job.addTask(task);
    return job;
}
Also used : TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) JavaTask(org.ow2.proactive.scheduler.common.task.JavaTask) ForkEnvironment(org.ow2.proactive.scheduler.common.task.ForkEnvironment)

Example 28 with ForkEnvironment

use of org.ow2.proactive.scheduler.common.task.ForkEnvironment in project scheduling by ow2-proactive.

the class TestForkedTaskWorkingDir method createFileInLocalSpaceJob.

private TaskFlowJob createFileInLocalSpaceJob(String blockTaskFromTestUrl, String blockTestBeforeKillingNodeUrl) throws Exception {
    TaskFlowJob job = new TaskFlowJob();
    JavaTask task1 = new JavaTask();
    task1.setForkEnvironment(new ForkEnvironment());
    task1.setName("task1");
    task1.setExecutableClassName(CreateFileInLocalSpaceTask.class.getName());
    task1.addArgument("blockTaskFromTestUrl", blockTaskFromTestUrl);
    task1.addArgument("blockTestBeforeKillingNodeUrl", blockTestBeforeKillingNodeUrl);
    task1.addOutputFiles("output_file.txt", OutputAccessMode.TransferToUserSpace);
    job.addTask(task1);
    return job;
}
Also used : TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) JavaTask(org.ow2.proactive.scheduler.common.task.JavaTask) ForkEnvironment(org.ow2.proactive.scheduler.common.task.ForkEnvironment)

Example 29 with ForkEnvironment

use of org.ow2.proactive.scheduler.common.task.ForkEnvironment in project scheduling by ow2-proactive.

the class TestUnauthorizedScripts method createJob.

public Job createJob(String forkScriptContent, String cleanScriptContent) throws InvalidScriptException, UserException {
    TaskFlowJob job = new TaskFlowJob();
    job.setName(this.getClass().getSimpleName() + "_forkAndClean");
    ScriptTask taskWithFork = new ScriptTask();
    taskWithFork.setScript(new TaskScript(new SimpleScript("println 'Hello'", "groovy")));
    ForkEnvironment forkEnvironment = new ForkEnvironment();
    forkEnvironment.setEnvScript(new SimpleScript(forkScriptContent, "groovy"));
    taskWithFork.setForkEnvironment(forkEnvironment);
    ScriptTask taskWithClean = new ScriptTask();
    taskWithClean.setScript(new TaskScript(new SimpleScript("println 'Hello'", "groovy")));
    taskWithClean.setCleaningScript(new SimpleScript(cleanScriptContent, "groovy"));
    job.addTask(taskWithFork);
    job.addTask(taskWithClean);
    return job;
}
Also used : ScriptTask(org.ow2.proactive.scheduler.common.task.ScriptTask) TaskScript(org.ow2.proactive.scripting.TaskScript) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) SimpleScript(org.ow2.proactive.scripting.SimpleScript) ForkEnvironment(org.ow2.proactive.scheduler.common.task.ForkEnvironment)

Example 30 with ForkEnvironment

use of org.ow2.proactive.scheduler.common.task.ForkEnvironment in project scheduling by ow2-proactive.

the class TestNativeTaskPaths method testNativeTaskPaths.

@Test
public void testNativeTaskPaths() throws Throwable {
    File in = File.createTempFile("input", "space");
    in.delete();
    in.mkdir();
    String inPath = in.getAbsolutePath();
    File out = File.createTempFile("output", "space");
    out.delete();
    out.mkdir();
    File outc = new File(out, OutVarsFileC);
    File outd = new File(out, OutVarsFileD);
    if (outc.exists()) {
        outc.delete();
    }
    if (outd.exists()) {
        outd.delete();
    }
    File scriptTestEnv = null;
    if (OperatingSystem.getOperatingSystem() == OperatingSystem.unix) {
        scriptTestEnv = new File(inPath + File.separator + scriptCLinux);
        scriptTestEnv.createNewFile();
        PrintWriter out3 = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(scriptTestEnv))));
        out3.print(scriptCLinuxContent);
        out3.close();
    } else {
        scriptTestEnv = new File(inPath + File.separator + scriptCWindows);
        scriptTestEnv.createNewFile();
        PrintWriter out3 = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(scriptTestEnv))));
        out3.print(scriptCWindowsContent);
        out3.close();
    }
    TaskFlowJob job = new TaskFlowJob();
    job.setName(this.getClass().getSimpleName());
    job.setInputSpace(in.toURI().toURL().toString());
    job.setOutputSpace(out.toURI().toURL().toString());
    // // testing paths pattern
    // NativeTask C = new NativeTask();
    // C.setName("C");
    // C.addOutputFiles(OutVarsFileC, OutputAccessMode.TransferToOutputSpace);
    // switch (OperatingSystem.getOperatingSystem()) {
    // case windows:
    // C.setCommandLine(new String[] { "cmd", "/C",
    // "echo \"$JAVA\" \"$PROACTIVE_HOME\" > $LOCALSPACE\\" + OutVarsFileC });
    // break;
    // case unix:
    // C.setCommandLine(new String[] { "/bin/bash", "-c",
    // "echo \\\"$JAVA\\\" \\\"$PROACTIVE_HOME\\\" > $LOCALSPACE/" + OutVarsFileC });
    // break;
    // default:
    // throw new IllegalStateException("Unsupported operating system");
    // }
    // job.addTask(C);
    // testing $USERSPACE environment variable
    NativeTask D = new NativeTask();
    D.setName("D");
    if (OperatingSystem.getOperatingSystem() == OperatingSystem.unix) {
        D.addInputFiles(scriptCLinux, InputAccessMode.TransferFromInputSpace);
    } else {
        D.addInputFiles(scriptCWindows, InputAccessMode.TransferFromInputSpace);
    }
    D.addOutputFiles(OutVarsFileD, OutputAccessMode.TransferToOutputSpace);
    switch(OperatingSystem.getOperatingSystem()) {
        case windows:
            D.setCommandLine(new String[] { "cmd", "/C", scriptCWindows });
            break;
        case unix:
            D.setCommandLine(new String[] { "/bin/bash", "-c", "chmod u+x $localspace/" + scriptCLinux + "; $localspace/" + scriptCLinux });
            break;
        default:
            throw new IllegalStateException("Unsupported operating system");
    }
    D.setForkEnvironment(new ForkEnvironment("$LOCALSPACE"));
    job.addTask(D);
    Scheduler sched = schedulerHelper.getSchedulerInterface();
    JobId id = sched.submit(job);
    schedulerHelper.waitForEventJobFinished(id);
    String contentExpected = "foo";
    JobResult jr = schedulerHelper.getJobResult(id);
    Assert.assertFalse(jr.hadException());
    logger.info("Expected : '" + contentExpected + "'");
    // logger.info(jr.getAllResults().get("C").getOutput().getAllLogs(true));
    // String receivedc = IOUtils.toString(outc.toURI()).trim();
    // logger.info("Received C : '" + receivedc + "'");
    // Assert.assertEquals(contentExpected.toLowerCase(), receivedc.toLowerCase());
    logger.info(jr.getAllResults().get("D").getOutput().getAllLogs(true));
    String receivedd = IOUtils.toString(outd.toURI()).trim();
    logger.info("Received D : '" + receivedd + "'");
    Assert.assertEquals(contentExpected.toLowerCase(), receivedd.toLowerCase());
}
Also used : JobResult(org.ow2.proactive.scheduler.common.job.JobResult) Scheduler(org.ow2.proactive.scheduler.common.Scheduler) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) NativeTask(org.ow2.proactive.scheduler.common.task.NativeTask) ForkEnvironment(org.ow2.proactive.scheduler.common.task.ForkEnvironment) JobId(org.ow2.proactive.scheduler.common.job.JobId) Test(org.junit.Test)

Aggregations

ForkEnvironment (org.ow2.proactive.scheduler.common.task.ForkEnvironment)54 Test (org.junit.Test)27 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)25 JavaTask (org.ow2.proactive.scheduler.common.task.JavaTask)22 ScriptExecutableContainer (org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer)17 TaskContext (org.ow2.proactive.scheduler.task.context.TaskContext)15 TaskLauncherInitializer (org.ow2.proactive.scheduler.task.TaskLauncherInitializer)14 SimpleScript (org.ow2.proactive.scripting.SimpleScript)14 NodeDataSpacesURIs (org.ow2.proactive.scheduler.task.context.NodeDataSpacesURIs)13 VariablesMap (org.ow2.proactive.scheduler.task.utils.VariablesMap)9 ScriptHandler (org.ow2.proactive.scripting.ScriptHandler)9 File (java.io.File)8 NativeTask (org.ow2.proactive.scheduler.common.task.NativeTask)8 TaskScript (org.ow2.proactive.scripting.TaskScript)8 JobId (org.ow2.proactive.scheduler.common.job.JobId)7 JobCreationException (org.ow2.proactive.scheduler.common.exception.JobCreationException)5 JobResult (org.ow2.proactive.scheduler.common.job.JobResult)5 InternalJob (org.ow2.proactive.scheduler.job.InternalJob)5 InternalTask (org.ow2.proactive.scheduler.task.internal.InternalTask)5 FileNotFoundException (java.io.FileNotFoundException)4