gtj 2 rokov pred
rodič
commit
5af5359c87

+ 1 - 1
other/gpload/pm_lte_gpload.sh

@@ -5,8 +5,8 @@ source /usr/local/greenplum-db-clients/greenplum_loaders_path.sh
 new_date=$1
 
 # 修改gpload配置文件
-sed -i 's/\/data1\/pm\/pm_4g\/distinct\/pm_4g_hour_[0-9]\{10\}.csv/\/data1\/pm\/distinct\/pm_4g_hour_'${new_date}'.csv/' /data1/pm/pm_4g/pm_lte_gpload2.yml
 
+sed -i 's/\/data1\/pm\/pm_4g\/distinct\/pm_4g_hour_[0-9]\{10\}.csv/\/data1\/pm\/distinct\/pm_4g_hour_'${new_date}'.csv/' /data1/pm/pm_4g/pm_lte_gpload2.yml
 # 由于gpload需要输入密码,这里需要使用expect执行
 password=sqmdb_1QAZ
 

+ 1 - 1
other/gpload/pm_lte_gpload2.yml

@@ -7,7 +7,7 @@ GPLOAD:
   INPUT:
     - SOURCE:
         LOCAL_HOSTNAME:
-          - 192.168.50.3
+          - 192.168.10.7
         PORT: 54321
         FILE:
           - /data1/pm/pm_4g/distinct/pm_4g_hour_2022052409.csv

+ 4 - 2
src/main/java/com/nokia/common/ssh/SSHUtil.java

@@ -194,8 +194,8 @@ public class SSHUtil {
             session = getConnectSession();
             // scp内置了两个参数 -t 和 -f ,这两个参数是隐藏的,不会被用户显式提供,
             // 两个scp进程之间传输数据时,远端机器上的scp进程被本地scp进程启动起来时提供上去。
-            // 需要说明的是,这是通过本地scp进程经ssh远程过去开启远端机器的scp进程来实现的
-            // -f 指定对端为from 也就是源端模式 指定的对象就是session对应的连接对象targetServer
+            // 需要说明的是,。
+            // -f 指定对端为from 也就是源端模式 指定的对象就是se这是通过本地scp进程经ssh远程过去开启远端机器的scp进程来实现的ssion对应的连接对象targetServer
             String command = "scp -f " + sourceFilePath;
             Channel channel = session.openChannel("exec");
             ((ChannelExec) channel).setCommand(command);
@@ -289,12 +289,14 @@ public class SSHUtil {
         log.info("user: {}, host: {}, port: {}", targetServer.getUser(), targetServer.getHost(), targetServer.getPort());
         jSch = new JSch();
         session = jSch.getSession(targetServer.getUser(), targetServer.getHost(), targetServer.getPort());
+        log.info("session {}",session);
         session.setPassword(targetServer.getPassword());
         session.setUserInfo(new UserInfoImpl());
         // 不需要输入保存ssh安全密钥的yes或no
         Properties properties = new Properties();
         properties.put("StrictHostKeyChecking", "no");
         session.setConfig(properties);
+        log.info("session {}",session);
         session.connect();
         log.debug("已连接到{}@{}:{}", targetServer.getUser(), targetServer.getHost(), targetServer.getPort());
         return session;

+ 8 - 10
src/main/java/com/nokia/task/LtePmTask.java

@@ -6,6 +6,7 @@ import com.nokia.common.gpload.GploadUtil;
 import com.nokia.common.gpload.entity.GploadResult;
 import com.nokia.common.ssh.SSHUtil;
 import com.nokia.common.ssh.exception.SSHUtilException;
+import com.xxl.job.core.context.XxlJobHelper;
 import com.xxl.job.core.handler.annotation.XxlJob;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.csv.CSVFormat;
@@ -55,23 +56,17 @@ public class LtePmTask {
 
     @XxlJob("execHandlerPm4G")
     public void cronTask() throws JSchException, SSHUtilException, IOException, SftpException {
-        System.out.println("已触发pm4G");
-        log.info("1");
         // 创建文件夹
         Files.createDirectories(Paths.get(downloadTargetDir));
-        log.info("2");
         Files.createDirectories(Paths.get(distinctTargetDir));
-        log.info("3");
         SSHUtil sshUtil = new SSHUtil(host, port, username, password);
-        log.info("4");
         // 获取文件列表
         List<String> list = sshUtil.ls(sourceDir);
-        log.info("5");
         if (CollectionUtils.isEmpty(list)) {
-            log.info("6");
             return;
         }
         log.debug("扫描到的文件: {}", list);
+        XxlJobHelper.log("扫描到的文件: {}",list);
         for (String s : list) {
             String[] s1 = s.split("_");
             String[] split = s1[3].split("\\.");
@@ -96,7 +91,6 @@ public class LtePmTask {
     }
 
     public void download(String hourString) throws JSchException, SSHUtilException, IOException, SftpException {
-        log.info("hourString: {}", hourString);
         SSHUtil sshUtil = new SSHUtil(host, port, username, password);
         String downloadFileName = filePrefix + hourString + ".csv";
         String sourceFilePath = sourceDir + "/" + downloadFileName;
@@ -108,7 +102,8 @@ public class LtePmTask {
         boolean b = sshUtil.scpFrom(sourceFilePath, targetPath);
         if (b) {
             log.debug("文件 {} 下载成功...", targetPath);
-//           sshUtil.delete(sourceFilePath);
+            XxlJobHelper.log("文件 {} 下载成功...",targetPath);
+           sshUtil.delete(sourceFilePath);
         }
     }
 
@@ -131,15 +126,18 @@ public class LtePmTask {
         printer.flush();
         printer.close();
         log.debug("去重完成,原文件{}条数据,去重后{}条数据", count, recordMap.size());
+        XxlJobHelper.log("去重完成,原文件{}条数据,去重后{}条数据",count, recordMap.size());
     }
 
     public void gpload(String hourString) {
         String gploadCommand = "sh /data1/pm/pm_4g/pm_lte_gpload.sh " + hourString;
         GploadResult gpload = GploadUtil.gpload(gploadCommand);
         if (Boolean.TRUE.equals(gpload.getTaskStatus())) {
-            log.debug("gpload完成: {}", gpload);
+            log.debug("gpload 完成: {}", gpload);
+            XxlJobHelper.log("gpload 完成: {}", gpload);
         } else {
             log.error("gpload 失败: {}", gpload.getMessage());
+            XxlJobHelper.log("gpload 失败: {}", gpload);
         }
     }
 }