|
|
|
@ -1,6 +1,8 @@
|
|
|
|
|
package com.supervision.rasa.service;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
|
|
import cn.hutool.core.lang.Assert;
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
import com.supervision.model.RasaModelInfo;
|
|
|
|
|
import com.supervision.rasa.constant.RasaConstant;
|
|
|
|
@ -9,9 +11,14 @@ import com.supervision.rasa.util.PortUtil;
|
|
|
|
|
import com.supervision.service.RasaModeService;
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.FileFilter;
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
import java.util.Comparator;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.concurrent.ExecutionException;
|
|
|
|
|
import java.util.concurrent.TimeoutException;
|
|
|
|
@ -22,6 +29,9 @@ import java.util.stream.Collectors;
|
|
|
|
|
@RequiredArgsConstructor
|
|
|
|
|
public class RasaModelManager {
|
|
|
|
|
|
|
|
|
|
@Value("${rasa.models-path}")
|
|
|
|
|
private String modelsPath;
|
|
|
|
|
|
|
|
|
|
private final RasaModeService rasaModeService;
|
|
|
|
|
|
|
|
|
|
private final RasaCmdService rasaCmdService;
|
|
|
|
@ -40,12 +50,20 @@ public class RasaModelManager {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 2. 重新启动中断的服务
|
|
|
|
|
for (RasaModelInfo rasaModelInfo : activeRasaList) {
|
|
|
|
|
for (RasaModelInfo rasaModelInfo : activeRasaList) {
|
|
|
|
|
if (!PortUtil.portIsActive(rasaModelInfo.getPort())){
|
|
|
|
|
try {
|
|
|
|
|
RasaRunParam rasaRunParam = RasaRunParam.build(rasaModelInfo.getRunCmd());
|
|
|
|
|
rasaRunParam.setPort(String.valueOf(rasaModelInfo.getPort()));
|
|
|
|
|
rasaRunParam.setShellPath(rasaCmdService.getShellPath(RasaConstant.RUN_SHELL));
|
|
|
|
|
String rasaModelPath = rasaRunParam.getRasaModelPath();
|
|
|
|
|
if (StrUtil.isEmpty(rasaModelPath) || !FileUtil.exist(rasaModelPath)){
|
|
|
|
|
log.info("wakeUpInterruptServer: rasa model path {} not exist,attempt find last ...",rasaModelPath);
|
|
|
|
|
String modeParentPath = replaceDuplicateSeparator(String.join(File.separator, modelsPath, rasaModelInfo.getModelId()));
|
|
|
|
|
String fixedModePath = listLastFilePath(modeParentPath, f -> f.getName().matches("-?\\d+(\\.\\d+)?.tar.gz"));
|
|
|
|
|
Assert.notEmpty(fixedModePath,"wakeUpInterruptService: rasa model path {} not exist,attempt find last ...",rasaModelPath);
|
|
|
|
|
rasaRunParam.setRasaModelPath(fixedModePath);
|
|
|
|
|
}
|
|
|
|
|
List<String> outMessageList = rasaCmdService.execCmd(rasaRunParam.toList(),
|
|
|
|
|
s -> StrUtil.isNotBlank(s) && s.contains(RasaConstant.RUN_SUCCESS_MESSAGE), 300);
|
|
|
|
|
|
|
|
|
@ -79,7 +97,8 @@ public class RasaModelManager {
|
|
|
|
|
wakeUpInterruptServer();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
} finally {
|
|
|
|
|
} catch (Exception e){
|
|
|
|
|
log.error("wakeUpInterruptServerScheduled: Scheduled is run failed....",e);
|
|
|
|
|
wakeUpInterruptServerRunning = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -99,4 +118,31 @@ public class RasaModelManager {
|
|
|
|
|
}
|
|
|
|
|
return messageList.stream().anyMatch(s->StrUtil.isNotEmpty(s) && s.contains(keyWord));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String replaceDuplicateSeparator(String path){
|
|
|
|
|
|
|
|
|
|
if (StrUtil.isEmpty(path)){
|
|
|
|
|
return path;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return path.replace(File.separator + File.separator, File.separator);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String listLastFilePath(String path, FileFilter filter){
|
|
|
|
|
File file = listLastFile(path, filter);
|
|
|
|
|
if (null == file){
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return file.getPath();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private File listLastFile(String path,FileFilter filter){
|
|
|
|
|
File file = new File(path);
|
|
|
|
|
File[] files = file.listFiles(filter);
|
|
|
|
|
if (null == files){
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Arrays.stream(files).max(Comparator.comparing(File::getName)).orElse(null);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|