Search in sources :

Example 1 with DataStorageRule

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

the class PipelineCRUDManager method createDefaultDataStorageRule.

private DataStorageRule createDefaultDataStorageRule(Pipeline pipeline, Date now) {
    DataStorageRule rule = new DataStorageRule();
    rule.setPipelineId(pipeline.getId());
    rule.setCreatedDate(now);
    rule.setMoveToSts(DataStorageRule.DEFAULT_MOVE_TO_STS);
    rule.setFileMask(DataStorageRule.DEFAULT_FILE_MASK);
    return rule;
}
Also used : DataStorageRule(com.epam.pipeline.entity.datastorage.rules.DataStorageRule)

Example 2 with DataStorageRule

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

the class DataStorageRuleManager method loadRule.

@Transactional(propagation = Propagation.REQUIRED)
public DataStorageRule loadRule(Long pipelineId, String fileMask) {
    DataStorageRule rule = dataStorageRuleDao.loadDataStorageRule(pipelineId, fileMask);
    Assert.notNull(rule, messageHelper.getMessage(MessageConstants.ERROR_DATASTORAGE_RULE_NOT_FOUND, pipelineId, fileMask));
    return rule;
}
Also used : DataStorageRule(com.epam.pipeline.entity.datastorage.rules.DataStorageRule) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with DataStorageRule

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

the class DataStorageRuleManager method deleteRule.

@Transactional(propagation = Propagation.REQUIRED)
public DataStorageRule deleteRule(Long pipelineId, String fileMask) {
    pipelineManager.load(pipelineId);
    DataStorageRule rule = loadRule(pipelineId, fileMask);
    dataStorageRuleDao.deleteDataStorageRule(pipelineId, fileMask);
    return rule;
}
Also used : DataStorageRule(com.epam.pipeline.entity.datastorage.rules.DataStorageRule) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with DataStorageRule

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

the class PipelineCRUDManager method save.

@Transactional(propagation = Propagation.REQUIRED)
public Pipeline save(final Pipeline pipeline) {
    Date now = DateUtils.now();
    pipeline.setCreatedDate(now);
    pipelineDao.createPipeline(pipeline);
    DataStorageRule rule = createDefaultDataStorageRule(pipeline, now);
    dataStorageRuleDao.createDataStorageRule(rule);
    return pipeline;
}
Also used : DataStorageRule(com.epam.pipeline.entity.datastorage.rules.DataStorageRule) Date(java.util.Date) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with DataStorageRule

use of com.epam.pipeline.entity.datastorage.rules.DataStorageRule 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)

Aggregations

DataStorageRule (com.epam.pipeline.entity.datastorage.rules.DataStorageRule)5 Transactional (org.springframework.transaction.annotation.Transactional)3 Date (java.util.Date)2 TaskGraphVO (com.epam.pipeline.controller.vo.TaskGraphVO)1 AbstractDataStorage (com.epam.pipeline.entity.datastorage.AbstractDataStorage)1 StoragePolicy (com.epam.pipeline.entity.datastorage.StoragePolicy)1 GitRepositoryEntry (com.epam.pipeline.entity.git.GitRepositoryEntry)1 TaskNode (com.epam.pipeline.entity.graph.TaskNode)1 Pipeline (com.epam.pipeline.entity.pipeline.Pipeline)1 Revision (com.epam.pipeline.entity.pipeline.Revision)1 Tool (com.epam.pipeline.entity.pipeline.Tool)1 GitClientException (com.epam.pipeline.exception.git.GitClientException)1 DataStorageManager (com.epam.pipeline.manager.datastorage.DataStorageManager)1 DataStorageRuleManager (com.epam.pipeline.manager.datastorage.DataStorageRuleManager)1 GitManager (com.epam.pipeline.manager.git.GitManager)1 DocumentGenerationPropertyManager (com.epam.pipeline.manager.pipeline.DocumentGenerationPropertyManager)1 PipelineManager (com.epam.pipeline.manager.pipeline.PipelineManager)1 PipelineVersionManager (com.epam.pipeline.manager.pipeline.PipelineVersionManager)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1