Search in sources :

Example 66 with JobInfo

use of org.ow2.proactive.scheduler.common.job.JobInfo 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 67 with JobInfo

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

the class JobResultDecorator method jobRunningToFinishedEvent.

@Override
protected void jobRunningToFinishedEvent(NotificationData<JobInfo> event) {
    super.jobRunningToFinishedEvent(event);
    JobId jobId = event.getData().getJobId();
    if (!this.mapOfJobs.containsKey(jobId)) {
        logger.trace("We are not waiting for the result of job ID " + jobId);
        return;
    }
    logger.trace("Trying to get the job result for job " + jobId);
    try {
        logger.info("The result for job with ID " + jobId + " is " + this.daddy.getJobResult(jobId));
    } catch (SchedulerException e) {
        logger.error("Cannot get the job result for job with id " + jobId + " from the scheduler", e);
    }
    // we have the result => stop monitoring this job
    this.stopMonitoring(jobId);
}
Also used : SchedulerException(org.ow2.proactive.scheduler.common.exception.SchedulerException) JobId(org.ow2.proactive.scheduler.common.job.JobId)

Example 68 with JobInfo

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

Example 69 with JobInfo

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

the class JobRemoveHandler method call.

@Override
public Boolean call() {
    boolean allJobsWereRemoved;
    try {
        long start = 0;
        if (jobIds.isEmpty()) {
            logger.info("No jobs to remove. You should not create JobRemoveHandler with empty list of ids.");
            return false;
        }
        if (logger.isInfoEnabled()) {
            start = System.currentTimeMillis();
            logger.info("Removing jobs " + jobIds.stream().map(JobId::value).collect(Collectors.joining(", ")));
        }
        SchedulerDBManager dbManager = service.getInfrastructure().getDBManager();
        List<InternalJob> jobs = dbManager.loadJobWithTasksIfNotRemoved(jobIds.toArray(new JobId[0]));
        List<JobId> dbJobsIds = jobs.stream().map(InternalJob::getId).collect(Collectors.toList());
        long removedTime = System.currentTimeMillis();
        List<JobId> aliveJobsIds = jobs.stream().filter(job -> !isInFinishedState(job)).map(InternalJob::getId).collect(Collectors.toList());
        if (aliveJobsIds.size() > 0) {
            TerminationData terminationData = service.getJobs().killJobs(aliveJobsIds);
            service.submitTerminationDataHandler(terminationData);
        }
        for (InternalJob job : jobs) {
            job.setRemovedTime(removedTime);
        }
        boolean removeFromDb = PASchedulerProperties.JOB_REMOVE_FROM_DB.getValueAsBoolean();
        Set<String> updatedParentIds = dbManager.removeJob(dbJobsIds, removedTime, removeFromDb);
        if (!updatedParentIds.isEmpty()) {
            // If parent jobs' children count have been modified, we need to send a JOB_UPDATED notification
            List<JobInfo> parentJobsInfo = dbManager.getJobs(updatedParentIds.stream().collect(Collectors.toList()));
            for (JobInfo parentJobInfo : parentJobsInfo) {
                service.getListener().jobStateUpdated(parentJobInfo.getJobOwner(), new NotificationData<>(SchedulerEvent.JOB_UPDATED, parentJobInfo));
            }
        }
        for (InternalJob job : jobs) {
            ServerJobAndTaskLogs.getInstance().remove(job.getId(), job.getOwner(), job.getCredentials());
            if (logger.isInfoEnabled()) {
                logger.info("Job " + job.getId() + " removed in " + (System.currentTimeMillis() - start) + "ms");
            }
            // send event to front-end
            service.getListener().jobStateUpdated(job.getOwner(), new NotificationData<>(SchedulerEvent.JOB_REMOVE_FINISHED, new JobInfoImpl((JobInfoImpl) job.getJobInfo())));
        }
        allJobsWereRemoved = dbJobsIds.size() == jobIds.size();
        service.wakeUpSchedulingThread();
    } catch (Exception e) {
        logger.error("Error while removing list of jobs (" + jobIds.stream().map(JobId::value).collect(Collectors.joining(", ")) + ") due to : " + e.getMessage(), e);
        throw e;
    }
    return allJobsWereRemoved;
}
Also used : InternalJob(org.ow2.proactive.scheduler.job.InternalJob) SchedulerDBManager(org.ow2.proactive.scheduler.core.db.SchedulerDBManager) JobInfo(org.ow2.proactive.scheduler.common.job.JobInfo) JobInfoImpl(org.ow2.proactive.scheduler.job.JobInfoImpl) JobId(org.ow2.proactive.scheduler.common.job.JobId)

Example 70 with JobInfo

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

the class SchedulerFrontendState method jobStateUpdated.

@Override
public void jobStateUpdated(String owner, NotificationData<JobInfo> notification) {
    Lambda.withLock(stateWriteLock, () -> {
        if (notification.getEventType().equals(SchedulerEvent.JOB_REMOVE_FINISHED)) {
            // removing jobs from the global list : this job is no more managed
            schedulerState.removeFinished(notification.getData().getJobId());
            jobsMap.remove(notification.getData().getJobId());
            finishedJobsLRUCache.remove(notification.getData().getJobId());
            jobs.remove(notification.getData().getJobId());
            logger.debug("HOUSEKEEPING removed the finished job " + notification.getData().getJobId() + " from the SchedulerFrontEndState");
            return;
        }
        ClientJobState js = getClientJobState(notification.getData().getJobId());
        boolean withAttachment = false;
        if (js != null) {
            try {
                js.writeLock();
                js.update(notification.getData());
                switch(notification.getEventType()) {
                    case JOB_PENDING_TO_RUNNING:
                        schedulerState.pendingToRunning(js);
                        break;
                    case JOB_PAUSED:
                    case JOB_IN_ERROR:
                    case JOB_RESUMED:
                    case JOB_RESTARTED_FROM_ERROR:
                    case JOB_CHANGE_PRIORITY:
                    case TASK_REPLICATED:
                    case TASK_SKIPPED:
                    case JOB_UPDATED:
                        break;
                    case JOB_PENDING_TO_FINISHED:
                        schedulerState.pendingToFinished(js);
                        // set this job finished, user can get its result
                        jobs.remove(notification.getData().getJobId()).setFinished(true);
                        jobsMap.remove(notification.getData().getJobId());
                        withAttachment = true;
                        break;
                    case JOB_RUNNING_TO_FINISHED:
                        schedulerState.runningToFinished(js);
                        // set this job finished, user can get its result
                        jobs.remove(notification.getData().getJobId()).setFinished(true);
                        jobsMap.remove(notification.getData().getJobId());
                        withAttachment = true;
                        break;
                    default:
                        logger.warn("**WARNING** - Unconsistent update type received from Scheduler Core : " + notification.getEventType());
                        return;
                }
                new JobEmailNotification(js, notification, dbManager).checkAndSendAsync(withAttachment);
            } finally {
                js.writeUnlock();
            }
        }
    });
    dispatchJobStateUpdated(owner, notification);
}
Also used : ClientJobState(org.ow2.proactive.scheduler.job.ClientJobState)

Aggregations

JobInfo (org.ow2.proactive.scheduler.common.job.JobInfo)47 JobId (org.ow2.proactive.scheduler.common.job.JobId)29 Test (org.junit.Test)26 ArrayList (java.util.ArrayList)12 InternalJob (org.ow2.proactive.scheduler.job.InternalJob)12 JobInfoImpl (org.ow2.proactive.scheduler.job.JobInfoImpl)11 Scheduler (org.ow2.proactive.scheduler.common.Scheduler)10 JobState (org.ow2.proactive.scheduler.common.job.JobState)10 TaskInfo (org.ow2.proactive.scheduler.common.task.TaskInfo)10 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)9 TaskState (org.ow2.proactive.scheduler.common.task.TaskState)9 Job (org.ow2.proactive.scheduler.common.job.Job)8 TaskId (org.ow2.proactive.scheduler.common.task.TaskId)8 TaskInfoImpl (org.ow2.proactive.scheduler.task.TaskInfoImpl)8 File (java.io.File)7 NotConnectedException (org.ow2.proactive.scheduler.common.exception.NotConnectedException)7 PermissionException (org.ow2.proactive.scheduler.common.exception.PermissionException)7 JobResult (org.ow2.proactive.scheduler.common.job.JobResult)7 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)7 InternalTask (org.ow2.proactive.scheduler.task.internal.InternalTask)7