|
|
@ -5,6 +5,7 @@ import cn.hutool.core.collection.ListUtil;
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
import com.supervision.model.RasaModelInfo;
|
|
|
|
import com.supervision.model.RasaModelInfo;
|
|
|
|
import com.supervision.rasa.config.ThreadPoolExecutorConfig;
|
|
|
|
import com.supervision.rasa.config.ThreadPoolExecutorConfig;
|
|
|
|
|
|
|
|
import com.supervision.rasa.constant.RasaConstant;
|
|
|
|
import com.supervision.rasa.pojo.vo.RasaCmdArgumentVo;
|
|
|
|
import com.supervision.rasa.pojo.vo.RasaCmdArgumentVo;
|
|
|
|
import com.supervision.rasa.service.RasaCmdService;
|
|
|
|
import com.supervision.rasa.service.RasaCmdService;
|
|
|
|
import com.supervision.rasa.util.PortUtil;
|
|
|
|
import com.supervision.rasa.util.PortUtil;
|
|
|
@ -54,8 +55,6 @@ public class RasaCmdServiceImpl implements RasaCmdService {
|
|
|
|
|
|
|
|
|
|
|
|
private final RasaModeService rasaModeService;
|
|
|
|
private final RasaModeService rasaModeService;
|
|
|
|
|
|
|
|
|
|
|
|
private final String TRAN_SUCCESS_MESSAGE = "Your Rasa model is trained and saved at";
|
|
|
|
|
|
|
|
private final String RUN_SUCCESS_MESSAGE = "Rasa server is up and running";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
@Transactional
|
|
|
|
@Transactional
|
|
|
@ -63,11 +62,12 @@ public class RasaCmdServiceImpl implements RasaCmdService {
|
|
|
|
|
|
|
|
|
|
|
|
String domain = dataPath+"domain.yml";
|
|
|
|
String domain = dataPath+"domain.yml";
|
|
|
|
List<String> cmds = ListUtil.toList(shellEnv, trainShell,config,dataPath,domain,modelsPath);
|
|
|
|
List<String> cmds = ListUtil.toList(shellEnv, trainShell,config,dataPath,domain,modelsPath);
|
|
|
|
|
|
|
|
|
|
|
|
cmds.add(argument.getFixedModelName());
|
|
|
|
cmds.add(argument.getFixedModelName());
|
|
|
|
|
|
|
|
|
|
|
|
log.info("trainExec cmd : {}",StrUtil.join(" ",cmds));
|
|
|
|
log.info("trainExec cmd : {}",StrUtil.join(" ",cmds));
|
|
|
|
|
|
|
|
|
|
|
|
List<String> outMessage = execCmd(cmds, s -> false, 300);
|
|
|
|
List<String> outMessage = execCmd(cmds, s -> StrUtil.isNotBlank(s) && s.contains(RasaConstant.TRAN_SUCCESS_MESSAGE), 300);
|
|
|
|
|
|
|
|
|
|
|
|
//保存 模型信息
|
|
|
|
//保存 模型信息
|
|
|
|
RasaModelInfo rasaModelInfo = new RasaModelInfo();
|
|
|
|
RasaModelInfo rasaModelInfo = new RasaModelInfo();
|
|
|
@ -95,13 +95,14 @@ public class RasaCmdServiceImpl implements RasaCmdService {
|
|
|
|
|
|
|
|
|
|
|
|
log.info("runExec cmd : {}",StrUtil.join(" ",cmds));
|
|
|
|
log.info("runExec cmd : {}",StrUtil.join(" ",cmds));
|
|
|
|
|
|
|
|
|
|
|
|
List<String> outMessageList = execCmd(cmds, s -> StrUtil.isNotBlank(s) && s.contains(RUN_SUCCESS_MESSAGE), 300);
|
|
|
|
List<String> outMessageList = execCmd(cmds, s -> StrUtil.isNotBlank(s) && s.contains(RasaConstant.RUN_SUCCESS_MESSAGE), 300);
|
|
|
|
|
|
|
|
|
|
|
|
// 3. 更新模型信息
|
|
|
|
// 3. 更新模型信息
|
|
|
|
RasaModelInfo rasaModelInfo = new RasaModelInfo();
|
|
|
|
RasaModelInfo rasaModelInfo = new RasaModelInfo();
|
|
|
|
rasaModelInfo.setModelId(argument.getModelId());
|
|
|
|
rasaModelInfo.setModelId(argument.getModelId());
|
|
|
|
rasaModelInfo.setPort(port);
|
|
|
|
rasaModelInfo.setPort(port);
|
|
|
|
rasaModelInfo.setServerStatus(runIsSuccess(outMessageList)?1:0);
|
|
|
|
rasaModelInfo.setServerStatus(runIsSuccess(outMessageList)?1:0);
|
|
|
|
|
|
|
|
rasaModelInfo.setCmd(ListUtil.toList(shellEnv, runShell,mPath,endpoints));
|
|
|
|
rasaModeService.saveOrUpdateByModelId(rasaModelInfo);
|
|
|
|
rasaModeService.saveOrUpdateByModelId(rasaModelInfo);
|
|
|
|
|
|
|
|
|
|
|
|
return String.join("\r\n",outMessageList);
|
|
|
|
return String.join("\r\n",outMessageList);
|
|
|
@ -117,7 +118,7 @@ public class RasaCmdServiceImpl implements RasaCmdService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private List<String> execCmd(List<String> cmds, Predicate<String> endPredicate, long timeOut) throws InterruptedException, ExecutionException, TimeoutException {
|
|
|
|
public List<String> execCmd(List<String> cmds, Predicate<String> endPredicate, long timeOut) throws InterruptedException, ExecutionException, TimeoutException {
|
|
|
|
ProcessBuilder processBuilder = new ProcessBuilder(cmds);
|
|
|
|
ProcessBuilder processBuilder = new ProcessBuilder(cmds);
|
|
|
|
processBuilder.directory(new File(shellWork));
|
|
|
|
processBuilder.directory(new File(shellWork));
|
|
|
|
processBuilder.redirectErrorStream(true);
|
|
|
|
processBuilder.redirectErrorStream(true);
|
|
|
@ -139,7 +140,7 @@ public class RasaCmdServiceImpl implements RasaCmdService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bufferedReader.close();
|
|
|
|
bufferedReader.close();
|
|
|
|
return new ArrayList<>();
|
|
|
|
return outString;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
return future.get(timeOut, TimeUnit.SECONDS);
|
|
|
|
return future.get(timeOut, TimeUnit.SECONDS);
|
|
|
@ -150,13 +151,13 @@ public class RasaCmdServiceImpl implements RasaCmdService {
|
|
|
|
|
|
|
|
|
|
|
|
private boolean trainIsSuccess(List<String> messageList){
|
|
|
|
private boolean trainIsSuccess(List<String> messageList){
|
|
|
|
|
|
|
|
|
|
|
|
return containKey(messageList,TRAN_SUCCESS_MESSAGE);
|
|
|
|
return containKey(messageList,RasaConstant.TRAN_SUCCESS_MESSAGE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private boolean runIsSuccess(List<String> messageList){
|
|
|
|
private boolean runIsSuccess(List<String> messageList){
|
|
|
|
|
|
|
|
|
|
|
|
return containKey(messageList,RUN_SUCCESS_MESSAGE);
|
|
|
|
return containKey(messageList,RasaConstant.RUN_SUCCESS_MESSAGE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private boolean containKey(List<String> messageList,String keyWord){
|
|
|
|
private boolean containKey(List<String> messageList,String keyWord){
|
|
|
|