Search in sources :

Example 1 with Credential

use of com.sequenceiq.datalake.entity.Credential in project cloudbreak by hortonworks.

the class CloudStorageValidator method validate.

public void validate(CloudStorageRequest cloudStorageRequest, DetailedEnvironmentResponse environment, ValidationResult.ValidationResultBuilder validationResultBuilder) {
    if (CloudStorageValidation.DISABLED.equals(environment.getCloudStorageValidation())) {
        LOGGER.info("Due to cloud storage validation not being enabled, not validating cloudStorageRequest: {}", JsonUtil.writeValueAsStringSilent(cloudStorageRequest));
        return;
    }
    String accountId = ThreadBasedUserCrnProvider.getAccountId();
    if (!entitlementService.cloudStorageValidationEnabled(accountId)) {
        LOGGER.info("Cloud storage validation entitlement is missing, not validating cloudStorageRequest: {}", JsonUtil.writeValueAsStringSilent(cloudStorageRequest));
        return;
    }
    LOGGER.info("Validating cloudStorageRequest: {}", JsonUtil.writeValueAsStringSilent(cloudStorageRequest));
    if (cloudStorageRequest != null) {
        Credential credential = getCredential(environment);
        CloudCredential cloudCredential = credentialToCloudCredentialConverter.convert(credential);
        ObjectStorageValidateRequest request = createObjectStorageValidateRequest(cloudCredential, cloudStorageRequest, environment);
        ObjectStorageValidateResponse response = ThreadBasedUserCrnProvider.doAsInternalActor(regionAwareInternalCrnGeneratorFactory.iam().getInternalCrnForServiceAsString(), () -> cloudProviderServicesV4Endpoint.validateObjectStorage(request));
        LOGGER.info("ValidateObjectStorage: request: {}, response: {}", AnonymizerUtil.anonymize(JsonUtil.writeValueAsStringSilent(request)), JsonUtil.writeValueAsStringSilent(response));
        if (ResponseStatus.ERROR.equals(response.getStatus())) {
            validationResultBuilder.error(response.getError());
        } else if (StringUtils.isNotBlank(response.getError())) {
            validationResultBuilder.warning(response.getError());
        }
    }
}
Also used : CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) Credential(com.sequenceiq.datalake.entity.Credential) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) ObjectStorageValidateResponse(com.sequenceiq.cloudbreak.cloud.model.objectstorage.ObjectStorageValidateResponse) ObjectStorageValidateRequest(com.sequenceiq.cloudbreak.cloud.model.objectstorage.ObjectStorageValidateRequest)

Example 2 with Credential

use of com.sequenceiq.datalake.entity.Credential in project cloudbreak by hortonworks.

the class CloudStorageLocationValidator method validate.

public void validate(String storageLocation, FileSystemType fileSystemType, DetailedEnvironmentResponse environment, ValidationResultBuilder resultBuilder) {
    String bucketName = getBucketName(fileSystemType, storageLocation);
    Credential credential = getCredential(environment);
    CloudCredential cloudCredential = credentialToCloudCredentialConverter.convert(credential);
    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().getName().equals(response.getRegion()), String.format("Object storage location [%s] of bucket '%s' must match environment location [%s]", response.getRegion(), bucketName, environment.getLocation().getName()));
}
Also used : ObjectStorageMetadataResponse(com.sequenceiq.cloudbreak.cloud.model.objectstorage.ObjectStorageMetadataResponse) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) Credential(com.sequenceiq.datalake.entity.Credential) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) ObjectStorageMetadataRequest(com.sequenceiq.cloudbreak.cloud.model.objectstorage.ObjectStorageMetadataRequest)

Aggregations

CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)2 Credential (com.sequenceiq.datalake.entity.Credential)2 ObjectStorageMetadataRequest (com.sequenceiq.cloudbreak.cloud.model.objectstorage.ObjectStorageMetadataRequest)1 ObjectStorageMetadataResponse (com.sequenceiq.cloudbreak.cloud.model.objectstorage.ObjectStorageMetadataResponse)1 ObjectStorageValidateRequest (com.sequenceiq.cloudbreak.cloud.model.objectstorage.ObjectStorageValidateRequest)1 ObjectStorageValidateResponse (com.sequenceiq.cloudbreak.cloud.model.objectstorage.ObjectStorageValidateResponse)1