use of com.ibeiliao.deployment.admin.websocket.request.ShellLogRequestMessage in project Corgi by kevinYin.
the class LogMessageProcessor method process.
@Override
public void process(WebSocketSession webSocketSession, String message) {
ShellLogRequestMessage request = JSONObject.parseObject(message, ShellLogRequestMessage.class);
if (request != null && !CollectionUtils.isEmpty(request.getServerDeployIdList())) {
if (hasPermission(webSocketSession, request)) {
List<Integer> ids = request.getServerDeployIdList();
logger.info("处理读取日志的消息, ids: " + JSON.toJSONString(ids));
// 保存链接的session, 监控的服务器发布id 采用并集模式
Set<Integer> allIds = mergeId(webSocketSession, request);
ShellLogResponseMessage responseMessage = new ShellLogResponseMessage();
DeployHistoryService deployHistoryService = SpringContextUtil.getBean(DeployHistoryService.class);
Redis redis = SpringContextUtil.getBean(Redis.class);
// 获取模块完成的发布步骤
DeployHistory deployHistory = deployHistoryService.getByServerDeployHistoryId(ids.get(0));
if (deployHistory != null) {
String stepLogKey = RedisKey.getProjectHistoryLogKey(deployHistory.getHistoryId());
Long stepCount = redis.llen(stepLogKey);
if (stepCount != null && stepCount > 0) {
responseMessage.setStepLogs(redis.lrange(stepLogKey, 0, stepCount));
}
// 一次性读取历史记录至客户端
List<ShellLogResponseMessage.ServerShellLog> shellLogList = readLogs(request);
responseMessage.setCode(ApiCode.SUCCESS);
responseMessage.setType(WebSocketRequestType.DEPLOY_SHELL_LOG.getName());
responseMessage.setServerLogs(shellLogList);
try {
webSocketSession.sendMessage(new TextMessage(JSONObject.toJSONString(responseMessage)));
} catch (IOException e) {
logger.error("发送消息失败", e);
}
LogSessionHolder.getInstance().save(webSocketSession, allIds);
logger.info("日志处理完毕 ...");
} else {
logger.info("错误的ID: " + ids.get(0));
}
}
}
}
Aggregations