|
@@ -257,12 +257,12 @@ public class algTrainController {
|
|
|
@GetMapping("/startTraining")
|
|
|
public R startTraining(String algorithmTrainingId) throws DockerException, InterruptedException, RegionConflictException, InvalidBucketNameException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException {
|
|
|
AlgTrain algTrain=algTrainService.selectByPrimaryKey(Long.parseLong(algorithmTrainingId));
|
|
|
- try {
|
|
|
+// try {
|
|
|
// if(!DockerClientUtils.isContainerRunning(algTrain.getContainerId())){
|
|
|
// DockerClientUtils.startContainer(algTrain.getContainerId());
|
|
|
// Thread.sleep(7000);
|
|
|
// }
|
|
|
- String minioPath = DockerClientUtils.execPython(algTrain.getContainerId(), "algTrain" + algTrain.getAlgorithmTrainingId(), algTrain.getRunfileName(), algorithmTrainingId);
|
|
|
+ String logFile = DockerClientUtils.execPython(algTrain.getContainerId(), "algTrain" + algTrain.getAlgorithmTrainingId(), algTrain.getRunfileName(), algorithmTrainingId);
|
|
|
|
|
|
//完成训练后,将任务状态改为已结束,并保存结束时间
|
|
|
algTrain.setMissStatus((byte) 3);
|
|
@@ -275,19 +275,20 @@ public class algTrainController {
|
|
|
Date date = new Date();
|
|
|
//SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
algTrain.setMissStopTime(date);
|
|
|
+ algTrain.setLogFile(logFile);
|
|
|
algTrainService.update(algTrain);
|
|
|
|
|
|
//保存日志到数据库
|
|
|
- String algorithmTrainingLogContent = (String) getOutput(algorithmTrainingId, minioPath).get("output");
|
|
|
+ String algorithmTrainingLogContent = (String) getOutput(algorithmTrainingId, logFile).get("output");
|
|
|
AlgTrainLog algTrainLog = new AlgTrainLog();
|
|
|
algTrainLog.setAlgorithmTrainingId(Long.parseLong(algorithmTrainingId));
|
|
|
algTrainLog.setAlgorithmTrainingLogContent(algorithmTrainingLogContent);
|
|
|
- algTrainLog.setAlgorithmTrainingLogMinioPath(minioPath);
|
|
|
+ algTrainLog.setAlgorithmTrainingLogMinioPath(logFile);
|
|
|
algTrainLogService.save(algTrainLog);
|
|
|
//运行结束之后停掉docker
|
|
|
- } finally {
|
|
|
+// } finally {
|
|
|
// DockerClientUtils.stopContainer(algTrain.getContainerId());
|
|
|
- }
|
|
|
+// }
|
|
|
|
|
|
// 产生数据
|
|
|
// publisher.publishMessage(
|
|
@@ -310,7 +311,7 @@ public class algTrainController {
|
|
|
// }catch (Exception e){
|
|
|
// throw e;
|
|
|
// }
|
|
|
- return R.ok();
|
|
|
+ return R.ok().put("logFile", logFile);
|
|
|
}
|
|
|
|
|
|
@Async
|
|
@@ -358,6 +359,7 @@ public class algTrainController {
|
|
|
Long algorithmTrainingId = algTrain.getAlgorithmTrainingId();
|
|
|
executorService.submit(() -> {
|
|
|
try {
|
|
|
+ changeMissStatus(String.valueOf(algorithmTrainingId));
|
|
|
startTraining(String.valueOf(algorithmTrainingId));
|
|
|
} catch (Exception e) {
|
|
|
throw new RRException(e.getMessage());
|
|
@@ -374,7 +376,7 @@ public class algTrainController {
|
|
|
// // 初始化时运行
|
|
|
// int flag = 0; //标志位,判断是否初始化成功
|
|
|
// if (subscriber.listener != null && subscriber.listener.isRequest == 1) {
|
|
|
-//// algRun(subscriber.listener.algMap);
|
|
|
+// algRun(subscriber.listener.algMap);
|
|
|
// flag = 1;
|
|
|
// }
|
|
|
// if (flag == 1) {
|
|
@@ -382,19 +384,16 @@ public class algTrainController {
|
|
|
// }
|
|
|
// }
|
|
|
|
|
|
- private void algRun(Map<String, String> algMap) throws DockerException, InvalidBucketNameException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InterruptedException, InvalidResponseException, XmlParserException, InternalException, RegionConflictException {
|
|
|
- for(Map.Entry<String, String> map : algMap.entrySet()){
|
|
|
- String key = map.getKey();
|
|
|
- String missName = map.getValue();
|
|
|
- AlgTrain algTrain = algTrainService.selectByMissName(missName);
|
|
|
- Long algorithmTrainingId = algTrain.getAlgorithmTrainingId();
|
|
|
- startTraining(String.valueOf(algorithmTrainingId));
|
|
|
- }
|
|
|
- }
|
|
|
-//
|
|
|
-// private void resolverDDS(){
|
|
|
-// subscriber.listener.algMap.get()
|
|
|
+// private void algRun(Map<String, String> algMap) throws DockerException, InvalidBucketNameException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InterruptedException, InvalidResponseException, XmlParserException, InternalException, RegionConflictException {
|
|
|
+// for(Map.Entry<String, String> map : algMap.entrySet()){
|
|
|
+// String key = map.getKey();
|
|
|
+// String missName = map.getValue();
|
|
|
+// AlgTrain algTrain = algTrainService.selectByMissName(missName);
|
|
|
+// Long algorithmTrainingId = algTrain.getAlgorithmTrainingId();
|
|
|
+// startTraining(String.valueOf(algorithmTrainingId));
|
|
|
+// }
|
|
|
// }
|
|
|
+//
|
|
|
/**
|
|
|
* Description:根据algorithmTrainingId,开始训练,并附带参数
|
|
|
* @param algorithmTrainingId
|
|
@@ -466,39 +465,20 @@ public class algTrainController {
|
|
|
* @return
|
|
|
*/
|
|
|
@GetMapping("/getOutput")
|
|
|
- public R getOutput(String algorithmTrainingId, String minioPath) throws DockerException, InterruptedException, IOException, InvalidResponseException, InvalidKeyException, NoSuchAlgorithmException, ErrorResponseException, XmlParserException, InvalidBucketNameException, InsufficientDataException, InternalException {
|
|
|
-// AlgTrain algTrain = algTrainService.selectByPrimaryKey(Long.parseLong(algorithmTrainingId));
|
|
|
-// DockerClientUtils.copyFile(algTrain.getContainerId(),"/" + returnFileName,"/opt/algTrain" + algorithmTrainingId);
|
|
|
-// InputStream inputStream = FTPUtils.downloadFile("/opt/uploadFile/algTrain" + algorithmTrainingId + "/" + returnFileName);
|
|
|
-// if (inputStream == null) {
|
|
|
-// return R.error("结果不存在");
|
|
|
-// }
|
|
|
-// String result = new BufferedReader(new InputStreamReader(inputStream))
|
|
|
-// .lines().collect(Collectors.joining("\n"));
|
|
|
-//
|
|
|
-// inputStream.close();
|
|
|
-//// System.out.println(result);
|
|
|
-//
|
|
|
-// return R.ok().put("output",result);
|
|
|
- String objectName = "";
|
|
|
- if (minioPath == null) {
|
|
|
- AlgTrainLog algTrainLog = algTrainLogService.selectByAlgTrainId(Long.parseLong(algorithmTrainingId));
|
|
|
- objectName = algTrainLog.getAlgorithmTrainingLogMinioPath();
|
|
|
- } else {
|
|
|
- objectName = minioPath;
|
|
|
- }
|
|
|
- log.info("获取文件从minio的objectName {}", objectName);
|
|
|
- try (InputStream fileInputStream = MinIoUtils.getFileInputStream("algorithm-train-task", objectName)) {
|
|
|
- // 继续处理文件流
|
|
|
- String result = new BufferedReader(new InputStreamReader(fileInputStream))
|
|
|
- .lines().collect(Collectors.joining("\n"));
|
|
|
- log.info("result {}", result);
|
|
|
- return R.ok().put("output", result);
|
|
|
- } catch (ErrorResponseException e){
|
|
|
- if (e.getMessage().equals("The specified key does not exist."))
|
|
|
- return R.error("文件不存在,请确认文件位置或者重新上传");
|
|
|
- else return R.error(e.getMessage());
|
|
|
+ public R getOutput(String algorithmTrainingId, String logFile) throws DockerException, InterruptedException, IOException, InvalidResponseException, InvalidKeyException, NoSuchAlgorithmException, ErrorResponseException, XmlParserException, InvalidBucketNameException, InsufficientDataException, InternalException {
|
|
|
+ AlgTrain algTrain = algTrainService.selectByPrimaryKey(Long.parseLong(algorithmTrainingId));
|
|
|
+ DockerClientUtils.copyFile(algTrain.getContainerId(),"/" + logFile,"/opt/algTrain" + algorithmTrainingId);
|
|
|
+ InputStream inputStream = FTPUtils.downloadFile("/opt/uploadFile/algTrain" + algorithmTrainingId + "/" + logFile);
|
|
|
+ if (inputStream == null) {
|
|
|
+ return R.error("结果不存在");
|
|
|
}
|
|
|
+ String result = new BufferedReader(new InputStreamReader(inputStream))
|
|
|
+ .lines().collect(Collectors.joining("\n"));
|
|
|
+
|
|
|
+ inputStream.close();
|
|
|
+// System.out.println(result);
|
|
|
+
|
|
|
+ return R.ok().put("output",result);
|
|
|
}
|
|
|
|
|
|
/**
|