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;
}
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;
}
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);
}
}
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()));
}
}
}
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;
}
Aggregations