Search in sources :

Example 1 with CDPStructuredEventEntity

use of com.sequenceiq.cloudbreak.structuredevent.domain.CDPStructuredEventEntity in project cloudbreak by hortonworks.

the class CDPStructuredEventDBService method create.

@Override
public void create(CDPStructuredEvent structuredEvent) {
    LOGGER.info("Stored StructuredEvent type: {}, payload: {}", structuredEvent.getType(), AnonymizerUtil.anonymize(JsonUtil.writeValueAsStringSilent(structuredEvent)));
    ValidationResult validationResult = validate(structuredEvent);
    if (validationResult.hasError()) {
        LOGGER.warn(validationResult.getFormattedErrors());
    } else {
        CDPStructuredEventEntity structuredEventEntityEntity = cdpStructuredEventToCDPStructuredEventEntityConverter.convert(structuredEvent);
        create(structuredEventEntityEntity, structuredEventEntityEntity.getAccountId());
    }
}
Also used : CDPStructuredEventEntity(com.sequenceiq.cloudbreak.structuredevent.domain.CDPStructuredEventEntity) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult)

Example 2 with CDPStructuredEventEntity

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

use of com.sequenceiq.cloudbreak.structuredevent.domain.CDPStructuredEventEntity in project cloudbreak by hortonworks.

the class CDPStructuredEventEntityToCDPStructuredEventConverterTest method testConvertWhenSuccess.

@Test
public void testConvertWhenSuccess() {
    CDPOperationDetails operationDetails = new CDPOperationDetails();
    operationDetails.setAccountId("accountId");
    FlowDetails flowDetails = new FlowDetails();
    Serializable payload = "payload";
    CDPStructuredEvent event = new CDPStructuredFlowEvent(operationDetails, flowDetails, payload, null, null);
    CDPStructuredEventEntity eventEntity = new CDPStructuredEventEntity();
    eventEntity.setEventType(StructuredEventType.FLOW);
    eventEntity.setStructuredEventJson(new Json(event));
    CDPStructuredFlowEvent<String> actual = (CDPStructuredFlowEvent<String>) underTest.convert(eventEntity);
    Assertions.assertEquals("accountId", operationDetails.getAccountId());
    Assertions.assertEquals("payload", actual.getPayload());
}
Also used : Serializable(java.io.Serializable) CDPStructuredFlowEvent(com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPStructuredFlowEvent) FlowDetails(com.sequenceiq.cloudbreak.structuredevent.event.FlowDetails) CDPStructuredEventEntity(com.sequenceiq.cloudbreak.structuredevent.domain.CDPStructuredEventEntity) CDPStructuredEvent(com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPStructuredEvent) Json(com.sequenceiq.cloudbreak.common.json.Json) CDPOperationDetails(com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPOperationDetails) Test(org.junit.jupiter.api.Test)

Example 4 with CDPStructuredEventEntity

use of com.sequenceiq.cloudbreak.structuredevent.domain.CDPStructuredEventEntity in project cloudbreak by hortonworks.

the class CDPStructuredEventDBServiceTest method testCreateWhenResourceCrnIsNotEmpty.

@Test
public void testCreateWhenResourceCrnIsNotEmpty() {
    CDPStructuredEvent event = new CDPStructuredRestCallEvent();
    CDPOperationDetails operation = new CDPOperationDetails();
    operation.setResourceCrn("crn:cdp:cloudbreak:us-west-1:someone:stack:12345");
    event.setOperation(operation);
    CDPStructuredEventEntity entity = new CDPStructuredEventEntity();
    when(cdpStructuredEventToCDPStructuredEventEntityConverter.convert(event)).thenReturn(entity);
    underTest.create(event);
    verify(cdpStructuredEventToCDPStructuredEventEntityConverter, Mockito.times(1)).convert(event);
    verify(structuredEventRepository, Mockito.times(1)).save(entity);
}
Also used : CDPStructuredRestCallEvent(com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPStructuredRestCallEvent) CDPStructuredEventEntity(com.sequenceiq.cloudbreak.structuredevent.domain.CDPStructuredEventEntity) CDPStructuredEvent(com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPStructuredEvent) CDPOperationDetails(com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPOperationDetails) Test(org.junit.jupiter.api.Test)

Example 5 with CDPStructuredEventEntity

use of com.sequenceiq.cloudbreak.structuredevent.domain.CDPStructuredEventEntity in project cloudbreak by hortonworks.

the class CDPStructuredEventToCDPStructuredEventEntityConverter method convert.

public CDPStructuredEventEntity convert(CDPStructuredEvent source) {
    try {
        CDPStructuredEventEntity structuredEventEntity = new CDPStructuredEventEntity();
        structuredEventEntity.setStructuredEventJson(new Json(source));
        CDPOperationDetails operationDetails = source.getOperation();
        structuredEventEntity.setEventType(operationDetails.getEventType());
        structuredEventEntity.setResourceType(operationDetails.getResourceType());
        structuredEventEntity.setResourceCrn(operationDetails.getResourceCrn());
        structuredEventEntity.setTimestamp(operationDetails.getTimestamp());
        structuredEventEntity.setAccountId(source.getOperation().getAccountId());
        return structuredEventEntity;
    } catch (IllegalArgumentException e) {
        LOGGER.error("Failed to parse structured event JSON, source: {}", source.getType(), e);
        return null;
    }
}
Also used : CDPStructuredEventEntity(com.sequenceiq.cloudbreak.structuredevent.domain.CDPStructuredEventEntity) Json(com.sequenceiq.cloudbreak.common.json.Json) CDPOperationDetails(com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPOperationDetails)

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