Search in sources :

Example 66 with IdmMonitoringDto

use of eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringDto in project CzechIdMng by bcvsolutions.

the class InitMonitoringProcessor method initH2DatabaseMonitoring.

protected IdmMonitoringDto initH2DatabaseMonitoring() {
    String instanceId = configurationService.getInstanceId();
    String evaluatorType = AutowireHelper.getTargetType(h2DatabaseMonitoringEvaluator);
    IdmMonitoringDto monitoring = findMonitoring(evaluatorType, instanceId, null);
    if (monitoring == null) {
        monitoring = new IdmMonitoringDto();
        monitoring.setEvaluatorType(evaluatorType);
        monitoring.setInstanceId(instanceId);
        // ~ application start only
        monitoring.setCheckPeriod(0L);
        // ~ quick
        monitoring.setSeq((short) 0);
        monitoring.setDescription(PRODUCT_PROVIDED_MONITORING_DESCRIPTION);
        // 
        monitoring = monitoringService.save(monitoring);
        LOG.info("H2 database monitoring for instance id [{}] configured automatically.", instanceId);
    }
    // 
    return monitoring;
}
Also used : IdmMonitoringDto(eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringDto)

Example 67 with IdmMonitoringDto

use of eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringDto in project CzechIdMng by bcvsolutions.

the class InitMonitoringProcessor method initLongRunningTaskMonitoring.

protected IdmMonitoringDto initLongRunningTaskMonitoring() {
    String evaluatorType = AutowireHelper.getTargetType(longRunningTaskMonitoringEvaluator);
    IdmMonitoringDto monitoring = findMonitoring(evaluatorType, null, null);
    if (monitoring == null) {
        monitoring = new IdmMonitoringDto();
        monitoring.setEvaluatorType(evaluatorType);
        monitoring.setInstanceId(configurationService.getInstanceId());
        // ~ per hour
        monitoring.setCheckPeriod(3600L);
        // ~ quick
        monitoring.setSeq((short) 0);
        monitoring.setDescription(PRODUCT_PROVIDED_MONITORING_DESCRIPTION);
        ConfigurationMap evaluatorProperties = new ConfigurationMap();
        evaluatorProperties.put(LongRunningTaskMonitoringEvaluator.PARAMETER_NUMBER_OF_DAYS, LongRunningTaskMonitoringEvaluator.DEFAULT_NUMBER_OF_DAYS);
        monitoring.setEvaluatorProperties(evaluatorProperties);
        // 
        monitoring = monitoringService.save(monitoring);
        LOG.info("Long running task monitoring configured automatically.");
    }
    // 
    return monitoring;
}
Also used : IdmMonitoringDto(eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringDto) ConfigurationMap(eu.bcvsolutions.idm.core.api.domain.ConfigurationMap)

Example 68 with IdmMonitoringDto

use of eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringDto in project CzechIdMng by bcvsolutions.

the class IdmMonitoringController method execute.

/**
 * Execute monitoring evaluator synchronously.
 *
 * @since 11.2.0
 */
@ResponseBody
@RequestMapping(method = RequestMethod.PUT, value = "/{backendId}/execute")
@PreAuthorize("hasAuthority('" + MonitoringGroupPermission.MONITORING_EXECUTE + "')")
@ApiOperation(value = "Execute monitoring evaluator", nickname = "executeMonitoring", tags = { IdmMonitoringController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = MonitoringGroupPermission.MONITORING_EXECUTE, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = MonitoringGroupPermission.MONITORING_EXECUTE, description = "") }) }, notes = "Execute monitoring evaluator synchronously.")
public ResponseEntity<?> execute(@ApiParam(value = "Monitoring codeable identifier.", required = true) @PathVariable @NotNull String backendId) {
    IdmMonitoringDto monitoring = getDto(backendId);
    if (monitoring == null) {
        throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("entity", backendId));
    }
    IdmMonitoringResultDto monitoringResult = monitoringManager.execute(monitoring, IdmBasePermission.EXECUTE);
    // without result
    if (monitoringResult == null) {
        new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }
    // return current result
    return new ResponseEntity<>(monitoringResultController.toResource(monitoringResult), HttpStatus.CREATED);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) IdmMonitoringDto(eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IdmMonitoringResultDto(eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringResultDto) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 69 with IdmMonitoringDto

use of eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringDto in project CzechIdMng by bcvsolutions.

the class DefaultMonitoringManager method execute.

@Override
public IdmMonitoringResultDto execute(IdmMonitoringDto monitoring, BasePermission... permission) {
    Assert.notNull(monitoring, "Monitoring is required.");
    // 
    EventContext<IdmMonitoringDto> context = monitoringService.publish(new MonitoringEvent(MonitoringEventType.EXECUTE, monitoring), permission);
    // with result
    for (EventResult<IdmMonitoringDto> eventResult : context.getResults()) {
        for (OperationResult operationResult : eventResult.getResults()) {
            ResultModel model = operationResult.getModel();
            if (model != null && CoreResultCode.MONITORING_RESULT.getCode().equals(model.getStatusEnum()) && model.getParameters().containsKey(EventResult.EVENT_PROPERTY_RESULT)) {
                return (IdmMonitoringResultDto) model.getParameters().get(EventResult.EVENT_PROPERTY_RESULT);
            }
        }
    }
    // without result (just for sure - e.g. wrong exception handling in custom monitoring evaluator)
    return null;
}
Also used : IdmMonitoringDto(eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringDto) MonitoringEvent(eu.bcvsolutions.idm.core.monitoring.api.event.MonitoringEvent) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) ResultModel(eu.bcvsolutions.idm.core.api.dto.ResultModel) IdmMonitoringResultDto(eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringResultDto)

Example 70 with IdmMonitoringDto

use of eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringDto in project CzechIdMng by bcvsolutions.

the class DefaultMonitoringManager method scheduleExecute.

/**
 * Spring schedule run all registered monitoring evaluators
 */
@Scheduled(fixedDelay = 10000)
public void scheduleExecute() {
    String instanceId = configurationService.getInstanceId();
    LOG.debug("Processing monitoring evaluators on instance id [{}]", instanceId);
    // 
    IdmMonitoringFilter filter = new IdmMonitoringFilter();
    filter.setDisabled(Boolean.FALSE);
    filter.setInstanceId(instanceId);
    // 
    List<IdmMonitoringDto> monitorings = monitoringService.find(filter, PageRequest.of(0, Integer.MAX_VALUE, Sort.by(IdmMonitoring_.seq.getName()))).getContent();
    // 
    for (IdmMonitoringDto monitoring : monitorings) {
        UUID monitoringId = monitoring.getId();
        // 
        // check execute date
        ZonedDateTime executeDate = monitoring.getExecuteDate();
        if (executeDate != null && ZonedDateTime.now().isBefore(executeDate)) {
            LOG.trace("Monitoring evaluator [{}] will be evaluted after [{}].", monitoringId, executeDate);
            // 
            continue;
        }
        // 
        // check last result is in period
        // seconds
        Long checkPeriod = monitoring.getCheckPeriod();
        if (checkPeriod == null) {
            checkPeriod = 0L;
        }
        // 
        IdmMonitoringResultDto lastResult = getLastResult(monitoringId);
        if (lastResult != null) {
            if (checkPeriod == 0 && firstExecuted) {
                LOG.trace("Monitoring evaluator [{}] was already executed.", monitoringId);
                // 
                continue;
            }
            // 
            if (lastResult.getCreated().isAfter(ZonedDateTime.now().minusSeconds(checkPeriod))) {
                LOG.trace("Monitoring evaluator [{}] was already executed.", monitoringId);
                // 
                continue;
            }
        }
        // 
        execute(monitoring);
    }
    // 
    firstExecuted = true;
}
Also used : IdmMonitoringFilter(eu.bcvsolutions.idm.core.monitoring.api.dto.filter.IdmMonitoringFilter) IdmMonitoringDto(eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringDto) ZonedDateTime(java.time.ZonedDateTime) UUID(java.util.UUID) IdmMonitoringResultDto(eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringResultDto) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Aggregations

IdmMonitoringDto (eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringDto)73 Test (org.junit.Test)46 IdmMonitoringResultDto (eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringResultDto)45 AbstractUnitTest (eu.bcvsolutions.idm.test.api.AbstractUnitTest)24 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)16 UUID (java.util.UUID)13 IdmMonitoringResultFilter (eu.bcvsolutions.idm.core.monitoring.api.dto.filter.IdmMonitoringResultFilter)10 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)6 SysSystemMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto)6 SysSyncConfigFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSyncConfigFilter)6 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)6 SysSchemaObjectClassDto (eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto)5 SysSyncConfigDto (eu.bcvsolutions.idm.acc.dto.SysSyncConfigDto)5 ConfigurationMap (eu.bcvsolutions.idm.core.api.domain.ConfigurationMap)5 OperationResultDto (eu.bcvsolutions.idm.core.api.dto.OperationResultDto)5 AbstractReadWriteDtoControllerRestTest (eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest)5 IdmMonitoringFilter (eu.bcvsolutions.idm.core.monitoring.api.dto.filter.IdmMonitoringFilter)5 DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)4 AutowireHelper (eu.bcvsolutions.idm.core.api.utils.AutowireHelper)4 IdmMonitoringService (eu.bcvsolutions.idm.core.monitoring.api.service.IdmMonitoringService)4