Search in sources :

Example 71 with JobState

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

the class GetJobStateCommand method execute.

@Override
public void execute(ApplicationContext currentContext) throws CLIException {
    SchedulerRestInterface scheduler = currentContext.getRestClient().getScheduler();
    try {
        JobStateData jobState = scheduler.listJobs(currentContext.getSessionId(), jobId);
        resultStack(currentContext).push(jobState);
        if (!currentContext.isSilent()) {
            writeLine(currentContext, "%s", StringUtility.jobStateAsString(job(), jobState));
        }
    } catch (Exception e) {
        handleError(String.format("An error occurred while retrieving %s state:", job()), e, currentContext);
    }
}
Also used : JobStateData(org.ow2.proactive_grid_cloud_portal.scheduler.dto.JobStateData) SchedulerRestInterface(org.ow2.proactive_grid_cloud_portal.common.SchedulerRestInterface) CLIException(org.ow2.proactive_grid_cloud_portal.cli.CLIException)

Example 72 with JobState

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

the class SchedulerFrontendStateTest method getIdentifiedJobTest.

@Test
public void getIdentifiedJobTest() throws Exception {
    SchedulerJMXHelper mockJMX = mock(SchedulerJMXHelper.class);
    when(mockJMX.getSchedulerRuntimeMBean()).thenReturn(new RuntimeDataMBeanImpl(null));
    SchedulerStateImpl<ClientJobState> schedulerStateImpl = new SchedulerStateImpl<>();
    JobIdImpl jobId = new JobIdImpl(1234L, "job name");
    ClientJobState jobState = mock(ClientJobState.class);
    when(jobState.getId()).thenReturn(jobId);
    schedulerStateImpl.setFinishedJobs(new Vector(Lists.newArrayList(jobState)));
    final SchedulerFrontendState schedulerFrontendState = new SchedulerFrontendState(schedulerStateImpl, mockJMX);
    assertEquals(schedulerFrontendState.getIdentifiedJob(jobId).getJobId(), (jobId));
}
Also used : SchedulerJMXHelper(org.ow2.proactive.scheduler.core.jmx.SchedulerJMXHelper) RuntimeDataMBeanImpl(org.ow2.proactive.scheduler.core.jmx.mbean.RuntimeDataMBeanImpl) ClientJobState(org.ow2.proactive.scheduler.job.ClientJobState) JobIdImpl(org.ow2.proactive.scheduler.job.JobIdImpl) Vector(java.util.Vector) Test(org.junit.Test)

Example 73 with JobState

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

the class SchedulerTHelper method testJobSubmission.

/**
 * Creates and submit a job from an XML job descriptor, and check, with assertions,
 * event related to this job submission :
 * 1/ job submitted event
 * 2/ job passing from pending to running (with state set to running).
 * 3/ job passing from running to finished (with state set to finished).
 * 4/ every task finished with or without error (configurable)
 * <p>
 * Then returns.
 * <p>
 * This is the simplest events sequence of a job submission. If you need to test
 * specific events or task states (failures, rescheduling etc, you must not use this
 * helper and check events sequence with waitForEvent**() functions.
 *
 * @param userInt         scheduler interface
 * @param jobToSubmit     job object to schedule.
 * @param acceptSkipped   if true then skipped task will not fail the test
 * @param failIfTaskError if true then the test will fail if a task was in error
 * @return JobId, the job's identifier.
 * @throws Exception if an error occurs at job submission, or during
 *                   verification of events sequence.
 */
public JobId testJobSubmission(Scheduler userInt, Job jobToSubmit, boolean acceptSkipped, boolean failIfTaskError) throws Exception {
    JobId id = userInt.submit(jobToSubmit);
    log("Job submitted, id " + id.toString());
    log("Waiting for jobSubmitted");
    JobState receivedState = waitForEventJobSubmitted(id);
    Assert.assertEquals(id, receivedState.getId());
    log("Waiting for job running");
    JobInfo jInfo = waitForEventJobRunning(id);
    Assert.assertEquals(jInfo.getJobId(), id);
    Assert.assertEquals("Job " + jInfo.getJobId(), JobStatus.RUNNING, jInfo.getStatus());
    log("Waiting for job finished");
    jInfo = waitForEventJobFinished(userInt, id);
    Assert.assertEquals("Job " + jInfo.getJobId(), JobStatus.FINISHED, jInfo.getStatus());
    log("Job finished");
    boolean taskError = false;
    String message = "";
    if (jobToSubmit instanceof TaskFlowJob) {
        JobState jobState = userInt.getJobState(id);
        for (TaskState t : jobState.getTasks()) {
            log("Looking at the result of task : " + t.getName());
            if (t.getStatus() == TaskStatus.FAULTY) {
                TaskResult tres = userInt.getTaskResult(jInfo.getJobId(), t.getName());
                if (tres == null) {
                    message = "Task result of " + t.getName() + " should not be null.";
                    taskError = true;
                    break;
                }
                if (tres.getOutput() != null) {
                    System.err.println("Output of failing task (" + t.getName() + ") :");
                    System.err.println(tres.getOutput().getAllLogs(true));
                }
                if (tres.hadException()) {
                    System.err.println("Exception occurred in task (" + t.getName() + ") :");
                    tres.getException().printStackTrace(System.err);
                    message = "Exception occurred in task (" + t.getName() + ")";
                    taskError = true;
                    break;
                }
            } else if (acceptSkipped && t.getStatus() == TaskStatus.SKIPPED) {
            // do nothing
            } else if (t.getStatus() != TaskStatus.FINISHED) {
                message = "Invalid task status for task " + t.getName() + " : " + t.getStatus();
                taskError = true;
                break;
            } else {
                TaskResult tres = userInt.getTaskResult(jInfo.getJobId(), t.getName());
                System.out.println("Output of task (" + t.getName() + ") :");
                System.out.println(tres.getOutput().getAllLogs(true));
            }
        }
    }
    if (taskError && failIfTaskError) {
        fail(message);
    }
    return id;
}
Also used : TaskResult(org.ow2.proactive.scheduler.common.task.TaskResult) TaskState(org.ow2.proactive.scheduler.common.task.TaskState)

Example 74 with JobState

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

the class TRepJobs method testJobs.

public void testJobs(TRepCase... testCases) throws Throwable {
    for (TRepCase tcase : testCases) {
        String path = new File(TWorkflowJobs.class.getResource(tcase.jobPath).toURI()).getAbsolutePath();
        Job job = JobFactory.getFactory().createJob(path);
        JobId id = schedulerHelper.submitJob(job);
        SchedulerTHelper.log("Job submitted, id " + id.toString());
        JobState receivedstate = schedulerHelper.waitForEventJobSubmitted(id);
        Assert.assertEquals(id, receivedstate.getId());
        JobInfo jInfo = schedulerHelper.waitForEventJobRunning(id);
        Assert.assertEquals(jInfo.getJobId(), id);
        Assert.assertEquals(JobStatus.RUNNING, jInfo.getStatus());
        jInfo = schedulerHelper.waitForEventJobFinished(id);
        Assert.assertEquals(JobStatus.FINISHED, jInfo.getStatus());
        SchedulerTHelper.log("Job finished");
        JobResult res = schedulerHelper.getJobResult(id);
        Assert.assertFalse(schedulerHelper.getJobResult(id).hadException());
        JobState js = schedulerHelper.getSchedulerInterface().getJobState(id);
        // final number of tasks
        Assert.assertEquals(tcase.total, js.getTasks().size());
        // to be checked against this.tasks
        HashMap<String, Long> finalTaskCount = new HashMap<>();
        // to be checked against this.results
        HashMap<String, Long> finalResSum = new HashMap<>();
        for (TaskState ts : js.getTasks()) {
            String baseName = InternalTask.getInitialName(ts.getName());
            long count = 0;
            long sum = 0;
            if (finalTaskCount.containsKey(baseName)) {
                count = finalTaskCount.get(baseName);
                sum = finalResSum.get(baseName);
            }
            finalTaskCount.put(baseName, count + 1);
            long tr = 0;
            if (ts.getStatus().equals(TaskStatus.SKIPPED)) {
                tr = -1;
            } else {
                Serializable sr = res.getAllResults().get(ts.getName()).value();
                if (sr instanceof Long) {
                    tr = ((Long) sr).longValue();
                }
            }
            finalResSum.put(baseName, sum + tr);
        }
        Assert.assertEquals(tcase.tasks.size(), finalTaskCount.size());
        Assert.assertEquals(tcase.results.size(), finalResSum.size());
        Assert.assertEquals(finalTaskCount.size(), finalResSum.size());
        for (Entry<String, Long> entry : finalTaskCount.entrySet()) {
            Assert.assertTrue(tcase.tasks.containsKey(entry.getKey()));
            long val = tcase.tasks.get(entry.getKey());
            Assert.assertEquals(val, entry.getValue().longValue());
        }
        for (Entry<String, Long> entry : finalResSum.entrySet()) {
            Assert.assertTrue(tcase.results.containsKey(entry.getKey()));
            long val = tcase.results.get(entry.getKey());
            Assert.assertEquals(val, entry.getValue().longValue());
        }
        schedulerHelper.removeJob(id);
        schedulerHelper.waitForEventJobRemoved(id);
    }
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) File(java.io.File) TaskState(org.ow2.proactive.scheduler.common.task.TaskState)

Example 75 with JobState

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

the class TestGenericInformation method testRegularJob.

public void testRegularJob() throws Throwable {
    JobId jobId = schedulerHelper.submitJob(createJob());
    SchedulerTHelper.log("Job submitted, id " + jobId.toString());
    JobState js = schedulerHelper.waitForEventJobSubmitted(jobId);
    checkJobState(js);
    checkTaskState(js.getTasks().get(0));
}
Also used : JobState(org.ow2.proactive.scheduler.common.job.JobState) JobId(org.ow2.proactive.scheduler.common.job.JobId)

Aggregations

JobState (org.ow2.proactive.scheduler.common.job.JobState)67 Test (org.junit.Test)34 JobId (org.ow2.proactive.scheduler.common.job.JobId)28 TaskState (org.ow2.proactive.scheduler.common.task.TaskState)25 Scheduler (org.ow2.proactive.scheduler.common.Scheduler)23 UnknownJobException (org.ow2.proactive.scheduler.common.exception.UnknownJobException)19 NotConnectedException (org.ow2.proactive.scheduler.common.exception.NotConnectedException)17 PermissionException (org.ow2.proactive.scheduler.common.exception.PermissionException)17 UnknownJobRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.UnknownJobRestException)15 ArrayList (java.util.ArrayList)14 NotConnectedRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException)14 PermissionRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException)14 GET (javax.ws.rs.GET)13 Path (javax.ws.rs.Path)13 Produces (javax.ws.rs.Produces)13 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)13 File (java.io.File)12 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)9 ClientJobState (org.ow2.proactive.scheduler.job.ClientJobState)9 TaskStatesPage (org.ow2.proactive.scheduler.common.task.TaskStatesPage)8