Search in sources :

Example 1 with TaskLauncher

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

the class InternalForkedScriptTask method createLauncher.

/**
 * {@inheritDoc}
 */
@Override
public TaskLauncher createLauncher(Node node) throws ActiveObjectCreationException, NodeException {
    logger.info(getTaskInfo().getTaskId(), "creating forked task launcher");
    TaskLauncher launcher = (TaskLauncher) PAActiveObject.newActive(TaskLauncher.class.getName(), new Object[] { getDefaultTaskLauncherInitializer(), new ProActiveForkedTaskLauncherFactory() }, node);
    // wait until the task launcher is active
    launcher.isActivated();
    setExecuterInformation(new ExecuterInformation(launcher, node));
    return launcher;
}
Also used : TaskLauncher(org.ow2.proactive.scheduler.task.TaskLauncher) PAActiveObject(org.objectweb.proactive.api.PAActiveObject) ProActiveForkedTaskLauncherFactory(org.ow2.proactive.scheduler.task.ProActiveForkedTaskLauncherFactory)

Example 2 with TaskLauncher

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

the class InternalScriptTask method createLauncher.

/**
 * {@inheritDoc}
 */
@Override
public TaskLauncher createLauncher(Node node) throws ActiveObjectCreationException, NodeException {
    logger.info(getTaskInfo().getTaskId(), "creating non forked task launcher");
    TaskLauncher launcher = (TaskLauncher) PAActiveObject.newActive(TaskLauncher.class.getName(), new Object[] { getDefaultTaskLauncherInitializer(), new ProActiveNonForkedTaskLauncherFactory() }, node);
    // wait until the task launcher is active
    launcher.isActivated();
    setExecuterInformation(new ExecuterInformation(launcher, node));
    return launcher;
}
Also used : TaskLauncher(org.ow2.proactive.scheduler.task.TaskLauncher) PAActiveObject(org.objectweb.proactive.api.PAActiveObject) ProActiveNonForkedTaskLauncherFactory(org.ow2.proactive.scheduler.task.ProActiveNonForkedTaskLauncherFactory)

Example 3 with TaskLauncher

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

the class TaskLauncherTest method thirdPartyCredentials.

@Test
public void thirdPartyCredentials() throws Throwable {
    ScriptExecutableContainer executableContainer = new ScriptExecutableContainer(new TaskScript(new SimpleScript("print(credentials.get('password'))", "groovy")));
    TaskLauncherInitializer initializer = new TaskLauncherInitializer();
    initializer.setTaskId(TaskIdImpl.createTaskId(JobIdImpl.makeJobId("1000"), "job", 1000L));
    createLauncherWithInjectedMocks(initializer, new TestTaskLauncherFactory());
    CredData credData = new CredData("john", "pwd");
    credData.addThirdPartyCredential("password", "r00t");
    final KeyPairProducer keyPairProducer = new KeyPairProducer();
    final TaskLauncher spy = spy(taskLauncher);
    doReturn(keyPairProducer.getKeyPair()).when(spy).getKeyPair();
    Credentials thirdPartyCredentials = Credentials.createCredentials(credData, spy.generatePublicKey());
    executableContainer.setCredentials(thirdPartyCredentials);
    TaskResult taskResult = runTaskLauncher(spy, executableContainer);
    final String allLogs = taskResult.getOutput().getAllLogs(false);
    assertThat(allLogs.contains(String.format("r00t%n")), is(true));
}
Also used : TaskScript(org.ow2.proactive.scripting.TaskScript) SimpleScript(org.ow2.proactive.scripting.SimpleScript) CredData(org.ow2.proactive.authentication.crypto.CredData) ScriptExecutableContainer(org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) KeyPairProducer(org.ow2.proactive.resourcemanager.utils.KeyPairProducer) Credentials(org.ow2.proactive.authentication.crypto.Credentials) Test(org.junit.Test)

Example 4 with TaskLauncher

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

the class KillTaskLauncherTest method kill_while_looping_in_task.

@Test
@Repeat(value = repetitions, parallel = parallel, timeout = timeout)
public void kill_while_looping_in_task() throws Exception {
    final ScriptExecutableContainer executableContainer = new ScriptExecutableContainer(new TaskScript(new SimpleScript("for(;;){}", "javascript")));
    TaskLauncherInitializer initializer = new TaskLauncherInitializer();
    initializer.setTaskId(TaskIdImpl.createTaskId(JobIdImpl.makeJobId("1000"), "job", 1000L));
    Semaphore taskRunning = new Semaphore(0);
    final TaskLauncher taskLauncher = createLauncherWithInjectedMocks(initializer, new TestTaskLauncherFactory(taskRunning));
    final TaskLauncher taskLauncherPA = PAActiveObject.turnActive(taskLauncher);
    taskLauncherPA.doTask(executableContainer, null, null);
    taskRunning.acquire();
    taskLauncherPA.kill();
    assertTaskLauncherIsTerminated(taskLauncherPA);
    PAActiveObject.terminateActiveObject(taskLauncherPA, true);
}
Also used : TaskScript(org.ow2.proactive.scripting.TaskScript) SimpleScript(org.ow2.proactive.scripting.SimpleScript) ScriptExecutableContainer(org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer) Semaphore(java.util.concurrent.Semaphore) Test(org.junit.Test) Repeat(org.ow2.proactive.utils.Repeat)

Example 5 with TaskLauncher

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

the class KillTaskLauncherTest method kill_when_finished.

@Test
@Repeat(value = repetitions, parallel = parallel, timeout = timeout)
public void kill_when_finished() throws Throwable {
    final ScriptExecutableContainer executableContainer = new ScriptExecutableContainer(new TaskScript(new SimpleScript("result='done'", "javascript")));
    TaskLauncherInitializer initializer = new TaskLauncherInitializer();
    initializer.setTaskId(TaskIdImpl.createTaskId(JobIdImpl.makeJobId("1000"), "job", 1000L));
    final TaskLauncher taskLauncher = createLauncherWithInjectedMocks(initializer, new TestTaskLauncherFactory(new Semaphore(0)));
    final TaskLauncher taskLauncherPA = PAActiveObject.turnActive(taskLauncher);
    TaskResultWaiter taskResultWaiter = new TaskResultWaiter();
    WaitForResultNotification waitForResultNotification = new WaitForResultNotification(taskResultWaiter);
    waitForResultNotification = PAActiveObject.turnActive(waitForResultNotification);
    taskLauncherPA.doTask(executableContainer, null, waitForResultNotification);
    assertEquals("done", taskResultWaiter.getTaskResult().value());
    try {
        taskLauncherPA.kill();
    } catch (Exception ignored) {
    // task launcher can be terminated before the kill message is received
    }
    assertTaskLauncherIsTerminated(taskLauncherPA);
    PAActiveObject.terminateActiveObject(taskLauncherPA, true);
}
Also used : TaskScript(org.ow2.proactive.scripting.TaskScript) SimpleScript(org.ow2.proactive.scripting.SimpleScript) ScriptExecutableContainer(org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer) Semaphore(java.util.concurrent.Semaphore) Test(org.junit.Test) Repeat(org.ow2.proactive.utils.Repeat)

Aggregations

TaskLauncher (org.ow2.proactive.scheduler.task.TaskLauncher)11 Test (org.junit.Test)7 ScriptExecutableContainer (org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer)6 SimpleScript (org.ow2.proactive.scripting.SimpleScript)6 TaskScript (org.ow2.proactive.scripting.TaskScript)6 Semaphore (java.util.concurrent.Semaphore)5 PAActiveObject (org.objectweb.proactive.api.PAActiveObject)5 Repeat (org.ow2.proactive.utils.Repeat)5 InternalTask (org.ow2.proactive.scheduler.task.internal.InternalTask)4 ExecuterInformation (org.ow2.proactive.scheduler.task.internal.ExecuterInformation)3 Node (org.objectweb.proactive.core.node.Node)2 NodeException (org.objectweb.proactive.core.node.NodeException)2 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)2 InternalJob (org.ow2.proactive.scheduler.job.InternalJob)2 InternalTaskFlowJob (org.ow2.proactive.scheduler.job.InternalTaskFlowJob)2 ProActiveForkedTaskLauncherFactory (org.ow2.proactive.scheduler.task.ProActiveForkedTaskLauncherFactory)2 ProActiveNonForkedTaskLauncherFactory (org.ow2.proactive.scheduler.task.ProActiveNonForkedTaskLauncherFactory)2 NodeSet (org.ow2.proactive.utils.NodeSet)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1