Search in sources :

Example 71 with JobExecutionException

use of org.quartz.JobExecutionException in project cdap by caskdata.

the class LogPrintingJob method execute.

@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
    try {
        LOG.info("Received Trigger at {}", context.getScheduledFireTime().toString());
        JobDataMap triggerMap = context.getTrigger().getJobDataMap();
        JobDataMap map = context.getMergedJobDataMap();
        String[] keys = map.getKeys();
        TriggerKey triggerKey = context.getTrigger().getKey();
        if (triggerKey.getName().equalsIgnoreCase("g2")) {
            Preconditions.checkArgument(triggerMap.getString(KEY).equals(VALUE));
        } else {
            Preconditions.checkArgument(!triggerMap.containsKey(KEY));
        }
        Preconditions.checkArgument(keys != null);
        Preconditions.checkArgument(keys.length > 0);
        LOG.info("Number of parameters {}", keys.length);
        for (String key : keys) {
            LOG.info("Parameter key: {}, value: {}", key, map.get(key));
        }
    } catch (Throwable e) {
        throw Throwables.propagate(e);
    }
    throw new JobExecutionException("exception");
}
Also used : TriggerKey(org.quartz.TriggerKey) JobDataMap(org.quartz.JobDataMap) JobExecutionException(org.quartz.JobExecutionException)

Example 72 with JobExecutionException

use of org.quartz.JobExecutionException in project xwiki-platform by xwiki.

the class WatchListJob method executeJob.

/**
 * Method called from the scheduler.
 *
 * @param jobContext Context of the request
 * @throws JobExecutionException if the job execution fails.
 */
@Override
public void executeJob(JobExecutionContext jobContext) throws JobExecutionException {
    try {
        // Don't go further if the application is disabled
        if (!isWatchListEnabled()) {
            return;
        }
        init(jobContext);
        if (this.watchListJobObject == null) {
            return;
        }
        Collection<String> subscribers = getSubscribers();
        // Stop here if nobody is interested.
        if (!hasSubscribers()) {
            return;
        }
        // Determine what happened since the last execution for everybody.
        Date previousFireTime = getPreviousFireTime();
        WatchListEventMatcher eventMatcher = Utils.getComponent(WatchListEventMatcher.class);
        List<WatchListEvent> events = eventMatcher.getEventsSince(previousFireTime);
        setPreviousFireTime();
        // Stop here if nothing happened in the meantime.
        if (events.size() == 0) {
            return;
        }
        // Notify all the interested subscribers of the events that occurred.
        // When processing the events, a subscriber will only be notified of events that interest him.
        Map<String, Object> notificationData = new HashMap<>();
        notificationData.put(DefaultWatchListNotifier.PREVIOUS_FIRE_TIME_VARIABLE, previousFireTime);
        String mailTemplate = this.watchListJobObject.getStringValue(WatchListJobClassDocumentInitializer.TEMPLATE_FIELD);
        notificationData.put(WatchListEventMimeMessageFactory.TEMPLATE_PARAMETER, mailTemplate);
        // Send the notification for processing.
        this.watchlist.getNotifier().sendNotification(subscribers, events, notificationData);
    } catch (Exception e) {
        // We're in a job, we don't throw exceptions
        LOGGER.error("Exception while running job", e);
    }
}
Also used : WatchListEvent(org.xwiki.watchlist.internal.api.WatchListEvent) HashMap(java.util.HashMap) BaseObject(com.xpn.xwiki.objects.BaseObject) WatchListEventMatcher(org.xwiki.watchlist.internal.WatchListEventMatcher) Date(java.util.Date) XWikiException(com.xpn.xwiki.XWikiException) JobExecutionException(org.quartz.JobExecutionException)

Example 73 with JobExecutionException

use of org.quartz.JobExecutionException in project syncope by apache.

the class AbstractPushResultHandler method handle.

@Transactional(propagation = Propagation.REQUIRES_NEW)
@Override
public boolean handle(final String anyKey) {
    Any<?> any = null;
    try {
        any = getAny(anyKey);
        doHandle(any);
        return true;
    } catch (IgnoreProvisionException e) {
        ProvisioningReport result = new ProvisioningReport();
        result.setOperation(ResourceOperation.NONE);
        result.setAnyType(any == null ? null : any.getType().getKey());
        result.setStatus(ProvisioningReport.Status.IGNORE);
        result.setKey(anyKey);
        profile.getResults().add(result);
        LOG.warn("Ignoring during push", e);
        return true;
    } catch (JobExecutionException e) {
        LOG.error("Push failed", e);
        return false;
    }
}
Also used : JobExecutionException(org.quartz.JobExecutionException) IgnoreProvisionException(org.apache.syncope.core.provisioning.api.pushpull.IgnoreProvisionException) ProvisioningReport(org.apache.syncope.core.provisioning.api.pushpull.ProvisioningReport) Transactional(org.springframework.transaction.annotation.Transactional)

Example 74 with JobExecutionException

use of org.quartz.JobExecutionException in project syncope by apache.

the class DefaultRealmPullResultHandler method handle.

@Override
public boolean handle(final SyncDelta delta) {
    try {
        OrgUnit orgUnit = profile.getTask().getResource().getOrgUnit();
        if (orgUnit == null) {
            throw new JobExecutionException("No orgUnit found on " + profile.getTask().getResource() + " for " + delta.getObject().getObjectClass());
        }
        doHandle(delta, orgUnit);
        executor.reportHandled(delta.getObjectClass(), delta.getObject().getName());
        LOG.debug("Successfully handled {}", delta);
        if (profile.getTask().getPullMode() != PullMode.INCREMENTAL) {
            return true;
        }
        boolean shouldContinue;
        synchronized (this) {
            shouldContinue = latestResult == Result.SUCCESS;
            this.latestResult = null;
        }
        if (shouldContinue) {
            executor.setLatestSyncToken(delta.getObjectClass(), delta.getToken());
        }
        return shouldContinue;
    } catch (IgnoreProvisionException e) {
        ProvisioningReport ignoreResult = new ProvisioningReport();
        ignoreResult.setOperation(ResourceOperation.NONE);
        ignoreResult.setStatus(ProvisioningReport.Status.IGNORE);
        ignoreResult.setAnyType(REALM_TYPE);
        ignoreResult.setKey(null);
        ignoreResult.setName(delta.getObject().getName().getNameValue());
        profile.getResults().add(ignoreResult);
        LOG.warn("Ignoring during pull", e);
        executor.setLatestSyncToken(delta.getObjectClass(), delta.getToken());
        executor.reportHandled(delta.getObjectClass(), delta.getObject().getName());
        return true;
    } catch (JobExecutionException e) {
        LOG.error("Pull failed", e);
        return false;
    }
}
Also used : OrgUnit(org.apache.syncope.core.persistence.api.entity.resource.OrgUnit) JobExecutionException(org.quartz.JobExecutionException) IgnoreProvisionException(org.apache.syncope.core.provisioning.api.pushpull.IgnoreProvisionException) ProvisioningReport(org.apache.syncope.core.provisioning.api.pushpull.ProvisioningReport)

Example 75 with JobExecutionException

use of org.quartz.JobExecutionException in project syncope by apache.

the class DefaultRealmPullResultHandler method create.

private void create(final RealmTO realmTO, final SyncDelta delta, final String operation, final ProvisioningReport result) throws JobExecutionException {
    Object output;
    Result resultStatus;
    try {
        Realm realm = realmDAO.save(binder.create(profile.getTask().getDestinatioRealm(), realmTO));
        PropagationByResource propByRes = new PropagationByResource();
        for (String resource : realm.getResourceKeys()) {
            propByRes.add(ResourceOperation.CREATE, resource);
        }
        List<PropagationTaskTO> tasks = propagationManager.createTasks(realm, propByRes, null);
        taskExecutor.execute(tasks, false);
        RealmTO actual = binder.getRealmTO(realm, true);
        result.setKey(actual.getKey());
        result.setName(profile.getTask().getDestinatioRealm().getFullPath() + "/" + actual.getName());
        output = actual;
        resultStatus = Result.SUCCESS;
        for (PullActions action : profile.getActions()) {
            action.after(profile, delta, actual, result);
        }
        LOG.debug("Realm {} successfully created", actual.getKey());
    } catch (PropagationException e) {
        // A propagation failure doesn't imply a pull failure.
        // The propagation exception status will be reported into the propagation task execution.
        LOG.error("Could not propagate Realm {}", delta.getUid().getUidValue(), e);
        output = e;
        resultStatus = Result.FAILURE;
    } catch (Exception e) {
        throwIgnoreProvisionException(delta, e);
        result.setStatus(ProvisioningReport.Status.FAILURE);
        result.setMessage(ExceptionUtils.getRootCauseMessage(e));
        LOG.error("Could not create Realm {} ", delta.getUid().getUidValue(), e);
        output = e;
        resultStatus = Result.FAILURE;
    }
    finalize(operation, resultStatus, null, output, delta);
}
Also used : PropagationException(org.apache.syncope.core.provisioning.api.propagation.PropagationException) PropagationTaskTO(org.apache.syncope.common.lib.to.PropagationTaskTO) PullActions(org.apache.syncope.core.provisioning.api.pushpull.PullActions) RealmTO(org.apache.syncope.common.lib.to.RealmTO) PropagationByResource(org.apache.syncope.core.provisioning.api.PropagationByResource) Realm(org.apache.syncope.core.persistence.api.entity.Realm) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) DelegatedAdministrationException(org.apache.syncope.core.spring.security.DelegatedAdministrationException) IgnoreProvisionException(org.apache.syncope.core.provisioning.api.pushpull.IgnoreProvisionException) PropagationException(org.apache.syncope.core.provisioning.api.propagation.PropagationException) JobExecutionException(org.quartz.JobExecutionException) Result(org.apache.syncope.common.lib.types.AuditElements.Result)

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