|
|
package com.supervision.rasa.controller;
|
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.supervision.rasa.pojo.vo.RasaArgumentVo;
|
|
|
import com.supervision.rasa.service.RasaCmdService;
|
|
|
import com.supervision.exception.BusinessException;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import java.io.*;
|
|
|
import java.util.concurrent.*;
|
|
|
|
|
|
@Api(tags = "rasa文件保存")
|
|
|
@RestController
|
|
|
@RequestMapping("rasaCmd")
|
|
|
@RequiredArgsConstructor
|
|
|
public class RasaCmdController {
|
|
|
|
|
|
private final RasaCmdService rasaCmdService;
|
|
|
|
|
|
@ApiOperation("执行训练shell命令")
|
|
|
@PostMapping("/trainExec")
|
|
|
public String trainExec(@RequestBody RasaArgumentVo argument) throws IOException, ExecutionException, InterruptedException, TimeoutException {
|
|
|
|
|
|
if (StrUtil.isEmpty(argument.getFixedModelName())){
|
|
|
throw new BusinessException("fixedModelName参数不能为空!");
|
|
|
}
|
|
|
|
|
|
if (StrUtil.isEmpty(argument.getModelId())){
|
|
|
throw new BusinessException("modelId参数不能为空! ");
|
|
|
}
|
|
|
|
|
|
return rasaCmdService.trainExec(argument);
|
|
|
|
|
|
}
|
|
|
|
|
|
@ApiOperation("执行启动shell命令")
|
|
|
@PostMapping("/runExec")
|
|
|
public String runExec(@RequestBody RasaArgumentVo argument) throws ExecutionException, InterruptedException, TimeoutException {
|
|
|
|
|
|
if (StrUtil.isEmpty(argument.getFixedModelName())){
|
|
|
throw new BusinessException("fixedModelName参数不能为空!");
|
|
|
}
|
|
|
if (StrUtil.isEmpty(argument.getModelId())){
|
|
|
throw new BusinessException("modelId参数不能为空! ");
|
|
|
}
|
|
|
String outString = rasaCmdService.runExec(argument);
|
|
|
if (StrUtil.isEmptyIfStr(outString) || !outString.contains("Rasa server is up and running")){
|
|
|
throw new BusinessException("任务执行异常。详细日志:"+outString);
|
|
|
}
|
|
|
return outString;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ApiOperation("执行启动shell命令")
|
|
|
@PostMapping("/test")
|
|
|
public String test(@RequestBody RasaArgumentVo argument) throws ExecutionException, InterruptedException, TimeoutException {
|
|
|
|
|
|
|
|
|
rasaCmdService.test();
|
|
|
|
|
|
return " dd";
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|