|
@@ -1,5 +1,6 @@
|
|
|
package cn.reghao.devops.mgr.ops.app.service.impl;
|
|
package cn.reghao.devops.mgr.ops.app.service.impl;
|
|
|
|
|
|
|
|
|
|
+import cn.reghao.devops.common.model.DockerParams;
|
|
|
import cn.reghao.devops.common.msg.DeployStepName;
|
|
import cn.reghao.devops.common.msg.DeployStepName;
|
|
|
import cn.reghao.devops.common.docker.model.DockerContainerConfig;
|
|
import cn.reghao.devops.common.docker.model.DockerContainerConfig;
|
|
|
import cn.reghao.devops.common.msg.constant.PackType;
|
|
import cn.reghao.devops.common.msg.constant.PackType;
|
|
@@ -14,7 +15,6 @@ 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.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.builder.model.po.AppBuilding;
|
|
import cn.reghao.devops.mgr.ops.builder.model.po.AppBuilding;
|
|
|
import cn.reghao.devops.mgr.ops.builder.model.po.AppDeploying;
|
|
import cn.reghao.devops.mgr.ops.builder.model.po.AppDeploying;
|
|
|
import cn.reghao.devops.mgr.ops.app.model.po.AppConfig;
|
|
import cn.reghao.devops.mgr.ops.app.model.po.AppConfig;
|
|
@@ -31,6 +31,7 @@ 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.serializer.JsonConverter;
|
|
import cn.reghao.jutil.jdk.serializer.JsonConverter;
|
|
|
import cn.reghao.jutil.jdk.thread.ThreadPoolWrapper;
|
|
import cn.reghao.jutil.jdk.thread.ThreadPoolWrapper;
|
|
|
|
|
+import cn.reghao.jutil.jdk.web.result.ResultStatus;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
@@ -82,56 +83,54 @@ 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(cn.reghao.jutil.jdk.web.result.ResultStatus.ERROR, msg);
|
|
|
|
|
|
|
+ return Result.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(cn.reghao.jutil.jdk.web.result.ResultStatus.ERROR, msg);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- String startScript = deployConfigDto.getStartScript();
|
|
|
|
|
- if (startScript == null || startScript.isBlank()) {
|
|
|
|
|
- startScript = "{}";
|
|
|
|
|
|
|
+ return Result.result(ResultStatus.ERROR, msg);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ String startScript;
|
|
|
String packType = deployConfigDto.getPackType();
|
|
String packType = deployConfigDto.getPackType();
|
|
|
if (packType.equals(PackType.docker.name())) {
|
|
if (packType.equals(PackType.docker.name())) {
|
|
|
- DockerContainerConfig containerConfig = JsonConverter.jsonToObject(startScript, DockerContainerConfig.class);
|
|
|
|
|
|
|
+ DockerParams dockerParams = deployConfigDto.getDockerParams();
|
|
|
|
|
+ startScript = JsonConverter.objectToJson(dockerParams);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ startScript = deployConfigDto.getStartScript();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
AppDeployConfig appDeployConfig = new AppDeployConfig(appConfig, machineInfo, startScript);
|
|
AppDeployConfig appDeployConfig = new AppDeployConfig(appConfig, machineInfo, startScript);
|
|
|
deployConfigRepository.save(appDeployConfig);
|
|
deployConfigRepository.save(appDeployConfig);
|
|
|
-
|
|
|
|
|
AppDeploying appDeploying = new AppDeploying(appDeployConfig);
|
|
AppDeploying appDeploying = new AppDeploying(appDeployConfig);
|
|
|
appDeployingRepository.save(appDeploying);
|
|
appDeployingRepository.save(appDeploying);
|
|
|
- return Result.result(cn.reghao.jutil.jdk.web.result.ResultStatus.SUCCESS);
|
|
|
|
|
|
|
+ return Result.result(ResultStatus.SUCCESS);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public Result updateStartScript(DeployConfigUpdateDto deployConfigUpdateDto) {
|
|
|
|
|
- String appId = deployConfigUpdateDto.getAppId();
|
|
|
|
|
- String machineId = deployConfigUpdateDto.getMachineId();
|
|
|
|
|
|
|
+ public Result updateStartScript(DeployConfigDto deployConfigDto) {
|
|
|
|
|
+ String appId = deployConfigDto.getAppId();
|
|
|
|
|
+ String machineId = deployConfigDto.getMachineId();
|
|
|
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(cn.reghao.jutil.jdk.web.result.ResultStatus.ERROR, msg);
|
|
|
|
|
|
|
+ return Result.result(ResultStatus.ERROR, msg);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- String startScript = deployConfigUpdateDto.getStartScript();
|
|
|
|
|
String packType = appDeployConfig.getAppConfig().getPackerConfig().getType();
|
|
String packType = appDeployConfig.getAppConfig().getPackerConfig().getType();
|
|
|
if (packType.equals(PackType.docker.name())) {
|
|
if (packType.equals(PackType.docker.name())) {
|
|
|
- DockerContainerConfig containerConfig = JsonConverter.jsonToObject(startScript, DockerContainerConfig.class);
|
|
|
|
|
- if (startScript == null || startScript.isBlank()) {
|
|
|
|
|
- startScript = "{}";
|
|
|
|
|
|
|
+ DockerParams dockerParams = deployConfigDto.getDockerParams();
|
|
|
|
|
+ if (dockerParams == null) {
|
|
|
|
|
+ return Result.result(ResultStatus.FAIL, "param dockerParams is null");
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ appDeployConfig.setStartScript(JsonConverter.objectToJson(dockerParams));
|
|
|
|
|
+ deployConfigRepository.save(appDeployConfig);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- appDeployConfig.setStartScript(startScript);
|
|
|
|
|
- deployConfigRepository.save(appDeployConfig);
|
|
|
|
|
- return Result.result(cn.reghao.jutil.jdk.web.result.ResultStatus.SUCCESS);
|
|
|
|
|
|
|
+ return Result.result(ResultStatus.SUCCESS);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -144,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(cn.reghao.jutil.jdk.web.result.ResultStatus.FAIL, "AppDeployConfig not exists");
|
|
|
|
|
|
|
+ return Result.result(ResultStatus.FAIL, "AppDeployConfig not exists");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return deleteAppDeployConfig(appDeployConfig);
|
|
return deleteAppDeployConfig(appDeployConfig);
|
|
@@ -157,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(cn.reghao.jutil.jdk.web.result.ResultStatus.SUCCESS);
|
|
|
|
|
|
|
+ return Result.result(ResultStatus.SUCCESS);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- return Result.result(cn.reghao.jutil.jdk.web.result.ResultStatus.FAIL, "app is running");
|
|
|
|
|
|
|
+ return Result.result(ResultStatus.FAIL, "app is running");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -168,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() != cn.reghao.jutil.jdk.web.result.ResultStatus.SUCCESS.getCode()) {
|
|
|
|
|
|
|
+ if (result.getCode() != ResultStatus.SUCCESS.getCode()) {
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- return Result.result(cn.reghao.jutil.jdk.web.result.ResultStatus.SUCCESS);
|
|
|
|
|
|
|
+ return Result.result(ResultStatus.SUCCESS);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|