|
|
@@ -8,22 +8,21 @@ import cn.reghao.autodop.dmaster.app.entity.build.update.AppUpdate;
|
|
|
import cn.reghao.autodop.dmaster.app.entity.orchestration.AppOrchestration;
|
|
|
import cn.reghao.autodop.dmaster.app.entity.orchestration.Notification;
|
|
|
import cn.reghao.autodop.dmaster.app.entity.orchestration.ProjOrchestration;
|
|
|
-import cn.reghao.autodop.dmaster.app.repository.AppDAO;
|
|
|
+import cn.reghao.autodop.dmaster.app.repository.orchestration.ProjDAO;
|
|
|
import cn.reghao.autodop.dmaster.app.repository.build.AppCompileRepository;
|
|
|
import cn.reghao.autodop.dmaster.app.repository.build.AppPackRepository;
|
|
|
import cn.reghao.autodop.dmaster.app.repository.build.AppUpdateRepository;
|
|
|
import cn.reghao.autodop.dmaster.app.repository.orchestration.AppOrchestrationRepository;
|
|
|
import cn.reghao.autodop.dmaster.app.repository.orchestration.NotificationRepository;
|
|
|
import cn.reghao.autodop.dmaster.app.repository.orchestration.ProjectOrchestrationRepository;
|
|
|
-import cn.reghao.autodop.dmaster.app.vo.AppVO;
|
|
|
import cn.reghao.autodop.dmaster.app.vo.PageList;
|
|
|
-import cn.reghao.autodop.dmaster.app.vo.ProjVO;
|
|
|
-import cn.reghao.autodop.dmaster.common.webresult.WebResult;
|
|
|
+import cn.reghao.autodop.dmaster.app.vo.ResultVO;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.data.domain.PageRequest;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
|
@@ -31,29 +30,29 @@ import java.util.List;
|
|
|
* @date 2020-02-28 17:10:37
|
|
|
*/
|
|
|
@Service
|
|
|
-public class OrchestrateService {
|
|
|
+public class AppOrchestrateService {
|
|
|
private ProjectOrchestrationRepository projRepository;
|
|
|
private AppOrchestrationRepository appRepository;
|
|
|
private AppUpdateRepository appUpdateRepository;
|
|
|
private AppCompileRepository appCompileRepository;
|
|
|
private AppPackRepository appPackRepository;
|
|
|
private NotificationRepository notificationRepository;
|
|
|
- private AppDAO appDAO;
|
|
|
-
|
|
|
- public OrchestrateService(ProjectOrchestrationRepository projRepository,
|
|
|
- AppOrchestrationRepository appRepository,
|
|
|
- AppUpdateRepository appUpdateRepository,
|
|
|
- AppCompileRepository appCompileRepository,
|
|
|
- AppPackRepository appPackRepository,
|
|
|
- NotificationRepository notificationRepository,
|
|
|
- AppDAO appDAO) {
|
|
|
+ private ProjDAO projDAO;
|
|
|
+
|
|
|
+ public AppOrchestrateService(ProjectOrchestrationRepository projRepository,
|
|
|
+ AppOrchestrationRepository appRepository,
|
|
|
+ AppUpdateRepository appUpdateRepository,
|
|
|
+ AppCompileRepository appCompileRepository,
|
|
|
+ AppPackRepository appPackRepository,
|
|
|
+ NotificationRepository notificationRepository,
|
|
|
+ ProjDAO projDAO) {
|
|
|
this.projRepository = projRepository;
|
|
|
this.appRepository = appRepository;
|
|
|
this.appUpdateRepository = appUpdateRepository;
|
|
|
this.appCompileRepository = appCompileRepository;
|
|
|
this.appPackRepository = appPackRepository;
|
|
|
this.notificationRepository = notificationRepository;
|
|
|
- this.appDAO = appDAO;
|
|
|
+ this.projDAO = projDAO;
|
|
|
}
|
|
|
|
|
|
public void add(int type, String json) {
|
|
|
@@ -70,22 +69,57 @@ public class OrchestrateService {
|
|
|
// 应用编排
|
|
|
// TODO 添加应用的配置文件
|
|
|
AppOrchestration app = (AppOrchestration) JsonUtil.jsonToObject(json, AppOrchestration.class);
|
|
|
- String projId = app.getProjId();
|
|
|
- if (projId == null) {
|
|
|
- appBuild = app.getAppBuild();
|
|
|
- checkSharedEntity(appBuild);
|
|
|
- }
|
|
|
+ saveApp(app);
|
|
|
+ default:
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- Notification notification = app.getNotification();
|
|
|
- Notification notifyEntity = notificationRepository.findByNotifyName(notification.getNotifyName());
|
|
|
- if (notifyEntity != null) {
|
|
|
- app.setNotification(notifyEntity);
|
|
|
- } else {
|
|
|
- notificationRepository.save(notification);
|
|
|
- }
|
|
|
+ private void saveApp(AppOrchestration app) {
|
|
|
+ String projId = app.getProjId();
|
|
|
+ if (projId == null) {
|
|
|
+ AppBuild appBuild = app.getAppBuild();
|
|
|
+ checkSharedEntity(appBuild);
|
|
|
+ }
|
|
|
+
|
|
|
+ Notification notification = app.getNotification();
|
|
|
+ Notification notifyEntity = notificationRepository.findByNotifyName(notification.getNotifyName());
|
|
|
+ if (notifyEntity != null) {
|
|
|
+ app.setNotification(notifyEntity);
|
|
|
+ } else {
|
|
|
+ notificationRepository.save(notification);
|
|
|
+ }
|
|
|
+
|
|
|
+ appRepository.save(app);
|
|
|
+ }
|
|
|
|
|
|
- appRepository.save(app);
|
|
|
+ public boolean duplicate(int type, String from, String to) throws Exception {
|
|
|
+ switch (type) {
|
|
|
+ case 1:
|
|
|
+ ProjOrchestration projEntity = projRepository.findByProjId(from);
|
|
|
+ ProjOrchestration proj = projRepository.findByProjId(to);
|
|
|
+ if (projEntity != null && proj == null) {
|
|
|
+ proj = (ProjOrchestration) projEntity.clone();
|
|
|
+ proj.setProjId(to);
|
|
|
+ proj.setId(null);
|
|
|
+ checkSharedEntity(proj.getAppBuild());
|
|
|
+ projRepository.save(proj);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ case 2:
|
|
|
+ AppOrchestration appEntity = appRepository.findByAppId(from);
|
|
|
+ AppOrchestration app = appRepository.findByAppId(to);
|
|
|
+ if (appEntity != null && app == null) {
|
|
|
+ app = (AppOrchestration) appEntity.clone();
|
|
|
+ app.setAppId(to);
|
|
|
+ app.setId(null);
|
|
|
+ // TODO 复制共享实体
|
|
|
+ app.setConfigFiles(null);
|
|
|
+ app.getAppDeploy().setLogs(null);
|
|
|
+ saveApp(app);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
default:
|
|
|
+ return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -126,81 +160,77 @@ public class OrchestrateService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public void batchAdd(int type, String json) throws Exception {
|
|
|
- // TODO 优化代码
|
|
|
- AppBuild appBuild;
|
|
|
+ public Object get(int type, String id) {
|
|
|
switch (type) {
|
|
|
case 1:
|
|
|
- List<Object> objs = JsonUtil.jsonToObjectArray(json, ProjOrchestration.class);
|
|
|
- List<ProjOrchestration> projs = new ArrayList<>();
|
|
|
- for (Object obj : objs) {
|
|
|
- ProjOrchestration proj = (ProjOrchestration) obj;
|
|
|
- appBuild = proj.getAppBuild();
|
|
|
- checkSharedEntity(appBuild);
|
|
|
- projs.add(proj);
|
|
|
- }
|
|
|
- projRepository.saveAll(projs);
|
|
|
- break;
|
|
|
+ ProjOrchestration proj = projRepository.findByProjId(id);
|
|
|
+ return ResultVO.projVO(proj);
|
|
|
case 2:
|
|
|
- List<Object> objs1 = JsonUtil.jsonToObjectArray(json, AppOrchestration.class);
|
|
|
- List<AppOrchestration> apps = new ArrayList<>();
|
|
|
- for (Object obj : objs1) {
|
|
|
- AppOrchestration app = (AppOrchestration) obj;
|
|
|
- String projId = app.getProjId();
|
|
|
- if (projId == null) {
|
|
|
- appBuild = app.getAppBuild();
|
|
|
- checkSharedEntity(appBuild);
|
|
|
- }
|
|
|
- Notification notification = app.getNotification();
|
|
|
- Notification notifyEntity = notificationRepository.findByNotifyName(notification.getNotifyName());
|
|
|
- if (notifyEntity != null) {
|
|
|
- app.setNotification(notifyEntity);
|
|
|
- } else {
|
|
|
- notificationRepository.save(notification);
|
|
|
- }
|
|
|
- apps.add(app);
|
|
|
- }
|
|
|
- // TODO 使用 saveAll 时若多个编排中具有相同的 UNIQUE 约束值会引发 UNIQUE 约束异常
|
|
|
- appRepository.saveAll(apps);
|
|
|
+ AppOrchestration app = appRepository.findByAppId(id);
|
|
|
+ return ResultVO.appVO(app);
|
|
|
default:
|
|
|
+ return "编排类型错误";
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public String getByPage(int type, PageRequest pageRequest) {
|
|
|
+ public Object getByPage(int type, PageRequest pageRequest) {
|
|
|
switch (type) {
|
|
|
case 1:
|
|
|
Page<ProjOrchestration> projPages = projRepository.findAll(pageRequest);
|
|
|
- List<ProjVO> vos = new ArrayList<>();
|
|
|
+ List<ProjOrchestration> projVOs = new ArrayList<>();
|
|
|
projPages.forEach(proj -> {
|
|
|
- List<String> appIds = appDAO.findAppsByProjId(proj.getProjId());
|
|
|
- ProjVO vo = ProjVO.of(proj, appIds.toString()
|
|
|
- .replace("[", "").replace("]", ""));
|
|
|
- vos.add(vo);
|
|
|
+ projVOs.add(ResultVO.projVO(proj));
|
|
|
});
|
|
|
|
|
|
- PageList<ProjVO> list = new PageList<>();
|
|
|
- list.setList(vos);
|
|
|
- list.setSize(vos.size());
|
|
|
-
|
|
|
- return WebResult.success(list);
|
|
|
+ PageList<ProjOrchestration> projs = new PageList<>();
|
|
|
+ projs.setList(projVOs);
|
|
|
+ projs.setSize(projVOs.size());
|
|
|
+ return projs;
|
|
|
case 2:
|
|
|
Page<AppOrchestration> appPages = appRepository.findAll(pageRequest);
|
|
|
- List<AppVO> appVOS = new ArrayList<>();
|
|
|
+ List<AppOrchestration> appVOs = new ArrayList<>();
|
|
|
appPages.getContent().forEach(app -> {
|
|
|
- appVOS.add(AppVO.of(app));
|
|
|
+ appVOs.add(ResultVO.appVO(app));
|
|
|
});
|
|
|
|
|
|
- PageList<AppVO> list1 = new PageList<>();
|
|
|
- list1.setList(appVOS);
|
|
|
- list1.setSize(appVOS.size());
|
|
|
-
|
|
|
- return WebResult.success(list1);
|
|
|
+ PageList<AppOrchestration> apps = new PageList<>();
|
|
|
+ apps.setList(appVOs);
|
|
|
+ apps.setSize(appVOs.size());
|
|
|
+ return apps;
|
|
|
default:
|
|
|
- return WebResult.fail("编排类型错误");
|
|
|
+ return "编排类型错误";
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public void modify(int type, String json) {
|
|
|
+ public boolean modify(int type, String json) {
|
|
|
+ switch (type) {
|
|
|
+ case 1:
|
|
|
+ ProjOrchestration proj = (ProjOrchestration) JsonUtil.jsonToObject(json, ProjOrchestration.class);
|
|
|
+ ProjOrchestration projEntity = projRepository.findByProjId(proj.getProjId());
|
|
|
+ if (projEntity != null) {
|
|
|
+ AppBuild appBuild = proj.getAppBuild();
|
|
|
+ checkSharedEntity(appBuild);
|
|
|
+
|
|
|
+ proj.setId(projEntity.getId());
|
|
|
+ proj.setCreateTime(projEntity.getCreateTime());
|
|
|
+ proj.setUpdateTime(new Date());
|
|
|
+ projRepository.save(proj);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ case 2:
|
|
|
+ AppOrchestration app = (AppOrchestration) JsonUtil.jsonToObject(json, AppOrchestration.class);
|
|
|
+ String appId = app.getAppId();
|
|
|
+ AppOrchestration appEntity = appRepository.findByAppId(appId);
|
|
|
+ if (appEntity != null) {
|
|
|
+ app.setId(appEntity.getId());
|
|
|
+ app.setCreateTime(appEntity.getCreateTime());
|
|
|
+ app.setUpdateTime(new Date());
|
|
|
+ saveApp(app);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ default:
|
|
|
+ return false;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public void delete(int type, String appId) {
|