Search in sources :

Example 1 with DeployHistoryService

use of com.ibeiliao.deployment.admin.service.deploy.DeployHistoryService in project Corgi by kevinYin.

the class LogMessageProcessor method hasPermission.

private boolean hasPermission(WebSocketSession webSocketSession, ShellLogRequestMessage message) {
    List<Integer> ids = message.getServerDeployIdList();
    if (CollectionUtils.isEmpty(ids)) {
        return false;
    }
    DeployHistoryService deployHistoryService = SpringContextUtil.getBean(DeployHistoryService.class);
    List<Project> projects = deployHistoryService.getProjectByServerDeployIds(ids);
    if (CollectionUtils.isEmpty(projects)) {
        logger.error("要读取的数据不属于任何project");
    }
    if (projects.size() != 1) {
        logger.error("不能同时读取多个项目的日志, size: " + projects.size());
    }
    logger.info("读取log, ids=" + JSON.toJSONString(ids));
    AdminLoginUser adminLoginUser = UserIdentitySessionHolder.getInstance().getSessionValue(webSocketSession);
    if (adminLoginUser == null) {
        logger.error("找不到登录用户的信息, session: " + webSocketSession.getId());
        return false;
    }
    long accountId = adminLoginUser.getAccountId();
    ProjectAccountRelationService projectAccountRelationService = SpringContextUtil.getBean(ProjectAccountRelationService.class);
    for (Project p : projects) {
        if (!projectAccountRelationService.hasRelation(accountId, p.getProjectId())) {
            logger.error("用户:{} 没有项目:{} 的权限", accountId, p.getProjectId());
        // return false;
        }
    }
    return true;
}
Also used : Project(com.ibeiliao.deployment.admin.vo.project.Project) AdminLoginUser(com.ibeiliao.deployment.admin.context.AdminLoginUser) DeployHistoryService(com.ibeiliao.deployment.admin.service.deploy.DeployHistoryService) ProjectAccountRelationService(com.ibeiliao.deployment.admin.service.project.ProjectAccountRelationService)

Example 2 with DeployHistoryService

use of com.ibeiliao.deployment.admin.service.deploy.DeployHistoryService 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

DeployHistoryService (com.ibeiliao.deployment.admin.service.deploy.DeployHistoryService)2 AdminLoginUser (com.ibeiliao.deployment.admin.context.AdminLoginUser)1 ProjectAccountRelationService (com.ibeiliao.deployment.admin.service.project.ProjectAccountRelationService)1 DeployHistory (com.ibeiliao.deployment.admin.vo.deploy.DeployHistory)1 Project (com.ibeiliao.deployment.admin.vo.project.Project)1 ShellLogRequestMessage (com.ibeiliao.deployment.admin.websocket.request.ShellLogRequestMessage)1 ShellLogResponseMessage (com.ibeiliao.deployment.admin.websocket.request.ShellLogResponseMessage)1 Redis (com.ibeiliao.deployment.common.util.redis.Redis)1 IOException (java.io.IOException)1 TextMessage (org.springframework.web.socket.TextMessage)1