Search in sources :

Example 41 with SimpleScript

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);
    }
}
Also used : InternalScriptTask(org.ow2.proactive.scheduler.task.internal.InternalScriptTask) TaskScript(org.ow2.proactive.scripting.TaskScript) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) InternalForkedScriptTask(org.ow2.proactive.scheduler.task.internal.InternalForkedScriptTask) SimpleScript(org.ow2.proactive.scripting.SimpleScript) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) ScriptExecutableContainer(org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer) ForkEnvironment(org.ow2.proactive.scheduler.common.task.ForkEnvironment) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) InvalidScriptException(org.ow2.proactive.scripting.InvalidScriptException) InternalException(org.ow2.proactive.scheduler.common.exception.InternalException)

Example 42 with SimpleScript

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;
}
Also used : InternalScriptTask(org.ow2.proactive.scheduler.task.internal.InternalScriptTask) TaskScript(org.ow2.proactive.scripting.TaskScript) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) InternalForkedScriptTask(org.ow2.proactive.scheduler.task.internal.InternalForkedScriptTask) InvalidScriptException(org.ow2.proactive.scripting.InvalidScriptException) SimpleScript(org.ow2.proactive.scripting.SimpleScript) ScriptExecutableContainer(org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) InvalidScriptException(org.ow2.proactive.scripting.InvalidScriptException) InternalException(org.ow2.proactive.scheduler.common.exception.InternalException)

Example 43 with SimpleScript

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();
}
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 44 with SimpleScript

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", "");
}
Also used : ScriptTask(org.ow2.proactive.scheduler.common.task.ScriptTask) TaskScript(org.ow2.proactive.scripting.TaskScript) JobResult(org.ow2.proactive.scheduler.common.job.JobResult) SimpleScript(org.ow2.proactive.scripting.SimpleScript) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) JobId(org.ow2.proactive.scheduler.common.job.JobId)

Example 45 with SimpleScript

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;
}
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)

Aggregations

SimpleScript (org.ow2.proactive.scripting.SimpleScript)99 TaskScript (org.ow2.proactive.scripting.TaskScript)78 Test (org.junit.Test)68 ScriptExecutableContainer (org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer)64 NodeDataSpacesURIs (org.ow2.proactive.scheduler.task.context.NodeDataSpacesURIs)31 TaskContext (org.ow2.proactive.scheduler.task.context.TaskContext)31 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)21 TaskLauncherInitializer (org.ow2.proactive.scheduler.task.TaskLauncherInitializer)19 InProcessTaskExecutor (org.ow2.proactive.scheduler.task.executors.InProcessTaskExecutor)19 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)18 File (java.io.File)16 ForkEnvironment (org.ow2.proactive.scheduler.common.task.ForkEnvironment)13 Serializable (java.io.Serializable)12 ScriptTask (org.ow2.proactive.scheduler.common.task.ScriptTask)10 TaskResultImpl (org.ow2.proactive.scheduler.task.TaskResultImpl)10 TestTaskOutput (org.ow2.proactive.scheduler.task.TestTaskOutput)9 ForkedTaskExecutor (org.ow2.proactive.scheduler.task.executors.ForkedTaskExecutor)9 JobIdImpl (org.ow2.proactive.scheduler.job.JobIdImpl)8 HashMap (java.util.HashMap)7 JobId (org.ow2.proactive.scheduler.common.job.JobId)7