|
|
@@ -7,8 +7,11 @@ 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;
|
|
|
import cn.reghao.autodop.dmaster.app.db.query.config.AppConfigQuery;
|
|
|
+import cn.reghao.autodop.dmaster.app.db.query.config.AppDeployConfigQuery;
|
|
|
import cn.reghao.autodop.dmaster.app.db.query.log.BuildLogQuery;
|
|
|
import cn.reghao.autodop.dmaster.app.model.po.config.AppConfig;
|
|
|
+import cn.reghao.autodop.dmaster.app.model.po.config.AppDeployConfig;
|
|
|
+import cn.reghao.autodop.dmaster.app.model.po.config.build.LocalBuildDir;
|
|
|
import cn.reghao.autodop.dmaster.app.model.po.log.BuildLog;
|
|
|
import cn.reghao.autodop.dmaster.app.service.AppBuildSupplier;
|
|
|
import cn.reghao.autodop.dmaster.app.service.BuildDeployService;
|
|
|
@@ -16,14 +19,13 @@ import cn.reghao.autodop.dmaster.app.service.AppDeployer;
|
|
|
import cn.reghao.autodop.dmaster.app.service.AppBuilder;
|
|
|
import cn.reghao.autodop.dmaster.app.service.bd.AppBuildingService;
|
|
|
import cn.reghao.autodop.dmaster.util.UploadDownload;
|
|
|
-import cn.reghao.autodop.dmaster.spring.HttpRequestUtil;
|
|
|
+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.BufferedInputStream;
|
|
|
import java.io.File;
|
|
|
import java.io.FileInputStream;
|
|
|
import java.util.List;
|
|
|
@@ -48,10 +50,12 @@ public class BuildDeployServiceImpl implements BuildDeployService {
|
|
|
private final UploadDownload uploadDownload;
|
|
|
private final AppConfigQuery appConfigQuery;
|
|
|
private final BuildLogQuery buildLogQuery;
|
|
|
+ private AppDeployConfigQuery deployConfigQuery;
|
|
|
|
|
|
public BuildDeployServiceImpl(AsyncMqttClient mqttClient, AppDeployer appDeployer,
|
|
|
AppBuildingService buildingService, UploadDownload uploadDownload,
|
|
|
- AppConfigQuery appConfigQuery, BuildLogQuery buildLogQuery) {
|
|
|
+ AppConfigQuery appConfigQuery, BuildLogQuery buildLogQuery,
|
|
|
+ AppDeployConfigQuery deployConfigQuery) {
|
|
|
this.threadPool = ThreadPoolWrapper.threadPool("build-deploy");
|
|
|
this.mqttClient = mqttClient;
|
|
|
this.buildingService = buildingService;
|
|
|
@@ -59,6 +63,7 @@ public class BuildDeployServiceImpl implements BuildDeployService {
|
|
|
this.uploadDownload = uploadDownload;
|
|
|
this.appConfigQuery = appConfigQuery;
|
|
|
this.buildLogQuery = buildLogQuery;
|
|
|
+ this.deployConfigQuery = deployConfigQuery;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -112,13 +117,34 @@ public class BuildDeployServiceImpl implements BuildDeployService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void deploy(String buildLogId, String machineId) {
|
|
|
+ public void deploy(String buildLogId, String machineId) throws MqttException {
|
|
|
BuildLog buildLog = buildLogQuery.findById(buildLogId);
|
|
|
if (buildLog == null) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
String appId = buildLog.getAppId();
|
|
|
+ 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());
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -144,9 +170,7 @@ public class BuildDeployServiceImpl implements BuildDeployService {
|
|
|
case zip:
|
|
|
String packagePath = buildLog.getPackagePath();
|
|
|
String filename = packagePath.substring(packagePath.lastIndexOf(File.separator)+1);
|
|
|
- FileInputStream fileInputStream = new FileInputStream(packagePath);
|
|
|
- BufferedInputStream bis = new BufferedInputStream(fileInputStream);
|
|
|
- uploadDownload.download(filename, bis, HttpRequestUtil.getResponse());
|
|
|
+ dlPackage(filename);
|
|
|
break;
|
|
|
case zipHttp:
|
|
|
throw new Exception(String.format("打包类型 %s 暂未实现", packType));
|
|
|
@@ -155,12 +179,10 @@ public class BuildDeployServiceImpl implements BuildDeployService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
public List<String> currentlyBuilding() {
|
|
|
return List.copyOf(onBuilding);
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
public List<String> currentlyDeploying() {
|
|
|
List<DeployParam> list = mqttClient.unreturnedRpc().values().stream()
|
|
|
.filter(rpcMsg -> {
|