|
|
@@ -1,117 +1,49 @@
|
|
|
package cn.reghao.autodop.dmaster.mqttsub.impl.rpcresult;
|
|
|
|
|
|
-import cn.reghao.autodop.common.http.DefaultWebRequest;
|
|
|
-import cn.reghao.autodop.common.http.WebRequest;
|
|
|
import cn.reghao.autodop.common.msg.rpc.dto.app.StatusResult;
|
|
|
import cn.reghao.autodop.common.msg.rpc.dto.app.DeployResult;
|
|
|
-import cn.reghao.autodop.dmaster.app.db.crud.AppDeployingCrud;
|
|
|
-import cn.reghao.autodop.dmaster.app.db.crud.AppRunningCrud;
|
|
|
-import cn.reghao.autodop.dmaster.app.db.query.AppDeployingQuery;
|
|
|
-import cn.reghao.autodop.dmaster.app.db.query.AppRunningQuery;
|
|
|
-import cn.reghao.autodop.dmaster.app.db.query.config.AppConfigQuery;
|
|
|
-import cn.reghao.autodop.dmaster.app.db.repository.log.BuildLogRepository;
|
|
|
-import cn.reghao.autodop.dmaster.app.db.repository.log.DeployLogRepository;
|
|
|
-import cn.reghao.autodop.dmaster.app.model.po.AppDeploying;
|
|
|
-import cn.reghao.autodop.dmaster.app.model.po.AppRunning;
|
|
|
-import cn.reghao.autodop.dmaster.app.model.po.config.AppConfig;
|
|
|
-import cn.reghao.autodop.dmaster.app.model.po.log.BuildLog;
|
|
|
-import cn.reghao.autodop.dmaster.app.model.po.log.DeployLog;
|
|
|
-import cn.reghao.autodop.dmaster.app.service.bd.DeployNotifyMsg;
|
|
|
-import cn.reghao.autodop.dmaster.notification.model.po.NotifyGroup;
|
|
|
-import cn.reghao.autodop.dmaster.notification.model.po.NotifyType;
|
|
|
-import cn.reghao.autodop.dmaster.notification.service.NotifyService;
|
|
|
-import cn.reghao.autodop.dmaster.notification.service.notifier.ding.DingMsg;
|
|
|
+import cn.reghao.autodop.dmaster.app.db.crud.log.DeployLogCrud;
|
|
|
+import cn.reghao.autodop.dmaster.app.service.config.AppDeployingService;
|
|
|
+import cn.reghao.autodop.dmaster.app.service.config.AppRunningService;
|
|
|
+import cn.reghao.jdkutil.result.Result;
|
|
|
+import cn.reghao.jdkutil.result.ResultStatus;
|
|
|
+import cn.reghao.jdkutil.serializer.JsonConverter;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.util.List;
|
|
|
-import java.util.Optional;
|
|
|
-
|
|
|
/**
|
|
|
* @author reghao
|
|
|
* @date 2021-07-01 20:15:57
|
|
|
*/
|
|
|
+@Slf4j
|
|
|
@Service
|
|
|
public class AppRpcClazzResultImpl {
|
|
|
- private AppRunningQuery appRunningQuery;
|
|
|
- private AppRunningCrud appRunningCrud;
|
|
|
- private NotifyService notifyService;
|
|
|
- private WebRequest webRequest;
|
|
|
- private BuildLogRepository buildLogRepository;
|
|
|
- private DeployLogRepository deployLogRepository;
|
|
|
- private AppConfigQuery appConfigQuery;
|
|
|
- private AppDeployingQuery appDeployingQuery;
|
|
|
- private AppDeployingCrud appDeployingCrud;
|
|
|
+ private DeployLogCrud deployLogCrud;
|
|
|
+ private AppDeployingService deployingService;
|
|
|
+ private final AppRunningService runningService;
|
|
|
|
|
|
- public AppRpcClazzResultImpl(AppRunningQuery appRunningQuery, AppRunningCrud appRunningCrud,
|
|
|
- NotifyService notifyService,
|
|
|
- BuildLogRepository buildLogRepository,
|
|
|
- DeployLogRepository deployLogRepository,
|
|
|
- AppConfigQuery appConfigQuery, AppDeployingQuery appDeployingQuery,
|
|
|
- AppDeployingCrud appDeployingCrud) {
|
|
|
- this.appRunningQuery = appRunningQuery;
|
|
|
- this.appRunningCrud = appRunningCrud;
|
|
|
- this.notifyService = notifyService;
|
|
|
- this.webRequest = new DefaultWebRequest();
|
|
|
- this.buildLogRepository = buildLogRepository;
|
|
|
- this.deployLogRepository = deployLogRepository;
|
|
|
- this.appConfigQuery = appConfigQuery;
|
|
|
- this.appDeployingQuery = appDeployingQuery;
|
|
|
- this.appDeployingCrud = appDeployingCrud;
|
|
|
+ public AppRpcClazzResultImpl(AppDeployingService deployingService, AppRunningService runningService) {
|
|
|
+ this.deployingService = deployingService;
|
|
|
+ this.runningService = runningService;
|
|
|
}
|
|
|
|
|
|
public void deployResult(DeployResult deployResult) {
|
|
|
- DeployLog deployLog = DeployLog.from(deployResult);
|
|
|
- deployLogRepository.save(deployLog);
|
|
|
-
|
|
|
- String buildId = deployResult.getBuildLogId();
|
|
|
- // TODO 部署时将 BuildLog 放到缓存中
|
|
|
- Optional<BuildLog> optional = buildLogRepository.findById(buildId);
|
|
|
- if (optional.isPresent()) {
|
|
|
- BuildLog buildLog = optional.get();
|
|
|
- updateDeployingStatus(buildLog, deployResult);
|
|
|
- updateRunningStatus(buildLog, deployResult);
|
|
|
- deployNotify(buildLog, deployResult);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private void updateDeployingStatus(BuildLog buildLog, DeployResult deployResult) {
|
|
|
- String appId = buildLog.getAppId();
|
|
|
- String machineId = deployResult.getMachineId();
|
|
|
- AppDeploying deploying = appDeployingQuery.findByAppIdAndMachineId(appId, machineId);
|
|
|
- if (deploying != null) {
|
|
|
- deploying.update(buildLog, deployResult);
|
|
|
- appDeployingCrud.update(deploying);
|
|
|
+ Result result = deployResult.getResult();
|
|
|
+ int code = result.getCode();
|
|
|
+ String msg = result.getMsg();
|
|
|
+ if (code != ResultStatus.SUCCESS.getCode()) {
|
|
|
+ log.error("msg -> {}", msg);
|
|
|
+ return;
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- private void updateRunningStatus(BuildLog buildLog, DeployResult deployResult) {
|
|
|
- String appId = buildLog.getAppId();
|
|
|
- String machineId = deployResult.getMachineId();
|
|
|
- AppRunning running = appRunningQuery.findByAppIdAndMachineId(appId, machineId);
|
|
|
- }
|
|
|
|
|
|
- private void deployNotify(BuildLog buildLog, DeployResult deployResult) {
|
|
|
- AppConfig app = appConfigQuery.findByAppId(buildLog.getAppId());
|
|
|
- List<NotifyGroup> notifyGroups = app.getNotifyGroups();
|
|
|
- notifyGroups.forEach(notifyGroup -> {
|
|
|
- String notifyType = notifyGroup.getNotifyType();
|
|
|
- switch (NotifyType.valueOf(notifyType)) {
|
|
|
- case ding:
|
|
|
- DingMsg dingMsg = new DeployNotifyMsg(buildLog, deployResult).dingMsg();
|
|
|
- notifyService.notify(notifyGroup, dingMsg);
|
|
|
- break;
|
|
|
- case email:
|
|
|
- break;
|
|
|
- case sms:
|
|
|
- break;
|
|
|
- default:
|
|
|
- }
|
|
|
- });
|
|
|
+ // 1.添加 DeployLog
|
|
|
+ // 2.更新 AppDeploying
|
|
|
+ // 3.更新 AppRunning
|
|
|
+ // 4.发送部署通知
|
|
|
+ StatusResult statusResult = JsonConverter.jsonToObject(msg, StatusResult.class);
|
|
|
}
|
|
|
|
|
|
- public void statusResult(StatusResult appStatus) {
|
|
|
- String appId = appStatus.getAppId();
|
|
|
- String machineId = appStatus.getMachineId();
|
|
|
- AppRunning appRunning = appRunningQuery.findByAppIdAndMachineId(appId, machineId);
|
|
|
+ public void statusResult(StatusResult statusResult) {
|
|
|
+ runningService.refresh(statusResult);
|
|
|
}
|
|
|
}
|