Search in sources :

Example 66 with SchedulerException

use of org.quartz.SchedulerException in project midpoint by Evolveum.

the class TaskSynchronizer method synchronizeJobStores.

/**
     * Checks for consistency between Quartz job store and midPoint repository.
     * In case of conflict, the latter is taken as authoritative source.
     *
     * (For RAM Job Store, running this method at startup effectively means that tasks from midPoint repo are imported into Quartz job store.)
     *
     */
boolean synchronizeJobStores(OperationResult parentResult) {
    OperationResult result = parentResult.createSubresult(this.getClass().getName() + ".synchronizeJobStores");
    Scheduler scheduler = taskManager.getExecutionManager().getQuartzScheduler();
    LOGGER.info("Synchronizing Quartz job store with midPoint repository.");
    List<PrismObject<TaskType>> tasks;
    try {
        tasks = getRepositoryService().searchObjects(TaskType.class, new ObjectQuery(), null, result);
    } catch (SchemaException | RuntimeException e) {
        LoggingUtils.logUnexpectedException(LOGGER, "Synchronization cannot be done, because tasks cannot be listed from the repository.", e);
        return false;
    }
    LOGGER.trace("There are {} task(s) in repository", tasks.size());
    // check consistency of tasks present in repo
    Set<String> oidsInRepo = new HashSet<>();
    int processed = 0;
    int changed = 0;
    int errors = 0;
    for (PrismObject<TaskType> taskPrism : tasks) {
        if (taskPrism.getOid() == null) {
            LOGGER.error("Skipping task with no OID: {}", taskPrism);
            errors++;
            continue;
        }
        oidsInRepo.add(taskPrism.getOid());
        TaskQuartzImpl task;
        try {
            // in order for the task to be "fresh"
            task = (TaskQuartzImpl) taskManager.getTask(taskPrism.getOid(), result);
            if (synchronizeTask(task, result)) {
                // todo are we sure that we increment this counter only for successfully processed tasks? we hope so :)
                changed++;
            }
        } catch (SchemaException e) {
            LoggingUtils.logUnexpectedException(LOGGER, "Task Manager cannot synchronize task {} due to schema exception.", e, taskPrism.getOid());
        } catch (ObjectNotFoundException e) {
            LoggingUtils.logException(LOGGER, "Task Manager cannot synchronize task {} because it does not exist", e, taskPrism.getOid());
        }
        if (result.getLastSubresultStatus() == OperationResultStatus.SUCCESS) {
            processed++;
        } else {
            errors++;
        }
    }
    // remove non-existing tasks
    int removed = 0;
    Set<JobKey> jobs = null;
    try {
        jobs = new HashSet<>(scheduler.getJobKeys(jobGroupEquals(JobKey.DEFAULT_GROUP)));
    } catch (SchedulerException e) {
        String message = "Cannot list jobs from Quartz scheduler, skipping second part of synchronization procedure.";
        LoggingUtils.logUnexpectedException(LOGGER, message, e);
        result.recordPartialError(message, e);
    }
    if (jobs != null) {
        LOGGER.trace("There are {} job(s) in Quartz job store", jobs.size());
        for (JobKey job : jobs) {
            if (!oidsInRepo.contains(job.getName()) && !RemoteNodesManager.STARTER_JOB_KEY.equals(job)) {
                LOGGER.info("Task " + job.getName() + " is not in repository, removing from Quartz job store.");
                try {
                    scheduler.deleteJob(job);
                    removed++;
                } catch (SchedulerException e) {
                    String message = "Cannot remove job " + job.getName() + " from Quartz job store";
                    LoggingUtils.logUnexpectedException(LOGGER, message, e);
                    result.createSubresult("deleteQuartzJob").recordPartialError(message, e);
                    errors++;
                }
            }
        }
    }
    String resultMessage = "Synchronization of midpoint and Quartz task store finished. " + processed + " task(s) existing in midPoint repository successfully processed, resulting in " + changed + " updated Quartz job(s). " + removed + " task(s) removed from Quartz job store. Processing of " + errors + " task(s) failed.";
    LOGGER.info(resultMessage);
    if (result.isUnknown()) {
        result.recordStatus(OperationResultStatus.SUCCESS, resultMessage);
    }
    return true;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) SchedulerException(org.quartz.SchedulerException) Scheduler(org.quartz.Scheduler) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) PrismObject(com.evolveum.midpoint.prism.PrismObject) JobKey(org.quartz.JobKey) TaskType(com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType) TaskQuartzImpl(com.evolveum.midpoint.task.quartzimpl.TaskQuartzImpl) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) HashSet(java.util.HashSet)

Example 67 with SchedulerException

use of org.quartz.SchedulerException in project midpoint by Evolveum.

the class TestQuartzTaskManagerContract method test015DeleteTaskFromRepo.

@Test(enabled = true)
public void test015DeleteTaskFromRepo() throws Exception {
    final String test = "015DeleteTaskFromRepo";
    final OperationResult result = createResult(test);
    PrismObject<? extends ObjectType> object = addObjectFromFile(taskFilename(test));
    String oid = taskOid(test);
    // is the task in Quartz?
    final JobKey key = TaskQuartzImplUtil.createJobKeyForTaskOid(oid);
    AssertJUnit.assertTrue("Job in Quartz does not exist", taskManager.getExecutionManager().getQuartzScheduler().checkExists(key));
    // Remove task from repo
    repositoryService.deleteObject(TaskType.class, taskOid(test), result);
    // We need to wait for a sync interval, so the task scanner has a chance
    // to pick up this task
    waitFor("Waiting for the job to disappear from Quartz Job Store", new Checker() {

        public boolean check() throws ObjectNotFoundException, SchemaException {
            try {
                return !taskManager.getExecutionManager().getQuartzScheduler().checkExists(key);
            } catch (SchedulerException e) {
                throw new SystemException(e);
            }
        }

        @Override
        public void timeout() {
        }
    }, 10000, 2000);
}
Also used : JobKey(org.quartz.JobKey) Checker(com.evolveum.midpoint.test.Checker) SchedulerException(org.quartz.SchedulerException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test)

Example 68 with SchedulerException

use of org.quartz.SchedulerException in project ddf by codice.

the class QueryJob method execute.

@Override
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
    LOGGER.trace("Calling execute");
    LOCK.lock();
    try {
        SchedulerContext schedulerContext = jobExecutionContext.getScheduler().getContext();
        WorkspaceQueryService workspaceQueryService = (WorkspaceQueryService) schedulerContext.get(WorkspaceQueryServiceImpl.JOB_IDENTITY);
        workspaceQueryService.run();
    } catch (SchedulerException e) {
        LOGGER.warn("Could not get Scheduler Context.  The job will not run", e);
    } finally {
        LOCK.unlock();
    }
}
Also used : WorkspaceQueryService(org.codice.ddf.catalog.ui.query.monitor.api.WorkspaceQueryService) SchedulerException(org.quartz.SchedulerException) SchedulerContext(org.quartz.SchedulerContext)

Example 69 with SchedulerException

use of org.quartz.SchedulerException in project searchcode-server by boyter.

the class JobService method startIndexSvnRepoJobs.

/**
     * Creates a svn repo indexer job which will pull from the list of git repositories and start
     * indexing them
     */
public void startIndexSvnRepoJobs(String uniquename) {
    try {
        Scheduler scheduler = Singleton.getScheduler();
        JobDetail job = newJob(IndexSvnRepoJob.class).withIdentity("updateindex-svn-" + uniquename).build();
        SimpleTrigger trigger = newTrigger().withIdentity("updateindex-svn-" + uniquename).withSchedule(simpleSchedule().withIntervalInSeconds(this.INDEXTIME).repeatForever()).build();
        job.getJobDataMap().put("REPOLOCATIONS", this.REPOLOCATION);
        job.getJobDataMap().put("LOWMEMORY", this.LOWMEMORY);
        scheduler.scheduleJob(job, trigger);
        scheduler.start();
    } catch (SchedulerException ex) {
        Singleton.getLogger().severe(" caught a " + ex.getClass() + "\n with message: " + ex.getMessage());
    }
}
Also used : JobDetail(org.quartz.JobDetail) SchedulerException(org.quartz.SchedulerException) Scheduler(org.quartz.Scheduler) SimpleTrigger(org.quartz.SimpleTrigger)

Example 70 with SchedulerException

use of org.quartz.SchedulerException in project searchcode-server by boyter.

the class Singleton method getScheduler.

public static synchronized Scheduler getScheduler() {
    try {
        if (scheduler == null || scheduler.isShutdown()) {
            try {
                SchedulerFactory sf = new StdSchedulerFactory();
                scheduler = sf.getScheduler();
            } catch (SchedulerException ex) {
                Singleton.getLogger().severe(" caught a " + ex.getClass() + "\n with message: " + ex.getMessage());
            }
        }
    } catch (SchedulerException e) {
    }
    return scheduler;
}
Also used : StdSchedulerFactory(org.quartz.impl.StdSchedulerFactory) SchedulerException(org.quartz.SchedulerException) StdSchedulerFactory(org.quartz.impl.StdSchedulerFactory) SchedulerFactory(org.quartz.SchedulerFactory)

Aggregations

SchedulerException (org.quartz.SchedulerException)133 JobDetail (org.quartz.JobDetail)59 Trigger (org.quartz.Trigger)42 Scheduler (org.quartz.Scheduler)37 JobKey (org.quartz.JobKey)33 SimpleTrigger (org.quartz.SimpleTrigger)19 JobDataMap (org.quartz.JobDataMap)18 CronTrigger (org.quartz.CronTrigger)17 TriggerBuilder.newTrigger (org.quartz.TriggerBuilder.newTrigger)15 ApplicationContext (org.springframework.context.ApplicationContext)15 ArrayList (java.util.ArrayList)12 SchedulerContext (org.quartz.SchedulerContext)12 IOException (java.io.IOException)11 TriggerKey (org.quartz.TriggerKey)10 Date (java.util.Date)9 JobExecutionException (org.quartz.JobExecutionException)9 StdSchedulerFactory (org.quartz.impl.StdSchedulerFactory)6 ParseException (java.text.ParseException)5 Command (org.openhab.core.types.Command)5 JobSystemException (com.dangdang.ddframe.job.exception.JobSystemException)4