|
|
@@ -3,7 +3,6 @@ package cn.reghao.autodop.dmaster.app.service;
|
|
|
import cn.reghao.autodop.dmaster.app.cache.OrchestrationCache;
|
|
|
import cn.reghao.autodop.dmaster.app.constant.BuildStage;
|
|
|
import cn.reghao.autodop.dmaster.app.entity.deploy.DeployConfig;
|
|
|
-import cn.reghao.autodop.dmaster.app.entity.log.DeployResult;
|
|
|
import cn.reghao.autodop.dmaster.app.entity.log.BuildLog;
|
|
|
import cn.reghao.autodop.dmaster.app.entity.log.BuildResult;
|
|
|
import cn.reghao.autodop.dmaster.app.entity.log.DeployLog;
|
|
|
@@ -14,6 +13,7 @@ import cn.reghao.autodop.dmaster.app.entity.config.orchestration.AppOrchestratio
|
|
|
import cn.reghao.autodop.dmaster.app.repository.log.LogRepository;
|
|
|
import cn.reghao.autodop.dmaster.app.service.log.LogConsumer;
|
|
|
import cn.reghao.autodop.dmaster.common.exception.ExceptionUtil;
|
|
|
+import cn.reghao.autodop.dmaster.common.thread.ThreadPoolWrapper;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
@@ -37,12 +37,15 @@ public class BuildDeployDispatcher {
|
|
|
private Map<String, AppIntegrate> integrateMap = new ConcurrentHashMap<>();
|
|
|
private OrchestrationCache cache;
|
|
|
private AppDeployer appDeployer;
|
|
|
+
|
|
|
+ private ExecutorService threadPool = ThreadPoolWrapper.threadPool("build-deploy");
|
|
|
private LogConsumer logConsumer;
|
|
|
|
|
|
public BuildDeployDispatcher(OrchestrationCache orchestrationCache, AppDeployer appDeployer, LogRepository logDAO) {
|
|
|
this.cache = orchestrationCache;
|
|
|
this.appDeployer = appDeployer;
|
|
|
this.logConsumer = new LogConsumer(logDAO);
|
|
|
+ threadPool.submit(logConsumer);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -58,7 +61,7 @@ public class BuildDeployDispatcher {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
- // TODO AppOrchestration 修改后需要重新初始化 AppIntegrate
|
|
|
+ // TODO AppOrchestration 修改后需要重新初始化 AppIntegrate,尝试使用 AOP 来完成
|
|
|
AppIntegrate appIntegrate = integrateMap.get(appId);
|
|
|
if (appIntegrate == null) {
|
|
|
AppOrchestration app = cache.findByAppId(appId);
|
|
|
@@ -73,8 +76,8 @@ public class BuildDeployDispatcher {
|
|
|
|
|
|
// TODO 抛出异常时从 onBuilding 中移除当前应用
|
|
|
BuildLog buildLog = buildTask(appIntegrate);
|
|
|
- if (isDeploy) {
|
|
|
- deploy(buildLog.getAppId(), buildLog.getPackagePath());
|
|
|
+ if (buildLog.getStatusCode() == 0 && isDeploy) {
|
|
|
+ DeployLog deployLog = deploy(buildLog.getAppId(), buildLog.getPackagePath());
|
|
|
}
|
|
|
|
|
|
onBuilding.remove(appId);
|
|
|
@@ -91,6 +94,7 @@ public class BuildDeployDispatcher {
|
|
|
buildLog.setAppId(appIntegrate.appId());
|
|
|
|
|
|
long start = System.currentTimeMillis();
|
|
|
+ // TODO 只使用一个 try-catch
|
|
|
try {
|
|
|
CommitLog commitLog = appIntegrate.update();
|
|
|
buildLog.setUpdate(commitLog.isUpdate());
|
|
|
@@ -99,6 +103,7 @@ public class BuildDeployDispatcher {
|
|
|
logConsumer.addCommitLog(commitLog);
|
|
|
} catch (Exception e) {
|
|
|
buildException(buildLog, BuildStage.update, e);
|
|
|
+ logConsumer.addBuildLog(buildLog);
|
|
|
return buildLog;
|
|
|
}
|
|
|
|
|
|
@@ -108,6 +113,7 @@ public class BuildDeployDispatcher {
|
|
|
buildLog.setCompileTotalTime(System.currentTimeMillis()-start);
|
|
|
} catch (Exception e) {
|
|
|
buildException(buildLog, BuildStage.compile, e);
|
|
|
+ logConsumer.addBuildLog(buildLog);
|
|
|
return buildLog;
|
|
|
}
|
|
|
|
|
|
@@ -118,12 +124,14 @@ public class BuildDeployDispatcher {
|
|
|
buildLog.setPackTotalTime(System.currentTimeMillis()-start);
|
|
|
} catch (Exception e) {
|
|
|
buildException(buildLog, BuildStage.pack, e);
|
|
|
+ logConsumer.addBuildLog(buildLog);
|
|
|
return buildLog;
|
|
|
}
|
|
|
|
|
|
buildLog.setStage(BuildStage.done);
|
|
|
buildLog.setStatusCode(0);
|
|
|
buildLog.setBuildTime(LocalDateTime.now());
|
|
|
+ logConsumer.addBuildLog(buildLog);
|
|
|
return buildLog;
|
|
|
}
|
|
|
|
|
|
@@ -141,17 +149,21 @@ public class BuildDeployDispatcher {
|
|
|
* @return
|
|
|
* @date 2021-02-06 上午2:02
|
|
|
*/
|
|
|
- public DeployResult deploy(String appId, String packagePath) {
|
|
|
+ public DeployLog deploy(String appId, String packagePath) {
|
|
|
if (!onDeploying.add(appId)) {
|
|
|
// TODO 应用正在部署中...
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
DeployConfig deployConfig = cache.findByAppId(appId).getDeployConfig();
|
|
|
- List<DeployLog> deployLogs = appDeployer.deploy(appId, packagePath, deployConfig);
|
|
|
+ DeployLog deployLog = appDeployer.deploy(appId, packagePath, deployConfig);
|
|
|
// TODO 部署完成后发出通知
|
|
|
|
|
|
onDeploying.remove(appId);
|
|
|
- return null;
|
|
|
+ logConsumer.addDeployLog(deployLog);
|
|
|
+ return deployLog;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void deploy1(String appId, String commitId) {
|
|
|
}
|
|
|
}
|