Search in sources :

Example 96 with JobExecutionException

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);
    }
}
Also used : JobDataMap(org.quartz.JobDataMap) Owner(org.candlepin.model.Owner) JobExecutionException(org.quartz.JobExecutionException) Consumer(org.candlepin.model.Consumer) BadRequestException(org.jboss.resteasy.spi.BadRequestException) Date(java.util.Date) BadRequestException(org.jboss.resteasy.spi.BadRequestException) JobExecutionException(org.quartz.JobExecutionException) AutobindDisabledForOwnerException(org.candlepin.controller.AutobindDisabledForOwnerException)

Example 97 with JobExecutionException

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);
    }
}
Also used : ImporterException(org.candlepin.sync.ImporterException) ConflictOverrides(org.candlepin.sync.ConflictOverrides) JobDataMap(org.quartz.JobDataMap) Owner(org.candlepin.model.Owner) SyncDataFormatException(org.candlepin.sync.SyncDataFormatException) NotFoundException(org.candlepin.common.exceptions.NotFoundException) ImportRecord(org.candlepin.model.ImportRecord) NotFoundException(org.candlepin.common.exceptions.NotFoundException) SyncDataFormatException(org.candlepin.sync.SyncDataFormatException) JobExecutionException(org.quartz.JobExecutionException) IseException(org.candlepin.common.exceptions.IseException) BadRequestException(org.candlepin.common.exceptions.BadRequestException) ImporterException(org.candlepin.sync.ImporterException) JobExecutionException(org.quartz.JobExecutionException) IseException(org.candlepin.common.exceptions.IseException) BadRequestException(org.candlepin.common.exceptions.BadRequestException)

Example 98 with JobExecutionException

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);
    }
}
Also used : JobExecutionException(org.quartz.JobExecutionException) SchedulerException(org.quartz.SchedulerException) CancelJobJob(org.candlepin.pinsetter.tasks.CancelJobJob)

Example 99 with JobExecutionException

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.");
    }
}
Also used : JobDetail(org.quartz.JobDetail) Set(java.util.Set) JobExecutionException(org.quartz.JobExecutionException) VirtConsumerMap(org.candlepin.model.VirtConsumerMap) JobExecutionContext(org.quartz.JobExecutionContext) Test(org.junit.Test)

Example 100 with JobExecutionException

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

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