use of org.apache.syncope.common.lib.to.JobTO in project syncope by apache.
the class TaskLogic method getJob.
@PreAuthorize("hasRole('" + StandardEntitlement.TASK_READ + "')")
@Override
public JobTO getJob(final String key) {
Task task = taskDAO.find(key);
if (task == null) {
throw new NotFoundException("Task " + key);
}
JobTO jobTO = null;
try {
jobTO = getJobTO(JobNamer.getJobKey(task));
} catch (SchedulerException e) {
LOG.error("Problems while retrieving scheduled job {}", JobNamer.getJobKey(task), e);
SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.Scheduling);
sce.getElements().add(e.getMessage());
throw sce;
}
if (jobTO == null) {
throw new NotFoundException("Job for task " + key);
}
return jobTO;
}
use of org.apache.syncope.common.lib.to.JobTO in project syncope by apache.
the class AbstractJobLogic method getJobTO.
protected JobTO getJobTO(final JobKey jobKey) throws SchedulerException {
JobTO jobTO = null;
Triple<JobType, String, String> reference = getReference(jobKey);
if (reference != null) {
jobTO = new JobTO();
jobTO.setType(reference.getLeft());
jobTO.setRefKey(reference.getMiddle());
jobTO.setRefDesc(reference.getRight());
List<? extends Trigger> jobTriggers = scheduler.getScheduler().getTriggersOfJob(jobKey);
if (jobTriggers.isEmpty()) {
jobTO.setScheduled(false);
} else {
jobTO.setScheduled(true);
jobTO.setStart(jobTriggers.get(0).getStartTime());
}
jobTO.setRunning(jobManager.isRunning(jobKey));
jobTO.setStatus("UNKNOWN");
if (jobTO.isRunning()) {
try {
Object job = ApplicationContextProvider.getBeanFactory().getBean(jobKey.getName());
if (job instanceof AbstractInterruptableJob && ((AbstractInterruptableJob) job).getDelegate() != null) {
jobTO.setStatus(((AbstractInterruptableJob) job).getDelegate().currentStatus());
}
} catch (NoSuchBeanDefinitionException e) {
LOG.warn("Could not find job {} implementation", jobKey, e);
}
}
}
return jobTO;
}
Aggregations