use of com.sequenceiq.cloudbreak.cloud.model.objectstorage.ObjectStorageMetadataResponse in project cloudbreak by hortonworks.
the class CloudStorageLocationValidatorTest method validateS3.
@Test
public void validateS3() {
ObjectStorageMetadataRequest request = ObjectStorageMetadataRequest.builder().withCloudPlatform(CLOUD_PLATFORM).withCredential(CLOUD_CREDENTIAL).withObjectStoragePath(BUCKET_NAME).build();
ObjectStorageMetadataResponse response = ObjectStorageMetadataResponse.builder().withRegion(ENV_REGION).withStatus(ResponseStatus.OK).build();
when(cloudProviderServicesEndpoint.getObjectStorageMetaData(eq(request))).thenReturn(response);
when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn");
when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
ValidationResultBuilder validationResultBuilder = new ValidationResultBuilder();
underTest.validate(S3_OBJECT_PATH, FileSystemType.S3, environment, validationResultBuilder);
assertFalse(validationResultBuilder.build().hasError());
}
use of com.sequenceiq.cloudbreak.cloud.model.objectstorage.ObjectStorageMetadataResponse in project cloudbreak by hortonworks.
the class CloudStorageLocationValidatorTest method validateWasb.
@Test
public void validateWasb() {
ObjectStorageMetadataRequest request = ObjectStorageMetadataRequest.builder().withCloudPlatform(CLOUD_PLATFORM).withCredential(CLOUD_CREDENTIAL).withObjectStoragePath(BUCKET_NAME).build();
ObjectStorageMetadataResponse response = ObjectStorageMetadataResponse.builder().withRegion(ENV_REGION).withStatus(ResponseStatus.OK).build();
when(cloudProviderServicesEndpoint.getObjectStorageMetaData(eq(request))).thenReturn(response);
when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn");
when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
ValidationResultBuilder validationResultBuilder = new ValidationResultBuilder();
underTest.validate(WASB_OBJECT_PATH, FileSystemType.WASB, environment, validationResultBuilder);
assertFalse(validationResultBuilder.build().hasError());
}
use of com.sequenceiq.cloudbreak.cloud.model.objectstorage.ObjectStorageMetadataResponse in project cloudbreak by hortonworks.
the class CloudStorageLocationValidatorTest method validateNoProtocol.
@Test
public void validateNoProtocol() {
ObjectStorageMetadataRequest request = ObjectStorageMetadataRequest.builder().withCloudPlatform(CLOUD_PLATFORM).withCredential(CLOUD_CREDENTIAL).withObjectStoragePath(BUCKET_NAME).build();
ObjectStorageMetadataResponse response = ObjectStorageMetadataResponse.builder().withRegion(ENV_REGION).withStatus(ResponseStatus.OK).build();
when(cloudProviderServicesEndpoint.getObjectStorageMetaData(eq(request))).thenReturn(response);
when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn");
when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
ValidationResultBuilder validationResultBuilder = new ValidationResultBuilder();
underTest.validate(OBJECT_PATH, FileSystemType.S3, environment, validationResultBuilder);
assertFalse(validationResultBuilder.build().hasError());
}
use of com.sequenceiq.cloudbreak.cloud.model.objectstorage.ObjectStorageMetadataResponse in project cloudbreak by hortonworks.
the class CloudStorageLocationValidatorTest method validateError.
@Test
public void validateError() {
ObjectStorageMetadataRequest request = ObjectStorageMetadataRequest.builder().withCloudPlatform(CLOUD_PLATFORM).withCredential(CLOUD_CREDENTIAL).withObjectStoragePath(BUCKET_NAME).build();
ObjectStorageMetadataResponse response = ObjectStorageMetadataResponse.builder().withRegion(OTHER_REGION).withStatus(ResponseStatus.OK).build();
when(cloudProviderServicesEndpoint.getObjectStorageMetaData(eq(request))).thenReturn(response);
when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn");
when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
ValidationResultBuilder validationResultBuilder = new ValidationResultBuilder();
underTest.validate(OBJECT_PATH, FileSystemType.S3, environment, validationResultBuilder);
ValidationResult result = validationResultBuilder.build();
assertTrue(result.hasError());
assertEquals(String.format("Object storage location [%s] of bucket '%s' must match environment location [%s]", OTHER_REGION, BUCKET_NAME, ENV_REGION), result.getErrors().get(0));
}
use of com.sequenceiq.cloudbreak.cloud.model.objectstorage.ObjectStorageMetadataResponse 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())));
}
Aggregations