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