Search in sources :

Example 46 with CloudStorageRequest

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

the class CloudStorageDecoratorTest method testUpdateCloudStorageLocationsWhenRequestContainsOneTemplatedLocationAndOneWithoutTemplatePlaceholderThenThatShouldBeReplaced.

@Test
void testUpdateCloudStorageLocationsWhenRequestContainsOneTemplatedLocationAndOneWithoutTemplatePlaceholderThenThatShouldBeReplaced() {
    String templatedStorageLocationBaseValue = "s3a://some-dir/some-other-dir/";
    CloudStorageCdpService templatedStorageLocationType = CloudStorageCdpService.DEFAULT_FS;
    String templatedStorageLocationValue = templatedStorageLocationBaseValue + "{{{clusterName}}}";
    StorageLocationBase templatedStorageLocationBase = new StorageLocationBase();
    templatedStorageLocationBase.setType(templatedStorageLocationType);
    templatedStorageLocationBase.setValue(templatedStorageLocationValue);
    CloudStorageCdpService storageLocationType = CloudStorageCdpService.FLINK_JOBMANAGER_ARCHIVE;
    String eStorageLocationValue = "s3a://some-awesome-dir/some-other-awesome-dir/" + CLUSTER_NAME;
    StorageLocationBase storageLocationBase = new StorageLocationBase();
    storageLocationBase.setType(storageLocationType);
    storageLocationBase.setValue(eStorageLocationValue);
    List<StorageLocationBase> storageLocations = new ArrayList<>(2);
    storageLocations.add(storageLocationBase);
    storageLocations.add(templatedStorageLocationBase);
    ConfigQueryEntry cqe = new ConfigQueryEntry();
    cqe.setType(CloudStorageCdpService.DEFAULT_FS);
    cqe.setDefaultPath(templatedStorageLocationBaseValue + CLUSTER_NAME);
    CloudStorageRequest request = new CloudStorageRequest();
    request.setLocations(storageLocations);
    SdxClusterResponse sdxReponse = new SdxClusterResponse();
    String storageLocationValue = eStorageLocationValue;
    sdxReponse.setCloudStorageBaseLocation(storageLocationValue);
    sdxReponse.setCloudStorageFileSystemType(FileSystemType.S3);
    ConfigQueryEntry cqeFlink = new ConfigQueryEntry();
    cqeFlink.setType(CloudStorageCdpService.FLINK_JOBMANAGER_ARCHIVE);
    cqeFlink.setDefaultPath(storageLocationValue);
    Set<ConfigQueryEntry> cqes = new LinkedHashSet<>(1);
    cqes.add(cqe);
    cqes.add(cqeFlink);
    when(blueprintService.queryFileSystemParameters(BLUEPRINT_NAME, CLUSTER_NAME, storageLocationValue, FileSystemType.S3.name(), "", true, false, 0L)).thenReturn(cqes);
    Pair<Blueprint, String> mockBt = mock(Pair.class);
    when(blueprintService.getBlueprintAndText(BLUEPRINT_NAME, 0L)).thenReturn(mockBt);
    FileSystemConfigQueryObject mockfscqo = mock(FileSystemConfigQueryObject.class);
    when(blueprintService.createFileSystemConfigQueryObject(mockBt, CLUSTER_NAME, sdxReponse.getCloudStorageBaseLocation(), sdxReponse.getCloudStorageFileSystemType().name(), "", true, false)).thenReturn(mockfscqo);
    when(cmCloudStorageConfigProvider.queryParameters(any(), eq(mockfscqo))).thenReturn(cqes);
    CloudStorageRequest result = underTest.updateCloudStorageLocations(BLUEPRINT_NAME, CLUSTER_NAME, request, List.of(sdxReponse));
    assertNotNull(result);
    assertEquals(0, result.getLocations().stream().filter(slb -> slb.getValue().contains("{{{") && slb.getValue().contains("}}}")).count());
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ConfigQueryEntry(com.sequenceiq.common.api.cloudstorage.query.ConfigQueryEntry) CloudStorageCdpService(com.sequenceiq.common.model.CloudStorageCdpService) CloudStorageRequest(com.sequenceiq.common.api.cloudstorage.CloudStorageRequest) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) ArrayList(java.util.ArrayList) FileSystemConfigQueryObject(com.sequenceiq.cloudbreak.template.filesystem.FileSystemConfigQueryObject) SdxClusterResponse(com.sequenceiq.sdx.api.model.SdxClusterResponse) StorageLocationBase(com.sequenceiq.common.api.cloudstorage.StorageLocationBase) Test(org.junit.jupiter.api.Test)

Example 47 with CloudStorageRequest

use of com.sequenceiq.common.api.cloudstorage.CloudStorageRequest 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 48 with CloudStorageRequest

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

the class CloudStorageConverter method requestToAdditionalFileSystem.

public FileSystem requestToAdditionalFileSystem(CloudStorageBase cloudStorageRequest) {
    FileSystem fileSystem = new FileSystem();
    AwsEfsParameters efsParameters = cloudStorageRequest.getAws() == null ? null : cloudStorageRequest.getAws().getEfsParameters();
    if (efsParameters == null || StringUtils.isEmpty(efsParameters.getName())) {
        return null;
    }
    fileSystem.setName(efsParameters.getName());
    FileSystemType fileSystemType = FileSystemType.EFS;
    fileSystem.setType(fileSystemType);
    Map<String, Object> configurations = new HashMap<>();
    configurations.put(CloudEfsConfiguration.KEY_BACKUP_POLICY_STATUS, efsParameters.getBackupPolicyStatus());
    configurations.put(CloudEfsConfiguration.KEY_ENCRYPTED, efsParameters.getEncrypted());
    configurations.put(CloudEfsConfiguration.KEY_FILESYSTEM_POLICY, efsParameters.getFileSystemPolicy());
    configurations.put(CloudEfsConfiguration.KEY_FILESYSTEM_TAGS, efsParameters.getFileSystemTags());
    configurations.put(CloudEfsConfiguration.KEY_KMSKEYID, efsParameters.getKmsKeyId());
    configurations.put(CloudEfsConfiguration.KEY_LIFECYCLE_POLICIES, efsParameters.getLifeCyclePolicies());
    configurations.put(CloudEfsConfiguration.KEY_PERFORMANCE_MODE, efsParameters.getPerformanceMode());
    configurations.put(CloudEfsConfiguration.KEY_PROVISIONED_THROUGHPUT_INMIBPS, efsParameters.getProvisionedThroughputInMibps());
    configurations.put(CloudEfsConfiguration.KEY_THROUGHPUT_MODE, efsParameters.getThroughputMode());
    String configString;
    try {
        configString = JsonUtil.writeValueAsString(configurations);
    } catch (JsonProcessingException ignored) {
        configString = configurations.toString();
    }
    fileSystem.setConfigurations(new Json(configString));
    CloudStorage cloudStorage = new CloudStorage();
    if (cloudStorageRequest.getIdentities() != null) {
        Optional<CloudIdentity> cloudIdentity = cloudStorageRequest.getIdentities().stream().map(this::identityRequestToCloudIdentity).filter(currCloudIdentity -> currCloudIdentity.getEfsIdentity() != null).findFirst();
        if (cloudIdentity != null && cloudIdentity.get() != null) {
            cloudStorage.setCloudIdentities(List.of(cloudIdentity.get()));
        }
    }
    cloudStorage.setAccountMapping(accountMappingRequestToAccountMapping(cloudStorageRequest.getAccountMapping()));
    fileSystem.setCloudStorage(cloudStorage);
    return fileSystem;
}
Also used : 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) HashMap(java.util.HashMap) CloudIdentity(com.sequenceiq.cloudbreak.domain.cloudstorage.CloudIdentity) Json(com.sequenceiq.cloudbreak.common.json.Json) CloudStorage(com.sequenceiq.cloudbreak.domain.cloudstorage.CloudStorage) SpiFileSystem(com.sequenceiq.cloudbreak.cloud.model.SpiFileSystem) FileSystem(com.sequenceiq.cloudbreak.domain.FileSystem) FileSystemType(com.sequenceiq.common.model.FileSystemType) AwsEfsParameters(com.sequenceiq.common.api.cloudstorage.AwsEfsParameters) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 49 with CloudStorageRequest

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

the class CloudStorageManifester method initCloudStorageRequest.

public CloudStorageRequest initCloudStorageRequest(DetailedEnvironmentResponse environment, ClusterV4Request clusterRequest, SdxCluster sdxCluster, SdxClusterRequest sdxClusterRequest) {
    CloudStorageRequest cloudStorageRequest = null;
    boolean anyCloudStorageIsConfigured = isCloudStorageConfigured(sdxClusterRequest) || isInternalCloudStorageConfigured(clusterRequest);
    boolean loggingConfigured = isLoggingConfigured(environment);
    if (isCloudStorageConfigured(sdxClusterRequest)) {
        LOGGER.debug("Cloud storage configurations found in SDX cluster request.");
        cloudStorageRequest = initSdxCloudStorageRequest(environment.getCloudPlatform(), clusterRequest.getBlueprintName(), sdxCluster.getClusterName(), sdxClusterRequest.getCloudStorage());
    } else if (isInternalCloudStorageConfigured(clusterRequest)) {
        LOGGER.debug("Cloud storage configurations found in internal SDX stack request.");
        cloudStorageRequest = clusterRequest.getCloudStorage();
    }
    if (loggingConfigured) {
        LOGGER.debug("Cloud storage logging is enabled.");
        if (!anyCloudStorageIsConfigured) {
            LOGGER.debug("Creating cloud storage request only for logging identity.");
            cloudStorageRequest = new CloudStorageRequest();
        }
        addLogIdentity(cloudStorageRequest, environment);
    }
    if (loggingConfigured || anyCloudStorageIsConfigured) {
        addS3Guard(cloudStorageRequest, environment);
    }
    return cloudStorageRequest;
}
Also used : SdxCloudStorageRequest(com.sequenceiq.sdx.api.model.SdxCloudStorageRequest) CloudStorageRequest(com.sequenceiq.common.api.cloudstorage.CloudStorageRequest)

Example 50 with CloudStorageRequest

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

the class CloudStorageManifester method initSdxCloudStorageRequest.

public CloudStorageRequest initSdxCloudStorageRequest(String cloudPlatform, String blueprint, String clusterName, SdxCloudStorageRequest cloudStorage) {
    CloudStorageRequest cloudStorageRequest = new CloudStorageRequest();
    normalizeCloudStorageRequest(cloudStorage);
    storageValidationService.validateCloudStorage(cloudPlatform, cloudStorage);
    FileSystemParameterV4Responses fileSystemRecommendations = getFileSystemRecommendations(blueprint, clusterName, cloudStorage);
    LOGGER.info("File recommendations {}", fileSystemRecommendations);
    setStorageLocations(fileSystemRecommendations, cloudStorageRequest);
    addIdBrokerIdentity(cloudStorage, cloudStorageRequest);
    return cloudStorageRequest;
}
Also used : SdxCloudStorageRequest(com.sequenceiq.sdx.api.model.SdxCloudStorageRequest) CloudStorageRequest(com.sequenceiq.common.api.cloudstorage.CloudStorageRequest) FileSystemParameterV4Responses(com.sequenceiq.cloudbreak.api.endpoint.v4.filesystems.responses.FileSystemParameterV4Responses)

Aggregations

CloudStorageRequest (com.sequenceiq.common.api.cloudstorage.CloudStorageRequest)53 Test (org.junit.jupiter.api.Test)27 StorageLocationBase (com.sequenceiq.common.api.cloudstorage.StorageLocationBase)24 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)16 CloudStorageCdpService (com.sequenceiq.common.model.CloudStorageCdpService)15 SdxCloudStorageRequest (com.sequenceiq.sdx.api.model.SdxCloudStorageRequest)15 ClusterV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.cluster.ClusterV4Request)14 LoggingResponse (com.sequenceiq.common.api.telemetry.response.LoggingResponse)14 ArrayList (java.util.ArrayList)14 TelemetryResponse (com.sequenceiq.common.api.telemetry.response.TelemetryResponse)13 FileSystemType (com.sequenceiq.common.model.FileSystemType)13 List (java.util.List)12 StorageIdentityBase (com.sequenceiq.common.api.cloudstorage.StorageIdentityBase)11 CloudIdentityType (com.sequenceiq.common.model.CloudIdentityType)11 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)10 Assertions.assertNull (org.junit.jupiter.api.Assertions.assertNull)10 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)10 InjectMocks (org.mockito.InjectMocks)10 Mock (org.mockito.Mock)10 Mockito.when (org.mockito.Mockito.when)10