Search in sources :

Example 11 with FlowProgressResponse

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

the class FlowProgressResponseConverterTest method testConvertList.

@Test
public void testConvertList() {
    // GIVEN
    given(flowProgressHolder.getProgressPercentageForState(TestFlowConfig.class.getCanonicalName(), "FINISHED")).willReturn(100);
    given(flowProgressHolder.getProgressPercentageForState(TestFlowConfig.class.getCanonicalName(), "CANCELLED")).willReturn(100);
    // WHEN
    List<FlowProgressResponse> responses = underTest.convertList(createFlowLogs(true), DUMMY_CRN);
    FlowProgressResponse latestResponse = responses.get(0);
    FlowProgressResponse firstResponse = responses.get(1);
    // THEN
    assertEquals(2, responses.size());
    assertEquals("flow2", latestResponse.getFlowId());
    assertEquals(2, latestResponse.getTransitions().size());
    assertEquals(0.002, latestResponse.getElapsedTimeInSeconds());
    assertEquals(100, latestResponse.getProgress());
    assertEquals("flow1", firstResponse.getFlowId());
    assertEquals(2, firstResponse.getTransitions().size());
    assertEquals(0.001, firstResponse.getElapsedTimeInSeconds());
    assertEquals(100, firstResponse.getProgress());
}
Also used : TestFlowConfig(com.sequenceiq.flow.core.config.TestFlowConfig) FlowProgressResponse(com.sequenceiq.flow.api.model.FlowProgressResponse) Test(org.junit.jupiter.api.Test)

Example 12 with FlowProgressResponse

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

the class FlowProgressResponseConverterTest method testConvertWithEmptyList.

@Test
public void testConvertWithEmptyList() {
    // GIVEN
    // WHEN
    FlowProgressResponse response = underTest.convert(new ArrayList<>(), DUMMY_CRN);
    // THEN
    assertNull(response.getFlowId());
}
Also used : FlowProgressResponse(com.sequenceiq.flow.api.model.FlowProgressResponse) Test(org.junit.jupiter.api.Test)

Example 13 with FlowProgressResponse

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

the class FlowProgressResponseConverterTest method testConvertWithNull.

@Test
public void testConvertWithNull() {
    // GIVEN
    // WHEN
    FlowProgressResponse response = underTest.convert(null, DUMMY_CRN);
    // THEN
    assertNull(response.getFlowId());
}
Also used : FlowProgressResponse(com.sequenceiq.flow.api.model.FlowProgressResponse) Test(org.junit.jupiter.api.Test)

Example 14 with FlowProgressResponse

use of com.sequenceiq.flow.api.model.FlowProgressResponse 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 15 with FlowProgressResponse

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

the class FlowService method getLastFlowProgressByResourceCrn.

public FlowProgressResponse getLastFlowProgressByResourceCrn(String resourceCrn) {
    checkState(Crn.isCrn(resourceCrn));
    LOGGER.info("Getting flow logs (progress) by resource crn {}", resourceCrn);
    List<FlowLog> flowLogs = flowLogDBService.getFlowLogsByResourceCrnOrName(resourceCrn);
    FlowProgressResponse response = flowProgressResponseConverter.convert(flowLogs, resourceCrn);
    if (StringUtils.isBlank(response.getFlowId())) {
        throw new NotFoundException(String.format("Not found any historical flow data for requested resource (crn: %s)", resourceCrn));
    }
    return flowProgressResponseConverter.convert(flowLogs, resourceCrn);
}
Also used : FlowLog(com.sequenceiq.flow.domain.FlowLog) FlowProgressResponse(com.sequenceiq.flow.api.model.FlowProgressResponse) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException)

Aggregations

FlowProgressResponse (com.sequenceiq.flow.api.model.FlowProgressResponse)16 Test (org.junit.jupiter.api.Test)7 OperationFlowsView (com.sequenceiq.flow.api.model.operation.OperationFlowsView)5 OperationView (com.sequenceiq.flow.api.model.operation.OperationView)5 ArrayList (java.util.ArrayList)5 FlowStateTransitionResponse (com.sequenceiq.flow.api.model.FlowStateTransitionResponse)4 FlowLog (com.sequenceiq.flow.domain.FlowLog)4 HashMap (java.util.HashMap)4 Optional (java.util.Optional)4 Date (java.util.Date)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 CollectionUtils (org.apache.commons.collections4.CollectionUtils)3 Component (org.springframework.stereotype.Component)3 OperationProgressStatus (com.sequenceiq.flow.api.model.operation.OperationProgressStatus)2 TestFlowConfig (com.sequenceiq.flow.core.config.TestFlowConfig)2 DecimalFormat (java.text.DecimalFormat)2 Map (java.util.Map)2 Splitter (com.google.common.base.Splitter)1 EvictingQueue (com.google.common.collect.EvictingQueue)1