Search in sources :

Example 46 with AbstractDataStorage

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);
}
Also used : MessageConstants(com.epam.pipeline.common.MessageConstants) LoggerFactory(org.slf4j.LoggerFactory) SystemPreferences(com.epam.pipeline.manager.preference.SystemPreferences) Autowired(org.springframework.beans.factory.annotation.Autowired) CompletableFuture(java.util.concurrent.CompletableFuture) StringUtils(org.apache.commons.lang3.StringUtils) MessageHelper(com.epam.pipeline.common.MessageHelper) Propagation(org.springframework.transaction.annotation.Propagation) Service(org.springframework.stereotype.Service) DateUtils(com.epam.pipeline.entity.utils.DateUtils) PreferenceManager(com.epam.pipeline.manager.preference.PreferenceManager) Logger(org.slf4j.Logger) AbstractDataStorage(com.epam.pipeline.entity.datastorage.AbstractDataStorage) Attachment(com.epam.pipeline.entity.issue.Attachment) AccessDeniedException(org.springframework.security.access.AccessDeniedException) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) DataStorageFile(com.epam.pipeline.entity.datastorage.DataStorageFile) Objects(java.util.Objects) List(java.util.List) DataStorageStreamingContent(com.epam.pipeline.entity.datastorage.DataStorageStreamingContent) AuthManager(com.epam.pipeline.manager.security.AuthManager) UpdateDataStorageItemVO(com.epam.pipeline.controller.vo.data.storage.UpdateDataStorageItemVO) DataStorageManager(com.epam.pipeline.manager.datastorage.DataStorageManager) Collections(java.util.Collections) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) InputStream(java.io.InputStream) AbstractDataStorage(com.epam.pipeline.entity.datastorage.AbstractDataStorage) UpdateDataStorageItemVO(com.epam.pipeline.controller.vo.data.storage.UpdateDataStorageItemVO) AccessDeniedException(org.springframework.security.access.AccessDeniedException)

Example 47 with AbstractDataStorage

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;
}
Also used : DataStorageFile(com.epam.pipeline.entity.datastorage.DataStorageFile) AbstractDataStorage(com.epam.pipeline.entity.datastorage.AbstractDataStorage) Attachment(com.epam.pipeline.entity.issue.Attachment) UUID(java.util.UUID)

Example 48 with AbstractDataStorage

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;
}
Also used : AbstractDataStorage(com.epam.pipeline.entity.datastorage.AbstractDataStorage) RunConfiguration(com.epam.pipeline.entity.configuration.RunConfiguration) PasswordGenerator.generateRandomString(com.epam.pipeline.utils.PasswordGenerator.generateRandomString) Folder(com.epam.pipeline.entity.pipeline.Folder) Pipeline(com.epam.pipeline.entity.pipeline.Pipeline)

Example 49 with AbstractDataStorage

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));
        }
    }
}
Also used : PipelineManager(com.epam.pipeline.manager.pipeline.PipelineManager) GitClientException(com.epam.pipeline.exception.git.GitClientException) Date(java.util.Date) Autowired(org.springframework.beans.factory.annotation.Autowired) GitRepositoryEntry(com.epam.pipeline.entity.git.GitRepositoryEntry) DocumentGenerationPropertyManager(com.epam.pipeline.manager.pipeline.DocumentGenerationPropertyManager) StoragePolicy(com.epam.pipeline.entity.datastorage.StoragePolicy) PipelineVersionManager(com.epam.pipeline.manager.pipeline.PipelineVersionManager) ArrayList(java.util.ArrayList) Service(org.springframework.stereotype.Service) TaskNode(com.epam.pipeline.entity.graph.TaskNode) Pipeline(com.epam.pipeline.entity.pipeline.Pipeline) GitManager(com.epam.pipeline.manager.git.GitManager) AbstractDataStorage(com.epam.pipeline.entity.datastorage.AbstractDataStorage) Collectors(java.util.stream.Collectors) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) Tool(com.epam.pipeline.entity.pipeline.Tool) DataStorageRuleManager(com.epam.pipeline.manager.datastorage.DataStorageRuleManager) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) TaskGraphVO(com.epam.pipeline.controller.vo.TaskGraphVO) Revision(com.epam.pipeline.entity.pipeline.Revision) Optional(java.util.Optional) DataStorageManager(com.epam.pipeline.manager.datastorage.DataStorageManager) DataStorageRule(com.epam.pipeline.entity.datastorage.rules.DataStorageRule) AbstractDataStorage(com.epam.pipeline.entity.datastorage.AbstractDataStorage) ArrayList(java.util.ArrayList) DataStorageRule(com.epam.pipeline.entity.datastorage.rules.DataStorageRule) StoragePolicy(com.epam.pipeline.entity.datastorage.StoragePolicy)

Example 50 with AbstractDataStorage

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);
    });
}
Also used : AbstractDataStorage(com.epam.pipeline.entity.datastorage.AbstractDataStorage)

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