|
|
@@ -5,15 +5,12 @@ import cn.reghao.autodop.dmaster.app.constant.BuildStage;
|
|
|
import cn.reghao.autodop.dmaster.app.constant.NotifierType;
|
|
|
import cn.reghao.autodop.dmaster.app.entity.config.NotifierConfig;
|
|
|
import cn.reghao.autodop.dmaster.app.entity.deploy.DeployConfig;
|
|
|
-import cn.reghao.autodop.dmaster.app.entity.log.BuildLog;
|
|
|
-import cn.reghao.autodop.dmaster.app.vo.log.BuildDeployAppVO;
|
|
|
-import cn.reghao.autodop.dmaster.app.entity.log.DeployLog;
|
|
|
+import cn.reghao.autodop.dmaster.app.entity.log.*;
|
|
|
import cn.reghao.autodop.dmaster.app.service.build.AppIntegrate;
|
|
|
import cn.reghao.autodop.dmaster.app.service.deploy.AppDeployer;
|
|
|
-import cn.reghao.autodop.dmaster.app.service.build.tools.repo.CommitLog;
|
|
|
import cn.reghao.autodop.dmaster.app.entity.config.orchestration.AppOrchestration;
|
|
|
-import cn.reghao.autodop.dmaster.app.repository.log.LogRepository;
|
|
|
-import cn.reghao.autodop.dmaster.app.service.log.LogConsumer;
|
|
|
+import cn.reghao.autodop.dmaster.app.service.log.BuildDeployLogService;
|
|
|
+import cn.reghao.autodop.dmaster.app.service.log.BuildDeployLogConsumer;
|
|
|
import cn.reghao.autodop.dmaster.common.exception.ExceptionUtil;
|
|
|
import cn.reghao.autodop.dmaster.common.thread.ThreadPoolWrapper;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
@@ -41,13 +38,13 @@ public class BuildDeployDispatcher {
|
|
|
private AppDeployer appDeployer;
|
|
|
|
|
|
private ExecutorService threadPool = ThreadPoolWrapper.threadPool("build-deploy");
|
|
|
- private LogConsumer logConsumer;
|
|
|
+ private BuildDeployLogConsumer buildDeployLogConsumer;
|
|
|
|
|
|
- public BuildDeployDispatcher(BuildDeployCache buildDeployCache, AppDeployer appDeployer, LogRepository logDAO) {
|
|
|
+ public BuildDeployDispatcher(BuildDeployCache buildDeployCache, AppDeployer appDeployer, BuildDeployLogService logDAO) {
|
|
|
this.cache = buildDeployCache;
|
|
|
this.appDeployer = appDeployer;
|
|
|
- this.logConsumer = new LogConsumer(logDAO);
|
|
|
- threadPool.submit(logConsumer);
|
|
|
+ this.buildDeployLogConsumer = new BuildDeployLogConsumer(logDAO);
|
|
|
+ threadPool.submit(buildDeployLogConsumer);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -57,7 +54,7 @@ public class BuildDeployDispatcher {
|
|
|
* @return
|
|
|
* @date 2021-02-06 上午1:46
|
|
|
*/
|
|
|
- public BuildDeployAppVO buildAndDeploy(String appId, boolean isDeploy) throws Exception {
|
|
|
+ public BuildDeployApp buildAndDeploy(String appId, boolean isDeploy) throws Exception {
|
|
|
if (!onBuilding.add(appId)) {
|
|
|
// TODO 应用正在构建中...
|
|
|
return null;
|
|
|
@@ -80,10 +77,11 @@ public class BuildDeployDispatcher {
|
|
|
BuildLog buildLog = buildPipeline(appIntegrate);
|
|
|
onBuilding.remove(appId);
|
|
|
if (buildLog.getStatusCode() == 0 && isDeploy) {
|
|
|
- DeployLog deployLog = deployApp(appId, buildLog.getCommitId(), buildLog.getPackagePath());
|
|
|
- return BuildDeployAppVO.fromDeployLog(deployLog);
|
|
|
+ DeployResult deployResult = deployApp(buildLog);
|
|
|
+ assert deployResult != null;
|
|
|
+ return BuildDeployApp.of(deployResult);
|
|
|
} else {
|
|
|
- return BuildDeployAppVO.fromBuildLog(buildLog);
|
|
|
+ return BuildDeployApp.of(buildLog);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -94,7 +92,8 @@ public class BuildDeployDispatcher {
|
|
|
*/
|
|
|
private BuildLog buildPipeline(AppIntegrate appIntegrate) {
|
|
|
BuildLog buildLog = new BuildLog();
|
|
|
- buildLog.setAppId(appIntegrate.appId());
|
|
|
+ buildLog.setAppId(appIntegrate.app().getAppId());
|
|
|
+ buildLog.setEnv(appIntegrate.app().getEnv());
|
|
|
|
|
|
long start = System.currentTimeMillis();
|
|
|
// TODO 只使用一个 try-catch
|
|
|
@@ -103,10 +102,10 @@ public class BuildDeployDispatcher {
|
|
|
buildLog.setUpdate(commitLog.isUpdate());
|
|
|
buildLog.setCommitId(commitLog.getCommitId());
|
|
|
buildLog.setUpdateTotalTime(System.currentTimeMillis()-start);
|
|
|
- logConsumer.addCommitLog(commitLog);
|
|
|
+ buildDeployLogConsumer.addCommitLog(commitLog);
|
|
|
} catch (Exception e) {
|
|
|
buildException(buildLog, BuildStage.update, e);
|
|
|
- logConsumer.addBuildLog(buildLog);
|
|
|
+ buildDeployLogConsumer.addBuildLog(buildLog);
|
|
|
return buildLog;
|
|
|
}
|
|
|
|
|
|
@@ -116,7 +115,7 @@ public class BuildDeployDispatcher {
|
|
|
buildLog.setCompileTotalTime(System.currentTimeMillis()-start);
|
|
|
} catch (Exception e) {
|
|
|
buildException(buildLog, BuildStage.compile, e);
|
|
|
- logConsumer.addBuildLog(buildLog);
|
|
|
+ buildDeployLogConsumer.addBuildLog(buildLog);
|
|
|
return buildLog;
|
|
|
}
|
|
|
|
|
|
@@ -127,14 +126,14 @@ public class BuildDeployDispatcher {
|
|
|
buildLog.setPackTotalTime(System.currentTimeMillis()-start);
|
|
|
} catch (Exception e) {
|
|
|
buildException(buildLog, BuildStage.pack, e);
|
|
|
- logConsumer.addBuildLog(buildLog);
|
|
|
+ buildDeployLogConsumer.addBuildLog(buildLog);
|
|
|
return buildLog;
|
|
|
}
|
|
|
|
|
|
buildLog.setStage(BuildStage.done);
|
|
|
buildLog.setStatusCode(0);
|
|
|
buildLog.setBuildTime(LocalDateTime.now());
|
|
|
- logConsumer.addBuildLog(buildLog);
|
|
|
+ buildDeployLogConsumer.addBuildLog(buildLog);
|
|
|
return buildLog;
|
|
|
}
|
|
|
|
|
|
@@ -152,26 +151,26 @@ public class BuildDeployDispatcher {
|
|
|
* @return
|
|
|
* @date 2021-02-06 上午2:02
|
|
|
*/
|
|
|
- private DeployLog deployApp(String appId, String commitId, String packagePath) {
|
|
|
- if (!onDeploying.add(appId)) {
|
|
|
+ private DeployResult deployApp(BuildLog buildLog) {
|
|
|
+ if (!onDeploying.add(buildLog.getAppId())) {
|
|
|
// TODO 应用正在部署中...
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
- List<DeployConfig> deployConfigs = cache.findByAppId(appId).getDeployConfigs();
|
|
|
- DeployLog deployLog = appDeployer.deploy(appId, commitId, packagePath, deployConfigs);
|
|
|
+ List<DeployConfig> deployConfigs = cache.findByAppId(buildLog.getAppId()).getDeployConfigs();
|
|
|
+ DeployResult deployResult = appDeployer.deploy(buildLog, deployConfigs);
|
|
|
// TODO 部署完成后发出通知
|
|
|
- onDeploying.remove(appId);
|
|
|
- logConsumer.addDeployLog(deployLog);
|
|
|
- return deployLog;
|
|
|
+ onDeploying.remove(buildLog.getAppId());
|
|
|
+ deployResult.getDeployLogs().forEach(deployLog -> buildDeployLogConsumer.addDeployLog(deployLog));
|
|
|
+ return deployResult;
|
|
|
}
|
|
|
|
|
|
- public BuildDeployAppVO deploy(String appId, String commitId) {
|
|
|
+ public BuildDeployApp deploy(String appId, String commitId) {
|
|
|
BuildLog buildLog = cache.findByAppIdAndCommitId(appId, commitId);
|
|
|
- String packagePath = buildLog.getPackagePath();
|
|
|
- DeployLog deployLog = deployApp(appId, commitId, packagePath);
|
|
|
- logConsumer.addDeployLog(deployLog);
|
|
|
- return BuildDeployAppVO.fromDeployLog(deployLog);
|
|
|
+ DeployResult deployResult = deployApp(buildLog);
|
|
|
+ assert deployResult != null;
|
|
|
+ deployResult.getDeployLogs().forEach(deployLog -> buildDeployLogConsumer.addDeployLog(deployLog));
|
|
|
+ return BuildDeployApp.of(deployResult);
|
|
|
}
|
|
|
|
|
|
public void deployNotify(NotifierConfig notifierConfig, DeployLog deployLog) {
|