Search in sources :

Example 6 with SchedulerEvent

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

the class LiveJobs method killJobs.

/**
 * @param jobIds terminated jobs with given id
 * @return return TerminationData which is than used to kill all running tasks
 */
public TerminationData killJobs(List<JobId> jobIds) {
    jobIds.forEach(jobId -> jlogger.info(jobId, "killing job"));
    List<JobData> jobDatas = lockJobs(jobIds);
    if (jobDatas == null || jobDatas.isEmpty()) {
        return TerminationData.EMPTY;
    }
    try {
        TaskResultImpl taskResult = null;
        JobStatus jobStatus = JobStatus.KILLED;
        Set<TaskId> tasksToUpdate = new HashSet<>();
        TerminationData terminationData = TerminationData.newTerminationData();
        for (JobData jobData : jobDatas) {
            JobId jobId = jobData.job.getId();
            jobs.remove(jobId);
            terminationData.addJobToTerminate(jobId, jobData.job.getGenericInformation(), jobData.job.getCredentials());
            InternalJob job = jobData.job;
            jlogger.info(job.getId(), "ending request");
            for (Iterator<RunningTaskData> i = runningTasksData.values().iterator(); i.hasNext(); ) {
                RunningTaskData taskData = i.next();
                if (taskData.getTask().getJobId().equals(jobId)) {
                    i.remove();
                    // remove previous read progress
                    taskData.getTask().setProgress(0);
                    terminationData.addTaskData(job, taskData, TerminationData.TerminationStatus.ABORTED, taskResult);
                }
            }
            // if job has been killed
            tasksToUpdate.addAll(job.failed(null, jobStatus));
        }
        dbManager.killJobs(jobDatas.stream().map(jobData -> jobData.job).collect(Collectors.toList()));
        for (JobData jobData : jobDatas) {
            InternalJob job = jobData.job;
            updateTasksInSchedulerState(job, tasksToUpdate);
            SchedulerEvent event;
            if (job.getStatus() == JobStatus.PENDING) {
                event = SchedulerEvent.JOB_PENDING_TO_FINISHED;
            } else {
                event = SchedulerEvent.JOB_RUNNING_TO_FINISHED;
            }
            // Cleaning job signals
            cleanJobSignals(jobData.job.getId());
            // update job and tasks events list and send it to front-end
            updateJobInSchedulerState(job, event);
            jlogger.info(job.getId(), "finished (" + jobStatus + ")");
            jlogger.close(job.getId());
        }
        return terminationData;
    } finally {
        jobDatas.forEach(JobData::unlock);
    }
}
Also used : TaskId(org.ow2.proactive.scheduler.common.task.TaskId) InternalJob(org.ow2.proactive.scheduler.job.InternalJob) TaskResultImpl(org.ow2.proactive.scheduler.task.TaskResultImpl) SchedulerEvent(org.ow2.proactive.scheduler.common.SchedulerEvent) JobStatus(org.ow2.proactive.scheduler.common.job.JobStatus) JobId(org.ow2.proactive.scheduler.common.job.JobId)

Example 7 with SchedulerEvent

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

the class SchedulerMonitorsHandler method removeTaskEvent.

/**
 * Remove, if exist a TaskEventMonitor to the list of memorized tasks events
 * @param id
 * @param taskName
 * @param event
 * @return
 */
private TaskEventMonitor removeTaskEvent(JobId id, String taskName, SchedulerEvent event) {
    TaskEventMonitor tmp = new TaskEventMonitor(event, id, taskName);
    for (Entry<TaskIdWrapper, List<TaskEventMonitor>> entry : tasksEvents.entrySet()) {
        TaskId taskId = entry.getKey().getTaskId();
        List<TaskEventMonitor> value = entry.getValue();
        if (taskId.getJobId().equals(id) && taskId.getReadableName().equals(taskName) && value.contains(tmp)) {
            return value.remove(value.indexOf(tmp));
        }
    }
    return null;
}
Also used : TaskId(org.ow2.proactive.scheduler.common.task.TaskId) TaskIdWrapper(org.ow2.proactive.utils.TaskIdWrapper) ArrayList(java.util.ArrayList) List(java.util.List)

Example 8 with SchedulerEvent

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

the class SchedulerMonitorsHandler method addTaskEvent.

/**
 * Add a Task Event to the list of occurred events (memorize it).
 * @param event type of task event
 * @param taskInfo TaskEvent object associated to Event
 */
private void addTaskEvent(SchedulerEvent event, TaskInfo taskInfo) {
    TaskIdWrapper taskId = TaskIdWrapper.wrap(taskInfo.getTaskId());
    List<TaskEventMonitor> taskEventMonitors = tasksEvents.get(taskId);
    if (taskEventMonitors == null) {
        taskEventMonitors = new ArrayList<>();
        tasksEvents.put(taskId, taskEventMonitors);
    }
    taskEventMonitors.add(new TaskEventMonitor(event, taskInfo));
}
Also used : TaskIdWrapper(org.ow2.proactive.utils.TaskIdWrapper)

Example 9 with SchedulerEvent

use of org.ow2.proactive.scheduler.common.SchedulerEvent 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)

Example 10 with SchedulerEvent

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

the class MyEventListener method jobStateUpdatedEvent.

@Override
public void jobStateUpdatedEvent(NotificationData<JobInfo> notification) {
    System.out.println("MyEventListener.jobStateUpdatedEvent() " + notification);
    JobId id = notification.getData().getJobId();
    if (!id.equals(jobId))
        return;
    SchedulerEvent event = notification.getEventType();
    if (event == SchedulerEvent.JOB_RUNNING_TO_FINISHED) {
        jobFinished = true;
        if (synchronous) {
            synchronized (monitor) {
                System.out.println("[MyEventListener] job finished event occured for " + jobId);
                monitor.setEventOccured();
                monitor.notifyAll();
            }
        }
    }
}
Also used : JobId(org.ow2.proactive.scheduler.common.job.JobId) SchedulerEvent(org.ow2.proactive.scheduler.common.SchedulerEvent)

Aggregations

SchedulerEvent (org.ow2.proactive.scheduler.common.SchedulerEvent)5 JobId (org.ow2.proactive.scheduler.common.job.JobId)4 TaskId (org.ow2.proactive.scheduler.common.task.TaskId)3 JobStatus (org.ow2.proactive.scheduler.common.job.JobStatus)2 InternalJob (org.ow2.proactive.scheduler.job.InternalJob)2 TaskResultImpl (org.ow2.proactive.scheduler.task.TaskResultImpl)2 TaskIdWrapper (org.ow2.proactive.utils.TaskIdWrapper)2 AsyncHttpClient (com.ning.http.client.AsyncHttpClient)1 AsyncHttpClientConfig (com.ning.http.client.AsyncHttpClientConfig)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Semaphore (java.util.concurrent.Semaphore)1 MutableBoolean (org.apache.commons.lang3.mutable.MutableBoolean)1 Client (org.atmosphere.wasync.Client)1 Function (org.atmosphere.wasync.Function)1 RequestBuilder (org.atmosphere.wasync.RequestBuilder)1 Test (org.junit.Test)1 UniqueID (org.objectweb.proactive.core.UniqueID)1 NotificationData (org.ow2.proactive.scheduler.common.NotificationData)1