|
|
@@ -9,10 +9,10 @@ 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;
|
|
|
+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.app.db.repository.AppDeployConfigRepository;
|
|
|
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.DeployConfigUpdateDto;
|
|
|
import cn.reghao.devops.mgr.ops.builder.model.po.AppBuilding;
|
|
|
@@ -27,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.service.MachineQuery;
|
|
|
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.ResultStatus;
|
|
|
import cn.reghao.jutil.jdk.serializer.JsonConverter;
|
|
|
import cn.reghao.jutil.jdk.thread.ThreadPoolWrapper;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
@@ -38,7 +38,6 @@ import org.springframework.util.StringUtils;
|
|
|
|
|
|
import java.time.Duration;
|
|
|
import java.time.LocalDateTime;
|
|
|
-import java.util.Arrays;
|
|
|
import java.util.List;
|
|
|
import java.util.concurrent.ScheduledExecutorService;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
@@ -83,14 +82,14 @@ public class AppDeployServiceImpl implements AppDeployService {
|
|
|
AppConfig appConfig = appBuildQuery.getAppConfig(appId);
|
|
|
if (appConfig == null) {
|
|
|
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();
|
|
|
MachineInfo machineInfo = machineQuery.getMachineInfo(machineId);
|
|
|
if (machineInfo == null) {
|
|
|
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();
|
|
|
@@ -106,13 +105,8 @@ public class AppDeployServiceImpl implements AppDeployService {
|
|
|
deployConfigRepository.save(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);
|
|
|
- return Result.result(ResultStatus.SUCCESS);
|
|
|
+ return Result.result(cn.reghao.jutil.jdk.web.result.ResultStatus.SUCCESS);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -122,7 +116,7 @@ public class AppDeployServiceImpl implements AppDeployService {
|
|
|
AppDeployConfig appDeployConfig = appDeployQuery.getByAppIdAndMachineId(appId, machineId);
|
|
|
if (appDeployConfig == null) {
|
|
|
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();
|
|
|
@@ -136,7 +130,7 @@ public class AppDeployServiceImpl implements AppDeployService {
|
|
|
|
|
|
appDeployConfig.setStartScript(startScript);
|
|
|
deployConfigRepository.save(appDeployConfig);
|
|
|
- return Result.result(ResultStatus.SUCCESS);
|
|
|
+ return Result.result(cn.reghao.jutil.jdk.web.result.ResultStatus.SUCCESS);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -149,7 +143,7 @@ public class AppDeployServiceImpl implements AppDeployService {
|
|
|
public Result deleteDeployConfig(int appDeployConfigId) {
|
|
|
AppDeployConfig appDeployConfig = deployConfigRepository.findById(appDeployConfigId).orElse(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);
|
|
|
@@ -162,10 +156,10 @@ public class AppDeployServiceImpl implements AppDeployService {
|
|
|
appDeployingRepository.delete(appDeploying);
|
|
|
deployLogRepository.deleteByAppDeployConfig_MachineInfo_MachineId(machineId);
|
|
|
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
|
|
|
@@ -173,12 +167,12 @@ public class AppDeployServiceImpl implements AppDeployService {
|
|
|
List<AppDeployConfig> list = deployConfigRepository.findByAppConfig_AppId(appId);
|
|
|
for (AppDeployConfig appDeployConfig : list) {
|
|
|
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.result(ResultStatus.SUCCESS);
|
|
|
+ return Result.result(cn.reghao.jutil.jdk.web.result.ResultStatus.SUCCESS);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -217,9 +211,14 @@ public class AppDeployServiceImpl implements AppDeployService {
|
|
|
AppDeploying appDeploying = appDeployingRepository.findByAppDeployConfig_AppConfig_AppIdAndAppDeployConfig_MachineInfo_MachineId(appId, machineId);
|
|
|
if (appDeploying != null) {
|
|
|
String opsBy = UserContext.getUsername();
|
|
|
+ if (opsBy.equals(NotAvailable.na.getDesc())) {
|
|
|
+ opsBy = appBuilding.getOpsBy();
|
|
|
+ }
|
|
|
+
|
|
|
appDeploying.setDeployTime(LocalDateTime.now());
|
|
|
- appDeploying.setDeployResult(DeployStatus.onDeploying.getDesc());
|
|
|
+ appDeploying.setDeployStatus(BuildStatus.OpsRunning.name());
|
|
|
appDeploying.setOpsBy(opsBy);
|
|
|
+ appDeploying.updateBeforeDeploy();
|
|
|
appDeployingRepository.save(appDeploying);
|
|
|
} else {
|
|
|
log.error("AppDeploying with appId {} not exist", appId);
|
|
|
@@ -247,25 +246,7 @@ public class AppDeployServiceImpl implements AppDeployService {
|
|
|
}
|
|
|
|
|
|
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())) {
|
|
|
appDeployingRepository.save(appDeploying);
|
|
|
return;
|
|
|
@@ -276,9 +257,9 @@ public class AppDeployServiceImpl implements AppDeployService {
|
|
|
String machineIpv4 = deployConfig.getMachineInfo().getMachineIpv4();
|
|
|
log.info("部署在 {} 的应用 {} 已完成", machineIpv4, appId);
|
|
|
if (stepStatus.equals(StepStatus.FAILURE.name())) {
|
|
|
- appDeploying.setDeployResult(DeployStatus.deployFail.getDesc());
|
|
|
+ appDeploying.setDeployStatus(BuildStatus.OpsFail.name());
|
|
|
} else {
|
|
|
- appDeploying.setDeployResult(DeployStatus.deploySuccess.getDesc());
|
|
|
+ appDeploying.setDeployStatus(BuildStatus.OpsSuccess.name());
|
|
|
appDeploying.setRunning(deployResult.getRunning());
|
|
|
appDeploying.setStartTime(DateTimeConverter.localDateTime(deployResult.getStartTime()));
|
|
|
appDeploying.setPid(deployResult.getPid());
|
|
|
@@ -307,7 +288,6 @@ public class AppDeployServiceImpl implements AppDeployService {
|
|
|
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();
|
|
|
@@ -318,7 +298,7 @@ public class AppDeployServiceImpl implements AppDeployService {
|
|
|
deployLog.setStartTime(startTime);
|
|
|
deployLog.setEndTime(endTime);
|
|
|
deployLog.setDuration(seconds);
|
|
|
- deployLog.setStatus(stepStatus);
|
|
|
+ deployLog.setStatus(appDeploying.getDeployStatus());
|
|
|
deployLog.setErrorMsg(deployResult.getErrorMsg());
|
|
|
deployLog.setStepJson(stepJson);
|
|
|
deployLog.setConfigSnapshot(configSnapshot);
|