Search in sources :

Example 11 with OperationView

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

the class OperationService method handleProvisionOperation.

private void handleProvisionOperation(String resourceCrn, OperationView response, boolean detailed) {
    String accountId = ThreadBasedUserCrnProvider.getAccountId();
    EnvironmentDto envDto = environmentService.getByCrnAndAccountId(resourceCrn, accountId);
    boolean needsFreeipa = envDto.getFreeIpaCreation().getCreate();
    if (needsFreeipa) {
        Optional<OperationView> freeIpaFlows = freeIpaService.getFreeIpaOperation(resourceCrn, detailed);
        response.setSubOperationConditions(Map.of(OperationResource.FREEIPA, OperationCondition.REQUIRED));
        if (freeIpaFlows.isPresent()) {
            OperationView freeIpaOpView = freeIpaFlows.get();
            if (OperationType.PROVISION.equals(freeIpaOpView.getOperationType())) {
                response.setSubOperations(Map.of(OperationResource.FREEIPA, freeIpaOpView));
            }
        }
    } else {
        response.setSubOperationConditions(Map.of(OperationResource.FREEIPA, OperationCondition.NONE));
    }
}
Also used : EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) OperationView(com.sequenceiq.flow.api.model.operation.OperationView)

Example 12 with OperationView

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

the class OperationService method handleProvisionOperation.

private void handleProvisionOperation(String resourceCrn, OperationView sdxOperationView, boolean detailed) {
    String userCrn = ThreadBasedUserCrnProvider.getUserCrn();
    SdxCluster sdxCluster = sdxService.getByCrn(userCrn, resourceCrn);
    boolean createDb = sdxCluster.isCreateDatabase();
    Map<OperationResource, OperationView> subOperations = new HashMap<>();
    Map<OperationResource, OperationCondition> conditionMap = new HashMap<>();
    conditionMap.put(OperationResource.DATALAKE, OperationCondition.REQUIRED);
    if (createDb) {
        conditionMap.put(OperationResource.REMOTEDB, OperationCondition.REQUIRED);
        try {
            OperationView rdbOperationView = databaseService.getOperationProgressStatus(sdxCluster.getDatabaseCrn(), detailed);
            if (OperationType.PROVISION.equals(rdbOperationView.getOperationType())) {
                subOperations.put(OperationResource.REMOTEDB, rdbOperationView);
            }
        } catch (Exception e) {
            LOGGER.warn("Error during fetching provision progress from remote database API. Skip filling remote database response.", e);
        }
    } else {
        conditionMap.put(OperationResource.REMOTEDB, OperationCondition.NONE);
    }
    sdxOperationView.setSubOperationConditions(conditionMap);
    try {
        OperationView stackOperationProgressView = operationV4Endpoint.getOperationProgressByResourceCrn(resourceCrn, detailed);
        if (OperationType.PROVISION.equals(stackOperationProgressView.getOperationType())) {
            subOperations.put(OperationResource.DATALAKE, stackOperationProgressView);
        }
    } catch (Exception e) {
        LOGGER.warn("Error during fetching provision progress from stack API. Skip filling stack progress response.", e);
    }
    sdxOperationView.setSubOperations(subOperations);
}
Also used : OperationCondition(com.sequenceiq.flow.api.model.operation.OperationCondition) HashMap(java.util.HashMap) OperationView(com.sequenceiq.flow.api.model.operation.OperationView) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) OperationResource(com.sequenceiq.flow.api.model.operation.OperationResource)

Example 13 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 sdxOperationView = new OperationView();
    Optional<OperationFlowsView> operationFlowsViewOpt = flowService.getLastFlowOperationByResourceCrn(resourceCrn);
    if (operationFlowsViewOpt.isPresent()) {
        OperationFlowsView operationFlowsView = operationFlowsViewOpt.get();
        OperationType operationType = operationFlowsView.getOperationType();
        sdxOperationView = operationDetailsPopulator.createOperationView(operationFlowsView, OperationResource.DATALAKE);
        if (OperationType.PROVISION.equals(operationType)) {
            if (detailed) {
                handleProvisionOperation(resourceCrn, sdxOperationView, detailed);
            } else {
                LOGGER.debug("Skipping detailed SDX provision operation response");
            }
        }
    }
    return sdxOperationView;
}
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)

Example 14 with OperationView

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

the class SdxPollerProvider method upgradeCcmPoller.

public AttemptResult<Void> upgradeCcmPoller(Long envId, String datalakeCrn) {
    if (PollGroup.CANCELLED.equals(EnvironmentInMemoryStateStore.get(envId))) {
        String message = "SDX polling cancelled in inmemory store, environment id: " + envId;
        LOGGER.info(message);
        throw new PollerStoppedException(message);
    }
    OperationView operation = sdxService.getOperation(datalakeCrn, false);
    OperationProgressStatus progressStatus = operation.getProgressStatus();
    switch(progressStatus) {
        case CANCELLED:
            return AttemptResults.breakFor("SDX Upgrade CCM cancelled for datalake CRN " + datalakeCrn);
        case FAILED:
            return AttemptResults.breakFor("SDX Upgrade CCM failed for environment CRN " + datalakeCrn);
        case FINISHED:
            return AttemptResults.justFinish();
        case RUNNING:
            return AttemptResults.justContinue();
        default:
            return AttemptResults.breakFor("SDX Upgrade CCM is in ambiguous state " + progressStatus + " for environment CRN " + datalakeCrn);
    }
}
Also used : OperationProgressStatus(com.sequenceiq.flow.api.model.operation.OperationProgressStatus) OperationView(com.sequenceiq.flow.api.model.operation.OperationView) PollerStoppedException(com.dyngr.exception.PollerStoppedException)

Example 15 with OperationView

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

the class OperationDetailsPopulator method populateOperationDetails.

private void populateOperationDetails(OperationView source, List<Optional<FlowProgressResponse>> operations, int expectedNumberOfFlows, Integer progressFromHistory) {
    int preProgress = 0;
    int overallProgress = 0;
    boolean foundFlow = false;
    boolean expectFlowChainId = operations.size() > 1;
    for (Optional<FlowProgressResponse> operationOpt : operations) {
        if (operationOpt.isPresent()) {
            if (!foundFlow) {
                overallProgress += preProgress;
                source.setOperationId(operationOpt.get().getFlowId());
            }
            foundFlow = true;
            FlowProgressResponse flowProgress = operationOpt.get();
            if (flowProgress.getProgress() != DEFAULT_PROGRESS) {
                overallProgress += flowProgress.getProgress();
            }
            source.getOperations().add(flowProgress);
        } else if (expectFlowChainId && !foundFlow) {
            preProgress += MAX_PROGRESS;
            operationOpt.ifPresent(flowProgressResponse -> source.setOperationId(flowProgressResponse.getFlowChainId()));
        }
    }
    setProgressAndStatus(source, expectedNumberOfFlows, progressFromHistory, overallProgress);
}
Also used : FlowProgressResponse(com.sequenceiq.flow.api.model.FlowProgressResponse) FlowStateTransitionResponse(com.sequenceiq.flow.api.model.FlowStateTransitionResponse) OperationProgressStatus(com.sequenceiq.flow.api.model.operation.OperationProgressStatus) OperationView(com.sequenceiq.flow.api.model.operation.OperationView) StateStatus(com.sequenceiq.flow.api.model.StateStatus) Collectors(java.util.stream.Collectors) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ArrayList(java.util.ArrayList) List(java.util.List) Component(org.springframework.stereotype.Component) OperationFlowsView(com.sequenceiq.flow.api.model.operation.OperationFlowsView) Map(java.util.Map) OperationResource(com.sequenceiq.flow.api.model.operation.OperationResource) Optional(java.util.Optional) FlowProgressResponse(com.sequenceiq.flow.api.model.FlowProgressResponse)

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