Search in sources :

Example 6 with PayloadContext

use of com.sequenceiq.cloudbreak.common.event.PayloadContext in project cloudbreak by hortonworks.

the class FlowStatCacheTest method testPutFlow.

@Test
public void testPutFlow() {
    // GIVEN
    PayloadContext payloadContext = PayloadContext.create(SAMPLE_RESOURCE_CRN, SAMPLE_CLOUD_PLATFORM);
    given(payloadContextProvider.getPayloadContext(SAMPLE_RESOURCE_ID)).willReturn(payloadContext);
    // WHEN
    underTest.put(SAMPLE_FLOW_ID, null, SAMPLE_RESOURCE_ID, OperationType.PROVISION.name(), null, false);
    FlowStat result = underTest.getFlowStatByResourceCrn(SAMPLE_RESOURCE_CRN);
    FlowStat resultByFlowId = underTest.getFlowStatByFlowId(SAMPLE_FLOW_ID);
    // THEN
    assertEquals(SAMPLE_FLOW_ID, result.getFlowId());
    assertEquals(OperationType.PROVISION, result.getOperationType());
    assertNotNull(resultByFlowId);
    verify(payloadContextProvider, times(1)).getPayloadContext(anyLong());
}
Also used : PayloadContext(com.sequenceiq.cloudbreak.common.event.PayloadContext) Test(org.junit.jupiter.api.Test)

Example 7 with PayloadContext

use of com.sequenceiq.cloudbreak.common.event.PayloadContext 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 8 with PayloadContext

use of com.sequenceiq.cloudbreak.common.event.PayloadContext in project cloudbreak by hortonworks.

the class FlowStatCache method removeByFlowChainId.

public void removeByFlowChainId(String flowChainId, boolean store) {
    if (flowChainIdStatCache.containsKey(flowChainId)) {
        FlowStat flowStat = flowChainIdStatCache.get(flowChainId);
        if (store) {
            flowOperationStatisticsService.save(flowStat);
        }
        PayloadContext payloadContext = flowStat.getPayloadContext();
        resourceCrnFlowChainStatCache.remove(payloadContext.getResourceCrn());
        if (StringUtils.isNotBlank(payloadContext.getEnvironmentCrn())) {
            resourceCrnFlowChainStatCache.remove(payloadContext.getEnvironmentCrn());
        }
        flowChainIdStatCache.remove(flowChainId);
    }
}
Also used : PayloadContext(com.sequenceiq.cloudbreak.common.event.PayloadContext)

Aggregations

PayloadContext (com.sequenceiq.cloudbreak.common.event.PayloadContext)8 Date (java.util.Date)5 TransactionService (com.sequenceiq.cloudbreak.common.service.TransactionService)2 OperationType (com.sequenceiq.flow.api.model.operation.OperationType)2 FlowOperationStats (com.sequenceiq.flow.domain.FlowOperationStats)2 Splitter (com.google.common.base.Splitter)1 EvictingQueue (com.google.common.collect.EvictingQueue)1 FlowProgressResponse (com.sequenceiq.flow.api.model.FlowProgressResponse)1 OperationFlowsView (com.sequenceiq.flow.api.model.operation.OperationFlowsView)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 FlowOperationStatsRepository (com.sequenceiq.flow.repository.FlowOperationStatsRepository)1 DecimalFormat (java.text.DecimalFormat)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1