Search in sources :

Example 1 with BadRequestException

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

the class FileSystemValidator method validate.

public void validate(String platform, CloudCredential cloudCredential, CloudStorageBase cloudStorageRequest, Long workspaceId) {
    if (cloudStorageRequest == null) {
        return;
    }
    LOGGER.info("Sending fileSystemRequest to {} to validate the file system", platform);
    CloudContext cloudContext = CloudContext.Builder.builder().withPlatform(platform).withWorkspaceId(workspaceId).build();
    SpiFileSystem spiFileSystem = cloudStorageConverter.requestToSpiFileSystem(cloudStorageRequest);
    FileSystemValidationRequest request = new FileSystemValidationRequest(spiFileSystem, cloudCredential, cloudContext);
    eventBus.notify(request.selector(), eventFactory.createEvent(request));
    try {
        FileSystemValidationResult result = request.await();
        LOGGER.info("File system validation result: {}", result);
        Exception exception = result.getErrorDetails();
        if (exception != null) {
            throw new BadRequestException(result.getStatusReason(), exception);
        }
    } catch (InterruptedException e) {
        LOGGER.error("Error while sending the file system validation request", e);
        throw new OperationException(e);
    }
}
Also used : FileSystemValidationResult(com.sequenceiq.cloudbreak.cloud.event.validation.FileSystemValidationResult) FileSystemValidationRequest(com.sequenceiq.cloudbreak.cloud.event.validation.FileSystemValidationRequest) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) SpiFileSystem(com.sequenceiq.cloudbreak.cloud.model.SpiFileSystem) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) OperationException(com.sequenceiq.cloudbreak.service.OperationException) OperationException(com.sequenceiq.cloudbreak.service.OperationException)

Example 2 with BadRequestException

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

the class ImageCatalogService method getImagesFromDefault.

public Images getImagesFromDefault(Long workspaceId, String stackName, String platform, Set<String> operatingSystems) throws CloudbreakImageCatalogException {
    if (isNotEmpty(platform) && isNotEmpty(stackName)) {
        throw new BadRequestException("Platform or stackName cannot be filled in the same request.");
    }
    if (isNotEmpty(platform)) {
        User user = getLoggedInUser();
        ImageFilter imageFilter = new ImageFilter(getDefaultImageCatalog(user), Set.of(platform), null, baseImageEnabled(), operatingSystems, null);
        return getStatedImagesFilteredByOperatingSystems(imageFilter, image -> true).getImages();
    } else if (isNotEmpty(stackName)) {
        return stackImageFilterService.getApplicableImages(workspaceId, stackName);
    } else {
        throw new BadRequestException("Either platform or stackName should be filled in request.");
    }
}
Also used : EntitlementService(com.sequenceiq.cloudbreak.auth.altus.EntitlementService) UserProfileService(com.sequenceiq.cloudbreak.service.user.UserProfileService) LoggerFactory(org.slf4j.LoggerFactory) TransactionRuntimeExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionRuntimeExecutionException) StringUtils(org.apache.commons.lang3.StringUtils) CloudbreakRestRequestThreadLocalService(com.sequenceiq.cloudbreak.structuredevent.CloudbreakRestRequestThreadLocalService) ThreadBasedUserCrnProvider(com.sequenceiq.cloudbreak.auth.ThreadBasedUserCrnProvider) TransactionService(com.sequenceiq.cloudbreak.common.service.TransactionService) Map(java.util.Map) AuthorizationResourceType(com.sequenceiq.authorization.resource.AuthorizationResourceType) Images(com.sequenceiq.cloudbreak.cloud.model.catalog.Images) CloudbreakImageCatalogException(com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) EnumSet(java.util.EnumSet) ResourceWithId(com.sequenceiq.authorization.service.list.ResourceWithId) ImmutableSet(com.google.common.collect.ImmutableSet) ImageCatalogRepository(com.sequenceiq.cloudbreak.repository.ImageCatalogRepository) WorkspaceResourceRepository(com.sequenceiq.cloudbreak.workspace.repository.workspace.WorkspaceResourceRepository) Collections.emptyList(java.util.Collections.emptyList) Predicate(java.util.function.Predicate) Collection(java.util.Collection) Set(java.util.Set) Crn(com.sequenceiq.cloudbreak.auth.crn.Crn) Collectors(java.util.stream.Collectors) ImageCatalog(com.sequenceiq.cloudbreak.domain.ImageCatalog) Sets(com.google.common.collect.Sets) Objects(java.util.Objects) List(java.util.List) MDCUtils(com.sequenceiq.cloudbreak.logger.MDCUtils) CollectionUtils(org.springframework.util.CollectionUtils) TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) UserProfile(com.sequenceiq.cloudbreak.domain.UserProfile) PreferencesService(com.sequenceiq.cloudbreak.service.account.PreferencesService) Optional(java.util.Optional) UserProfileHandler(com.sequenceiq.cloudbreak.service.user.UserProfileHandler) Collectors.partitioningBy(java.util.stream.Collectors.partitioningBy) OwnerAssignmentService(com.sequenceiq.authorization.service.OwnerAssignmentService) HashMap(java.util.HashMap) BooleanUtils(org.apache.commons.lang3.BooleanUtils) CompositeAuthResourcePropertyProvider(com.sequenceiq.authorization.service.CompositeAuthResourcePropertyProvider) StringUtils.isNotEmpty(org.apache.commons.lang3.StringUtils.isNotEmpty) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) Value(org.springframework.beans.factory.annotation.Value) Strings(com.google.common.base.Strings) CrnResourceDescriptor(com.sequenceiq.cloudbreak.auth.crn.CrnResourceDescriptor) StatedImage.statedImage(com.sequenceiq.cloudbreak.service.image.StatedImage.statedImage) ImageType(com.sequenceiq.common.api.type.ImageType) CloudbreakImageCatalogV3(com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV3) Nonnull(javax.annotation.Nonnull) NotFoundException.notFound(com.sequenceiq.cloudbreak.common.exception.NotFoundException.notFound) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) Logger(org.slf4j.Logger) Collections.emptySet(java.util.Collections.emptySet) StatedImages.statedImages(com.sequenceiq.cloudbreak.service.image.StatedImages.statedImages) RegionAwareCrnGenerator(com.sequenceiq.cloudbreak.auth.crn.RegionAwareCrnGenerator) Image(com.sequenceiq.cloudbreak.cloud.model.catalog.Image) Workspace(com.sequenceiq.cloudbreak.workspace.model.Workspace) NameOrCrn(com.sequenceiq.cloudbreak.api.endpoint.v4.dto.NameOrCrn) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) ImageCatalogServiceProxy(com.sequenceiq.cloudbreak.service.image.catalog.ImageCatalogServiceProxy) Collectors.toList(java.util.stream.Collectors.toList) Component(org.springframework.stereotype.Component) User(com.sequenceiq.cloudbreak.workspace.model.User) CustomImage(com.sequenceiq.cloudbreak.domain.CustomImage) NameUtil.generateArchiveName(com.sequenceiq.cloudbreak.util.NameUtil.generateArchiveName) Comparator(java.util.Comparator) AbstractWorkspaceAwareResourceService(com.sequenceiq.cloudbreak.service.AbstractWorkspaceAwareResourceService) User(com.sequenceiq.cloudbreak.workspace.model.User) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException)

Example 3 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, CloudCredential cloudCredential, Stack stack, User user, Workspace workspace, DetailedEnvironmentResponse environment) {
    MdcContext.builder().userCrn(user.getUserCrn()).tenant(user.getTenant().getName()).buildMdc();
    CloudCredential credential = cloudCredential;
    if (credential == null) {
        credential = stackUtil.getCloudCredential(stack);
    }
    fileSystemValidator.validate(stack.cloudPlatform(), credential, request.getCloudStorage(), stack.getWorkspace().getId());
    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 : CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) 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 4 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, Cluster cluster) {
    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 a cluster '%s'. Reason: %s", cluster.getId(), reason.getReason()));
    } else if (!stack.isReadyForStop() && !stack.isStopFailed()) {
        throw NotAllowedStatusUpdate.cluster(stack).to(STOPPED).expectedIn(AVAILABLE).badRequest();
    } else {
        clusterService.updateClusterStatusByStackId(stack.getId(), DetailedStackStatus.STOP_REQUESTED);
        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 5 with BadRequestException

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

the class SdxService method validateInternalSdxRequest.

private void validateInternalSdxRequest(StackV4Request stackv4Request, SdxClusterShape clusterShape) {
    ValidationResultBuilder validationResultBuilder = ValidationResult.builder();
    if (stackv4Request != null) {
        if (!clusterShape.equals(CUSTOM)) {
            validationResultBuilder.error("Cluster shape '" + clusterShape + "' is not accepted on SDX Internal API. Use 'CUSTOM' cluster shape");
        }
        if (stackv4Request.getCluster() == null) {
            validationResultBuilder.error("Cluster cannot be null.");
        }
    }
    ValidationResult validationResult = validationResultBuilder.build();
    if (validationResult.hasError()) {
        LOGGER.error("Cannot create SDX via internal API: {}", validationResult.getFormattedErrors());
        throw new BadRequestException(validationResult.getFormattedErrors());
    }
}
Also used : ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult)

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