diff --git a/src/main/java/net/wicp/tams/app/duckula/controller/config/constant/DevOpsType.java b/src/main/java/net/wicp/tams/app/duckula/controller/config/constant/DevOpsType.java index 46161e7516be1b3a3c6d311eab167f8fe79d91f9..fcd46c7e9e5a42b9c3fca5d0a73e33fe5b782704 100644 --- a/src/main/java/net/wicp/tams/app/duckula/controller/config/constant/DevOpsType.java +++ b/src/main/java/net/wicp/tams/app/duckula/controller/config/constant/DevOpsType.java @@ -1,5 +1,6 @@ package net.wicp.tams.app.duckula.controller.config.constant; +import net.wicp.tams.common.apiext.IOUtil; import net.wicp.tams.common.constant.dic.intf.IEnumCombobox; /** @@ -12,7 +13,7 @@ public enum DevOpsType implements IEnumCombobox { flink("flink流计算", "oss://lc-bigdata/flink", "oss://lc-bigdata/flink/init/frontcheck.sh", "oss://lc-bigdata/doris/%s/check_system.sh", "v12", "oss://lc-bigdata/flink/init.tar", - new String[] { "oss://lc-bigdata/flink/init/frontcheck.sh" }), + new String[] { "oss://lc-bigdata/flink/init/ssh_free.sh" }), doris("大数据存储", "oss://lc-bigdata/doris", "oss://lc-bigdata/doris/check_system.sh", "", "", "oss://lc-bigdata/doris/check_system.sh", new String[] {}), @@ -25,24 +26,27 @@ public enum DevOpsType implements IEnumCombobox { private final String installurlFormat; private final String lastversion; private final String[] otherparams;// 其它文件 ,如flink需要在check后要做免密 - private final String checkDownFile;//OSS要下载的文件 + private final String checkDownFile;// OSS要下载的文件 public String getCheckDownFile() { return checkDownFile; } + // 服务器上相对文件地址 public String getRelaPath(String url) { - return url.replace(this.baseurl, ""); + return url.replace(this.baseurl, "/" + this.name()); } public String getRelaPathCheck() { return getRelaPath(this.checkurl); } - public String getRelaPathCheckDir() { + // 服务器上真实的目录地址 + public String getRemoteDirCheckDir() { String fileName = this.checkurl.substring(this.checkurl.lastIndexOf("/") + 1); String replace = getRelaPathCheck().replace(fileName, ""); - return replace; + String retstr = IOUtil.mergeFolderAndFilePath("~/", replace); + return retstr; } public String[] getOtherparams() { diff --git a/src/main/java/net/wicp/tams/duckula/ops/pages/devops/FlinkConfig.java b/src/main/java/net/wicp/tams/duckula/ops/pages/devops/FlinkConfig.java index 75ef34ff5482833005ca6767111db80dfd3f92c6..960026f6562ee5fb1d07a9e2ccf4c138300f5dac 100644 --- a/src/main/java/net/wicp/tams/duckula/ops/pages/devops/FlinkConfig.java +++ b/src/main/java/net/wicp/tams/duckula/ops/pages/devops/FlinkConfig.java @@ -1,6 +1,7 @@ package net.wicp.tams.duckula.ops.pages.devops; import java.util.List; +import java.util.concurrent.CountDownLatch; import org.apache.commons.collections.CollectionUtils; import org.apache.tapestry5.ioc.annotations.Inject; @@ -15,13 +16,16 @@ import net.wicp.tams.app.duckula.controller.bean.models.DevopsFlinkExample; import net.wicp.tams.app.duckula.controller.bean.models.DevopsFlinkExample.Criteria; import net.wicp.tams.app.duckula.controller.config.constant.DevOpsType; import net.wicp.tams.app.duckula.controller.dao.DevopsFlinkMapper; +import net.wicp.tams.common.Conf; import net.wicp.tams.common.Result; import net.wicp.tams.common.apiext.IOUtil; import net.wicp.tams.common.apiext.StringUtil; +import net.wicp.tams.common.apiext.TimeAssist; import net.wicp.tams.common.constant.PathType; import net.wicp.tams.common.constant.dic.YesOrNo; import net.wicp.tams.common.os.SSHAssit; import net.wicp.tams.common.os.pool.SSHConnection; +import net.wicp.tams.common.thread.ThreadPool; import net.wicp.tams.component.tools.TapestryAssist; import net.wicp.tams.duckula.ops.pages.ParentPageBean; @@ -101,7 +105,7 @@ public class FlinkConfig extends ParentPageBean { // 1、登陆 SSHConnection conn = SSHAssit.getConn(devopsFlink.getIp(), devopsFlink.getRootUser(), devopsFlink.getRootPwd()); // String fileName = localPath.substring(localPath.lastIndexOf("/") + 1); - String remoteDir = IOUtil.mergeFolderAndFilePath("~/", DevOpsType.flink.getRelaPathCheckDir()); + String remoteDir = DevOpsType.flink.getRemoteDirCheckDir(); conn.executeCommand("mkdir -p " + remoteDir); // conn.scpToDir(localPath,remoteDir , "0744"); conn.scpDir(localPath, remoteDir, "0744", new String[] {}, new String[] {}); @@ -117,6 +121,7 @@ public class FlinkConfig extends ParentPageBean { } devopsFlink.setIsInit(YesOrNo.yes.name()); devopsFlinkMapper.updateByPrimaryKeySelective(devopsFlink);// 保存check结果 + list = queryHostByCluster(devopsFlink.getCluster());// 重新查一下数据库,因为有数据改变状态 if (YesOrNo.yes.name().equals(devopsFlink.getNeedFree())) { boolean doFree = true;// 默认需要做 for (DevopsFlink ele : list) { @@ -126,27 +131,61 @@ public class FlinkConfig extends ParentPageBean { } } if (doFree) { + CountDownLatch countDownLatch = new CountDownLatch(list.size()); // 三台机都做免密 for (DevopsFlink devopsFlink2 : list) { - SSHConnection freeconn = SSHAssit.getConn(devopsFlink.getIp(), devopsFlink2.getRootUser(), - devopsFlink2.getRootPwd()); - try { - // free - Result freeRs = freeconn.executeCommand(String.format("sh %s %s", - IOUtil.mergeFolderAndFilePath("~/", - DevOpsType.flink.getRelaPath(DevOpsType.flink.getOtherparams()[0])), - freeparam.toString())); - if (freeRs.isSuc()) { - // 保存 - devopsFlink2.setIsFree(YesOrNo.yes.name()); - devopsFlinkMapper.updateByPrimaryKeySelective(devopsFlink2);// 保存免密结果 + ThreadPool.getDefaultPool().submit(new Runnable() { + @Override + public void run() { + Conf.overProp("common.os.ssh.timeout", "30000"); + SSHConnection freeconn = SSHAssit.getConn(devopsFlink2.getIp(), 22, + devopsFlink2.getRootUser(), devopsFlink2.getRootPwd(), 5 * 6000); + try { + // free,由于需要ssh到别的服务器,拿到到返回的日志,采用先做,重定向到~/flink/freelog,再查日志文件的方式完成 + Result freeRs = freeconn.executeCommand(String.format("sh %s %s &>~/flink/freelog", + IOUtil.mergeFolderAndFilePath("~/", + DevOpsType.flink.getRelaPath(DevOpsType.flink.getOtherparams()[0])), + freeparam.toString())); + + TimeAssist.reDoWaitInit("flinkconfig-free"); + while (true) { + try { + boolean reDoWait = TimeAssist.reDoWait("flinkconfig-free", 9);// 9次512秒9分钟不到 + if (reDoWait) { + break; + } + Result freeResult = freeconn.executeCommand("cat ~/flink/freelog"); + if (freeResult.isSuc()) { + if (freeResult.getMessage().contains("执行免密操作结束")) {// 执行完了 + // 成功:ssh scripts run cmd SUCCESS + boolean contains = freeResult.getMessage() + .contains("ssh scripts run cmd ERROR"); + if (!contains) {// 成功 + // 保存 + devopsFlink2.setIsFree(YesOrNo.yes.name()); + devopsFlinkMapper.updateByPrimaryKeySelective(devopsFlink2);// 保存免密结果 + } + break; + } + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + } finally { + SSHAssit.close(freeconn); + countDownLatch.countDown(); + } } - } finally { - SSHAssit.close(freeconn); - } + }); + } + try { + countDownLatch.await();// 全部做完了就放 + } catch (InterruptedException e) { + e.printStackTrace(); } - } } return TapestryAssist.getTextStreamResponse(Result.getSuc());