Search in sources :

Example 6 with OperationFlowsView

use of com.sequenceiq.flow.api.model.operation.OperationFlowsView in project cloudbreak by hortonworks.

the class OperationService method getOperationProgressByResourceCrn.

public OperationView getOperationProgressByResourceCrn(String resourceCrn, boolean detailed) {
    OperationView response = new OperationView();
    Optional<OperationFlowsView> operationFlowsViewOpt = flowService.getLastFlowOperationByResourceCrn(resourceCrn);
    if (operationFlowsViewOpt.isPresent()) {
        OperationFlowsView operationFlowsView = operationFlowsViewOpt.get();
        OperationType operationType = operationFlowsView.getOperationType();
        response = operationDetailsPopulator.createOperationView(operationFlowsView, OperationResource.ENVIRONMENT);
        if (OperationType.PROVISION.equals(operationType)) {
            if (detailed) {
                handleProvisionOperation(resourceCrn, response, detailed);
            } else {
                LOGGER.debug("Skipping detailed environment provision operation response");
            }
        }
    }
    return response;
}
Also used : OperationView(com.sequenceiq.flow.api.model.operation.OperationView) OperationFlowsView(com.sequenceiq.flow.api.model.operation.OperationFlowsView) OperationType(com.sequenceiq.flow.api.model.operation.OperationType)

Example 7 with OperationFlowsView

use of com.sequenceiq.flow.api.model.operation.OperationFlowsView in project cloudbreak by hortonworks.

the class OperationService method getOperationProgressByResourceCrn.

public OperationView getOperationProgressByResourceCrn(String resourceCrn, boolean detailed) {
    OperationView sdxOperationView = new OperationView();
    Optional<OperationFlowsView> operationFlowsViewOpt = flowService.getLastFlowOperationByResourceCrn(resourceCrn);
    if (operationFlowsViewOpt.isPresent()) {
        OperationFlowsView operationFlowsView = operationFlowsViewOpt.get();
        OperationType operationType = operationFlowsView.getOperationType();
        sdxOperationView = operationDetailsPopulator.createOperationView(operationFlowsView, OperationResource.DATALAKE);
        if (OperationType.PROVISION.equals(operationType)) {
            if (detailed) {
                handleProvisionOperation(resourceCrn, sdxOperationView, detailed);
            } else {
                LOGGER.debug("Skipping detailed SDX provision operation response");
            }
        }
    }
    return sdxOperationView;
}
Also used : OperationView(com.sequenceiq.flow.api.model.operation.OperationView) OperationFlowsView(com.sequenceiq.flow.api.model.operation.OperationFlowsView) OperationType(com.sequenceiq.flow.api.model.operation.OperationType)

Example 8 with OperationFlowsView

use of com.sequenceiq.flow.api.model.operation.OperationFlowsView in project cloudbreak by hortonworks.

the class OperationDetailsPopulatorTest method testCreateOperationViewWithoutFlows.

@Test
public void testCreateOperationViewWithoutFlows() {
    // GIVEN
    OperationFlowsView operationFlowsView = createOperationFlowsView(new HashMap<>());
    // WHEN
    OperationView operationView = underTest.createOperationView(operationFlowsView, OperationResource.ENVIRONMENT);
    // THEN
    assertEquals(DEFAULT_PROGRESS, operationView.getProgress());
    assertEquals(OperationProgressStatus.UNKNOWN, operationView.getProgressStatus());
}
Also used : OperationView(com.sequenceiq.flow.api.model.operation.OperationView) OperationFlowsView(com.sequenceiq.flow.api.model.operation.OperationFlowsView) Test(org.junit.jupiter.api.Test)

Example 9 with OperationFlowsView

use of com.sequenceiq.flow.api.model.operation.OperationFlowsView in project cloudbreak by hortonworks.

the class OperationDetailsPopulatorTest method testCreateOperationView.

@Test
public void testCreateOperationView() {
    // GIVEN
    Map<String, FlowProgressResponse> flowProgressResponseMap = new HashMap<>();
    flowProgressResponseMap.put(DUMMY_CLASS, createFlowProgressResponse("SUCCESSFUL", true).get());
    OperationFlowsView operationFlowsView = createOperationFlowsView(flowProgressResponseMap);
    // WHEN
    OperationView operationView = underTest.createOperationView(operationFlowsView, OperationResource.ENVIRONMENT);
    // THEN
    assertEquals(MAX_PROGRESS, operationView.getProgress());
    assertEquals(OperationProgressStatus.FINISHED, operationView.getProgressStatus());
}
Also used : FlowProgressResponse(com.sequenceiq.flow.api.model.FlowProgressResponse) HashMap(java.util.HashMap) OperationView(com.sequenceiq.flow.api.model.operation.OperationView) OperationFlowsView(com.sequenceiq.flow.api.model.operation.OperationFlowsView) Test(org.junit.jupiter.api.Test)

Example 10 with OperationFlowsView

use of com.sequenceiq.flow.api.model.operation.OperationFlowsView 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)

Aggregations

OperationFlowsView (com.sequenceiq.flow.api.model.operation.OperationFlowsView)10 OperationView (com.sequenceiq.flow.api.model.operation.OperationView)9 FlowProgressResponse (com.sequenceiq.flow.api.model.FlowProgressResponse)4 OperationType (com.sequenceiq.flow.api.model.operation.OperationType)4 HashMap (java.util.HashMap)4 Test (org.junit.jupiter.api.Test)4 OperationResource (com.sequenceiq.flow.api.model.operation.OperationResource)2 Splitter (com.google.common.base.Splitter)1 EvictingQueue (com.google.common.collect.EvictingQueue)1 PayloadContext (com.sequenceiq.cloudbreak.common.event.PayloadContext)1 TransactionService (com.sequenceiq.cloudbreak.common.service.TransactionService)1 FlowProgressResponseConverter (com.sequenceiq.flow.converter.FlowProgressResponseConverter)1 PayloadContextProvider (com.sequenceiq.flow.core.PayloadContextProvider)1 FlowStat (com.sequenceiq.flow.core.cache.FlowStat)1 FlowLog (com.sequenceiq.flow.domain.FlowLog)1 FlowOperationStats (com.sequenceiq.flow.domain.FlowOperationStats)1 FlowOperationStatsRepository (com.sequenceiq.flow.repository.FlowOperationStatsRepository)1 DecimalFormat (java.text.DecimalFormat)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1