Search in sources :

Example 11 with ObjectStorageMetadataResponse

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());
}
Also used : ObjectStorageMetadataResponse(com.sequenceiq.cloudbreak.cloud.model.objectstorage.ObjectStorageMetadataResponse) ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder) ObjectStorageMetadataRequest(com.sequenceiq.cloudbreak.cloud.model.objectstorage.ObjectStorageMetadataRequest) Test(org.junit.jupiter.api.Test)

Example 12 with ObjectStorageMetadataResponse

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());
}
Also used : ObjectStorageMetadataResponse(com.sequenceiq.cloudbreak.cloud.model.objectstorage.ObjectStorageMetadataResponse) ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder) ObjectStorageMetadataRequest(com.sequenceiq.cloudbreak.cloud.model.objectstorage.ObjectStorageMetadataRequest) Test(org.junit.jupiter.api.Test)

Example 13 with ObjectStorageMetadataResponse

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()));
}
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)

Example 14 with ObjectStorageMetadataResponse

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());
}
Also used : ObjectStorageMetadataResponse(com.sequenceiq.cloudbreak.cloud.model.objectstorage.ObjectStorageMetadataResponse) ObjectStorageMetadataRequest(com.sequenceiq.cloudbreak.cloud.model.objectstorage.ObjectStorageMetadataRequest) AmazonS3Exception(com.amazonaws.services.s3.model.AmazonS3Exception) Test(org.junit.Test)

Example 15 with ObjectStorageMetadataResponse

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());
}
Also used : ObjectStorageMetadataResponse(com.sequenceiq.cloudbreak.cloud.model.objectstorage.ObjectStorageMetadataResponse) ObjectStorageMetadataRequest(com.sequenceiq.cloudbreak.cloud.model.objectstorage.ObjectStorageMetadataRequest) Test(org.junit.Test)

Aggregations

ObjectStorageMetadataRequest (com.sequenceiq.cloudbreak.cloud.model.objectstorage.ObjectStorageMetadataRequest)15 ObjectStorageMetadataResponse (com.sequenceiq.cloudbreak.cloud.model.objectstorage.ObjectStorageMetadataResponse)15 ValidationResultBuilder (com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder)10 Test (org.junit.jupiter.api.Test)10 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)3 ValidationResult (com.sequenceiq.cloudbreak.validation.ValidationResult)2 FileSystemType (com.sequenceiq.common.model.FileSystemType)2 Test (org.junit.Test)2 AmazonS3Exception (com.amazonaws.services.s3.model.AmazonS3Exception)1 Credential (com.sequenceiq.datalake.entity.Credential)1 EnvironmentServiceException (com.sequenceiq.environment.exception.EnvironmentServiceException)1