|
@@ -3,11 +3,14 @@ package com.gyee.impala.service.custom.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.util.JudeSystem;
|
|
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.service.custom.SftpFileService;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
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 java.io.BufferedReader;
|
|
import java.io.BufferedReader;
|
|
import java.io.InputStreamReader;
|
|
import java.io.InputStreamReader;
|
|
@@ -16,6 +19,13 @@ import java.io.InputStreamReader;
|
|
@Service
|
|
@Service
|
|
public class CmdFaultPredictService {
|
|
public class CmdFaultPredictService {
|
|
|
|
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private SftpFileService fileService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private JSchConfig config;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 保存脚本的位置
|
|
* 保存脚本的位置
|
|
*/
|
|
*/
|
|
@@ -41,41 +51,93 @@ public class CmdFaultPredictService {
|
|
return historyQueue;
|
|
return historyQueue;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
- * 在线训诊断用脚本
|
|
|
|
|
|
+ * 使用文件训练故障预测模型
|
|
|
|
+ * @param forecastLabel
|
|
|
|
+ * @param inputLabel
|
|
|
|
+ * @param host
|
|
|
|
+ * @param file
|
|
|
|
+ */
|
|
|
|
+ public void exec(String forecastLabel, String[] inputLabel, String host, MultipartFile file) {
|
|
|
|
+ //判断当前是否有模型在训练
|
|
|
|
+ if (!isComplete) {
|
|
|
|
+ log.error("已有进程在预测");
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ isComplete = false;
|
|
|
|
+ /**上传文件**/
|
|
|
|
+ log.info("正在上传故障预测文件...");
|
|
|
|
+ fileService.uploadFile(file.getOriginalFilename(), file.getInputStream(), "10.155.32.14");
|
|
|
|
+ log.info("上传故障预测文件结束...");
|
|
|
|
+ //文件路径
|
|
|
|
+ String filePath = config.getPath() + file.getOriginalFilename();
|
|
|
|
+ log.info("开始执行离线文件故障预测脚本" + (isComplete) + "...");
|
|
|
|
+
|
|
|
|
+ Process p;
|
|
|
|
+ //组装调用python脚本命令
|
|
|
|
+ String cmdPath = gyeeConfig.getDiagnosePath();
|
|
|
|
+ String inst = JudeSystem.isWindows() ? "cmd" : "/bin/sh";
|
|
|
|
+ String c = JudeSystem.isWindows() ? "/c" : "-c";
|
|
|
|
+ String[] cmd = {inst, c, "python " + cmdPath + "Faul_prediction.py " + filePath};
|
|
|
|
+ log.info(cmd[0] + " " + cmd[1] + " " + cmd[2]);
|
|
|
|
+ //执行命令
|
|
|
|
+ p = Runtime.getRuntime().exec(cmd);
|
|
|
|
+
|
|
|
|
+ p.waitFor();
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }finally {
|
|
|
|
+ isComplete = true;
|
|
|
|
+ log.info("离线文件故障预测脚本执行结束" + (isComplete) + "...");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 在线数据训练故障预测模型
|
|
*/
|
|
*/
|
|
public void exec() {
|
|
public void exec() {
|
|
//判断当前是否有模型在训练
|
|
//判断当前是否有模型在训练
|
|
if (!isComplete) {
|
|
if (!isComplete) {
|
|
- log.error("已有进程在诊断");
|
|
|
|
|
|
+ log.error("已有进程在预测");
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
try {
|
|
try {
|
|
isComplete = false;
|
|
isComplete = false;
|
|
- log.info("开始执行诊断脚本" + (isComplete) + "...");
|
|
|
|
|
|
+ log.info("开始执行在线故障预测脚本" + (isComplete) + "...");
|
|
|
|
|
|
//组装调用脚本命令
|
|
//组装调用脚本命令
|
|
Process p;
|
|
Process p;
|
|
String cmdPath = gyeeConfig.getDiagnosePath();
|
|
String cmdPath = gyeeConfig.getDiagnosePath();
|
|
String inst = JudeSystem.isWindows() ? "cmd" : "/bin/sh";
|
|
String inst = JudeSystem.isWindows() ? "cmd" : "/bin/sh";
|
|
String c = JudeSystem.isWindows() ? "/c" : "-c";
|
|
String c = JudeSystem.isWindows() ? "/c" : "-c";
|
|
- String[] cmd = {inst, c, "python " + cmdPath +".py "};
|
|
|
|
|
|
+ String[] cmd = {inst, c, "python " + cmdPath +"Faul_prediction.py"};
|
|
log.info(cmd[0] + " " + cmd[1] + " " + cmd[2]);
|
|
log.info(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()));
|
|
String si = null, se = null;
|
|
String si = null, se = null;
|
|
while ((si = bri.readLine()) != null || (se = bre.readLine()) != null) {
|
|
while ((si = bri.readLine()) != null || (se = bre.readLine()) != null) {
|
|
if (si != null) {
|
|
if (si != null) {
|
|
- System.out.println("诊断返回信息:" + si);
|
|
|
|
|
|
+ System.out.println("预测返回信息:" + si);
|
|
}
|
|
}
|
|
if (se != null) {
|
|
if (se != null) {
|
|
- System.err.println("诊断返回错误信息:" + se);
|
|
|
|
|
|
+ System.err.println("预测返回错误信息:" + se);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
p.waitFor();
|
|
p.waitFor();
|
|
@@ -84,7 +146,7 @@ public class CmdFaultPredictService {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
}finally {
|
|
}finally {
|
|
isComplete = true;
|
|
isComplete = true;
|
|
- log.info("诊断脚本执行结束" + (isComplete) + "...");
|
|
|
|
|
|
+ log.info("在线故障预测脚本执行结束" + (isComplete) + "...");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|