Search in sources :

Example 1 with FileTailVO

use of com.orion.ops.entity.vo.FileTailVO in project orion-ops by lijiahangmax.

the class FileTailServiceImpl method tailFileList.

@Override
public DataGrid<FileTailVO> tailFileList(FileTailRequest request) {
    LambdaQueryWrapper<FileTailListDO> wrapper = new LambdaQueryWrapper<FileTailListDO>().eq(Objects.nonNull(request.getMachineId()), FileTailListDO::getMachineId, request.getMachineId()).like(!Strings.isEmpty(request.getName()), FileTailListDO::getAliasName, request.getName()).like(!Strings.isEmpty(request.getPath()), FileTailListDO::getFilePath, request.getPath()).like(!Strings.isEmpty(request.getCommand()), FileTailListDO::getTailCommand, request.getCommand()).orderByDesc(FileTailListDO::getUpdateTime);
    DataGrid<FileTailVO> dataGrid = DataQuery.of(fileTailListDAO).page(request).wrapper(wrapper).dataGrid(FileTailVO.class);
    // 设置机器信息
    Map<Long, MachineInfoDO> machineCache = Maps.newMap();
    dataGrid.forEach(p -> {
        MachineInfoDO machine = machineCache.computeIfAbsent(p.getMachineId(), mid -> machineInfoService.selectById(p.getMachineId()));
        if (machine != null) {
            p.setMachineName(machine.getMachineName());
            p.setMachineHost(machine.getMachineHost());
        }
    });
    return dataGrid;
}
Also used : FileTailListDO(com.orion.ops.entity.domain.FileTailListDO) MachineInfoDO(com.orion.ops.entity.domain.MachineInfoDO) FileTailVO(com.orion.ops.entity.vo.FileTailVO)

Example 2 with FileTailVO

use of com.orion.ops.entity.vo.FileTailVO in project orion-ops by lijiahangmax.

the class FileTailServiceImpl method getTailToken.

@Override
public FileTailVO getTailToken(FileTailType type, Long relId) {
    FileTailVO res;
    // 获取日志路径
    final boolean isLocal = type.isLocal();
    if (isLocal) {
        String path = this.getTailFilePath(type, relId);
        res = new FileTailVO();
        res.setPath(path);
        res.setOffset(machineEnvService.getTailOffset(Const.HOST_MACHINE_ID));
        res.setCharset(machineEnvService.getTailCharset(Const.HOST_MACHINE_ID));
        res.setCommand(machineEnvService.getTailDefaultCommand(Const.HOST_MACHINE_ID));
    } else {
        // tail list
        FileTailListDO fileTail = fileTailListDAO.selectById(relId);
        Valid.notNull(fileTail, MessageConst.UNKNOWN_DATA);
        res = Converts.to(fileTail, FileTailVO.class);
    }
    // 设置命令
    this.replaceTailCommand(res);
    // 设置机器信息
    MachineInfoDO machine = machineInfoService.selectById(isLocal ? Const.HOST_MACHINE_ID : res.getMachineId());
    Valid.notNull(machine, MessageConst.INVALID_MACHINE);
    res.setMachineId(machine.getId());
    res.setMachineName(machine.getMachineName());
    res.setMachineHost(machine.getMachineHost());
    // 设置token
    String token = UUIds.random19();
    res.setToken(token);
    // 设置缓存
    FileTailDTO tail = Converts.to(res, FileTailDTO.class);
    tail.setUserId(Currents.getUserId());
    // 追踪模式
    String tailMode = isLocal ? systemEnvService.getTailMode() : res.getTailMode();
    tail.setMode(tailMode);
    String key = Strings.format(KeyConst.FILE_TAIL_ACCESS_TOKEN, token);
    redisTemplate.opsForValue().set(key, JSON.toJSONString(tail), KeyConst.FILE_TAIL_ACCESS_EXPIRE, TimeUnit.SECONDS);
    // 非列表不返回命令和路径
    if (isLocal) {
        res.setPath(null);
        res.setCommand(null);
    }
    return res;
}
Also used : FileTailListDO(com.orion.ops.entity.domain.FileTailListDO) MachineInfoDO(com.orion.ops.entity.domain.MachineInfoDO) FileTailDTO(com.orion.ops.entity.dto.FileTailDTO) FileTailVO(com.orion.ops.entity.vo.FileTailVO)

Example 3 with FileTailVO

use of com.orion.ops.entity.vo.FileTailVO in project orion-ops by lijiahangmax.

the class FileTailServiceImpl method tailFileDetail.

@Override
public FileTailVO tailFileDetail(Long id) {
    FileTailListDO tail = fileTailListDAO.selectById(id);
    Valid.notNull(tail, MessageConst.UNKNOWN_DATA);
    FileTailVO vo = Converts.to(tail, FileTailVO.class);
    // 设置机器信息
    MachineInfoDO machine = machineInfoService.selectById(tail.getMachineId());
    Valid.notNull(machine, MessageConst.INVALID_MACHINE);
    vo.setMachineName(machine.getMachineName());
    vo.setMachineHost(machine.getMachineHost());
    return vo;
}
Also used : FileTailListDO(com.orion.ops.entity.domain.FileTailListDO) MachineInfoDO(com.orion.ops.entity.domain.MachineInfoDO) FileTailVO(com.orion.ops.entity.vo.FileTailVO)

Aggregations

FileTailListDO (com.orion.ops.entity.domain.FileTailListDO)3 MachineInfoDO (com.orion.ops.entity.domain.MachineInfoDO)3 FileTailVO (com.orion.ops.entity.vo.FileTailVO)3 FileTailDTO (com.orion.ops.entity.dto.FileTailDTO)1