Explorar el Código

将 mgr 节点的配置放入 RemoteAgentConfig 中

reghao hace 2 meses
padre
commit
11717bdf65

+ 2 - 9
web/src/main/java/cn/reghao/bnt/web/devops/deployer/controller/DeployerController.java

@@ -48,8 +48,8 @@ public class DeployerController {
 
     @Operation(summary = "获取节点配置", description = "N")
     @GetMapping(value = "/agent_config/list", produces = MediaType.APPLICATION_JSON_VALUE)
-    public String getAgentConfigs() {
-        List<RemoteAgentConfig> list = deployApp.getAgentConfigs();
+    public String getAgentConfigs(@RequestParam("nodeType") String nodeType) {
+        List<RemoteAgentConfig> list = deployApp.getAgentConfigs(nodeType);
         return WebResult.success(list);
     }
 
@@ -74,13 +74,6 @@ public class DeployerController {
         return WebResult.success(list);
     }
 
-    @Operation(summary = "获取 mgr 配置", description = "N")
-    @GetMapping(value = "/mgr_config", produces = MediaType.APPLICATION_JSON_VALUE)
-    public String getMgrConfig() {
-        String mgrConfig = deployApp.getMgrConfig();
-        return WebResult.success(mgrConfig);
-    }
-
     @Operation(summary = "部署 devops-mgr", description = "N")
     @PostMapping(value = "/update", produces = MediaType.APPLICATION_JSON_VALUE)
     public String deployMgr(@RequestBody UpdateApp updateApp) {

+ 3 - 0
web/src/main/java/cn/reghao/bnt/web/devops/deployer/db/RemoteAgentConfigRepository.java

@@ -1,6 +1,8 @@
 package cn.reghao.bnt.web.devops.deployer.db;
 
 import cn.reghao.bnt.web.devops.deployer.model.po.RemoteAgentConfig;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
 import org.springframework.data.jpa.repository.JpaRepository;
 
 /**
@@ -8,5 +10,6 @@ import org.springframework.data.jpa.repository.JpaRepository;
  * @date 2025-12-22 16:16:24
  */
 public interface RemoteAgentConfigRepository extends JpaRepository<RemoteAgentConfig, Integer> {
+    Page<RemoteAgentConfig> findByNodeType(String nodeType, Pageable pageable);
     RemoteAgentConfig findByMgrHost(String mgrHost);
 }

+ 4 - 5
web/src/main/java/cn/reghao/bnt/web/devops/deployer/model/po/RemoteAgentConfig.java

@@ -20,12 +20,11 @@ import lombok.Setter;
 @Table(name = "devops_remote_agent_config")
 public class RemoteAgentConfig extends BaseEntity {
     @NotBlank
-    @Size(max = 4, message = "mgrProtocol 最大长度不能超过 4 个字符")
+    @Size(max = 5, message = "nodeType 最大长度不能超过 4 个字符")
+    private String nodeType;
     private String mgrProtocol;
-    @NotBlank
-    @Size(max = 255, message = "mgrHost 最大长度不能超过 255 个字符")
-    @Column(unique = true, nullable = false)
     private String mgrHost;
-    @NotNull(message = "mgrPort 不能为空")
     private Integer mgrPort;
+    @Column(columnDefinition="text")
+    private String mgrConfig;
 }

+ 11 - 6
web/src/main/java/cn/reghao/bnt/web/devops/deployer/service/DeployApp.java

@@ -52,6 +52,15 @@ public class DeployApp {
     }
 
     public void addAgentConfig(RemoteAgentConfig remoteAgentConfig) {
+        String nodeType = remoteAgentConfig.getNodeType();
+        if (nodeType.equals(NodeType.mgr.name())) {
+            remoteAgentConfig.setMgrProtocol(null);
+            remoteAgentConfig.setMgrHost(null);
+            remoteAgentConfig.setMgrPort(null);
+        } else {
+            remoteAgentConfig.setMgrConfig(null);
+        }
+
         RemoteAgentConfig entity = remoteAgentConfigRepository.findByMgrHost(remoteAgentConfig.getMgrHost());
         if (entity == null) {
             remoteAgentConfigRepository.save(remoteAgentConfig);
@@ -62,9 +71,9 @@ public class DeployApp {
         remoteAgentConfigRepository.deleteById(id);
     }
 
-    public List<RemoteAgentConfig> getAgentConfigs() {
+    public List<RemoteAgentConfig> getAgentConfigs(String nodeType) {
         PageRequest pageRequest = PageRequest.of(0, 100);
-        return remoteAgentConfigRepository.findAll(pageRequest).getContent();
+        return remoteAgentConfigRepository.findByNodeType(nodeType, pageRequest).getContent();
     }
 
     public Result addRemoteHost(RemoteMachine remoteMachine) {
@@ -118,10 +127,6 @@ public class DeployApp {
         return remoteHostRepository.findByNodeType(nodeType, pageRequest).getContent();
     }
 
-    public String getMgrConfig() {
-        return "mgr config";
-    }
-
     public Result deployApp(UpdateApp updateApp) {
         AppConfig appConfig = appBuildQuery.getAppConfig(appId);
         if (appConfig == null) {