|
|
@@ -1,8 +1,6 @@
|
|
|
package cn.reghao.autodop.dmaster.app.service.impl;
|
|
|
|
|
|
import cn.reghao.autodop.common.mqtt.AsyncMqttClient;
|
|
|
-import cn.reghao.autodop.common.msg.rpc.constant.AppRpcClazz;
|
|
|
-import cn.reghao.autodop.common.msg.rpc.dto.app.DeployParam;
|
|
|
import cn.reghao.autodop.common.msg.rpc.dto.app.PackType;
|
|
|
import cn.reghao.autodop.common.util.ExceptionUtil;
|
|
|
import cn.reghao.autodop.common.util.thread.ThreadPoolWrapper;
|
|
|
@@ -21,19 +19,16 @@ import cn.reghao.autodop.dmaster.app.service.bd.AppBuildingService;
|
|
|
import cn.reghao.autodop.dmaster.util.UploadDownload;
|
|
|
import cn.reghao.autodop.dmaster.spring.HttpUtil;
|
|
|
import cn.reghao.jdkutil.result.ResultStatus;
|
|
|
-import cn.reghao.jdkutil.serializer.JsonConverter;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.eclipse.paho.client.mqttv3.MqttException;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.io.File;
|
|
|
import java.io.FileInputStream;
|
|
|
-import java.util.List;
|
|
|
import java.util.Set;
|
|
|
import java.util.concurrent.CompletableFuture;
|
|
|
import java.util.concurrent.ConcurrentSkipListSet;
|
|
|
import java.util.concurrent.ExecutorService;
|
|
|
-import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* @author reghao
|
|
|
@@ -43,6 +38,7 @@ import java.util.stream.Collectors;
|
|
|
@Service
|
|
|
public class BuildDeployServiceImpl implements BuildDeployService {
|
|
|
private final Set<String> onBuilding = new ConcurrentSkipListSet<>();
|
|
|
+ private final Set<String> onDeploying = new ConcurrentSkipListSet<>();
|
|
|
private final ExecutorService threadPool;
|
|
|
private final AsyncMqttClient mqttClient;
|
|
|
private final AppBuildingService buildingService;
|
|
|
@@ -106,11 +102,17 @@ public class BuildDeployServiceImpl implements BuildDeployService {
|
|
|
.thenAccept(buildLog -> {
|
|
|
if (isDeploy && buildLog.getResult().getCode() == ResultStatus.SUCCESS.getCode()) {
|
|
|
log.info("开始部署 {}", appId);
|
|
|
+ if (!onDeploying.add(appId)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
try {
|
|
|
appDeployer.deploy(buildLog);
|
|
|
} catch (MqttException e) {
|
|
|
String errMsg = ExceptionUtil.errorMsg(e);
|
|
|
log.error("部署 {} 时抛出异常: {}", appId, errMsg);
|
|
|
+ } finally {
|
|
|
+ onDeploying.remove(appId);
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
@@ -124,31 +126,20 @@ public class BuildDeployServiceImpl implements BuildDeployService {
|
|
|
}
|
|
|
|
|
|
String appId = buildLog.getAppId();
|
|
|
+ if (!onDeploying.add(appId)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
AppDeployConfig deployConfig = deployConfigQuery.findByAppIdAndMachineId(appId, machineId);
|
|
|
if (deployConfig != null) {
|
|
|
appDeployer.deploy(buildLog, deployConfig);
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- @Override
|
|
|
- public void dlPackage(String filename) throws Exception {
|
|
|
- String[] arr = filename.split("_");
|
|
|
- if (arr.length != 2) {
|
|
|
- String errMsg = String.format("%s 不合法", filename);
|
|
|
- throw new Exception(errMsg);
|
|
|
- }
|
|
|
-
|
|
|
- String appId = arr[0];
|
|
|
- String commitId = arr[1];
|
|
|
- String localPath = String.format("%s%s%s%s%s",
|
|
|
- LocalBuildDir.packDir, File.separator, appId, File.separator, filename);
|
|
|
- FileInputStream fileInputStream = new FileInputStream(localPath);
|
|
|
- //BufferedInputStream bis = new BufferedInputStream(fileInputStream);
|
|
|
- uploadDownload.download(filename, fileInputStream, HttpUtil.getResponse());
|
|
|
+ onDeploying.remove(appId);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void downloadPackage(String buildLogId) throws Exception {
|
|
|
+ public String packageUrl(String buildLogId) throws Exception {
|
|
|
BuildLog buildLog = buildLogQuery.findById(buildLogId);
|
|
|
if (buildLog == null) {
|
|
|
String errMsg = "构建不存在";
|
|
|
@@ -162,37 +153,35 @@ public class BuildDeployServiceImpl implements BuildDeployService {
|
|
|
throw new Exception(errMsg);
|
|
|
}
|
|
|
|
|
|
+ String packagePath = buildLog.getPackagePath();
|
|
|
String packType = appConfig.getPackerConfig().getType();
|
|
|
switch (PackType.valueOf(packType)) {
|
|
|
- case docker:
|
|
|
- String errMsg = "docker 打包类型的应用不能下载";
|
|
|
- throw new Exception(errMsg);
|
|
|
case zip:
|
|
|
- String packagePath = buildLog.getPackagePath();
|
|
|
- String filename = packagePath.substring(packagePath.lastIndexOf(File.separator)+1);
|
|
|
- dlPackage(filename);
|
|
|
- break;
|
|
|
+ return packagePath;
|
|
|
case zipHttp:
|
|
|
throw new Exception(String.format("打包类型 %s 暂未实现", packType));
|
|
|
+ case docker:
|
|
|
+ String errMsg = "docker 打包类型的应用不能下载";
|
|
|
+ throw new Exception(errMsg);
|
|
|
default:
|
|
|
throw new Exception(String.format("打包类型 %s 不存在", packType));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public List<String> currentlyBuilding() {
|
|
|
- return List.copyOf(onBuilding);
|
|
|
- }
|
|
|
-
|
|
|
- public List<String> currentlyDeploying() {
|
|
|
- List<DeployParam> list = mqttClient.unreturnedRpc().values().stream()
|
|
|
- .filter(rpcMsg -> {
|
|
|
- String clazz = rpcMsg.getClazz();
|
|
|
- String method = rpcMsg.getMethod();
|
|
|
- return clazz.equals(AppRpcClazz.class.getSimpleName()) && method.equals(AppRpcClazz.deploy.name());
|
|
|
- })
|
|
|
- .map(rpcMsg -> JsonConverter.jsonToObject(rpcMsg.getJsonParam(), DeployParam.class))
|
|
|
- .collect(Collectors.toList());
|
|
|
+ @Override
|
|
|
+ public void dlPackage(String filename) throws Exception {
|
|
|
+ String[] arr = filename.split("_");
|
|
|
+ if (arr.length != 2) {
|
|
|
+ String errMsg = String.format("%s 不合法", filename);
|
|
|
+ throw new Exception(errMsg);
|
|
|
+ }
|
|
|
|
|
|
- return list.stream().map(DeployParam::getAppId).collect(Collectors.toList());
|
|
|
+ String appId = arr[0];
|
|
|
+ String commitId = arr[1];
|
|
|
+ String localPath = String.format("%s%s%s%s%s",
|
|
|
+ LocalBuildDir.packDir, File.separator, appId, File.separator, filename);
|
|
|
+ FileInputStream fileInputStream = new FileInputStream(localPath);
|
|
|
+ //BufferedInputStream bis = new BufferedInputStream(fileInputStream);
|
|
|
+ uploadDownload.download(filename, fileInputStream, HttpUtil.getResponse());
|
|
|
}
|
|
|
}
|