Search in sources :

Example 91 with JobState

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

the class SchedulerStateRestJobLogsTest method job_full_logs_not_finished.

@Test
public void job_full_logs_not_finished() throws Exception {
    InternalTaskFlowJob jobState = new InternalTaskFlowJob();
    jobState.addTask(new InternalScriptTask(jobState));
    when(mockScheduler.getJobState("123")).thenReturn(jobState);
    InputStream fullLogs = (InputStream) restScheduler.jobFullLogs(validSessionId, "123", validSessionId, null).getEntity();
    String logsString = IOUtils.toString(fullLogs);
    assertEquals("", logsString);
}
Also used : InternalScriptTask(org.ow2.proactive.scheduler.task.internal.InternalScriptTask) InputStream(java.io.InputStream) InternalTaskFlowJob(org.ow2.proactive.scheduler.job.InternalTaskFlowJob) Test(org.junit.Test)

Example 92 with JobState

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

the class SchedulerStateRestPaginationTest method testGetJobTasksIdsByTagPaginated.

@Test
public void testGetJobTasksIdsByTagPaginated() throws Throwable {
    JobState job = newMockedJob(jobIdStr, nbTasks);
    when(mockOfScheduler.getJobState(jobIdStr)).thenReturn(job);
    RestPage<String> page = restInterface.getTasksNamesPaginated(sessionId, jobIdStr, 0, nbTasks);
    assertTasks(nbTasks, jobIdStr, page);
}
Also used : JobState(org.ow2.proactive.scheduler.common.job.JobState) Test(org.junit.Test)

Example 93 with JobState

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

the class SchedulerStateRestPaginationTest method newMockedJob.

private JobState newMockedJob(final String jobIdStr, final int nbTasks) {
    JobState mockedJob = mock(JobState.class);
    JobId mockedJobId = mock(JobId.class);
    List<TaskState> dumbList = new ArrayList<TaskState>(nbTasks);
    for (int i = 0; i < nbTasks; i++) {
        TaskState mockedTask = mock(TaskState.class);
        TaskId mockedTaskId = mock(TaskId.class);
        when(mockedTaskId.getReadableName()).thenReturn(generateReadableName(jobIdStr, i, nbTasks));
        when(mockedTask.getId()).thenReturn(mockedTaskId);
        dumbList.add(mockedTask);
    }
    when(mockedJobId.value()).thenReturn(jobIdStr);
    when(mockedJob.getId()).thenReturn(mockedJobId);
    when(mockedJob.getTasksPaginated(0, 50)).thenReturn(new TaskStatesPage(dumbList, nbTasks));
    when(mockedJob.getTaskByTagPaginated("", 0, 50)).thenReturn(new TaskStatesPage(dumbList, nbTasks));
    return mockedJob;
}
Also used : TaskId(org.ow2.proactive.scheduler.common.task.TaskId) ArrayList(java.util.ArrayList) JobState(org.ow2.proactive.scheduler.common.job.JobState) TaskStatesPage(org.ow2.proactive.scheduler.common.task.TaskStatesPage) TaskState(org.ow2.proactive.scheduler.common.task.TaskState) JobId(org.ow2.proactive.scheduler.common.job.JobId)

Example 94 with JobState

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

the class RestTestUtils method newMockedJob.

protected static JobState newMockedJob(final String jobIdStr, final String tag, final int nbTasks) {
    JobState mockedJob = mock(JobState.class);
    JobId mockedJobId = mock(JobId.class);
    JobInfo mockedJobInfo = mock(JobInfo.class);
    List<TaskState> dumbList = new ArrayList<TaskState>(nbTasks);
    for (int i = 0; i < nbTasks; i++) {
        dumbList.add(newTaskState(jobIdStr, null, i, nbTasks));
    }
    when(mockedJobId.value()).thenReturn(jobIdStr);
    when(mockedJobInfo.getJobId()).thenReturn(mockedJobId);
    when(mockedJobInfo.getStatus()).thenReturn(JobStatus.PENDING);
    when(mockedJob.getId()).thenReturn(mockedJobId);
    when(mockedJob.getTasksPaginated(0, 50)).thenReturn(new TaskStatesPage(dumbList, nbTasks));
    when(mockedJob.getTaskByTagPaginated("", 0, 50)).thenReturn(new TaskStatesPage(dumbList, nbTasks));
    when(mockedJob.getJobInfo()).thenReturn(mockedJobInfo);
    return mockedJob;
}
Also used : JobInfo(org.ow2.proactive.scheduler.common.job.JobInfo) ArrayList(java.util.ArrayList) JobState(org.ow2.proactive.scheduler.common.job.JobState) TaskStatesPage(org.ow2.proactive.scheduler.common.task.TaskStatesPage) TaskState(org.ow2.proactive.scheduler.common.task.TaskState) JobId(org.ow2.proactive.scheduler.common.job.JobId)

Example 95 with JobState

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

the class RestSmartProxyTest method testInErrorEventsReception.

@Test(timeout = TEN_MINUTES)
public void testInErrorEventsReception() throws Exception {
    System.out.println("Begin testInErrorEventsReception ");
    TaskFlowJob job = createInErrorJob();
    final Semaphore semaphore = new Semaphore(0);
    printJobXmlRepresentation(job);
    final MutableBoolean taskHasBeenInError = new MutableBoolean(false);
    final MutableBoolean taskMarkedAsFinished = new MutableBoolean(false);
    SchedulerEventListenerExtended listener = new SchedulerEventListenerExtended() {

        @Override
        public void schedulerStateUpdatedEvent(SchedulerEvent eventType) {
            System.out.println("RestSmartProxyTest.schedulerStateUpdatedEvent " + eventType);
        }

        @Override
        public void jobSubmittedEvent(JobState job) {
            System.out.println("RestSmartProxyTest.jobSubmittedEvent");
        }

        @Override
        public void jobStateUpdatedEvent(NotificationData<JobInfo> notification) {
            JobStatus status = notification.getData().getStatus();
            System.out.println("RestSmartProxyTest.jobStateUpdatedEvent, eventType=" + notification.getEventType() + ", jobStatus=" + status);
            if (status == JobStatus.IN_ERROR) {
                semaphore.release();
            }
        }

        @Override
        public void taskStateUpdatedEvent(NotificationData<TaskInfo> notification) {
            TaskStatus status = notification.getData().getStatus();
            System.out.println("RestSmartProxyTest.taskStateUpdatedEvent, taskStatus=" + status);
            if (status == TaskStatus.WAITING_ON_ERROR || status == TaskStatus.IN_ERROR) {
                // IN_ERROR previously
                taskHasBeenInError.setTrue();
            }
            if (status == TaskStatus.FINISHED && taskHasBeenInError.isTrue()) {
                taskMarkedAsFinished.setTrue();
            }
        }

        @Override
        public void usersUpdatedEvent(NotificationData<UserIdentification> notification) {
            System.out.println("RestSmartProxyTest.usersUpdatedEvent " + notification.getData());
        }

        @Override
        public void pullDataFinished(String jobId, String taskName, String localFolderPath) {
            System.out.println("RestSmartProxyTest.pullDataFinished");
        }

        @Override
        public void pullDataFailed(String jobId, String taskName, String remoteFolder_URL, Throwable t) {
            System.out.println("RestSmartProxyTest.pullDataFailed");
        }

        @Override
        public void jobUpdatedFullDataEvent(JobState job) {
            System.out.println("RestSmartProxyTest.jobUpdatedFullDataEvent");
        }
    };
    restSmartProxy.addEventListener(listener);
    JobId jobId = restSmartProxy.submit(job, inputLocalFolder.getAbsolutePath(), outputLocalFolder.getAbsolutePath(), false, false);
    // the next line blocks until jobStateUpdatedEvent is called on the
    // listener
    // with job status set to IN_ERROR
    semaphore.acquire();
    String jobIdAsString = jobId.value();
    System.out.println("Finish in-error task");
    restSmartProxy.finishInErrorTask(jobIdAsString, inerrorTaskName);
    waitForJobFinishState(jobIdAsString);
    assertThat(taskHasBeenInError.booleanValue()).isTrue();
    assertThat(taskMarkedAsFinished.booleanValue()).isTrue();
    System.out.println("End testInErrorEventsReception");
}
Also used : JobStatus(org.ow2.proactive.scheduler.common.job.JobStatus) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) JobState(org.ow2.proactive.scheduler.common.job.JobState) SchedulerEventListenerExtended(org.ow2.proactive.scheduler.smartproxy.common.SchedulerEventListenerExtended) Semaphore(java.util.concurrent.Semaphore) TaskStatus(org.ow2.proactive.scheduler.common.task.TaskStatus) JobId(org.ow2.proactive.scheduler.common.job.JobId) SchedulerEvent(org.ow2.proactive.scheduler.common.SchedulerEvent) NotificationData(org.ow2.proactive.scheduler.common.NotificationData) Test(org.junit.Test)

Aggregations

JobState (org.ow2.proactive.scheduler.common.job.JobState)75 Test (org.junit.Test)44 JobId (org.ow2.proactive.scheduler.common.job.JobId)36 Scheduler (org.ow2.proactive.scheduler.common.Scheduler)30 TaskState (org.ow2.proactive.scheduler.common.task.TaskState)26 UnknownJobException (org.ow2.proactive.scheduler.common.exception.UnknownJobException)21 File (java.io.File)20 NotConnectedException (org.ow2.proactive.scheduler.common.exception.NotConnectedException)19 PermissionException (org.ow2.proactive.scheduler.common.exception.PermissionException)19 ArrayList (java.util.ArrayList)18 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)16 UnknownJobRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.UnknownJobRestException)14 GET (javax.ws.rs.GET)13 Path (javax.ws.rs.Path)13 Produces (javax.ws.rs.Produces)13 ClientJobState (org.ow2.proactive.scheduler.job.ClientJobState)13 NotConnectedRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException)13 PermissionRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException)13 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)10 TaskStatesPage (org.ow2.proactive.scheduler.common.task.TaskStatesPage)10