Search in sources :

Example 1 with MonitoringEvent

use of eu.bcvsolutions.idm.core.monitoring.api.event.MonitoringEvent 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 2 with MonitoringEvent

use of eu.bcvsolutions.idm.core.monitoring.api.event.MonitoringEvent 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;
}
Also used : IdmMonitoringDto(eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringDto) MonitoringEvent(eu.bcvsolutions.idm.core.monitoring.api.event.MonitoringEvent) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) ResultModel(eu.bcvsolutions.idm.core.api.dto.ResultModel) IdmMonitoringResultDto(eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringResultDto)

Aggregations

IdmMonitoringDto (eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringDto)2 IdmMonitoringResultDto (eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringResultDto)2 MonitoringEvent (eu.bcvsolutions.idm.core.monitoring.api.event.MonitoringEvent)2 ResultModel (eu.bcvsolutions.idm.core.api.dto.ResultModel)1 OperationResult (eu.bcvsolutions.idm.core.api.entity.OperationResult)1 IdmMonitoringResultFilter (eu.bcvsolutions.idm.core.monitoring.api.dto.filter.IdmMonitoringResultFilter)1 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)1 Test (org.junit.Test)1 Transactional (org.springframework.transaction.annotation.Transactional)1