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());
}
}
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);
}
}
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());
}
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);
}
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;
}
}
Aggregations