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