Search in sources :

Example 66 with JobId

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

the class TestNativeTaskPaths method testNativeTaskPaths.

@Test
public void testNativeTaskPaths() throws Throwable {
    File in = File.createTempFile("input", "space");
    in.delete();
    in.mkdir();
    String inPath = in.getAbsolutePath();
    File out = File.createTempFile("output", "space");
    out.delete();
    out.mkdir();
    File outc = new File(out, OutVarsFileC);
    File outd = new File(out, OutVarsFileD);
    if (outc.exists()) {
        outc.delete();
    }
    if (outd.exists()) {
        outd.delete();
    }
    File scriptTestEnv = null;
    if (OperatingSystem.getOperatingSystem() == OperatingSystem.unix) {
        scriptTestEnv = new File(inPath + File.separator + scriptCLinux);
        scriptTestEnv.createNewFile();
        PrintWriter out3 = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(scriptTestEnv))));
        out3.print(scriptCLinuxContent);
        out3.close();
    } else {
        scriptTestEnv = new File(inPath + File.separator + scriptCWindows);
        scriptTestEnv.createNewFile();
        PrintWriter out3 = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(scriptTestEnv))));
        out3.print(scriptCWindowsContent);
        out3.close();
    }
    TaskFlowJob job = new TaskFlowJob();
    job.setName(this.getClass().getSimpleName());
    job.setInputSpace(in.toURI().toURL().toString());
    job.setOutputSpace(out.toURI().toURL().toString());
    // // testing paths pattern
    // NativeTask C = new NativeTask();
    // C.setName("C");
    // C.addOutputFiles(OutVarsFileC, OutputAccessMode.TransferToOutputSpace);
    // switch (OperatingSystem.getOperatingSystem()) {
    // case windows:
    // C.setCommandLine(new String[] { "cmd", "/C",
    // "echo \"$JAVA\" \"$PROACTIVE_HOME\" > $LOCALSPACE\\" + OutVarsFileC });
    // break;
    // case unix:
    // C.setCommandLine(new String[] { "/bin/bash", "-c",
    // "echo \\\"$JAVA\\\" \\\"$PROACTIVE_HOME\\\" > $LOCALSPACE/" + OutVarsFileC });
    // break;
    // default:
    // throw new IllegalStateException("Unsupported operating system");
    // }
    // job.addTask(C);
    // testing $USERSPACE environment variable
    NativeTask D = new NativeTask();
    D.setName("D");
    if (OperatingSystem.getOperatingSystem() == OperatingSystem.unix) {
        D.addInputFiles(scriptCLinux, InputAccessMode.TransferFromInputSpace);
    } else {
        D.addInputFiles(scriptCWindows, InputAccessMode.TransferFromInputSpace);
    }
    D.addOutputFiles(OutVarsFileD, OutputAccessMode.TransferToOutputSpace);
    switch(OperatingSystem.getOperatingSystem()) {
        case windows:
            D.setCommandLine(new String[] { "cmd", "/C", scriptCWindows });
            break;
        case unix:
            D.setCommandLine(new String[] { "/bin/bash", "-c", "chmod u+x $localspace/" + scriptCLinux + "; $localspace/" + scriptCLinux });
            break;
        default:
            throw new IllegalStateException("Unsupported operating system");
    }
    D.setForkEnvironment(new ForkEnvironment("$LOCALSPACE"));
    job.addTask(D);
    Scheduler sched = schedulerHelper.getSchedulerInterface();
    JobId id = sched.submit(job);
    schedulerHelper.waitForEventJobFinished(id);
    String contentExpected = "foo";
    JobResult jr = schedulerHelper.getJobResult(id);
    Assert.assertFalse(jr.hadException());
    logger.info("Expected : '" + contentExpected + "'");
    // logger.info(jr.getAllResults().get("C").getOutput().getAllLogs(true));
    // String receivedc = IOUtils.toString(outc.toURI()).trim();
    // logger.info("Received C : '" + receivedc + "'");
    // Assert.assertEquals(contentExpected.toLowerCase(), receivedc.toLowerCase());
    logger.info(jr.getAllResults().get("D").getOutput().getAllLogs(true));
    String receivedd = IOUtils.toString(outd.toURI()).trim();
    logger.info("Received D : '" + receivedd + "'");
    Assert.assertEquals(contentExpected.toLowerCase(), receivedd.toLowerCase());
}
Also used : JobResult(org.ow2.proactive.scheduler.common.job.JobResult) Scheduler(org.ow2.proactive.scheduler.common.Scheduler) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) NativeTask(org.ow2.proactive.scheduler.common.task.NativeTask) ForkEnvironment(org.ow2.proactive.scheduler.common.task.ForkEnvironment) JobId(org.ow2.proactive.scheduler.common.job.JobId) Test(org.junit.Test)

Example 67 with JobId

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

the class TestVariablesPatternLateBindings method testPropagatedVariableResolution.

@Test
public void testPropagatedVariableResolution() throws Throwable {
    TaskFlowJob job = (TaskFlowJob) StaxJobFactory.getFactory().createJob(absolutePath(job_desc));
    JobId id = schedulerHelper.submitJob(job);
    TaskInfo taskInfo = schedulerHelper.waitForEventTaskFinished(id, "Groovy_Task2");
    // assert the task finished correctly
    assertEquals(TaskStatus.FINISHED, taskInfo.getStatus());
    // for the second task:
    String jobLog = schedulerHelper.getTaskResult(id, "Groovy_Task2").getOutput().getAllLogs();
    Assert.assertThat(jobLog, CoreMatchers.containsString("WORKFLOW_VAR1=workflow_value"));
    Assert.assertThat(jobLog, CoreMatchers.containsString("WORKFLOW_VAR2=var2_workflow_value"));
    Assert.assertThat(jobLog, CoreMatchers.containsString("WORKFLOW_VAR3=workflow_value"));
    Assert.assertThat(jobLog, CoreMatchers.containsString("WORKFLOW_VAR4=workflow_value_task_value"));
    Assert.assertThat(jobLog, CoreMatchers.containsString("TASK_VAR1=task_value"));
    Assert.assertThat(jobLog, CoreMatchers.containsString("TASK_VAR2=task_value_" + id.toString()));
    Assert.assertThat(jobLog, CoreMatchers.containsString("TASK_VAR3=task_value_task_value"));
    Assert.assertThat(jobLog, CoreMatchers.containsString("TASK_VAR4=task_value_inherited_value"));
    Assert.assertThat(jobLog, CoreMatchers.containsString("INHERITED_VAR1=inherited_value"));
    Assert.assertThat(jobLog, CoreMatchers.containsString("INHERITED_VAR2=inherited_value_" + id.toString()));
    Assert.assertThat(jobLog, CoreMatchers.containsString("INHERITED_VAR3=inherited_value_task_value"));
    Assert.assertThat(jobLog, CoreMatchers.containsString("INHERITED_VAR4=inherited_value_inherited_value"));
}
Also used : TaskInfo(org.ow2.proactive.scheduler.common.task.TaskInfo) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) JobId(org.ow2.proactive.scheduler.common.job.JobId) Test(org.junit.Test)

Example 68 with JobId

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

the class JobRemoveHandlerTest method init.

@Before
public void init() throws Exception {
    jobId = new JobIdImpl(id, jobName);
    MockitoAnnotations.initMocks(this);
    Mockito.when(infrastructure.getDBManager()).thenReturn(dbManager);
    Mockito.when(infrastructure.getRMProxiesManager()).thenReturn(rmProxiesManager);
    Mockito.when(rmProxiesManager.getRmUrl()).thenReturn(null);
    Mockito.when(dbManager.loadJobWithTasksIfNotRemoved(jobId)).thenReturn(Collections.singletonList(job));
    Mockito.when(job.getJobInfo()).thenReturn(jobInfo);
    service = new SchedulingService(infrastructure, listener, null, policyClassName, schedulingMethod);
    jobRemoveHandler = new JobRemoveHandler(service, jobId);
}
Also used : JobIdImpl(org.ow2.proactive.scheduler.job.JobIdImpl) Before(org.junit.Before)

Example 69 with JobId

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

the class LiveJobsTest method testResumeUnstartedJob.

@Test(timeout = 60000)
public void testResumeUnstartedJob() {
    InternalJob job = new InternalTaskFlowJob("test-name", JobPriority.NORMAL, OnTaskError.CANCEL_JOB, "description");
    JobId id = new JobIdImpl(666L, "test-name");
    job.setId(id);
    List<InternalTask> tasksList = new ArrayList<>();
    InternalTask internalTask = new InternalScriptTask(job);
    tasksList.add(internalTask);
    job.setTasks(tasksList);
    liveJobs.jobSubmitted(job);
    assertThat(liveJobs.resumeJob(id), is(false));
}
Also used : InternalScriptTask(org.ow2.proactive.scheduler.task.internal.InternalScriptTask) InternalJob(org.ow2.proactive.scheduler.job.InternalJob) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) ArrayList(java.util.ArrayList) JobIdImpl(org.ow2.proactive.scheduler.job.JobIdImpl) InternalTaskFlowJob(org.ow2.proactive.scheduler.job.InternalTaskFlowJob) JobId(org.ow2.proactive.scheduler.common.job.JobId) Test(org.junit.Test)

Example 70 with JobId

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

the class LiveJobsTest method testFinishInErrorTaskDoesNotFinishPendingTask.

@Test(timeout = 60000)
public void testFinishInErrorTaskDoesNotFinishPendingTask() throws UnknownTaskException, UnknownJobException {
    InternalJob job = new InternalTaskFlowJob("test-name", JobPriority.NORMAL, OnTaskError.CONTINUE_JOB_EXECUTION, "description");
    JobId id = new JobIdImpl(666L, "test-name");
    job.setId(id);
    List<InternalTask> tasksList = new ArrayList<>();
    InternalTask internalTask = new InternalScriptTask(job);
    internalTask.setName("task-name");
    internalTask.setStatus(TaskStatus.PENDING);
    tasksList.add(internalTask);
    job.setTasks(tasksList);
    liveJobs.jobSubmitted(job);
    liveJobs.finishInErrorTask(job.getId(), "task-name");
    assertThat(internalTask.getStatus(), is(TaskStatus.PENDING));
}
Also used : InternalScriptTask(org.ow2.proactive.scheduler.task.internal.InternalScriptTask) InternalJob(org.ow2.proactive.scheduler.job.InternalJob) InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) ArrayList(java.util.ArrayList) JobIdImpl(org.ow2.proactive.scheduler.job.JobIdImpl) InternalTaskFlowJob(org.ow2.proactive.scheduler.job.InternalTaskFlowJob) JobId(org.ow2.proactive.scheduler.common.job.JobId) Test(org.junit.Test)

Aggregations

JobId (org.ow2.proactive.scheduler.common.job.JobId)179 Test (org.junit.Test)121 Scheduler (org.ow2.proactive.scheduler.common.Scheduler)73 File (java.io.File)58 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)57 UnknownJobException (org.ow2.proactive.scheduler.common.exception.UnknownJobException)55 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)55 JobState (org.ow2.proactive.scheduler.common.job.JobState)51 ArrayList (java.util.ArrayList)45 PermissionException (org.ow2.proactive.scheduler.common.exception.PermissionException)43 NotConnectedException (org.ow2.proactive.scheduler.common.exception.NotConnectedException)42 JobIdImpl (org.ow2.proactive.scheduler.job.JobIdImpl)40 InternalJob (org.ow2.proactive.scheduler.job.InternalJob)38 TaskId (org.ow2.proactive.scheduler.common.task.TaskId)37 JobResult (org.ow2.proactive.scheduler.common.job.JobResult)36 Path (javax.ws.rs.Path)35 NotConnectedRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException)35 PermissionRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException)34 Produces (javax.ws.rs.Produces)33 UnknownJobRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.UnknownJobRestException)33