From 3de93f8f122e68065d3f54875956a79ffcc3d193 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=91=E6=98=8E=E4=BB=81?= <903716863@qq.com> Date: Thu, 26 Sep 2019 10:53:18 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/educoder/bridge/game/controller/GameController.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/educoder/bridge/game/controller/GameController.java b/src/main/java/com/educoder/bridge/game/controller/GameController.java index 187bded..b0a1015 100644 --- a/src/main/java/com/educoder/bridge/game/controller/GameController.java +++ b/src/main/java/com/educoder/bridge/game/controller/GameController.java @@ -147,6 +147,7 @@ public class GameController { String evaluateStartTime = requestTime.toString(); JSONObject cost = new JSONObject(); cost.put("evaluateStartTime", evaluateStartTime); + JedisUtil.set("timeCost:" + tpiID + ":" + buildID, cost.toJSONString()); Boolean reuseFlag = reusePod == null ? Boolean.FALSE : reusePod; needPortMapping = needPortMapping == null ? 0 : needPortMapping; From bc1b0fc1cce948ce3a8cf723e17c7457b1ab3878 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=91=E6=98=8E=E4=BB=81?= <903716863@qq.com> Date: Thu, 26 Sep 2019 16:40:03 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9git=20pull?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/educoder/bridge/game/service/GameService.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/educoder/bridge/game/service/GameService.java b/src/main/java/com/educoder/bridge/game/service/GameService.java index 60e0c76..05a2199 100644 --- a/src/main/java/com/educoder/bridge/game/service/GameService.java +++ b/src/main/java/com/educoder/bridge/game/service/GameService.java @@ -193,8 +193,9 @@ public class GameService { + " && git config user.name educoder " + "&& git config core.fileMode false" + // 忽略文件权限 "&& git remote set-url origin " + tpiGitURL + " && git pull origin master"; // 本地直接清除所有改动 JSONObject result = ShellUtil.executeAndGetExitStatus(pullCommand, 3); - logger.debug("result: {}, out: {}", result.getInteger("exitStatus"), result.getString("out")); - if (result.getString("out").contains("commit your changes or stash them before you can merge")) { + String out = result.getString("out"); + logger.debug("{} git pull result: {}, out: {}", tpiID, result.getInteger("exitStatus"), out); + if (out.contains("commit your changes or stash")) { String stashCmd = "cd " + tpiRepoPath + " && git stash save " + TimeHelper.getCurrentTime("yyyyMMddHHmmss"); logger.info("tpi {} git pull与未commit代码冲突,先保存本地代码, cmd:{}", tpiID, stashCmd); @@ -205,8 +206,7 @@ public class GameService { } logger.info("tpi {} git pull与未commit代码冲突, 保存本地代码代码后, 再pull", tpiID); result = ShellUtil.executeAndGetExitStatus(pullCommand, 3); - } else if(result.getString("out").contains("Merge conflict") - || result.getString("out").contains("Pull is not possible because you have unmerged files")) { + } else if(out.contains("Merge conflict") || out.contains("have unmerged files")) { String resetCmd = "cd " + tpiRepoPath + " && git reset --hard FETCH_HEAD "; logger.info("tpi {} git pull与本地commit冲突, 使用远程版本, cmd:{}", tpiID, resetCmd); JSONObject resetResult = ShellUtil.executeAndGetExitStatus(resetCmd, 3); From 7612cf06f52335f1f8ea2935bd0583f173b61b04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=91=E6=98=8E=E4=BB=81?= <903716863@qq.com> Date: Thu, 26 Sep 2019 17:03:44 +0800 Subject: [PATCH 3/3] update git pull --- .../bridge/game/service/GameService.java | 180 +++++++++--------- 1 file changed, 91 insertions(+), 89 deletions(-) diff --git a/src/main/java/com/educoder/bridge/game/service/GameService.java b/src/main/java/com/educoder/bridge/game/service/GameService.java index 05a2199..b92b265 100644 --- a/src/main/java/com/educoder/bridge/game/service/GameService.java +++ b/src/main/java/com/educoder/bridge/game/service/GameService.java @@ -156,96 +156,98 @@ public class GameService { * @param tpiGitURL * @throws GameException */ - public void gitPull(String path, String tpiGitURL, Integer contentModified) throws Exception { - logger.debug("git pull, path: {}, tpiGitURL: {}", path, tpiGitURL); - String tpiRepoName = GameHelper.getRepoName(tpiGitURL); - String tpiRepoPath = path + File.separator + tpiRepoName; - String tpiID = path.substring(path.lastIndexOf("_") + 1); - // pull 操作之前,如果tpi本地版本库不存在,则克隆,主机名为origin - File file = FileUtils.getFile(tpiRepoPath); - if (!file.exists()) { - logger.warn("版本库不存在,先克隆! tpiGitURL: {}, tpiID: {}", tpiGitURL, tpiID); - gitClone(path, tpiGitURL, "origin", tpiRepoName, "--depth=1"); - } - // pull之前,先判断版本库的origin主机是否存在,若不存在,则先创建 - String cmd = "cd " + tpiRepoPath + " && git remote | grep ^origin$"; - JSONObject remoteExist = ShellUtil.executeAndGetExitStatus(cmd); - if (remoteExist.getInteger("exitStatus") != 0) { - if (remoteExist.getString("out").contains("fatal")) { - logger.warn("版本库不完整,先进行init操作, tpiID: {}, tpiGitURL: {}, 检查cmd: {}", tpiID, tpiGitURL, cmd); - ShellUtil.execute("cd " + tpiRepoPath + " && git init"); - } - logger.warn("origin主机名不存在,先添加主机名及其git地址,remoteName: {}, tpiGitURL: {}, tpiID: {}", "origin", tpiGitURL, - tpiID); - cmd = "cd " + tpiRepoPath + " && git remote add origin " + tpiGitURL; - JSONObject addRemote = ShellUtil.executeAndGetExitStatus(cmd, 3); - if (addRemote.getInteger("exitStatus") != 0) { - logger.error("origin主机名不存在,添加主机名失败, tpiGitURL: {}, tpiID: {}, cmd: {}", tpiGitURL, tpiID, cmd); - throw new GameException("origin主机名不存在,无法完成pull操作,tpiID:" + tpiID); - } else { - logger.debug("origin主机名不存在,添加主机名成功, tpiGitURL: {}, tpiID: {}", tpiGitURL, tpiID); - } - } - // 执行pull操作 - long currentPullStart = System.currentTimeMillis(); - logger.debug("##----> gitpull 开始,包括git config ; set remote,当前时间为:" + currentPullStart); - String pullCommand = "cd " + tpiRepoPath + " && git config user.email educoder@163.com" - + " && git config user.name educoder " + "&& git config core.fileMode false" + // 忽略文件权限 - "&& git remote set-url origin " + tpiGitURL + " && git pull origin master"; // 本地直接清除所有改动 - JSONObject result = ShellUtil.executeAndGetExitStatus(pullCommand, 3); - String out = result.getString("out"); - logger.debug("{} git pull result: {}, out: {}", tpiID, result.getInteger("exitStatus"), out); - if (out.contains("commit your changes or stash")) { - String stashCmd = "cd " + tpiRepoPath + " && git stash save " - + TimeHelper.getCurrentTime("yyyyMMddHHmmss"); - logger.info("tpi {} git pull与未commit代码冲突,先保存本地代码, cmd:{}", tpiID, stashCmd); - result = ShellUtil.executeAndGetExitStatus(stashCmd, 3); - if (result.getInteger("exitStatus") != 0) { - logger.error("tpi {} git pull与未commit代码冲突,保存本地代码失败, cmd:{}, error: {}", tpiID, stashCmd, result.getString("out")); - throw new GameException("git pull与未commit代码冲突,保存本地代码失败,tpiID:" + tpiID); - } - logger.info("tpi {} git pull与未commit代码冲突, 保存本地代码代码后, 再pull", tpiID); - result = ShellUtil.executeAndGetExitStatus(pullCommand, 3); - } else if(out.contains("Merge conflict") || out.contains("have unmerged files")) { - String resetCmd = "cd " + tpiRepoPath + " && git reset --hard FETCH_HEAD "; - logger.info("tpi {} git pull与本地commit冲突, 使用远程版本, cmd:{}", tpiID, resetCmd); - JSONObject resetResult = ShellUtil.executeAndGetExitStatus(resetCmd, 3); - if (resetResult.getInteger("exitStatus") != 0) { - logger.error("tpi {}git pull与本地commit冲突, 使用远程版本失败, cmd:{}, error: {}", tpiID, resetCmd, resetResult.getString("out")); - throw new GameException("git pull与本地commit冲突, 使用远程版本失败,tpiID:" + tpiID); - } else { - return; - } + public void gitPull(String path, String tpiGitURL, Integer contentModified) throws Exception { + logger.debug("git pull, path: {}, tpiGitURL: {}", path, tpiGitURL); + String tpiRepoName = GameHelper.getRepoName(tpiGitURL); + String tpiRepoPath = path + File.separator + tpiRepoName; + String tpiID = path.substring(path.lastIndexOf("_") + 1); + // pull 操作之前,如果tpi本地版本库不存在,则克隆,主机名为origin + File file = FileUtils.getFile(tpiRepoPath); + if (!file.exists()) { + logger.warn("版本库不存在,先克隆! tpiGitURL: {}, tpiID: {}", tpiGitURL, tpiID); + gitClone(path, tpiGitURL, "origin", tpiRepoName, "--depth=1"); + } + // pull之前,先判断版本库的origin主机是否存在,若不存在,则先创建 + String cmd = "cd " + tpiRepoPath + " && git remote | grep ^origin$"; + JSONObject remoteExist = ShellUtil.executeAndGetExitStatus(cmd); + if (remoteExist.getInteger("exitStatus") != 0) { + if (remoteExist.getString("out").contains("fatal")) { + logger.warn("版本库不完整,先进行init操作, tpiID: {}, tpiGitURL: {}, 检查cmd: {}", tpiID, tpiGitURL, cmd); + ShellUtil.execute("cd " + tpiRepoPath + " && git init"); + } + logger.warn("origin主机名不存在,先添加主机名及其git地址,remoteName: {}, tpiGitURL: {}, tpiID: {}", "origin", tpiGitURL, + tpiID); + cmd = "cd " + tpiRepoPath + " && git remote add origin " + tpiGitURL; + JSONObject addRemote = ShellUtil.executeAndGetExitStatus(cmd, 3); + if (addRemote.getInteger("exitStatus") != 0) { + logger.error("origin主机名不存在,添加主机名失败, tpiGitURL: {}, tpiID: {}, cmd: {}", tpiGitURL, tpiID, cmd); + throw new GameException("origin主机名不存在,无法完成pull操作,tpiID:" + tpiID); + } else { + logger.debug("origin主机名不存在,添加主机名成功, tpiGitURL: {}, tpiID: {}", tpiGitURL, tpiID); + } + } + // 执行pull操作 + long currentPullStart = System.currentTimeMillis(); + logger.debug("##----> gitpull 开始,包括git config ; set remote,当前时间为:" + currentPullStart); + String pullCommand = "cd " + tpiRepoPath + " && git config user.email educoder@163.com" + + " && git config user.name educoder " + "&& git config core.fileMode false" + // 忽略文件权限 + "&& git remote set-url origin " + tpiGitURL + " && git pull origin master"; // 本地直接清除所有改动 + JSONObject result = ShellUtil.executeAndGetExitStatus(pullCommand, 3); + logger.debug("{} git pull result: {}, out: {}", tpiID, result.getInteger("exitStatus"), result.getString("out")); + if (result.getString("out").contains("commit your changes or stash") + || result.getString("out").contains("would be overwritten by merge")) { + String stashCmd = "cd " + tpiRepoPath + " && git stash save " + + TimeHelper.getCurrentTime("yyyyMMddHHmmss"); + logger.info("tpi {} git pull与未commit代码冲突,先保存本地代码, cmd:{}", tpiID, stashCmd); + result = ShellUtil.executeAndGetExitStatus(stashCmd, 3); + if (result.getInteger("exitStatus") != 0) { + logger.error("tpi {} git pull与未commit代码冲突,保存本地代码失败, cmd:{}, error: {}", tpiID, stashCmd, result.getString("out")); + throw new GameException("git pull与未commit代码冲突,保存本地代码失败,tpiID:" + tpiID); + } + logger.info("tpi {} git pull与未commit代码冲突, 保存本地代码代码后, 再pull", tpiID); + result = ShellUtil.executeAndGetExitStatus(pullCommand, 3); + } + if(result.getString("out").contains("Merge conflict") + || result.getString("out").contains("have unmerged files")) { + String resetCmd = "cd " + tpiRepoPath + " && git reset --hard FETCH_HEAD "; + logger.info("tpi {} git pull与本地commit冲突, 使用远程版本, cmd:{}", tpiID, resetCmd); + JSONObject resetResult = ShellUtil.executeAndGetExitStatus(resetCmd, 3); + if (resetResult.getInteger("exitStatus") != 0) { + logger.error("tpi {}git pull与本地commit冲突, 使用远程版本失败, cmd:{}, error: {}", tpiID, resetCmd, resetResult.getString("out")); + throw new GameException("git pull与本地commit冲突, 使用远程版本失败,tpiID:" + tpiID); + } else { + return; + } + } + long currentPullEnd = System.currentTimeMillis(); + logger.debug("##----> gitpull 结束,总耗时间为:" + (currentPullEnd - currentPullStart)); + if (result.getInteger("exitStatus") != 0) { + logger.info("pullCommand: {}, tpiID: {}", pullCommand, tpiID); + logger.info("output: {}, tpiID: {}", result.getString("out"), tpiID); + // 如果pull失败,先check一下,看是不是远端版本库HEAD丢失,如果是,进行修复 + check(tpiID, tpiGitURL); + backupPullError(path, tpiRepoPath, tpiID); + // 重新clone + gitClone(path, tpiGitURL, "origin", tpiRepoName, "--depth=1"); + logger.debug("gitPull冲突,重新clone结束, tpiGitURL: {}, tpiID: {}", tpiGitURL, tpiID); + } else { + // 判段是否成功拉取到更新 + int rePullTimes = 10; + while (contentModified == 1 && rePullTimes > 0 && "Already up-to-date.".equals(result.getString("out"))) { + try { + Thread.sleep(200); + } catch (Exception e) { + } + result = ShellUtil.executeAndGetExitStatus(pullCommand, 1); + rePullTimes--; + } + if (rePullTimes == 0) { + logger.error("版本库有更新,2s之内拉取版本库更新失败!, tpiGitURL: {}, tpiID: {}", tpiGitURL, tpiID); + } else { + logger.debug("pull成功, tpiGitURL: {}, tpiID: {}", tpiGitURL, tpiID); + } + } } - long currentPullEnd = System.currentTimeMillis(); - logger.debug("##----> gitpull 结束,总耗时间为:" + (currentPullEnd - currentPullStart)); - if (result.getInteger("exitStatus") != 0) { - logger.info("pullCommand: {}, tpiID: {}", pullCommand, tpiID); - logger.info("output: {}, tpiID: {}", result.getString("out"), tpiID); - // 如果pull失败,先check一下,看是不是远端版本库HEAD丢失,如果是,进行修复 - check(tpiID, tpiGitURL); - backupPullError(path, tpiRepoPath, tpiID); - // 重新clone - gitClone(path, tpiGitURL, "origin", tpiRepoName, "--depth=1"); - logger.debug("gitPull冲突,重新clone结束, tpiGitURL: {}, tpiID: {}", tpiGitURL, tpiID); - } else { - // 判段是否成功拉取到更新 - int rePullTimes = 10; - while (contentModified == 1 && rePullTimes > 0 && "Already up-to-date.".equals(result.getString("out"))) { - try { - Thread.sleep(200); - } catch (Exception e) { - } - result = ShellUtil.executeAndGetExitStatus(pullCommand, 1); - rePullTimes--; - } - if (rePullTimes == 0) { - logger.error("版本库有更新,2s之内拉取版本库更新失败!, tpiGitURL: {}, tpiID: {}", tpiGitURL, tpiID); - } else { - logger.debug("pull成功, tpiGitURL: {}, tpiID: {}", tpiGitURL, tpiID); - } - } - } private void backupPullError(String path, String tpiRepoPath, String tpiID) { try {