Commit c42a09c2 by guo_minglei@163.com

将运行日志放到fastdfs上

parent dfdd469e
package com.byit.executor.jobExecutor.process; package com.byit.executor.jobExecutor.process;
import com.byit.executor.conf.FileSystemContext;
import com.byit.executor.util.JobContentUtil; import com.byit.executor.util.JobContentUtil;
import com.byit.executor.util.LogGobbler; import com.byit.executor.util.LogGobbler;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
...@@ -11,6 +12,7 @@ import java.io.IOException; ...@@ -11,6 +12,7 @@ import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
...@@ -49,22 +51,26 @@ public class MythJobProcess implements Runnable{ ...@@ -49,22 +51,26 @@ public class MythJobProcess implements Runnable{
//本次任务对应的日志id //本次任务对应的日志id
private Integer logId; private Integer logId;
//执行日志内容 //执行日志内容
private String logContent; private String logFilePath;
//上传日志工具类
private FileSystemContext fileSystemContext;
public MythJobProcess(final List<String> cmd, final Map<String, String> env, public MythJobProcess(final List<String> cmd, final Map<String, String> env,
final String workingDir, final Integer logId) { final String workingDir, final Integer logId, FileSystemContext fileSystemContext) {
this.cmd = cmd; this.cmd = cmd;
this.env = env; this.env = env;
this.workingDir = workingDir; this.workingDir = workingDir;
this.processId = -1; this.processId = -1;
this.startupLatch = new CountDownLatch(1); this.startupLatch = new CountDownLatch(1);
this.completeLatch = new CountDownLatch(1); this.completeLatch = new CountDownLatch(1);
this.logId = logId;
this.fileSystemContext = fileSystemContext;
} }
public MythJobProcess(final List<String> cmd, final Map<String, String> env, public MythJobProcess(final List<String> cmd, final Map<String, String> env,
final String workingDir, final String executeAsUserBinary, final String workingDir, final String executeAsUserBinary,
final String effectiveUser, Integer logId) { final String effectiveUser, Integer logId, FileSystemContext fileSystemContext) {
this(cmd, env, workingDir, logId); this(cmd, env, workingDir, logId, fileSystemContext);
this.isExecuteAsUser = true; this.isExecuteAsUser = true;
this.executeAsUserBinary = executeAsUserBinary; this.executeAsUserBinary = executeAsUserBinary;
this.effectiveUser = effectiveUser; this.effectiveUser = effectiveUser;
...@@ -141,8 +147,11 @@ public class MythJobProcess implements Runnable{ ...@@ -141,8 +147,11 @@ public class MythJobProcess implements Runnable{
if (this.process.isAlive()){ if (this.process.isAlive()){
this.process.destroy(); this.process.destroy();
} }
logContent = outputGobbler.getRecentLog() + "\n" + errorGobbler.getRecentLog(); String logContent = outputGobbler.getRecentLog() + "\n" + errorGobbler.getRecentLog();
//TODO 将日志写到fastdfs上 //TODO 将日志写到fastdfs上
Map<String,String> map = new HashMap<String,String>(10);
map.put("filename", logId + ".log");
logFilePath = fileSystemContext.uploadFile(logContent.getBytes(), "log", map);
} }
} }
...@@ -299,6 +308,6 @@ public class MythJobProcess implements Runnable{ ...@@ -299,6 +308,6 @@ public class MythJobProcess implements Runnable{
} }
public String getLogContent(){ public String getLogContent(){
return logContent; return logFilePath;
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment