Search in sources :

Example 11 with BadRequestException

use of com.sequenceiq.cloudbreak.common.exception.BadRequestException in project cloudbreak by hortonworks.

the class ClusterCommonService method put.

public FlowIdentifier put(String crn, UpdateClusterV4Request updateJson) {
    Stack stack = stackService.getByCrnWithLists(crn);
    Long stackId = stack.getId();
    MDCBuilder.buildMdcContext(stack);
    UserNamePasswordV4Request userNamePasswordJson = updateJson.getUserNamePassword();
    FlowIdentifier flowIdentifier;
    if (userNamePasswordJson != null) {
        flowIdentifier = clusterManagerUserNamePasswordChange(stack, userNamePasswordJson);
    } else if (updateJson.getStatus() != null) {
        LOGGER.debug("Cluster status update request received. Stack id:  {}, status: {} ", stackId, updateJson.getStatus());
        flowIdentifier = clusterOperationService.updateStatus(stackId, updateJson.getStatus());
    } else if (updateJson.getBlueprintName() != null && updateJson.getHostgroups() != null && stack.getCluster().isCreateFailed()) {
        LOGGER.debug("Cluster rebuild request received. Stack id:  {}", stackId);
        try {
            flowIdentifier = recreateCluster(stack, updateJson);
        } catch (TransactionExecutionException e) {
            throw new TransactionRuntimeExecutionException(e);
        }
    } else if (updateJson.getHostGroupAdjustment() != null) {
        environmentService.checkEnvironmentStatus(stack, EnvironmentStatus.upscalable());
        flowIdentifier = clusterHostgroupAdjustmentChange(stackId, updateJson, stack);
    } else {
        LOGGER.info("Invalid cluster update request received. Stack id: {}", stackId);
        throw new BadRequestException("Invalid update cluster request!");
    }
    return flowIdentifier;
}
Also used : TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) UserNamePasswordV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.UserNamePasswordV4Request) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) TransactionRuntimeExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionRuntimeExecutionException)

Example 12 with BadRequestException

use of com.sequenceiq.cloudbreak.common.exception.BadRequestException in project cloudbreak by hortonworks.

the class ClusterCommonService method setMaintenanceMode.

public FlowIdentifier setMaintenanceMode(Stack stack, MaintenanceModeStatus maintenanceMode) {
    Cluster cluster = stack.getCluster();
    if (cluster == null) {
        throw new BadRequestException(String.format("Cluster does not exist on stack with '%s' id.", stack.getId()));
    } else if (!stack.isAvailable() && !stack.isMaintenanceModeEnabled()) {
        throw new BadRequestException(String.format("Cluster '%s' is currently in '%s' state. Maintenance mode can be set to a cluster if it is 'AVAILABLE'.", stack.getId(), stack.getStatus()));
    }
    FlowIdentifier flowIdentifier = FlowIdentifier.notTriggered();
    switch(maintenanceMode) {
        case ENABLED:
            saveAndFireEventOnClusterStatusChange(stack, DetailedStackStatus.MAINTENANCE_MODE_ENABLED, ResourceEvent.MAINTENANCE_MODE_ENABLED);
            break;
        case DISABLED:
            saveAndFireEventOnClusterStatusChange(stack, DetailedStackStatus.AVAILABLE, ResourceEvent.MAINTENANCE_MODE_DISABLED);
            break;
        case VALIDATION_REQUESTED:
            if (!MAINTENANCE_MODE_ENABLED.equals(stack.getStatus())) {
                throw new BadRequestException(String.format("Maintenance mode is not enabled for cluster '%s' (status:'%s'), it should be enabled before validation.", cluster.getId(), stack.getStatus()));
            }
            flowIdentifier = clusterOperationService.triggerMaintenanceModeValidation(stack);
            clusterService.save(cluster);
            break;
        default:
            // Nothing to do here
            break;
    }
    return flowIdentifier;
}
Also used : Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier)

Example 13 with BadRequestException

use of com.sequenceiq.cloudbreak.common.exception.BadRequestException in project cloudbreak by hortonworks.

the class ClusterCreationSetupService method validate.

@Measure(ClusterCreationSetupService.class)
public void validate(ClusterV4Request request, Stack stack, User user, Workspace workspace, DetailedEnvironmentResponse environment) {
    MdcContext.builder().userCrn(user.getUserCrn()).tenant(user.getTenant().getName()).buildMdc();
    rdsConfigValidator.validateRdsConfigs(request, user, workspace);
    ValidationResult.ValidationResultBuilder resultBuilder = ValidationResult.builder();
    environmentValidator.validateRdsConfigNames(request.getDatabases(), resultBuilder, stack.getWorkspace().getId());
    environmentValidator.validateProxyConfig(request.getProxyConfigCrn(), resultBuilder);
    String parentEnvironmentCloudPlatform = environment.getParentEnvironmentCloudPlatform();
    environmentValidator.validateAutoTls(request, stack, resultBuilder, parentEnvironmentCloudPlatform);
    ValidationResult build = resultBuilder.build();
    if (build.hasError()) {
        throw new BadRequestException(build.getFormattedErrors());
    }
}
Also used : BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) Benchmark.multiCheckedMeasure(com.sequenceiq.cloudbreak.util.Benchmark.multiCheckedMeasure) Measure(com.sequenceiq.cloudbreak.aspect.Measure)

Example 14 with BadRequestException

use of com.sequenceiq.cloudbreak.common.exception.BadRequestException in project cloudbreak by hortonworks.

the class ClusterOperationService method stop.

private FlowIdentifier stop(Stack stack) {
    StopRestrictionReason reason = stackStopRestrictionService.isInfrastructureStoppable(stack);
    FlowIdentifier flowIdentifier = FlowIdentifier.notTriggered();
    if (stack.isStopped()) {
        eventService.fireCloudbreakEvent(stack.getId(), stack.getStatus().name(), CLUSTER_STOP_IGNORED);
    } else if (reason != StopRestrictionReason.NONE) {
        throw new BadRequestException(String.format("Cannot stop the cluster. Reason: %s", reason.getReason()));
    } else if (!stack.isReadyForStop() && !stack.isStopFailed()) {
        throw NotAllowedStatusUpdate.cluster(stack).to(STOPPED).expectedIn(AVAILABLE).badRequest();
    } else {
        flowIdentifier = flowManager.triggerClusterStop(stack.getId());
    }
    return flowIdentifier;
}
Also used : StopRestrictionReason(com.sequenceiq.cloudbreak.domain.StopRestrictionReason) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier)

Example 15 with BadRequestException

use of com.sequenceiq.cloudbreak.common.exception.BadRequestException in project cloudbreak by hortonworks.

the class ClusterOperationService method updateHosts.

public FlowIdentifier updateHosts(Long stackId, HostGroupAdjustmentV4Request hostGroupAdjustment) {
    Stack stack = stackService.getById(stackId);
    Cluster cluster = stack.getCluster();
    if (cluster == null) {
        throw new BadRequestException(String.format("There is no cluster installed on stack '%s'.", stack.getName()));
    }
    boolean downscaleRequest = updateHostsValidator.validateRequest(stack, hostGroupAdjustment);
    if (downscaleRequest) {
        stackUpdater.updateStackStatus(stackId, DetailedStackStatus.DOWNSCALE_REQUESTED, "Requested node count for downscaling: " + abs(hostGroupAdjustment.getScalingAdjustment()));
        return flowManager.triggerClusterDownscale(stackId, hostGroupAdjustment);
    } else {
        stackUpdater.updateStackStatus(stackId, DetailedStackStatus.UPSCALE_REQUESTED, "Requested node count for upscaling: " + hostGroupAdjustment.getScalingAdjustment());
        return flowManager.triggerClusterUpscale(stackId, hostGroupAdjustment);
    }
}
Also used : Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack)

Aggregations

BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)298 Test (org.junit.jupiter.api.Test)134 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)45 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)34 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)26 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)23 ValidationResult (com.sequenceiq.cloudbreak.validation.ValidationResult)22 StackV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request)21 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)21 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)19 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)19 Stack (com.sequenceiq.freeipa.entity.Stack)18 BaseDiagnosticsCollectionRequest (com.sequenceiq.common.api.diagnostics.BaseDiagnosticsCollectionRequest)14 FlowIdentifier (com.sequenceiq.flow.api.model.FlowIdentifier)14 SdxClusterRequest (com.sequenceiq.sdx.api.model.SdxClusterRequest)14 Set (java.util.Set)14 NotFoundException (com.sequenceiq.cloudbreak.common.exception.NotFoundException)13 NameOrCrn (com.sequenceiq.cloudbreak.api.endpoint.v4.dto.NameOrCrn)12 Json (com.sequenceiq.cloudbreak.common.json.Json)12 TransactionExecutionException (com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException)12