Search in sources :

Example 1 with ShellLogResponseMessage

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);
}
Also used : ShellLogResponseMessage(com.ibeiliao.deployment.admin.websocket.request.ShellLogResponseMessage)

Example 2 with ShellLogResponseMessage

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("订阅结束 ...");
}
Also used : ServerCollectLog(com.ibeiliao.deployment.common.vo.ServerCollectLog) JedisPubSub(redis.clients.jedis.JedisPubSub) ShellLogResponseMessage(com.ibeiliao.deployment.admin.websocket.request.ShellLogResponseMessage) WebSocketSession(org.springframework.web.socket.WebSocketSession) TextMessage(org.springframework.web.socket.TextMessage)

Example 3 with ShellLogResponseMessage

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));
            }
        }
    }
}
Also used : ShellLogRequestMessage(com.ibeiliao.deployment.admin.websocket.request.ShellLogRequestMessage) DeployHistoryService(com.ibeiliao.deployment.admin.service.deploy.DeployHistoryService) Redis(com.ibeiliao.deployment.common.util.redis.Redis) IOException(java.io.IOException) DeployHistory(com.ibeiliao.deployment.admin.vo.deploy.DeployHistory) ShellLogResponseMessage(com.ibeiliao.deployment.admin.websocket.request.ShellLogResponseMessage) TextMessage(org.springframework.web.socket.TextMessage)

Aggregations

ShellLogResponseMessage (com.ibeiliao.deployment.admin.websocket.request.ShellLogResponseMessage)3 TextMessage (org.springframework.web.socket.TextMessage)2 DeployHistoryService (com.ibeiliao.deployment.admin.service.deploy.DeployHistoryService)1 DeployHistory (com.ibeiliao.deployment.admin.vo.deploy.DeployHistory)1 ShellLogRequestMessage (com.ibeiliao.deployment.admin.websocket.request.ShellLogRequestMessage)1 Redis (com.ibeiliao.deployment.common.util.redis.Redis)1 ServerCollectLog (com.ibeiliao.deployment.common.vo.ServerCollectLog)1 IOException (java.io.IOException)1 WebSocketSession (org.springframework.web.socket.WebSocketSession)1 JedisPubSub (redis.clients.jedis.JedisPubSub)1