Search in sources :

Example 1 with OperationView

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

the class OperationService method getOperationProgressByResourceCrn.

public OperationView getOperationProgressByResourceCrn(String resourceCrn, boolean detailed) {
    OperationView stackOperationView = new OperationView();
    try {
        OperationResource operationResource = OperationResource.fromCrn(Crn.safeFromString(resourceCrn));
        Optional<OperationFlowsView> operationFlowsViewOpt = flowService.getLastFlowOperationByResourceCrn(resourceCrn);
        if (operationFlowsViewOpt.isPresent()) {
            OperationFlowsView operationFlowsView = operationFlowsViewOpt.get();
            OperationType operationType = operationFlowsView.getOperationType();
            if (OperationType.PROVISION.equals(operationType)) {
                stackOperationView = handleProvisionOperation(resourceCrn, operationResource, operationFlowsView, detailed);
            } else {
                stackOperationView = operationDetailsPopulator.createOperationView(operationFlowsView, operationResource);
            }
        }
    } catch (Exception e) {
        LOGGER.debug(String.format("Could not fetch remote database details for stack with crn %s", resourceCrn), e);
    }
    return stackOperationView;
}
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) OperationResource(com.sequenceiq.flow.api.model.operation.OperationResource)

Example 2 with OperationView

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

the class OperationService method handleProvisionOperation.

private OperationView handleProvisionOperation(String resourceCrn, OperationResource operationResource, OperationFlowsView operationFlowsView, boolean detailed) {
    OperationView stackOperationView;
    stackOperationView = operationDetailsPopulator.createOperationView(operationFlowsView, operationResource, List.of(CloudConfigValidationFlowConfig.class, KerberosConfigValidationFlowConfig.class, ExternalDatabaseCreationFlowConfig.class, StackCreationFlowConfig.class, ClusterCreationFlowConfig.class));
    if (detailed && !OperationResource.DATALAKE.equals(operationResource)) {
        Stack stack = stackOperations.getStackByCrn(resourceCrn);
        DatabaseAvailabilityType databaseAvailabilityType = stack.getExternalDatabaseCreationType();
        Map<OperationResource, OperationCondition> conditionMap = new HashMap<>();
        Map<OperationResource, OperationView> subOperations = new HashMap<>();
        if (!DatabaseAvailabilityType.NONE.equals(databaseAvailabilityType)) {
            conditionMap.put(OperationResource.REMOTEDB, OperationCondition.REQUIRED);
            subOperations.put(OperationResource.REMOTEDB, databaseService.getRemoteDatabaseOperationProgress(stack, detailed).orElse(null));
        } else {
            conditionMap.put(OperationResource.REMOTEDB, OperationCondition.NONE);
        }
        stackOperationView.setSubOperationConditions(conditionMap);
        stackOperationView.setSubOperations(subOperations);
    }
    return stackOperationView;
}
Also used : OperationCondition(com.sequenceiq.flow.api.model.operation.OperationCondition) HashMap(java.util.HashMap) OperationView(com.sequenceiq.flow.api.model.operation.OperationView) OperationResource(com.sequenceiq.flow.api.model.operation.OperationResource) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) DatabaseAvailabilityType(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.database.DatabaseAvailabilityType)

Example 3 with OperationView

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

the class SdxPollerProviderTest method getOperationViewWithStatus.

private OperationView getOperationViewWithStatus(OperationProgressStatus status) {
    OperationView operationView = new OperationView();
    operationView.setProgressStatus(status);
    return operationView;
}
Also used : OperationView(com.sequenceiq.flow.api.model.operation.OperationView)

Example 4 with OperationView

use of com.sequenceiq.flow.api.model.operation.OperationView 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()) {
        return operationDetailsPopulator.createOperationView(operationFlowsViewOpt.get(), OperationResource.REMOTEDB);
    }
    return response;
}
Also used : OperationView(com.sequenceiq.flow.api.model.operation.OperationView) OperationFlowsView(com.sequenceiq.flow.api.model.operation.OperationFlowsView)

Example 5 with OperationView

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

the class OperationServiceTest method testGetOperationProgressByResourceCrnWithDatalake.

@Test
public void testGetOperationProgressByResourceCrnWithDatalake() {
    // 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.DATALAKE, EXPECTED_TYPE_LIST)).willReturn(operationView);
    // WHEN
    OperationView result = underTest.getOperationProgressByResourceCrn(TEST_DATALAKE_CRN, true);
    // THEN
    assertEquals(operationView, result);
    verify(operationDetailsPopulator, times(1)).createOperationView(operationFlowsView, OperationResource.DATALAKE, EXPECTED_TYPE_LIST);
    // Checks that the number of provision flows are the same as in the operation check
    assertEquals(eventQueue.getQueue().size(), EXPECTED_TYPE_LIST.size());
}
Also used : FlowTriggerEventQueue(com.sequenceiq.flow.core.chain.config.FlowTriggerEventQueue) StackEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackEvent) ProvisionFlowEventChainFactory(com.sequenceiq.cloudbreak.core.flow2.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