use of eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringResultDto in project CzechIdMng by bcvsolutions.
the class LongRunningTaskResultMonitoringEvaluator method evaluate.
@Override
public IdmMonitoringResultDto evaluate(IdmMonitoringDto monitoring) {
IdmMonitoringResultDto result = new IdmMonitoringResultDto();
ResultModel resultModel;
//
IdmProcessedTaskItemFilter filter = new IdmProcessedTaskItemFilter();
filter.setOperationState(OperationState.EXCEPTION);
filter.setTaskMonitoringIgnored(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 = processedTaskItemService.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;
}
use of eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringResultDto in project CzechIdMng by bcvsolutions.
the class MonitoringResultRunBulkActionIntegrationTest method testRun.
@Test
public void testRun() {
IdmMonitoringResultDto monitoringResult = createDto();
IdmBulkActionDto bulkAction = findBulkAction(IdmMonitoringResult.class, MonitoringResultRunBulkAction.NAME);
Set<UUID> ids = Sets.newHashSet(monitoringResult.getId());
bulkAction.setIdentifiers(ids);
IdmBulkActionDto processAction = bulkActionManager.processAction(bulkAction);
checkResultLrt(processAction, 1l, null, null);
monitoringService.deleteById(monitoringResult.getMonitoring());
}
use of eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringResultDto in project CzechIdMng by bcvsolutions.
the class MonitoringResultRunBulkActionIntegrationTest method createDto.
protected IdmMonitoringResultDto createDto() {
IdmMonitoringDto monitoring = new IdmMonitoringDto();
monitoring.setCheckPeriod(0L);
monitoring.setEvaluatorType(AutowireHelper.getTargetType(h2DatabaseMonitoringEvaluator));
monitoring.setInstanceId(configurationService.getInstanceId());
monitoring = monitoringService.save(monitoring);
//
IdmMonitoringResultDto dto = new IdmMonitoringResultDto();
dto.setMonitoring(monitoring.getId());
dto.setEvaluatorType(AutowireHelper.getTargetType(h2DatabaseMonitoringEvaluator));
dto.setInstanceId(configurationService.getInstanceId());
dto.setResult(new OperationResultDto(OperationState.BLOCKED));
//
return monitoringResultService.save(dto);
}
use of eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringResultDto in project CzechIdMng by bcvsolutions.
the class DatabaseTableMonitoringEvaluatorUnitTest method testWarning.
@Test
public void testWarning() {
Mockito.when(context.getBean("mock")).thenReturn(identityService);
Mockito.when(identityService.count(ArgumentMatchers.any())).thenReturn(DatabaseTableMonitoringEvaluator.DEFAULT_THRESHOLD + 1);
Mockito.when(identityService.getEntityClass()).thenReturn(IdmIdentity.class);
Mockito.when(identityService.getDtoClass()).thenReturn(IdmIdentityDto.class);
//
IdmMonitoringDto monitoring = new IdmMonitoringDto();
monitoring.setInstanceId("mock");
monitoring.getEvaluatorProperties().put(DatabaseTableMonitoringEvaluator.PARAMETER_READ_SERVICE_BEAN_NAME, "mock");
IdmMonitoringResultDto result = evaluator.evaluate(monitoring);
//
Assert.assertEquals(CoreResultCode.MONITORING_DATABASE_TABLE.getCode(), result.getResult().getCode());
Assert.assertEquals(NotificationLevel.WARNING, result.getLevel());
Assert.assertEquals(String.valueOf(DatabaseTableMonitoringEvaluator.DEFAULT_THRESHOLD + 1), result.getValue());
}
use of eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringResultDto in project CzechIdMng by bcvsolutions.
the class DemoAdminMonitoringEvaluatorUnitTest method testProductionWithDemoAdmin.
@Test
public void testProductionWithDemoAdmin() {
Mockito.when(applicationConfiguration.isDevelopment()).thenReturn(false);
Mockito.when(lookupService.lookupDto(IdmIdentityDto.class, InitAdminIdentityProcessor.ADMIN_USERNAME)).thenReturn(new IdmIdentityDto(InitAdminIdentityProcessor.ADMIN_USERNAME));
Mockito.when(authenticationManager.validate(ArgumentMatchers.any())).thenReturn(true);
//
IdmMonitoringDto monitoring = new IdmMonitoringDto();
monitoring.setInstanceId("mock");
IdmMonitoringResultDto result = evaluator.evaluate(monitoring);
//
Assert.assertEquals(CoreResultCode.MONITORING_DEMO_ADMIN_WARNING.getCode(), result.getResult().getCode());
Assert.assertEquals(NotificationLevel.ERROR, result.getLevel());
}
Aggregations