Search in sources :

Example 1 with S3bucketDataStorage

use of com.epam.pipeline.entity.datastorage.S3bucketDataStorage in project cloud-pipeline by epam.

the class DataStorageLoaderTest method shouldLoadDataStorageTest.

@Test
void shouldLoadDataStorageTest() throws EntityNotFoundException {
    StoragePolicy policy = new StoragePolicy();
    policy.setBackupDuration(DURATION);
    policy.setLongTermStorageDuration(DURATION);
    policy.setShortTermStorageDuration(DURATION);
    S3bucketDataStorage expectedDataStorage = new S3bucketDataStorage();
    expectedDataStorage.setId(1L);
    expectedDataStorage.setParentFolderId(1L);
    expectedDataStorage.setName(TEST_NAME);
    expectedDataStorage.setPath(TEST_PATH);
    expectedDataStorage.setOwner(TEST_NAME);
    expectedDataStorage.setStoragePolicy(policy);
    DataStorageLoader dataStorageLoader = new DataStorageLoader(apiClient);
    when(apiClient.loadDataStorage(anyLong())).thenReturn(expectedDataStorage);
    Optional<EntityContainer<DataStorageDoc>> container = dataStorageLoader.loadEntity(1L);
    EntityContainer<DataStorageDoc> storageDocEntityContainer = container.orElseThrow(AssertionError::new);
    DataStorageDoc actualDataStorageDoc = storageDocEntityContainer.getEntity();
    assertNotNull(actualDataStorageDoc);
    AbstractDataStorage actualDataStorage = actualDataStorageDoc.getStorage();
    verifyDataStorage(expectedDataStorage, actualDataStorage);
    verifyPipelineUser(storageDocEntityContainer.getOwner());
    verifyPermissions(PERMISSIONS_CONTAINER_WITH_OWNER, storageDocEntityContainer.getPermissions());
    verifyMetadata(EXPECTED_METADATA, new ArrayList<>(storageDocEntityContainer.getMetadata().values()));
}
Also used : AbstractDataStorage(com.epam.pipeline.entity.datastorage.AbstractDataStorage) DataStorageDoc(com.epam.pipeline.elasticsearchagent.model.DataStorageDoc) EntityContainer(com.epam.pipeline.elasticsearchagent.model.EntityContainer) S3bucketDataStorage(com.epam.pipeline.entity.datastorage.S3bucketDataStorage) StoragePolicy(com.epam.pipeline.entity.datastorage.StoragePolicy) Test(org.junit.jupiter.api.Test)

Example 2 with S3bucketDataStorage

use of com.epam.pipeline.entity.datastorage.S3bucketDataStorage in project cloud-pipeline by epam.

the class DataStorageMapperTest method shouldMapS3DataStorage.

@Test
void shouldMapS3DataStorage() throws IOException {
    DataStorageMapper mapper = new DataStorageMapper(SearchDocumentType.S3_STORAGE);
    StoragePolicy policy = new StoragePolicy();
    policy.setBackupDuration(DURATION);
    policy.setLongTermStorageDuration(DURATION);
    policy.setShortTermStorageDuration(DURATION);
    S3bucketDataStorage dataStorage = new S3bucketDataStorage();
    fillStorage(dataStorage);
    dataStorage.setStoragePolicy(policy);
    DataStorageDoc doc = DataStorageDoc.builder().regionName(TEST_REGION).storage(dataStorage).build();
    XContentBuilder contentBuilder = mapper.map(buildContainer(doc));
    verifyS3Storage(dataStorage, TEST_REGION, contentBuilder);
    verifyPermissions(PERMISSIONS_CONTAINER, contentBuilder);
    verifyMetadata(EXPECTED_METADATA, contentBuilder);
    verifyPipelineUser(USER, contentBuilder);
}
Also used : DataStorageDoc(com.epam.pipeline.elasticsearchagent.model.DataStorageDoc) S3bucketDataStorage(com.epam.pipeline.entity.datastorage.S3bucketDataStorage) StoragePolicy(com.epam.pipeline.entity.datastorage.StoragePolicy) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) Test(org.junit.jupiter.api.Test)

Example 3 with S3bucketDataStorage

use of com.epam.pipeline.entity.datastorage.S3bucketDataStorage in project cloud-pipeline by epam.

the class DataStorageLoader method fetchEntity.

@Override
protected DataStorageDoc fetchEntity(final Long id) {
    AbstractDataStorage dataStorage = getApiClient().loadDataStorage(id);
    List<AwsRegion> awsRegions = getApiClient().loadAllRegions();
    DataStorageDoc.DataStorageDocBuilder docBuilder = DataStorageDoc.builder().storage(dataStorage);
    if (dataStorage instanceof S3bucketDataStorage) {
        S3bucketDataStorage bucket = (S3bucketDataStorage) dataStorage;
        docBuilder.regionName(Optional.ofNullable(bucket.getRegionId()).flatMap(regionId -> awsRegions.stream().filter(region -> region.getId().equals(bucket.getRegionId())).findFirst().map(AwsRegion::getAwsRegionName)).orElse(StringUtils.EMPTY));
    }
    return docBuilder.build();
}
Also used : AbstractCloudPipelineEntityLoader(com.epam.pipeline.elasticsearchagent.service.impl.converter.AbstractCloudPipelineEntityLoader) List(java.util.List) DataStorageDoc(com.epam.pipeline.elasticsearchagent.model.DataStorageDoc) S3bucketDataStorage(com.epam.pipeline.entity.datastorage.S3bucketDataStorage) CloudPipelineAPIClient(com.epam.pipeline.elasticsearchagent.service.impl.CloudPipelineAPIClient) AclClass(com.epam.pipeline.entity.security.acl.AclClass) Optional(java.util.Optional) AbstractDataStorage(com.epam.pipeline.entity.datastorage.AbstractDataStorage) AwsRegion(com.epam.pipeline.entity.region.AwsRegion) StringUtils(org.apache.commons.lang3.StringUtils) AbstractDataStorage(com.epam.pipeline.entity.datastorage.AbstractDataStorage) AwsRegion(com.epam.pipeline.entity.region.AwsRegion) DataStorageDoc(com.epam.pipeline.elasticsearchagent.model.DataStorageDoc) S3bucketDataStorage(com.epam.pipeline.entity.datastorage.S3bucketDataStorage)

Aggregations

DataStorageDoc (com.epam.pipeline.elasticsearchagent.model.DataStorageDoc)3 S3bucketDataStorage (com.epam.pipeline.entity.datastorage.S3bucketDataStorage)3 AbstractDataStorage (com.epam.pipeline.entity.datastorage.AbstractDataStorage)2 StoragePolicy (com.epam.pipeline.entity.datastorage.StoragePolicy)2 Test (org.junit.jupiter.api.Test)2 EntityContainer (com.epam.pipeline.elasticsearchagent.model.EntityContainer)1 CloudPipelineAPIClient (com.epam.pipeline.elasticsearchagent.service.impl.CloudPipelineAPIClient)1 AbstractCloudPipelineEntityLoader (com.epam.pipeline.elasticsearchagent.service.impl.converter.AbstractCloudPipelineEntityLoader)1 AwsRegion (com.epam.pipeline.entity.region.AwsRegion)1 AclClass (com.epam.pipeline.entity.security.acl.AclClass)1 List (java.util.List)1 Optional (java.util.Optional)1 StringUtils (org.apache.commons.lang3.StringUtils)1 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)1