use of org.candlepin.pinsetter.core.RetryJobException 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.candlepin.pinsetter.core.RetryJobException in project candlepin by candlepin.
the class UndoImportsJob method toExecute.
/**
* {@inheritDoc}
*
* Executes {@link PoolManager#refreshPools(org.candlepin.model.Owner)}
* as a pinsetter job.
*
* @param context the job's execution context
*/
@Transactional
public void toExecute(JobExecutionContext context) throws JobExecutionException {
try {
JobDataMap map = context.getMergedJobDataMap();
String ownerId = map.getString(JobStatus.TARGET_ID);
String ownerKey = map.getString(OWNER_KEY);
Owner owner = this.ownerCurator.lockAndLoadById(ownerId);
Boolean lazy = map.getBoolean(LAZY_REGEN);
Principal principal = (Principal) map.get(PinsetterJobListener.PRINCIPAL_KEY);
if (owner == null) {
log.debug("Owner no longer exists: {}", ownerKey);
context.setResult("Nothing to do; owner no longer exists: " + ownerKey);
return;
}
String displayName = owner.getDisplayName();
// Remove imports
ExporterMetadata metadata = this.exportCurator.lookupByTypeAndOwner(ExporterMetadata.TYPE_PER_USER, owner);
if (metadata == null) {
log.debug("No imports exist for owner {}", displayName);
context.setResult("Nothing to do; imports no longer exist for owner: " + displayName);
return;
}
log.info("Deleting all pools originating from manifests for owner/org: {}", displayName);
List<Pool> pools = this.poolManager.listPoolsByOwner(owner).list();
for (Pool pool : pools) {
if (this.poolManager.isManaged(pool)) {
this.poolManager.deletePool(pool);
}
}
// Clear out upstream ID so owner can import from other distributors:
UpstreamConsumer uc = owner.getUpstreamConsumer();
owner.setUpstreamConsumer(null);
this.exportCurator.delete(metadata);
this.recordManifestDeletion(owner, principal.getUsername(), uc);
context.setResult("Imported pools removed for owner " + displayName);
} catch (PersistenceException e) {
throw new RetryJobException("UndoImportsJob 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("UndoImportsJob encountered a problem.", e);
}
cause = cause.getCause();
}
// Otherwise throw as we would normally for any generic Exception:
log.error("UndoImportsJob encountered a problem.", e);
context.setResult(e.getMessage());
throw new JobExecutionException(e.getMessage(), e, false);
}// cleaned up on failure.
catch (Exception e) {
log.error("UndoImportsJob encountered a problem.", e);
context.setResult(e.getMessage());
throw new JobExecutionException(e.getMessage(), e, false);
}
}
Aggregations