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;
}
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;
}
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);
}
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;
}
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;
}
Aggregations