martin vor 3 Jahren
Ursprung
Commit
1e72af688a

+ 13 - 0
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/service/TaskService.java

@@ -119,7 +119,20 @@ public class TaskService {
             //result-path-minio: /project/manual-project/
             String projectId = taskMapper.selectProjectIdById(taskId);
             String minioPathOfErrorLog = resultPathMinio + projectId + "/" + taskId + "error.log";
+            String errorString = MinioUtil.downloadToString(minioClient, bucketName, minioPathOfErrorLog);
+            String[] lines = errorString.split("\n");
+            AtomicReference<String> errorMessage = new AtomicReference<>("");
+            for (String line : lines) {
+                if (line.startsWith("Original Error")) {
+                    errorMessage.set(errorMessage.get() + line + "\n");
+                }
 
+                if (line.startsWith("Possible Cause")) {
+                    errorMessage.set(errorMessage.get() + line);
+                    break;
+                }
+            }
+            String errorMessageString = errorMessage.get();
             return;
         } else if ("PendingAnalysis".equals(state)) {
             LinuxUtil.execute("kubectl delete pod " + podName);

+ 23 - 0
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/util/MinioUtil.java

@@ -134,4 +134,27 @@ public class MinioUtil {
                 .object(objectName)
                 .build());
     }
+
+    /**
+     * 读取文件内容
+     */
+    public static String downloadToString(
+            MinioClient minioClient,
+            String bucketName,
+            String objectName
+    ) throws IOException, ServerException, InsufficientDataException, ErrorResponseException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, io.minio.errors.InternalException {
+        GetObjectResponse response = minioClient.getObject(GetObjectArgs.builder()
+                .bucket(bucketName)
+                .object(objectName)
+                .build());
+        StringBuilder result = new StringBuilder();
+        byte[] buf = new byte[4096];//创建字节数组,存储临时读取的数据
+        int len;//记录数据读取的长度
+        //循环读取数据
+        while ((len = response.read(buf)) != -1) { //长度为-1则读取完毕
+            result.append(new String(buf, 0, len)).append("\n");
+        }
+        response.close();
+        return result.toString();
+    }
 }