|
|
@@ -17,6 +17,7 @@ import org.eclipse.paho.client.mqttv3.MqttException;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.*;
|
|
|
+import java.util.concurrent.ConcurrentSkipListSet;
|
|
|
|
|
|
/**
|
|
|
* 应用部署
|
|
|
@@ -27,6 +28,7 @@ import java.util.*;
|
|
|
@Slf4j
|
|
|
@Service
|
|
|
public class AppDeployer {
|
|
|
+ private final Set<String> onDeploying = new ConcurrentSkipListSet<>();
|
|
|
private final AsyncMqttClient mqttClient;
|
|
|
private final AppDeployingService deployingService;
|
|
|
private final AppDeployConfigQuery deployConfigQuery;
|
|
|
@@ -39,40 +41,27 @@ public class AppDeployer {
|
|
|
}
|
|
|
|
|
|
public void deploy(BuildLog buildLog) throws MqttException {
|
|
|
- String buildLogId = buildLog.getId();
|
|
|
String appId = buildLog.getAppId();
|
|
|
+ if (!onDeploying.add(appId)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ String buildLogId = buildLog.getId();
|
|
|
String packagePath = buildLog.getPackagePath();
|
|
|
String deployBy = buildLog.getBuildBy();
|
|
|
String commitId = buildLog.getCommitInfo().getCommitId();
|
|
|
|
|
|
List<AppDeployConfig> deployConfigs = deployConfigQuery.findByAppId(appId);
|
|
|
// TODO 使用线程池并发执行
|
|
|
- for (AppDeployConfig deployConfig : deployConfigs) {
|
|
|
- String machineId = deployConfig.getMachineHost().getMachineId();
|
|
|
- String machineIpv4 = deployConfig.getMachineHost().getMachineIpv4();
|
|
|
- String packType = deployConfig.getPackType();
|
|
|
- String startScript = deployConfig.getStartScript();
|
|
|
- String startHome = deployConfig.getStartHome();
|
|
|
- String unpackScript = deployConfig.getUnpackScript();
|
|
|
-
|
|
|
- DeployParam deployParam = new DeployParam();
|
|
|
- deployParam.setBuildLogId(buildLogId);
|
|
|
- deployParam.setAppId(appId);
|
|
|
- deployParam.setPackagePath(packagePath);
|
|
|
- deployParam.setPackType(packType);
|
|
|
- deployParam.setStartScript(startScript);
|
|
|
- //deployParam.setStartHome(startHome);
|
|
|
-
|
|
|
- RpcMsg rpcMsg = RpcMsg.paramMsg(AppRpcClazz.class.getSimpleName(), AppRpcClazz.deploy.name(),
|
|
|
- JsonConverter.objectToJson(deployParam));
|
|
|
- Message message = Message.rpcParamMsg(rpcMsg);
|
|
|
- // TODO 对于需要返回值的 pub,需要做一个记录,pub 和 sub 一一对应
|
|
|
- String topic = MsgQueue.dagentTopic(machineId);
|
|
|
- mqttClient.pubWithResult(topic, 1, message);
|
|
|
-
|
|
|
- deployingService.refreshBeforeDeploy(deployConfig, buildLog);
|
|
|
+ for (AppDeployConfig appDeployConfig : deployConfigs) {
|
|
|
+ String machineId = appDeployConfig.getMachineHost().getMachineId();
|
|
|
+ String machineIpv4 = appDeployConfig.getMachineHost().getMachineIpv4();
|
|
|
+ deployingService.refreshBeforeDeploy(appDeployConfig, buildLog);
|
|
|
deployingService.addDeployLog(new DeployLog(buildLogId, machineId, machineIpv4, deployBy));
|
|
|
+ deploy(buildLog, appDeployConfig);
|
|
|
}
|
|
|
+
|
|
|
+ onDeploying.remove(appId);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -82,6 +71,33 @@ public class AppDeployer {
|
|
|
* @return
|
|
|
* @date 2020-03-13 下午1:00
|
|
|
*/
|
|
|
- public void deploy(BuildLog buildLog, List<AppDeployConfig> deployConfigs) {
|
|
|
+ public void deploy(BuildLog buildLog, AppDeployConfig appDeployConfig) throws MqttException {
|
|
|
+ String buildLogId = buildLog.getId();
|
|
|
+ String appId = buildLog.getAppId();
|
|
|
+ String packagePath = buildLog.getPackagePath();
|
|
|
+ String deployBy = buildLog.getBuildBy();
|
|
|
+ String commitId = buildLog.getCommitInfo().getCommitId();
|
|
|
+
|
|
|
+ String machineId = appDeployConfig.getMachineHost().getMachineId();
|
|
|
+ String machineIpv4 = appDeployConfig.getMachineHost().getMachineIpv4();
|
|
|
+ String packType = appDeployConfig.getPackType();
|
|
|
+ String startScript = appDeployConfig.getStartScript();
|
|
|
+ String startHome = appDeployConfig.getStartHome();
|
|
|
+ String unpackScript = appDeployConfig.getUnpackScript();
|
|
|
+
|
|
|
+ DeployParam deployParam = new DeployParam();
|
|
|
+ deployParam.setBuildLogId(buildLogId);
|
|
|
+ deployParam.setAppId(appId);
|
|
|
+ deployParam.setPackagePath(packagePath);
|
|
|
+ deployParam.setPackType(packType);
|
|
|
+ deployParam.setStartScript(startScript);
|
|
|
+ deployParam.setStartHome(startHome);
|
|
|
+
|
|
|
+ RpcMsg rpcMsg = RpcMsg.paramMsg(AppRpcClazz.class.getSimpleName(), AppRpcClazz.deploy.name(),
|
|
|
+ JsonConverter.objectToJson(deployParam));
|
|
|
+ Message message = Message.rpcParamMsg(rpcMsg);
|
|
|
+ // TODO 对于需要返回值的 pub,需要做一个记录,pub 和 sub 一一对应
|
|
|
+ String topic = MsgQueue.dagentTopic(machineId);
|
|
|
+ mqttClient.pubWithResult(topic, 1, message);
|
|
|
}
|
|
|
}
|