Search in sources :

Example 26 with StorageLocationBase

use of com.sequenceiq.common.api.cloudstorage.StorageLocationBase in project cloudbreak by hortonworks.

the class CloudStorageConverter method storageLocationToRequest.

private StorageLocationBase storageLocationToRequest(StorageLocation storageLocation) {
    StorageLocationBase storageLocationRequest = new StorageLocationBase();
    storageLocationRequest.setType(storageLocation.getType());
    storageLocationRequest.setValue(storageLocation.getValue());
    return storageLocationRequest;
}
Also used : StorageLocationBase(com.sequenceiq.common.api.cloudstorage.StorageLocationBase)

Example 27 with StorageLocationBase

use of com.sequenceiq.common.api.cloudstorage.StorageLocationBase in project cloudbreak by hortonworks.

the class CloudStorageConverter method fileSystemToRequest.

public CloudStorageRequest fileSystemToRequest(FileSystem fileSystem) {
    CloudStorageRequest result = new CloudStorageRequest();
    CloudStorage cloudStorage = fileSystem.getCloudStorage();
    if (cloudStorage != null) {
        List<StorageIdentityBase> storageIdentityRequests = cloudStorage.getCloudIdentities().stream().map(this::cloudIdentityToRequest).collect(Collectors.toList());
        result.setIdentities(storageIdentityRequests);
        List<StorageLocationBase> storageLocationRequests = cloudStorage.getLocations().stream().map(this::storageLocationToRequest).collect(Collectors.toList());
        result.setLocations(storageLocationRequests);
        NullUtil.doIfNotNull(cloudStorage.getS3GuardDynamoTableName(), tableName -> {
            AwsStorageParameters awsStorageParameters = new AwsStorageParameters();
            S3Guard s3Guard = new S3Guard();
            s3Guard.setDynamoTableName(tableName);
            awsStorageParameters.setS3Guard(s3Guard);
            result.setAws(awsStorageParameters);
        });
        result.setAccountMapping(accountMappingToAccountMappingRequest(cloudStorage.getAccountMapping()));
    }
    return result;
}
Also used : CloudStorage(com.sequenceiq.cloudbreak.domain.cloudstorage.CloudStorage) AwsStorageParameters(com.sequenceiq.common.api.cloudstorage.AwsStorageParameters) CloudStorageRequest(com.sequenceiq.common.api.cloudstorage.CloudStorageRequest) S3Guard(com.sequenceiq.common.api.cloudstorage.S3Guard) StorageIdentityBase(com.sequenceiq.common.api.cloudstorage.StorageIdentityBase) StorageLocationBase(com.sequenceiq.common.api.cloudstorage.StorageLocationBase)

Example 28 with StorageLocationBase

use of com.sequenceiq.common.api.cloudstorage.StorageLocationBase in project cloudbreak by hortonworks.

the class CloudStorageConverter method fileSystemToResponse.

public CloudStorageResponse fileSystemToResponse(FileSystem fileSystem) {
    CloudStorageResponse response = new CloudStorageResponse();
    CloudStorage cloudStorage = fileSystem.getCloudStorage();
    if (cloudStorage != null) {
        if (StringUtils.isNotEmpty(cloudStorage.getS3GuardDynamoTableName())) {
            AwsStorageParameters awsStorageParameters = new AwsStorageParameters();
            S3Guard s3Guard = new S3Guard();
            s3Guard.setDynamoTableName(cloudStorage.getS3GuardDynamoTableName());
            awsStorageParameters.setS3Guard(s3Guard);
            response.setAws(awsStorageParameters);
        }
        List<StorageIdentityBase> storageIdentities = cloudStorage.getCloudIdentities().stream().map(this::cloudIdentityToStorageIdentityBase).collect(Collectors.toList());
        response.setIdentities(storageIdentities);
        List<StorageLocationBase> storageLocations = cloudStorage.getLocations().stream().map(storageLocation -> {
            StorageLocationBase storageLocationBase = new StorageLocationBase();
            storageLocationBase.setType(storageLocation.getType());
            storageLocationBase.setValue(storageLocation.getValue());
            return storageLocationBase;
        }).collect(Collectors.toList());
        response.setLocations(storageLocations);
        response.setAccountMapping(accountMappingToAccountMappingRequest(cloudStorage.getAccountMapping()));
    }
    return response;
}
Also used : CloudStorage(com.sequenceiq.cloudbreak.domain.cloudstorage.CloudStorage) AwsStorageParameters(com.sequenceiq.common.api.cloudstorage.AwsStorageParameters) EfsIdentity(com.sequenceiq.cloudbreak.domain.cloudstorage.EfsIdentity) AwsStorageParameters(com.sequenceiq.common.api.cloudstorage.AwsStorageParameters) AwsEfsParameters(com.sequenceiq.common.api.cloudstorage.AwsEfsParameters) SpiFileSystem(com.sequenceiq.cloudbreak.cloud.model.SpiFileSystem) HashMap(java.util.HashMap) JsonUtil(com.sequenceiq.cloudbreak.common.json.JsonUtil) GcsCloudStorageV1Parameters(com.sequenceiq.common.api.cloudstorage.old.GcsCloudStorageV1Parameters) StringUtils(org.apache.commons.lang3.StringUtils) AccountMapping(com.sequenceiq.cloudbreak.domain.cloudstorage.AccountMapping) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) AccountMappingBase(com.sequenceiq.common.api.cloudstorage.AccountMappingBase) CloudS3View(com.sequenceiq.cloudbreak.cloud.model.filesystem.CloudS3View) CloudIdentity(com.sequenceiq.cloudbreak.domain.cloudstorage.CloudIdentity) Map(java.util.Map) AdlsGen2Identity(com.sequenceiq.cloudbreak.domain.cloudstorage.AdlsGen2Identity) GcsIdentity(com.sequenceiq.cloudbreak.domain.cloudstorage.GcsIdentity) CloudEfsConfiguration(com.sequenceiq.cloudbreak.cloud.model.filesystem.efs.CloudEfsConfiguration) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) CloudStorageBase(com.sequenceiq.common.api.cloudstorage.CloudStorageBase) CloudStorageCdpService(com.sequenceiq.common.model.CloudStorageCdpService) StorageIdentityBase(com.sequenceiq.common.api.cloudstorage.StorageIdentityBase) StorageLocationBase(com.sequenceiq.common.api.cloudstorage.StorageLocationBase) NullUtil(com.sequenceiq.cloudbreak.util.NullUtil) CloudStorageResponse(com.sequenceiq.common.api.cloudstorage.CloudStorageResponse) S3CloudStorageV1Parameters(com.sequenceiq.common.api.cloudstorage.old.S3CloudStorageV1Parameters) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) CloudFileSystemView(com.sequenceiq.cloudbreak.cloud.model.filesystem.CloudFileSystemView) Collectors(java.util.stream.Collectors) Json(com.sequenceiq.cloudbreak.common.json.Json) S3Identity(com.sequenceiq.cloudbreak.domain.cloudstorage.S3Identity) StorageLocation(com.sequenceiq.cloudbreak.domain.cloudstorage.StorageLocation) List(java.util.List) Component(org.springframework.stereotype.Component) WasbIdentity(com.sequenceiq.cloudbreak.domain.cloudstorage.WasbIdentity) WasbCloudStorageV1Parameters(com.sequenceiq.common.api.cloudstorage.old.WasbCloudStorageV1Parameters) MissingResourceNameGenerator(com.sequenceiq.cloudbreak.common.converter.MissingResourceNameGenerator) FileSystem(com.sequenceiq.cloudbreak.domain.FileSystem) CloudStorageRequest(com.sequenceiq.common.api.cloudstorage.CloudStorageRequest) FileSystemType(com.sequenceiq.common.model.FileSystemType) AdlsGen2CloudStorageV1Parameters(com.sequenceiq.common.api.cloudstorage.old.AdlsGen2CloudStorageV1Parameters) Optional(java.util.Optional) FileSystemResolver(com.sequenceiq.cloudbreak.service.filesystem.FileSystemResolver) S3Guard(com.sequenceiq.common.api.cloudstorage.S3Guard) FILESYSTEM(com.sequenceiq.cloudbreak.common.type.APIResourceType.FILESYSTEM) CloudStorage(com.sequenceiq.cloudbreak.domain.cloudstorage.CloudStorage) CloudStorageResponse(com.sequenceiq.common.api.cloudstorage.CloudStorageResponse) S3Guard(com.sequenceiq.common.api.cloudstorage.S3Guard) StorageIdentityBase(com.sequenceiq.common.api.cloudstorage.StorageIdentityBase) StorageLocationBase(com.sequenceiq.common.api.cloudstorage.StorageLocationBase)

Example 29 with StorageLocationBase

use of com.sequenceiq.common.api.cloudstorage.StorageLocationBase in project cloudbreak by hortonworks.

the class AwsDataAccessRolePermissionValidatorTest method testGetPolicyJsonReplacements.

@Test
@Override
public void testGetPolicyJsonReplacements() {
    String storageLocationBaseStr = "bucket/cluster";
    String bucket = "bucket";
    String dynamodbTableName = "tableName";
    Map<String, String> expectedPolicyJsonReplacements = Map.ofEntries(Map.entry("${ARN_PARTITION}", "aws"), Map.entry("${STORAGE_LOCATION_BASE}", storageLocationBaseStr), Map.entry("${DATALAKE_BUCKET}", bucket), Map.entry("${DYNAMODB_TABLE_NAME}", dynamodbTableName));
    StorageLocationBase storageLocationBase = new StorageLocationBase();
    storageLocationBase.setValue(storageLocationBaseStr);
    CloudS3View cloudFileSystem = new CloudS3View(CloudIdentityType.ID_BROKER);
    cloudFileSystem.setS3GuardDynamoTableName(dynamodbTableName);
    cloudFileSystem.setInstanceProfile("arn:aws:iam::11111111111:instance-profile/instanceprofile");
    Map<String, String> policyJsonReplacements = awsDataAccessRolePermissionValidator.getPolicyJsonReplacements(storageLocationBase, cloudFileSystem);
    assertThat(policyJsonReplacements).isEqualTo(expectedPolicyJsonReplacements);
}
Also used : CloudS3View(com.sequenceiq.cloudbreak.cloud.model.filesystem.CloudS3View) StorageLocationBase(com.sequenceiq.common.api.cloudstorage.StorageLocationBase) Test(org.junit.jupiter.api.Test)

Example 30 with StorageLocationBase

use of com.sequenceiq.common.api.cloudstorage.StorageLocationBase in project cloudbreak by hortonworks.

the class AwsDataAccessRolePermissionValidatorTest method testCollectPolicies.

@Test
@Override
public void testCollectPolicies() {
    ArgumentCaptor<Map<String, String>> replacementsCaptor = ArgumentCaptor.forClass(Map.class);
    when(awsIamService.getPolicy(eq("policyFile1"), replacementsCaptor.capture())).thenReturn(new Policy());
    CloudS3View cloudFileSystem = new CloudS3View(CloudIdentityType.ID_BROKER);
    StorageLocationBase storageLocationBase1 = new StorageLocationBase();
    storageLocationBase1.setType(CloudStorageCdpService.HIVE_METASTORE_WAREHOUSE);
    storageLocationBase1.setValue("s3a://bucket/cluster/hive/metadata");
    cloudFileSystem.setLocations(List.of(storageLocationBase1));
    cloudFileSystem.setInstanceProfile("arn:aws:iam::11111111111:instance-profile/instanceprofile");
    List<Policy> policies = getValidator().collectPolicies(cloudFileSystem, List.of("policyFile1"));
    assertEquals(1, policies.size());
    Map<String, String> replacements = replacementsCaptor.getValue();
    assertEquals("bucket/cluster/hive/metadata", replacements.get("${STORAGE_LOCATION_BASE}"));
    assertEquals("bucket", replacements.get("${DATALAKE_BUCKET}"));
    assertEquals("", replacements.get("${DYNAMODB_TABLE_NAME}"));
}
Also used : Policy(com.amazonaws.auth.policy.Policy) Map(java.util.Map) CloudS3View(com.sequenceiq.cloudbreak.cloud.model.filesystem.CloudS3View) StorageLocationBase(com.sequenceiq.common.api.cloudstorage.StorageLocationBase) Test(org.junit.jupiter.api.Test)

Aggregations

StorageLocationBase (com.sequenceiq.common.api.cloudstorage.StorageLocationBase)34 CloudStorageRequest (com.sequenceiq.common.api.cloudstorage.CloudStorageRequest)19 Test (org.junit.jupiter.api.Test)19 CloudStorageCdpService (com.sequenceiq.common.model.CloudStorageCdpService)10 StorageIdentityBase (com.sequenceiq.common.api.cloudstorage.StorageIdentityBase)9 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)9 ArrayList (java.util.ArrayList)9 CloudS3View (com.sequenceiq.cloudbreak.cloud.model.filesystem.CloudS3View)7 LoggingResponse (com.sequenceiq.common.api.telemetry.response.LoggingResponse)7 FileSystemType (com.sequenceiq.common.model.FileSystemType)7 List (java.util.List)7 ConfigQueryEntry (com.sequenceiq.common.api.cloudstorage.query.ConfigQueryEntry)6 TelemetryResponse (com.sequenceiq.common.api.telemetry.response.TelemetryResponse)6 CloudIdentityType (com.sequenceiq.common.model.CloudIdentityType)6 LinkedHashSet (java.util.LinkedHashSet)6 ClusterV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.cluster.ClusterV4Request)5 S3CloudStorageV1Parameters (com.sequenceiq.common.api.cloudstorage.old.S3CloudStorageV1Parameters)5 SdxCloudStorageRequest (com.sequenceiq.sdx.api.model.SdxCloudStorageRequest)5 SdxClusterRequest (com.sequenceiq.sdx.api.model.SdxClusterRequest)5 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)5