Search in sources :

Example 26 with TaskIdImpl.createTaskId

use of org.ow2.proactive.scheduler.task.TaskIdImpl.createTaskId 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 27 with TaskIdImpl.createTaskId

use of org.ow2.proactive.scheduler.task.TaskIdImpl.createTaskId 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 28 with TaskIdImpl.createTaskId

use of org.ow2.proactive.scheduler.task.TaskIdImpl.createTaskId 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 29 with TaskIdImpl.createTaskId

use of org.ow2.proactive.scheduler.task.TaskIdImpl.createTaskId 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)

Example 30 with TaskIdImpl.createTaskId

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

the class TaskLoggerTest method logStreaming.

@Test
public void logStreaming() 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.activateLogs(stringAppenderProvider);
    assertEquals("", stringAppender.toString());
    taskLogger.getOutputSink().println("hello");
    // async appender, it gets buffered
    assertEquals("", stringAppender.toString());
    for (int i = 0; i < 1000; i++) {
        taskLogger.getOutputSink().println("hello");
    }
    assertNotEquals("", 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)

Aggregations

Test (org.junit.Test)86 ScriptExecutableContainer (org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer)52 SimpleScript (org.ow2.proactive.scripting.SimpleScript)52 TaskScript (org.ow2.proactive.scripting.TaskScript)52 JobIdImpl (org.ow2.proactive.scheduler.job.JobIdImpl)49 TaskId (org.ow2.proactive.scheduler.common.task.TaskId)32 TaskContext (org.ow2.proactive.scheduler.task.context.TaskContext)30 NodeDataSpacesURIs (org.ow2.proactive.scheduler.task.context.NodeDataSpacesURIs)29 TaskResultImpl (org.ow2.proactive.scheduler.task.TaskResultImpl)22 JobId (org.ow2.proactive.scheduler.common.job.JobId)19 InProcessTaskExecutor (org.ow2.proactive.scheduler.task.executors.InProcessTaskExecutor)19 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)18 InternalTask (org.ow2.proactive.scheduler.task.internal.InternalTask)15 InternalJob (org.ow2.proactive.scheduler.job.InternalJob)14 InternalTaskFlowJob (org.ow2.proactive.scheduler.job.InternalTaskFlowJob)14 InternalScriptTask (org.ow2.proactive.scheduler.task.internal.InternalScriptTask)14 File (java.io.File)11 ArrayList (java.util.ArrayList)11 TaskLauncherInitializer (org.ow2.proactive.scheduler.task.TaskLauncherInitializer)10 ExecuterInformation (org.ow2.proactive.scheduler.task.internal.ExecuterInformation)10