|
|
@@ -3,14 +3,23 @@ package cn.reghao.autodop.dmaster.utils.dispatcher;
|
|
|
import cn.reghao.autodop.common.dagent.app.api.data.AppStatus;
|
|
|
import cn.reghao.autodop.common.dagent.app.api.data.DeployResult;
|
|
|
import cn.reghao.autodop.common.message.AppOps;
|
|
|
-import cn.reghao.autodop.common.message.CallResult;
|
|
|
import cn.reghao.autodop.common.result.ResultStatus;
|
|
|
import cn.reghao.autodop.common.utils.serializer.JsonConverter;
|
|
|
-import com.google.gson.reflect.TypeToken;
|
|
|
+import cn.reghao.autodop.dmaster.app.cache.BuildDeployCache;
|
|
|
+import cn.reghao.autodop.dmaster.app.entity.config.AppOrchestration;
|
|
|
+import cn.reghao.autodop.dmaster.app.entity.config.NotifyReceiver;
|
|
|
+import cn.reghao.autodop.dmaster.app.entity.log.BuildLog;
|
|
|
+import cn.reghao.autodop.dmaster.app.entity.log.DeployLog;
|
|
|
+import cn.reghao.autodop.dmaster.app.repository.log.BuildLogRepository;
|
|
|
+import cn.reghao.autodop.dmaster.app.repository.log.DeployLogRepository;
|
|
|
+import cn.reghao.autodop.dmaster.app.service.bd.DeployNotifyMsg;
|
|
|
+import cn.reghao.autodop.dmaster.utils.notifier.DingMsg;
|
|
|
+import cn.reghao.autodop.dmaster.utils.notifier.NotifyService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
-import java.lang.reflect.Type;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Optional;
|
|
|
|
|
|
/**
|
|
|
* 分发对 App 的操作
|
|
|
@@ -21,16 +30,42 @@ import java.lang.reflect.Type;
|
|
|
@Slf4j
|
|
|
@Component
|
|
|
public class AppOpsDispatcher {
|
|
|
+ private BuildLogRepository buildLogRepository;
|
|
|
+ private DeployLogRepository deployLogRepository;
|
|
|
+ private BuildDeployCache cache;
|
|
|
+ private NotifyService notifyService;
|
|
|
+
|
|
|
+ public AppOpsDispatcher(BuildLogRepository buildLogRepository,
|
|
|
+ DeployLogRepository deployLogRepository,
|
|
|
+ BuildDeployCache cache,
|
|
|
+ NotifyService notifyService) {
|
|
|
+ this.buildLogRepository = buildLogRepository;
|
|
|
+ this.deployLogRepository = deployLogRepository;
|
|
|
+ this.cache = cache;
|
|
|
+ this.notifyService = notifyService;
|
|
|
+ }
|
|
|
+
|
|
|
public void dispatch(String ops, String payload) {
|
|
|
switch (AppOps.valueOf(ops)) {
|
|
|
case appDeployResult:
|
|
|
DeployResult deployResult = JsonConverter.jsonToObject(payload, DeployResult.class);
|
|
|
+ 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();
|
|
|
+ AppOrchestration app = cache.findByAppId(buildLog.getAppId());
|
|
|
+ DingMsg dingMsg = new DeployNotifyMsg(buildLog, deployResult).dingMsg();
|
|
|
+ List<NotifyReceiver> notifyReceivers = app.getNotifyReceivers();
|
|
|
+ notifyReceivers.forEach(notifyReceiver -> notifyService.notify(notifyReceiver, dingMsg));
|
|
|
+ log.info("应用 {} 部署成功...", buildLog.getAppId());
|
|
|
+ }
|
|
|
+
|
|
|
if (deployResult.getResult().getCode() == ResultStatus.SUCCESS.getCode()) {
|
|
|
AppStatus appStatus = deployResult.getAppStatus();
|
|
|
- log.info("应用 {} 部署成功...", appStatus.getAppId());
|
|
|
- //BuildDeployNotifyMsg msg = BuildDeployNotifyMsg.deployNotifyMsg(null);
|
|
|
- } else {
|
|
|
- log.info("应用部署失败...");
|
|
|
}
|
|
|
break;
|
|
|
case appStatusResult:
|