Search in sources :

Example 36 with JobExecutionException

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

the class TaskJob method execute.

@Override
public void execute(final JobExecutionContext context) throws JobExecutionException {
    try {
        AuthContextUtils.execWithAuthContext(context.getMergedJobDataMap().getString(JobManager.DOMAIN_KEY), () -> {
            try {
                ImplementationDAO implementationDAO = ApplicationContextProvider.getApplicationContext().getBean(ImplementationDAO.class);
                Implementation implementation = implementationDAO.find(context.getMergedJobDataMap().getString(DELEGATE_IMPLEMENTATION));
                if (implementation == null) {
                    LOG.error("Could not find Implementation '{}', aborting", context.getMergedJobDataMap().getString(DELEGATE_IMPLEMENTATION));
                } else {
                    delegate = ImplementationManager.<SchedTaskJobDelegate>build(implementation);
                    delegate.execute(taskKey, context.getMergedJobDataMap().getBoolean(DRY_RUN_JOBDETAIL_KEY), context);
                }
            } catch (Exception e) {
                LOG.error("While executing task {}", taskKey, e);
                throw new RuntimeException(e);
            }
            return null;
        });
    } catch (RuntimeException e) {
        LOG.error("While executing task {}", taskKey, e);
        throw new JobExecutionException("While executing task " + taskKey, e);
    }
}
Also used : JobExecutionException(org.quartz.JobExecutionException) ImplementationDAO(org.apache.syncope.core.persistence.api.dao.ImplementationDAO) Implementation(org.apache.syncope.core.persistence.api.entity.Implementation) JobExecutionException(org.quartz.JobExecutionException)

Example 37 with JobExecutionException

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

the class EncodeJob method execute.

@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
    JobDataMap data = context.getJobDetail().getJobDataMap();
    CaptureScreen capture = (CaptureScreen) data.get(CAPTURE_KEY);
    if (screen == null) {
        dim = capture.getDim();
        screen = new Rectangle(dim.getSpinnerX(), dim.getSpinnerY(), dim.getSpinnerWidth(), dim.getSpinnerHeight());
    }
    long start = 0;
    if (log.isTraceEnabled()) {
        start = System.currentTimeMillis();
    }
    image = ScreenV1Encoder.getImage(dim, screen, robot);
    if (log.isTraceEnabled()) {
        log.trace(String.format("encode: Image was captured in %s ms, size %sk", System.currentTimeMillis() - start, 4 * image.length * image[0].length / 1024));
        start = System.currentTimeMillis();
    }
    try {
        VideoData vData = capture.getEncoder().encode(image);
        if (log.isTraceEnabled()) {
            long now = System.currentTimeMillis();
            log.trace(String.format("encode: Image was encoded in %s ms, timestamp is %s", now - start, now - capture.getStartTime()));
        }
        capture.getFrames().offer(vData);
        capture.getEncoder().createUnalteredFrame();
    } catch (Exception e) {
        log.error("Error while encoding: ", e);
    }
}
Also used : JobDataMap(org.quartz.JobDataMap) Rectangle(java.awt.Rectangle) VideoData(org.red5.server.net.rtmp.event.VideoData) CaptureScreen(org.apache.openmeetings.screenshare.CaptureScreen) JobExecutionException(org.quartz.JobExecutionException) AWTException(java.awt.AWTException)

Example 38 with JobExecutionException

use of org.quartz.JobExecutionException in project candlepin by candlepin.

the class PinsetterJobListenerDatabaseTest method verifyDatabaseConstraintIsNotViolated.

@Test
public void verifyDatabaseConstraintIsNotViolated() {
    JobExecutionException e = mock(JobExecutionException.class);
    String longstr = RandomStringUtils.randomAlphanumeric(300);
    when(e.getMessage()).thenReturn(longstr);
    JobDataMap map = new JobDataMap();
    Principal principal = mock(Principal.class);
    when(principal.getPrincipalName()).thenReturn("test-admin");
    map.put(PinsetterJobListener.PRINCIPAL_KEY, principal);
    map.put(JobStatus.TARGET_TYPE, JobStatus.TargetType.OWNER);
    map.put(JobStatus.TARGET_ID, "10");
    JobDetail detail = mock(JobDetail.class);
    when(detail.getKey()).thenReturn(jobKey("name", "group"));
    when(detail.getJobDataMap()).thenReturn(map);
    JobStatus status = new JobStatus(detail);
    // store a merge so we can find it in the test run
    curator.merge(status);
    JobExecutionContext ctx = mock(JobExecutionContext.class);
    when(ctx.getMergedJobDataMap()).thenReturn(map);
    when(ctx.getJobDetail()).thenReturn(detail);
    // thing to be tested
    listener.jobWasExecuted(ctx, e);
    // verify the message stored is a substring of the long message
    JobStatus verify = curator.find("name");
    assertEquals(longstr.substring(0, JobStatus.RESULT_COL_LENGTH), verify.getResult());
}
Also used : JobStatus(org.candlepin.pinsetter.core.model.JobStatus) JobDataMap(org.quartz.JobDataMap) JobDetail(org.quartz.JobDetail) JobExecutionException(org.quartz.JobExecutionException) JobExecutionContext(org.quartz.JobExecutionContext) Principal(org.candlepin.auth.Principal) Test(org.junit.Test)

Example 39 with JobExecutionException

use of org.quartz.JobExecutionException in project candlepin by candlepin.

the class PinsetterJobListenerTest method executedNullStatus.

@Test
public void executedNullStatus() {
    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(null);
    listener.jobWasExecuted(ctx, e);
    verifyZeroInteractions(status);
    verify(jcurator, never()).merge(eq(status));
    verifyZeroInteractions(e);
}
Also used : JobStatus(org.candlepin.pinsetter.core.model.JobStatus) JobDetail(org.quartz.JobDetail) JobExecutionException(org.quartz.JobExecutionException) Test(org.junit.Test)

Example 40 with JobExecutionException

use of org.quartz.JobExecutionException in project candlepin by candlepin.

the class PinsetterJobListenerTest method handleResultTooLong.

@Test
public void handleResultTooLong() {
    JobExecutionException e = mock(JobExecutionException.class);
    JobDetail detail = mock(JobDetail.class);
    JobDataMap map = new JobDataMap();
    map.put(JobStatus.TARGET_TYPE, JobStatus.TargetType.OWNER);
    when(detail.getKey()).thenReturn(jobKey("name", "group"));
    when(detail.getJobDataMap()).thenReturn(map);
    when(ctx.getJobDetail()).thenReturn(detail);
    JobStatus status = new JobStatus(detail);
    when(jcurator.find(eq("name"))).thenReturn(status);
    String longstr = RandomStringUtils.randomAlphanumeric(300);
    when(e.getMessage()).thenReturn(longstr);
    listener.jobWasExecuted(ctx, e);
    assertEquals(longstr.substring(0, JobStatus.RESULT_COL_LENGTH), status.getResult());
    assertEquals(JobState.FAILED, status.getState());
    verify(jcurator).merge(eq(status));
}
Also used : JobStatus(org.candlepin.pinsetter.core.model.JobStatus) JobDetail(org.quartz.JobDetail) JobDataMap(org.quartz.JobDataMap) JobExecutionException(org.quartz.JobExecutionException) 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