Search in sources :

Example 16 with OperationView

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

the class OperationDetailsPopulator method createOperationView.

public OperationView createOperationView(OperationFlowsView operationFlowsView, OperationResource resource, List<Class<?>> expectedTypeOrder) {
    OperationView response = new OperationView();
    response.setOperationType(operationFlowsView.getOperationType());
    response.setOperationResource(resource);
    response.setOperationId(operationFlowsView.getOperationId());
    List<String> typeOrderList = CollectionUtils.isNotEmpty(expectedTypeOrder) ? expectedTypeOrder.stream().map(Class::getCanonicalName).collect(Collectors.toList()) : operationFlowsView.getTypeOrderList();
    int expectedNumberOfFlows = typeOrderList.size();
    Map<String, FlowProgressResponse> flowTypeProgressMap = operationFlowsView.getFlowTypeProgressMap();
    List<Optional<FlowProgressResponse>> responseListToProcess = new ArrayList<>();
    for (String typeName : typeOrderList) {
        if (flowTypeProgressMap != null && flowTypeProgressMap.containsKey(typeName)) {
            responseListToProcess.add(Optional.of(flowTypeProgressMap.get(typeName)));
        } else {
            responseListToProcess.add(Optional.empty());
        }
    }
    populateOperationDetails(response, responseListToProcess, expectedNumberOfFlows, operationFlowsView.getProgressFromHistory());
    return response;
}
Also used : Optional(java.util.Optional) FlowProgressResponse(com.sequenceiq.flow.api.model.FlowProgressResponse) OperationView(com.sequenceiq.flow.api.model.operation.OperationView) ArrayList(java.util.ArrayList)

Example 17 with OperationView

use of com.sequenceiq.flow.api.model.operation.OperationView 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 18 with OperationView

use of com.sequenceiq.flow.api.model.operation.OperationView 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 19 with OperationView

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

the class OperationServiceTest method testGetOperationProgressByResourceCrnWithDatahub.

@Test
public void testGetOperationProgressByResourceCrnWithDatahub() {
    // GIVEN
    given(flowService.getLastFlowOperationByResourceCrn(anyString())).willReturn(Optional.of(operationFlowsView));
    given(operationFlowsView.getOperationType()).willReturn(OperationType.PROVISION);
    given(operationDetailsPopulator.createOperationView(operationFlowsView, OperationResource.DATAHUB, EXPECTED_TYPE_LIST)).willReturn(new OperationView());
    given(stackOperations.getStackByCrn(anyString())).willReturn(stack);
    given(stack.getExternalDatabaseCreationType()).willReturn(DatabaseAvailabilityType.NON_HA);
    given(databaseService.getRemoteDatabaseOperationProgress(any(), anyBoolean())).willReturn(Optional.of(remoteDatabaseOperationView));
    // WHEN
    OperationView result = underTest.getOperationProgressByResourceCrn(TEST_CLUSTER_CRN, true);
    // THEN
    assertEquals(remoteDatabaseOperationView, result.getSubOperations().get(OperationResource.REMOTEDB));
    verify(databaseService, times(1)).getRemoteDatabaseOperationProgress(any(), anyBoolean());
    verify(operationDetailsPopulator, times(1)).createOperationView(operationFlowsView, OperationResource.DATAHUB, EXPECTED_TYPE_LIST);
}
Also used : OperationView(com.sequenceiq.flow.api.model.operation.OperationView) Test(org.junit.jupiter.api.Test)

Example 20 with OperationView

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

the class FlowOperationServiceTest method testGetOperationProgressByResourceCrn.

@Test
public void testGetOperationProgressByResourceCrn() {
    // GIVEN
    ProvisionFlowEventChainFactory provisionFlowEventChainFactory = new ProvisionFlowEventChainFactory();
    FlowTriggerEventQueue eventQueue = provisionFlowEventChainFactory.createFlowTriggerEventQueue(new StackEvent(null, null));
    given(flowService.getLastFlowOperationByResourceCrn(anyString())).willReturn(Optional.of(operationFlowsView));
    given(operationFlowsView.getOperationType()).willReturn(OperationType.PROVISION);
    given(operationDetailsPopulator.createOperationView(operationFlowsView, OperationResource.FREEIPA, EXPECTED_TYPE_LIST)).willReturn(new OperationView());
    // WHEN
    underTest.getOperationProgressByEnvironmentCrn(TEST_ENV_CRN, false);
    // THEN
    verify(operationDetailsPopulator, times(1)).createOperationView(operationFlowsView, OperationResource.FREEIPA, EXPECTED_TYPE_LIST);
    // Checks that the number of provision flows are the same as in the operation check
    assertEquals(EXPECTED_TYPE_LIST.size(), eventQueue.getQueue().size());
}
Also used : FlowTriggerEventQueue(com.sequenceiq.flow.core.chain.config.FlowTriggerEventQueue) StackEvent(com.sequenceiq.freeipa.flow.stack.StackEvent) ProvisionFlowEventChainFactory(com.sequenceiq.freeipa.flow.chain.ProvisionFlowEventChainFactory) OperationView(com.sequenceiq.flow.api.model.operation.OperationView) Test(org.junit.jupiter.api.Test)

Aggregations

OperationView (com.sequenceiq.flow.api.model.operation.OperationView)20 OperationFlowsView (com.sequenceiq.flow.api.model.operation.OperationFlowsView)10 Test (org.junit.jupiter.api.Test)8 FlowProgressResponse (com.sequenceiq.flow.api.model.FlowProgressResponse)5 OperationResource (com.sequenceiq.flow.api.model.operation.OperationResource)5 HashMap (java.util.HashMap)5 OperationType (com.sequenceiq.flow.api.model.operation.OperationType)3 OperationCondition (com.sequenceiq.flow.api.model.operation.OperationCondition)2 OperationProgressStatus (com.sequenceiq.flow.api.model.operation.OperationProgressStatus)2 FlowTriggerEventQueue (com.sequenceiq.flow.core.chain.config.FlowTriggerEventQueue)2 ArrayList (java.util.ArrayList)2 Optional (java.util.Optional)2 PollerStoppedException (com.dyngr.exception.PollerStoppedException)1 DatabaseAvailabilityType (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.database.DatabaseAvailabilityType)1 ProvisionFlowEventChainFactory (com.sequenceiq.cloudbreak.core.flow2.chain.ProvisionFlowEventChainFactory)1 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)1 StackEvent (com.sequenceiq.cloudbreak.reactor.api.event.StackEvent)1 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)1 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)1 FlowStateTransitionResponse (com.sequenceiq.flow.api.model.FlowStateTransitionResponse)1