فهرست منبع

update DeployApp.java & Sftp.java

reghao 3 ماه پیش
والد
کامیت
f5349f36f6

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

@@ -143,13 +143,16 @@ public class DeployApp {
             String localDir = String.format("%s/%s/%s_%s/%s", LocalBuildDir.packDir, appId, appId, commitId, nodeType);
             String remoteDir = remoteHost.getAppDir();
             try {
-                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));
+                if (remoteAgentConfig != null) {
+                    Map<String, String> map = new HashMap<>();
+                    map.put("protocol", remoteAgentConfig.getMgrProtocol());
+                    map.put("host", remoteAgentConfig.getMgrHost());
+                    map.put("port", remoteAgentConfig.getMgrPort() + "");
+
+                    String agentConfigPath = String.format("%s/%s", localDir, "devopsagent.json");
+                    textFile.write(new File(agentConfigPath), JsonConverter.objectToJson(map));
+                }
 
                 Result result = sftp.deploy(localDir, remoteDir, remoteHost);
                 if (result.getCode() == ResultStatus.SUCCESS.getCode()) {

+ 8 - 6
web/src/main/java/cn/reghao/bnt/web/devops/deployer/util/Sftp.java

@@ -119,7 +119,7 @@ public class Sftp {
      * @return
      * @date 2024-02-20 09:20:11
      */
-    public boolean mkdir1(Session session, String remotePath) throws SftpException, JSchException {
+    public boolean mkdir(Session session, String remotePath) throws SftpException, JSchException {
         boolean exist = true;
         // 创建 sftp 通信通道
         Channel channel = session.openChannel("sftp");
@@ -149,7 +149,7 @@ public class Sftp {
         return exist;
     }
 
-    public boolean mkdir(Session session, String remotePath) throws Exception {
+    public boolean mkdir0(Session session, String remotePath) throws Exception {
         boolean exist = true;
         // 创建 sftp 通信通道
         Channel channel = session.openChannel("sftp");
@@ -244,8 +244,9 @@ public class Sftp {
                 String command = String.format("cd %s && %s shutdown.sh", remoteDir, bash);
                 ShellResult shellResult = exec(session, command);
                 if (!shellResult.isSuccess()) {
-                    log.info("shutdown application failed\nexitCode: {}\nresult:\n{}", shellResult.getExitCode(), shellResult.getResult());
-                    result = Result.fail("");
+                    String errMsg = String.format("shutdown application failed\nexitCode: %s\nresult:\n%s", shellResult.getExitCode(), shellResult.getResult());
+                    log.error(errMsg);
+                    result = Result.fail(errMsg);
                 } else {
                     log.info("shutdown application successfully");
                 }
@@ -259,8 +260,9 @@ public class Sftp {
             String command = String.format("cd %s && %s start.sh", remoteDir, bash);
             ShellResult shellResult = exec(session, command);
             if (!shellResult.isSuccess()) {
-                log.info("start application failed\nexitCode: {}\nresult:\n{}", shellResult.getExitCode(), shellResult.getResult());
-                System.exit(-1);
+                String errMsg = String.format("start application failed\nexitCode: %s\nresult:\n%s", shellResult.getExitCode(), shellResult.getResult());
+                log.error(errMsg);
+                result = Result.fail(errMsg);
             } else {
                 log.info("start application successfully");
             }