Search in sources :

Example 96 with Job

use of org.ow2.proactive.scheduler.common.job.Job in project scheduling by ow2-proactive.

the class TaskLauncherTest method javaTask.

@Test
public void javaTask() throws Throwable {
    HashMap<String, byte[]> args = new HashMap<>();
    args.put("number", AllObjects2BytesConverterHandler.convertObject2Byte("number", 123));
    ScriptExecutableContainer executableContainer = new ScriptExecutableContainer(new TaskScript(new SimpleScript(WaitAndPrint.class.getName(), "java", new Serializable[] { args })));
    TaskLauncherInitializer initializer = new TaskLauncherInitializer();
    initializer.setTaskId(TaskIdImpl.createTaskId(JobIdImpl.makeJobId("1000"), "job*1", 1000L));
    TaskResult taskResult = runTaskLauncher(createLauncherWithInjectedMocks(initializer, new TestTaskLauncherFactory()), executableContainer);
    assertThat((String) taskResult.value(), is(not("")));
    assertThat(taskResult.getOutput().getAllLogs(false).contains("123"), is(true));
}
Also used : TaskScript(org.ow2.proactive.scripting.TaskScript) HashMap(java.util.HashMap) SimpleScript(org.ow2.proactive.scripting.SimpleScript) WaitAndPrint(org.ow2.proactive.scheduler.examples.WaitAndPrint) ScriptExecutableContainer(org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) Test(org.junit.Test)

Example 97 with Job

use of org.ow2.proactive.scheduler.common.job.Job in project scheduling by ow2-proactive.

the class TaskLauncherTest method simpleTask.

@Test
public void simpleTask() throws Throwable {
    ScriptExecutableContainer executableContainer = new ScriptExecutableContainer(new TaskScript(new SimpleScript("print('hello'); result='hello'", "groovy")));
    TaskLauncherInitializer initializer = new TaskLauncherInitializer();
    initializer.setPreScript(new SimpleScript("print('pre')", "groovy"));
    initializer.setPostScript(new SimpleScript("print('post')", "groovy"));
    initializer.setTaskId(TaskIdImpl.createTaskId(JobIdImpl.makeJobId("1000"), "job", 1000L));
    TaskResult taskResult = runTaskLauncher(createLauncherWithInjectedMocks(initializer, new TestTaskLauncherFactory()), executableContainer);
    assertThat((String) taskResult.value(), is("hello"));
    assertThat(taskResult.getOutput().getAllLogs(false).contains(String.format("prehellopost%n")), is(true));
}
Also used : TaskScript(org.ow2.proactive.scripting.TaskScript) SimpleScript(org.ow2.proactive.scripting.SimpleScript) ScriptExecutableContainer(org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer) TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) Test(org.junit.Test)

Example 98 with Job

use of org.ow2.proactive.scheduler.common.job.Job 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 99 with Job

use of org.ow2.proactive.scheduler.common.job.Job in project scheduling by ow2-proactive.

the class TaskLoggerTest method getStoredLogs.

@Test
public void getStoredLogs() throws Exception {
    taskLogger = new TaskLogger(TaskIdImpl.createTaskId(new JobIdImpl(1000, "job"), "task", 42L), "myhost");
    final StringWriter stringAppender = new StringWriter();
    AppenderProvider stringAppenderProvider = new AppenderProvider() {

        @Override
        public Appender getAppender() throws LogForwardingException {
            return new WriterAppender(new PatternLayout("%m%n"), stringAppender);
        }
    };
    taskLogger.getStoredLogs(stringAppenderProvider);
    assertEquals("", stringAppender.toString());
    taskLogger.getOutputSink().println("hello");
    taskLogger.getStoredLogs(stringAppenderProvider);
    assertEquals(String.format("hello%n"), stringAppender.toString());
}
Also used : StringWriter(java.io.StringWriter) AppenderProvider(org.ow2.proactive.scheduler.common.util.logforwarder.AppenderProvider) PatternLayout(org.apache.log4j.PatternLayout) JobIdImpl(org.ow2.proactive.scheduler.job.JobIdImpl) WriterAppender(org.apache.log4j.WriterAppender) Test(org.junit.Test)

Example 100 with Job

use of org.ow2.proactive.scheduler.common.job.Job in project scheduling by ow2-proactive.

the class TaskLoggerTest method logPattern.

@Test
public void logPattern() throws Exception {
    TaskId taskId = TaskIdImpl.createTaskId(new JobIdImpl(1000, "job"), "task", 42L);
    taskLogger = new TaskLogger(taskId, "myhost");
    assertEquals("", taskLogger.getLogs().getAllLogs(false));
    taskLogger.getOutputSink().println("hello");
    String quotedStringTaskId = Pattern.quote(taskId.toString());
    assertTrue(taskLogger.getLogs().getAllLogs(true).matches("\\[" + quotedStringTaskId + "@myhost;[0-9][0-9]:[0-9][0-9]:[0-9][0-9]\\] hello \r?\n"));
    taskLogger.getErrorSink().println("error");
    assertTrue(taskLogger.getLogs().getStderrLogs(true).matches("\\[" + quotedStringTaskId + "@myhost;[0-9][0-9]:[0-9][0-9]:[0-9][0-9]\\] error \r?\n"));
}
Also used : TaskId(org.ow2.proactive.scheduler.common.task.TaskId) JobIdImpl(org.ow2.proactive.scheduler.job.JobIdImpl) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)260 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)198 InternalJob (org.ow2.proactive.scheduler.job.InternalJob)145 JobId (org.ow2.proactive.scheduler.common.job.JobId)122 InternalTask (org.ow2.proactive.scheduler.task.internal.InternalTask)91 JavaTask (org.ow2.proactive.scheduler.common.task.JavaTask)87 File (java.io.File)76 SimpleScript (org.ow2.proactive.scripting.SimpleScript)70 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)68 TaskScript (org.ow2.proactive.scripting.TaskScript)65 JobIdImpl (org.ow2.proactive.scheduler.job.JobIdImpl)64 Scheduler (org.ow2.proactive.scheduler.common.Scheduler)58 ScriptExecutableContainer (org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer)52 UnknownJobException (org.ow2.proactive.scheduler.common.exception.UnknownJobException)48 TaskId (org.ow2.proactive.scheduler.common.task.TaskId)48 ArrayList (java.util.ArrayList)46 JobState (org.ow2.proactive.scheduler.common.job.JobState)45 TaskResultImpl (org.ow2.proactive.scheduler.task.TaskResultImpl)45 PermissionException (org.ow2.proactive.scheduler.common.exception.PermissionException)41 NotConnectedException (org.ow2.proactive.scheduler.common.exception.NotConnectedException)39