Search in sources :

Example 16 with DeployHistory

use of com.ibeiliao.deployment.admin.vo.deploy.DeployHistory in project Corgi by kevinYin.

the class ProcessTimeoutTask method process.

/**
 * 每15分钟处理一次
 */
@Scheduled(cron = "0 */15 * * * ?")
public void process() {
    // lock 时间要超过5分钟,防止上一个任务没处理完,新的任务又来了
    // 1800 秒最多可以占 1800/5 次定时任务
    RedisLock redisLock = new RedisLock(redis, "deployment_timeout_task_check", 1800);
    if (redisLock.lock()) {
        logger.info("准备处理超时任务 ...");
        try {
            Date now = new Date();
            Date startTime = DateUtils.addSeconds(now, -Constants.DEPLOY_TASK_TIMEOUT * 3);
            Date endTime = DateUtils.addSeconds(now, -Constants.DEPLOY_TASK_TIMEOUT);
            final int MAX = 1000;
            logger.info("startTime: {}, endTime: {}", startTime, endTime);
            List<DeployHistory> list = deployHistoryService.queryUnfinished(startTime, endTime, MAX);
            if (list.size() > 0) {
                for (DeployHistory history : list) {
                    deployHistoryService.systemCancel(history.getHistoryId());
                }
                logger.info("处理超时任务数量: " + list.size());
            }
        } catch (Exception e) {
            logger.error("处理超时任务出错", e);
        } finally {
            redisLock.unlock();
        }
    } else {
        logger.info("抢锁失败,跳过 ......");
    }
}
Also used : RedisLock(com.ibeiliao.deployment.common.util.redis.RedisLock) DeployHistory(com.ibeiliao.deployment.admin.vo.deploy.DeployHistory) Date(java.util.Date) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Example 17 with DeployHistory

use of com.ibeiliao.deployment.admin.vo.deploy.DeployHistory in project Corgi by kevinYin.

the class DeployHistoryServiceImplTest method testCreateStopHistory.

/**
 * 测试 stop
 * 期望:测试通过
 */
@Test
public void testCreateStopHistory() {
    InitTestDataService.InitData data = initTestDataService.init();
    long accountId = data.account.getUid();
    int serverId = data.module.getServerGroups().get(0).getServers().get(0).getServerId();
    DeployHistory deployHistory = deployHistoryService.createStopHistory(accountId, serverId);
    validateStopRestart(data, deployHistory.getHistoryId(), serverId);
}
Also used : DeployHistory(com.ibeiliao.deployment.admin.vo.deploy.DeployHistory) ServerDeployHistory(com.ibeiliao.deployment.admin.vo.deploy.ServerDeployHistory) InitTestDataService(com.ibeiliao.deployment.admin.service.InitTestDataService) Test(org.junit.Test)

Example 18 with DeployHistory

use of com.ibeiliao.deployment.admin.vo.deploy.DeployHistory in project Corgi by kevinYin.

the class DeployHistoryServiceImplTest method testReject.

/**
 * 测试拒绝审核
 * 期望:测试通过
 */
@Test
public void testReject() {
    DeployHistory history = createDeployHistory();
    deployHistoryService.reject(history.getAccountId(), history.getHistoryId());
    DeployHistory newHistory = deployHistoryService.getByHistoryId(history.getHistoryId());
    assertTrue(newHistory.getDeployStatus() == DeployStatus.AUDIT_REJECTED.getValue());
}
Also used : DeployHistory(com.ibeiliao.deployment.admin.vo.deploy.DeployHistory) ServerDeployHistory(com.ibeiliao.deployment.admin.vo.deploy.ServerDeployHistory) Test(org.junit.Test)

Example 19 with DeployHistory

use of com.ibeiliao.deployment.admin.vo.deploy.DeployHistory in project Corgi by kevinYin.

the class DeployHistoryServiceImplTest method validateStopRestart.

private void validateStopRestart(InitTestDataService.InitData data, int historyId, int serverId) {
    DeployHistory tmp = deployHistoryService.getByHistoryId(historyId);
    assertTrue(tmp.getDeployStatus() == DeployStatus.WAITING_FOR_DEPLOYMENT.getValue());
    assertTrue(tmp.getIsRestart() == Constants.TRUE);
    assertTrue(tmp.getServerDeployHistories().size() == 1);
    assertTrue(tmp.getServerDeployHistories().get(0).getServerId() == serverId);
    assertTrue(tmp.getProjectId() == data.project.getProjectId());
    assertTrue(tmp.getModuleId() == data.module.getModuleId());
    assertTrue(tmp.getAccountId() == data.account.getUid());
    deployHistoryService.finishStopRestart(historyId, DeployResult.SUCCESS);
    DeployHistory tmp2 = deployHistoryService.getByHistoryId(historyId);
    assertTrue(tmp2.getDeployTime() != null);
    assertTrue(tmp2.getDeployStatus() == DeployStatus.DEPLOYED.getValue());
    assertTrue(tmp2.getResult() == DeployResult.SUCCESS.getValue());
    assertTrue(tmp2.getServerDeployHistories().get(0).getDeployStatus() == ServerDeployResult.SUCCESS.getValue());
}
Also used : DeployHistory(com.ibeiliao.deployment.admin.vo.deploy.DeployHistory) ServerDeployHistory(com.ibeiliao.deployment.admin.vo.deploy.ServerDeployHistory)

Example 20 with DeployHistory

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

DeployHistory (com.ibeiliao.deployment.admin.vo.deploy.DeployHistory)20 ServerDeployHistory (com.ibeiliao.deployment.admin.vo.deploy.ServerDeployHistory)14 Test (org.junit.Test)6 InitTestDataService (com.ibeiliao.deployment.admin.service.InitTestDataService)4 DeploymentOrder (com.ibeiliao.deployment.admin.vo.deploy.DeploymentOrder)3 ProjectEnv (com.ibeiliao.deployment.admin.vo.global.ProjectEnv)3 RestResult (com.ibeiliao.deployment.admin.common.RestResult)2 DeployHistoryPO (com.ibeiliao.deployment.admin.po.deploy.DeployHistoryPO)2 ServerDeployHistoryPO (com.ibeiliao.deployment.admin.po.deploy.ServerDeployHistoryPO)2 MenuResource (com.ibeiliao.deployment.admin.utils.resource.MenuResource)2 Date (java.util.Date)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 DeployHistoryService (com.ibeiliao.deployment.admin.service.deploy.DeployHistoryService)1 AdminAccount (com.ibeiliao.deployment.admin.vo.account.AdminAccount)1 ProjectModule (com.ibeiliao.deployment.admin.vo.project.ProjectModule)1 Server (com.ibeiliao.deployment.admin.vo.server.Server)1 ServerGroup (com.ibeiliao.deployment.admin.vo.server.ServerGroup)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