Search in sources :

Example 6 with CDPStructuredEventEntity

use of com.sequenceiq.cloudbreak.structuredevent.domain.CDPStructuredEventEntity 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 7 with CDPStructuredEventEntity

use of com.sequenceiq.cloudbreak.structuredevent.domain.CDPStructuredEventEntity 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 8 with CDPStructuredEventEntity

use of com.sequenceiq.cloudbreak.structuredevent.domain.CDPStructuredEventEntity 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

CDPStructuredEventEntity (com.sequenceiq.cloudbreak.structuredevent.domain.CDPStructuredEventEntity)8 CloudbreakServiceException (com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)4 StructuredEventType (com.sequenceiq.cloudbreak.structuredevent.event.StructuredEventType)4 CDPStructuredEvent (com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPStructuredEvent)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 CDPOperationDetails (com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPOperationDetails)3 ValidationResult (com.sequenceiq.cloudbreak.validation.ValidationResult)3 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 Json (com.sequenceiq.cloudbreak.common.json.Json)2 JsonUtil (com.sequenceiq.cloudbreak.common.json.JsonUtil)2 AbstractAccountAwareResourceService (com.sequenceiq.cloudbreak.common.service.account.AbstractAccountAwareResourceService)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 Optional (java.util.Optional)2