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