use of com.ibeiliao.deployment.admin.websocket.request.ShellLogResponseMessage in project Corgi by kevinYin.
the class PushStepLogToClientThread method buildClientLogMessage.
private String buildClientLogMessage(List<String> stepLogs, List<String> serverDeployLogs) {
ShellLogResponseMessage responseMessage = new ShellLogResponseMessage();
responseMessage.setStepLogs(stepLogs);
responseMessage.setServerDeployLogs(serverDeployLogs);
responseMessage.setType(WebSocketRequestType.DEPLOY_STEP_LOG.getName());
responseMessage.setCode(LogType.MAIN_STEP_LOG.getType());
return JSON.toJSONString(responseMessage);
}
use of com.ibeiliao.deployment.admin.websocket.request.ShellLogResponseMessage in project Corgi by kevinYin.
the class SubscribeLogThread method run.
@Override
public void run() {
jedisPubSub = new JedisPubSub() {
@Override
public void onMessage(String channel, String message) {
logger.info("接收到通道:{} 发布的信息, message: {}", channel, message);
try {
// 向用户推送监控的发布服务器信息
List<ServerCollectLog> logList = JSONArray.parseArray(message, ServerCollectLog.class);
// 发布服务器对应的模块id map
Map<Integer, Integer> serverDeployId2ModuleIdMap = new HashMap<>();
for (ServerCollectLog log : logList) {
// Set<WebSocketSession> sessions = serverDeployRelates.get(log.getId());
Set<WebSocketSession> sessions = LogIdToSessionHolder.getInstance().get(log.getId());
if (CollectionUtils.isNotEmpty(sessions)) {
// 推送信息
ShellLogResponseMessage responseMessage = new ShellLogResponseMessage();
// responseMessage.setStepLogs(readStepLogs(serverDeployId2ModuleIdMap, log));
ShellLogResponseMessage.ServerShellLog shellLog = new ShellLogResponseMessage.ServerShellLog();
shellLog.setServerDeployId(log.getId());
shellLog.setLog(log.getContent());
List<ShellLogResponseMessage.ServerShellLog> shellLogList = new ArrayList<>();
shellLogList.add(shellLog);
responseMessage.setServerLogs(shellLogList);
responseMessage.setCode(ApiCode.SUCCESS);
responseMessage.setType(WebSocketRequestType.DEPLOY_SHELL_LOG.getName());
String messageStr = JSONObject.toJSONString(responseMessage);
// 向监听用户发送消息
for (WebSocketSession session : sessions) {
if (session.isOpen()) {
try {
session.sendMessage(new TextMessage(messageStr));
} catch (Exception e) {
logger.error("发送推送日志消息失败 | msg:{}", e.getMessage(), e);
}
}
}
}
}
// end for
} catch (Exception e) {
logger.error("处理订阅的日志更改信息失败 | msg:{}", e.getMessage(), e);
}
}
};
logger.info("订阅开始……");
redis.subscribe(jedisPubSub, RedisKey.getDeploySubscribeChannelKey());
logger.info("订阅结束 ...");
}
use of com.ibeiliao.deployment.admin.websocket.request.ShellLogResponseMessage 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