Search in sources :

Example 1 with MachineTerminalVO

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

the class MachineTerminalServiceImpl method getAccessConfig.

@Override
public TerminalAccessVO getAccessConfig(Long machineId) {
    // 获取机器信息
    MachineInfoDO machine = machineInfoService.selectById(machineId);
    Valid.notNull(machine, MessageConst.INVALID_MACHINE);
    if (!Const.ENABLE.equals(machine.getMachineStatus())) {
        throw Exceptions.codeArgument(HttpWrapper.HTTP_ERROR_CODE, MessageConst.MACHINE_NOT_ENABLE);
    }
    // 设置accessToken
    Long userId = Currents.getUserId();
    String token = ValueMix.base62ecbEnc(userId + "_" + System.currentTimeMillis(), TerminalConst.TERMINAL);
    // 获取终端配置
    MachineTerminalVO config = this.getMachineConfig(machineId);
    // 设置数据
    TerminalAccessVO access = new TerminalAccessVO();
    access.setId(config.getId());
    access.setAccessToken(token);
    access.setHost(machine.getMachineHost());
    access.setPort(machine.getSshPort());
    access.setMachineName(machine.getMachineName());
    access.setMachineId(machineId);
    access.setUsername(machine.getUsername());
    access.setTerminalType(config.getTerminalType());
    access.setBackgroundColor(config.getBackgroundColor());
    access.setFontSize(config.getFontSize());
    access.setFontFamily(config.getFontFamily());
    access.setFontColor(config.getFontColor());
    access.setEnableWebLink(config.getEnableWebLink());
    access.setEnableWebGL(config.getEnableWebGL());
    // 设置缓存
    String cacheKey = Strings.format(KeyConst.TERMINAL_ACCESS_TOKEN, token);
    redisTemplate.opsForValue().set(cacheKey, machineId + Strings.EMPTY, KeyConst.TERMINAL_ACCESS_TOKEN_EXPIRE, TimeUnit.SECONDS);
    log.info("用户获取terminal uid: {} machineId: {} token: {}", userId, machineId, token);
    // 设置日志参数
    EventParamsHolder.addParam(EventKeys.MACHINE_NAME, machine.getMachineName());
    return access;
}
Also used : MachineTerminalVO(com.orion.ops.entity.vo.MachineTerminalVO) TerminalAccessVO(com.orion.ops.entity.vo.TerminalAccessVO) MachineInfoDO(com.orion.ops.entity.domain.MachineInfoDO)

Aggregations

MachineInfoDO (com.orion.ops.entity.domain.MachineInfoDO)1 MachineTerminalVO (com.orion.ops.entity.vo.MachineTerminalVO)1 TerminalAccessVO (com.orion.ops.entity.vo.TerminalAccessVO)1