|
|
|
@ -2,7 +2,9 @@ package com.supervision.rasa.service.impl;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
|
|
import cn.hutool.core.collection.ListUtil;
|
|
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
import com.supervision.exception.BusinessException;
|
|
|
|
|
import com.supervision.model.RasaModelInfo;
|
|
|
|
|
import com.supervision.rasa.config.ThreadPoolExecutorConfig;
|
|
|
|
|
import com.supervision.rasa.constant.RasaConstant;
|
|
|
|
@ -13,6 +15,7 @@ import com.supervision.service.RasaModeService;
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
import org.springframework.core.io.ClassPathResource;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
@ -43,14 +46,6 @@ public class RasaCmdServiceImpl implements RasaCmdService {
|
|
|
|
|
@Value("${rasa.shell-env:/bin/bash}")
|
|
|
|
|
private String shellEnv;
|
|
|
|
|
|
|
|
|
|
@Value("${rasa.train-shell}")
|
|
|
|
|
private String trainShell;
|
|
|
|
|
|
|
|
|
|
@Value("${rasa.run-shell}")
|
|
|
|
|
private String runShell;
|
|
|
|
|
|
|
|
|
|
@Value("${rasa.kill-shell}")
|
|
|
|
|
private String killShell;
|
|
|
|
|
|
|
|
|
|
@Value("${rasa.shell.work:/data/vp/rasa_shell/}")
|
|
|
|
|
private String shellWork;
|
|
|
|
@ -73,7 +68,7 @@ public class RasaCmdServiceImpl implements RasaCmdService {
|
|
|
|
|
// /rasa/models 生成出来的模型的存放路径,也写在配置文件里面
|
|
|
|
|
String localModelsPath = replaceDuplicateSeparator(String.join(File.separator,modelsPath,argument.getModelId()));
|
|
|
|
|
|
|
|
|
|
List<String> cmds = ListUtil.toList(shellEnv, trainShell,config,localDataPath,domain,localModelsPath);
|
|
|
|
|
List<String> cmds = ListUtil.toList(shellEnv, getShellPath(RasaConstant.TRAIN_SHELL),config,localDataPath,domain,localModelsPath);
|
|
|
|
|
|
|
|
|
|
cmds.add(argument.getFixedModelName());
|
|
|
|
|
|
|
|
|
@ -87,6 +82,7 @@ public class RasaCmdServiceImpl implements RasaCmdService {
|
|
|
|
|
rasaModelInfo.setModelId(argument.getModelId());
|
|
|
|
|
rasaModelInfo.setTranStatus(trainIsSuccess(outMessage)?1:0);
|
|
|
|
|
rasaModelInfo.setServerStatus(-1);
|
|
|
|
|
cmds.set(1,null);
|
|
|
|
|
rasaModelInfo.setTrainCmd(cmds);
|
|
|
|
|
rasaModelInfo.setTrainLog(outMessageString);
|
|
|
|
|
rasaModeService.saveOrUpdateByModelId(rasaModelInfo);
|
|
|
|
@ -117,7 +113,7 @@ public class RasaCmdServiceImpl implements RasaCmdService {
|
|
|
|
|
fixedModePath = String.join(modeParentPath,fixedModelName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<String> cmds = ListUtil.toList(shellEnv, runShell,fixedModePath,endpoints,String.valueOf(port));
|
|
|
|
|
List<String> cmds = ListUtil.toList(shellEnv, getShellPath(RasaConstant.RUN_SHELL),fixedModePath,endpoints,String.valueOf(port));
|
|
|
|
|
|
|
|
|
|
log.info("runExec cmd : {}",StrUtil.join(" ",cmds));
|
|
|
|
|
|
|
|
|
@ -131,7 +127,7 @@ public class RasaCmdServiceImpl implements RasaCmdService {
|
|
|
|
|
if (null != dbRasaModelInfo.getPort() && runIsSuccess){
|
|
|
|
|
log.info("runExec server is up and dbRasaModelInfo is: {}, start kill old server ....",dbRasaModelInfo.getPort());
|
|
|
|
|
// 3.1 如果原本的程序已经运行且本次成功启动,杀掉原本的进程
|
|
|
|
|
execCmd(ListUtil.toList(runShell, killShell, String.valueOf(dbRasaModelInfo.getPort())), s -> false, 20);
|
|
|
|
|
execCmd(ListUtil.toList(shellEnv, getShellPath(RasaConstant.KILL_SHELL), String.valueOf(dbRasaModelInfo.getPort())), s -> false, 20);
|
|
|
|
|
}
|
|
|
|
|
if (null != dbRasaModelInfo.getPort() && !runIsSuccess){
|
|
|
|
|
// 3.2 如果原本的程序已经运行,但本次程序未正常启动,不对端口号进行变动
|
|
|
|
@ -142,8 +138,8 @@ public class RasaCmdServiceImpl implements RasaCmdService {
|
|
|
|
|
RasaModelInfo rasaModelInfo = new RasaModelInfo();
|
|
|
|
|
rasaModelInfo.setModelId(argument.getModelId());
|
|
|
|
|
rasaModelInfo.setPort(port);
|
|
|
|
|
rasaModelInfo.setServerStatus( runIsSuccess ? 1:0);
|
|
|
|
|
rasaModelInfo.setRunCmd(ListUtil.toList(shellEnv, runShell,fixedModePath,endpoints));
|
|
|
|
|
rasaModelInfo.setServerStatus( runIsSuccess ? 1 : 0 );
|
|
|
|
|
rasaModelInfo.setRunCmd(ListUtil.toList(shellEnv, null,fixedModePath,endpoints));
|
|
|
|
|
rasaModelInfo.setRunLog(outMessageString);
|
|
|
|
|
rasaModeService.saveOrUpdateByModelId(rasaModelInfo);
|
|
|
|
|
|
|
|
|
@ -234,4 +230,24 @@ public class RasaCmdServiceImpl implements RasaCmdService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public String getShellPath(String shell){
|
|
|
|
|
if (StrUtil.isEmpty(shell)){
|
|
|
|
|
throw new BusinessException("shell 不能为空...");
|
|
|
|
|
}
|
|
|
|
|
// 获取 shell 脚本的路径
|
|
|
|
|
String shellPath = "shellScript/" + shell;
|
|
|
|
|
ClassPathResource shellScript = new ClassPathResource(shellPath);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
InputStream inputStream = shellScript.getInputStream();
|
|
|
|
|
File tempFile = File.createTempFile(shell, ".sh");
|
|
|
|
|
tempFile.deleteOnExit();
|
|
|
|
|
FileUtil.writeFromStream(inputStream, tempFile);
|
|
|
|
|
return tempFile.getAbsolutePath();
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|