|
@@ -4,12 +4,14 @@ package com.gyee.impala.service.master.diagnose;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.gyee.impala.common.config.GyeeConfig;
|
|
import com.gyee.impala.common.config.GyeeConfig;
|
|
import com.gyee.impala.common.config.jsch.JSchConfig;
|
|
import com.gyee.impala.common.config.jsch.JSchConfig;
|
|
|
|
+import com.gyee.impala.common.util.JudeSystem;
|
|
import com.gyee.impala.model.master.diagnose.Diagnosetrainhistory;
|
|
import com.gyee.impala.model.master.diagnose.Diagnosetrainhistory;
|
|
import com.gyee.impala.model.master.diagnose.TrainInfo;
|
|
import com.gyee.impala.model.master.diagnose.TrainInfo;
|
|
import com.gyee.impala.service.custom.SftpFileService;
|
|
import com.gyee.impala.service.custom.SftpFileService;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
+
|
|
import java.io.BufferedReader;
|
|
import java.io.BufferedReader;
|
|
import java.io.InputStreamReader;
|
|
import java.io.InputStreamReader;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
@@ -60,20 +62,23 @@ public class TrainFileModeService {
|
|
isComplete = false;
|
|
isComplete = false;
|
|
//获取上传文件的文件名
|
|
//获取上传文件的文件名
|
|
String type = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
|
|
String type = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
|
|
- ;
|
|
|
|
/**上传文件**/
|
|
/**上传文件**/
|
|
fileService.uploadFile(file.getOriginalFilename(), file.getInputStream(), "10.155.32.14");
|
|
fileService.uploadFile(file.getOriginalFilename(), file.getInputStream(), "10.155.32.14");
|
|
|
|
|
|
|
|
+
|
|
//文件路径
|
|
//文件路径
|
|
String filePath = config.getPath() + file.getOriginalFilename();
|
|
String filePath = config.getPath() + file.getOriginalFilename();
|
|
|
|
|
|
System.out.println(new Date() + "开始执行脚本...");
|
|
System.out.println(new Date() + "开始执行脚本...");
|
|
Process p;
|
|
Process p;
|
|
String cmdPath = gyeeConfig.getDiagnosePath();
|
|
String cmdPath = gyeeConfig.getDiagnosePath();
|
|
|
|
+ String inst = JudeSystem.isWindows() ? "cmd" : "/bin/sh";
|
|
|
|
+ String c = JudeSystem.isWindows() ? "/c" : "-c";
|
|
// String[] cmd = {"/bin/sh", "-c", "python " + cmdPath + name + ".py " + filePath};
|
|
// String[] cmd = {"/bin/sh", "-c", "python " + cmdPath + name + ".py " + filePath};
|
|
- String cmd = "cmd /c python " + cmdPath + name + ".py " + filePath;
|
|
|
|
|
|
+ String[] cmd = {inst, c, "python " + cmdPath + name + ".py " + filePath};
|
|
|
|
|
|
-// System.out.println(cmd[0] + " " + cmd[1] + " " + cmd[2]);
|
|
|
|
|
|
+ Thread.sleep(3000);
|
|
|
|
+ System.out.println(cmd[0] + " " + cmd[1] + " " + cmd[2]);
|
|
p = Runtime.getRuntime().exec(cmd);
|
|
p = Runtime.getRuntime().exec(cmd);
|
|
BufferedReader bri = new BufferedReader(new InputStreamReader(p.getInputStream()));
|
|
BufferedReader bri = new BufferedReader(new InputStreamReader(p.getInputStream()));
|
|
BufferedReader bre = new BufferedReader(new InputStreamReader(p.getErrorStream()));
|
|
BufferedReader bre = new BufferedReader(new InputStreamReader(p.getErrorStream()));
|
|
@@ -84,34 +89,16 @@ public class TrainFileModeService {
|
|
}
|
|
}
|
|
if (se != null) {
|
|
if (se != null) {
|
|
System.err.println(se);
|
|
System.err.println(se);
|
|
|
|
+ TrainInfo t = JSONObject.parseObject(se, TrainInfo.class);
|
|
|
|
+ produce(t);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
-
|
|
|
|
p.waitFor();
|
|
p.waitFor();
|
|
|
|
|
|
- for (int l = 0; l < 20; l++) {
|
|
|
|
- TrainInfo t = new TrainInfo();
|
|
|
|
- t.setLog("请求第" + l + "次");
|
|
|
|
- t.setTime("" + (20 - l));
|
|
|
|
- t.setComplete(isComplete);
|
|
|
|
- produce(t);
|
|
|
|
- Thread.sleep(1000);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
} finally {
|
|
} finally {
|
|
isComplete = true;
|
|
isComplete = true;
|
|
- try {
|
|
|
|
- TrainInfo t1 = new TrainInfo();
|
|
|
|
- t1.setLog("请求第20次");
|
|
|
|
- t1.setTime("0");
|
|
|
|
- t1.setComplete(isComplete);
|
|
|
|
- produce(t1);
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- e.printStackTrace();
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
|
|
|
|
System.out.println(new Date() + "脚本执行结束...");
|
|
System.out.println(new Date() + "脚本执行结束...");
|
|
@@ -121,7 +108,9 @@ public class TrainFileModeService {
|
|
// 控制台信息
|
|
// 控制台信息
|
|
public void produce(TrainInfo trainInfo) throws Exception {
|
|
public void produce(TrainInfo trainInfo) throws Exception {
|
|
// put 控制台信息到队列中
|
|
// put 控制台信息到队列中
|
|
- trainInfo.setComplete(trainInfo.isComplete() ? trainInfo.isComplete() : isComplete);
|
|
|
|
|
|
+// trainInfo.setComplete(trainInfo.getComplete() ? trainInfo.isComplete() : isComplete);
|
|
|
|
+
|
|
|
|
+ System.out.println("add log =["+trainInfo.getLog()+"] time = ["+trainInfo.getTime()+"] complete = ["+isComplete+"]");
|
|
infoQueue.put(trainInfo);
|
|
infoQueue.put(trainInfo);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -134,23 +123,39 @@ public class TrainFileModeService {
|
|
for (int i = 0; i < sise; i++) {
|
|
for (int i = 0; i < sise; i++) {
|
|
TrainInfo info = infoQueue.take();
|
|
TrainInfo info = infoQueue.take();
|
|
list.add(info);
|
|
list.add(info);
|
|
- if (info.isComplete()) {
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
return list;
|
|
return list;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
- public void putDiagnosetrainhistory(String history) throws Exception{
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 保存训练结果
|
|
|
|
+ *
|
|
|
|
+ * @param history
|
|
|
|
+ * @throws Exception
|
|
|
|
+ */
|
|
|
|
+ public void putDiagnosetrainhistory(String history) throws Exception {
|
|
|
|
|
|
Diagnosetrainhistory d = JSONObject.parseObject(history, Diagnosetrainhistory.class);
|
|
Diagnosetrainhistory d = JSONObject.parseObject(history, Diagnosetrainhistory.class);
|
|
d.setEnable(true);
|
|
d.setEnable(true);
|
|
diagnosetrainhistoryService.insertItem(d);
|
|
diagnosetrainhistoryService.insertItem(d);
|
|
- historyQueue.put(d);
|
|
|
|
|
|
+ Diagnosetrainhistory dbhistory = diagnosetrainhistoryService.getHistoryByModel(d.getModel());
|
|
|
|
+ historyQueue.put(dbhistory);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public Diagnosetrainhistory getDiagnosetrainhistory(String id) throws Exception {
|
|
|
|
+ Diagnosetrainhistory history = historyQueue.take();
|
|
|
|
+ return history;
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
|
|
+ public int editDiagnosetrainhistory(String history) {
|
|
|
|
+ Diagnosetrainhistory update = JSONObject.parseObject(history, Diagnosetrainhistory.class);
|
|
|
|
|
|
|
|
+ int code = diagnosetrainhistoryService.editDiagnosetrainhistory(update);
|
|
|
|
+
|
|
|
|
+ return code;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
}
|
|
}
|