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();
when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn:cdp:datahub:us-west-1:altus:user:__internal__actor__");
when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
ObjectStorageMetadataResponse response = ObjectStorageMetadataResponse.builder().withRegion(ENV_REGION).withStatus(ResponseStatus.OK).build();
when(cloudProviderServicesEndpoint.getObjectStorageMetaData(eq(request))).thenReturn(response);
ValidationResultBuilder validationResultBuilder = new ValidationResultBuilder();
underTest.validate(OBJECT_PATH, environment, validationResultBuilder);
assertFalse(validationResultBuilder.build().hasError());
}
use of com.sequenceiq.cloudbreak.cloud.model.objectstorage.ObjectStorageMetadataResponse in project cloudbreak by hortonworks.
the class CloudStorageLocationValidatorTest method validateS3.
@Test
public void validateS3() {
when(environmentLogging.getS3()).thenReturn(s3);
when(s3.getType()).thenReturn(FileSystemType.S3);
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:cdp:datahub:us-west-1:altus:user:__internal__actor__");
when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
ValidationResultBuilder validationResultBuilder = new ValidationResultBuilder();
underTest.validate(S3_OBJECT_PATH, environment, validationResultBuilder);
assertFalse(validationResultBuilder.build().hasError());
}
use of com.sequenceiq.cloudbreak.cloud.model.objectstorage.ObjectStorageMetadataResponse 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()));
}
use of com.sequenceiq.cloudbreak.cloud.model.objectstorage.ObjectStorageMetadataResponse in project cloudbreak by hortonworks.
the class AwsObjectStorageConnectorTest method getObjectStorageMetadataAccessDenied.
@Test
public void getObjectStorageMetadataAccessDenied() {
AmazonS3Exception exception = new AmazonS3Exception(ERROR_MESSAGE);
exception.setStatusCode(403);
when(s3Client.getBucketLocation(BUCKET_NAME)).thenThrow(exception);
ObjectStorageMetadataRequest request = ObjectStorageMetadataRequest.builder().withObjectStoragePath(BUCKET_NAME).build();
ObjectStorageMetadataResponse result = underTest.getObjectStorageMetadata(request);
verify(s3Client).getBucketLocation(BUCKET_NAME);
assertNull(result.getRegion());
assertEquals(ResponseStatus.ACCESS_DENIED, result.getStatus());
}
use of com.sequenceiq.cloudbreak.cloud.model.objectstorage.ObjectStorageMetadataResponse in project cloudbreak by hortonworks.
the class AwsObjectStorageConnectorTest method getObjectStorageMetadata.
@Test
public void getObjectStorageMetadata() {
when(s3Client.getBucketLocation(BUCKET_NAME)).thenReturn(REGION_NAME);
ObjectStorageMetadataRequest request = ObjectStorageMetadataRequest.builder().withObjectStoragePath(BUCKET_NAME).build();
ObjectStorageMetadataResponse result = underTest.getObjectStorageMetadata(request);
verify(s3Client).getBucketLocation(BUCKET_NAME);
assertEquals(REGION_NAME, result.getRegion());
assertEquals(ResponseStatus.OK, result.getStatus());
}
Aggregations