Search in sources :

Example 1 with Arrays1

use of com.orion.utils.Arrays1 in project orion-ops by lijiahangmax.

the class StatisticsServiceImpl method schedulerTaskStatistic.

@Override
public SchedulerTaskRecordStatisticsVO schedulerTaskStatistic(Long taskId) {
    // 查询缓存
    String cacheKey = Strings.format(KeyConst.SCHEDULER_TASK_STATISTIC_KEY, taskId);
    String cacheData = redisTemplate.opsForValue().get(cacheKey);
    if (Strings.isBlank(cacheData)) {
        // 获取图表时间
        Date[] chartDates = Dates.getIncrementDates(Dates.clearHms(), Calendar.DAY_OF_MONTH, -1, 7);
        Date rangeStartDate = Arrays1.last(chartDates);
        // 获取任务统计信息
        SchedulerTaskRecordStatisticsDTO taskStatisticDTO = schedulerTaskRecordDAO.getTaskRecordStatistic(taskId, rangeStartDate);
        SchedulerTaskRecordStatisticsVO statisticTask = Converts.to(taskStatisticDTO, SchedulerTaskRecordStatisticsVO.class);
        // 获取机器统计信息
        // List<SchedulerTaskRecordStatisticsDTO> machines = schedulerTaskRecordDAO.getTaskMachineRecordStatistic(taskId);
        // List<SchedulerTaskMachineRecordStatisticsVO> statisticMachines = Converts.toList(machines, SchedulerTaskMachineRecordStatisticsVO.class);
        // statisticTask.setMachineList(statisticMachines);
        // 获取任务统计图表
        List<SchedulerTaskRecordStatisticsDTO> dateStatistic = schedulerTaskRecordDAO.getTaskRecordDateStatistic(taskId, rangeStartDate);
        Map<String, SchedulerTaskRecordStatisticsDTO> dateStatisticMap = dateStatistic.stream().collect(Collectors.toMap(s -> Dates.format(s.getDate(), Dates.YMD), Function.identity(), (e1, e2) -> e2));
        // 填充数据
        List<SchedulerTaskRecordStatisticsChartVO> statisticCharts = Arrays.stream(chartDates).sorted().map(s -> Dates.format(s, Dates.YMD)).map(date -> Optional.ofNullable(dateStatisticMap.get(date)).map(s -> Converts.to(s, SchedulerTaskRecordStatisticsChartVO.class)).orElseGet(() -> {
            SchedulerTaskRecordStatisticsChartVO dateChart = new SchedulerTaskRecordStatisticsChartVO();
            dateChart.setDate(date);
            dateChart.setScheduledCount(0);
            dateChart.setSuccessCount(0);
            dateChart.setFailureCount(0);
            return dateChart;
        })).collect(Collectors.toList());
        statisticTask.setCharts(statisticCharts);
        // 设置缓存
        redisTemplate.opsForValue().set(cacheKey, JSON.toJSONString(statisticTask), Integer.parseInt(SystemEnvAttr.STATISTICS_CACHE_EXPIRE.getValue()), TimeUnit.MINUTES);
        return statisticTask;
    } else {
        return JSON.parseObject(cacheData, SchedulerTaskRecordStatisticsVO.class);
    }
}
Also used : com.orion.ops.dao(com.orion.ops.dao) java.util(java.util) Dates(com.orion.utils.time.Dates) Resource(javax.annotation.Resource) StatisticCountVO(com.orion.ops.entity.vo.StatisticCountVO) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) SchedulerTaskRecordStatisticsChartVO(com.orion.ops.entity.vo.SchedulerTaskRecordStatisticsChartVO) SchedulerTaskRecordStatisticsVO(com.orion.ops.entity.vo.SchedulerTaskRecordStatisticsVO) TimeUnit(java.util.concurrent.TimeUnit) StatisticsService(com.orion.ops.service.api.StatisticsService) Converts(com.orion.utils.convert.Converts) JSON(com.alibaba.fastjson.JSON) SystemEnvAttr(com.orion.ops.consts.system.SystemEnvAttr) Service(org.springframework.stereotype.Service) SchedulerTaskRecordStatisticsDTO(com.orion.ops.entity.dto.SchedulerTaskRecordStatisticsDTO) Arrays1(com.orion.utils.Arrays1) RedisTemplate(org.springframework.data.redis.core.RedisTemplate) StatisticCountDTO(com.orion.ops.entity.dto.StatisticCountDTO) KeyConst(com.orion.ops.consts.KeyConst) StatisticsVO(com.orion.ops.entity.vo.StatisticsVO) Strings(com.orion.utils.Strings) SchedulerTaskRecordStatisticsChartVO(com.orion.ops.entity.vo.SchedulerTaskRecordStatisticsChartVO) SchedulerTaskRecordStatisticsVO(com.orion.ops.entity.vo.SchedulerTaskRecordStatisticsVO) SchedulerTaskRecordStatisticsDTO(com.orion.ops.entity.dto.SchedulerTaskRecordStatisticsDTO)

Example 2 with Arrays1

use of com.orion.utils.Arrays1 in project orion-ops by lijiahangmax.

the class ApplicationVcsServiceImpl method cleanBuildVcs.

@Override
public void cleanBuildVcs(Long id) {
    // 查询数据
    ApplicationVcsDO vcs = applicationVcsDAO.selectById(id);
    Valid.notNull(vcs, MessageConst.UNKNOWN_DATA);
    // 设置日志参数
    EventParamsHolder.addParam(EventKeys.ID, id);
    EventParamsHolder.addParam(EventKeys.NAME, vcs.getVcsName());
    File rootPath = new File(Files1.getPath(SystemEnvAttr.VCS_PATH.getValue(), id + Const.EMPTY));
    if (!Files1.isDirectory(rootPath)) {
        return;
    }
    // 查询文件夹
    File[] files = rootPath.listFiles(e -> !e.getName().equals(Const.EVENT) && e.isDirectory() && Strings.isInteger(e.getName()));
    if (Arrays1.isEmpty(files)) {
        return;
    }
    // 保留两个版本 防止清空正在进行中的构建任务
    int length = files.length;
    if (length <= 2) {
        return;
    }
    Arrays.sort(files, Comparator.comparing(s -> Integer.parseInt(s.getName())));
    for (int i = 0; i < length - 2; i++) {
        Files1.delete(files[i]);
    }
}
Also used : EventKeys(com.orion.ops.consts.event.EventKeys) LogInfo(com.orion.vcs.git.info.LogInfo) Exceptions(com.orion.utils.Exceptions) java.util(java.util) ApplicationVcsCommitVO(com.orion.ops.entity.vo.ApplicationVcsCommitVO) ValueMix(com.orion.ops.utils.ValueMix) ApplicationVcsRequest(com.orion.ops.entity.request.ApplicationVcsRequest) ApplicationInfoDAO(com.orion.ops.dao.ApplicationInfoDAO) MessageConst(com.orion.ops.consts.MessageConst) ApplicationVcsBranchVO(com.orion.ops.entity.vo.ApplicationVcsBranchVO) EventParamsHolder(com.orion.ops.consts.event.EventParamsHolder) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) ApplicationVcsDAO(com.orion.ops.dao.ApplicationVcsDAO) VcsStatus(com.orion.ops.consts.app.VcsStatus) ApplicationBuildDAO(com.orion.ops.dao.ApplicationBuildDAO) ApplicationVcsInfoVO(com.orion.ops.entity.vo.ApplicationVcsInfoVO) Streams(com.orion.utils.io.Streams) Service(org.springframework.stereotype.Service) Arrays1(com.orion.utils.Arrays1) VcsAuthType(com.orion.ops.consts.app.VcsAuthType) Utils(com.orion.ops.utils.Utils) Const(com.orion.ops.consts.Const) DataGrid(com.orion.lang.wrapper.DataGrid) ApplicationVcsDO(com.orion.ops.entity.domain.ApplicationVcsDO) ApplicationVcsVO(com.orion.ops.entity.vo.ApplicationVcsVO) Resource(javax.annotation.Resource) BranchInfo(com.orion.vcs.git.info.BranchInfo) Valid(com.orion.ops.utils.Valid) File(java.io.File) Files1(com.orion.utils.io.Files1) DataQuery(com.orion.ops.utils.DataQuery) Converts(com.orion.utils.convert.Converts) Slf4j(lombok.extern.slf4j.Slf4j) VcsTokenType(com.orion.ops.consts.app.VcsTokenType) SystemEnvAttr(com.orion.ops.consts.system.SystemEnvAttr) ApplicationVcsService(com.orion.ops.service.api.ApplicationVcsService) VcsType(com.orion.ops.consts.app.VcsType) Strings(com.orion.utils.Strings) Gits(com.orion.vcs.git.Gits) Transactional(org.springframework.transaction.annotation.Transactional) ApplicationVcsDO(com.orion.ops.entity.domain.ApplicationVcsDO) File(java.io.File)

Aggregations

SystemEnvAttr (com.orion.ops.consts.system.SystemEnvAttr)2 Arrays1 (com.orion.utils.Arrays1)2 Strings (com.orion.utils.Strings)2 Converts (com.orion.utils.convert.Converts)2 java.util (java.util)2 Resource (javax.annotation.Resource)2 Service (org.springframework.stereotype.Service)2 JSON (com.alibaba.fastjson.JSON)1 LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)1 DataGrid (com.orion.lang.wrapper.DataGrid)1 Const (com.orion.ops.consts.Const)1 KeyConst (com.orion.ops.consts.KeyConst)1 MessageConst (com.orion.ops.consts.MessageConst)1 VcsAuthType (com.orion.ops.consts.app.VcsAuthType)1 VcsStatus (com.orion.ops.consts.app.VcsStatus)1 VcsTokenType (com.orion.ops.consts.app.VcsTokenType)1 VcsType (com.orion.ops.consts.app.VcsType)1 EventKeys (com.orion.ops.consts.event.EventKeys)1 EventParamsHolder (com.orion.ops.consts.event.EventParamsHolder)1 com.orion.ops.dao (com.orion.ops.dao)1