use of com.sequenceiq.flow.api.model.operation.OperationType in project cloudbreak by hortonworks.
the class OperationService method getOperationProgressByResourceCrn.
public OperationView getOperationProgressByResourceCrn(String resourceCrn, boolean detailed) {
OperationView stackOperationView = new OperationView();
try {
OperationResource operationResource = OperationResource.fromCrn(Crn.safeFromString(resourceCrn));
Optional<OperationFlowsView> operationFlowsViewOpt = flowService.getLastFlowOperationByResourceCrn(resourceCrn);
if (operationFlowsViewOpt.isPresent()) {
OperationFlowsView operationFlowsView = operationFlowsViewOpt.get();
OperationType operationType = operationFlowsView.getOperationType();
if (OperationType.PROVISION.equals(operationType)) {
stackOperationView = handleProvisionOperation(resourceCrn, operationResource, operationFlowsView, detailed);
} else {
stackOperationView = operationDetailsPopulator.createOperationView(operationFlowsView, operationResource);
}
}
} catch (Exception e) {
LOGGER.debug(String.format("Could not fetch remote database details for stack with crn %s", resourceCrn), e);
}
return stackOperationView;
}
use of com.sequenceiq.flow.api.model.operation.OperationType in project cloudbreak by hortonworks.
the class FlowChainHandler method restoreFlowChain.
public void restoreFlowChain(String flowChainId) {
Optional<FlowChainLog> chainLog = flowLogService.findFirstByFlowChainIdOrderByCreatedDesc(flowChainId);
if (chainLog.isPresent()) {
String flowChainType = chainLog.get().getFlowChainType();
Queue<Selectable> queue = (Queue<Selectable>) JsonReader.jsonToJava(chainLog.get().getChain());
Payload triggerEvent = tryDeserializeTriggerEvent(chainLog.get());
FlowTriggerEventQueue chain = new FlowTriggerEventQueue(flowChainType, triggerEvent, queue);
if (chainLog.get().getParentFlowChainId() != null) {
chain.setParentFlowChainId(chainLog.get().getParentFlowChainId());
}
flowChains.putFlowChain(flowChainId, chainLog.get().getParentFlowChainId(), chain);
Selectable selectable = queue.peek();
if (selectable != null) {
OperationType operationType = flowChainOperationTypeConfig.getFlowTypeOperationTypeMap().getOrDefault(flowChainType, OperationType.UNKNOWN);
flowStatCache.putByFlowChainId(flowChainId, selectable.getResourceId(), operationType.name(), true);
}
if (chainLog.get().getParentFlowChainId() != null) {
restoreFlowChain(chainLog.get().getParentFlowChainId());
}
}
}
use of com.sequenceiq.flow.api.model.operation.OperationType in project cloudbreak by hortonworks.
the class FlowChainOperationTypeConfig method init.
@PostConstruct
public void init() {
for (FlowEventChainFactory<?> flowEventChainFactory : flowChainFactories) {
String flowType = flowEventChainFactory.getName();
OperationType operationType = flowEventChainFactory.getFlowOperationType();
if (flowTypeOperationTypeMap.get(flowType) != null) {
throw new UnsupportedOperationException("Flow type already registered: " + flowType);
}
flowTypeOperationTypeMap.put(flowType, operationType);
}
}
use of com.sequenceiq.flow.api.model.operation.OperationType 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.flow.api.model.operation.OperationType in project cloudbreak by hortonworks.
the class FlowLogDBService method finalize.
private FlowLog finalize(Long resourceId, String flowId, String state, boolean failed) throws TransactionExecutionException {
return transactionService.required(() -> {
flowLogRepository.finalizeByFlowId(flowId);
Optional<FlowLog> lastFlowLogOpt = getLastFlowLog(flowId);
OperationType operationType = OperationType.UNKNOWN;
if (lastFlowLogOpt.isPresent()) {
FlowLog lastFlowLog = lastFlowLogOpt.get();
updateLastFlowLogStatus(lastFlowLog, failed);
operationType = lastFlowLog.getOperationType();
}
FlowLog flowLog = new FlowLog(resourceId, flowId, state, Boolean.TRUE, StateStatus.SUCCESSFUL, operationType);
flowLog.setCloudbreakNodeId(nodeConfig.getId());
return flowLogRepository.save(flowLog);
});
}
Aggregations