|
|
@@ -3,14 +3,22 @@ package cn.reghao.autodop.dmaster.app.repository.log;
|
|
|
import cn.reghao.autodop.dmaster.app.entity.deploy.DeployedApp;
|
|
|
import cn.reghao.autodop.dmaster.app.entity.log.BuildLog;
|
|
|
import cn.reghao.autodop.dmaster.app.entity.log.DeployLog;
|
|
|
-import cn.reghao.autodop.dmaster.app.entity.orchestration.AppOrchestration;
|
|
|
import cn.reghao.autodop.dmaster.app.repository.deploy.DeployedAppRepository;
|
|
|
import cn.reghao.autodop.dmaster.app.repository.orchestration.AppOrchestrationRepository;
|
|
|
+import cn.reghao.autodop.dmaster.app.service.tools.updater.CommitLog;
|
|
|
+import cn.reghao.autodop.dmaster.app.vo.log.BuildDeployResult;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.data.jpa.domain.Specification;
|
|
|
import org.springframework.stereotype.Repository;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import javax.persistence.criteria.CriteriaBuilder;
|
|
|
+import javax.persistence.criteria.CriteriaQuery;
|
|
|
+import javax.persistence.criteria.Predicate;
|
|
|
+import javax.persistence.criteria.Root;
|
|
|
import java.time.LocalDateTime;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
|
|
|
/**
|
|
|
* 持久化构建、部署日志
|
|
|
@@ -21,15 +29,18 @@ import java.time.LocalDateTime;
|
|
|
@Slf4j
|
|
|
@Repository
|
|
|
public class LogRepository {
|
|
|
+ private CommitLogRepository commitLogRepository;
|
|
|
private BuildLogRepository buildLogRepository;
|
|
|
private DeployLogRepository deployLogRepository;
|
|
|
private DeployedAppRepository deployedAppRepository;
|
|
|
private AppOrchestrationRepository appRepository;
|
|
|
|
|
|
- public LogRepository(BuildLogRepository buildLogRepository,
|
|
|
+ public LogRepository(CommitLogRepository commitLogRepository,
|
|
|
+ BuildLogRepository buildLogRepository,
|
|
|
DeployLogRepository deployLogRepository,
|
|
|
DeployedAppRepository deployedAppRepository,
|
|
|
AppOrchestrationRepository appRepository) {
|
|
|
+ this.commitLogRepository = commitLogRepository;
|
|
|
this.buildLogRepository = buildLogRepository;
|
|
|
this.deployLogRepository = deployLogRepository;
|
|
|
this.deployedAppRepository = deployedAppRepository;
|
|
|
@@ -38,11 +49,21 @@ public class LogRepository {
|
|
|
|
|
|
@Transactional(rollbackFor = {Exception.class})
|
|
|
public void saveBuildLog(BuildLog buildLog) {
|
|
|
- AppOrchestration app = buildLog.getApp();
|
|
|
- String commitId = buildLog.getCommitLog().getCommitId();
|
|
|
- BuildLog entity = buildLogRepository.findByAppAndAppCompileAndAppPackAndCommitLog_CommitIdAndStatusCode(
|
|
|
- app, app.getAppBuild().getAppCompile(), app.getAppBuild().getAppPack(), commitId, 0);
|
|
|
- // BuildLog 已存在时不再更新
|
|
|
+ CommitLog commitLog = buildLog.getCommitLog();
|
|
|
+ CommitLog e = commitLogRepository.findByCommitId(commitLog.getCommitId());
|
|
|
+ if (e != null) {
|
|
|
+ buildLog.setCommitLog(e);
|
|
|
+ } else {
|
|
|
+ commitLog.setIsDelete(false);
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
+ commitLog.setCreateTime(now);
|
|
|
+ commitLog.setUpdateTime(now);
|
|
|
+ commitLogRepository.save(commitLog);
|
|
|
+ }
|
|
|
+
|
|
|
+ BuildLog entity = buildLogRepository.findByCommitLogAndAppCompileAndAppPackAndAppIdAndStatusCode(
|
|
|
+ commitLog, buildLog.getAppCompile(), buildLog.getAppPack(), buildLog.getAppId(), 0);
|
|
|
+ // 当前 commit 构建成功的 BuildLog 已存在时不再更新
|
|
|
if (entity == null) {
|
|
|
buildLog.setIsDelete(false);
|
|
|
LocalDateTime now = LocalDateTime.now();
|
|
|
@@ -54,7 +75,7 @@ public class LogRepository {
|
|
|
|
|
|
@Transactional(rollbackFor = {Exception.class})
|
|
|
public void saveDeployLog(DeployLog deployLog) {
|
|
|
- BuildLog buildLog = deployLog.getBuildLog();
|
|
|
+ /*BuildLog buildLog = deployLog.getBuildLog();
|
|
|
AppOrchestration app = buildLog.getApp();
|
|
|
String commitId = buildLog.getCommitLog().getCommitId();
|
|
|
BuildLog entity = buildLogRepository.findByAppAndAppCompileAndAppPackAndCommitLog_CommitIdAndStatusCode(
|
|
|
@@ -66,11 +87,11 @@ public class LogRepository {
|
|
|
deployLog.setCreateTime(now);
|
|
|
deployLog.setUpdateTime(now);
|
|
|
deployLogRepository.save(deployLog);
|
|
|
- }
|
|
|
+ }*/
|
|
|
}
|
|
|
|
|
|
private void saveOrUpdateDeployedApp(BuildLog buildLog) {
|
|
|
- AppOrchestration app = buildLog.getApp();
|
|
|
+ /*AppOrchestration app = buildLog.getApp();
|
|
|
DeployedApp entity = deployedAppRepository.findByApp(app);
|
|
|
// TODO 新增或更新
|
|
|
if (entity == null) {
|
|
|
@@ -80,13 +101,23 @@ public class LogRepository {
|
|
|
entity.setCommitId(buildLog.getCommitLog().getCommitId());
|
|
|
entity.setUpdateTime(LocalDateTime.now());
|
|
|
deployedAppRepository.save(entity);
|
|
|
- }
|
|
|
+ }*/
|
|
|
}
|
|
|
|
|
|
private DeployedApp deployedApp(BuildLog buildLog) {
|
|
|
DeployedApp deployedApp = new DeployedApp();
|
|
|
- deployedApp.setApp(buildLog.getApp());
|
|
|
- deployedApp.setCommitId(buildLog.getCommitLog().getCommitId());
|
|
|
+ /*deployedApp.setApp(buildLog.getApp());
|
|
|
+ deployedApp.setCommitId(buildLog.getCommitLog().getCommitId());*/
|
|
|
return deployedApp;
|
|
|
}
|
|
|
+
|
|
|
+ public void test() {
|
|
|
+ Specification spec = new Specification<BuildDeployResult>() {
|
|
|
+ @Override
|
|
|
+ public Predicate toPredicate(Root root, CriteriaQuery query, CriteriaBuilder cb) {
|
|
|
+ List<Predicate> list = new ArrayList<>();
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ };
|
|
|
+ }
|
|
|
}
|