use of com.sequenceiq.environment.exception.EnvironmentServiceException in project cloudbreak by hortonworks.
the class CloudStorageLocationValidator method validate.
public void validate(String storageLocation, Environment environment, ValidationResultBuilder resultBuilder) {
Optional<FileSystemType> fileSystemType = getFileSystemType(environment);
if (fileSystemType.isPresent() && FileSystemType.GCS.equals(fileSystemType.get()) && !storageLocation.startsWith("gs://")) {
throw new EnvironmentServiceException(String.format("The Google storage location [%s] should be a gs:// URL. %s", storageLocation, getDocLink(environment.getCloudPlatform())));
}
String bucketName = getBucketName(fileSystemType, storageLocation);
CloudCredential cloudCredential = credentialToCloudCredentialConverter.convert(environment.getCredential());
ObjectStorageMetadataRequest request = createObjectStorageMetadataRequest(environment.getCloudPlatform(), cloudCredential, bucketName);
ObjectStorageMetadataResponse response = ThreadBasedUserCrnProvider.doAsInternalActor(regionAwareInternalCrnGeneratorFactory.iam().getInternalCrnForServiceAsString(), () -> cloudProviderServicesV4Endopint.getObjectStorageMetaData(request));
resultBuilder.ifError(() -> response.getStatus() == ResponseStatus.OK && !environment.getLocation().equals(response.getRegion()), String.format("Object storage location [%s] of bucket '%s' must match environment location [%s].%s", response.getRegion(), bucketName, environment.getLocation(), getDocLink(environment.getCloudPlatform())));
}
use of com.sequenceiq.environment.exception.EnvironmentServiceException in project cloudbreak by hortonworks.
the class PemBasedEnvironmentDomainProvider method generate.
public String generate(Environment environment) {
String managedDomain = null;
String environmentName = environment.getName();
String accountId = ThreadBasedUserCrnProvider.getAccountId();
LOGGER.debug("Generate managed domain name via PEM for environment ame: '{}' and account: '{}'", environmentName, accountId);
try {
managedDomain = dnsManagementService.generateManagedDomain(accountId, environmentName);
LOGGER.info("Generated managed domain name via PEM: '{}' for environment name: '{}' and account: '{}'", managedDomain, environmentName, accountId);
} catch (Exception ex) {
LOGGER.warn("Failed to generate managed domain name for the environment '{}' via PEM", environmentName, ex);
throw new EnvironmentServiceException("Failed to generate managed domain name for the environment", ex);
}
if (StringUtils.isEmpty(managedDomain)) {
throw new EnvironmentServiceException("Failed to generate managed domain name for the environment, initialization failed.");
}
return managedDomain;
}
use of com.sequenceiq.environment.exception.EnvironmentServiceException in project cloudbreak by hortonworks.
the class EnvironmentValidationHandler method validateCloudStorage.
private void validateCloudStorage(Event<EnvironmentValidationDto> environmentDtoEvent, EnvironmentDto environmentDto) {
EnvironmentCloudStorageValidationRequest cloudStorageValidationRequest = new EnvironmentCloudStorageValidationRequest();
cloudStorageValidationRequest.setCredentialCrn(environmentDto.getCredential().getResourceCrn());
TelemetryRequest telemetryRequest = telemetryApiConverter.convertToRequest(environmentDto.getTelemetry());
BackupRequest backupRequest = backupConverter.convertToRequest(environmentDto.getBackup());
cloudStorageValidationRequest.setTelemetry(telemetryRequest);
cloudStorageValidationRequest.setBackup(backupRequest);
ObjectStorageValidateResponse response = null;
try {
response = cloudStorageValidator.validateCloudStorage(environmentDto.getAccountId(), cloudStorageValidationRequest);
} catch (Exception e) {
String message = String.format("Error occured during object storage validation, validation skipped. Error: %s", e.getMessage());
LOGGER.warn(message);
eventSenderService.sendEventAndNotification(environmentDto, ThreadBasedUserCrnProvider.getUserCrn(), ResourceEvent.ENVIRONMENT_VALIDATION_FAILED_AND_SKIPPED, Set.of(e.getMessage()));
}
if (response != null && ResponseStatus.ERROR.equals(response.getStatus())) {
throw new EnvironmentServiceException(response.getError());
}
if (response != null && ResponseStatus.OK.equals(response.getStatus()) && isNotBlank(response.getError())) {
eventSenderService.sendEventAndNotification(environmentDto, ThreadBasedUserCrnProvider.getUserCrn(), ResourceEvent.ENVIRONMENT_VALIDATION_FAILED_AND_SKIPPED, Set.of(response.getError()));
}
}
use of com.sequenceiq.environment.exception.EnvironmentServiceException in project cloudbreak by hortonworks.
the class EnvironmentValidationHandler method validateEnvironment.
private void validateEnvironment(Event<EnvironmentValidationDto> environmentDtoEvent, EnvironmentValidationDto environmentValidationDto, Environment environment) {
EnvironmentDto environmentDto = environmentValidationDto.getEnvironmentDto();
RegionWrapper regionWrapper = environment.getRegionWrapper();
CloudRegions cloudRegions = environmentService.getRegionsByEnvironment(environment);
ValidationResult.ValidationResultBuilder validationBuilder = validatorService.validateRegionsAndLocation(regionWrapper.getName(), regionWrapper.getRegions(), environment, cloudRegions);
validationBuilder.merge(validatorService.validateTelemetryLoggingStorageLocation(environment));
validationBuilder.merge(validatorService.validateTelemetryLoggingStorageConfig(environment));
validationBuilder.merge(validatorService.validateBackupStorageLocation(environment));
validationBuilder.merge(validatorService.validateBackupStorageConfig(environment));
validationBuilder.merge(validatorService.validateParameters(environmentValidationDto, environmentDto.getParameters()));
validationBuilder.merge(validatorService.validateNetworkWithProvider(environmentValidationDto));
validationBuilder.merge(validatorService.validateAuthentication(environmentValidationDto));
validationBuilder.merge(validatorService.validateAwsKeysPresent(environmentValidationDto));
ValidationResult validationResult = validationBuilder.build();
if (validationResult.hasError()) {
throw new EnvironmentServiceException(validationResult.getFormattedErrors());
}
}
Aggregations