Search in sources :

Example 11 with IdmMonitoringResultFilter

use of eu.bcvsolutions.idm.core.monitoring.api.dto.filter.IdmMonitoringResultFilter 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);
    }
}
Also used : IdmMonitoringDto(eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringDto) MonitoringEvent(eu.bcvsolutions.idm.core.monitoring.api.event.MonitoringEvent) IdmMonitoringResultFilter(eu.bcvsolutions.idm.core.monitoring.api.dto.filter.IdmMonitoringResultFilter) IdmMonitoringResultDto(eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringResultDto) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 12 with IdmMonitoringResultFilter

use of eu.bcvsolutions.idm.core.monitoring.api.dto.filter.IdmMonitoringResultFilter 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);
    }
}
Also used : IdmMonitoringDto(eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringDto) IdmMonitoringResultFilter(eu.bcvsolutions.idm.core.monitoring.api.dto.filter.IdmMonitoringResultFilter) IdmMonitoringResultDto(eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringResultDto) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Example 13 with IdmMonitoringResultFilter

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

the class DefaultMonitoringManager method getLastResult.

/**
 * Find last monitoring result.
 *
 * @param monitoringId monitoring evaluator identifier
 * @return last result
 */
private IdmMonitoringResultDto getLastResult(UUID monitoringId, BasePermission... permission) {
    // try to get cached value
    ValueWrapper value = cacheManager.getValue(LAST_RESULT_CACHE_NAME, monitoringId);
    if (value != null) {
        return monitoringResultService.checkAccess((IdmMonitoringResultDto) value.get(), permission);
    }
    // or load from database
    IdmMonitoringResultFilter resultFilter = new IdmMonitoringResultFilter();
    resultFilter.setMonitoring(monitoringId);
    List<IdmMonitoringResultDto> monitoringResults = monitoringResultService.find(resultFilter, PageRequest.of(0, 1, Sort.by(Direction.DESC, IdmMonitoringResult_.created.getName())), permission).getContent();
    if (monitoringResults.isEmpty()) {
        // null => prevent to load again
        cacheManager.cacheValue(LAST_RESULT_CACHE_NAME, monitoringId, null);
        // 
        return null;
    }
    // 
    IdmMonitoringResultDto lastResult = monitoringResults.get(0);
    cacheManager.cacheValue(LAST_RESULT_CACHE_NAME, monitoringId, lastResult);
    // 
    return lastResult;
}
Also used : ValueWrapper(eu.bcvsolutions.idm.core.api.config.cache.domain.ValueWrapper) IdmMonitoringResultFilter(eu.bcvsolutions.idm.core.monitoring.api.dto.filter.IdmMonitoringResultFilter) IdmMonitoringResultDto(eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringResultDto)

Example 14 with IdmMonitoringResultFilter

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

the class IdmMonitoringResultController method toFilter.

@Override
protected IdmMonitoringResultFilter toFilter(MultiValueMap<String, Object> parameters) {
    IdmMonitoringResultFilter filter = new IdmMonitoringResultFilter(parameters, getParameterConverter());
    // 
    filter.setMonitoring(getParameterConverter().toEntityUuid(parameters, IdmMonitoringResultFilter.PARAMETER_MONITORING, IdmMonitoringDto.class));
    // 
    return filter;
}
Also used : IdmMonitoringDto(eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringDto) IdmMonitoringResultFilter(eu.bcvsolutions.idm.core.monitoring.api.dto.filter.IdmMonitoringResultFilter)

Aggregations

IdmMonitoringResultFilter (eu.bcvsolutions.idm.core.monitoring.api.dto.filter.IdmMonitoringResultFilter)14 IdmMonitoringDto (eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringDto)13 IdmMonitoringResultDto (eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringResultDto)13 Test (org.junit.Test)11 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)7 OperationResultDto (eu.bcvsolutions.idm.core.api.dto.OperationResultDto)4 AbstractReadWriteDtoControllerRestTest (eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest)4 OperationState (eu.bcvsolutions.idm.core.api.domain.OperationState)3 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)3 AbstractReadWriteDtoController (eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoController)3 ConfigurationService (eu.bcvsolutions.idm.core.api.service.ConfigurationService)3 IdmCacheManager (eu.bcvsolutions.idm.core.api.service.IdmCacheManager)3 AutowireHelper (eu.bcvsolutions.idm.core.api.utils.AutowireHelper)3 IdmIdentity (eu.bcvsolutions.idm.core.model.entity.IdmIdentity)3 IdmMonitoringResultService (eu.bcvsolutions.idm.core.monitoring.api.service.IdmMonitoringResultService)3 IdmMonitoringService (eu.bcvsolutions.idm.core.monitoring.api.service.IdmMonitoringService)3 MonitoringManager (eu.bcvsolutions.idm.core.monitoring.api.service.MonitoringManager)3 H2DatabaseMonitoringEvaluator (eu.bcvsolutions.idm.core.monitoring.service.impl.H2DatabaseMonitoringEvaluator)3 TestMonitoringEvaluator (eu.bcvsolutions.idm.core.monitoring.service.impl.TestMonitoringEvaluator)3 NotificationLevel (eu.bcvsolutions.idm.core.notification.api.domain.NotificationLevel)3