Search in sources :

Example 1 with FileTailListDO

use of com.orion.ops.entity.domain.FileTailListDO in project orion-ops by lijiahangmax.

the class FileTailServiceImpl method insertTailFile.

@Override
public Long insertTailFile(FileTailRequest request) {
    Long machineId = request.getMachineId();
    // 插入
    FileTailListDO insert = new FileTailListDO();
    insert.setAliasName(request.getName());
    insert.setMachineId(machineId);
    insert.setFilePath(request.getPath());
    insert.setFileCharset(request.getCharset());
    insert.setFileOffset(request.getOffset());
    insert.setTailCommand(request.getCommand());
    insert.setTailMode(FileTailMode.of(request.getTailMode(), Const.HOST_MACHINE_ID.equals(machineId)).getMode());
    fileTailListDAO.insert(insert);
    // 设置日志参数
    EventParamsHolder.addParams(insert);
    return insert.getId();
}
Also used : FileTailListDO(com.orion.ops.entity.domain.FileTailListDO)

Example 2 with FileTailListDO

use of com.orion.ops.entity.domain.FileTailListDO in project orion-ops by lijiahangmax.

the class FileTailServiceImpl method deleteTailFile.

@Override
public Integer deleteTailFile(Long id) {
    // 查询文件
    FileTailListDO beforeTail = fileTailListDAO.selectById(id);
    Valid.notNull(beforeTail, MessageConst.UNKNOWN_DATA);
    // 删除
    int effect = fileTailListDAO.deleteById(id);
    // 设置日志参数
    EventParamsHolder.addParam(EventKeys.ID, id);
    EventParamsHolder.addParam(EventKeys.NAME, beforeTail.getAliasName());
    return effect;
}
Also used : FileTailListDO(com.orion.ops.entity.domain.FileTailListDO)

Example 3 with FileTailListDO

use of com.orion.ops.entity.domain.FileTailListDO 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 4 with FileTailListDO

use of com.orion.ops.entity.domain.FileTailListDO in project orion-ops by lijiahangmax.

the class FileTailServiceImpl method updateTailFile.

@Override
public Integer updateTailFile(FileTailRequest request) {
    // 查询文件
    Long id = request.getId();
    FileTailListDO beforeTail = fileTailListDAO.selectById(id);
    Valid.notNull(beforeTail, MessageConst.UNKNOWN_DATA);
    Long machineId = request.getMachineId();
    // 修改
    FileTailListDO update = new FileTailListDO();
    update.setId(id);
    update.setAliasName(request.getName());
    update.setMachineId(machineId);
    update.setFilePath(request.getPath());
    update.setFileOffset(request.getOffset());
    update.setFileCharset(request.getCharset());
    update.setTailCommand(request.getCommand());
    update.setTailMode(FileTailMode.of(request.getTailMode(), Const.HOST_MACHINE_ID.equals(machineId)).getMode());
    update.setUpdateTime(new Date());
    int effect = fileTailListDAO.updateById(update);
    // 设置日志参数
    EventParamsHolder.addParams(update);
    EventParamsHolder.addParam(EventKeys.NAME, beforeTail.getAliasName());
    return effect;
}
Also used : FileTailListDO(com.orion.ops.entity.domain.FileTailListDO) Date(java.util.Date)

Example 5 with FileTailListDO

use of com.orion.ops.entity.domain.FileTailListDO in project orion-ops by lijiahangmax.

the class FileDownloadServiceImpl method getDownloadToken.

@Override
public String getDownloadToken(Long id, FileDownloadType type) {
    String path = null;
    String name = null;
    Long machineId = Const.HOST_MACHINE_ID;
    // 获取日志绝对路径
    switch(type) {
        case SECRET_KEY:
            // 秘钥
            path = this.getDownloadSecretKeyFilePath(id);
            name = Optional.ofNullable(path).map(Files1::getFileName).orElse(null);
            break;
        case TERMINAL_LOG:
            // terminal 日志
            path = this.getDownloadTerminalLogFilePath(id);
            name = Optional.ofNullable(path).map(Files1::getFileName).orElse(null);
            break;
        case EXEC_LOG:
            // 执行日志
            path = commandExecService.getExecLogFilePath(id);
            name = Optional.ofNullable(path).map(Files1::getFileName).orElse(null);
            break;
        case SFTP_DOWNLOAD:
            // sftp 下载文件
            FileTransferLogDO transferLog = sftpService.getDownloadFilePath(id);
            if (transferLog != null) {
                path = transferLog.getLocalFile();
                name = Files1.getFileName(transferLog.getRemoteFile());
            }
            break;
        case TAIL_LIST_FILE:
            // tail 列表文件
            FileTailListDO tailFile = fileTailListDAO.selectById(id);
            if (tailFile != null) {
                path = tailFile.getFilePath();
                name = Files1.getFileName(path);
                machineId = tailFile.getMachineId();
            }
            break;
        case APP_BUILD_LOG:
            // 应用构建日志
            path = applicationBuildService.getBuildLogPath(id);
            name = Optional.ofNullable(path).map(Files1::getFileName).orElse(null);
            break;
        case APP_BUILD_ACTION_LOG:
        case APP_RELEASE_ACTION_LOG:
            // 应用构建操作日志
            path = applicationActionLogService.getActionLogPath(id);
            name = Optional.ofNullable(path).map(Files1::getFileName).orElse(null);
            break;
        case APP_BUILD_BUNDLE:
            // 应用构建 产物文件
            path = applicationBuildService.getBuildBundlePath(id);
            // 如果是文件夹则获取压缩文件
            if (path != null && Files1.isDirectory(path)) {
                path += "." + Const.SUFFIX_ZIP;
            }
            name = Optional.ofNullable(path).map(Files1::getFileName).orElse(null);
            break;
        case APP_RELEASE_MACHINE_LOG:
            // 应用发布机器日志
            path = applicationReleaseMachineService.getReleaseMachineLogPath(id);
            name = Optional.ofNullable(path).map(Files1::getFileName).orElse(null);
            break;
        case SCHEDULER_TASK_MACHINE_LOG:
            // 调度任务机器日志
            path = schedulerTaskMachineRecordService.getTaskMachineLogPath(id);
            name = Optional.ofNullable(path).map(Files1::getFileName).orElse(null);
            break;
        default:
            break;
    }
    // 检查文件是否存在
    if (path == null || (type.isLocal() && !Files1.isFile(path))) {
        throw Exceptions.httpWrapper(HttpWrapper.of(ResultCode.FILE_MISSING));
    }
    // 设置缓存
    FileDownloadDTO download = new FileDownloadDTO();
    download.setFilePath(path);
    download.setFileName(Strings.def(name, Const.UNKNOWN));
    download.setUserId(Currents.getUserId());
    download.setType(type.getType());
    download.setMachineId(machineId);
    String token = UUIds.random19();
    String key = Strings.format(KeyConst.FILE_DOWNLOAD_TOKEN, token);
    redisTemplate.opsForValue().set(key, JSON.toJSONString(download), KeyConst.FILE_DOWNLOAD_EXPIRE, TimeUnit.SECONDS);
    return token;
}
Also used : FileTailListDO(com.orion.ops.entity.domain.FileTailListDO) FileTransferLogDO(com.orion.ops.entity.domain.FileTransferLogDO) Files1(com.orion.utils.io.Files1) FileDownloadDTO(com.orion.ops.entity.dto.FileDownloadDTO)

Aggregations

FileTailListDO (com.orion.ops.entity.domain.FileTailListDO)8 MachineInfoDO (com.orion.ops.entity.domain.MachineInfoDO)3 FileTailVO (com.orion.ops.entity.vo.FileTailVO)3 Date (java.util.Date)2 FileTransferLogDO (com.orion.ops.entity.domain.FileTransferLogDO)1 FileDownloadDTO (com.orion.ops.entity.dto.FileDownloadDTO)1 FileTailDTO (com.orion.ops.entity.dto.FileTailDTO)1 Files1 (com.orion.utils.io.Files1)1