Prechádzať zdrojové kódy

update DeployApp.java

reghao 2 mesiacov pred
rodič
commit
1904edc8b4

+ 12 - 32
web/src/main/java/cn/reghao/bnt/web/devops/deployer/service/DeployApp.java

@@ -148,12 +148,17 @@ public class DeployApp {
             }
 
             String commitId = appBuilding.getCommitId();
-            String nodeType = remoteHost.getNodeType();
-            String localDir = String.format("%s/%s/%s_%s/%s", LocalBuildDir.packDir, appId, appId, commitId, nodeType);
             String remoteDir = remoteHost.getAppDir();
             try {
+                String nodeType = remoteHost.getNodeType();
                 RemoteAgentConfig remoteAgentConfig = remoteHost.getRemoteAgentConfig();
-                if (remoteAgentConfig != null) {
+                if (remoteAgentConfig == null) {
+                    log.error("RemoteAgentConfig of {} not exists", nodeType);
+                    return;
+                }
+
+                String localDir = String.format("%s/%s/%s_%s/%s", LocalBuildDir.packDir, appId, appId, commitId, nodeType);
+                if (nodeType.equals(NodeType.agent.name())) {
                     Map<String, String> map = new HashMap<>();
                     map.put("protocol", remoteAgentConfig.getMgrProtocol());
                     map.put("host", remoteAgentConfig.getMgrHost());
@@ -161,6 +166,10 @@ public class DeployApp {
 
                     String agentConfigPath = String.format("%s/%s", localDir, "devopsagent.json");
                     textFile.write(new File(agentConfigPath), JsonConverter.objectToJson(map));
+                } else {
+                    String mgrConfig = remoteAgentConfig.getMgrConfig();
+                    String mgrConfigPath = String.format("%s/%s", localDir, "bntweb.yml");
+                    textFile.write(new File(mgrConfig), mgrConfigPath);
                 }
 
                 Result result = sftp.deploy(localDir, remoteDir, remoteHost);
@@ -188,35 +197,6 @@ public class DeployApp {
 
         @Override
         public void run() {
-            try {
-                RemoteHost remoteHost = remoteHostRepository.findByHost(host);
-                if (remoteHost == null) {
-                    log.error("host {} not exists", host);
-                    return;
-                }
-
-                String commitId = appBuilding.getCommitId();
-                String nodeType = remoteHost.getNodeType();
-                String localDir = String.format("%s/%s/%s_%s/%s", LocalBuildDir.packDir, appId, appId, commitId, nodeType);
-                String remoteDir = remoteHost.getAppDir();
-
-                String agentConfigPath = String.format("%s/%s", localDir, "devopsagent.json");
-                RemoteAgentConfig remoteAgentConfig = remoteHost.getRemoteAgentConfig();
-                Map<String, String> map = new HashMap<>();
-                map.put("protocol", remoteAgentConfig.getMgrProtocol());
-                map.put("host", remoteAgentConfig.getMgrHost());
-                map.put("port", remoteAgentConfig.getMgrPort() + "");
-                textFile.write(new File(agentConfigPath), JsonConverter.objectToJson(map));
-
-                Result result = sftp.deploy(localDir, remoteDir, remoteHost);
-                if (result.getCode() == ResultStatus.SUCCESS.getCode()) {
-                    remoteHost.setAppVersion(commitId);
-                    remoteHost.setUpdateTime(LocalDateTime.now());
-                    remoteHostRepository.save(remoteHost);
-                }
-            } catch (Exception e) {
-                e.printStackTrace();
-            }
         }
     }
 }