|
@@ -5,13 +5,14 @@ import cn.reghao.devops.common.docker.model.DockerContainerConfig;
|
|
|
import cn.reghao.devops.common.msg.constant.PackType;
|
|
import cn.reghao.devops.common.msg.constant.PackType;
|
|
|
import cn.reghao.devops.common.msg.constant.StepStatus;
|
|
import cn.reghao.devops.common.msg.constant.StepStatus;
|
|
|
import cn.reghao.devops.common.msg.event.EvtAppStatResult;
|
|
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.aliyun.service.AliyunCdn;
|
|
|
import cn.reghao.devops.mgr.ops.app.db.query.AppBuildQuery;
|
|
import cn.reghao.devops.mgr.ops.app.db.query.AppBuildQuery;
|
|
|
import cn.reghao.devops.mgr.ops.app.db.query.AppDeployQuery;
|
|
import cn.reghao.devops.mgr.ops.app.db.query.AppDeployQuery;
|
|
|
|
|
+import cn.reghao.devops.mgr.ops.builder.model.constant.BuildStatus;
|
|
|
import cn.reghao.devops.mgr.ops.builder.db.repository.AppDeployingRepository;
|
|
import cn.reghao.devops.mgr.ops.builder.db.repository.AppDeployingRepository;
|
|
|
import cn.reghao.devops.mgr.ops.app.db.repository.AppDeployConfigRepository;
|
|
import cn.reghao.devops.mgr.ops.app.db.repository.AppDeployConfigRepository;
|
|
|
import cn.reghao.devops.mgr.ops.builder.db.repository.DeployLogRepository;
|
|
import cn.reghao.devops.mgr.ops.builder.db.repository.DeployLogRepository;
|
|
|
-import cn.reghao.devops.mgr.ops.app.model.constant.DeployStatus;
|
|
|
|
|
import cn.reghao.devops.mgr.ops.app.model.dto.DeployConfigDto;
|
|
import cn.reghao.devops.mgr.ops.app.model.dto.DeployConfigDto;
|
|
|
import cn.reghao.devops.mgr.ops.app.model.dto.DeployConfigUpdateDto;
|
|
import cn.reghao.devops.mgr.ops.app.model.dto.DeployConfigUpdateDto;
|
|
|
import cn.reghao.devops.mgr.ops.builder.model.po.AppBuilding;
|
|
import cn.reghao.devops.mgr.ops.builder.model.po.AppBuilding;
|
|
@@ -26,8 +27,8 @@ import cn.reghao.devops.mgr.ops.builder.task.RereshCheckTask;
|
|
|
import cn.reghao.devops.mgr.ops.machine.model.po.MachineInfo;
|
|
import cn.reghao.devops.mgr.ops.machine.model.po.MachineInfo;
|
|
|
import cn.reghao.devops.mgr.ops.machine.service.MachineQuery;
|
|
import cn.reghao.devops.mgr.ops.machine.service.MachineQuery;
|
|
|
import cn.reghao.jutil.jdk.converter.DateTimeConverter;
|
|
import cn.reghao.jutil.jdk.converter.DateTimeConverter;
|
|
|
|
|
+import cn.reghao.jutil.jdk.web.result.NotAvailable;
|
|
|
import cn.reghao.jutil.jdk.web.result.Result;
|
|
import cn.reghao.jutil.jdk.web.result.Result;
|
|
|
-import cn.reghao.jutil.jdk.web.result.ResultStatus;
|
|
|
|
|
import cn.reghao.jutil.jdk.serializer.JsonConverter;
|
|
import cn.reghao.jutil.jdk.serializer.JsonConverter;
|
|
|
import cn.reghao.jutil.jdk.thread.ThreadPoolWrapper;
|
|
import cn.reghao.jutil.jdk.thread.ThreadPoolWrapper;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -37,7 +38,6 @@ import org.springframework.util.StringUtils;
|
|
|
|
|
|
|
|
import java.time.Duration;
|
|
import java.time.Duration;
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
|
-import java.util.Arrays;
|
|
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
import java.util.concurrent.ScheduledExecutorService;
|
|
import java.util.concurrent.ScheduledExecutorService;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
import java.util.concurrent.TimeUnit;
|
|
@@ -82,14 +82,14 @@ public class AppDeployServiceImpl implements AppDeployService {
|
|
|
AppConfig appConfig = appBuildQuery.getAppConfig(appId);
|
|
AppConfig appConfig = appBuildQuery.getAppConfig(appId);
|
|
|
if (appConfig == null) {
|
|
if (appConfig == null) {
|
|
|
String msg = String.format("%s 不存在", appId);
|
|
String msg = String.format("%s 不存在", appId);
|
|
|
- return Result.result(ResultStatus.ERROR, msg);
|
|
|
|
|
|
|
+ return Result.result(cn.reghao.jutil.jdk.web.result.ResultStatus.ERROR, msg);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
String machineId = deployConfigDto.getMachineId();
|
|
String machineId = deployConfigDto.getMachineId();
|
|
|
MachineInfo machineInfo = machineQuery.getMachineInfo(machineId);
|
|
MachineInfo machineInfo = machineQuery.getMachineInfo(machineId);
|
|
|
if (machineInfo == null) {
|
|
if (machineInfo == null) {
|
|
|
String msg = String.format("%s 不存在", machineId);
|
|
String msg = String.format("%s 不存在", machineId);
|
|
|
- return Result.result(ResultStatus.ERROR, msg);
|
|
|
|
|
|
|
+ return Result.result(cn.reghao.jutil.jdk.web.result.ResultStatus.ERROR, msg);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
String startScript = deployConfigDto.getStartScript();
|
|
String startScript = deployConfigDto.getStartScript();
|
|
@@ -105,13 +105,8 @@ public class AppDeployServiceImpl implements AppDeployService {
|
|
|
deployConfigRepository.save(appDeployConfig);
|
|
deployConfigRepository.save(appDeployConfig);
|
|
|
|
|
|
|
|
AppDeploying appDeploying = new AppDeploying(appDeployConfig);
|
|
AppDeploying appDeploying = new AppDeploying(appDeployConfig);
|
|
|
- // 定义流水线环节:检出 -> 编译 -> 打包 -> (部署)
|
|
|
|
|
- List<String> stepNames = Arrays.stream(DeployStepName.values())
|
|
|
|
|
- .map(Enum::name)
|
|
|
|
|
- .collect(Collectors.toList());
|
|
|
|
|
- appDeploying.initSteps(stepNames, "");
|
|
|
|
|
appDeployingRepository.save(appDeploying);
|
|
appDeployingRepository.save(appDeploying);
|
|
|
- return Result.result(ResultStatus.SUCCESS);
|
|
|
|
|
|
|
+ return Result.result(cn.reghao.jutil.jdk.web.result.ResultStatus.SUCCESS);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -121,7 +116,7 @@ public class AppDeployServiceImpl implements AppDeployService {
|
|
|
AppDeployConfig appDeployConfig = appDeployQuery.getByAppIdAndMachineId(appId, machineId);
|
|
AppDeployConfig appDeployConfig = appDeployQuery.getByAppIdAndMachineId(appId, machineId);
|
|
|
if (appDeployConfig == null) {
|
|
if (appDeployConfig == null) {
|
|
|
String msg = String.format("%s 在 %s 上的部署配置不存在", appId, machineId);
|
|
String msg = String.format("%s 在 %s 上的部署配置不存在", appId, machineId);
|
|
|
- return Result.result(ResultStatus.ERROR, msg);
|
|
|
|
|
|
|
+ return Result.result(cn.reghao.jutil.jdk.web.result.ResultStatus.ERROR, msg);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
String startScript = deployConfigUpdateDto.getStartScript();
|
|
String startScript = deployConfigUpdateDto.getStartScript();
|
|
@@ -135,7 +130,7 @@ public class AppDeployServiceImpl implements AppDeployService {
|
|
|
|
|
|
|
|
appDeployConfig.setStartScript(startScript);
|
|
appDeployConfig.setStartScript(startScript);
|
|
|
deployConfigRepository.save(appDeployConfig);
|
|
deployConfigRepository.save(appDeployConfig);
|
|
|
- return Result.result(ResultStatus.SUCCESS);
|
|
|
|
|
|
|
+ return Result.result(cn.reghao.jutil.jdk.web.result.ResultStatus.SUCCESS);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -148,7 +143,7 @@ public class AppDeployServiceImpl implements AppDeployService {
|
|
|
public Result deleteDeployConfig(int appDeployConfigId) {
|
|
public Result deleteDeployConfig(int appDeployConfigId) {
|
|
|
AppDeployConfig appDeployConfig = deployConfigRepository.findById(appDeployConfigId).orElse(null);
|
|
AppDeployConfig appDeployConfig = deployConfigRepository.findById(appDeployConfigId).orElse(null);
|
|
|
if (appDeployConfig == null) {
|
|
if (appDeployConfig == null) {
|
|
|
- return Result.result(ResultStatus.FAIL, "AppDeployConfig not exists");
|
|
|
|
|
|
|
+ return Result.result(cn.reghao.jutil.jdk.web.result.ResultStatus.FAIL, "AppDeployConfig not exists");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return deleteAppDeployConfig(appDeployConfig);
|
|
return deleteAppDeployConfig(appDeployConfig);
|
|
@@ -161,10 +156,10 @@ public class AppDeployServiceImpl implements AppDeployService {
|
|
|
appDeployingRepository.delete(appDeploying);
|
|
appDeployingRepository.delete(appDeploying);
|
|
|
deployLogRepository.deleteByAppDeployConfig_MachineInfo_MachineId(machineId);
|
|
deployLogRepository.deleteByAppDeployConfig_MachineInfo_MachineId(machineId);
|
|
|
deployConfigRepository.delete(appDeployConfig);
|
|
deployConfigRepository.delete(appDeployConfig);
|
|
|
- return Result.result(ResultStatus.SUCCESS);
|
|
|
|
|
|
|
+ return Result.result(cn.reghao.jutil.jdk.web.result.ResultStatus.SUCCESS);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- return Result.result(ResultStatus.FAIL, "app is running");
|
|
|
|
|
|
|
+ return Result.result(cn.reghao.jutil.jdk.web.result.ResultStatus.FAIL, "app is running");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -172,12 +167,12 @@ public class AppDeployServiceImpl implements AppDeployService {
|
|
|
List<AppDeployConfig> list = deployConfigRepository.findByAppConfig_AppId(appId);
|
|
List<AppDeployConfig> list = deployConfigRepository.findByAppConfig_AppId(appId);
|
|
|
for (AppDeployConfig appDeployConfig : list) {
|
|
for (AppDeployConfig appDeployConfig : list) {
|
|
|
Result result = deleteAppDeployConfig(appDeployConfig);
|
|
Result result = deleteAppDeployConfig(appDeployConfig);
|
|
|
- if (result.getCode() != ResultStatus.SUCCESS.getCode()) {
|
|
|
|
|
|
|
+ if (result.getCode() != cn.reghao.jutil.jdk.web.result.ResultStatus.SUCCESS.getCode()) {
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- return Result.result(ResultStatus.SUCCESS);
|
|
|
|
|
|
|
+ return Result.result(cn.reghao.jutil.jdk.web.result.ResultStatus.SUCCESS);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -211,18 +206,23 @@ public class AppDeployServiceImpl implements AppDeployService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public void updateBeforeDeploy(AppBuilding appBuilding, String machineId, String opsBy) {
|
|
|
|
|
|
|
+ public void updateBeforeDeploy(AppBuilding appBuilding, String machineId) {
|
|
|
String appId = appBuilding.getAppConfig().getAppId();
|
|
String appId = appBuilding.getAppConfig().getAppId();
|
|
|
AppDeploying appDeploying = appDeployingRepository.findByAppDeployConfig_AppConfig_AppIdAndAppDeployConfig_MachineInfo_MachineId(appId, machineId);
|
|
AppDeploying appDeploying = appDeployingRepository.findByAppDeployConfig_AppConfig_AppIdAndAppDeployConfig_MachineInfo_MachineId(appId, machineId);
|
|
|
- String machineId1 = appDeploying.getAppDeployConfig().getMachineInfo().getMachineId();
|
|
|
|
|
- if (machineId1.equals(machineId)) {
|
|
|
|
|
- appDeploying.setDeployResult(DeployStatus.onDeploying.getDesc());
|
|
|
|
|
|
|
+ if (appDeploying != null) {
|
|
|
|
|
+ String opsBy = UserContext.getUsername();
|
|
|
|
|
+ if (opsBy.equals(NotAvailable.na.getDesc())) {
|
|
|
|
|
+ opsBy = appBuilding.getOpsBy();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ appDeploying.setDeployTime(LocalDateTime.now());
|
|
|
|
|
+ appDeploying.setDeployStatus(BuildStatus.OpsRunning.name());
|
|
|
appDeploying.setOpsBy(opsBy);
|
|
appDeploying.setOpsBy(opsBy);
|
|
|
|
|
+ appDeploying.updateBeforeDeploy();
|
|
|
|
|
+ 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
|
|
@Override
|
|
@@ -235,34 +235,18 @@ public class AppDeployServiceImpl implements AppDeployService {
|
|
|
|
|
|
|
|
AppDeployConfig deployConfig = deployConfigRepository.findByAppConfig_AppIdAndMachineInfo_MachineId(appId, machineId);
|
|
AppDeployConfig deployConfig = deployConfigRepository.findByAppConfig_AppIdAndMachineInfo_MachineId(appId, machineId);
|
|
|
if (deployConfig == null) {
|
|
if (deployConfig == null) {
|
|
|
|
|
+ log.error("AppDeployConfig with appId {} not exist", appId);
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
AppDeploying appDeploying = appDeployingRepository.findByAppDeployConfigId(deployConfig.getId());
|
|
AppDeploying appDeploying = appDeployingRepository.findByAppDeployConfigId(deployConfig.getId());
|
|
|
if (appDeploying == null) {
|
|
if (appDeploying == null) {
|
|
|
|
|
+ log.error("AppDeploying with appId {} not exist", appId);
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
String stepStatus = deployResult.getDeployStepStatus();
|
|
String stepStatus = deployResult.getDeployStepStatus();
|
|
|
- appDeploying.getSteps().stream()
|
|
|
|
|
- .filter(s -> s.getStepName().equals(stepName))
|
|
|
|
|
- .findFirst()
|
|
|
|
|
- .ifPresent(step -> {
|
|
|
|
|
- step.setStatus(stepStatus);
|
|
|
|
|
- step.setErrorMsg(errorMsg);
|
|
|
|
|
- // 记录时间
|
|
|
|
|
- if (StepStatus.RUNNING.name().equals(stepStatus)) {
|
|
|
|
|
- step.setStartTime(LocalDateTime.now());
|
|
|
|
|
- } else if (StepStatus.SUCCESS.name().equals(stepStatus)
|
|
|
|
|
- || StepStatus.FAILURE.name().equals(stepStatus)) {
|
|
|
|
|
- LocalDateTime endTime = LocalDateTime.now();
|
|
|
|
|
- // 计算总耗时
|
|
|
|
|
- long seconds = Duration.between(step.getStartTime(), endTime).getSeconds();
|
|
|
|
|
- step.setEndTime(endTime);
|
|
|
|
|
- step.setDuration(seconds);
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
|
|
+ appDeploying.updateStep(stepName, stepStatus, errorMsg);
|
|
|
if (stepName.equals(DeployStepName.HEALTH_CHECK.name())) {
|
|
if (stepName.equals(DeployStepName.HEALTH_CHECK.name())) {
|
|
|
appDeployingRepository.save(appDeploying);
|
|
appDeployingRepository.save(appDeploying);
|
|
|
return;
|
|
return;
|
|
@@ -273,9 +257,9 @@ public class AppDeployServiceImpl implements AppDeployService {
|
|
|
String machineIpv4 = deployConfig.getMachineInfo().getMachineIpv4();
|
|
String machineIpv4 = deployConfig.getMachineInfo().getMachineIpv4();
|
|
|
log.info("部署在 {} 的应用 {} 已完成", machineIpv4, appId);
|
|
log.info("部署在 {} 的应用 {} 已完成", machineIpv4, appId);
|
|
|
if (stepStatus.equals(StepStatus.FAILURE.name())) {
|
|
if (stepStatus.equals(StepStatus.FAILURE.name())) {
|
|
|
- appDeploying.setDeployResult(DeployStatus.deployFail.getDesc());
|
|
|
|
|
|
|
+ appDeploying.setDeployStatus(BuildStatus.OpsFail.name());
|
|
|
} else {
|
|
} else {
|
|
|
- appDeploying.setDeployResult(DeployStatus.deploySuccess.getDesc());
|
|
|
|
|
|
|
+ appDeploying.setDeployStatus(BuildStatus.OpsSuccess.name());
|
|
|
appDeploying.setRunning(deployResult.getRunning());
|
|
appDeploying.setRunning(deployResult.getRunning());
|
|
|
appDeploying.setStartTime(DateTimeConverter.localDateTime(deployResult.getStartTime()));
|
|
appDeploying.setStartTime(DateTimeConverter.localDateTime(deployResult.getStartTime()));
|
|
|
appDeploying.setPid(deployResult.getPid());
|
|
appDeploying.setPid(deployResult.getPid());
|
|
@@ -285,11 +269,9 @@ public class AppDeployServiceImpl implements AppDeployService {
|
|
|
AppDeployConfig appDeployConfig = appDeploying.getAppDeployConfig();
|
|
AppDeployConfig appDeployConfig = appDeploying.getAppDeployConfig();
|
|
|
BuildLog buildLog = appBuildQuery.getAppBuilding(appId).getBuildLog();
|
|
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());
|
|
log.info("{} 的通知已发送", deployResult.getAppId());
|
|
|
AppConfig appConfig = deployConfig.getAppConfig();
|
|
AppConfig appConfig = deployConfig.getAppConfig();
|
|
@@ -302,6 +284,27 @@ public class AppDeployServiceImpl implements AppDeployService {
|
|
|
appDeployingRepository.save(appDeploying);
|
|
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 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(appDeploying.getDeployStatus());
|
|
|
|
|
+ deployLog.setErrorMsg(deployResult.getErrorMsg());
|
|
|
|
|
+ deployLog.setStepJson(stepJson);
|
|
|
|
|
+ deployLog.setConfigSnapshot(configSnapshot);
|
|
|
|
|
+ return deployLog;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
private void refreshCdn(AppConfig appConfig, BuildLog buildLog) {
|
|
private void refreshCdn(AppConfig appConfig, BuildLog buildLog) {
|
|
|
String buildId = buildLog.getBuildLogId();
|
|
String buildId = buildLog.getBuildLogId();
|
|
|
String appId = appConfig.getAppId();
|
|
String appId = appConfig.getAppId();
|