use of com.sequenceiq.flow.domain.FlowLog in project cloudbreak by hortonworks.
the class FlowLogDBService method save.
@Override
public FlowLog save(FlowParameters flowParameters, String flowChanId, String key, Payload payload, Map<Object, Object> variables, Class<?> flowType, FlowState currentState) {
String payloadAsString = getSerializedString(payload);
String variablesJson = getSerializedString(variables);
FlowLog flowLog = new FlowLog(payload.getResourceId(), flowParameters.getFlowId(), flowChanId, flowParameters.getFlowTriggerUserCrn(), key, payloadAsString, ClassValue.of(payload.getClass()), variablesJson, ClassValue.of(flowType), currentState.toString());
flowLog.setOperationType(StringUtils.isNotBlank(flowParameters.getFlowOperationType()) ? OperationType.valueOf(flowParameters.getFlowOperationType()) : OperationType.UNKNOWN);
flowLog.setCloudbreakNodeId(nodeConfig.getId());
return flowLogRepository.save(flowLog);
}
use of com.sequenceiq.flow.domain.FlowLog in project cloudbreak by hortonworks.
the class FlowOperationStatisticsService method createOperationResponse.
public Optional<OperationFlowsView> createOperationResponse(String resourceCrn, List<FlowLog> flowLogs) {
Double avgProgressTime = 0.0d;
OperationType operationType;
if (flowLogs.isEmpty()) {
operationType = OperationType.UNKNOWN;
} else {
FlowLog flowLog = flowLogs.get(0);
operationType = flowLog.getOperationType();
if (!operationType.equals(OperationType.UNKNOWN)) {
PayloadContext payloadContext = payloadContextProvider.getPayloadContext(flowLog.getResourceId());
avgProgressTime = getExpectedAverageTimeForOperation(operationType, payloadContext.getCloudPlatform());
}
}
Map<String, List<FlowLog>> flowLogsPerType = flowLogs.stream().filter(fl -> fl.getFlowType() != null).collect(groupingBy(fl -> fl.getFlowType().getName()));
Map<String, FlowProgressResponse> response = new HashMap<>();
Map<Long, String> createdMap = new TreeMap<>();
Integer progressFromHistory = DEFAULT_PROGRESS;
for (Map.Entry<String, List<FlowLog>> entry : flowLogsPerType.entrySet()) {
FlowProgressResponse progressResponse = flowProgressResponseConverter.convert(entry.getValue(), resourceCrn);
response.put(entry.getKey(), progressResponse);
createdMap.put(progressResponse.getCreated(), entry.getKey());
}
List<String> typeOrderList = new ArrayList<>(createdMap.values());
if (!createdMap.isEmpty()) {
Long operationCreated = createdMap.keySet().stream().mapToLong(v -> v).min().getAsLong();
progressFromHistory = getProgressFromHistory(avgProgressTime, operationCreated);
}
if (CollectionUtils.isEmpty(response.entrySet())) {
LOGGER.debug("Not found any historical flow data for requested resource (crn: {})", resourceCrn);
return Optional.empty();
}
return Optional.of(OperationFlowsView.Builder.newBuilder().withOperationType(operationType).withFlowTypeProgressMap(response).withTypeOrderList(typeOrderList).withProgressFromHistory(progressFromHistory).build());
}
use of com.sequenceiq.flow.domain.FlowLog in project cloudbreak by hortonworks.
the class FlowLogsToListDiagnosticsCollectionResponseConverter method convert.
public ListDiagnosticsCollectionResponse convert(List<FlowLog> flowLogs) {
ListDiagnosticsCollectionResponse response = new ListDiagnosticsCollectionResponse();
if (!flowLogs.isEmpty()) {
List<DiagnosticsCollection> collections = flowLogs.stream().map(flowLog -> {
DiagnosticsCollection collection = new DiagnosticsCollection();
collection.setFlowId(flowLog.getFlowId());
collection.setCreated(flowLog.getCreated());
collection.setProperties(flowPayloadToDiagnosticDetailsConverter.convert(flowLog.getPayload()));
collection.setStatus(calculateStatus(flowLog));
collection.setCurrentFlowStatus(flowLog.getCurrentState());
collection.setProgressPercentage(calculateProgressPercentage(flowLog));
return collection;
}).collect(Collectors.toList());
response.setCollections(collections);
}
return response;
}
use of com.sequenceiq.flow.domain.FlowLog in project cloudbreak by hortonworks.
the class FreeIpaDeletionServiceTest method testTerminationFlowExists.
@Test
public void testTerminationFlowExists() {
when(stackService.findAllByEnvironmentCrnAndAccountId(eq(ENVIRONMENT_CRN), eq(ACCOUNT_ID))).thenReturn(Collections.singletonList(stack));
when(applicationFlowInformation.getTerminationFlow()).thenReturn(List.of(StackTerminationFlowConfig.class));
FlowLog flowLog = new FlowLog();
flowLog.setFlowType(ClassValue.of(StackTerminationFlowConfig.class));
flowLog.setCurrentState(StackTerminationState.INIT_STATE.name());
when(flowLogService.findAllByResourceIdAndFinalizedIsFalseOrderByCreatedDesc(stack.getId())).thenReturn(List.of(flowLog));
underTest.delete(ENVIRONMENT_CRN, ACCOUNT_ID, false);
verify(flowManager, never()).notify(anyString(), any(Acceptable.class));
verify(flowCancelService, never()).cancelRunningFlows(stack.getId());
}
use of com.sequenceiq.flow.domain.FlowLog in project cloudbreak by hortonworks.
the class FreeIpaDeletionService method handleIfStackIsNotTerminated.
private void handleIfStackIsNotTerminated(Stack stack, boolean forced) {
LOGGER.info("Stack {} in environment {} is not deleted.", stack.getName(), stack.getEnvironmentCrn());
Optional<FlowLog> optionalFlowLog = findLatestTerminationFlowLogWithInitState(stack);
if (optionalFlowLog.isPresent()) {
FlowLog flowLog = optionalFlowLog.get();
LOGGER.debug("Found termination flowlog with id [{}] and payload [{}]", flowLog.getFlowId(), flowLog.getPayload());
} else {
fireTerminationEvent(stack, forced);
}
}
Aggregations