Search in sources :

Example 41 with BadRequestException

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

the class NetworkConfigurationValidator method validateNetworkForStack.

public boolean validateNetworkForStack(Network network, Iterable<InstanceGroup> instanceGroups) {
    if (network.getSubnetCIDR() != null) {
        SubnetUtils utils = new SubnetUtils(network.getSubnetCIDR());
        int addressCount = utils.getInfo().getAddressCount();
        int nodeCount = 0;
        for (InstanceGroup instanceGroup : instanceGroups) {
            nodeCount += instanceGroup.getNodeCount();
        }
        if (addressCount < nodeCount) {
            LOGGER.error("Cannot assign more than {} addresses in the selected subnet.", addressCount);
            throw new BadRequestException(String.format("Cannot assign more than %s addresses in the selected subnet.", addressCount));
        }
    }
    return true;
}
Also used : SubnetUtils(org.apache.commons.net.util.SubnetUtils) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup)

Example 42 with BadRequestException

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

the class RdsConnectionBuilder method buildRdsConnection.

public Map<String, String> buildRdsConnection(String connectionURL, String connectionUserName, String connectionPassword, String clusterName, Iterable<String> targets) {
    Map<String, String> map = new HashMap<>();
    Properties connectionProps = new Properties();
    connectionProps.setProperty("user", connectionUserName);
    connectionProps.setProperty("password", connectionPassword);
    try (Connection conn = DriverManager.getConnection(connectionURL, connectionProps)) {
        for (String target : targets) {
            createDb(conn, clusterName, target);
            map.put(target, clusterName + target);
        }
    } catch (SQLException e) {
        throw new BadRequestException("Failed to connect to RDS: " + e.getMessage(), e);
    }
    return map;
}
Also used : HashMap(java.util.HashMap) SQLException(java.sql.SQLException) PSQLException(org.postgresql.util.PSQLException) Connection(java.sql.Connection) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) Properties(java.util.Properties)

Example 43 with BadRequestException

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

the class RdsConnectionBuilder method createDb.

private void createDb(Connection conn, String clusterName, String service) {
    String createSQL = "CREATE DATABASE ?";
    try (PreparedStatement preparedStatement = conn.prepareStatement(createSQL)) {
        preparedStatement.setString(1, clusterName + service);
        preparedStatement.executeUpdate(createSQL);
    } catch (PSQLException ex) {
        if ("42P04".equals(ex.getSQLState())) {
            LOGGER.warn("The expected database already exist");
        } else {
            throw new BadRequestException("Failed to create database in RDS: " + ex.getMessage(), ex);
        }
    } catch (SQLException e) {
        throw new BadRequestException("Failed to connect to RDS: " + e.getMessage(), e);
    }
}
Also used : SQLException(java.sql.SQLException) PSQLException(org.postgresql.util.PSQLException) PSQLException(org.postgresql.util.PSQLException) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) PreparedStatement(java.sql.PreparedStatement)

Example 44 with BadRequestException

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

the class TemplateValidator method validateVolumeType.

private void validateVolumeType(Template value, Platform platform) {
    DiskType diskType = DiskType.diskType(value.getVolumeType());
    Map<Platform, Collection<DiskType>> diskTypes = cloudParameterService.getDiskTypes().getDiskTypes();
    if (diskTypes.containsKey(platform) && !diskTypes.get(platform).isEmpty()) {
        if (!diskTypes.get(platform).contains(diskType)) {
            throw new BadRequestException(String.format("The '%s' platform does not support '%s' volume type", platform.value(), diskType.value()));
        }
    }
}
Also used : DiskType(com.sequenceiq.cloudbreak.cloud.model.DiskType) Platform(com.sequenceiq.cloudbreak.cloud.model.Platform) Collection(java.util.Collection) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException)

Example 45 with BadRequestException

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

the class UpdateAmbariRequestToUpdateClusterRequestConverter method convert.

@Override
public UpdateClusterJson convert(ReinstallRequestV2 source) {
    UpdateClusterJson updateStackJson = new UpdateClusterJson();
    updateStackJson.setValidateBlueprint(true);
    updateStackJson.setKerberosPassword(source.getKerberosPassword());
    updateStackJson.setKerberosPrincipal(source.getKerberosPrincipal());
    Blueprint blueprint = blueprintRepository.findOneByName(source.getBlueprintName(), source.getAccount());
    if (blueprint != null) {
        updateStackJson.setBlueprintId(blueprint.getId());
        updateStackJson.setAmbariStackDetails(source.getAmbariStackDetails());
        Set<HostGroupRequest> hostgroups = new HashSet<>();
        for (InstanceGroupV2Request instanceGroupV2Request : source.getInstanceGroups()) {
            HostGroupRequest hostGroupRequest = new HostGroupRequest();
            hostGroupRequest.setRecoveryMode(instanceGroupV2Request.getRecoveryMode());
            hostGroupRequest.setRecipeNames(instanceGroupV2Request.getRecipeNames());
            hostGroupRequest.setName(instanceGroupV2Request.getGroup());
            ConstraintJson constraintJson = new ConstraintJson();
            constraintJson.setHostCount(instanceGroupV2Request.getNodeCount());
            constraintJson.setInstanceGroupName(instanceGroupV2Request.getGroup());
            hostGroupRequest.setConstraint(constraintJson);
            hostgroups.add(hostGroupRequest);
        }
        updateStackJson.setHostgroups(hostgroups);
    } else {
        throw new BadRequestException(String.format("Blueprint '%s' not available", source.getBlueprintName()));
    }
    return updateStackJson;
}
Also used : InstanceGroupV2Request(com.sequenceiq.cloudbreak.api.model.v2.InstanceGroupV2Request) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) HostGroupRequest(com.sequenceiq.cloudbreak.api.model.HostGroupRequest) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) ConstraintJson(com.sequenceiq.cloudbreak.api.model.ConstraintJson) UpdateClusterJson(com.sequenceiq.cloudbreak.api.model.UpdateClusterJson) HashSet(java.util.HashSet)

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