Search in sources :

Example 16 with Command

use of org.ow2.proactive_grid_cloud_portal.cli.cmd.Command in project scheduling by ow2-proactive.

the class AbstractIModeCommand method execute.

@Override
public void execute(ApplicationContext currentContext) throws CLIException {
    currentContext.setProperty(IMODE, true);
    ScriptEngine engine = currentContext.getEngine();
    try {
        // load supported functions
        engine.eval(new InputStreamReader(script()));
    } catch (ScriptException error) {
        throw new CLIException(CLIException.REASON_OTHER, error);
    }
    while (!currentContext.getProperty(TERMINATE, Boolean.TYPE, false)) {
        try {
            String command = readLine(currentContext, "> ");
            if (command == null) {
                // EOF, exit interactive shell
                break;
            }
            engine.eval(command);
        } catch (ScriptException se) {
            handleError(String.format("An error occurred while executing the script:"), se, currentContext);
        }
    }
}
Also used : ScriptException(javax.script.ScriptException) InputStreamReader(java.io.InputStreamReader) CLIException(org.ow2.proactive_grid_cloud_portal.cli.CLIException) ScriptEngine(javax.script.ScriptEngine)

Example 17 with Command

use of org.ow2.proactive_grid_cloud_portal.cli.cmd.Command 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 18 with Command

use of org.ow2.proactive_grid_cloud_portal.cli.cmd.Command in project scheduling by ow2-proactive.

the class TestReadSchedulerAccount method singleJobScenario.

private void singleJobScenario(AccountData accountData) throws Exception {
    TaskFlowJob jobDef1 = new TaskFlowJob();
    JavaTask javaTask = new JavaTask();
    javaTask.setExecutableClassName(TestDummyExecutable.class.getName());
    javaTask.setName("task1");
    jobDef1.addTask(javaTask);
    JavaTask forkJavaTask = createDefaultTask("task2");
    forkJavaTask.setExecutableClassName(TestDummyExecutable.class.getName());
    forkJavaTask.setForkEnvironment(new ForkEnvironment());
    jobDef1.addTask(forkJavaTask);
    NativeTask nativeTask = new NativeTask();
    nativeTask.setName("task3");
    nativeTask.setCommandLine("command");
    jobDef1.addTask(nativeTask);
    InternalJob job1 = defaultSubmitJobAndLoadInternal(true, jobDef1, accountData.userName);
    // job is submitted
    checkAccount(invalidUser);
    checkAccount(accountData);
    // task1 started
    job1.start();
    startTask(job1, job1.getTask("task1"));
    dbManager.jobTaskStarted(job1, job1.getTask("task1"), true);
    checkAccount(invalidUser);
    checkAccount(accountData);
    // task1 finished
    accountData.taskTime += finishTask(job1, "task1");
    accountData.taskCount++;
    checkAccount(invalidUser);
    checkAccount(accountData);
    // task2 and task3 started
    startTask(job1, job1.getTask("task2"));
    dbManager.jobTaskStarted(job1, job1.getTask("task2"), true);
    startTask(job1, job1.getTask("task3"));
    dbManager.jobTaskStarted(job1, job1.getTask("task3"), true);
    checkAccount(invalidUser);
    checkAccount(accountData);
    // task2 finished
    accountData.taskTime += finishTask(job1, "task2");
    accountData.taskCount++;
    checkAccount(invalidUser);
    checkAccount(accountData);
    // task3 and job finished
    accountData.taskTime += finishTask(job1, "task3");
    accountData.taskCount++;
    accountData.jobCount++;
    accountData.jobTime += job1.getFinishedTime() - job1.getStartTime();
    checkAccount(invalidUser);
    checkAccount(accountData);
}
Also used : InternalJob(org.ow2.proactive.scheduler.job.InternalJob) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) JavaTask(org.ow2.proactive.scheduler.common.task.JavaTask) NativeTask(org.ow2.proactive.scheduler.common.task.NativeTask) ForkEnvironment(org.ow2.proactive.scheduler.common.task.ForkEnvironment)

Example 19 with Command

use of org.ow2.proactive_grid_cloud_portal.cli.cmd.Command in project scheduling by ow2-proactive.

the class TestReportingQueries method doTest.

@Test
public void doTest() throws Exception {
    checkInvalidIds();
    checkJobAndTasksNumbers(0, 0, 0, 0, 0, 0, 0, 0);
    checkMeanPendingTime();
    checkMeanExecutionTime();
    checkMeanSubmittingPeriod();
    TaskFlowJob jobDef1 = new TaskFlowJob();
    JavaTask javaTask = new JavaTask();
    javaTask.setExecutableClassName(TestDummyExecutable.class.getName());
    javaTask.setName("task1");
    jobDef1.addTask(javaTask);
    JavaTask forkJavaTask = createDefaultTask("task2");
    forkJavaTask.setExecutableClassName(TestDummyExecutable.class.getName());
    forkJavaTask.setForkEnvironment(new ForkEnvironment());
    jobDef1.addTask(forkJavaTask);
    NativeTask nativeTask = new NativeTask();
    nativeTask.setName("task3");
    nativeTask.setCommandLine("command");
    jobDef1.addTask(nativeTask);
    InternalJob job1 = defaultSubmitJobAndLoadInternal(true, jobDef1);
    try {
        dbManager.getJobPendingTime(job1.getJobInfo().getJobId().value());
        Assert.fail();
    } catch (RuntimeException e) {
    }
    try {
        dbManager.getJobRunningTime(job1.getJobInfo().getJobId().value());
        Assert.fail();
    } catch (RuntimeException e) {
    }
    checkJobAndTasksNumbers(1, 0, 0, 1, 3, 0, 0, 3);
    checkMeanSubmittingPeriod(job1);
    checkMeanTaskPendingTime(job1);
    checkMeanTaskRunningTime(job1);
    checkNumberOfHosts(job1, 0);
    Thread.sleep(100);
    InternalJob job2 = defaultSubmitJobAndLoadInternal(true, jobDef1);
    checkMeanSubmittingPeriod(job1, job2);
    checkJobAndTasksNumbers(2, 0, 0, 2, 6, 0, 0, 6);
    // job1: task1 started
    job1.start();
    startTask(job1, job1.getTask("task1"));
    dbManager.jobTaskStarted(job1, job1.getTask("task1"), true);
    checkNumberOfHosts(job1, 1);
    checkJobPendingTime(job1);
    checkMeanPendingTime(job1);
    checkMeanTaskPendingTime(job1);
    checkMeanTaskRunningTime(job1);
    checkJobAndTasksNumbers(1, 1, 0, 2, 5, 1, 0, 6);
    // job1: task1 finished
    finishTask(job1, "task1");
    checkJobAndTasksNumbers(1, 1, 0, 2, 5, 0, 1, 6);
    checkMeanTaskRunningTime(job1);
    checkNumberOfHosts(job1, 1);
    // job2: task1 started
    job2.start();
    startTask(job2, job2.getTask("task1"));
    dbManager.jobTaskStarted(job2, job2.getTask("task1"), true);
    checkMeanPendingTime(job1, job2);
    checkMeanTaskRunningTime(job2);
    checkJobAndTasksNumbers(0, 2, 0, 2, 4, 1, 1, 6);
    // job1: task2 and task3 started
    startTask(job1, job1.getTask("task2"));
    dbManager.jobTaskStarted(job1, job1.getTask("task2"), false);
    startTask(job1, job1.getTask("task3"));
    dbManager.jobTaskStarted(job1, job1.getTask("task3"), false);
    checkMeanTaskPendingTime(job1);
    checkMeanTaskRunningTime(job1);
    checkJobAndTasksNumbers(0, 2, 0, 2, 2, 3, 1, 6);
    // job1: task2 and task3 finished, job1 finished
    finishTask(job1, "task2");
    finishTask(job1, "task3");
    checkJobRunningTime(job1);
    checkMeanExecutionTime(job1);
    checkMeanTaskRunningTime(job1);
    checkJobAndTasksNumbers(0, 1, 1, 2, 2, 1, 3, 6);
    checkNumberOfHosts(job1, 1);
    // job2: task1, task2 and task3 finished, job2 finished
    finishTask(job2, "task1");
    finishTask(job2, "task2");
    finishTask(job2, "task3");
    checkJobRunningTime(job2);
    checkMeanExecutionTime(job1, job2);
    checkMeanTaskRunningTime(job2);
    checkJobAndTasksNumbers(0, 0, 2, 2, 0, 0, 6, 6);
    // remove job2
    dbManager.removeJob(job2.getId(), System.currentTimeMillis(), false);
    checkJobAndTasksNumbers(0, 0, 1, 1, 0, 0, 3, 3);
    checkMeanPendingTime(job1, job2);
    checkMeanExecutionTime(job1, job2);
    checkMeanSubmittingPeriod(job1, job2);
    InternalJob job3 = defaultSubmitJobAndLoadInternal(true, jobDef1);
    checkMeanSubmittingPeriod(job1, job2, job3);
}
Also used : InternalJob(org.ow2.proactive.scheduler.job.InternalJob) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) JavaTask(org.ow2.proactive.scheduler.common.task.JavaTask) NativeTask(org.ow2.proactive.scheduler.common.task.NativeTask) ForkEnvironment(org.ow2.proactive.scheduler.common.task.ForkEnvironment) Test(org.junit.Test)

Example 20 with Command

use of org.ow2.proactive_grid_cloud_portal.cli.cmd.Command 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)

Aggregations

Test (org.junit.Test)12 IOException (java.io.IOException)11 RMDeployingNode (org.ow2.proactive.resourcemanager.rmnode.RMDeployingNode)10 Throwables.getStackTraceAsString (com.google.common.base.Throwables.getStackTraceAsString)9 ArrayList (java.util.ArrayList)9 RMException (org.ow2.proactive.resourcemanager.exception.RMException)9 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)9 NativeTask (org.ow2.proactive.scheduler.common.task.NativeTask)9 KeyException (java.security.KeyException)8 File (java.io.File)7 ForkEnvironment (org.ow2.proactive.scheduler.common.task.ForkEnvironment)6 JobCreationException (org.ow2.proactive.scheduler.common.exception.JobCreationException)5 CommandLineBuilder (org.ow2.proactive.resourcemanager.utils.CommandLineBuilder)4 JavaTask (org.ow2.proactive.scheduler.common.task.JavaTask)4 UnknownHostException (java.net.UnknownHostException)3 Client (org.ow2.proactive.resourcemanager.authentication.Client)3 Command (org.ow2.proactive_grid_cloud_portal.cli.cmd.Command)3 InetAddress (java.net.InetAddress)2 Properties (java.util.Properties)2 ExecutionException (java.util.concurrent.ExecutionException)2