Search in sources :

Example 11 with BadRequestException

use of com.sequenceiq.cloudbreak.controller.BadRequestException in project cloudbreak by hortonworks.

the class FlexSubscriptionRequestToFlexSubscriptionConverter method convert.

@Override
public FlexSubscription convert(FlexSubscriptionRequest source) {
    FlexSubscription subscription = new FlexSubscription();
    subscription.setName(source.getName());
    subscription.setSubscriptionId(source.getSubscriptionId());
    subscription.setDefault(source.getUsedAsDefault());
    subscription.setUsedForController(source.isUsedForController());
    Long smartSenseSubscriptionId = source.getSmartSenseSubscriptionId();
    try {
        SmartSenseSubscription smartSenseSubscription = smartSenseSubscriptionService.findOneById(smartSenseSubscriptionId);
        subscription.setSmartSenseSubscription(smartSenseSubscription);
    } catch (NotFoundException ignored) {
        throw new BadRequestException("SmartSense subscription could not be found with id: " + smartSenseSubscriptionId);
    }
    return subscription;
}
Also used : FlexSubscription(com.sequenceiq.cloudbreak.domain.FlexSubscription) SmartSenseSubscription(com.sequenceiq.cloudbreak.domain.SmartSenseSubscription) NotFoundException(com.sequenceiq.cloudbreak.controller.NotFoundException) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException)

Example 12 with BadRequestException

use of com.sequenceiq.cloudbreak.controller.BadRequestException in project cloudbreak by hortonworks.

the class RdsConnectionValidator method validateRdsConnection.

public void validateRdsConnection(String connectionURL, String connectionUserName, String connectionPassword) {
    Properties connectionProps = new Properties();
    connectionProps.setProperty("user", connectionUserName);
    connectionProps.setProperty("password", connectionPassword);
    try (Connection conn = DriverManager.getConnection(connectionURL, connectionProps)) {
        LOGGER.debug("RDS is available");
    } catch (SQLException e) {
        throw new BadRequestException("Failed to connect to RDS: " + e.getMessage(), e);
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) Properties(java.util.Properties)

Example 13 with BadRequestException

use of com.sequenceiq.cloudbreak.controller.BadRequestException in project cloudbreak by hortonworks.

the class TemplateValidator method validateCustomInstanceType.

private void validateCustomInstanceType(Template template) {
    Map<String, Object> params = template.getAttributes().getMap();
    Platform platform = Platform.platform(template.cloudPlatform());
    PlatformParameters pps = platformParameters.get().get(platform);
    if (pps != null) {
        Boolean customInstanceType = pps.specialParameters().getSpecialParameters().get(PlatformParametersConsts.CUSTOM_INSTANCETYPE);
        if (BooleanUtils.isTrue(customInstanceType)) {
            if (params.get(PlatformParametersConsts.CUSTOM_INSTANCETYPE_CPUS) == null || params.get(PlatformParametersConsts.CUSTOM_INSTANCETYPE_MEMORY) == null) {
                throw new BadRequestException(String.format("Missing 'cpus' or 'memory' param for custom instancetype on %s platform", template.cloudPlatform()));
            }
        } else {
            throw new BadRequestException(String.format("Custom instancetype is not supported on %s platform", template.cloudPlatform()));
        }
    }
}
Also used : Platform(com.sequenceiq.cloudbreak.cloud.model.Platform) PlatformParameters(com.sequenceiq.cloudbreak.cloud.PlatformParameters) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException)

Example 14 with BadRequestException

use of com.sequenceiq.cloudbreak.controller.BadRequestException in project cloudbreak by hortonworks.

the class TemplateValidator method validateTemplateRequest.

public void validateTemplateRequest(Credential credential, Template value, String region, String availabilityZone, String variant) {
    CloudVmTypes cloudVmTypes = cloudParameterService.getVmTypesV2(credential, region, variant, new HashMap<>());
    if (StringUtils.isEmpty(value.getInstanceType())) {
        validateCustomInstanceType(value);
    } else {
        VmType vmType = null;
        VolumeParameterType volumeParameterType = null;
        Platform platform = Platform.platform(value.cloudPlatform());
        Map<String, Set<VmType>> machines = cloudVmTypes.getCloudVmResponses();
        String locationString = locationService.location(region, availabilityZone);
        if (machines.containsKey(locationString) && !machines.get(locationString).isEmpty()) {
            for (VmType type : machines.get(locationString)) {
                if (type.value().equals(value.getInstanceType())) {
                    vmType = type;
                    break;
                }
            }
            if (vmType == null) {
                throw new BadRequestException(String.format("The '%s' instance type isn't supported by '%s' platform", value.getInstanceType(), platform.value()));
            }
        }
        Map<Platform, Map<String, VolumeParameterType>> disks = diskMappings.get();
        if (disks.containsKey(platform) && !disks.get(platform).isEmpty()) {
            Map<String, VolumeParameterType> map = disks.get(platform);
            volumeParameterType = map.get(value.getVolumeType());
            if (volumeParameterType == null) {
                throw new BadRequestException(String.format("The '%s' volume type isn't supported by '%s' platform", value.getVolumeType(), platform.value()));
            }
        }
        validateVolume(value, vmType, platform, volumeParameterType);
    }
}
Also used : CloudVmTypes(com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes) Set(java.util.Set) Platform(com.sequenceiq.cloudbreak.cloud.model.Platform) VmType(com.sequenceiq.cloudbreak.cloud.model.VmType) VolumeParameterType(com.sequenceiq.cloudbreak.cloud.model.VolumeParameterType) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 15 with BadRequestException

use of com.sequenceiq.cloudbreak.controller.BadRequestException in project cloudbreak by hortonworks.

the class FileSystemValidator method validateFileSystem.

public void validateFileSystem(String platform, CloudCredential cloudCredential, FileSystemRequest fileSystemRequest) {
    if (fileSystemRequest == null) {
        return;
    }
    validateFilesystemRequest(fileSystemRequest);
    LOGGER.debug("Sending fileSystemRequest to {} to validate the file system", platform);
    CloudContext cloudContext = new CloudContext(null, null, platform, null, null, null);
    FileSystem fileSystem = converter.convert(fileSystemRequest);
    FileSystemValidationRequest request = new FileSystemValidationRequest(fileSystem, 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) FileSystem(com.sequenceiq.cloudbreak.cloud.model.FileSystem) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) OperationException(com.sequenceiq.cloudbreak.service.stack.connector.OperationException) IOException(java.io.IOException) ConstraintViolationException(javax.validation.ConstraintViolationException) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) OperationException(com.sequenceiq.cloudbreak.service.stack.connector.OperationException)

Aggregations

BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)87 Stack (com.sequenceiq.cloudbreak.domain.Stack)16 Transactional (javax.transaction.Transactional)13 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)12 Cluster (com.sequenceiq.cloudbreak.domain.Cluster)12 Json (com.sequenceiq.cloudbreak.domain.json.Json)12 DataIntegrityViolationException (org.springframework.dao.DataIntegrityViolationException)12 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)11 HostGroup (com.sequenceiq.cloudbreak.domain.HostGroup)9 InstanceGroup (com.sequenceiq.cloudbreak.domain.InstanceGroup)9 IOException (java.io.IOException)7 Credential (com.sequenceiq.cloudbreak.domain.Credential)6 HashMap (java.util.HashMap)6 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 Constraint (com.sequenceiq.cloudbreak.domain.Constraint)5 BlueprintParameterJson (com.sequenceiq.cloudbreak.api.model.BlueprintParameterJson)4 Platform (com.sequenceiq.cloudbreak.cloud.model.Platform)4 CloudbreakException (com.sequenceiq.cloudbreak.service.CloudbreakException)4 HashSet (java.util.HashSet)4 BlueprintInputJson (com.sequenceiq.cloudbreak.api.model.BlueprintInputJson)3