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());
}
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());
}
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);
}
}
Aggregations