Search in sources :

Example 21 with AbstractDataStorage

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

the class DataStorageManager method generateTemporaryCredentials.

public AbstractTemporaryCredentials generateTemporaryCredentials(List<DataStorageAction> actions) {
    AbstractDataStorage dataStorage = ListUtils.emptyIfNull(actions).stream().findFirst().map(action -> load(action.getId())).orElseThrow(() -> new IllegalArgumentException("Actions are not provided"));
    Assert.isTrue(dataStorage instanceof S3bucketDataStorage, "Temporary credentials are supported only for S3 Buckets.");
    S3bucketDataStorage bucket = (S3bucketDataStorage) dataStorage;
    AwsRegion awsRegion = awsRegionManager.getAwsRegion(bucket);
    actions.forEach(action -> {
        AbstractDataStorage loaded = action.getId().equals(dataStorage.getId()) ? dataStorage : load(action.getId());
        Assert.isTrue(loaded instanceof S3bucketDataStorage, "Temporary credentials are supported only for S3 Buckets.");
        action.setBucketName(loaded.getPath());
        Long regionId = ((S3bucketDataStorage) loaded).getRegionId();
        Assert.isTrue(Objects.equals(regionId, bucket.getRegionId()), "Actions shall be requested for buckets from the same region");
    });
    return dataStorageFactory.temporaryCredentials(bucket.getType()).withRole(preferenceManager.getPreference(SystemPreferences.DATA_STORAGE_TEMP_CREDENTIALS_ROLE)).withDurationSeconds(preferenceManager.getPreference(SystemPreferences.DATA_STORAGE_TEMP_CREDENTIALS_DURATION)).withKmsArn(awsRegion.getKmsKeyArn()).withRegionId(awsRegion.getAwsRegionName()).generate(actions);
}
Also used : Arrays(java.util.Arrays) S3Constants(com.epam.pipeline.manager.datastorage.providers.aws.s3.S3Constants) LoggerFactory(org.slf4j.LoggerFactory) SystemPreferences(com.epam.pipeline.manager.preference.SystemPreferences) Autowired(org.springframework.beans.factory.annotation.Autowired) StoragePolicy(com.epam.pipeline.entity.datastorage.StoragePolicy) StringUtils(org.apache.commons.lang3.StringUtils) DataStorageVO(com.epam.pipeline.controller.vo.DataStorageVO) Folder(com.epam.pipeline.entity.pipeline.Folder) PipelineRun(com.epam.pipeline.entity.pipeline.PipelineRun) PipeConfValue(com.epam.pipeline.entity.metadata.PipeConfValue) MessageHelper(com.epam.pipeline.common.MessageHelper) ListUtils(org.apache.commons.collections4.ListUtils) Map(java.util.Map) DataStorageItemContent(com.epam.pipeline.entity.datastorage.DataStorageItemContent) DataStorageListing(com.epam.pipeline.entity.datastorage.DataStorageListing) AntPathMatcher(org.springframework.util.AntPathMatcher) SecuredEntityManager(com.epam.pipeline.manager.security.SecuredEntityManager) DataStorageItemType(com.epam.pipeline.entity.datastorage.DataStorageItemType) DataStorageLink(com.epam.pipeline.entity.pipeline.run.parameter.DataStorageLink) AbstractSecuredEntity(com.epam.pipeline.entity.AbstractSecuredEntity) RoleManager(com.epam.pipeline.manager.user.RoleManager) DataStorageDownloadFileUrl(com.epam.pipeline.entity.datastorage.DataStorageDownloadFileUrl) Collection(java.util.Collection) Set(java.util.Set) StorageContainer(com.epam.pipeline.entity.user.StorageContainer) AwsRegion(com.epam.pipeline.entity.region.AwsRegion) Collectors(java.util.stream.Collectors) AbstractDataStorageFactory(com.epam.pipeline.entity.datastorage.AbstractDataStorageFactory) DataStorageFile(com.epam.pipeline.entity.datastorage.DataStorageFile) Objects(java.util.Objects) List(java.util.List) UserManager(com.epam.pipeline.manager.user.UserManager) DataStorageStreamingContent(com.epam.pipeline.entity.datastorage.DataStorageStreamingContent) AclSync(com.epam.pipeline.manager.security.acl.AclSync) Optional(java.util.Optional) EntityVO(com.epam.pipeline.controller.vo.EntityVO) AbstractTemporaryCredentials(com.epam.pipeline.entity.datastorage.AbstractTemporaryCredentials) DataStorageDao(com.epam.pipeline.dao.datastorage.DataStorageDao) MessageConstants(com.epam.pipeline.common.MessageConstants) DataStorageAction(com.epam.pipeline.entity.datastorage.DataStorageAction) HashMap(java.util.HashMap) Function(java.util.function.Function) DataStorageFolder(com.epam.pipeline.entity.datastorage.DataStorageFolder) ArrayList(java.util.ArrayList) MetadataManager(com.epam.pipeline.manager.metadata.MetadataManager) CollectionUtils(org.apache.commons.collections.CollectionUtils) Propagation(org.springframework.transaction.annotation.Propagation) Service(org.springframework.stereotype.Service) DataStorageException(com.epam.pipeline.entity.datastorage.DataStorageException) BaseEntity(com.epam.pipeline.entity.BaseEntity) PreferenceManager(com.epam.pipeline.manager.preference.PreferenceManager) Logger(org.slf4j.Logger) FolderManager(com.epam.pipeline.manager.pipeline.FolderManager) MapUtils(org.apache.commons.collections.MapUtils) AbstractDataStorage(com.epam.pipeline.entity.datastorage.AbstractDataStorage) DataStorageType(com.epam.pipeline.entity.datastorage.DataStorageType) AbstractDataStorageItem(com.epam.pipeline.entity.datastorage.AbstractDataStorageItem) Paths(java.nio.file.Paths) NumberUtils(org.apache.commons.lang3.math.NumberUtils) AclClass(com.epam.pipeline.entity.security.acl.AclClass) S3bucketDataStorage(com.epam.pipeline.entity.datastorage.aws.S3bucketDataStorage) AuthManager(com.epam.pipeline.manager.security.AuthManager) UpdateDataStorageItemVO(com.epam.pipeline.controller.vo.data.storage.UpdateDataStorageItemVO) Collections(java.util.Collections) AwsRegionManager(com.epam.pipeline.manager.region.AwsRegionManager) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) InputStream(java.io.InputStream) AbstractDataStorage(com.epam.pipeline.entity.datastorage.AbstractDataStorage) AwsRegion(com.epam.pipeline.entity.region.AwsRegion) S3bucketDataStorage(com.epam.pipeline.entity.datastorage.aws.S3bucketDataStorage)

Example 22 with AbstractDataStorage

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

the class DataStorageManager method generateDataStorageItemUploadUrl.

public List<DataStorageDownloadFileUrl> generateDataStorageItemUploadUrl(Long id, List<String> paths) {
    AbstractDataStorage dataStorage = load(id);
    List<DataStorageDownloadFileUrl> urls = new ArrayList<>();
    if (paths == null) {
        return urls;
    }
    paths.forEach(path -> urls.add(storageProviderManager.generateDataStorageItemUploadUrl(dataStorage, path)));
    return urls;
}
Also used : AbstractDataStorage(com.epam.pipeline.entity.datastorage.AbstractDataStorage) ArrayList(java.util.ArrayList) DataStorageDownloadFileUrl(com.epam.pipeline.entity.datastorage.DataStorageDownloadFileUrl)

Example 23 with AbstractDataStorage

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

the class DataStorageManager method updatePolicy.

@Transactional(propagation = Propagation.REQUIRED)
public AbstractDataStorage updatePolicy(DataStorageVO dataStorageVO) {
    AbstractDataStorage dataStorage = load(dataStorageVO.getId());
    AbstractDataStorage updated = updateStoragePolicy(dataStorage, dataStorageVO);
    storageProviderManager.applyStoragePolicy(dataStorage);
    dataStorageDao.updateDataStorage(updated);
    return updated;
}
Also used : AbstractDataStorage(com.epam.pipeline.entity.datastorage.AbstractDataStorage) Transactional(org.springframework.transaction.annotation.Transactional)

Example 24 with AbstractDataStorage

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

the class DataStorageManager method analyzePaths.

public void analyzePaths(List<PipeConfValue> values) {
    if (CollectionUtils.isEmpty(values)) {
        return;
    }
    List<AbstractDataStorage> dataStorages = getDataStorages();
    values.forEach(value -> {
        List<DataStorageLink> links = new ArrayList<>();
        for (AbstractDataStorage dataStorage : dataStorages) {
            List<DataStorageLink> dataStorageLinks = getLinks(dataStorage, value.getValue());
            if (!dataStorageLinks.isEmpty()) {
                links.addAll(dataStorageLinks);
            }
        }
        if (!links.isEmpty()) {
            value.setDataStorageLinks(links);
        }
    });
}
Also used : AbstractDataStorage(com.epam.pipeline.entity.datastorage.AbstractDataStorage) ArrayList(java.util.ArrayList) DataStorageLink(com.epam.pipeline.entity.pipeline.run.parameter.DataStorageLink)

Example 25 with AbstractDataStorage

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

the class DataStorageManager method delete.

@Transactional(propagation = Propagation.REQUIRED)
public AbstractDataStorage delete(Long id, boolean proceedOnCloud) {
    AbstractDataStorage dataStorage = load(id);
    validateStorageIsNotUsedAsDefault(id, roleManager.loadRolesByDefaultStorage(id));
    validateStorageIsNotUsedAsDefault(id, userManager.loadUsersByDeafultStorage(id));
    if (proceedOnCloud) {
        try {
            storageProviderManager.deleteBucket(dataStorage);
        } catch (DataStorageException e) {
            LOGGER.error(e.getMessage(), e);
        }
    }
    dataStorageDao.deleteDataStorage(id);
    return dataStorage;
}
Also used : AbstractDataStorage(com.epam.pipeline.entity.datastorage.AbstractDataStorage) DataStorageException(com.epam.pipeline.entity.datastorage.DataStorageException) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

AbstractDataStorage (com.epam.pipeline.entity.datastorage.AbstractDataStorage)62 AbstractSpringTest (com.epam.pipeline.AbstractSpringTest)22 Test (org.junit.Test)22 Transactional (org.springframework.transaction.annotation.Transactional)18 Folder (com.epam.pipeline.entity.pipeline.Folder)13 DataStorageVO (com.epam.pipeline.controller.vo.DataStorageVO)11 ArrayList (java.util.ArrayList)7 List (java.util.List)6 EntityVO (com.epam.pipeline.controller.vo.EntityVO)5 StoragePolicy (com.epam.pipeline.entity.datastorage.StoragePolicy)5 Service (org.springframework.stereotype.Service)5 Pipeline (com.epam.pipeline.entity.pipeline.Pipeline)4 UpdateDataStorageItemVO (com.epam.pipeline.controller.vo.data.storage.UpdateDataStorageItemVO)3 DataStorageDownloadFileUrl (com.epam.pipeline.entity.datastorage.DataStorageDownloadFileUrl)3 DataStorageException (com.epam.pipeline.entity.datastorage.DataStorageException)3 DataStorageFile (com.epam.pipeline.entity.datastorage.DataStorageFile)3 DataStorageLink (com.epam.pipeline.entity.pipeline.run.parameter.DataStorageLink)3 ObjectCreatorUtils.constructDataStorageVO (com.epam.pipeline.manager.ObjectCreatorUtils.constructDataStorageVO)3 IOException (java.io.IOException)3 MessageConstants (com.epam.pipeline.common.MessageConstants)2