use of org.quartz.JobExecutionException in project candlepin by candlepin.
the class PinsetterJobListenerTest method handleException.
@Test
public void handleException() {
JobExecutionException e = mock(JobExecutionException.class);
JobDetail detail = mock(JobDetail.class);
JobStatus status = mock(JobStatus.class);
when(detail.getKey()).thenReturn(jobKey("foo"));
when(ctx.getJobDetail()).thenReturn(detail);
when(jcurator.find(eq("foo"))).thenReturn(status);
when(e.getMessage()).thenReturn("job errored");
listener.jobWasExecuted(ctx, e);
verify(status).setState(eq(JobState.FAILED));
verify(status).setResult(eq("job errored"));
verify(status, never()).update(eq(ctx));
verify(jcurator).merge(eq(status));
}
use of org.quartz.JobExecutionException in project candlepin by candlepin.
the class RefreshPoolsJobTest method refireOnMultiLayerWrappedSQLException.
// If we encounter a runtime job exception, wrapping a SQLException, we should see
// a refire job exception thrown:
@Test
public void refireOnMultiLayerWrappedSQLException() throws JobExecutionException {
RuntimeException e = new RuntimeException("uh oh", new SQLException("not good"));
RuntimeException e2 = new RuntimeException("trouble!", e);
doThrow(e2).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());
}
}
use of org.quartz.JobExecutionException in project candlepin by candlepin.
the class EntitlerJob method toExecute.
@Override
public void toExecute(JobExecutionContext ctx) throws JobExecutionException {
try {
JobDataMap map = ctx.getMergedJobDataMap();
String uuid = (String) map.get(JobStatus.TARGET_ID);
PoolIdAndQuantity[] poolQuantities = (PoolIdAndQuantity[]) map.get("pool_and_quantities");
Map<String, Integer> poolMap = new HashMap<>();
for (PoolIdAndQuantity poolIdAndQuantity : poolQuantities) {
poolMap.put(poolIdAndQuantity.getPoolId(), poolIdAndQuantity.getQuantity());
}
List<Entitlement> ents = entitler.bindByPoolQuantities(uuid, poolMap);
entitler.sendEvents(ents);
PoolIdAndQuantity[] consumed = new PoolIdAndQuantity[ents.size()];
for (int i = 0; i < ents.size(); i++) {
consumed[i] = new PoolIdAndQuantity(ents.get(i).getPool().getId(), ents.get(i).getQuantity());
}
ctx.setResult(Arrays.asList(consumed));
poolCurator.clear();
} catch (EntitlementRefusedException e) {
log.error("EntitlerJob encountered a problem, translating errors", e);
Map<String, ValidationResult> validationResults = e.getResults();
EntitlementRulesTranslator translator = new EntitlementRulesTranslator(i18n);
List<PoolIdAndErrors> poolErrors = new ArrayList<>();
for (Pool pool : poolCurator.listAllByIds(validationResults.keySet())) {
List<String> errorMessages = new ArrayList<>();
for (ValidationError error : validationResults.get(pool.getId()).getErrors()) {
errorMessages.add(translator.poolErrorToMessage(pool, error));
}
poolErrors.add(new PoolIdAndErrors(pool.getId(), errorMessages));
}
ctx.setResult(poolErrors);
}// so that the job will be properly cleaned up on failure.
catch (Exception e) {
log.error("EntitlerJob encountered a problem.", e);
throw new JobExecutionException(e.getMessage(), e, false);
}
}
use of org.quartz.JobExecutionException in project candlepin by candlepin.
the class RefreshPoolsJob method toExecute.
/**
* {@inheritDoc}
*
* Executes {@link PoolManager#refreshPools(org.candlepin.model.Owner)}
* as a pinsetter job.
*
* @param context the job's execution context
*/
public void toExecute(JobExecutionContext context) throws JobExecutionException {
try {
JobDataMap map = context.getMergedJobDataMap();
String ownerKey = map.getString(JobStatus.TARGET_ID);
Boolean lazy = map.getBoolean(LAZY_REGEN);
Owner owner = ownerCurator.lookupByKey(ownerKey);
if (owner == null) {
context.setResult("Nothing to do. Owner no longer exists");
return;
}
// Assume that we verified the request in the resource layer:
poolManager.getRefresher(this.subAdapter, this.ownerAdapter, lazy).setUnitOfWork(unitOfWork).add(owner).run();
context.setResult("Pools refreshed for owner " + owner.getDisplayName());
} catch (PersistenceException e) {
throw new RetryJobException("RefreshPoolsJob encountered a problem.", e);
} catch (RuntimeException e) {
Throwable cause = e.getCause();
while (cause != null) {
if (SQLException.class.isAssignableFrom(cause.getClass())) {
log.warn("Caught a runtime exception wrapping an SQLException.");
throw new RetryJobException("RefreshPoolsJob encountered a problem.", e);
}
cause = cause.getCause();
}
// Otherwise throw as we would normally for any generic Exception:
log.error("RefreshPoolsJob encountered a problem.", e);
context.setResult(e.toString());
throw new JobExecutionException(e.toString(), e, false);
}// cleaned up on failure.
catch (Exception e) {
log.error("RefreshPoolsJob encountered a problem.", e);
context.setResult(e.toString());
throw new JobExecutionException(e.toString(), e, false);
}
}
use of org.quartz.JobExecutionException in project candlepin by candlepin.
the class SweepBarJob method toExecute.
@Override
public void toExecute(JobExecutionContext ctx) throws JobExecutionException {
try {
Set<JobKey> keys = pinsetterKernel.getSingleJobKeys();
Set<String> statusIds = new HashSet<>();
for (JobKey key : keys) {
statusIds.add(key.getName());
}
int cancelled = jobCurator.cancelOrphanedJobs(statusIds);
if (cancelled > 0) {
log.info("Cancelled {} orphaned jobs", cancelled);
}
} catch (Exception e) {
log.error("Failed to cancel orphaned jobs", e);
}
}
Aggregations