use of com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPOperationDetails in project cloudbreak by hortonworks.
the class CDPStructuredFlowEventToCDPOperationDetailsConverterTest method testFlowAndFlowChainType.
@Test
public void testFlowAndFlowChainType() {
CDPEnvironmentStructuredFlowEvent cdpStructuredFlowEvent = new CDPEnvironmentStructuredFlowEvent();
FlowDetails flowDetails = new FlowDetails();
flowDetails.setFlowId("flowId");
flowDetails.setFlowChainId("flowChainId");
flowDetails.setNextFlowState("ENV_CREATION_FINISHED_STATE");
cdpStructuredFlowEvent.setFlow(flowDetails);
CDPOperationDetails operationDetails = new CDPOperationDetails();
operationDetails.setUuid("correlationId");
cdpStructuredFlowEvent.setOperation(operationDetails);
UsageProto.CDPOperationDetails details = underTest.convert(cdpStructuredFlowEvent, null);
Assertions.assertEquals(UsageProto.CDPRequestProcessingStep.Value.FINAL, details.getCdpRequestProcessingStep());
Assertions.assertEquals("flowId", details.getFlowId());
Assertions.assertEquals("flowChainId", details.getFlowChainId());
Assertions.assertEquals("correlationId", details.getCorrelationId());
}
use of com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPOperationDetails in project cloudbreak by hortonworks.
the class CDPStructuredFlowEventToCDPOperationDetailsConverter method convert.
public UsageProto.CDPOperationDetails convert(CDPStructuredFlowEvent cdpStructuredFlowEvent, String cloudPlatform) {
UsageProto.CDPOperationDetails.Builder cdpOperationDetails = UsageProto.CDPOperationDetails.newBuilder();
if (cdpStructuredFlowEvent != null) {
CDPOperationDetails structuredOperationDetails = cdpStructuredFlowEvent.getOperation();
if (structuredOperationDetails != null) {
cdpOperationDetails.setAccountId(defaultIfEmpty(structuredOperationDetails.getAccountId(), ""));
cdpOperationDetails.setResourceCrn(defaultIfEmpty(structuredOperationDetails.getResourceCrn(), ""));
cdpOperationDetails.setResourceName(defaultIfEmpty(structuredOperationDetails.getResourceName(), ""));
cdpOperationDetails.setInitiatorCrn(defaultIfEmpty(structuredOperationDetails.getUserCrn(), ""));
cdpOperationDetails.setCorrelationId(defaultIfEmpty(structuredOperationDetails.getUuid(), ""));
}
if (cloudPlatform != null) {
cdpOperationDetails.setEnvironmentType(UsageProto.CDPEnvironmentsEnvironmentType.Value.valueOf(cloudPlatform));
}
FlowDetails flowDetails = cdpStructuredFlowEvent.getFlow();
if (flowDetails != null) {
String flowId = defaultIfEmpty(flowDetails.getFlowId(), "");
cdpOperationDetails.setFlowId(flowId);
// We will use flow id if there is no flowchain id, this helps to correlate requests
cdpOperationDetails.setFlowChainId(defaultIfEmpty(flowDetails.getFlowChainId(), flowId));
cdpOperationDetails.setFlowState(flowDetails.getFlowState() != null && !"unknown".equals(flowDetails.getFlowState()) && flowDetails.getNextFlowState() != null && (flowDetails.getNextFlowState().endsWith("_FAILED_STATE") || flowDetails.getNextFlowState().endsWith("_FAIL_STATE")) ? flowDetails.getFlowState() : "");
}
cdpOperationDetails.setCdpRequestProcessingStep(cdpRequestProcessingStepMapper.mapIt(cdpStructuredFlowEvent.getFlow()));
}
cdpOperationDetails.setApplicationVersion(appVersion);
return cdpOperationDetails.build();
}
use of com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPOperationDetails 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;
}
}
use of com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPOperationDetails in project cloudbreak by hortonworks.
the class FreeipaStructuredFlowEventFactory method createStructuredFlowEvent.
@Override
public CDPStructuredFlowEvent createStructuredFlowEvent(Long resourceId, FlowDetails flowDetails, Exception exception) {
Stack stack = stackService.getStackById(resourceId);
String resourceType = CloudbreakEventService.FREEIPA_RESOURCE_TYPE;
CDPOperationDetails operationDetails = new CDPOperationDetails(clock.getCurrentTimeMillis(), FLOW, resourceType, stack.getId(), stack.getName(), nodeConfig.getId(), serviceVersion, stack.getAccountId(), stack.getResourceCrn(), ThreadBasedUserCrnProvider.getUserCrn(), stack.getEnvironmentCrn(), null);
StackDetails stackDetails = stackToStackDetailsConverter.convert(stack);
StackStatus stackStatus = stack.getStackStatus();
CDPFreeIpaStructuredFlowEvent event = new CDPFreeIpaStructuredFlowEvent(operationDetails, flowDetails, stackDetails, stackStatus.getDetailedStackStatus().name(), stackStatus.getStatusReason());
if (exception != null) {
event.setException(ExceptionUtils.getStackTrace(exception));
}
return event;
}
use of com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPOperationDetails in project cloudbreak by hortonworks.
the class EnvironmentStructuredFlowEventFactory method createStructuredFlowEvent.
@Override
public CDPStructuredFlowEvent createStructuredFlowEvent(Long resourceId, FlowDetails flowDetails, Boolean detailed, Exception exception) {
Environment environment = environmentService.findEnvironmentByIdOrThrow(resourceId);
String resourceType = CloudbreakEventService.ENVIRONMENT_RESOURCE_TYPE;
CDPOperationDetails operationDetails = new CDPOperationDetails(clock.getCurrentTimeMillis(), FLOW, resourceType, environment.getId(), environment.getName(), nodeConfig.getId(), serviceVersion, environment.getAccountId(), environment.getResourceCrn(), environment.getCreator(), environment.getResourceCrn(), null);
EnvironmentDetails environmentDetails = environmentDtoConverter.environmentToDto(environment);
CDPEnvironmentStructuredFlowEvent event = new CDPEnvironmentStructuredFlowEvent(operationDetails, flowDetails, environmentDetails, environment.getStatus().name(), getReason(environment));
if (exception != null) {
event.setException(ExceptionUtils.getStackTrace(exception));
}
return event;
}
Aggregations