use of eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringResultDto in project CzechIdMng by bcvsolutions.
the class DefaultMonitoringManager method getLastResults.
@Override
public Page<IdmMonitoringResultDto> getLastResults(IdmMonitoringResultFilter filter, Pageable pageable, BasePermission... permission) {
// all instances => last results should be visible on each instance
IdmMonitoringFilter monitoringFilter = new IdmMonitoringFilter();
if (filter != null) {
monitoringFilter.setId(filter.getMonitoring());
}
monitoringFilter.setDisabled(Boolean.FALSE);
//
List<IdmMonitoringDto> monitorings = monitoringService.find(monitoringFilter, PageRequest.of(0, Integer.MAX_VALUE, Sort.by(IdmMonitoring_.seq.getName())), PermissionUtils.isEmpty(permission) ? null : IdmBasePermission.AUTOCOMPLETE).getContent();
//
// last results sorted by monitoring order
List<IdmMonitoringResultDto> results = new ArrayList<>(monitorings.size());
for (IdmMonitoringDto monitoring : monitorings) {
MonitoringEvaluator evaluator = getEvaluator(monitoring);
if (evaluator == null) {
LOG.debug("Monitoring evaluator for motitoring configuration [{}] not exists.", monitoring.getId());
continue;
}
IdmMonitoringResultDto lastResult = getLastResult(monitoring.getId(), permission);
if (lastResult == null) {
continue;
}
// filter by level
NotificationLevel lastResultLevel = lastResult.getLevel();
List<NotificationLevel> levels = filter == null ? null : filter.getLevels();
if (CollectionUtils.isNotEmpty(levels) && !levels.contains(lastResultLevel)) {
continue;
}
lastResult.setTrimmed(true);
results.add(lastResult);
}
//
// pageable is required internally
Pageable internalPageable;
if (pageable == null) {
internalPageable = PageRequest.of(0, Integer.MAX_VALUE);
} else {
internalPageable = pageable;
}
//
// Sort by level desc
results.sort((r1, r2) -> {
return ObjectUtils.compare(r2.getLevel(), r1.getLevel());
});
//
// "naive" pagination
int first = internalPageable.getPageNumber() * internalPageable.getPageSize();
int last = internalPageable.getPageSize() + first;
List<IdmMonitoringResultDto> page = results.subList(first < results.size() ? first : results.size() > 0 ? results.size() - 1 : 0, last < results.size() ? last : results.size());
//
return new PageImpl<>(page, internalPageable, results.size());
}
use of eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringResultDto in project CzechIdMng by bcvsolutions.
the class EntityEventLockQueueMonitoringEvaluator method evaluate.
@Override
public IdmMonitoringResultDto evaluate(IdmMonitoringDto monitoring) {
long treshold = getParameterConverter().toLong(monitoring.getEvaluatorProperties(), PARAMETER_THRESHOLD, DEFAULT_THRESHOLD);
long count = LOCK.getQueueLength();
ResultModel resultModel = new DefaultResultModel(CoreResultCode.MONITORING_EVENT_LOCK_QUEUE, ImmutableMap.of("count", Long.toString(count)));
IdmMonitoringResultDto result = new IdmMonitoringResultDto();
result.setValue(Long.toString(count));
result.setResult(new OperationResultDto.Builder(OperationState.EXECUTED).setModel(resultModel).build());
if (treshold < count) {
result.setLevel(NotificationLevel.WARNING);
}
//
return result;
}
use of eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringResultDto in project CzechIdMng by bcvsolutions.
the class H2DatabaseMonitoringEvaluator method evaluate.
@Override
public IdmMonitoringResultDto evaluate(IdmMonitoringDto monitoring) {
ResultModel resultModel;
//
String resolvedDbName = flywayMigrationStrategy.resolveDbName(dataSource);
if (IdmFlywayMigrationStrategy.H2_DBNAME.equals(resolvedDbName)) {
if (applicationConfiguration.isProduction()) {
resultModel = new DefaultResultModel(CoreResultCode.MONITORING_H2_DATABASE_ERROR, ImmutableMap.of("instanceId", monitoring.getInstanceId()));
} else {
resultModel = new DefaultResultModel(CoreResultCode.MONITORING_H2_DATABASE_WARNING, ImmutableMap.of("instanceId", monitoring.getInstanceId(), "stage", applicationConfiguration.getStage()));
}
} else {
resultModel = new DefaultResultModel(CoreResultCode.MONITORING_H2_DATABASE_SUCCESS, ImmutableMap.of("instanceId", monitoring.getInstanceId(), "databaseName", resolvedDbName));
}
//
IdmMonitoringResultDto result = new IdmMonitoringResultDto();
result.setValue(resolvedDbName);
result.setResult(new OperationResultDto.Builder(OperationState.EXECUTED).setModel(resultModel).build());
//
return result;
}
use of eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringResultDto in project CzechIdMng by bcvsolutions.
the class MonitoringReportExecutor method generateData.
@Override
protected IdmAttachmentDto generateData(RptReportDto report) {
// prepare temp file for json stream
File temp = getAttachmentManager().createTempFile();
//
try (FileOutputStream outputStream = new FileOutputStream(temp)) {
// write into json stream
JsonGenerator jGenerator = getMapper().getFactory().createGenerator(outputStream, JsonEncoding.UTF8);
try {
// json will be array of identities
jGenerator.writeStartArray();
//
List<IdmMonitoringResultDto> lastResults = monitoringManager.getLastResults(null, null, IdmBasePermission.READ).getContent();
counter = 0L;
count = Long.valueOf(lastResults.size());
boolean canContinue = true;
for (IdmMonitoringResultDto result : lastResults) {
IdmMonitoringDto monitoring = getLookupService().lookupEmbeddedDto(result, IdmMonitoringResult_.monitoring);
//
RptMonitoringResultDto resultDto = new RptMonitoringResultDto(result);
resultDto.setResultMessage(result.getResult().getModel() == null ? null : result.getResult().getModel().getMessage());
resultDto.setOwnerType(result.getOwnerType());
resultDto.setOwnerId(result.getOwnerId());
resultDto.setValue(result.getValue());
resultDto.setLevel(result.getLevel() == null ? NotificationLevel.SUCCESS : result.getLevel());
resultDto.setEvaluatorType(result.getEvaluatorType());
resultDto.setEvaluatorDescription(monitoring.getDescription());
resultDto.setInstanceId(result.getInstanceId());
//
// write dto into json
getMapper().writeValue(jGenerator, resultDto);
//
// supports cancel report generating (report extends long running task)
++counter;
canContinue = updateState();
if (!canContinue) {
break;
}
}
//
// close array of identities
jGenerator.writeEndArray();
} finally {
// close json stream
jGenerator.close();
}
// save create temp file with array of identities in json as attachment
return createAttachment(report, new FileInputStream(temp));
} catch (IOException ex) {
throw new ReportGenerateException(report.getName(), ex);
} finally {
FileUtils.deleteQuietly(temp);
}
}
use of eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringResultDto in project CzechIdMng by bcvsolutions.
the class SynchronizationMonitoringEvaluatorIntegrationTest method testSynchronizationNotRun.
@Test
public void testSynchronizationNotRun() {
UUID syncId = UUID.randomUUID();
SysSyncConfigDto config = new SysSyncConfigDto();
config.setName("mock");
SysSystemMappingDto mapping = new SysSystemMappingDto();
config.getEmbedded().put(SysSyncConfig_.systemMapping.getName(), mapping);
SysSchemaObjectClassDto schema = new SysSchemaObjectClassDto();
schema.setSystem(syncId);
mapping.getEmbedded().put(SysSystemMapping_.objectClass.getName(), schema);
SysSystemDto system = new SysSystemDto(UUID.randomUUID());
system.setName("mock");
//
SysSyncConfigFilter context = new SysSyncConfigFilter();
context.setIncludeLastLog(Boolean.TRUE);
Mockito.when(syncConfigService.get(ArgumentMatchers.any(), (SysSyncConfigFilter) ArgumentMatchers.any())).thenReturn(config);
Mockito.when(systemService.get(syncId)).thenReturn(system);
//
IdmMonitoringDto monitoring = new IdmMonitoringDto();
monitoring.getEvaluatorProperties().put(SynchronizationMonitoringEvaluator.PARAMETER_SYNCHRONIZATION, syncId);
IdmMonitoringResultDto result = evaluator.evaluate(monitoring);
//
Assert.assertEquals(AccResultCode.MONITORING_SYNCHRONIZATION_NOT_EXECUTED.getCode(), result.getResult().getCode());
}
Aggregations