Search in sources :

Example 21 with SchedulerDBManager

use of org.ow2.proactive.scheduler.core.db.SchedulerDBManager in project scheduling by ow2-proactive.

the class SchedulerStateRecoverHelperTest method testRecoverWithIncorrectStatusForLoadedNotFinishedJobs.

public void testRecoverWithIncorrectStatusForLoadedNotFinishedJobs(JobStatus jobStatus) {
    InternalJob job = new InternalTaskFlowJob();
    job.setStatus(jobStatus);
    SchedulerDBManager dbManager = Mockito.mock(SchedulerDBManager.class);
    SchedulerStateRecoverHelper stateRecoverHelper = new SchedulerStateRecoverHelper(dbManager);
    Mockito.when(dbManager.loadNotFinishedJobs(true)).thenReturn(ImmutableList.of(job));
    stateRecoverHelper.recover(-1);
}
Also used : InternalJob(org.ow2.proactive.scheduler.job.InternalJob) SchedulerDBManager(org.ow2.proactive.scheduler.core.db.SchedulerDBManager) SchedulerStateRecoverHelper(org.ow2.proactive.scheduler.core.db.SchedulerStateRecoverHelper) InternalTaskFlowJob(org.ow2.proactive.scheduler.job.InternalTaskFlowJob)

Example 22 with SchedulerDBManager

use of org.ow2.proactive.scheduler.core.db.SchedulerDBManager in project scheduling by ow2-proactive.

the class JobRemoveHandler method call.

@Override
public Boolean call() {
    long start = 0;
    if (logger.isInfoEnabled()) {
        start = System.currentTimeMillis();
        logger.info("Removing job " + jobId);
    }
    SchedulerDBManager dbManager = service.getInfrastructure().getDBManager();
    List<InternalJob> jobs = dbManager.loadJobWithTasksIfNotRemoved(jobId);
    TerminationData terminationData;
    // if the context is not in sync with the database
    if (jobs.size() != 1) {
        terminationData = service.getJobs().removeJob(jobId);
    } else {
        // if the job was already finished we just remove it from the context
        if (isInFinishedState(jobs.get(0))) {
            terminationData = service.getJobs().removeJob(jobId);
        } else {
            terminationData = service.getJobs().killJob(jobId);
        }
    }
    service.submitTerminationDataHandler(terminationData);
    // if the job doesn't exist in the DB anymore we can stop here
    if (jobs.size() != 1) {
        return false;
    }
    jobs.get(0).setRemovedTime(System.currentTimeMillis());
    boolean removeFromDb = PASchedulerProperties.JOB_REMOVE_FROM_DB.getValueAsBoolean();
    dbManager.removeJob(jobId, jobs.get(0).getRemovedTime(), removeFromDb);
    ServerJobAndTaskLogs.remove(jobId);
    if (logger.isInfoEnabled()) {
        logger.info("Job " + jobId + " removed in " + (System.currentTimeMillis() - start) + "ms");
    }
    // send event to front-end
    service.getListener().jobStateUpdated(jobs.get(0).getOwner(), new NotificationData<JobInfo>(SchedulerEvent.JOB_REMOVE_FINISHED, new JobInfoImpl((JobInfoImpl) jobs.get(0).getJobInfo())));
    service.wakeUpSchedulingThread();
    return true;
}
Also used : InternalJob(org.ow2.proactive.scheduler.job.InternalJob) JobInfo(org.ow2.proactive.scheduler.common.job.JobInfo) SchedulerDBManager(org.ow2.proactive.scheduler.core.db.SchedulerDBManager) JobInfoImpl(org.ow2.proactive.scheduler.job.JobInfoImpl)

Aggregations

SchedulerDBManager (org.ow2.proactive.scheduler.core.db.SchedulerDBManager)18 Test (org.junit.Test)14 HashMap (java.util.HashMap)9 JobId (org.ow2.proactive.scheduler.common.job.JobId)9 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)9 TaskId (org.ow2.proactive.scheduler.common.task.TaskId)8 InternalJob (org.ow2.proactive.scheduler.job.InternalJob)8 TaskResultImpl (org.ow2.proactive.scheduler.task.TaskResultImpl)8 List (java.util.List)7 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)3 ProActiveTest (org.ow2.tests.ProActiveTest)3 File (java.io.File)2 Map (java.util.Map)2 Configuration (org.hibernate.cfg.Configuration)2 Before (org.junit.Before)2 SchedulerStateRecoverHelper (org.ow2.proactive.scheduler.core.db.SchedulerStateRecoverHelper)2 JobDescriptorImpl (org.ow2.proactive.scheduler.descriptor.JobDescriptorImpl)2 InternalTask (org.ow2.proactive.scheduler.task.internal.InternalTask)2 ImmutableList (com.google.common.collect.ImmutableList)1 KeyException (java.security.KeyException)1