use of com.epam.pipeline.entity.datastorage.AbstractDataStorage in project cloud-pipeline by epam.
the class AttachmentFileManager method deleteAttachments.
/**
* Deletes attachments. Deletes records from DB transactionally and files from Data Storage in async mode.
* @param attachments attachments to delete
*/
public void deleteAttachments(List<Attachment> attachments) {
String systemDataStorageName = preferenceManager.getPreference(SystemPreferences.DATA_STORAGE_SYSTEM_DATA_STORAGE_NAME);
if (StringUtils.isBlank(systemDataStorageName)) {
LOGGER.debug(messageHelper.getMessage(MessageConstants.ERROR_ATTACHMENT_SYSTEM_DATA_STORAGE_NOT_CONFIGURED));
return;
}
AbstractDataStorage attachmentStorage = dataStorageManager.loadByNameOrId(systemDataStorageName);
CompletableFuture.runAsync(() -> {
List<UpdateDataStorageItemVO> itemsToDelete = attachments.stream().map(a -> {
UpdateDataStorageItemVO updateVO = new UpdateDataStorageItemVO();
updateVO.setPath(a.getPath());
return updateVO;
}).collect(Collectors.toList());
try {
dataStorageManager.deleteDataStorageItems(attachmentStorage.getId(), itemsToDelete, attachmentStorage.isVersioningEnabled());
} catch (Exception e) {
LOGGER.error("Error while deleting attachments:", e);
}
});
attachmentManager.deleteAttachments(attachments);
}
use of com.epam.pipeline.entity.datastorage.AbstractDataStorage in project cloud-pipeline by epam.
the class AttachmentFileManager method uploadAttachment.
public Attachment uploadAttachment(InputStream attachmentInputStream, String fileName) {
String systemDataStorageName = preferenceManager.getPreference(SystemPreferences.DATA_STORAGE_SYSTEM_DATA_STORAGE_NAME);
Assert.notNull(systemDataStorageName, messageHelper.getMessage(MessageConstants.ERROR_ATTACHMENT_SYSTEM_DATA_STORAGE_NOT_CONFIGURED));
AbstractDataStorage attachmentStorage = dataStorageManager.loadByNameOrId(systemDataStorageName);
UUID uuid = UUID.randomUUID();
String uniqueName = uuid.toString() + "-" + fileName;
DataStorageFile uploadedFile = dataStorageManager.createDataStorageFile(attachmentStorage.getId(), ATTACHMENTS_DIRECTORY, uniqueName, attachmentInputStream);
Attachment attachment = new Attachment();
attachment.setPath(uploadedFile.getPath());
attachment.setName(fileName);
attachment.setCreatedDate(DateUtils.now());
attachment.setOwner(authManager.getAuthorizedUser());
attachmentManager.create(attachment);
return attachment;
}
use of com.epam.pipeline.entity.datastorage.AbstractDataStorage in project cloud-pipeline by epam.
the class FolderManager method loadTree.
public Folder loadTree() {
List<Folder> result = folderDao.loadAllFolders();
List<Pipeline> rootPipelines = pipelineManager.loadRootPipelines();
List<AbstractDataStorage> rootDataStorages = dataStorageManager.loadRootDataStorages();
List<RunConfiguration> rootRunConfigurations = configurationManager.loadRootConfigurations();
Map<String, Integer> rootMetadataEntityCount = metadataEntityManager.loadRootMetadataEntities();
Folder root = new Folder();
root.setChildFolders(result);
if (!CollectionUtils.isEmpty(rootPipelines)) {
root.setPipelines(rootPipelines);
}
if (!CollectionUtils.isEmpty(rootDataStorages)) {
root.setStorages(rootDataStorages);
}
if (!CollectionUtils.isEmpty(rootRunConfigurations)) {
root.setConfigurations(rootRunConfigurations);
}
if (!CollectionUtils.sizeIsEmpty(rootMetadataEntityCount)) {
root.setMetadata(rootMetadataEntityCount);
}
return root;
}
use of com.epam.pipeline.entity.datastorage.AbstractDataStorage in project cloud-pipeline by epam.
the class PipelineDocumentTemplateManager method applyFilesGeneratedByPipeline.
private void applyFilesGeneratedByPipeline(PipelineDocumentTemplate template) {
Optional<AbstractDataStorage> dataStorageOptional = dataStorageManager.getDataStorages().stream().filter(ds -> ds.getName().toLowerCase().contains("analysis")).findAny();
if (dataStorageOptional.isPresent()) {
AbstractDataStorage abstractDataStorage = dataStorageOptional.get();
StoragePolicy policy = abstractDataStorage.getStoragePolicy();
Integer totalDays = policy == null ? 0 : policy.getLongTermStorageDuration();
final Integer daysInYear = 365;
final Integer daysInMonth = 30;
Integer years = Math.floorDiv(totalDays, daysInYear);
Integer months = Math.floorDiv(totalDays - years * daysInYear, daysInMonth);
Integer days = totalDays - years * daysInYear - months * daysInMonth;
List<String> fates = new ArrayList<>();
if (years > 1) {
fates.add(String.format("%d years", years));
} else if (years == 1) {
fates.add(String.format("%d year", years));
}
if (months > 1) {
fates.add(String.format("%d months", months));
} else if (months == 1) {
fates.add(String.format("%d month", months));
}
if (days > 1 || (days == 0 && fates.size() == 0)) {
fates.add(String.format("%d days", days));
} else if (days == 1) {
fates.add(String.format("%d day", days));
}
String fateDescription = String.join(", ", fates);
List<DataStorageRule> rules = dataStorageRuleManager.loadAllRulesForPipeline(template.getPipeline().getId());
for (DataStorageRule rule : rules) {
String name = rule.getFileMask();
String fate = rule.getMoveToSts() ? fateDescription : "Removed at completion";
template.getFilesGeneratedDuringPipelineProcessing().add(new ImmutablePair<>(name, fate));
}
}
}
use of com.epam.pipeline.entity.datastorage.AbstractDataStorage in project cloud-pipeline by epam.
the class FolderTemplateManager method prepareTemplateStorages.
private void prepareTemplateStorages(FolderTemplate template, String prefix) {
template.getDatastorages().forEach(storage -> {
String storageName = storage.getName();
Assert.isTrue(!StringUtils.isEmpty(storageName), messageHelper.getMessage(MessageConstants.ERROR_DATASTORAGE_NAME_IS_EMPTY));
Assert.notNull(storage.getType(), messageHelper.getMessage(MessageConstants.ERROR_DATASTORAGE_TYPE_NOT_SPECIFIED, storageName));
storage.setName(storageName.replaceAll(REPLACE_MARK, prefix));
verifyStoragePath(storage);
updateStoragePath(prefix, storage);
AbstractDataStorage dataStorage = dataStorageManager.convertToDataStorage(storage);
verifyDataStorageNonExistence(dataStorage);
});
}
Aggregations