use of eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringResultDto in project CzechIdMng by bcvsolutions.
the class DefaultMonitoringManagerIntegrationTest method testNotExecuteDisabledMonitoring.
@Test
public void testNotExecuteDisabledMonitoring() {
IdmMonitoringDto monitoring = new IdmMonitoringDto();
monitoring.setCheckPeriod(0L);
monitoring.setEvaluatorType(AutowireHelper.getTargetType(h2DatabaseMonitoringEvaluator));
monitoring.setInstanceId(configurationService.getInstanceId());
monitoring.setDisabled(true);
monitoring = monitoringService.save(monitoring);
try {
//
manager.scheduleExecute();
//
IdmMonitoringResultFilter filter = new IdmMonitoringResultFilter();
filter.setMonitoring(monitoring.getId());
//
List<IdmMonitoringResultDto> results = monitoringResultService.find(filter, null).getContent();
// executed only once => 0 check period
Assert.assertTrue(results.isEmpty());
} finally {
monitoringService.delete(monitoring);
}
}
use of eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringResultDto in project CzechIdMng by bcvsolutions.
the class DefaultMonitoringManagerIntegrationTest method testExecuteMonitoringAfterSave.
@Test
@Transactional
public void testExecuteMonitoringAfterSave() {
IdmMonitoringDto monitoring = new IdmMonitoringDto();
monitoring.setCheckPeriod(0L);
monitoring.setEvaluatorType(AutowireHelper.getTargetType(h2DatabaseMonitoringEvaluator));
monitoring.setInstanceId(configurationService.getInstanceId());
monitoring.setDisabled(false);
//
MonitoringEvent event = new MonitoringEvent(MonitoringEventType.CREATE, monitoring);
event.setPriority(PriorityType.HIGH);
monitoring = monitoringService.publish(event).getContent();
try {
IdmMonitoringResultFilter filter = new IdmMonitoringResultFilter();
filter.setMonitoring(monitoring.getId());
List<IdmMonitoringResultDto> results = monitoringResultService.find(filter, null).getContent();
Assert.assertFalse(results.isEmpty());
} finally {
monitoringService.delete(monitoring);
}
}
use of eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringResultDto in project CzechIdMng by bcvsolutions.
the class DefaultMonitoringManagerIntegrationTest method testRegisterMonitoringEvaluatorWithCheckPeriod.
@Test
public void testRegisterMonitoringEvaluatorWithCheckPeriod() {
IdmMonitoringDto monitoring = new IdmMonitoringDto();
// ~ hour
monitoring.setCheckPeriod(3600L);
monitoring.setEvaluatorType(AutowireHelper.getTargetType(h2DatabaseMonitoringEvaluator));
monitoring.setInstanceId(configurationService.getInstanceId());
monitoring = monitoringService.save(monitoring);
try {
//
manager.scheduleExecute();
manager.scheduleExecute();
manager.scheduleExecute();
//
IdmMonitoringResultFilter filter = new IdmMonitoringResultFilter();
filter.setMonitoring(monitoring.getId());
//
List<IdmMonitoringResultDto> results = monitoringResultService.find(filter, null).getContent();
// executed only once => 0 check period
Assert.assertEquals(1, results.size());
//
List<IdmMonitoringResultDto> lastResults = manager.getLastResults(filter, null).getContent();
//
Assert.assertEquals(1, lastResults.size());
Assert.assertEquals(results.get(0).getId(), lastResults.get(0).getId());
//
manager.init();
//
lastResults = manager.getLastResults(filter, null).getContent();
//
Assert.assertEquals(1, lastResults.size());
Assert.assertEquals(results.get(0).getId(), lastResults.get(0).getId());
//
// evict and load cache again
cacheManager.evictCache(MonitoringManager.LAST_RESULT_CACHE_NAME);
lastResults = manager.getLastResults(filter, null).getContent();
//
Assert.assertEquals(1, lastResults.size());
Assert.assertEquals(results.get(0).getId(), lastResults.get(0).getId());
} finally {
monitoringService.delete(monitoring);
}
}
use of eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringResultDto in project CzechIdMng by bcvsolutions.
the class EntityEventMonitoringEvaluatorUnitTest method testOk.
@Test
public void testOk() {
Mockito.when(entityEventService.count(ArgumentMatchers.any())).thenReturn(0L);
//
IdmMonitoringDto monitoring = new IdmMonitoringDto();
monitoring.setInstanceId("mock");
monitoring.getEvaluatorProperties().put(AbstractDailyMonitoringEvaluator.PARAMETER_NUMBER_OF_DAYS, 2);
IdmMonitoringResultDto result = evaluator.evaluate(monitoring);
//
Assert.assertEquals(CoreResultCode.OK.getCode(), result.getResult().getCode());
}
use of eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringResultDto 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);
}
Aggregations