use of com.sequenceiq.cloudbreak.common.event.PayloadContext in project cloudbreak by hortonworks.
the class FlowStatCache method putByFlowChainId.
public void putByFlowChainId(String flowChainId, Long resourceId, String operationType, boolean restored) {
if (!flowChainIdStatCache.containsKey(flowChainId)) {
PayloadContext payloadContext = payloadContextProvider.getPayloadContext(resourceId);
if (payloadContext != null) {
FlowStat flowStat = new FlowStat();
flowStat.setFlowChainId(flowChainId);
flowStat.setResourceId(resourceId);
flowStat.setStartTime(new Date().getTime());
flowStat.setOperationType(OperationType.valueOf(operationType));
flowStat.setPayloadContext(payloadContext);
flowStat.setRestored(restored);
flowChainIdStatCache.put(flowChainId, flowStat);
if (StringUtils.isNotBlank(payloadContext.getEnvironmentCrn())) {
resourceCrnFlowChainStatCache.put(payloadContext.getEnvironmentCrn(), flowStat);
}
resourceCrnFlowChainStatCache.put(payloadContext.getResourceCrn(), flowStat);
}
}
}
use of com.sequenceiq.cloudbreak.common.event.PayloadContext in project cloudbreak by hortonworks.
the class FlowStatCache method remove.
public void remove(String flowId, boolean store) {
if (flowIdStatCache.containsKey(flowId)) {
FlowStat flowStat = flowIdStatCache.get(flowId);
if (store && StringUtils.isBlank(flowStat.getFlowChainId())) {
flowOperationStatisticsService.save(flowStat);
}
PayloadContext payloadContext = flowStat.getPayloadContext();
resourceCrnFlowStatCache.remove(payloadContext.getResourceCrn());
if (StringUtils.isNotBlank(payloadContext.getEnvironmentCrn())) {
resourceCrnFlowStatCache.remove(payloadContext.getEnvironmentCrn());
}
flowIdStatCache.remove(flowId);
}
}
use of com.sequenceiq.cloudbreak.common.event.PayloadContext in project cloudbreak by hortonworks.
the class FlowStatCache method put.
public void put(String flowId, String flowChainId, Long resourceId, String operationType, Class<? extends FlowConfiguration<?>> flowConfigType, boolean restored) {
PayloadContext payloadContext = payloadContextProvider.getPayloadContext(resourceId);
if (payloadContext != null) {
FlowStat flowStat = new FlowStat();
flowStat.setFlowId(flowId);
flowStat.setFlowChainId(flowChainId);
flowStat.setResourceId(resourceId);
flowStat.setStartTime(new Date().getTime());
flowStat.setFlowType(flowConfigType);
flowStat.setOperationType(OperationType.valueOf(operationType));
flowStat.setPayloadContext(payloadContext);
flowStat.setRestored(restored);
flowIdStatCache.put(flowId, flowStat);
if (StringUtils.isNotBlank(payloadContext.getEnvironmentCrn())) {
resourceCrnFlowStatCache.put(payloadContext.getEnvironmentCrn(), flowStat);
}
resourceCrnFlowStatCache.put(payloadContext.getResourceCrn(), flowStat);
}
}
use of com.sequenceiq.cloudbreak.common.event.PayloadContext in project cloudbreak by hortonworks.
the class FlowOperationStatisticsService method save.
public synchronized void save(FlowStat flowStat) {
if (OperationType.UNKNOWN.equals(flowStat.getOperationType()) || flowStat.getPayloadContext() == null) {
return;
}
if (flowStat.isRestored()) {
LOGGER.debug("Flow was restored, so statistics won't be saved about that. (operation: {})", flowStat.getOperationType());
return;
}
try {
OperationType operationType = flowStat.getOperationType();
PayloadContext payloadContext = flowStat.getPayloadContext();
Optional<FlowOperationStats> flowOpStatOpt = flowOperationStatsRepository.findFirstByOperationTypeAndCloudPlatform(operationType, payloadContext.getCloudPlatform());
final FlowOperationStats flowOperationStats;
if (flowOpStatOpt.isPresent()) {
flowOperationStats = flowOpStatOpt.get();
} else {
flowOperationStats = new FlowOperationStats();
flowOperationStats.setOperationType(operationType);
flowOperationStats.setCloudPlatform(payloadContext.getCloudPlatform());
}
String durationHistory = flowOperationStats.getDurationHistory();
Queue<Double> durationHistoryQueue = EvictingQueue.create(MAX_FLOW_STAT_SIZE);
if (StringUtils.isNotBlank(durationHistory)) {
Splitter.on(",").splitToList(durationHistory).forEach(s -> {
durationHistoryQueue.add(Double.parseDouble(s));
});
}
Double elapsedOperationTime = getRoundedTimeInSeconds(flowStat.getStartTime(), new Date().getTime());
durationHistoryQueue.add(elapsedOperationTime);
durationHistory = StringUtils.join(durationHistoryQueue.stream().map(Object::toString).collect(Collectors.toList()), ",");
flowOperationStats.setDurationHistory(durationHistory);
transactionService.required(() -> flowOperationStatsRepository.save(flowOperationStats));
} catch (TransactionService.TransactionExecutionException e) {
LOGGER.warn("Cannot store flow operation statistics.", e);
} catch (Exception e) {
LOGGER.warn("Unexpected error happened during storing flow operation statistics", e);
}
}
use of com.sequenceiq.cloudbreak.common.event.PayloadContext in project cloudbreak by hortonworks.
the class FlowStatCacheTest method createFlowStat.
private FlowStat createFlowStat(String flowId, String flowChainId, String crn, boolean old) {
FlowStat flowStat = new FlowStat();
flowStat.setFlowId(flowId);
flowStat.setFlowChainId(flowChainId);
PayloadContext payloadContext = PayloadContext.create(crn, SAMPLE_CLOUD_PLATFORM);
flowStat.setPayloadContext(payloadContext);
if (old) {
flowStat.setStartTime(OLD_DATE.getTime());
} else {
flowStat.setStartTime(new Date().getTime());
}
return flowStat;
}
Aggregations