|
|
@@ -5,6 +5,7 @@ import cn.reghao.devops.common.docker.model.DockerContainerConfig;
|
|
|
import cn.reghao.devops.common.msg.constant.PackType;
|
|
|
import cn.reghao.devops.common.msg.constant.StepStatus;
|
|
|
import cn.reghao.devops.common.msg.event.EvtAppStatResult;
|
|
|
+import cn.reghao.devops.mgr.admin.service.UserContext;
|
|
|
import cn.reghao.devops.mgr.ops.aliyun.service.AliyunCdn;
|
|
|
import cn.reghao.devops.mgr.ops.app.db.query.AppBuildQuery;
|
|
|
import cn.reghao.devops.mgr.ops.app.db.query.AppDeployQuery;
|
|
|
@@ -211,18 +212,18 @@ public class AppDeployServiceImpl implements AppDeployService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void updateBeforeDeploy(AppBuilding appBuilding, String machineId, String opsBy) {
|
|
|
+ public void updateBeforeDeploy(AppBuilding appBuilding, String machineId) {
|
|
|
String appId = appBuilding.getAppConfig().getAppId();
|
|
|
AppDeploying appDeploying = appDeployingRepository.findByAppDeployConfig_AppConfig_AppIdAndAppDeployConfig_MachineInfo_MachineId(appId, machineId);
|
|
|
- String machineId1 = appDeploying.getAppDeployConfig().getMachineInfo().getMachineId();
|
|
|
- if (machineId1.equals(machineId)) {
|
|
|
+ if (appDeploying != null) {
|
|
|
+ String opsBy = UserContext.getUsername();
|
|
|
+ appDeploying.setDeployTime(LocalDateTime.now());
|
|
|
appDeploying.setDeployResult(DeployStatus.onDeploying.getDesc());
|
|
|
appDeploying.setOpsBy(opsBy);
|
|
|
+ appDeployingRepository.save(appDeploying);
|
|
|
+ } else {
|
|
|
+ log.error("AppDeploying with appId {} not exist", appId);
|
|
|
}
|
|
|
-
|
|
|
- BuildLog buildLog = appBuilding.getBuildLog();
|
|
|
- //DeployLog deployLog = new DeployLog(buildLog);
|
|
|
- appDeployingRepository.save(appDeploying);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -235,11 +236,13 @@ public class AppDeployServiceImpl implements AppDeployService {
|
|
|
|
|
|
AppDeployConfig deployConfig = deployConfigRepository.findByAppConfig_AppIdAndMachineInfo_MachineId(appId, machineId);
|
|
|
if (deployConfig == null) {
|
|
|
+ log.error("AppDeployConfig with appId {} not exist", appId);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
AppDeploying appDeploying = appDeployingRepository.findByAppDeployConfigId(deployConfig.getId());
|
|
|
if (appDeploying == null) {
|
|
|
+ log.error("AppDeploying with appId {} not exist", appId);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
@@ -285,11 +288,9 @@ public class AppDeployServiceImpl implements AppDeployService {
|
|
|
AppDeployConfig appDeployConfig = appDeploying.getAppDeployConfig();
|
|
|
BuildLog buildLog = appBuildQuery.getAppBuilding(appId).getBuildLog();
|
|
|
|
|
|
- String stepJson = JsonConverter.objectToJson(appDeploying.getSteps());
|
|
|
- String configSnapshot = JsonConverter.objectToJson(appDeployConfig);
|
|
|
- DeployLog deployLog = new DeployLog(buildLog, appDeployConfig);
|
|
|
- //deployLogRepository.save(deployLog);
|
|
|
- //buildDeployNotify.deployNotify(deployLog);
|
|
|
+ DeployLog deployLog = getDeployLog(appDeploying, appDeployConfig, deployResult, buildLog);
|
|
|
+ deployLogRepository.save(deployLog);
|
|
|
+ buildDeployNotify.deployNotify(deployLog);
|
|
|
|
|
|
log.info("{} 的通知已发送", deployResult.getAppId());
|
|
|
AppConfig appConfig = deployConfig.getAppConfig();
|
|
|
@@ -302,6 +303,28 @@ public class AppDeployServiceImpl implements AppDeployService {
|
|
|
appDeployingRepository.save(appDeploying);
|
|
|
}
|
|
|
|
|
|
+ private DeployLog getDeployLog(AppDeploying appDeploying, AppDeployConfig appDeployConfig,
|
|
|
+ EvtAppStatResult deployResult,BuildLog buildLog) {
|
|
|
+ String stepJson = JsonConverter.objectToJson(appDeploying.getSteps());
|
|
|
+ String configSnapshot = JsonConverter.objectToJson(appDeployConfig);
|
|
|
+ String stepStatus = deployResult.getDeployStepStatus();
|
|
|
+
|
|
|
+ String opsBy = appDeploying.getOpsBy();
|
|
|
+ LocalDateTime startTime = appDeploying.getDeployTime();
|
|
|
+ LocalDateTime endTime = LocalDateTime.now();
|
|
|
+ long seconds = Duration.between(startTime, endTime).getSeconds();
|
|
|
+
|
|
|
+ DeployLog deployLog = new DeployLog(buildLog, appDeployConfig, opsBy);
|
|
|
+ deployLog.setStartTime(startTime);
|
|
|
+ deployLog.setEndTime(endTime);
|
|
|
+ deployLog.setDuration(seconds);
|
|
|
+ deployLog.setStatus(stepStatus);
|
|
|
+ deployLog.setErrorMsg(deployResult.getErrorMsg());
|
|
|
+ deployLog.setStepJson(stepJson);
|
|
|
+ deployLog.setConfigSnapshot(configSnapshot);
|
|
|
+ return deployLog;
|
|
|
+ }
|
|
|
+
|
|
|
private void refreshCdn(AppConfig appConfig, BuildLog buildLog) {
|
|
|
String buildId = buildLog.getBuildLogId();
|
|
|
String appId = appConfig.getAppId();
|