Procházet zdrojové kódy

基本完成构建配置和应用配置的 CRUD 接口

reghao před 4 roky
rodič
revize
c04b608930

+ 9 - 4
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/controller/BuildDeployController.java

@@ -1,5 +1,6 @@
 package cn.reghao.autodop.dmaster.app.controller;
 
+import cn.reghao.autodop.dmaster.app.service.AppBuildService;
 import cn.reghao.autodop.dmaster.app.service.BuildDeployDispatcher;
 import cn.reghao.autodop.dmaster.utils.WebBody;
 import io.swagger.annotations.Api;
@@ -20,9 +21,11 @@ import org.springframework.web.bind.annotation.*;
 @RequestMapping("/api/app/bd")
 public class BuildDeployController {
     private BuildDeployDispatcher buildDeployDispatcher;
+    private AppBuildService buildService;
 
-    public BuildDeployController(BuildDeployDispatcher buildDeployDispatcher) {
+    public BuildDeployController(BuildDeployDispatcher buildDeployDispatcher, AppBuildService buildService) {
         this.buildDeployDispatcher = buildDeployDispatcher;
+        this.buildService = buildService;
     }
 
     @ApiOperation(value = "构建部署应用")
@@ -52,8 +55,10 @@ public class BuildDeployController {
         return WebBody.success();
     }
 
-    @GetMapping("/list")
-    public String buildList() {
-        return WebBody.success("build list");
+    @ApiOperation(value = "刷新应用构建部署列表")
+    @PostMapping(value = "/refresh", produces = MediaType.APPLICATION_JSON_VALUE)
+    public String refreshAppBuilding() {
+        buildService.refreshAppBuilding();
+        return WebBody.success();
     }
 }

+ 4 - 3
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/controller/view/AppPageController.java

@@ -11,6 +11,7 @@ import cn.reghao.autodop.dmaster.app.repository.AppRunningRepository;
 import cn.reghao.autodop.dmaster.app.entity.AppBuilding;
 import cn.reghao.autodop.dmaster.app.repository.log.BuildLogRepository;
 import cn.reghao.autodop.dmaster.app.repository.log.DeployLogRepository;
+import cn.reghao.autodop.dmaster.utils.WebBody;
 import cn.reghao.autodop.dmaster.utils.db.PageList;
 import cn.reghao.autodop.dmaster.utils.db.PageSort;
 import io.swagger.annotations.Api;
@@ -58,15 +59,15 @@ public class AppPageController {
     @ApiOperation(value = "构建部署页面")
     @GetMapping("/build")
     public String buildPage(@RequestParam(value = "env", required = false) String env,
-                            @RequestParam(value = "appId", required = false) String appId,
+                            @RequestParam(value = "appName", required = false) String appName,
                             Model model) {
         if (env == null) {
             env = EnvType.test.name();
         }
 
-        if (appId != null) {
+        if (appName != null) {
             Map<String, String> map = new HashMap<>();
-            map.put("appId", appId);
+            map.put("appName", appName);
             List<AppBuilding> list = buildingQuery.query(map);
             Page<AppBuilding> page = new PageImpl<>(list);
             PageList<AppBuilding> pageList = PageList.pageList(page);

+ 29 - 2
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/entity/AppBuilding.java

@@ -3,6 +3,7 @@ package cn.reghao.autodop.dmaster.app.entity;
 import cn.reghao.autodop.common.result.ResultStatus;
 import cn.reghao.autodop.common.utils.DateTimeConverter;
 import cn.reghao.autodop.dmaster.app.entity.config.AppOrchestration;
+import cn.reghao.autodop.dmaster.app.entity.config.deploy.RunningConfig;
 import cn.reghao.autodop.dmaster.app.entity.log.BuildLog;
 import cn.reghao.autodop.dmaster.app.service.bd.tools.repo.CommitInfo;
 import cn.reghao.autodop.dmaster.common.orm.BaseEntity;
@@ -22,23 +23,48 @@ import java.time.LocalDateTime;
 @EqualsAndHashCode(callSuper = false)
 @Entity
 public class AppBuilding extends BaseEntity<Integer> {
-    private String buildLogId;
     private String appId;
-    //private Integer httpPort;
+    private String appName;
     private String env;
     private String appType;
     private String branch;
+    private Integer httpPort;
+
+    private String buildLogId;
     private String commitId;
     private LocalDateTime commitTime;
     private String buildResult;
     private LocalDateTime buildTime;
+    private String packagePath;
     private String buildBy;
 
     public AppBuilding(AppOrchestration app) {
         this.appId = app.getAppId();
+        this.appName = app.getAppName();
         this.env = app.getEnv();
         this.appType = app.getAppType();
         this.branch = app.getBranch();
+        RunningConfig runningConfig = app.getRunningConfig();
+        if (runningConfig != null) {
+            this.httpPort = runningConfig.getHttpPort();
+        } else {
+            this.httpPort = 0;
+        }
+    }
+
+    public AppBuilding refresh(AppOrchestration app) {
+        this.appName = app.getAppName();
+        this.env = app.getEnv();
+        this.appType = app.getAppType();
+        this.branch = app.getBranch();
+        RunningConfig runningConfig = app.getRunningConfig();
+        if (runningConfig != null) {
+            this.httpPort = runningConfig.getHttpPort();
+        } else {
+            this.httpPort = 0;
+        }
+
+        return this;
     }
 
     public static AppBuilding from(BuildLog buildLog) {
@@ -62,6 +88,7 @@ public class AppBuilding extends BaseEntity<Integer> {
             appBuilding.setBuildResult(ResultStatus.FAIL.getMsg());
         }
         appBuilding.setBuildTime(buildLog.getBuildTime().getBuildTime());
+        appBuilding.setPackagePath(buildLog.getPackagePath());
         return appBuilding;
     }
 }

+ 2 - 1
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/repository/config/AppOrchestrationRepository.java

@@ -21,9 +21,10 @@ public interface AppOrchestrationRepository
     Page<AppOrchestration> findByEnableTrueAndEnv(String env, Pageable pageable);
     AppOrchestration findByAppId(String appId);
     List<AppOrchestration> findAllByIsDeleteFalseAndEnableTrueAndEnv(String env);
-    Page<AppOrchestration> findByIsDeleteFalseAndEnv(String env, Pageable pageable);
     AppOrchestration findByIsDeleteFalseAndAppId(String appId);
 
+    List<AppOrchestration> findAllByEnableIsTrue();
+
     List<AppOrchestration> findAllByRepoAuthConfig(RepoAuthConfig repoAuthConfig);
     List<AppOrchestration> findAllByCompilerConfig(CompilerConfig compilerConfig);
     List<AppOrchestration> findAllByPackerConfig(PackerConfig packerConfig);

+ 0 - 57
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/AppBakService.java

@@ -1,57 +0,0 @@
-package cn.reghao.autodop.dmaster.app.service;
-
-import cn.reghao.autodop.common.utils.serializer.JsonConverter;
-import cn.reghao.autodop.dmaster.app.entity.config.build.BuildDir;
-import cn.reghao.autodop.dmaster.app.entity.config.build.CompilerConfig;
-import cn.reghao.autodop.dmaster.app.entity.config.build.PackerConfig;
-import cn.reghao.autodop.dmaster.app.entity.config.build.RepoAuthConfig;
-import cn.reghao.autodop.dmaster.app.repository.config.AppOrchestrationRepository;
-import cn.reghao.autodop.dmaster.app.repository.config.ProjOrchestrationRepository;
-import cn.reghao.autodop.dmaster.app.repository.config.build.BuildDirRepository;
-import cn.reghao.autodop.dmaster.app.repository.config.build.CompilerConfigRepository;
-import cn.reghao.autodop.dmaster.app.repository.config.build.PackerConfigRepository;
-import cn.reghao.autodop.dmaster.app.repository.config.build.RepoAuthConfigRepository;
-import cn.reghao.autodop.dmaster.app.vo.BuildConfig;
-import org.springframework.stereotype.Service;
-
-import java.util.List;
-
-/**
- * @author reghao
- * @date 2021-06-04 10:01:41
- */
-@Service
-public class AppBakService {
-    private BuildDirRepository buildDirRepository;
-    private RepoAuthConfigRepository repoAuthRepository;
-    private CompilerConfigRepository compilerRepository;
-    private PackerConfigRepository packerRepository;
-    private AppOrchestrationRepository appRepository;
-    private ProjOrchestrationRepository projRepository;
-
-    public AppBakService(BuildDirRepository buildDirRepository,
-                         RepoAuthConfigRepository repoAuthRepository,
-                         CompilerConfigRepository compilerRepository,
-                         PackerConfigRepository packerRepository,
-                         AppOrchestrationRepository appRepository,
-                         ProjOrchestrationRepository projRepository) {
-        this.buildDirRepository = buildDirRepository;
-        this.repoAuthRepository = repoAuthRepository;
-        this.compilerRepository = compilerRepository;
-        this.packerRepository = packerRepository;
-        this.appRepository = appRepository;
-        this.projRepository = projRepository;
-    }
-
-    public String bakBuildConfig() {
-        List<BuildDir> buildDirs = buildDirRepository.findAll();
-        List<RepoAuthConfig> repoAuths = repoAuthRepository.findAll();
-        List<CompilerConfig> compilers = compilerRepository.findAll();
-        List<PackerConfig> packers = packerRepository.findAll();
-        BuildConfig buildConfig = new BuildConfig(buildDirs, repoAuths, compilers, packers);
-        return JsonConverter.objectToJson(buildConfig);
-    }
-
-    public void bakAppConfig() {
-    }
-}

+ 50 - 0
dmaster/src/main/java/cn/reghao/autodop/dmaster/app/service/AppBuildService.java

@@ -0,0 +1,50 @@
+package cn.reghao.autodop.dmaster.app.service;
+
+import cn.reghao.autodop.dmaster.app.entity.AppBuilding;
+import cn.reghao.autodop.dmaster.app.entity.config.AppOrchestration;
+import cn.reghao.autodop.dmaster.app.repository.AppBuildingRepository;
+import cn.reghao.autodop.dmaster.app.repository.AppDeployingRepository;
+import cn.reghao.autodop.dmaster.app.repository.config.AppOrchestrationRepository;
+import org.springframework.stereotype.Service;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author reghao
+ * @date 2021-06-04 10:01:41
+ */
+@Service
+public class AppBuildService {
+    private AppOrchestrationRepository appRepository;
+    private AppBuildingRepository buildingRepository;
+    private AppDeployingRepository deployingRepository;
+
+    public AppBuildService(AppOrchestrationRepository appRepository,
+                           AppBuildingRepository buildingRepository,
+                           AppDeployingRepository deployingRepository) {
+        this.appRepository = appRepository;
+        this.buildingRepository = buildingRepository;
+        this.deployingRepository = deployingRepository;
+    }
+
+    public void refreshAppBuilding() {
+        List<AppOrchestration> apps = appRepository.findAllByEnableIsTrue();
+        List<AppBuilding> newList = new ArrayList<>();
+        List<AppBuilding> existingList = new ArrayList<>();
+        for (AppOrchestration app : apps) {
+            AppBuilding entity = buildingRepository.findByAppId(app.getAppId());
+            if (entity == null) {
+                newList.add(new AppBuilding(app));
+            } else {
+                existingList.add(entity.refresh(app));
+            }
+        }
+
+        buildingRepository.saveAll(newList);
+        buildingRepository.saveAll(existingList);
+    }
+
+    public void refreshAppDeploying() {
+    }
+}

+ 5 - 5
dmaster/src/main/resources/application-prod.yml

@@ -1,15 +1,15 @@
 spring:
   datasource:
-    url: jdbc:mysql://192.168.0.211:3306/autodop_tdb?useSSL=false&useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull
-    username: prod
-    password: Prod@123456
+    url: jdbc:mysql://192.168.0.211:3306/reghao_devops_tdb?useSSL=false&useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull
+    username: test
+    password: Test@123456
   data:
     mongodb:
       uri: mongodb://192.168.0.211/log
 mosquitto:
   broker: tcp://192.168.0.211:1883
-  username: prod
-  password: Prod@123456
+  username: test
+  password: Test@123456
 oss:
   host: http://static.reghao.icu
   key: minioadmin

+ 8 - 6
dmaster/src/main/resources/templates/app/build.html

@@ -20,9 +20,9 @@
                     </div>
                 </div>
                 <div class="layui-inline timo-search-box">
-                    <label class="layui-form-label">应用 ID</label>
+                    <label class="layui-form-label">应用</label>
                     <div class="layui-input-block">
-                        <input type="text" name="appId" th:value="${param.appName}" placeholder="请输入应用 ID"
+                        <input type="text" name="appName" th:value="${param.appName}" placeholder="请输入应用名"
                                autocomplete="off" class="layui-input">
                     </div>
                 </div>
@@ -41,13 +41,14 @@
                         <label class="timo-checkbox"><input type="checkbox">
                             <i class="layui-icon layui-icon-ok"></i></label>
                     </th>
-                    <th class="sortable" data-field="appId">应用 ID</th>
-                    <!--<th class="sortable" data-field="httpPort">端口</th>-->
+                    <th class="sortable" data-field="appName">应用</th>
                     <th class="sortable" data-field="branch">分支</th>
+                    <th class="sortable" data-field="httpPort">HTTP 端口</th>
                     <th class="sortable" data-field="commitId">版本</th>
                     <th class="sortable" data-field="commitTime">提交时间</th>
                     <th class="sortable" data-field="result">构建结果</th>
                     <th class="sortable" data-field="buildTime">构建时间</th>
+                    <!--<th class="sortable" data-field="packagePath">包路径</th>-->
                     <th class="sortable" data-field="buildBy">构建用户</th>
                     <th>操作</th>
                 </tr>
@@ -58,10 +59,10 @@
                         <i class="layui-icon layui-icon-ok"></i></label></td>
                     <td>
                         <a class="open-popup" data-title="应用配置详情" data-size="1200,600" href="#"
-                           th:text="${item.appId}" th:attr="data-url=@{'/app/config/app/detail/'+${item.appId}}"></a>
+                           th:text="${item.appName}" th:attr="data-url=@{'/app/config/app/detail/'+${item.appId}}"></a>
                     </td>
-                    <!--<td th:text="${item.httpPort}">端口</td>-->
                     <td th:text="${item.branch}">分支</td>
+                    <td th:text="${item.httpPort}">HTTP 端口</td>
                     <td th:text="${item.commitId}">版本</td>
                     <td th:text="${item.commitTime}">提交时间</td>
                     <td>
@@ -69,6 +70,7 @@
                            th:text="${item.buildResult}" th:attr="data-url=@{'/app/log/build/'+${item.buildLogId} + '/result'}"></a>
                     </td>
                     <td th:text="${item.buildTime}">构建时间</td>
+                    <!--<td th:text="${item.packagePath}">包路径</td>-->
                     <td th:text="${item.buildBy}">构建用户</td>
                     <td>
                         <a class="ajax-post" th:href="@{'/api/app/bd/update?appId='+${item.appId}}">更新</a>

+ 1 - 1
dmaster/src/main/resources/templates/app/config/app/detail.html

@@ -61,7 +61,7 @@
             <tr>
                 <th>仓库类型</th>
                 <td th:text="${app.repoAuthConfig.type}"></td>
-                <th>仓库名字</th>
+                <th>仓库认证名字</th>
                 <td th:text="${app.repoAuthConfig.name}"></td>
                 <th>认证类型</th>
                 <td th:text="${app.repoAuthConfig.authType}"></td>

+ 1 - 0
scripts/shutdown.sh

@@ -0,0 +1 @@
+#!/bin/bash

+ 1 - 0
scripts/start.sh

@@ -0,0 +1 @@
+#!/bin/bash