use of org.apache.syncope.core.persistence.api.entity.task.TaskExec in project syncope by apache.
the class DefaultPropagationTaskCallable method call.
@Override
public TaskExec call() throws Exception {
// set security context according to the one gathered at instantiation time from the calling thread
UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken(new User(username, "FAKE_PASSWORD", authorities), "FAKE_PASSWORD", authorities);
auth.setDetails(new SyncopeAuthenticationDetails(domain));
SecurityContextHolder.getContext().setAuthentication(auth);
LOG.debug("Execution started for {}", taskTO);
TaskExec execution = executor.execute(taskTO, reporter);
LOG.debug("Execution completed for {}, {}", taskTO, execution);
return execution;
}
use of org.apache.syncope.core.persistence.api.entity.task.TaskExec in project syncope by apache.
the class TaskLogic method deleteExecution.
@PreAuthorize("hasRole('" + StandardEntitlement.TASK_DELETE + "')")
@Override
public ExecTO deleteExecution(final String execKey) {
TaskExec taskExec = taskExecDAO.find(execKey);
if (taskExec == null) {
throw new NotFoundException("Task execution " + execKey);
}
ExecTO taskExecutionToDelete = binder.getExecTO(taskExec);
taskExecDAO.delete(taskExec);
return taskExecutionToDelete;
}
use of org.apache.syncope.core.persistence.api.entity.task.TaskExec in project syncope by apache.
the class TaskLogic method execute.
@PreAuthorize("hasRole('" + StandardEntitlement.TASK_EXECUTE + "')")
@Override
public ExecTO execute(final String key, final Date startAt, final boolean dryRun) {
Task task = taskDAO.find(key);
if (task == null) {
throw new NotFoundException("Task " + key);
}
if (startAt != null && startAt.before(new Date())) {
SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.Scheduling);
sce.getElements().add("Cannot schedule in the past");
throw sce;
}
TaskUtils taskUtil = taskUtilsFactory.getInstance(task);
ExecTO result = null;
switch(taskUtil.getType()) {
case PROPAGATION:
TaskExec propExec = taskExecutor.execute((PropagationTaskTO) binder.getTaskTO(task, taskUtil, false));
result = binder.getExecTO(propExec);
break;
case NOTIFICATION:
TaskExec notExec = notificationJobDelegate.executeSingle((NotificationTask) task);
result = binder.getExecTO(notExec);
break;
case SCHEDULED:
case PULL:
case PUSH:
if (!((SchedTask) task).isActive()) {
SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.Scheduling);
sce.getElements().add("Task " + key + " is not active");
throw sce;
}
try {
Map<String, Object> jobDataMap = jobManager.register((SchedTask) task, startAt, confDAO.find("tasks.interruptMaxRetries", 1L));
jobDataMap.put(TaskJob.DRY_RUN_JOBDETAIL_KEY, dryRun);
if (startAt == null) {
scheduler.getScheduler().triggerJob(JobNamer.getJobKey(task), new JobDataMap(jobDataMap));
}
} catch (Exception e) {
LOG.error("While executing task {}", task, e);
SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.Scheduling);
sce.getElements().add(e.getMessage());
throw sce;
}
result = new ExecTO();
result.setJobType(JobType.TASK);
result.setRefKey(task.getKey());
result.setRefDesc(binder.buildRefDesc(task));
result.setStart(new Date());
result.setStatus("JOB_FIRED");
result.setMessage("Job fired; waiting for results...");
break;
default:
}
return result;
}
use of org.apache.syncope.core.persistence.api.entity.task.TaskExec in project syncope by apache.
the class TaskTest method addPullTaskExecution.
@Test
public void addPullTaskExecution() {
PullTask task = taskDAO.find("c41b9b71-9bfa-4f90-89f2-84787def4c5c");
assertNotNull(task);
int executionNumber = task.getExecs().size();
TaskExec execution = entityFactory.newEntity(TaskExec.class);
execution.setStatus("Text-free status");
execution.setTask(task);
execution.setStart(new Date());
execution.setMessage("A message");
task.add(execution);
taskDAO.save(task);
taskDAO.flush();
task = taskDAO.find("c41b9b71-9bfa-4f90-89f2-84787def4c5c");
assertNotNull(task);
assertEquals(executionNumber + 1, task.getExecs().size());
}
use of org.apache.syncope.core.persistence.api.entity.task.TaskExec in project syncope by apache.
the class TaskTest method addPropagationTaskExecution.
@Test
public void addPropagationTaskExecution() {
PropagationTask task = taskDAO.find("1e697572-b896-484c-ae7f-0c8f63fcbc6c");
assertNotNull(task);
int executionNumber = task.getExecs().size();
TaskExec execution = entityFactory.newEntity(TaskExec.class);
execution.setTask(task);
execution.setStatus(PropagationTaskExecStatus.CREATED.name());
execution.setStart(new Date());
task.add(execution);
taskDAO.save(task);
taskDAO.flush();
task = taskDAO.find("1e697572-b896-484c-ae7f-0c8f63fcbc6c");
assertNotNull(task);
assertEquals(executionNumber + 1, task.getExecs().size());
}
Aggregations