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;
}
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);
}
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();
}
}
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());
}
}
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;
}
Aggregations