Search in sources :

Example 86 with FlowLog

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);
}
Also used : FlowLog(com.sequenceiq.flow.domain.FlowLog)

Example 87 with 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());
}
Also used : FlowProgressResponseConverter(com.sequenceiq.flow.converter.FlowProgressResponseConverter) Date(java.util.Date) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) StringUtils(org.apache.commons.lang3.StringUtils) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ArrayList(java.util.ArrayList) FlowOperationStats(com.sequenceiq.flow.domain.FlowOperationStats) TransactionService(com.sequenceiq.cloudbreak.common.service.TransactionService) OperationFlowsView(com.sequenceiq.flow.api.model.operation.OperationFlowsView) EvictingQueue(com.google.common.collect.EvictingQueue) Map(java.util.Map) OperationType(com.sequenceiq.flow.api.model.operation.OperationType) Splitter(com.google.common.base.Splitter) FlowStat(com.sequenceiq.flow.core.cache.FlowStat) FlowOperationStatsRepository(com.sequenceiq.flow.repository.FlowOperationStatsRepository) PayloadContext(com.sequenceiq.cloudbreak.common.event.PayloadContext) FlowLog(com.sequenceiq.flow.domain.FlowLog) FlowProgressResponse(com.sequenceiq.flow.api.model.FlowProgressResponse) Logger(org.slf4j.Logger) PayloadContextProvider(com.sequenceiq.flow.core.PayloadContextProvider) DecimalFormat(java.text.DecimalFormat) Collectors(java.util.stream.Collectors) List(java.util.List) Component(org.springframework.stereotype.Component) TreeMap(java.util.TreeMap) Optional(java.util.Optional) Queue(java.util.Queue) FlowLog(com.sequenceiq.flow.domain.FlowLog) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) PayloadContext(com.sequenceiq.cloudbreak.common.event.PayloadContext) FlowProgressResponse(com.sequenceiq.flow.api.model.FlowProgressResponse) ArrayList(java.util.ArrayList) List(java.util.List) OperationType(com.sequenceiq.flow.api.model.operation.OperationType) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 88 with FlowLog

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;
}
Also used : FlowLog(com.sequenceiq.flow.domain.FlowLog) DiagnosticsCollectionFlowConfig(com.sequenceiq.freeipa.flow.freeipa.diagnostics.config.DiagnosticsCollectionFlowConfig) HANDLED_FAILED_DIAGNOSTICS_COLLECTION_EVENT(com.sequenceiq.freeipa.flow.freeipa.diagnostics.event.DiagnosticsCollectionStateSelectors.HANDLED_FAILED_DIAGNOSTICS_COLLECTION_EVENT) DiagnosticsCollectionStatus(com.sequenceiq.common.api.diagnostics.DiagnosticsCollectionStatus) DIAGNOSTICS_COLLECTION_FINISHED_STATE(com.sequenceiq.freeipa.flow.freeipa.diagnostics.DiagnosticsCollectionsState.DIAGNOSTICS_COLLECTION_FINISHED_STATE) Collectors(java.util.stream.Collectors) FlowPayloadToDiagnosticDetailsConverter(com.sequenceiq.cloudbreak.telemetry.converter.FlowPayloadToDiagnosticDetailsConverter) Inject(javax.inject.Inject) ListDiagnosticsCollectionResponse(com.sequenceiq.common.api.diagnostics.ListDiagnosticsCollectionResponse) DIAGNOSTICS_COLLECTION_FAILED_STATE(com.sequenceiq.freeipa.flow.freeipa.diagnostics.DiagnosticsCollectionsState.DIAGNOSTICS_COLLECTION_FAILED_STATE) List(java.util.List) Component(org.springframework.stereotype.Component) FlowProgressHolder(com.sequenceiq.flow.core.config.FlowProgressHolder) DiagnosticsCollection(com.sequenceiq.common.api.diagnostics.DiagnosticsCollection) StateStatus(com.sequenceiq.flow.domain.StateStatus) ListDiagnosticsCollectionResponse(com.sequenceiq.common.api.diagnostics.ListDiagnosticsCollectionResponse) DiagnosticsCollection(com.sequenceiq.common.api.diagnostics.DiagnosticsCollection)

Example 89 with FlowLog

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());
}
Also used : StackTerminationFlowConfig(com.sequenceiq.freeipa.flow.stack.termination.StackTerminationFlowConfig) FlowLog(com.sequenceiq.flow.domain.FlowLog) Acceptable(com.sequenceiq.cloudbreak.common.event.Acceptable) Test(org.junit.jupiter.api.Test)

Example 90 with FlowLog

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);
    }
}
Also used : FlowLog(com.sequenceiq.flow.domain.FlowLog)

Aggregations

FlowLog (com.sequenceiq.flow.domain.FlowLog)92 Test (org.junit.jupiter.api.Test)25 Test (org.junit.Test)23 ArrayList (java.util.ArrayList)21 List (java.util.List)13 FlowConfiguration (com.sequenceiq.flow.core.config.FlowConfiguration)12 TransactionService (com.sequenceiq.cloudbreak.common.service.TransactionService)11 Mockito.times (org.mockito.Mockito.times)11 Mockito.verify (org.mockito.Mockito.verify)11 Mockito.when (org.mockito.Mockito.when)11 HelloWorldFlowConfig (com.sequenceiq.flow.core.helloworld.config.HelloWorldFlowConfig)10 Map (java.util.Map)10 UUID (java.util.UUID)10 Collectors (java.util.stream.Collectors)10 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)10 Clock (com.sequenceiq.cloudbreak.common.service.Clock)9 FlowIdentifier (com.sequenceiq.flow.api.model.FlowIdentifier)9 FlowRegister (com.sequenceiq.flow.core.FlowRegister)9 SecureRandom (java.security.SecureRandom)9 Random (java.util.Random)9