|
@@ -1,21 +1,19 @@
|
|
|
-package cn.reghao.autodop.dmaster.app.service.crud.orchestarte;
|
|
|
|
|
|
|
+package cn.reghao.autodop.dmaster.app.service.config.app;
|
|
|
|
|
|
|
|
import cn.reghao.autodop.dmaster.app.constant.AppType;
|
|
import cn.reghao.autodop.dmaster.app.constant.AppType;
|
|
|
import cn.reghao.autodop.dmaster.common.db.CrudOps;
|
|
import cn.reghao.autodop.dmaster.common.db.CrudOps;
|
|
|
import cn.reghao.autodop.dmaster.common.db.PageList;
|
|
import cn.reghao.autodop.dmaster.common.db.PageList;
|
|
|
import cn.reghao.autodop.dmaster.app.entity.status.BuildDeployApp;
|
|
import cn.reghao.autodop.dmaster.app.entity.status.BuildDeployApp;
|
|
|
-import cn.reghao.autodop.dmaster.app.entity.config.AppConfig;
|
|
|
|
|
|
|
+import cn.reghao.autodop.dmaster.app.entity.config.AppOrchestration;
|
|
|
import cn.reghao.autodop.dmaster.app.repository.config.AppConfigRepository;
|
|
import cn.reghao.autodop.dmaster.app.repository.config.AppConfigRepository;
|
|
|
-import cn.reghao.autodop.dmaster.app.service.crud.BuildDeployAppCrudService;
|
|
|
|
|
-import cn.reghao.autodop.dmaster.app.service.crud.SharedEntityChecker;
|
|
|
|
|
|
|
+import cn.reghao.autodop.dmaster.app.service.config.BuildDeployAppCrudService;
|
|
|
|
|
+import cn.reghao.autodop.dmaster.app.service.config.SharedEntityChecker;
|
|
|
import org.springframework.data.domain.Page;
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.data.domain.PageRequest;
|
|
import org.springframework.data.domain.PageRequest;
|
|
|
import org.springframework.data.domain.Sort;
|
|
import org.springframework.data.domain.Sort;
|
|
|
import org.springframework.data.jpa.domain.Specification;
|
|
import org.springframework.data.jpa.domain.Specification;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
-import javax.persistence.criteria.Join;
|
|
|
|
|
-import javax.persistence.criteria.JoinType;
|
|
|
|
|
import javax.persistence.criteria.Predicate;
|
|
import javax.persistence.criteria.Predicate;
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
@@ -26,7 +24,7 @@ import java.util.List;
|
|
|
*/
|
|
*/
|
|
|
//@CacheConfig(cacheNames = {"appCache"})
|
|
//@CacheConfig(cacheNames = {"appCache"})
|
|
|
@Service
|
|
@Service
|
|
|
-public class AppCrudService implements CrudOps<AppConfig> {
|
|
|
|
|
|
|
+public class AppCrudService implements CrudOps<AppOrchestration> {
|
|
|
private AppConfigRepository appRepository;
|
|
private AppConfigRepository appRepository;
|
|
|
private SharedEntityChecker sharedEntityChecker;
|
|
private SharedEntityChecker sharedEntityChecker;
|
|
|
private BuildDeployAppCrudService buildDeployAppCrudService;
|
|
private BuildDeployAppCrudService buildDeployAppCrudService;
|
|
@@ -40,9 +38,9 @@ public class AppCrudService implements CrudOps<AppConfig> {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public void add(AppConfig app) throws Exception {
|
|
|
|
|
|
|
+ public void add(AppOrchestration app) throws Exception {
|
|
|
checkSharedEntity(app);
|
|
checkSharedEntity(app);
|
|
|
- AppConfig appEntity = appRepository.findByIsDeleteFalseAndAppId(app.getAppId());
|
|
|
|
|
|
|
+ AppOrchestration appEntity = appRepository.findByIsDeleteFalseAndAppId(app.getAppId());
|
|
|
if (appEntity == null) {
|
|
if (appEntity == null) {
|
|
|
app.setIsDelete(false);
|
|
app.setIsDelete(false);
|
|
|
appRepository.save(app);
|
|
appRepository.save(app);
|
|
@@ -51,9 +49,9 @@ public class AppCrudService implements CrudOps<AppConfig> {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public void update(AppConfig app) throws Exception {
|
|
|
|
|
|
|
+ public void update(AppOrchestration app) throws Exception {
|
|
|
checkSharedEntity(app);
|
|
checkSharedEntity(app);
|
|
|
- AppConfig appEntity = appRepository.findByIsDeleteFalseAndAppId(app.getAppId());
|
|
|
|
|
|
|
+ AppOrchestration appEntity = appRepository.findByIsDeleteFalseAndAppId(app.getAppId());
|
|
|
if (appEntity != null) {
|
|
if (appEntity != null) {
|
|
|
app.setId(appEntity.getId());
|
|
app.setId(appEntity.getId());
|
|
|
app.setCreateTime(appEntity.getCreateTime());
|
|
app.setCreateTime(appEntity.getCreateTime());
|
|
@@ -64,27 +62,25 @@ public class AppCrudService implements CrudOps<AppConfig> {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private void checkSharedEntity(AppConfig app) throws Exception {
|
|
|
|
|
|
|
+ private void checkSharedEntity(AppOrchestration app) throws Exception {
|
|
|
if (app.getProj() != null) {
|
|
if (app.getProj() != null) {
|
|
|
sharedEntityChecker.checkAndSetProj(app);
|
|
sharedEntityChecker.checkAndSetProj(app);
|
|
|
} else {
|
|
} else {
|
|
|
sharedEntityChecker.checkAndSetBuildConfig(app.getBuildConfig());
|
|
sharedEntityChecker.checkAndSetBuildConfig(app.getBuildConfig());
|
|
|
}
|
|
}
|
|
|
- sharedEntityChecker.checkAndSetNotifier(app);
|
|
|
|
|
sharedEntityChecker.checkAndSetRole(app);
|
|
sharedEntityChecker.checkAndSetRole(app);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public void addOrUpdate(AppConfig app) throws Exception {
|
|
|
|
|
|
|
+ public void addOrUpdate(AppOrchestration app) throws Exception {
|
|
|
if (app.getProj() != null) {
|
|
if (app.getProj() != null) {
|
|
|
sharedEntityChecker.checkAndSetProj(app);
|
|
sharedEntityChecker.checkAndSetProj(app);
|
|
|
} else {
|
|
} else {
|
|
|
sharedEntityChecker.checkAndSetBuildConfig(app.getBuildConfig());
|
|
sharedEntityChecker.checkAndSetBuildConfig(app.getBuildConfig());
|
|
|
}
|
|
}
|
|
|
- sharedEntityChecker.checkAndSetNotifier(app);
|
|
|
|
|
sharedEntityChecker.checkAndSetRole(app);
|
|
sharedEntityChecker.checkAndSetRole(app);
|
|
|
|
|
|
|
|
- AppConfig appEntity = appRepository.findByIsDeleteFalseAndAppId(app.getAppId());
|
|
|
|
|
|
|
+ AppOrchestration appEntity = appRepository.findByIsDeleteFalseAndAppId(app.getAppId());
|
|
|
if (appEntity != null) {
|
|
if (appEntity != null) {
|
|
|
app.setId(appEntity.getId());
|
|
app.setId(appEntity.getId());
|
|
|
app.setCreateTime(appEntity.getCreateTime());
|
|
app.setCreateTime(appEntity.getCreateTime());
|
|
@@ -96,21 +92,21 @@ public class AppCrudService implements CrudOps<AppConfig> {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public void copy(String from, String to) throws Exception {
|
|
public void copy(String from, String to) throws Exception {
|
|
|
- AppConfig fromApp = appRepository.findByIsDeleteFalseAndAppId(from);
|
|
|
|
|
|
|
+ AppOrchestration fromApp = appRepository.findByIsDeleteFalseAndAppId(from);
|
|
|
if (fromApp == null) {
|
|
if (fromApp == null) {
|
|
|
throw new Exception("ID 为 " + from + " 的应用配置不存在...");
|
|
throw new Exception("ID 为 " + from + " 的应用配置不存在...");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- AppConfig toApp = appRepository.findByIsDeleteFalseAndAppId(to);
|
|
|
|
|
|
|
+ AppOrchestration toApp = appRepository.findByIsDeleteFalseAndAppId(to);
|
|
|
if (toApp == null) {
|
|
if (toApp == null) {
|
|
|
- toApp = (AppConfig) fromApp.clone();
|
|
|
|
|
|
|
+ toApp = (AppOrchestration) fromApp.clone();
|
|
|
copyToDifferentBranch(toApp, to);
|
|
copyToDifferentBranch(toApp, to);
|
|
|
appRepository.save(toApp);
|
|
appRepository.save(toApp);
|
|
|
buildDeployAppCrudService.addOrUpdate(BuildDeployApp.of(toApp));
|
|
buildDeployAppCrudService.addOrUpdate(BuildDeployApp.of(toApp));
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private void copyToDifferentBranch(AppConfig app, String to) {
|
|
|
|
|
|
|
+ private void copyToDifferentBranch(AppOrchestration app, String to) {
|
|
|
app.setAppId(to);
|
|
app.setAppId(to);
|
|
|
app.setBranch("");
|
|
app.setBranch("");
|
|
|
/*app.setDescription("");
|
|
/*app.setDescription("");
|
|
@@ -123,9 +119,9 @@ public class AppCrudService implements CrudOps<AppConfig> {
|
|
|
app.setRunningConfig(null);
|
|
app.setRunningConfig(null);
|
|
|
app.setNotifierConfig(null);*/
|
|
app.setNotifierConfig(null);*/
|
|
|
app.setDeployConfigs(null);
|
|
app.setDeployConfigs(null);
|
|
|
- if (app.getRunningConfig() != null) {
|
|
|
|
|
|
|
+ /*if (app.getRunningConfig() != null) {
|
|
|
app.getRunningConfig().setLogConfigs(null);
|
|
app.getRunningConfig().setLogConfigs(null);
|
|
|
- }
|
|
|
|
|
|
|
+ }*/
|
|
|
|
|
|
|
|
app.setId(null);
|
|
app.setId(null);
|
|
|
app.setCreateTime(null);
|
|
app.setCreateTime(null);
|
|
@@ -134,13 +130,13 @@ public class AppCrudService implements CrudOps<AppConfig> {
|
|
|
|
|
|
|
|
//@Cacheable("appList")
|
|
//@Cacheable("appList")
|
|
|
@Override
|
|
@Override
|
|
|
- public PageList<AppConfig> getByPage(int page, int size, String env) {
|
|
|
|
|
|
|
+ public PageList<AppOrchestration> getByPage(int page, int size, String env) {
|
|
|
// 默认按更新时间倒序
|
|
// 默认按更新时间倒序
|
|
|
PageRequest pageRequest =
|
|
PageRequest pageRequest =
|
|
|
PageRequest.of(page-1, size, Sort.by(Sort.Direction.DESC, "updateTime"));
|
|
PageRequest.of(page-1, size, Sort.by(Sort.Direction.DESC, "updateTime"));
|
|
|
// TODO 指定额外的参数
|
|
// TODO 指定额外的参数
|
|
|
- Page<AppConfig> page1 = appRepository.findByIsDeleteFalseAndEnv(env, pageRequest);
|
|
|
|
|
- PageList<AppConfig> pageList = new PageList<>();
|
|
|
|
|
|
|
+ Page<AppOrchestration> page1 = appRepository.findByIsDeleteFalseAndEnv(env, pageRequest);
|
|
|
|
|
+ PageList<AppOrchestration> pageList = new PageList<>();
|
|
|
pageList.setTotalSize(page1.getTotalElements());
|
|
pageList.setTotalSize(page1.getTotalElements());
|
|
|
pageList.setTotalPages(page1.getTotalPages());
|
|
pageList.setTotalPages(page1.getTotalPages());
|
|
|
pageList.setList(page1.getContent());
|
|
pageList.setList(page1.getContent());
|
|
@@ -150,7 +146,7 @@ public class AppCrudService implements CrudOps<AppConfig> {
|
|
|
//@CacheEvict(cacheNames = { "app" }, key = "#uniqueKey")
|
|
//@CacheEvict(cacheNames = { "app" }, key = "#uniqueKey")
|
|
|
@Override
|
|
@Override
|
|
|
public void delete(String uniqueKey) throws Exception {
|
|
public void delete(String uniqueKey) throws Exception {
|
|
|
- AppConfig appEntity = appRepository.findByIsDeleteFalseAndAppId(uniqueKey);
|
|
|
|
|
|
|
+ AppOrchestration appEntity = appRepository.findByIsDeleteFalseAndAppId(uniqueKey);
|
|
|
if (appEntity == null) {
|
|
if (appEntity == null) {
|
|
|
throw new Exception(uniqueKey + " 不存在");
|
|
throw new Exception(uniqueKey + " 不存在");
|
|
|
} else {
|
|
} else {
|
|
@@ -160,8 +156,8 @@ public class AppCrudService implements CrudOps<AppConfig> {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public List<AppConfig> find(String env) {
|
|
|
|
|
- Specification<AppConfig> spec = (Specification<AppConfig>) (root, query, cb) -> {
|
|
|
|
|
|
|
+ public List<AppOrchestration> find(String env) {
|
|
|
|
|
+ Specification<AppOrchestration> spec = (Specification<AppOrchestration>) (root, query, cb) -> {
|
|
|
Predicate predicate1 = cb.equal(root.get("env"), env);
|
|
Predicate predicate1 = cb.equal(root.get("env"), env);
|
|
|
Predicate predicate2 = cb.equal(root.get("appType"), AppType.dotnetCore.name());
|
|
Predicate predicate2 = cb.equal(root.get("appType"), AppType.dotnetCore.name());
|
|
|
return cb.and(predicate1, predicate2);
|
|
return cb.and(predicate1, predicate2);
|