Search in sources :

Example 1 with SimpleTaskTrigger

use of eu.bcvsolutions.idm.core.scheduler.api.dto.SimpleTaskTrigger in project CzechIdMng by bcvsolutions.

the class AbstractScheduledTaskInitializer method getTrigger.

/**
 * Method return {@link AbstractTaskTrigger} from
 * {@link IdmScheduledTaskTriggerType}
 *
 * @param triggerType
 * @return
 * @throws ClassNotFoundException
 */
protected AbstractTaskTrigger getTrigger(IdmScheduledTaskTriggerType triggerType) throws ClassNotFoundException {
    @SuppressWarnings("unchecked") Class<AbstractTaskTrigger> triggerClass = (Class<AbstractTaskTrigger>) Class.forName(triggerType.getType());
    if (triggerClass.isAssignableFrom(SimpleTaskTrigger.class)) {
        SimpleTaskTrigger simpleTrigger = new SimpleTaskTrigger();
        simpleTrigger = (SimpleTaskTrigger) setTriggerDefaultValues(simpleTrigger, triggerType);
        simpleTrigger.setFireTime(new DateTime(triggerType.getFireTime()));
        return simpleTrigger;
    } else if (triggerClass.isAssignableFrom(CronTaskTrigger.class)) {
        CronTaskTrigger cronTrigger = new CronTaskTrigger();
        cronTrigger = (CronTaskTrigger) setTriggerDefaultValues(cronTrigger, triggerType);
        cronTrigger.setCron(triggerType.getCron());
        return cronTrigger;
    } else {
        LOG.error("Trigger type: [{}] is not implemented, please override method getTrigger from AbstractScheduledTaskInitializer. " + "This trigger will be skipped.", triggerType.getType());
        return null;
    }
}
Also used : AbstractTaskTrigger(eu.bcvsolutions.idm.core.scheduler.api.dto.AbstractTaskTrigger) DateTime(org.joda.time.DateTime) CronTaskTrigger(eu.bcvsolutions.idm.core.scheduler.api.dto.CronTaskTrigger) SimpleTaskTrigger(eu.bcvsolutions.idm.core.scheduler.api.dto.SimpleTaskTrigger)

Example 2 with SimpleTaskTrigger

use of eu.bcvsolutions.idm.core.scheduler.api.dto.SimpleTaskTrigger in project CzechIdMng by bcvsolutions.

the class AbstractScheduledTaskInitializerTest method testInitTask.

@Test
public void testInitTask() {
    List<Task> tasks = schedulerService.getAllTasks();
    // found test task, other will be skip
    for (Task task : tasks) {
        if (task.getTaskType().equals(TestTaskExecutor.class)) {
            assertEquals(TEST_DESCRIPTION, task.getDescription());
            assertEquals(TEST_INSTANCE, task.getInstanceId());
            // assertEquals(InitTestScheduledTask.TEST_MODULE, task.getModule()); // module not working in Task
            Map<String, String> parameters = task.getParameters();
            assertEquals(3, parameters.size());
            String value1 = parameters.get(KEY_1);
            assertEquals(VALUE_1, value1);
            String value2 = parameters.get(KEY_2);
            assertEquals(VALUE_2, value2);
            String value3 = parameters.get(KEY_3);
            assertEquals(VALUE_3, value3);
            List<AbstractTaskTrigger> triggers = task.getTriggers();
            assertEquals(2, triggers.size());
            for (AbstractTaskTrigger trigger : triggers) {
                assertEquals(TaskTriggerState.ACTIVE, trigger.getState());
                if (trigger.getClass().equals(CronTaskTrigger.class)) {
                    CronTaskTrigger cronTrigger = (CronTaskTrigger) trigger;
                    assertEquals(TEST_CRON, cronTrigger.getCron());
                } else if (trigger.getClass().equals(SimpleTaskTrigger.class)) {
                    SimpleTaskTrigger simpleTrigger = (SimpleTaskTrigger) trigger;
                    assertEquals(TEST_FIRE_TIME, simpleTrigger.getFireTime());
                } else {
                    fail();
                }
            }
            // success
            return;
        }
    }
    // test task is not initialized
    fail();
}
Also used : AbstractTaskTrigger(eu.bcvsolutions.idm.core.scheduler.api.dto.AbstractTaskTrigger) Task(eu.bcvsolutions.idm.core.scheduler.api.dto.Task) CronTaskTrigger(eu.bcvsolutions.idm.core.scheduler.api.dto.CronTaskTrigger) SimpleTaskTrigger(eu.bcvsolutions.idm.core.scheduler.api.dto.SimpleTaskTrigger) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Example 3 with SimpleTaskTrigger

use of eu.bcvsolutions.idm.core.scheduler.api.dto.SimpleTaskTrigger in project CzechIdMng by bcvsolutions.

the class DefaultSchedulerManager method createTrigger.

@Override
public AbstractTaskTrigger createTrigger(String taskId, AbstractTaskTrigger trigger, boolean dryRun) {
    Assert.notNull(taskId, "Task identifier is required.");
    Assert.notNull(trigger, "Trigger is required.");
    // 
    // task has to support dry run mode
    Task task = getTask(taskId);
    Assert.notNull(task, "Task is required.");
    if (dryRun && !task.isSupportsDryRun()) {
        throw new DryRunNotSupportedException(task.getTaskType().getCanonicalName());
    }
    // 
    String triggerId = Key.createUniqueName(taskId);
    trigger.setId(triggerId);
    trigger.setTaskId(taskId);
    // TODO use of visitor pattern may be good
    if (trigger instanceof SimpleTaskTrigger) {
        createTriggerInternal(taskId, (SimpleTaskTrigger) trigger, dryRun);
    } else if (trigger instanceof CronTaskTrigger) {
        createTriggerInternal(taskId, (CronTaskTrigger) trigger, dryRun);
    } else if (trigger instanceof DependentTaskTrigger) {
        createTriggerInternal(taskId, (DependentTaskTrigger) trigger);
    } else {
        throw new SchedulerException(CoreResultCode.SCHEDULER_UNSUPPORTED_TASK_TRIGGER, ImmutableMap.of("trigger", trigger.getClass()));
    }
    return trigger;
}
Also used : Task(eu.bcvsolutions.idm.core.scheduler.api.dto.Task) SchedulerException(eu.bcvsolutions.idm.core.scheduler.exception.SchedulerException) DependentTaskTrigger(eu.bcvsolutions.idm.core.scheduler.api.dto.DependentTaskTrigger) IdmDependentTaskTrigger(eu.bcvsolutions.idm.core.scheduler.entity.IdmDependentTaskTrigger) DryRunNotSupportedException(eu.bcvsolutions.idm.core.scheduler.api.exception.DryRunNotSupportedException) CronTaskTrigger(eu.bcvsolutions.idm.core.scheduler.api.dto.CronTaskTrigger) SimpleTaskTrigger(eu.bcvsolutions.idm.core.scheduler.api.dto.SimpleTaskTrigger)

Example 4 with SimpleTaskTrigger

use of eu.bcvsolutions.idm.core.scheduler.api.dto.SimpleTaskTrigger in project CzechIdMng by bcvsolutions.

the class AbstractScheduledTaskInitializerTest method testInitTask.

@Test
public void testInitTask() {
    List<Task> tasks = schedulerService.getAllTasks();
    // found test task, other will be skip
    for (Task task : tasks) {
        if (task.getTaskType().equals(TestTaskExecutor.class)) {
            assertEquals(TEST_DESCRIPTION, task.getDescription());
            assertEquals(TEST_INSTANCE, task.getInstanceId());
            // assertEquals(InitTestScheduledTask.TEST_MODULE, task.getModule()); // module not working in Task
            Map<String, String> parameters = task.getParameters();
            assertEquals(4, parameters.size());
            String value1 = parameters.get(KEY_1);
            assertEquals(VALUE_1, value1);
            String value2 = parameters.get(KEY_2);
            assertEquals(VALUE_2, value2);
            String value3 = parameters.get(KEY_3);
            assertEquals(VALUE_3, value3);
            Assert.assertNotNull(parameters.get(SchedulableTaskExecutor.PARAMETER_MODIFIED));
            List<AbstractTaskTrigger> triggers = task.getTriggers();
            assertEquals(2, triggers.size());
            for (AbstractTaskTrigger trigger : triggers) {
                assertEquals(TaskTriggerState.ACTIVE, trigger.getState());
                if (trigger.getClass().equals(CronTaskTrigger.class)) {
                    CronTaskTrigger cronTrigger = (CronTaskTrigger) trigger;
                    assertEquals(TEST_CRON, cronTrigger.getCron());
                } else if (trigger.getClass().equals(SimpleTaskTrigger.class)) {
                    SimpleTaskTrigger simpleTrigger = (SimpleTaskTrigger) trigger;
                    assertEquals(TEST_FIRE_TIME, simpleTrigger.getFireTime());
                } else {
                    fail();
                }
            }
            // success
            return;
        }
    }
    // test task is not initialized
    fail();
}
Also used : AbstractTaskTrigger(eu.bcvsolutions.idm.core.scheduler.api.dto.AbstractTaskTrigger) Task(eu.bcvsolutions.idm.core.scheduler.api.dto.Task) CronTaskTrigger(eu.bcvsolutions.idm.core.scheduler.api.dto.CronTaskTrigger) SimpleTaskTrigger(eu.bcvsolutions.idm.core.scheduler.api.dto.SimpleTaskTrigger) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Example 5 with SimpleTaskTrigger

use of eu.bcvsolutions.idm.core.scheduler.api.dto.SimpleTaskTrigger in project CzechIdMng by bcvsolutions.

the class DefaultSchedulerManagerIntegrationTest method testMisfireHandlingSimpleTrigger.

@Test
public void testMisfireHandlingSimpleTrigger() {
    IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
    IdmIdentityDto identityOne = identityService.get(identity);
    Assert.assertNotEquals(identityOne.getUsername(), identityOne.getLastName());
    // 
    Task createTask = new Task();
    // 
    createTask.setInstanceId(configurationService.getInstanceId());
    createTask.setTaskType(TestUpdateIdentityTask.class);
    createTask.setDescription("test");
    createTask.getParameters().put(ObserveLongRunningTaskEndProcessor.RESULT_PROPERTY, identityOne.getUsername());
    // 
    Task taskOne = manager.createTask(createTask);
    Task task = manager.getTask(taskOne.getId());
    Function<String, Boolean> continueFunction = res -> {
        return !identityService.get(identity.getId()).getLastName().equals(identity.getUsername());
    };
    SimpleTaskTrigger trigger = new SimpleTaskTrigger();
    trigger.setTaskId(task.getId());
    trigger.setFireTime(ZonedDateTime.now().minusMinutes(10));
    manager.createTrigger(task.getId(), trigger);
    // 
    getHelper().waitForResult(continueFunction);
    // 
    identityOne = identityService.get(identityOne);
    Assert.assertEquals(identityOne.getUsername(), identityOne.getLastName());
}
Also used : IdmDependentTaskTriggerRepository(eu.bcvsolutions.idm.core.scheduler.repository.IdmDependentTaskTriggerRepository) IdentityRoleExpirationTaskExecutor(eu.bcvsolutions.idm.core.scheduler.task.impl.IdentityRoleExpirationTaskExecutor) DependentTaskTrigger(eu.bcvsolutions.idm.core.scheduler.api.dto.DependentTaskTrigger) Date(java.util.Date) SimpleTaskTrigger(eu.bcvsolutions.idm.core.scheduler.api.dto.SimpleTaskTrigger) ZonedDateTime(java.time.ZonedDateTime) Key(org.quartz.utils.Key) Autowired(org.springframework.beans.factory.annotation.Autowired) ConfigurationService(eu.bcvsolutions.idm.core.api.service.ConfigurationService) ObserveLongRunningTaskEndProcessor(eu.bcvsolutions.idm.core.scheduler.ObserveLongRunningTaskEndProcessor) Function(java.util.function.Function) Scheduler(org.quartz.Scheduler) AutowireHelper(eu.bcvsolutions.idm.core.api.utils.AutowireHelper) TriggerBuilder(org.quartz.TriggerBuilder) InvalidCronExpressionException(eu.bcvsolutions.idm.core.scheduler.exception.InvalidCronExpressionException) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) LongRunningTaskExecuteDependentProcessor(eu.bcvsolutions.idm.core.scheduler.event.processor.LongRunningTaskExecuteDependentProcessor) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) LongRunningTaskEventType(eu.bcvsolutions.idm.core.scheduler.api.event.LongRunningTaskEvent.LongRunningTaskEventType) SimpleScheduleBuilder(org.quartz.SimpleScheduleBuilder) EventResult(eu.bcvsolutions.idm.core.api.event.EventResult) Task(eu.bcvsolutions.idm.core.scheduler.api.dto.Task) Before(org.junit.Before) IdmScheduledTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmScheduledTaskDto) LongRunningTaskManager(eu.bcvsolutions.idm.core.scheduler.api.service.LongRunningTaskManager) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState) Test(org.junit.Test) UUID(java.util.UUID) ApplicationContext(org.springframework.context.ApplicationContext) DateUtils(org.apache.commons.lang3.time.DateUtils) ExecutionException(java.util.concurrent.ExecutionException) IdmScheduledTaskService(eu.bcvsolutions.idm.core.scheduler.api.service.IdmScheduledTaskService) List(java.util.List) IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) CoreResultCode(eu.bcvsolutions.idm.core.api.domain.CoreResultCode) AbstractTaskTrigger(eu.bcvsolutions.idm.core.scheduler.api.dto.AbstractTaskTrigger) CronTaskTrigger(eu.bcvsolutions.idm.core.scheduler.api.dto.CronTaskTrigger) LongRunningTaskEvent(eu.bcvsolutions.idm.core.scheduler.api.event.LongRunningTaskEvent) IdmIdentityService(eu.bcvsolutions.idm.core.api.service.IdmIdentityService) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) Assert(org.junit.Assert) SchedulerException(eu.bcvsolutions.idm.core.scheduler.exception.SchedulerException) DryRunNotSupportedException(eu.bcvsolutions.idm.core.scheduler.api.exception.DryRunNotSupportedException) Task(eu.bcvsolutions.idm.core.scheduler.api.dto.Task) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) SimpleTaskTrigger(eu.bcvsolutions.idm.core.scheduler.api.dto.SimpleTaskTrigger) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Aggregations

SimpleTaskTrigger (eu.bcvsolutions.idm.core.scheduler.api.dto.SimpleTaskTrigger)11 CronTaskTrigger (eu.bcvsolutions.idm.core.scheduler.api.dto.CronTaskTrigger)7 AbstractTaskTrigger (eu.bcvsolutions.idm.core.scheduler.api.dto.AbstractTaskTrigger)6 Task (eu.bcvsolutions.idm.core.scheduler.api.dto.Task)6 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)4 Test (org.junit.Test)4 DependentTaskTrigger (eu.bcvsolutions.idm.core.scheduler.api.dto.DependentTaskTrigger)3 IdmLongRunningTaskDto (eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto)2 DryRunNotSupportedException (eu.bcvsolutions.idm.core.scheduler.api.exception.DryRunNotSupportedException)2 IdmDependentTaskTrigger (eu.bcvsolutions.idm.core.scheduler.entity.IdmDependentTaskTrigger)2 SchedulerException (eu.bcvsolutions.idm.core.scheduler.exception.SchedulerException)2 DateTime (org.joda.time.DateTime)2 CoreResultCode (eu.bcvsolutions.idm.core.api.domain.CoreResultCode)1 OperationState (eu.bcvsolutions.idm.core.api.domain.OperationState)1 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)1 OperationResult (eu.bcvsolutions.idm.core.api.entity.OperationResult)1 EventResult (eu.bcvsolutions.idm.core.api.event.EventResult)1 CoreException (eu.bcvsolutions.idm.core.api.exception.CoreException)1 ConfigurationService (eu.bcvsolutions.idm.core.api.service.ConfigurationService)1 IdmIdentityService (eu.bcvsolutions.idm.core.api.service.IdmIdentityService)1