|
@@ -2,16 +2,21 @@ package cn.reghao.autodop.dmaster.app.service.build;
|
|
|
|
|
|
|
|
import cn.reghao.autodop.common.config.BuildDeployResult;
|
|
import cn.reghao.autodop.common.config.BuildDeployResult;
|
|
|
import cn.reghao.autodop.common.utils.JsonUtil;
|
|
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.build.AppBuild;
|
|
|
import cn.reghao.autodop.dmaster.app.entity.orchestration.AppOrchestration;
|
|
import cn.reghao.autodop.dmaster.app.entity.orchestration.AppOrchestration;
|
|
|
|
|
+import cn.reghao.autodop.dmaster.app.entity.orchestration.ProjOrchestration;
|
|
|
import cn.reghao.autodop.dmaster.app.thread.ThreadPoolWrapper;
|
|
import cn.reghao.autodop.dmaster.app.thread.ThreadPoolWrapper;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
import java.util.concurrent.*;
|
|
import java.util.concurrent.*;
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
|
|
+ * 应用构建分发
|
|
|
|
|
+ *
|
|
|
* @author reghao
|
|
* @author reghao
|
|
|
* @date 2019-11-12 17:20:27
|
|
* @date 2019-11-12 17:20:27
|
|
|
*/
|
|
*/
|
|
@@ -19,11 +24,11 @@ import java.util.concurrent.*;
|
|
|
@Service
|
|
@Service
|
|
|
public class BuildDispatcher {
|
|
public class BuildDispatcher {
|
|
|
private final String STANDALONE_APP = "standaloneApp";
|
|
private final String STANDALONE_APP = "standaloneApp";
|
|
|
- /*private OrchestrationCaching caching;
|
|
|
|
|
|
|
+ private OrchestrationCaching caching;
|
|
|
|
|
|
|
|
public BuildDispatcher(OrchestrationCaching caching) {
|
|
public BuildDispatcher(OrchestrationCaching caching) {
|
|
|
this.caching = caching;
|
|
this.caching = caching;
|
|
|
- }*/
|
|
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 根据项目分发应用
|
|
* 根据项目分发应用
|
|
@@ -38,15 +43,14 @@ public class BuildDispatcher {
|
|
|
// 分离出存在的应用和不存在的应用
|
|
// 分离出存在的应用和不存在的应用
|
|
|
if (appIds.remove("all")) {
|
|
if (appIds.remove("all")) {
|
|
|
// 处理所有需编译的应用
|
|
// 处理所有需编译的应用
|
|
|
- // existApps.addAll(config.getApps().values());
|
|
|
|
|
} else {
|
|
} else {
|
|
|
appIds.forEach(appId -> {
|
|
appIds.forEach(appId -> {
|
|
|
- /*AppOrchestration app = caching.findAppByIdentifier(appId);
|
|
|
|
|
|
|
+ AppOrchestration app = caching.findByAppId(appId);
|
|
|
if (app != null) {
|
|
if (app != null) {
|
|
|
existApps.add(app);
|
|
existApps.add(app);
|
|
|
} else {
|
|
} else {
|
|
|
results.add(new BuildDeployResult(appId, "初始化", 0, "应用不存在"));
|
|
results.add(new BuildDeployResult(appId, "初始化", 0, "应用不存在"));
|
|
|
- }*/
|
|
|
|
|
|
|
+ }
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -60,8 +64,8 @@ public class BuildDispatcher {
|
|
|
List<AppOrchestration> apps = entry.getValue();
|
|
List<AppOrchestration> apps = entry.getValue();
|
|
|
if (!STANDALONE_APP.equalsIgnoreCase(key)) {
|
|
if (!STANDALONE_APP.equalsIgnoreCase(key)) {
|
|
|
// 首先更新整个项目,然后再分别更新,编译,打包应用
|
|
// 首先更新整个项目,然后再分别更新,编译,打包应用
|
|
|
- //ProjOrchestration proj = caching.findProjByIdentifier(key);
|
|
|
|
|
- //projFutures.add(threadPool.submit(new ProjectUpdateTask(proj, apps)));
|
|
|
|
|
|
|
+ ProjOrchestration proj = caching.findByProjId(key);
|
|
|
|
|
+ projFutures.add(threadPool.submit(new ProjectUpdateTask(proj, apps)));
|
|
|
} else {
|
|
} else {
|
|
|
// 更新,编译,打包独立的应用
|
|
// 更新,编译,打包独立的应用
|
|
|
apps.forEach(app -> {
|
|
apps.forEach(app -> {
|
|
@@ -84,11 +88,11 @@ public class BuildDispatcher {
|
|
|
List<ProjectUpdateTask.AppVersion> appVersions = future.get();
|
|
List<ProjectUpdateTask.AppVersion> appVersions = future.get();
|
|
|
appVersions.forEach(appVersion -> {
|
|
appVersions.forEach(appVersion -> {
|
|
|
if (appVersion.isUpdated()) {
|
|
if (appVersion.isUpdated()) {
|
|
|
- /*appFutures.add(threadPool.submit(
|
|
|
|
|
- new AppBuildPipeline(appVersion.getApp(), appVersion.getVersion(), isDeploy)));*/
|
|
|
|
|
|
|
+ appFutures.add(threadPool.submit(
|
|
|
|
|
+ new AppBuildPipeline(appVersion.getApp(), appVersion.getVersion(), isDeploy)));
|
|
|
} else {
|
|
} else {
|
|
|
BuildDeployResult buildDeployResult = new BuildDeployResult();
|
|
BuildDeployResult buildDeployResult = new BuildDeployResult();
|
|
|
- //buildDeployResult.setAppId(appVersion.getApp());
|
|
|
|
|
|
|
+ buildDeployResult.setAppId(appVersion.getApp().getAppId());
|
|
|
buildDeployResult.setVersion(appVersion.getVersion());
|
|
buildDeployResult.setVersion(appVersion.getVersion());
|
|
|
buildDeployResult.setMsg("应用不需要更新");
|
|
buildDeployResult.setMsg("应用不需要更新");
|
|
|
results.add(buildDeployResult);
|
|
results.add(buildDeployResult);
|
|
@@ -125,16 +129,14 @@ public class BuildDispatcher {
|
|
|
private Map<String, List<AppOrchestration>> filterByProj(List<AppOrchestration> apps) {
|
|
private Map<String, List<AppOrchestration>> filterByProj(List<AppOrchestration> apps) {
|
|
|
Map<String, List<AppOrchestration>> appMap = new HashMap<>();
|
|
Map<String, List<AppOrchestration>> appMap = new HashMap<>();
|
|
|
for (AppOrchestration app : apps) {
|
|
for (AppOrchestration app : apps) {
|
|
|
- String mapkey = null;
|
|
|
|
|
- /*if (app.getProjBuild() != null) {
|
|
|
|
|
- mapkey = app.getProjBuild().getProjId();
|
|
|
|
|
- ProjOrchestration proj = caching.findProjByIdentifier(mapkey);
|
|
|
|
|
- AppBuild projBuild = proj.getBuild();
|
|
|
|
|
- fillAppBuild(projBuild, app);
|
|
|
|
|
|
|
+ String mapkey = app.getProjId();
|
|
|
|
|
+ if (mapkey != null) {
|
|
|
|
|
+ ProjOrchestration proj = caching.findByProjId(mapkey);
|
|
|
|
|
+ fillAppBuild(proj, app);
|
|
|
} else {
|
|
} else {
|
|
|
// 单独的应用,不隶属于任何项目
|
|
// 单独的应用,不隶属于任何项目
|
|
|
mapkey = STANDALONE_APP;
|
|
mapkey = STANDALONE_APP;
|
|
|
- }*/
|
|
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
if (appMap.containsKey(mapkey)) {
|
|
if (appMap.containsKey(mapkey)) {
|
|
|
appMap.get(mapkey).add(app);
|
|
appMap.get(mapkey).add(app);
|
|
@@ -157,31 +159,20 @@ public class BuildDispatcher {
|
|
|
* @return
|
|
* @return
|
|
|
* @date 2020-03-09 下午4:39
|
|
* @date 2020-03-09 下午4:39
|
|
|
*/
|
|
*/
|
|
|
- private void fillAppBuild(AppBuild build, AppOrchestration app) {
|
|
|
|
|
- //ProjBuild projBuild = app.getProjBuild();
|
|
|
|
|
-
|
|
|
|
|
- AppBuild appBuild = new AppBuild();
|
|
|
|
|
- /*appBuild.setNotifier(build.getNotifier());
|
|
|
|
|
- appBuild.setCodeCompiler(build.getCodeCompiler());
|
|
|
|
|
- appBuild.setAppPacker(build.getAppPacker());*/
|
|
|
|
|
-
|
|
|
|
|
- /*String projReposUrl = build.getCodeRepos().getReposUrl();
|
|
|
|
|
- String appReposUrl = projReposUrl + projBuild.getAppReposUrl();
|
|
|
|
|
-
|
|
|
|
|
- CodeRepos codeRepos = new CodeRepos();
|
|
|
|
|
- codeRepos.setReposUrl(appReposUrl);
|
|
|
|
|
- if (projBuild.getAppDependencyUrls() != null) {
|
|
|
|
|
- String[] urls = projBuild.getAppDependencyUrls().split(",");
|
|
|
|
|
- StringBuilder sb = new StringBuilder();
|
|
|
|
|
- for (String str : urls) {
|
|
|
|
|
- sb.append(projReposUrl).append(str).append(",");
|
|
|
|
|
- }
|
|
|
|
|
- String depUrl = sb.toString();
|
|
|
|
|
- int index = depUrl.lastIndexOf(",");
|
|
|
|
|
- codeRepos.setDependencyUrls(depUrl.substring(0, index));
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- appBuild.setCodeRepos(codeRepos);
|
|
|
|
|
- app.setBuild(appBuild);*/
|
|
|
|
|
|
|
+ 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);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|