|
|
@@ -1,18 +1,17 @@
|
|
|
package cn.reghao.autodop.dmaster.app.service.build;
|
|
|
|
|
|
-import cn.reghao.autodop.common.config.BuildDeployResult;
|
|
|
-import cn.reghao.autodop.common.utils.JsonUtil;
|
|
|
import cn.reghao.autodop.dmaster.app.caching.OrchestrationCaching;
|
|
|
import cn.reghao.autodop.dmaster.app.entity.build.AppBuild;
|
|
|
+import cn.reghao.autodop.dmaster.app.entity.log.BuildResult;
|
|
|
import cn.reghao.autodop.dmaster.app.entity.orchestration.AppOrchestration;
|
|
|
import cn.reghao.autodop.dmaster.app.entity.orchestration.ProjOrchestration;
|
|
|
+import cn.reghao.autodop.dmaster.app.repository.log.CommitInfoRepository;
|
|
|
import cn.reghao.autodop.dmaster.app.thread.ThreadPoolWrapper;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.*;
|
|
|
-import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 应用构建分发
|
|
|
@@ -25,9 +24,11 @@ import java.util.stream.Collectors;
|
|
|
public class BuildDispatcher {
|
|
|
private final String STANDALONE_APP = "standaloneApp";
|
|
|
private OrchestrationCaching caching;
|
|
|
+ private CommitInfoRepository commitInfoRepository;
|
|
|
|
|
|
- public BuildDispatcher(OrchestrationCaching caching) {
|
|
|
+ public BuildDispatcher(OrchestrationCaching caching, CommitInfoRepository commitInfoRepository) {
|
|
|
this.caching = caching;
|
|
|
+ this.commitInfoRepository = commitInfoRepository;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -37,8 +38,8 @@ public class BuildDispatcher {
|
|
|
* @return
|
|
|
* @date 2019-11-12 上午9:48
|
|
|
*/
|
|
|
- public List<BuildDeployResult> dispatch(Set<String> appIds, boolean isDeploy) throws Exception {
|
|
|
- List<BuildDeployResult> results = new ArrayList<>();
|
|
|
+ public List<BuildResult> dispatch(Set<String> appIds, boolean isDeploy) throws Exception {
|
|
|
+ List<BuildResult> results = new ArrayList<>();
|
|
|
List<AppOrchestration> existApps = new ArrayList<>();
|
|
|
// 分离出存在的应用和不存在的应用
|
|
|
if (appIds.remove("all")) {
|
|
|
@@ -49,15 +50,19 @@ public class BuildDispatcher {
|
|
|
if (app != null) {
|
|
|
existApps.add(app);
|
|
|
} else {
|
|
|
- results.add(new BuildDeployResult(appId, "初始化", 0, "应用不存在"));
|
|
|
+ BuildResult buildResult = new BuildResult();
|
|
|
+ buildResult.setAppId(appId);
|
|
|
+ buildResult.setCode(1);
|
|
|
+ buildResult.setMsg("应用不存在");
|
|
|
+ results.add(buildResult);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
// TODO 若应用当前正在进行构建,则忽略
|
|
|
Map<String, List<AppOrchestration>> appsByProj = filterByProj(existApps);
|
|
|
- List<Future<List<ProjectUpdateTask.AppVersion>>> projFutures = new ArrayList<>();
|
|
|
- List<Future<String>> appFutures = new ArrayList<>();
|
|
|
+ List<Future<List<ProjectUpdateTask.AppStatus>>> projFutures = new ArrayList<>();
|
|
|
+ List<Future<BuildResult>> appFutures = new ArrayList<>();
|
|
|
ExecutorService threadPool = ThreadPoolWrapper.threadPool("dispatcher");
|
|
|
for (Map.Entry<String, List<AppOrchestration>> entry : appsByProj.entrySet()) {
|
|
|
String key = entry.getKey();
|
|
|
@@ -69,15 +74,16 @@ public class BuildDispatcher {
|
|
|
} else {
|
|
|
// 更新,编译,打包独立的应用
|
|
|
apps.forEach(app -> {
|
|
|
- appFutures.add(threadPool.submit(new AppBuildPipeline(app, null, isDeploy)));
|
|
|
+ AppIntegrate appIntegrate = new AppIntegrate(app);
|
|
|
+ appFutures.add(threadPool.submit(new AppBuildPipeline(appIntegrate, isDeploy)));
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 构建项目中的应用
|
|
|
- Iterator<Future<List<ProjectUpdateTask.AppVersion>>> iterator = projFutures.iterator();
|
|
|
+ Iterator<Future<List<ProjectUpdateTask.AppStatus>>> iterator = projFutures.iterator();
|
|
|
while (iterator.hasNext()) {
|
|
|
- Future<List<ProjectUpdateTask.AppVersion>> future = iterator.next();
|
|
|
+ Future<List<ProjectUpdateTask.AppStatus>> future = iterator.next();
|
|
|
while (!future.isDone() && !future.isCancelled()) {
|
|
|
Thread.sleep(500);
|
|
|
}
|
|
|
@@ -85,17 +91,17 @@ public class BuildDispatcher {
|
|
|
if (future.isCancelled()) {
|
|
|
log.info("future is cannelled");
|
|
|
} else {
|
|
|
- List<ProjectUpdateTask.AppVersion> appVersions = future.get();
|
|
|
- appVersions.forEach(appVersion -> {
|
|
|
- if (appVersion.isUpdated()) {
|
|
|
- appFutures.add(threadPool.submit(
|
|
|
- new AppBuildPipeline(appVersion.getApp(), appVersion.getVersion(), isDeploy)));
|
|
|
+ List<ProjectUpdateTask.AppStatus> appStatusList = future.get();
|
|
|
+ appStatusList.forEach(appStatus -> {
|
|
|
+ if (appStatus.isUpdated()) {
|
|
|
+ AppIntegrate appIntegrate = new AppIntegrate(appStatus.getApp(), appStatus.getLastCommitInfo());
|
|
|
+ appFutures.add(threadPool.submit(new AppBuildPipeline(appIntegrate, isDeploy)));
|
|
|
} else {
|
|
|
- BuildDeployResult buildDeployResult = new BuildDeployResult();
|
|
|
- buildDeployResult.setAppId(appVersion.getApp().getAppId());
|
|
|
- buildDeployResult.setVersion(appVersion.getVersion());
|
|
|
- buildDeployResult.setMsg("应用不需要更新");
|
|
|
- results.add(buildDeployResult);
|
|
|
+ BuildResult buildResult = new BuildResult();
|
|
|
+ buildResult.setAppId(appStatus.getApp().getAppId());
|
|
|
+ buildResult.setCommitId(appStatus.getLastCommitInfo().getCommitId());
|
|
|
+ buildResult.setMsg("应用不需要更新");
|
|
|
+ results.add(buildResult);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
@@ -103,16 +109,14 @@ public class BuildDispatcher {
|
|
|
}
|
|
|
|
|
|
// 等待所有正在构建的应用
|
|
|
- Iterator<Future<String>> iterator1 = appFutures.iterator();
|
|
|
+ Iterator<Future<BuildResult>> iterator1 = appFutures.iterator();
|
|
|
while (iterator1.hasNext()) {
|
|
|
- Future<String> future = iterator1.next();
|
|
|
+ Future<BuildResult> future = iterator1.next();
|
|
|
while (!future.isDone() && !future.isCancelled()) {
|
|
|
Thread.sleep(1_000);
|
|
|
}
|
|
|
|
|
|
- JsonUtil.arrayToList(future.get(), BuildDeployResult.class).forEach(obj -> {
|
|
|
- results.add((BuildDeployResult) obj);
|
|
|
- });
|
|
|
+ results.add(future.get());
|
|
|
iterator1.remove();
|
|
|
}
|
|
|
|
|
|
@@ -160,19 +164,7 @@ public class BuildDispatcher {
|
|
|
* @date 2020-03-09 下午4:39
|
|
|
*/
|
|
|
private void fillAppBuild(ProjOrchestration proj, AppOrchestration app) {
|
|
|
- String projRepo = proj.getProjRepo();
|
|
|
AppBuild appBuild = proj.getAppBuild();
|
|
|
-
|
|
|
- String appRepo = app.getAppRepo();
|
|
|
- app.setAppRepo(projRepo + appRepo);
|
|
|
- StringBuilder sb = new StringBuilder();
|
|
|
- List<String> repos = Arrays.stream(app.getDependencyRepos().split(","))
|
|
|
- .map(repo -> projRepo + repo)
|
|
|
- .collect(Collectors.toList());
|
|
|
- repos.forEach(repo -> {
|
|
|
- sb.append(repo).append(",");
|
|
|
- });
|
|
|
- app.setDependencyRepos(sb.toString());
|
|
|
app.setAppBuild(appBuild);
|
|
|
}
|
|
|
}
|