Search in sources :

Example 1 with EnvironmentServiceException

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())));
}
Also used : ObjectStorageMetadataResponse(com.sequenceiq.cloudbreak.cloud.model.objectstorage.ObjectStorageMetadataResponse) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) FileSystemType(com.sequenceiq.common.model.FileSystemType) EnvironmentServiceException(com.sequenceiq.environment.exception.EnvironmentServiceException) ObjectStorageMetadataRequest(com.sequenceiq.cloudbreak.cloud.model.objectstorage.ObjectStorageMetadataRequest)

Example 2 with EnvironmentServiceException

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;
}
Also used : EnvironmentServiceException(com.sequenceiq.environment.exception.EnvironmentServiceException) EnvironmentServiceException(com.sequenceiq.environment.exception.EnvironmentServiceException)

Example 3 with EnvironmentServiceException

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()));
    }
}
Also used : BackupRequest(com.sequenceiq.common.api.backup.request.BackupRequest) TelemetryRequest(com.sequenceiq.common.api.telemetry.request.TelemetryRequest) EnvironmentCloudStorageValidationRequest(com.sequenceiq.environment.api.v1.environment.model.request.EnvironmentCloudStorageValidationRequest) ObjectStorageValidateResponse(com.sequenceiq.cloudbreak.cloud.model.objectstorage.ObjectStorageValidateResponse) EnvironmentServiceException(com.sequenceiq.environment.exception.EnvironmentServiceException) EnvironmentServiceException(com.sequenceiq.environment.exception.EnvironmentServiceException) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) WebApplicationException(javax.ws.rs.WebApplicationException)

Example 4 with EnvironmentServiceException

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());
    }
}
Also used : EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) CloudRegions(com.sequenceiq.cloudbreak.cloud.model.CloudRegions) EnvironmentServiceException(com.sequenceiq.environment.exception.EnvironmentServiceException) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) RegionWrapper(com.sequenceiq.environment.environment.domain.RegionWrapper)

Aggregations

EnvironmentServiceException (com.sequenceiq.environment.exception.EnvironmentServiceException)4 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)1 CloudRegions (com.sequenceiq.cloudbreak.cloud.model.CloudRegions)1 ObjectStorageMetadataRequest (com.sequenceiq.cloudbreak.cloud.model.objectstorage.ObjectStorageMetadataRequest)1 ObjectStorageMetadataResponse (com.sequenceiq.cloudbreak.cloud.model.objectstorage.ObjectStorageMetadataResponse)1 ObjectStorageValidateResponse (com.sequenceiq.cloudbreak.cloud.model.objectstorage.ObjectStorageValidateResponse)1 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)1 ValidationResult (com.sequenceiq.cloudbreak.validation.ValidationResult)1 BackupRequest (com.sequenceiq.common.api.backup.request.BackupRequest)1 TelemetryRequest (com.sequenceiq.common.api.telemetry.request.TelemetryRequest)1 FileSystemType (com.sequenceiq.common.model.FileSystemType)1 EnvironmentCloudStorageValidationRequest (com.sequenceiq.environment.api.v1.environment.model.request.EnvironmentCloudStorageValidationRequest)1 RegionWrapper (com.sequenceiq.environment.environment.domain.RegionWrapper)1 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)1 WebApplicationException (javax.ws.rs.WebApplicationException)1