Search in sources :

Example 1 with MachineInfoDO

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

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

the class MachineInfoServiceImpl method updateStatus.

@Override
@Transactional(rollbackFor = Exception.class)
public Integer updateStatus(List<Long> idList, Integer status) {
    int effect = 0;
    for (Long id : idList) {
        MachineInfoDO entity = new MachineInfoDO();
        entity.setId(id);
        entity.setMachineStatus(status);
        entity.setUpdateTime(new Date());
        effect += machineInfoDAO.updateById(entity);
    }
    // 设置日志参数
    EventParamsHolder.addParam(EventKeys.ID_LIST, idList);
    EventParamsHolder.addParam(EventKeys.COUNT, effect);
    EventParamsHolder.addParam(EventKeys.OPERATOR, Const.ENABLE.equals(status) ? Const.ENABLE_LABEL : Const.DISABLE_LABEL);
    return effect;
}
Also used : MachineInfoDO(com.orion.ops.entity.domain.MachineInfoDO) Date(java.util.Date) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with MachineInfoDO

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

the class HostMachineInitialize method initMachine.

/**
 * 初始化宿主机
 */
private void initMachine() {
    LambdaQueryWrapper<MachineInfoDO> wrapper = new LambdaQueryWrapper<MachineInfoDO>().eq(MachineInfoDO::getId, Const.HOST_MACHINE_ID);
    MachineInfoDO machineInfo = machineInfoDAO.selectOne(wrapper);
    if (machineInfo == null) {
        // 插入机器
        MachineInfoDO insert = new MachineInfoDO();
        insert.setMachineName(Systems.HOST_NAME);
        insert.setMachineTag(Const.HOST_MACHINE_TAG);
        insert.setMachineHost(IPs.IP);
        insert.setSshPort(22);
        insert.setDescription("宿主机");
        insert.setUsername(Systems.USER_NAME);
        insert.setAuthType(MachineAuthType.PASSWORD.getType());
        insert.setMachineStatus(Const.ENABLE);
        machineInfoDAO.insert(insert);
        machineInfoDAO.setId(insert.getId(), Const.HOST_MACHINE_ID);
        log.info("宿主机已初始化");
        // 初始化环境变量
        machineEnvService.initEnv(Const.HOST_MACHINE_ID);
    }
}
Also used : MachineInfoDO(com.orion.ops.entity.domain.MachineInfoDO)

Example 4 with MachineInfoDO

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

the class MachineInfoServiceImpl method copyMachine.

@Override
public Long copyMachine(Long id) {
    MachineInfoDO machine = machineInfoDAO.selectById(id);
    Valid.notNull(machine, MessageConst.INVALID_MACHINE);
    String sourceMachineName = machine.getMachineName();
    String targetMachineName = sourceMachineName + Utils.getCopySuffix();
    machine.setId(null);
    machine.setCreateTime(null);
    machine.setUpdateTime(null);
    machine.setMachineName(targetMachineName);
    machineInfoDAO.insert(machine);
    Long insertId = machine.getId();
    // 复制环境变量
    LambdaQueryWrapper<MachineEnvDO> wrapper = new LambdaQueryWrapper<MachineEnvDO>().eq(MachineEnvDO::getMachineId, id).orderByAsc(MachineEnvDO::getUpdateTime);
    machineEnvDAO.selectList(wrapper).forEach(e -> {
        // 插入环境变量
        e.setMachineId(insertId);
        e.setCreateTime(null);
        e.setUpdateTime(null);
        machineEnvDAO.insert(e);
        // 插入历史值
        historyValueService.addHistory(e.getId(), HistoryValueType.MACHINE_ENV, HistoryOperator.ADD, null, e.getAttrValue());
    });
    // 设置日志参数
    EventParamsHolder.addParam(EventKeys.ID, id);
    EventParamsHolder.addParam(EventKeys.SOURCE, sourceMachineName);
    EventParamsHolder.addParam(EventKeys.TARGET, targetMachineName);
    return insertId;
}
Also used : MachineInfoDO(com.orion.ops.entity.domain.MachineInfoDO) MachineEnvDO(com.orion.ops.entity.domain.MachineEnvDO) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)

Example 5 with MachineInfoDO

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

the class MachineTerminalServiceImpl method updateSetting.

@Override
public Integer updateSetting(MachineTerminalRequest request) {
    // 查询配置
    Long id = request.getId();
    MachineTerminalDO beforeConfig = machineTerminalDAO.selectById(id);
    Valid.notNull(beforeConfig, MessageConst.UNKNOWN_DATA);
    // 查询机器信息
    MachineInfoDO machineInfo = machineInfoService.selectById(beforeConfig.getMachineId());
    Valid.notNull(machineInfo, MessageConst.UNKNOWN_DATA);
    // 设置修改信息
    MachineTerminalDO update = new MachineTerminalDO();
    update.setId(id);
    update.setTerminalType(request.getTerminalType());
    update.setFontSize(request.getFontSize());
    update.setFontFamily(request.getFontFamily());
    update.setFontColor(request.getFontColor());
    update.setBackgroundColor(request.getBackgroundColor());
    update.setUpdateTime(new Date());
    update.setEnableWebLink(request.getEnableWebLink());
    update.setEnableWebGL(request.getEnableWebGL());
    // 修改
    int effect = machineTerminalDAO.updateById(update);
    // 设置日志参数
    EventParamsHolder.addParams(request);
    EventParamsHolder.addParam(EventKeys.NAME, machineInfo.getMachineName());
    return effect;
}
Also used : MachineTerminalDO(com.orion.ops.entity.domain.MachineTerminalDO) MachineInfoDO(com.orion.ops.entity.domain.MachineInfoDO) Date(java.util.Date)

Aggregations

MachineInfoDO (com.orion.ops.entity.domain.MachineInfoDO)16 Transactional (org.springframework.transaction.annotation.Transactional)4 FileTailListDO (com.orion.ops.entity.domain.FileTailListDO)3 FileTailVO (com.orion.ops.entity.vo.FileTailVO)3 LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)2 MachineEnvDO (com.orion.ops.entity.domain.MachineEnvDO)2 UserDTO (com.orion.ops.entity.dto.UserDTO)2 Date (java.util.Date)2 ApplicationMachineDO (com.orion.ops.entity.domain.ApplicationMachineDO)1 CommandExecDO (com.orion.ops.entity.domain.CommandExecDO)1 MachineTerminalDO (com.orion.ops.entity.domain.MachineTerminalDO)1 FileTailDTO (com.orion.ops.entity.dto.FileTailDTO)1 TerminalConnectDTO (com.orion.ops.entity.dto.TerminalConnectDTO)1 MachineInfoVO (com.orion.ops.entity.vo.MachineInfoVO)1 MachineTerminalVO (com.orion.ops.entity.vo.MachineTerminalVO)1 TerminalAccessVO (com.orion.ops.entity.vo.TerminalAccessVO)1 CommandTaskSubmitVO (com.orion.ops.entity.vo.sftp.CommandTaskSubmitVO)1 ApplicationMachineService (com.orion.ops.service.api.ApplicationMachineService)1 SessionStore (com.orion.remote.channel.SessionStore)1 IOException (java.io.IOException)1