use of org.candlepin.pinsetter.core.model.JobStatus in project candlepin by candlepin.
the class PinsetterAsyncFilter method postProcess.
/**
* {@inheritDoc}
*
* @param response the server response (provided by Resteasy)
*/
@Override
public void postProcess(ServerResponse response) {
Object entity = response.getEntity();
if (entity instanceof JobDetail) {
JobDetail jobDetail = (JobDetail) entity;
setJobPrincipal(jobDetail);
JobStatus status = this.scheduleJob(jobDetail);
response.setEntity(this.translator.translate(status, JobStatusDTO.class));
response.setStatus(HttpResponseCodes.SC_ACCEPTED);
} else if (entity instanceof JobDetail[]) {
JobDetail[] details = (JobDetail[]) entity;
JobStatus[] statuses = new JobStatus[details.length];
int i = 0;
for (JobDetail jobDetail : details) {
setJobPrincipal(jobDetail);
JobStatus status = this.scheduleJob(jobDetail);
statuses[i++] = status;
}
JobStatusDTO[] dtoStatuses = new JobStatusDTO[statuses.length];
for (int j = 0; j < statuses.length; j++) {
dtoStatuses[j] = this.translator.translate(statuses[j], JobStatusDTO.class);
}
response.setEntity(dtoStatuses);
response.setStatus(HttpResponseCodes.SC_ACCEPTED);
}
}
use of org.candlepin.pinsetter.core.model.JobStatus in project candlepin by candlepin.
the class PinsetterAsyncFilterTest method jobStatusSet.
@Test
public void jobStatusSet() throws PinsetterException {
JobDetail detail = newJob(RefreshPoolsJob.class).build();
JobStatus status = new JobStatus();
JobStatusDTO statusDTO = new JobStatusDTO();
when(response.getEntity()).thenReturn(detail);
when(this.pinsetterKernel.scheduleSingleJob(detail)).thenReturn(status);
when(this.translator.translate(status, JobStatusDTO.class)).thenReturn(statusDTO);
this.interceptor.postProcess(response);
verify(response).setEntity(statusDTO);
}
use of org.candlepin.pinsetter.core.model.JobStatus in project candlepin by candlepin.
the class JobStatusTranslatorTest method initSourceObject.
@Override
protected JobStatus initSourceObject() {
// JobStatus uses a JobDetail argument to populate fields instead
// of setters, which is why we need to mock here.
JobDetail jobDetail = mock(JobDetail.class);
JobDataMap jobDataMap = mock(JobDataMap.class);
Principal principal = mock(Principal.class);
JobKey jobKey = new JobKey("test-name", "test-group");
when(jobDetail.getKey()).thenReturn(jobKey);
when(jobDetail.getJobDataMap()).thenReturn(jobDataMap);
when(jobDataMap.get(PinsetterJobListener.PRINCIPAL_KEY)).thenReturn(principal);
when(principal.getPrincipalName()).thenReturn("test-principal-name");
when(jobDataMap.get(TARGET_TYPE)).thenReturn(CONSUMER);
when(jobDataMap.get(TARGET_ID)).thenReturn("test-target-id");
when(jobDataMap.get(OWNER_ID)).thenReturn("test-owner-id");
when(jobDataMap.get(CORRELATION_ID)).thenReturn("test-correlation-id");
JobStatus source = new JobStatus(jobDetail);
source.setState(JobStatus.JobState.CREATED);
source.setResult("result of job");
source.setResultData("result data of job");
return source;
}
use of org.candlepin.pinsetter.core.model.JobStatus 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());
}
use of org.candlepin.pinsetter.core.model.JobStatus in project candlepin by candlepin.
the class PinsetterKernelTest method handleExistingJobStatus.
@Test
public void handleExistingJobStatus() throws Exception {
pk = new PinsetterKernel(config, jfactory, jlistener, jcurator, sfactory, triggerListener, modeManager);
JobStatus status = mock(JobStatus.class);
when(jcurator.find(startsWith(Util.getClassName(JobCleaner.class)))).thenReturn(status);
when(jcurator.create(any(JobStatus.class))).thenThrow(new EntityExistsException());
pk.startup();
verify(sched).start();
// this test will have 2 jobs each throwing an exception, we should
// updated both statuses, then schedule both.
verify(jcurator, atMost(2)).merge(any(JobStatus.class));
verify(sched, atMost(2)).scheduleJob(any(JobDetail.class), any(Trigger.class));
}
Aggregations