Search in sources :

Example 41 with JobExecutionException

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));
}
Also used : JobStatus(org.candlepin.pinsetter.core.model.JobStatus) JobDetail(org.quartz.JobDetail) JobExecutionException(org.quartz.JobExecutionException) Test(org.junit.Test)

Example 42 with JobExecutionException

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());
    }
}
Also used : JobExecutionException(org.quartz.JobExecutionException) SQLException(java.sql.SQLException) Test(org.junit.Test)

Example 43 with JobExecutionException

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);
    }
}
Also used : JobDataMap(org.quartz.JobDataMap) PoolIdAndQuantity(org.candlepin.model.dto.PoolIdAndQuantity) PoolIdAndErrors(org.candlepin.model.dto.PoolIdAndErrors) HashMap(java.util.HashMap) EntitlementRefusedException(org.candlepin.policy.EntitlementRefusedException) SchedulerException(org.quartz.SchedulerException) EntitlementRefusedException(org.candlepin.policy.EntitlementRefusedException) JobExecutionException(org.quartz.JobExecutionException) JobExecutionException(org.quartz.JobExecutionException) ArrayList(java.util.ArrayList) List(java.util.List) Pool(org.candlepin.model.Pool) ValidationError(org.candlepin.policy.ValidationError) Entitlement(org.candlepin.model.Entitlement) EntitlementRulesTranslator(org.candlepin.policy.js.entitlement.EntitlementRulesTranslator) HashMap(java.util.HashMap) Map(java.util.Map) JobDataMap(org.quartz.JobDataMap)

Example 44 with JobExecutionException

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);
    }
}
Also used : JobDataMap(org.quartz.JobDataMap) Owner(org.candlepin.model.Owner) JobExecutionException(org.quartz.JobExecutionException) SQLException(java.sql.SQLException) PersistenceException(javax.persistence.PersistenceException) RetryJobException(org.candlepin.pinsetter.core.RetryJobException) JobExecutionException(org.quartz.JobExecutionException) SQLException(java.sql.SQLException) PersistenceException(javax.persistence.PersistenceException) RetryJobException(org.candlepin.pinsetter.core.RetryJobException)

Example 45 with JobExecutionException

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);
    }
}
Also used : JobKey(org.quartz.JobKey) JobExecutionException(org.quartz.JobExecutionException) HashSet(java.util.HashSet)

Aggregations

JobExecutionException (org.quartz.JobExecutionException)123 JobDataMap (org.quartz.JobDataMap)35 ArrayList (java.util.ArrayList)18 Date (java.util.Date)16 IgnoreProvisionException (org.apache.syncope.core.provisioning.api.pushpull.IgnoreProvisionException)16 SchedulerException (org.quartz.SchedulerException)16 HashMap (java.util.HashMap)15 ProvisioningReport (org.apache.syncope.core.provisioning.api.pushpull.ProvisioningReport)15 Test (org.junit.Test)13 Result (org.apache.syncope.common.lib.types.AuditElements.Result)12 JobDetail (org.quartz.JobDetail)12 PullActions (org.apache.syncope.core.provisioning.api.pushpull.PullActions)11 SQLException (java.sql.SQLException)10 PropagationException (org.apache.syncope.core.provisioning.api.propagation.PropagationException)10 DelegatedAdministrationException (org.apache.syncope.core.spring.security.DelegatedAdministrationException)10 Map (java.util.Map)9 JobExecutionContext (org.quartz.JobExecutionContext)9 List (java.util.List)8 IOException (java.io.IOException)7 Realm (org.apache.syncope.core.persistence.api.entity.Realm)7