use of com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPStructuredEvent in project cloudbreak by hortonworks.
the class CDPStructuredEventV1ControllerTest method createTestCDPStructuredEvent.
private CDPStructuredEvent createTestCDPStructuredEvent() {
CDPOperationDetails operationDetails = new CDPOperationDetails();
operationDetails.setResourceCrn("someCrn");
operationDetails.setResourceType("environment");
CDPStructuredEvent cdpStructuredEvent = new CDPStructuredEvent() {
@Override
public String getStatus() {
return SENT;
}
@Override
public Long getDuration() {
return 1L;
}
};
cdpStructuredEvent.setOperation(operationDetails);
return cdpStructuredEvent;
}
use of com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPStructuredEvent 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.event.cdp.CDPStructuredEvent in project cloudbreak by hortonworks.
the class CDPFlowStructuredEventHandler method buildCdpStructuredEvent.
private CDPStructuredEvent buildCdpStructuredEvent(String fromId, String toId, String eventId, long duration) {
FlowDetails flowDetails = new FlowDetails(flowChainType, flowType, flowChainId, flowId, fromId, toId, eventId, duration);
CDPStructuredEvent structuredEvent;
if (exception == null) {
structuredEvent = cdpStructuredFlowEventFactory.createStructuredFlowEvent(resourceId, flowDetails);
} else {
structuredEvent = cdpStructuredFlowEventFactory.createStructuredFlowEvent(resourceId, flowDetails, exception);
exception = null;
}
return structuredEvent;
}
use of com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPStructuredEvent in project cloudbreak by hortonworks.
the class CDPFlowStructuredEventHandler method stateMachineStopped.
@Override
public void stateMachineStopped(StateMachine<S, E> stateMachine) {
if (!stateMachine.isComplete()) {
State<S, E> currentState = stateMachine.getState();
Long currentTime = System.currentTimeMillis();
String fromId = currentState != null ? currentState.getId().toString() : "unknown";
FlowDetails flowDetails = new FlowDetails(flowChainType, flowType, flowChainId, flowId, fromId, "unknown", "FLOW_CANCEL", lastStateChange == null ? 0L : currentTime - lastStateChange);
CDPStructuredEvent structuredEvent = cdpStructuredFlowEventFactory.createStructuredFlowEvent(resourceId, flowDetails);
cdpDefaultStructuredEventClient.sendStructuredEvent(structuredEvent);
lastStateChange = currentTime;
}
}
use of com.sequenceiq.cloudbreak.structuredevent.event.cdp.CDPStructuredEvent in project cloudbreak by hortonworks.
the class CDPFlowStructuredEventHandler method transition.
/**
* Send a new structured event.
* @param transition provides information to build the new Structured Event.
*/
@Override
public void transition(Transition<S, E> transition) {
try {
String fromId = getFromId(transition);
String toId = getToId(transition);
String eventId = getEventId(transition);
LOGGER.debug("New transition arrived: from: {}, to: {}, eventId: {}, detailed: {}", fromId, toId, eventId, true);
Long currentTime = System.currentTimeMillis();
long duration = lastStateChange == null ? 0L : currentTime - lastStateChange;
LOGGER.debug("Build new CDP structured event");
CDPStructuredEvent structuredEvent = buildCdpStructuredEvent(fromId, toId, eventId, duration);
LOGGER.debug("New CDP structured event built, send to all consumers");
cdpDefaultStructuredEventClient.sendStructuredEvent(structuredEvent);
LOGGER.debug("CDP structured events sent to all consumers");
lastStateChange = currentTime;
} catch (RuntimeException ex) {
LOGGER.error("Error happened during structured flow event generation! The event won't be stored!", ex);
}
}
Aggregations