Search in sources :

Example 36 with IdmLongRunningTaskFilter

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

the class AbstractBulkAction method end.

@Override
protected OperationResult end(OperationResult result, Exception ex) {
    OperationResult end = null;
    if (result != null && result.getException() != null) {
        end = super.end(result, (Exception) result.getException());
    } else {
        end = super.end(result, ex);
    }
    // 
    // send message
    IdmLongRunningTaskFilter filter = new IdmLongRunningTaskFilter();
    filter.setIncludeItemCounts(true);
    IdmLongRunningTaskDto task = getLongRunningTaskService().get(getLongRunningTaskId(), filter);
    // 
    if (task.getCreatorId() != null) {
        IdmIdentityDto identityDto = identityService.get(task.getCreatorId());
        ConfigurationService configurationService = getConfigurationService();
        if (identityDto != null) {
            notificationManager.send(CoreModule.TOPIC_BULK_ACTION_END, new IdmMessageDto.Builder().addParameter("action", getAction()).addParameter("task", task).addParameter("owner", identityDto).addParameter("result", end).addParameter("detailUrl", configurationService.getFrontendUrl(String.format("scheduler/all-tasks/%s/detail", task.getId()))).addParameter("processItemslUrl", configurationService.getFrontendUrl(String.format("scheduler/all-tasks/%s/items", task.getId()))).build(), identityDto);
        }
    }
    // 
    return end;
}
Also used : IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) IdmLongRunningTaskFilter(eu.bcvsolutions.idm.core.scheduler.api.dto.filter.IdmLongRunningTaskFilter) ConfigurationService(eu.bcvsolutions.idm.core.api.service.ConfigurationService) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) UnexpectedRollbackException(org.springframework.transaction.UnexpectedRollbackException) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException)

Example 37 with IdmLongRunningTaskFilter

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

the class IdmLongRunningTaskController method getDto.

@Override
public IdmLongRunningTaskDto getDto(Serializable backendId) {
    // FIXME: Propagate filter in GET method (in AbstractReadDto controller => requires lookup api improvement).
    IdmLongRunningTaskFilter filter = toFilter(null);
    // 
    IdmLongRunningTaskDto dto = getService().get(backendId, filter, IdmBasePermission.READ);
    if (dto == null) {
        return null;
    }
    dto.getEmbedded().put(IdmFormInstanceDto.PROPERTY_FORM_INSTANCE, longRunningTaskManager.getTaskFormInstance(dto));
    // 
    return dto;
}
Also used : IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) IdmLongRunningTaskFilter(eu.bcvsolutions.idm.core.scheduler.api.dto.filter.IdmLongRunningTaskFilter)

Example 38 with IdmLongRunningTaskFilter

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

the class IdmLongRunningTaskController method toFilter.

@Override
protected IdmLongRunningTaskFilter toFilter(MultiValueMap<String, Object> parameters) {
    IdmLongRunningTaskFilter filter = new IdmLongRunningTaskFilter(parameters, getParameterConverter());
    // counters are loaded from controller all times
    filter.setIncludeItemCounts(true);
    // 
    return filter;
}
Also used : IdmLongRunningTaskFilter(eu.bcvsolutions.idm.core.scheduler.api.dto.filter.IdmLongRunningTaskFilter)

Example 39 with IdmLongRunningTaskFilter

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

the class DefaultSynchronizationService method init.

/**
 * Cancel all previously ran synchronizations
 */
@Override
@Transactional
public void init() {
    String instanceId = configurationService.getInstanceId();
    LOG.info("Cancel unprocessed synchronizations - tasks was interrupt during instance [{}] restart", instanceId);
    // 
    // find all running sync on all instances
    IdmLongRunningTaskFilter lrtFilter = new IdmLongRunningTaskFilter();
    lrtFilter.setRunning(Boolean.TRUE);
    lrtFilter.setTaskType(SynchronizationSchedulableTaskExecutor.class.getCanonicalName());
    List<IdmLongRunningTaskDto> allRunningSynchronizations = longRunningTaskService.find(lrtFilter, null).getContent();
    // stop logs on the same instance id
    SysSyncLogFilter logFilter = new SysSyncLogFilter();
    logFilter.setRunning(Boolean.TRUE);
    synchronizationLogService.find(logFilter, null).forEach(sync -> {
        boolean runningOnOtherInstance = allRunningSynchronizations.stream().anyMatch(lrt -> {
            return !lrt.getInstanceId().equals(instanceId) && sync.getSynchronizationConfig().equals(lrt.getTaskProperties().get(PARAMETER_SYNCHRONIZATION_ID));
        });
        if (!runningOnOtherInstance) {
            String message = MessageFormat.format("Cancel unprocessed synchronization [{0}] - tasks was interrupt during instance [{1}] restart", sync.getId(), instanceId);
            LOG.info(message);
            sync.addToLog(message);
            sync.setRunning(false);
            synchronizationLogService.save(sync);
        }
    });
    // Clear the executor cache
    this.idmCacheManager.evictCache(SYNC_EXECUTOR_CACHE_NAME);
}
Also used : IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) SynchronizationSchedulableTaskExecutor(eu.bcvsolutions.idm.acc.scheduler.task.impl.SynchronizationSchedulableTaskExecutor) SysSyncLogFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSyncLogFilter) IdmLongRunningTaskFilter(eu.bcvsolutions.idm.core.scheduler.api.dto.filter.IdmLongRunningTaskFilter) Transactional(org.springframework.transaction.annotation.Transactional)

Example 40 with IdmLongRunningTaskFilter

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

the class LongRunningTaskMonitoringEvaluator method evaluate.

@Override
public IdmMonitoringResultDto evaluate(IdmMonitoringDto monitoring) {
    IdmMonitoringResultDto result = new IdmMonitoringResultDto();
    ResultModel resultModel;
    // 
    IdmLongRunningTaskFilter filter = new IdmLongRunningTaskFilter();
    filter.setOperationState(OperationState.EXCEPTION);
    filter.setMonitoringIgnored(Boolean.FALSE);
    Long givenNumberOfDays = getParameterConverter().toLong(monitoring.getEvaluatorProperties(), PARAMETER_NUMBER_OF_DAYS);
    if (givenNumberOfDays != null) {
        filter.setCreatedFrom(ZonedDateTime.now().truncatedTo(ChronoUnit.DAYS).minusDays(givenNumberOfDays));
    }
    long count = longRunningTaskService.count(filter);
    // 
    if (count > 0) {
        resultModel = new DefaultResultModel(CoreResultCode.MONITORING_LONG_RUNNING_TASK_ERROR, ImmutableMap.of("count", Long.toString(count)));
    } else {
        resultModel = new DefaultResultModel(CoreResultCode.OK);
    }
    // 
    result.setResult(new OperationResultDto.Builder(OperationState.EXECUTED).setModel(resultModel).build());
    result.setValue(String.valueOf(count));
    // 
    return result;
}
Also used : DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) ResultModel(eu.bcvsolutions.idm.core.api.dto.ResultModel) IdmLongRunningTaskFilter(eu.bcvsolutions.idm.core.scheduler.api.dto.filter.IdmLongRunningTaskFilter) IdmMonitoringResultDto(eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringResultDto)

Aggregations

IdmLongRunningTaskFilter (eu.bcvsolutions.idm.core.scheduler.api.dto.filter.IdmLongRunningTaskFilter)54 IdmLongRunningTaskDto (eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto)41 Test (org.junit.Test)31 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)21 UUID (java.util.UUID)18 Transactional (org.springframework.transaction.annotation.Transactional)11 AbstractBulkActionTest (eu.bcvsolutions.idm.test.api.AbstractBulkActionTest)9 OperationState (eu.bcvsolutions.idm.core.api.domain.OperationState)8 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)8 AcceptedException (eu.bcvsolutions.idm.core.api.exception.AcceptedException)8 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)8 List (java.util.List)8 Autowired (org.springframework.beans.factory.annotation.Autowired)8 LongRunningFutureTask (eu.bcvsolutions.idm.core.scheduler.api.dto.LongRunningFutureTask)7 Assert (org.junit.Assert)7 OperationResultDto (eu.bcvsolutions.idm.core.api.dto.OperationResultDto)6 IdmBulkActionDto (eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto)5 EventConfiguration (eu.bcvsolutions.idm.core.api.config.domain.EventConfiguration)5 AutomaticRoleAttributeRuleComparison (eu.bcvsolutions.idm.core.api.domain.AutomaticRoleAttributeRuleComparison)5 AutomaticRoleAttributeRuleType (eu.bcvsolutions.idm.core.api.domain.AutomaticRoleAttributeRuleType)5