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