use of org.quartz.JobExecutionException in project candlepin by candlepin.
the class HealEntireOrgJob method toExecute.
@Override
public void toExecute(JobExecutionContext ctx) throws JobExecutionException {
try {
// NOTE: ownerId is actually the owner key here.
JobDataMap map = ctx.getMergedJobDataMap();
String ownerId = (String) map.get("ownerId");
Owner owner = ownerCurator.lookupByKey(ownerId);
if (owner.isAutobindDisabled()) {
throw new BadRequestException(i18n.tr("Auto-attach is disabled for owner {0}.", owner.getKey()));
}
Date entitleDate = (Date) map.get("entitle_date");
for (String uuid : ownerCurator.getConsumerUuids(owner).list()) {
// of looking up the non or partially compliant products to bind.
try {
Consumer consumer = consumerCurator.getConsumer(uuid);
healSingleConsumer(consumer, owner, entitleDate);
}// Perhaps add something to surface errors later
catch (Exception e) {
log.debug("Healing failed for UUID \"{}\" with message: {}", uuid, e.getMessage());
}
}
} catch (Exception e) {
log.error("EntitlerJob encountered a problem.", e);
ctx.setResult(e.getMessage());
throw new JobExecutionException(e.getMessage(), e, false);
}
}
use of org.quartz.JobExecutionException in project candlepin by candlepin.
the class ImportJob method toExecute.
@Override
public void toExecute(JobExecutionContext context) throws JobExecutionException {
JobDataMap map = context.getMergedJobDataMap();
String ownerKey = (String) map.get(JobStatus.TARGET_ID);
ConflictOverrides overrides = new ConflictOverrides((String[]) map.get(CONFLICT_OVERRIDES));
String storedFileId = (String) map.get(STORED_FILE_ID);
String uploadedFileName = (String) map.get(UPLOADED_FILE_NAME);
Throwable caught = null;
Owner targetOwner = null;
try {
targetOwner = ownerCurator.lookupByKey(ownerKey);
if (targetOwner == null) {
throw new NotFoundException(String.format("Owner %s was not found.", ownerKey));
}
ImportRecord importRecord = manifestManager.importStoredManifest(targetOwner, storedFileId, overrides, uploadedFileName);
context.setResult(importRecord);
}// info about the exception that was thrown (CandlepinException).
catch (SyncDataFormatException e) {
caught = new BadRequestException(e.getMessage(), e);
} catch (ImporterException e) {
caught = new IseException(e.getMessage(), e);
} catch (Exception e) {
caught = e;
}
if (caught != null) {
log.error("ImportJob encountered a problem.", caught);
manifestManager.recordImportFailure(targetOwner, caught, uploadedFileName);
context.setResult(caught.getMessage());
// If an exception was thrown, the importer's transaction was rolled
// back. We want to make sure that the file gets deleted so that it
// doesn't take up disk space. It may be possible that the file was
// already deleted, but we attempt it anyway.
manifestManager.deleteStoredManifest(storedFileId);
throw new JobExecutionException(caught.getMessage(), caught, false);
}
}
use of org.quartz.JobExecutionException in project candlepin by candlepin.
the class PinsetterKernel method unpauseScheduler.
public void unpauseScheduler() throws PinsetterException {
log.debug("looking for canceled jobs since scheduler was paused");
CancelJobJob cjj = new CancelJobJob(jobCurator, this);
try {
// Not sure why we don't want to use a UnitOfWork here
cjj.toExecute(null);
} catch (JobExecutionException e1) {
throw new PinsetterException("Could not clear canceled jobs before starting");
}
log.debug("restarting scheduler");
try {
scheduler.start();
} catch (SchedulerException e) {
throw new PinsetterException("There was a problem unpausing the scheduler", e);
}
}
use of org.quartz.JobExecutionException in project candlepin by candlepin.
the class HypervisorUpdateJobTest method ensureJobFailsWhenAutobindDisabledForTargetOwner.
@Test
public void ensureJobFailsWhenAutobindDisabledForTargetOwner() throws Exception {
// Disabled autobind
when(owner.isAutobindDisabled()).thenReturn(true);
when(ownerCurator.lookupByKey(eq("joe"))).thenReturn(owner);
JobDetail detail = HypervisorUpdateJob.forOwner(owner, hypervisorJson, true, principal, null);
JobExecutionContext ctx = mock(JobExecutionContext.class);
when(ctx.getMergedJobDataMap()).thenReturn(detail.getJobDataMap());
when(consumerCurator.getHostConsumersMap(eq(owner), any(Set.class))).thenReturn(new VirtConsumerMap());
HypervisorUpdateJob job = new HypervisorUpdateJob(ownerCurator, consumerCurator, consumerTypeCurator, consumerResource, i18n, subAdapter, complianceRules);
injector.injectMembers(job);
try {
job.execute(ctx);
fail("Expected exception due to autobind being disabled.");
} catch (JobExecutionException jee) {
assertEquals(jee.getCause().getMessage(), "Could not update host/guest mapping. Auto-attach is disabled for owner joe.");
}
}
use of org.quartz.JobExecutionException in project candlepin by candlepin.
the class RefreshPoolsJobTest method refireOnWrappedSQLException.
// If we encounter a runtime job exception, wrapping a SQLException, we should see
// a refire job exception thrown:
@Test
public void refireOnWrappedSQLException() throws JobExecutionException {
RuntimeException e = new RuntimeException("uh oh", new SQLException("not good"));
doThrow(e).when(refresher).run();
RefreshPoolsJob rpj = new RefreshPoolsJob(oc, pm, subAdapter, ownerAdapter);
injector.injectMembers(rpj);
try {
rpj.execute(ctx);
fail("Expected exception not thrown");
} catch (JobExecutionException ex) {
assertTrue(ex.refireImmediately());
}
}
Aggregations