Search in sources :

Example 1 with SchedTaskTO

use of org.apache.syncope.common.lib.to.SchedTaskTO in project syncope by apache.

the class SchedTaskITCase method issueSYNCOPE660.

@Test
public void issueSYNCOPE660() {
    List<JobTO> jobs = taskService.listJobs();
    int old_size = jobs.size();
    ImplementationTO taskJobDelegate = implementationService.read(ImplementationType.TASKJOB_DELEGATE, TestSampleJobDelegate.class.getSimpleName());
    assertNotNull(taskJobDelegate);
    SchedTaskTO task = new SchedTaskTO();
    task.setName("issueSYNCOPE660");
    task.setDescription("issueSYNCOPE660 Description");
    task.setJobDelegate(taskJobDelegate.getKey());
    Response response = taskService.create(TaskType.SCHEDULED, task);
    task = getObject(response.getLocation(), TaskService.class, SchedTaskTO.class);
    jobs = taskService.listJobs();
    assertEquals(old_size + 1, jobs.size());
    taskService.actionJob(task.getKey(), JobAction.START);
    int i = 0, maxit = 50;
    do {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
        // ignore
        }
        jobs = taskService.listJobs().stream().filter(job -> job.isRunning()).collect(Collectors.toList());
        i++;
    } while (jobs.size() < 1 && i < maxit);
    assertEquals(1, jobs.size());
    assertEquals(task.getKey(), jobs.get(0).getRefKey());
    taskService.actionJob(task.getKey(), JobAction.STOP);
    i = 0;
    do {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
        // ignore
        }
        jobs = taskService.listJobs().stream().filter(job -> job.isRunning()).collect(Collectors.toList());
        i++;
    } while (jobs.size() >= 1 && i < maxit);
    assertTrue(jobs.isEmpty());
}
Also used : ImplementationTO(org.apache.syncope.common.lib.to.ImplementationTO) Response(javax.ws.rs.core.Response) SchedTaskTO(org.apache.syncope.common.lib.to.SchedTaskTO) TaskService(org.apache.syncope.common.rest.api.service.TaskService) TestSampleJobDelegate(org.apache.syncope.fit.core.reference.TestSampleJobDelegate) JobTO(org.apache.syncope.common.lib.to.JobTO) Test(org.junit.jupiter.api.Test)

Example 2 with SchedTaskTO

use of org.apache.syncope.common.lib.to.SchedTaskTO in project syncope by apache.

the class SchedTaskITCase method issueSYNCOPE144.

@Test
public void issueSYNCOPE144() {
    ImplementationTO taskJobDelegate = implementationService.read(ImplementationType.TASKJOB_DELEGATE, TestSampleJobDelegate.class.getSimpleName());
    assertNotNull(taskJobDelegate);
    SchedTaskTO task = new SchedTaskTO();
    task.setName("issueSYNCOPE144");
    task.setDescription("issueSYNCOPE144 Description");
    task.setJobDelegate(taskJobDelegate.getKey());
    Response response = taskService.create(TaskType.SCHEDULED, task);
    task = getObject(response.getLocation(), TaskService.class, SchedTaskTO.class);
    assertNotNull(task);
    assertEquals("issueSYNCOPE144", task.getName());
    assertEquals("issueSYNCOPE144 Description", task.getDescription());
    task = taskService.read(TaskType.SCHEDULED, task.getKey(), true);
    assertNotNull(task);
    assertEquals("issueSYNCOPE144", task.getName());
    assertEquals("issueSYNCOPE144 Description", task.getDescription());
    task.setName("issueSYNCOPE144_2");
    task.setDescription("issueSYNCOPE144 Description_2");
    response = taskService.create(TaskType.SCHEDULED, task);
    task = getObject(response.getLocation(), TaskService.class, SchedTaskTO.class);
    assertNotNull(task);
    assertEquals("issueSYNCOPE144_2", task.getName());
    assertEquals("issueSYNCOPE144 Description_2", task.getDescription());
}
Also used : ImplementationTO(org.apache.syncope.common.lib.to.ImplementationTO) Response(javax.ws.rs.core.Response) SchedTaskTO(org.apache.syncope.common.lib.to.SchedTaskTO) TaskService(org.apache.syncope.common.rest.api.service.TaskService) TestSampleJobDelegate(org.apache.syncope.fit.core.reference.TestSampleJobDelegate) Test(org.junit.jupiter.api.Test)

Example 3 with SchedTaskTO

use of org.apache.syncope.common.lib.to.SchedTaskTO in project syncope by apache.

the class SchedTaskITCase method update.

@Test
public void update() {
    SchedTaskTO task = taskService.read(TaskType.SCHEDULED, SCHED_TASK_KEY, true);
    assertNotNull(task);
    SchedTaskTO taskMod = new SchedTaskTO();
    taskMod.setKey(SCHED_TASK_KEY);
    taskMod.setName(task.getName());
    taskMod.setCronExpression(null);
    taskService.update(TaskType.SCHEDULED, taskMod);
    SchedTaskTO actual = taskService.read(TaskType.SCHEDULED, taskMod.getKey(), true);
    assertNotNull(actual);
    assertEquals(task.getKey(), actual.getKey());
    assertNull(actual.getCronExpression());
}
Also used : SchedTaskTO(org.apache.syncope.common.lib.to.SchedTaskTO) Test(org.junit.jupiter.api.Test)

Example 4 with SchedTaskTO

use of org.apache.syncope.common.lib.to.SchedTaskTO in project syncope by apache.

the class TaskDetails method details.

public void details() {
    if (input.parameterNumber() == 0) {
        try {
            final Map<String, String> details = new LinkedHashMap<>();
            final List<TaskTO> notificationTaskTOs = taskSyncopeOperations.list(TaskType.NOTIFICATION.name());
            final List<TaskTO> propagationTaskTOs = taskSyncopeOperations.list(TaskType.PROPAGATION.name());
            final List<TaskTO> pushTaskTOs = taskSyncopeOperations.list(TaskType.PUSH.name());
            final List<TaskTO> scheduledTaskTOs = taskSyncopeOperations.list(TaskType.SCHEDULED.name());
            final List<TaskTO> pullTaskTOs = taskSyncopeOperations.list(TaskType.PULL.name());
            final List<JobTO> jobTOs = taskSyncopeOperations.listJobs();
            final int notificationTaskSize = notificationTaskTOs.size();
            final int propagationTaskSize = propagationTaskTOs.size();
            final int pushTaskSize = pushTaskTOs.size();
            final int scheduledTaskSize = scheduledTaskTOs.size();
            final int pullTaskSize = pullTaskTOs.size();
            final int jobsSize = jobTOs.size();
            long notificationNotExecuted = notificationTaskTOs.stream().filter(notificationTaskTO -> !((NotificationTaskTO) notificationTaskTO).isExecuted()).count();
            long propagationNotExecuted = propagationTaskTOs.stream().filter(propagationTaskTO -> ((PropagationTaskTO) propagationTaskTO).getExecutions().isEmpty()).count();
            long pushNotExecuted = pushTaskTOs.stream().filter(pushTaskTO -> ((PushTaskTO) pushTaskTO).getExecutions().isEmpty()).count();
            long scheduledNotExecuted = scheduledTaskTOs.stream().filter(scheduledTaskTO -> ((SchedTaskTO) scheduledTaskTO).getExecutions().isEmpty()).count();
            int pullNotExecuted = 0;
            int pullFull = 0;
            for (final TaskTO pullTaskTO : pullTaskTOs) {
                if (((PullTaskTO) pullTaskTO).getExecutions().isEmpty()) {
                    pullNotExecuted++;
                }
                if (((PullTaskTO) pullTaskTO).getPullMode() == PullMode.FULL_RECONCILIATION) {
                    pullFull++;
                }
            }
            details.put("total number", String.valueOf(notificationTaskSize + propagationTaskSize + pushTaskSize + scheduledTaskSize + pullTaskSize));
            details.put("notification tasks", String.valueOf(notificationTaskSize));
            details.put("notification tasks not executed", String.valueOf(notificationNotExecuted));
            details.put("propagation tasks", String.valueOf(propagationTaskSize));
            details.put("propagation tasks not executed", String.valueOf(propagationNotExecuted));
            details.put("push tasks", String.valueOf(pushTaskSize));
            details.put("push tasks not executed", String.valueOf(pushNotExecuted));
            details.put("scheduled tasks", String.valueOf(scheduledTaskSize));
            details.put("scheduled tasks not executed", String.valueOf(scheduledNotExecuted));
            details.put("pull tasks", String.valueOf(pullTaskSize));
            details.put("pull tasks not executed", String.valueOf(pullNotExecuted));
            details.put("pull tasks with full reconciliation", String.valueOf(pullFull));
            details.put("jobs", String.valueOf(jobsSize));
            taskResultManager.printDetails(details);
        } catch (final SyncopeClientException ex) {
            LOG.error("Error reading details about task", ex);
            taskResultManager.genericError(ex.getMessage());
        } catch (final IllegalArgumentException ex) {
            LOG.error("Error reading details about task", ex);
            taskResultManager.typeNotValidError("task", input.firstParameter(), CommandUtils.fromEnumToArray(TaskType.class));
        }
    } else {
        taskResultManager.commandOptionError(DETAILS_HELP_MESSAGE);
    }
}
Also used : NotificationTaskTO(org.apache.syncope.common.lib.to.NotificationTaskTO) CommandUtils(org.apache.syncope.client.cli.util.CommandUtils) PushTaskTO(org.apache.syncope.common.lib.to.PushTaskTO) Logger(org.slf4j.Logger) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) TaskTO(org.apache.syncope.common.lib.to.TaskTO) PullMode(org.apache.syncope.common.lib.types.PullMode) LoggerFactory(org.slf4j.LoggerFactory) LinkedHashMap(java.util.LinkedHashMap) List(java.util.List) PropagationTaskTO(org.apache.syncope.common.lib.to.PropagationTaskTO) SchedTaskTO(org.apache.syncope.common.lib.to.SchedTaskTO) Input(org.apache.syncope.client.cli.Input) Map(java.util.Map) PullTaskTO(org.apache.syncope.common.lib.to.PullTaskTO) JobTO(org.apache.syncope.common.lib.to.JobTO) TaskType(org.apache.syncope.common.lib.types.TaskType) NotificationTaskTO(org.apache.syncope.common.lib.to.NotificationTaskTO) PushTaskTO(org.apache.syncope.common.lib.to.PushTaskTO) TaskTO(org.apache.syncope.common.lib.to.TaskTO) PropagationTaskTO(org.apache.syncope.common.lib.to.PropagationTaskTO) SchedTaskTO(org.apache.syncope.common.lib.to.SchedTaskTO) PullTaskTO(org.apache.syncope.common.lib.to.PullTaskTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) JobTO(org.apache.syncope.common.lib.to.JobTO) LinkedHashMap(java.util.LinkedHashMap)

Example 5 with SchedTaskTO

use of org.apache.syncope.common.lib.to.SchedTaskTO in project syncope by apache.

the class TaskDataBinderImpl method getTaskTO.

@Override
public <T extends TaskTO> T getTaskTO(final Task task, final TaskUtils taskUtils, final boolean details) {
    T taskTO = taskUtils.newTaskTO();
    BeanUtils.copyProperties(task, taskTO, IGNORE_TASK_PROPERTIES);
    TaskExec latestExec = taskExecDAO.findLatestStarted(task);
    if (latestExec == null) {
        taskTO.setLatestExecStatus(StringUtils.EMPTY);
    } else {
        taskTO.setLatestExecStatus(latestExec.getStatus());
        taskTO.setStart(latestExec.getStart());
        taskTO.setEnd(latestExec.getEnd());
    }
    if (details) {
        task.getExecs().stream().filter(execution -> execution != null).forEachOrdered(execution -> taskTO.getExecutions().add(getExecTO(execution)));
    }
    switch(taskUtils.getType()) {
        case PROPAGATION:
            PropagationTask propagationTask = (PropagationTask) task;
            PropagationTaskTO propagationTaskTO = (PropagationTaskTO) taskTO;
            propagationTaskTO.setAnyTypeKind(propagationTask.getAnyTypeKind());
            propagationTaskTO.setEntityKey(propagationTask.getEntityKey());
            propagationTaskTO.setResource(propagationTask.getResource().getKey());
            propagationTaskTO.setAttributes(propagationTask.getSerializedAttributes());
            break;
        case SCHEDULED:
            SchedTask schedTask = (SchedTask) task;
            SchedTaskTO schedTaskTO = (SchedTaskTO) taskTO;
            setExecTime(schedTaskTO, task);
            if (schedTask.getJobDelegate() != null) {
                schedTaskTO.setJobDelegate(schedTask.getJobDelegate().getKey());
            }
            break;
        case PULL:
            PullTask pullTask = (PullTask) task;
            PullTaskTO pullTaskTO = (PullTaskTO) taskTO;
            setExecTime(pullTaskTO, task);
            pullTaskTO.setDestinationRealm(pullTask.getDestinatioRealm().getFullPath());
            pullTaskTO.setResource(pullTask.getResource().getKey());
            pullTaskTO.setMatchingRule(pullTask.getMatchingRule() == null ? MatchingRule.UPDATE : pullTask.getMatchingRule());
            pullTaskTO.setUnmatchingRule(pullTask.getUnmatchingRule() == null ? UnmatchingRule.PROVISION : pullTask.getUnmatchingRule());
            if (pullTask.getReconFilterBuilder() != null) {
                pullTaskTO.setReconFilterBuilder(pullTask.getReconFilterBuilder().getKey());
            }
            pullTaskTO.getActions().addAll(pullTask.getActions().stream().map(Entity::getKey).collect(Collectors.toList()));
            pullTask.getTemplates().forEach(template -> {
                pullTaskTO.getTemplates().put(template.getAnyType().getKey(), template.get());
            });
            pullTaskTO.setRemediation(pullTask.isRemediation());
            break;
        case PUSH:
            PushTask pushTask = (PushTask) task;
            PushTaskTO pushTaskTO = (PushTaskTO) taskTO;
            setExecTime(pushTaskTO, task);
            pushTaskTO.setSourceRealm(pushTask.getSourceRealm().getFullPath());
            pushTaskTO.setResource(pushTask.getResource().getKey());
            pushTaskTO.setMatchingRule(pushTask.getMatchingRule() == null ? MatchingRule.LINK : pushTask.getMatchingRule());
            pushTaskTO.setUnmatchingRule(pushTask.getUnmatchingRule() == null ? UnmatchingRule.ASSIGN : pushTask.getUnmatchingRule());
            pushTaskTO.getActions().addAll(pushTask.getActions().stream().map(Entity::getKey).collect(Collectors.toList()));
            pushTask.getFilters().forEach(filter -> {
                pushTaskTO.getFilters().put(filter.getAnyType().getKey(), filter.getFIQLCond());
            });
            break;
        case NOTIFICATION:
            NotificationTask notificationTask = (NotificationTask) task;
            NotificationTaskTO notificationTaskTO = (NotificationTaskTO) taskTO;
            notificationTaskTO.setNotification(notificationTask.getNotification().getKey());
            notificationTaskTO.setAnyTypeKind(notificationTask.getAnyTypeKind());
            notificationTaskTO.setEntityKey(notificationTask.getEntityKey());
            if (notificationTask.isExecuted() && StringUtils.isBlank(taskTO.getLatestExecStatus())) {
                taskTO.setLatestExecStatus("[EXECUTED]");
            }
            break;
        default:
    }
    return taskTO;
}
Also used : SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) TaskTO(org.apache.syncope.common.lib.to.TaskTO) LoggerFactory(org.slf4j.LoggerFactory) AnyType(org.apache.syncope.core.persistence.api.entity.AnyType) Autowired(org.springframework.beans.factory.annotation.Autowired) NotificationTask(org.apache.syncope.core.persistence.api.entity.task.NotificationTask) Entity(org.apache.syncope.core.persistence.api.entity.Entity) StringUtils(org.apache.commons.lang3.StringUtils) PropagationTask(org.apache.syncope.core.persistence.api.entity.task.PropagationTask) Scheduler(org.quartz.Scheduler) PropagationTaskTO(org.apache.syncope.common.lib.to.PropagationTaskTO) SchedTaskTO(org.apache.syncope.common.lib.to.SchedTaskTO) ProvisioningTaskTO(org.apache.syncope.common.lib.to.ProvisioningTaskTO) TaskExecDAO(org.apache.syncope.core.persistence.api.dao.TaskExecDAO) SchedulerFactoryBean(org.springframework.scheduling.quartz.SchedulerFactoryBean) ImplementationDAO(org.apache.syncope.core.persistence.api.dao.ImplementationDAO) NotificationTaskTO(org.apache.syncope.common.lib.to.NotificationTaskTO) PullJobDelegate(org.apache.syncope.core.provisioning.java.pushpull.PullJobDelegate) ExecTO(org.apache.syncope.common.lib.to.ExecTO) Task(org.apache.syncope.core.persistence.api.entity.task.Task) JobNamer(org.apache.syncope.core.provisioning.api.job.JobNamer) Implementation(org.apache.syncope.core.persistence.api.entity.Implementation) Collectors(java.util.stream.Collectors) UnmatchingRule(org.apache.syncope.common.lib.types.UnmatchingRule) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) AnyTypeDAO(org.apache.syncope.core.persistence.api.dao.AnyTypeDAO) ImplementationEngine(org.apache.syncope.common.lib.types.ImplementationEngine) EntityFactory(org.apache.syncope.core.persistence.api.entity.EntityFactory) AnyTemplatePullTask(org.apache.syncope.core.persistence.api.entity.task.AnyTemplatePullTask) TaskUtilsFactory(org.apache.syncope.core.persistence.api.entity.task.TaskUtilsFactory) ProvisioningTask(org.apache.syncope.core.persistence.api.entity.task.ProvisioningTask) TriggerKey(org.quartz.TriggerKey) ExternalResourceDAO(org.apache.syncope.core.persistence.api.dao.ExternalResourceDAO) TaskDataBinder(org.apache.syncope.core.provisioning.api.data.TaskDataBinder) BeanUtils(org.apache.syncope.core.spring.BeanUtils) PullTask(org.apache.syncope.core.persistence.api.entity.task.PullTask) SchedulerException(org.quartz.SchedulerException) Trigger(org.quartz.Trigger) ImplementationType(org.apache.syncope.common.lib.types.ImplementationType) TaskExec(org.apache.syncope.core.persistence.api.entity.task.TaskExec) ClientExceptionType(org.apache.syncope.common.lib.types.ClientExceptionType) SchedTask(org.apache.syncope.core.persistence.api.entity.task.SchedTask) RealmDAO(org.apache.syncope.core.persistence.api.dao.RealmDAO) TemplateUtils(org.apache.syncope.core.provisioning.java.utils.TemplateUtils) PushJobDelegate(org.apache.syncope.core.provisioning.java.pushpull.PushJobDelegate) PushTaskTO(org.apache.syncope.common.lib.to.PushTaskTO) Logger(org.slf4j.Logger) PushTaskAnyFilter(org.apache.syncope.core.persistence.api.entity.task.PushTaskAnyFilter) TaskUtils(org.apache.syncope.core.persistence.api.entity.task.TaskUtils) ExternalResource(org.apache.syncope.core.persistence.api.entity.resource.ExternalResource) PushTask(org.apache.syncope.core.persistence.api.entity.task.PushTask) Component(org.springframework.stereotype.Component) PullTaskTO(org.apache.syncope.common.lib.to.PullTaskTO) JobType(org.apache.syncope.common.lib.types.JobType) MatchingRule(org.apache.syncope.common.lib.types.MatchingRule) TaskType(org.apache.syncope.common.lib.types.TaskType) Entity(org.apache.syncope.core.persistence.api.entity.Entity) NotificationTask(org.apache.syncope.core.persistence.api.entity.task.NotificationTask) PropagationTask(org.apache.syncope.core.persistence.api.entity.task.PropagationTask) PropagationTaskTO(org.apache.syncope.common.lib.to.PropagationTaskTO) PushTask(org.apache.syncope.core.persistence.api.entity.task.PushTask) SchedTask(org.apache.syncope.core.persistence.api.entity.task.SchedTask) SchedTaskTO(org.apache.syncope.common.lib.to.SchedTaskTO) AnyTemplatePullTask(org.apache.syncope.core.persistence.api.entity.task.AnyTemplatePullTask) PullTask(org.apache.syncope.core.persistence.api.entity.task.PullTask) TaskExec(org.apache.syncope.core.persistence.api.entity.task.TaskExec) PushTaskTO(org.apache.syncope.common.lib.to.PushTaskTO) PullTaskTO(org.apache.syncope.common.lib.to.PullTaskTO) NotificationTaskTO(org.apache.syncope.common.lib.to.NotificationTaskTO)

Aggregations

SchedTaskTO (org.apache.syncope.common.lib.to.SchedTaskTO)9 Test (org.junit.jupiter.api.Test)5 Response (javax.ws.rs.core.Response)3 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)3 ExecTO (org.apache.syncope.common.lib.to.ExecTO)3 ImplementationTO (org.apache.syncope.common.lib.to.ImplementationTO)3 TaskService (org.apache.syncope.common.rest.api.service.TaskService)3 TestSampleJobDelegate (org.apache.syncope.fit.core.reference.TestSampleJobDelegate)3 Map (java.util.Map)2 JobTO (org.apache.syncope.common.lib.to.JobTO)2 NotificationTaskTO (org.apache.syncope.common.lib.to.NotificationTaskTO)2 PropagationTaskTO (org.apache.syncope.common.lib.to.PropagationTaskTO)2 PullTaskTO (org.apache.syncope.common.lib.to.PullTaskTO)2 PushTaskTO (org.apache.syncope.common.lib.to.PushTaskTO)2 TaskTO (org.apache.syncope.common.lib.to.TaskTO)2 TaskType (org.apache.syncope.common.lib.types.TaskType)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 URI (java.net.URI)1 Date (java.util.Date)1