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("抢锁失败,跳过 ......");
}
}
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);
}
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());
}
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());
}
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));
}
}
}
}
Aggregations