Search in sources :

Example 1 with StructuredEventType

use of com.sequenceiq.cloudbreak.structuredevent.event.StructuredEventType in project cloudbreak by hortonworks.

the class CDPStructuredEventDBService method getPagedEventsOfResources.

@Override
public <T extends CDPStructuredEvent> Page<T> getPagedEventsOfResources(List<StructuredEventType> eventTypes, List<String> resourceCrns, Pageable pageable) {
    LOGGER.debug("Gathering pageable events for types: '{}' and resource CRNs: '{}'", eventTypes, resourceCrns);
    List<StructuredEventType> types = getAllEventTypeIfEmpty(eventTypes);
    try {
        Page<CDPStructuredEventEntity> events = pagingStructuredEventRepository.findByEventTypeInAndResourceCrnIn(types, resourceCrns, pageable);
        return (Page<T>) Optional.ofNullable(events).orElse(Page.empty()).map(event -> cdpStructuredEventEntityToCDPStructuredEventConverter.convert(event));
    } catch (Exception ex) {
        String msg = String.format("Failed get pageable events for types: '%s' and resource CRNs: '%s'", types, resourceCrns);
        LOGGER.warn(msg, ex);
        throw new CloudbreakServiceException(msg, ex);
    }
}
Also used : CDPStructuredEventEntityToCDPStructuredEventConverter(com.sequenceiq.cloudbreak.structuredevent.service.converter.CDPStructuredEventEntityToCDPStructuredEventConverter) CDPStructuredEventService(com.sequenceiq.cloudbreak.structuredevent.service.CDPStructuredEventService) LoggerFactory(org.slf4j.LoggerFactory) JsonUtil(com.sequenceiq.cloudbreak.common.json.JsonUtil) CDPStructuredEvent(com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPStructuredEvent) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) AccountAwareResourceRepository(com.sequenceiq.cloudbreak.common.dal.repository.AccountAwareResourceRepository) Pageable(org.springframework.data.domain.Pageable) AnonymizerUtil(com.sequenceiq.cloudbreak.common.anonymizer.AnonymizerUtil) CDPStructuredEventRepository(com.sequenceiq.cloudbreak.structuredevent.repository.CDPStructuredEventRepository) Logger(org.slf4j.Logger) CDPPagingStructuredEventRepository(com.sequenceiq.cloudbreak.structuredevent.repository.CDPPagingStructuredEventRepository) Page(org.springframework.data.domain.Page) Crn(com.sequenceiq.cloudbreak.auth.crn.Crn) Collectors(java.util.stream.Collectors) StructuredEventType(com.sequenceiq.cloudbreak.structuredevent.event.StructuredEventType) List(java.util.List) Component(org.springframework.stereotype.Component) CollectionUtils(org.springframework.util.CollectionUtils) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) Optional(java.util.Optional) CDPStructuredEventToCDPStructuredEventEntityConverter(com.sequenceiq.cloudbreak.structuredevent.service.converter.CDPStructuredEventToCDPStructuredEventEntityConverter) AbstractAccountAwareResourceService(com.sequenceiq.cloudbreak.common.service.account.AbstractAccountAwareResourceService) StringUtils(org.springframework.util.StringUtils) CDPStructuredEventEntity(com.sequenceiq.cloudbreak.structuredevent.domain.CDPStructuredEventEntity) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) StructuredEventType(com.sequenceiq.cloudbreak.structuredevent.event.StructuredEventType) CDPStructuredEventEntity(com.sequenceiq.cloudbreak.structuredevent.domain.CDPStructuredEventEntity) Page(org.springframework.data.domain.Page) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)

Example 2 with StructuredEventType

use of com.sequenceiq.cloudbreak.structuredevent.event.StructuredEventType in project cloudbreak by hortonworks.

the class CDPAsyncAuditStructuredEventSender method create.

@Override
public void create(CDPStructuredEvent structuredEvent) {
    StructuredEventType eventType = structuredEvent.getOperation().getEventType();
    CDPEventDataExtractor<? extends CDPStructuredEvent> eventDataExtractor = eventDataExtractorMap.get(eventType.name().toLowerCase() + "CDPEventDataExtractor");
    if (eventDataExtractor == null) {
        LOGGER.debug("Event data converter does not exist for event type of {}", eventType);
        return;
    }
    boolean shouldAudit = eventDataExtractor.shouldAudit(structuredEvent);
    if (shouldAudit) {
        sendAsyncEvent(AUDIT_EVENT_LOG_MESSAGE, eventFactory.createEvent(structuredEvent));
        LOGGER.debug("Audit Event is fired for this structured event: {}", structuredEvent);
    } else {
        LOGGER.debug("Audit Event is disabled for this structured event: {}", structuredEvent);
    }
}
Also used : StructuredEventType(com.sequenceiq.cloudbreak.structuredevent.event.StructuredEventType)

Example 3 with StructuredEventType

use of com.sequenceiq.cloudbreak.structuredevent.event.StructuredEventType in project cloudbreak by hortonworks.

the class CDPStructuredEventDBService method getEventsOfResource.

@Override
public <T extends CDPStructuredEvent> List<T> getEventsOfResource(List<StructuredEventType> eventTypes, String resourceCrn) {
    LOGGER.debug("Gathering events for type: '{}' and resource CRN: '{}'", eventTypes, resourceCrn);
    List<StructuredEventType> types = getAllEventTypeIfEmpty(eventTypes);
    try {
        List<CDPStructuredEventEntity> events = structuredEventRepository.findByEventTypeInAndResourceCrn(types, resourceCrn);
        return (List<T>) Optional.ofNullable(events).orElse(new ArrayList<>()).stream().map(event -> cdpStructuredEventEntityToCDPStructuredEventConverter.convert(event)).collect(Collectors.toList());
    } catch (Exception ex) {
        String msg = String.format("Failed get events for types: '%s' and resource CRN: '%s'", types, resourceCrn);
        LOGGER.warn(msg, ex);
        throw new CloudbreakServiceException(msg, ex);
    }
}
Also used : CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) StructuredEventType(com.sequenceiq.cloudbreak.structuredevent.event.StructuredEventType) CDPStructuredEventEntity(com.sequenceiq.cloudbreak.structuredevent.domain.CDPStructuredEventEntity) ArrayList(java.util.ArrayList) List(java.util.List) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)

Example 4 with StructuredEventType

use of com.sequenceiq.cloudbreak.structuredevent.event.StructuredEventType in project cloudbreak by hortonworks.

the class CDPStructuredEventDBService method getEventsOfResources.

@Override
public <T extends CDPStructuredEvent> List<T> getEventsOfResources(List<StructuredEventType> eventTypes, List<String> resourceCrns) {
    LOGGER.debug("Gathering events for type: '{}' and resource CRN's: '{}'", eventTypes, resourceCrns);
    List<StructuredEventType> types = getAllEventTypeIfEmpty(eventTypes);
    try {
        List<CDPStructuredEventEntity> events = structuredEventRepository.findByEventTypeInAndResourceCrnIn(types, resourceCrns);
        return (List<T>) Optional.ofNullable(events).orElse(new ArrayList<>()).stream().map(event -> cdpStructuredEventEntityToCDPStructuredEventConverter.convert(event)).collect(Collectors.toList());
    } catch (Exception ex) {
        String msg = String.format("Failed get events for types: '%s' and resource CRNs: '%s'", types, resourceCrns);
        LOGGER.warn(msg, ex);
        throw new CloudbreakServiceException(msg, ex);
    }
}
Also used : CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) StructuredEventType(com.sequenceiq.cloudbreak.structuredevent.event.StructuredEventType) CDPStructuredEventEntity(com.sequenceiq.cloudbreak.structuredevent.domain.CDPStructuredEventEntity) ArrayList(java.util.ArrayList) List(java.util.List) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)

Example 5 with StructuredEventType

use of com.sequenceiq.cloudbreak.structuredevent.event.StructuredEventType in project cloudbreak by hortonworks.

the class CDPStructuredEventDBService method getPagedEventsOfResource.

@Override
public <T extends CDPStructuredEvent> Page<T> getPagedEventsOfResource(List<StructuredEventType> eventTypes, String resourceCrn, Pageable pageable) {
    LOGGER.debug("Gathering pageable events for types: '{}' and resource CRN: '{}'", eventTypes, resourceCrn);
    List<StructuredEventType> types = getAllEventTypeIfEmpty(eventTypes);
    try {
        Page<CDPStructuredEventEntity> events = pagingStructuredEventRepository.findByEventTypeInAndResourceCrn(types, resourceCrn, pageable);
        return (Page<T>) Optional.ofNullable(events).orElse(Page.empty()).map(event -> cdpStructuredEventEntityToCDPStructuredEventConverter.convert(event));
    } catch (Exception ex) {
        String msg = String.format("Failed get pageable events for types: '%s' and resource CRN: '%s'", types, resourceCrn);
        LOGGER.warn(msg, ex);
        throw new CloudbreakServiceException(msg, ex);
    }
}
Also used : CDPStructuredEventEntityToCDPStructuredEventConverter(com.sequenceiq.cloudbreak.structuredevent.service.converter.CDPStructuredEventEntityToCDPStructuredEventConverter) CDPStructuredEventService(com.sequenceiq.cloudbreak.structuredevent.service.CDPStructuredEventService) LoggerFactory(org.slf4j.LoggerFactory) JsonUtil(com.sequenceiq.cloudbreak.common.json.JsonUtil) CDPStructuredEvent(com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPStructuredEvent) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) AccountAwareResourceRepository(com.sequenceiq.cloudbreak.common.dal.repository.AccountAwareResourceRepository) Pageable(org.springframework.data.domain.Pageable) AnonymizerUtil(com.sequenceiq.cloudbreak.common.anonymizer.AnonymizerUtil) CDPStructuredEventRepository(com.sequenceiq.cloudbreak.structuredevent.repository.CDPStructuredEventRepository) Logger(org.slf4j.Logger) CDPPagingStructuredEventRepository(com.sequenceiq.cloudbreak.structuredevent.repository.CDPPagingStructuredEventRepository) Page(org.springframework.data.domain.Page) Crn(com.sequenceiq.cloudbreak.auth.crn.Crn) Collectors(java.util.stream.Collectors) StructuredEventType(com.sequenceiq.cloudbreak.structuredevent.event.StructuredEventType) List(java.util.List) Component(org.springframework.stereotype.Component) CollectionUtils(org.springframework.util.CollectionUtils) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) Optional(java.util.Optional) CDPStructuredEventToCDPStructuredEventEntityConverter(com.sequenceiq.cloudbreak.structuredevent.service.converter.CDPStructuredEventToCDPStructuredEventEntityConverter) AbstractAccountAwareResourceService(com.sequenceiq.cloudbreak.common.service.account.AbstractAccountAwareResourceService) StringUtils(org.springframework.util.StringUtils) CDPStructuredEventEntity(com.sequenceiq.cloudbreak.structuredevent.domain.CDPStructuredEventEntity) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) StructuredEventType(com.sequenceiq.cloudbreak.structuredevent.event.StructuredEventType) CDPStructuredEventEntity(com.sequenceiq.cloudbreak.structuredevent.domain.CDPStructuredEventEntity) Page(org.springframework.data.domain.Page) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)

Aggregations

StructuredEventType (com.sequenceiq.cloudbreak.structuredevent.event.StructuredEventType)5 CloudbreakServiceException (com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)4 CDPStructuredEventEntity (com.sequenceiq.cloudbreak.structuredevent.domain.CDPStructuredEventEntity)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Crn (com.sequenceiq.cloudbreak.auth.crn.Crn)2 AnonymizerUtil (com.sequenceiq.cloudbreak.common.anonymizer.AnonymizerUtil)2 AccountAwareResourceRepository (com.sequenceiq.cloudbreak.common.dal.repository.AccountAwareResourceRepository)2 JsonUtil (com.sequenceiq.cloudbreak.common.json.JsonUtil)2 AbstractAccountAwareResourceService (com.sequenceiq.cloudbreak.common.service.account.AbstractAccountAwareResourceService)2 CDPStructuredEvent (com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPStructuredEvent)2 CDPPagingStructuredEventRepository (com.sequenceiq.cloudbreak.structuredevent.repository.CDPPagingStructuredEventRepository)2 CDPStructuredEventRepository (com.sequenceiq.cloudbreak.structuredevent.repository.CDPStructuredEventRepository)2 CDPStructuredEventService (com.sequenceiq.cloudbreak.structuredevent.service.CDPStructuredEventService)2 CDPStructuredEventEntityToCDPStructuredEventConverter (com.sequenceiq.cloudbreak.structuredevent.service.converter.CDPStructuredEventEntityToCDPStructuredEventConverter)2 CDPStructuredEventToCDPStructuredEventEntityConverter (com.sequenceiq.cloudbreak.structuredevent.service.converter.CDPStructuredEventToCDPStructuredEventEntityConverter)2 ValidationResult (com.sequenceiq.cloudbreak.validation.ValidationResult)2 Optional (java.util.Optional)2 Collectors (java.util.stream.Collectors)2 Inject (javax.inject.Inject)2