use of eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto in project CzechIdMng by bcvsolutions.
the class AbstractLongRunningTaskExecutor method validate.
/**
* Validates task before start e.q. if task already running or to prevent run task concurrently.
*
* Look out: override this method additively
*
* @param task persisted task to validate
*/
@Override
public void validate(IdmLongRunningTaskDto task) {
Assert.notNull(task, "Long running task has to be prepared before task is started");
//
if (task.isRunning()) {
throw new ResultCodeException(CoreResultCode.LONG_RUNNING_TASK_IS_RUNNING, ImmutableMap.of("taskId", task.getId()));
}
if (!OperationState.isRunnable(task.getResultState())) {
throw new ResultCodeException(CoreResultCode.LONG_RUNNING_TASK_IS_PROCESSED, ImmutableMap.of("taskId", task.getId()));
}
//
if (this.getClass().isAnnotationPresent(DisallowConcurrentExecution.class)) {
IdmLongRunningTaskFilter filter = new IdmLongRunningTaskFilter();
filter.setTaskType(getName());
filter.setOperationState(OperationState.RUNNING);
List<IdmLongRunningTaskDto> runningTasks = longRunningTaskService.find(filter, null).getContent().stream().filter(t -> {
// not self
return !t.getId().equals(task.getId());
}).collect(Collectors.toList());
if (!runningTasks.isEmpty()) {
throw new ConcurrentExecutionException(CoreResultCode.LONG_RUNNING_TASK_IS_RUNNING, ImmutableMap.of("taskId", getName()));
}
}
}
use of eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto in project CzechIdMng by bcvsolutions.
the class AbstractLongRunningTaskExecutor method updateState.
@Override
public boolean updateState() {
// TODO: interface only + AOP => task can be ran directly without executor
if (longRunningTaskService == null || longRunningTaskId == null) {
return true;
}
longRunningTaskService.updateState(longRunningTaskId, count, counter);
//
IdmLongRunningTaskDto task = longRunningTaskService.get(longRunningTaskId);
if (task == null) {
return true;
}
return task.isRunning() && OperationState.isRunnable(task.getResultState());
}
use of eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto in project CzechIdMng by bcvsolutions.
the class AbstractLongRunningTaskExecutor method start.
/**
* Starts given task
* - persists task properties
*
* @return
*/
protected boolean start() {
Assert.notNull(longRunningTaskId);
IdmLongRunningTaskDto task = longRunningTaskService.get(longRunningTaskId);
//
validate(task);
//
Thread currentThread = Thread.currentThread();
task.setThreadId(currentThread.getId());
task.setThreadName(currentThread.getName());
//
setStateProperties(task);
//
task.setRunning(true);
task.setTaskStarted(DateTime.now());
task.setResult(new OperationResult.Builder(OperationState.RUNNING).build());
task.setStateful(isStateful());
Map<String, Object> taskProperties = task.getTaskProperties();
taskProperties.put(LongRunningTaskExecutor.PARAMETER_INSTANCE_ID, task.getInstanceId());
taskProperties.putAll(getProperties());
task.setTaskProperties(taskProperties);
task.setStateful(isStateful());
//
longRunningTaskService.save(task);
return true;
}
use of eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto in project CzechIdMng by bcvsolutions.
the class AbstractSchedulableTaskExecutor method createIdmLongRunningTask.
private IdmLongRunningTaskDto createIdmLongRunningTask(JobExecutionContext context, IdmScheduledTaskDto taskDto) {
IdmLongRunningTaskDto longRunningTask = new IdmLongRunningTaskDto();
longRunningTask.setTaskType(getClass().getCanonicalName());
longRunningTask.setTaskDescription(context.getJobDetail().getDescription());
longRunningTask.setTaskProperties(context.getMergedJobDataMap());
longRunningTask.setResult(new OperationResult.Builder(OperationState.CREATED).build());
longRunningTask.setInstanceId(context.getMergedJobDataMap().getString(SchedulableTaskExecutor.PARAMETER_INSTANCE_ID));
longRunningTask.setScheduledTask(taskDto.getId());
longRunningTask.setStateful(isStateful());
longRunningTask.setDryRun(context.getMergedJobDataMap().getBoolean(PARAMETER_DRY_RUN));
//
return longRunningTaskService.save(longRunningTask);
}
use of eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto in project CzechIdMng by bcvsolutions.
the class IdentityRoleValidRequestSchedulerTest method createNonValidRoleAndValid.
@Test
public void createNonValidRoleAndValid() throws InterruptedException, ExecutionException {
IdmIdentityDto identity = createAndSaveIdentity();
IdmRoleDto role = createAndSaveRole();
createAndSaveRoleSystem(role, system);
IdmTreeTypeDto treeType = createAndSaveTreeType();
IdmTreeNodeDto treeNode = createAndSaveTreeNode(treeType);
IdmIdentityContractDto identityContract = createAndSaveIdentityContract(identity, treeNode);
LocalDate validFrom = new LocalDate();
// set plus days
validFrom = validFrom.plusDays(5);
// provisioning is not executed, role isn't valid from now
createAndSaveIdentityRole(identityContract, role, null, validFrom);
AccIdentityAccountFilter filter = new AccIdentityAccountFilter();
filter.setIdentityId(identity.getId());
List<AccIdentityAccountDto> list = identityAccountService.find(filter, null).getContent();
// it must not exists
assertEquals(true, list.isEmpty());
//
IdentityRoleValidRequestTaskExecutor taskExecutor1 = new IdentityRoleValidRequestTaskExecutor();
LongRunningFutureTask<Boolean> futureTask1 = longRunningTaskManager.execute(taskExecutor1);
assertEquals(true, futureTask1.getFutureTask().get());
IdmLongRunningTaskDto longRunningTask1 = longRunningTaskService.get(taskExecutor1.getLongRunningTaskId());
assertEquals(OperationState.EXECUTED, longRunningTask1.getResult().getState());
list = identityAccountService.find(filter, null).getContent();
// still empty, role isn't valid
assertEquals(true, list.isEmpty());
List<IdmIdentityRole> roles = identityRoleRepository.findAllByIdentityContract_Identity_Id(identity.getId(), null);
assertEquals(1, roles.size());
IdmIdentityRole identityRole = roles.get(0);
validFrom = new LocalDate();
validFrom = validFrom.minusDays(5);
identityRole.setValidFrom(validFrom);
identityRoleRepository.save(identityRole);
// execute again
IdentityRoleValidRequestTaskExecutor taskExecutor2 = new IdentityRoleValidRequestTaskExecutor();
LongRunningFutureTask<Boolean> futureTask2 = longRunningTaskManager.execute(taskExecutor2);
assertEquals(true, futureTask2.getFutureTask().get());
IdmLongRunningTaskDto longRunningTask2 = longRunningTaskService.get(taskExecutor2.getLongRunningTaskId());
assertEquals(OperationState.EXECUTED, longRunningTask2.getResult().getState());
list = identityAccountService.find(filter, null).getContent();
assertEquals(false, list.isEmpty());
assertEquals(1, list.size());
// newly created accounts
assertNotNull(list.get(0));
}
Aggregations