Search in sources :

Example 11 with TaskExec

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;
}
Also used : User(org.springframework.security.core.userdetails.User) TaskExec(org.apache.syncope.core.persistence.api.entity.task.TaskExec) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) SyncopeAuthenticationDetails(org.apache.syncope.core.spring.security.SyncopeAuthenticationDetails)

Example 12 with TaskExec

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;
}
Also used : ExecTO(org.apache.syncope.common.lib.to.ExecTO) TaskExec(org.apache.syncope.core.persistence.api.entity.task.TaskExec) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 13 with TaskExec

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;
}
Also used : TaskUtils(org.apache.syncope.core.persistence.api.entity.task.TaskUtils) NotificationTask(org.apache.syncope.core.persistence.api.entity.task.NotificationTask) SchedTask(org.apache.syncope.core.persistence.api.entity.task.SchedTask) Task(org.apache.syncope.core.persistence.api.entity.task.Task) JobDataMap(org.quartz.JobDataMap) ExecTO(org.apache.syncope.common.lib.to.ExecTO) TaskExec(org.apache.syncope.core.persistence.api.entity.task.TaskExec) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) Date(java.util.Date) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) SchedulerException(org.quartz.SchedulerException) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 14 with TaskExec

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());
}
Also used : PullTask(org.apache.syncope.core.persistence.api.entity.task.PullTask) AnyTemplatePullTask(org.apache.syncope.core.persistence.api.entity.task.AnyTemplatePullTask) TaskExec(org.apache.syncope.core.persistence.api.entity.task.TaskExec) Date(java.util.Date) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

Example 15 with TaskExec

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());
}
Also used : PropagationTask(org.apache.syncope.core.persistence.api.entity.task.PropagationTask) TaskExec(org.apache.syncope.core.persistence.api.entity.task.TaskExec) Date(java.util.Date) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

Aggregations

TaskExec (org.apache.syncope.core.persistence.api.entity.task.TaskExec)19 Date (java.util.Date)9 PropagationTask (org.apache.syncope.core.persistence.api.entity.task.PropagationTask)7 AbstractTest (org.apache.syncope.core.persistence.jpa.AbstractTest)7 ExecTO (org.apache.syncope.common.lib.to.ExecTO)5 Test (org.junit.jupiter.api.Test)5 Collectors (java.util.stream.Collectors)4 PropagationTaskTO (org.apache.syncope.common.lib.to.PropagationTaskTO)4 NotFoundException (org.apache.syncope.core.persistence.api.dao.NotFoundException)4 NotificationTask (org.apache.syncope.core.persistence.api.entity.task.NotificationTask)4 Transactional (org.springframework.transaction.annotation.Transactional)4 List (java.util.List)3 Map (java.util.Map)3 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)3 ExternalResourceDAO (org.apache.syncope.core.persistence.api.dao.ExternalResourceDAO)3 ExternalResource (org.apache.syncope.core.persistence.api.entity.resource.ExternalResource)3 SchedTask (org.apache.syncope.core.persistence.api.entity.task.SchedTask)3 Task (org.apache.syncope.core.persistence.api.entity.task.Task)3 TaskUtils (org.apache.syncope.core.persistence.api.entity.task.TaskUtils)3 TaskUtilsFactory (org.apache.syncope.core.persistence.api.entity.task.TaskUtilsFactory)3