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