Search in sources :

Example 26 with BadRequestException

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

the class CustomImageCatalogService method delete.

public ImageCatalog delete(Long workspaceId, String imageCatalogName) {
    LOGGER.debug(String.format("Delete custom image catalog '%s' in workspace '%d'", imageCatalogName, workspaceId));
    ImageCatalog imageCatalog = imageCatalogService.getImageCatalogByName(workspaceId, imageCatalogName);
    if (Strings.isNullOrEmpty(imageCatalog.getImageCatalogUrl())) {
        return imageCatalogService.delete(workspaceId, imageCatalogName);
    } else {
        throw new BadRequestException(String.format("'%s' is not a custom image catalog.", imageCatalog.getName()));
    }
}
Also used : BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) ImageCatalog(com.sequenceiq.cloudbreak.domain.ImageCatalog)

Example 27 with BadRequestException

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

the class StackService method validateOrchestrator.

public void validateOrchestrator(Orchestrator orchestrator) {
    try {
        ContainerOrchestrator containerOrchestrator = containerOrchestratorResolver.get(orchestrator.getType());
        containerOrchestrator.validateApiEndpoint(new OrchestrationCredential(orchestrator.getApiEndpoint(), orchestrator.getAttributes().getMap()));
    } catch (CloudbreakException e) {
        throw new BadRequestException(format("Invalid orchestrator type: %s", e.getMessage()));
    } catch (CloudbreakOrchestratorException e) {
        throw new BadRequestException(format("Error occurred when trying to reach orchestrator API: %s", e.getMessage()));
    }
}
Also used : CloudbreakOrchestratorException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException) ContainerOrchestrator(com.sequenceiq.cloudbreak.orchestrator.container.ContainerOrchestrator) OrchestrationCredential(com.sequenceiq.cloudbreak.orchestrator.model.OrchestrationCredential) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException)

Example 28 with BadRequestException

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

the class StackService method setDefaultTags.

private void setDefaultTags(Stack stack) {
    try {
        StackTags stackTag = stack.getTags().get(StackTags.class);
        Map<String, String> userDefinedTags = stackTag.getUserDefinedTags();
        String accountId = Crn.safeFromString(stack.getResourceCrn()).getAccountId();
        boolean internalTenant = entitlementService.internalTenant(accountId);
        CDPTagGenerationRequest request = CDPTagGenerationRequest.Builder.builder().withCreatorCrn(stack.getCreator().getUserCrn()).withEnvironmentCrn(stack.getEnvironmentCrn()).withPlatform(stack.getCloudPlatform()).withAccountId(accountId).withResourceCrn(stack.getResourceCrn()).withIsInternalTenant(internalTenant).withUserName(stack.getCreator().getUserName()).withAccountTags(accountTagClientService.list()).withUserDefinedTags(userDefinedTags).build();
        Map<String, String> defaultTags = stackTag.getDefaultTags();
        defaultTags.putAll(costTagging.prepareDefaultTags(request));
        stack.setTags(new Json(new StackTags(userDefinedTags, stackTag.getApplicationTags(), defaultTags)));
    } catch (AccountTagValidationFailed aTVF) {
        throw new BadRequestException(aTVF.getMessage(), aTVF);
    } catch (Exception e) {
        LOGGER.debug("Exception during reading default tags.", e);
    }
}
Also used : StackTags(com.sequenceiq.cloudbreak.cloud.model.StackTags) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) CDPTagGenerationRequest(com.sequenceiq.cloudbreak.tag.request.CDPTagGenerationRequest) Json(com.sequenceiq.cloudbreak.common.json.Json) AccountTagValidationFailed(com.sequenceiq.cloudbreak.tag.AccountTagValidationFailed) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) TransactionRuntimeExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionRuntimeExecutionException) CloudbreakOrchestratorException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorException) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) IOException(java.io.IOException) CloudbreakImageCatalogException(com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) CloudbreakApiException(com.sequenceiq.cloudbreak.exception.CloudbreakApiException) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException)

Example 29 with BadRequestException

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

the class StackOperationService method updateNodeCount.

public FlowIdentifier updateNodeCount(Stack stack, InstanceGroupAdjustmentV4Request instanceGroupAdjustmentJson, boolean withClusterEvent) {
    environmentService.checkEnvironmentStatus(stack, EnvironmentStatus.upscalable());
    try {
        return transactionService.required(() -> {
            boolean upscale = instanceGroupAdjustmentJson.getScalingAdjustment() > 0;
            Stack stackWithLists = stackService.getByIdWithLists(stack.getId());
            updateNodeCountValidator.validateServiceRoles(stackWithLists, instanceGroupAdjustmentJson);
            updateNodeCountValidator.validateStackStatus(stackWithLists, upscale);
            updateNodeCountValidator.validateInstanceGroup(stackWithLists, instanceGroupAdjustmentJson.getInstanceGroup());
            updateNodeCountValidator.validateScalabilityOfInstanceGroup(stackWithLists, instanceGroupAdjustmentJson);
            updateNodeCountValidator.validateScalingAdjustment(instanceGroupAdjustmentJson, stackWithLists);
            boolean instanceStatusValidationNeeded = !upscale || !targetedUpscaleSupportService.targetedUpscaleOperationSupported(stackWithLists);
            if (instanceStatusValidationNeeded) {
                updateNodeCountValidator.validateInstanceStatuses(stackWithLists, instanceGroupAdjustmentJson);
            }
            if (withClusterEvent) {
                updateNodeCountValidator.validateClusterStatus(stackWithLists, upscale);
                updateNodeCountValidator.validateHostGroupIsPresent(instanceGroupAdjustmentJson, stackWithLists);
                if (instanceStatusValidationNeeded) {
                    updateNodeCountValidator.validataHostMetadataStatuses(stackWithLists, instanceGroupAdjustmentJson);
                }
            }
            if (upscale) {
                stackUpdater.updateStackStatus(stackWithLists.getId(), DetailedStackStatus.UPSCALE_REQUESTED, "Requested node count for upscaling: " + instanceGroupAdjustmentJson.getScalingAdjustment());
                return flowManager.triggerStackUpscale(stackWithLists.getId(), instanceGroupAdjustmentJson, withClusterEvent);
            } else {
                stackUpdater.updateStackStatus(stackWithLists.getId(), DetailedStackStatus.DOWNSCALE_REQUESTED, "Requested node count for downscaling: " + abs(instanceGroupAdjustmentJson.getScalingAdjustment()));
                return flowManager.triggerStackDownscale(stackWithLists.getId(), instanceGroupAdjustmentJson);
            }
        });
    } catch (TransactionExecutionException e) {
        if (e.getCause() instanceof ConcurrencyFailureException) {
            LOGGER.info("A concurrent update arrived to this cluster.", e.getCause());
            throw new BadRequestException("A concurrent update arrived to this cluster. Please try again later.");
        }
        if (e.getCause() instanceof BadRequestException) {
            throw e.getCause();
        }
        throw new TransactionRuntimeExecutionException(e);
    }
}
Also used : TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) ConcurrencyFailureException(org.springframework.dao.ConcurrencyFailureException) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) TransactionRuntimeExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionRuntimeExecutionException)

Example 30 with BadRequestException

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

the class StackOperationService method updateStatus.

public FlowIdentifier updateStatus(Long stackId, StatusRequest status, boolean updateCluster) {
    Stack stack = stackService.getByIdWithLists(stackId);
    Cluster cluster = null;
    if (stack.getCluster() != null) {
        cluster = clusterService.findOneWithLists(stack.getCluster().getId()).orElse(null);
    }
    switch(status) {
        case SYNC:
            return sync(stack, false);
        case FULL_SYNC:
            return sync(stack, true);
        case REPAIR_FAILED_NODES:
            return repairFailedNodes(stack);
        case STOPPED:
            return stop(stack, cluster, updateCluster);
        case STARTED:
            return start(stack);
        default:
            throw new BadRequestException("Cannot update the status of stack because status request not valid.");
    }
}
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