martin 3 năm trước cách đây
mục cha
commit
d4c5d12ca3

+ 42 - 0
api-common/src/main/java/api/common/util/HttpUtil.java

@@ -17,6 +17,7 @@ import org.apache.http.ssl.SSLContextBuilder;
 import org.apache.http.util.EntityUtils;
 
 import java.io.IOException;
+import java.io.InputStream;
 import java.security.KeyManagementException;
 import java.security.KeyStoreException;
 import java.security.NoSuchAlgorithmException;
@@ -116,6 +117,47 @@ public class HttpUtil {
         }
     }
 
+
+    /**
+     * 默认请求头的 get 请求下载文件
+     *
+     * @param url 请求地址
+     * @return 文件流
+     * @throws IOException 异常
+     */
+    public static InputStream getInputStream(CloseableHttpClient closeableHttpClient, RequestConfig requestConfig, String url) throws IOException {
+        return getInputStream(closeableHttpClient, requestConfig, url, null);
+    }
+
+    /**
+     * 自定义请求头的 get 请求下载文件
+     *
+     * @param url     请求地址
+     * @param headers 请求头,可为 null
+     * @return 文件流
+     * @throws IOException 异常
+     */
+    public static InputStream getInputStream(CloseableHttpClient closeableHttpClient, RequestConfig requestConfig, String url, Map<String, String> headers) throws IOException {
+        //1 创建 post 请求
+        HttpGet get = new HttpGet(url);
+        //2 设置请求默认配置
+        get.setConfig(requestConfig);
+        //3 设置请求头 post.setHeader("Content-type", "application/json; charset=utf-8");
+        if (!CollectionUtil.isEmpty(headers)) {
+            headers.forEach(get::setHeader);
+        }
+        //4 发送请求
+        CloseableHttpResponse response = closeableHttpClient.execute(get);
+        //5 处理返回结果,
+        //5-1 如果状态码为200,就是正常返回
+        int statusCode = response.getStatusLine().getStatusCode();
+        if (statusCode == 200) {
+            return response.getEntity().getContent();
+        } else {
+            throw new RuntimeException("------- 请求错误:" + statusCode);
+        }
+    }
+
     /**
      * 发送 post 请求
      */

+ 28 - 34
simulation-resource-common/src/main/java/com/css/simulation/resource/common/controller/MinioController.java

@@ -71,7 +71,7 @@ public class MinioController {
     ) throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException {
         String type = request.getParameter("type");
         String objectPath = request.getParameter("objectPath");
-        if (file != null){
+        if (file != null) {
             String objectName = "";
             Integer nowTime = TimeUtil.getRq(new Date(), 0);
             if (type.equals(DictConstants.ALGORITHM_FILE)) {
@@ -94,20 +94,14 @@ public class MinioController {
         return new ResponseBodyVO(ResponseBodyVO.Response.CLIENT_FAILURE, "文件流file为空,请检查!");
     }
 
-//    @PostMapping("/download")
-//    public ResponseBodyVO<String> download(
-//            @RequestBody @Validated MinioParameter minioParameter,
-//            HttpServletResponse response
-//    ) throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException {
-//        InputStream inputStream = MinioUtil.downloadToStream(
-//                minioClient,
-//                bucketName,
-//                minioParameter.getObjectName()
-//        );
-//        String fileName = FileUtil.getFileName(minioParameter.getObjectName());
-//        FileUtil.downloadForHttp(fileName, inputStream, response, 1024);
-//        return new ResponseBodyVO<>(ResponseBodyVO.Response.SUCCESS);
-//    }
+    @PostMapping("/download")
+    public ResponseBodyVO<List<String>> download(
+            @RequestBody @Validated MinioParameter minioParameter
+    ) throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException {
+
+        List<String> objects = MinioUtil.listObjects(minioClient, bucketName, minioParameter.getObjectName());
+        return new ResponseBodyVO<>(ResponseBodyVO.Response.SUCCESS, objects);
+    }
 
     @PostMapping("/download")
     public void download(
@@ -124,7 +118,7 @@ public class MinioController {
     }
 
     @RequestMapping("/preview")
-    public void preview(@RequestParam("objectName") String objectName, HttpServletResponse response ) throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException {
+    public void preview(@RequestParam("objectName") String objectName, HttpServletResponse response) throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException {
         InputStream inputStream = MinioUtil.downloadToStream(
                 minioClient,
                 bucketName,
@@ -136,26 +130,26 @@ public class MinioController {
 
     @RequestMapping("/createMultipartUpload")
     @ResponseBody
-    public ResponseBodyVO createMultipartUpload(@RequestBody Map<String,String> paramMap) throws Exception {
+    public ResponseBodyVO createMultipartUpload(@RequestBody Map<String, String> paramMap) throws Exception {
         String objectName = paramMap.get("objectName");
         String chunkSize = paramMap.get("chunkSize");
         String type = paramMap.get("type");
-        if(ObjectUtil.isNull(objectName) || ObjectUtil.isNull(chunkSize) || ObjectUtil.isNull(type)){
-            return new ResponseBodyVO(ResponseBodyVO.Response.CLIENT_FAILURE,"请求参数缺失");
+        if (ObjectUtil.isNull(objectName) || ObjectUtil.isNull(chunkSize) || ObjectUtil.isNull(type)) {
+            return new ResponseBodyVO(ResponseBodyVO.Response.CLIENT_FAILURE, "请求参数缺失");
         }
         Integer nowTime = TimeUtil.getRq(new Date(), 0);
         if (type.equals(DictConstants.ALGORITHM_FILE)) {
             objectName = "algorithm/" + nowTime + "/" + objectName;
         }
-        Map<String,Object> result = new HashMap<>();//结果数据
+        Map<String, Object> result = new HashMap<>();//结果数据
         CreateMultipartUploadResponse multipartUpload = minioClient.createMultipartUpload(bucketName, null, objectName, null, null);
         String uploadId = multipartUpload.result().uploadId();
         List<String> UrlList = new LinkedList<>();
-        Map<String,String> queryParam = new HashMap();
-        queryParam.put("uploadId",uploadId);
+        Map<String, String> queryParam = new HashMap();
+        queryParam.put("uploadId", uploadId);
         int size = Integer.valueOf(chunkSize);
         for (int i = 1; i <= size; i++) {
-            queryParam.put("partNumber",String.valueOf(i));
+            queryParam.put("partNumber", String.valueOf(i));
             String presignedObjectUrl = minioClient.getPresignedObjectUrl(GetPresignedObjectUrlArgs.builder()
                     .method(Method.PUT)
                     .bucket(bucketName)
@@ -165,29 +159,29 @@ public class MinioController {
                     .build());
             UrlList.add(presignedObjectUrl);
         }
-        result.put("uploadId",uploadId);
-        result.put("uploadUrls",UrlList);
-        result.put("objectName",objectName);
-        return new ResponseBodyVO(ResponseBodyVO.Response.SUCCESS,result);
+        result.put("uploadId", uploadId);
+        result.put("uploadUrls", UrlList);
+        result.put("objectName", objectName);
+        return new ResponseBodyVO(ResponseBodyVO.Response.SUCCESS, result);
     }
 
     @RequestMapping("/completeMultipartUpload")
     @ResponseBody
-    public ResponseBodyVO completeMultipartUpload(@RequestBody Map<String,String> paramMap) throws Exception {
+    public ResponseBodyVO completeMultipartUpload(@RequestBody Map<String, String> paramMap) throws Exception {
         String objectName = paramMap.get("objectName");
         String uploadId = paramMap.get("uploadId");
-        if(ObjectUtil.isNull(objectName) || ObjectUtil.isNull(uploadId)){
-            return new ResponseBodyVO(ResponseBodyVO.Response.CLIENT_FAILURE,"请求参数缺失");
+        if (ObjectUtil.isNull(objectName) || ObjectUtil.isNull(uploadId)) {
+            return new ResponseBodyVO(ResponseBodyVO.Response.CLIENT_FAILURE, "请求参数缺失");
         }
         ListPartsResponse listPartsResponse = minioClient.listParts(bucketName, null, objectName, 10000, 0, uploadId, null, null);
         List<Part> parts = listPartsResponse.result().partList();
         Part[] partArr = new Part[parts.size()];
         int partNumber = 1;
-        for (Part part: parts) {
-            partArr[partNumber-1] = new Part(partNumber,part.etag());
+        for (Part part : parts) {
+            partArr[partNumber - 1] = new Part(partNumber, part.etag());
             partNumber++;
         }
-        minioClient.completeMultipartUpload(bucketName,null,objectName,uploadId,partArr,null,null);
-        return new ResponseBodyVO(ResponseBodyVO.Response.SUCCESS,"合并成功");
+        minioClient.completeMultipartUpload(bucketName, null, objectName, uploadId, partArr, null, null);
+        return new ResponseBodyVO(ResponseBodyVO.Response.SUCCESS, "合并成功");
     }
 }

+ 26 - 14
simulation-resource-common/src/main/java/com/css/simulation/resource/common/util/MinioUtil.java

@@ -6,11 +6,9 @@ import api.common.util.ObjectUtil;
 import com.css.simulation.resource.common.controller.RedisController;
 import com.css.simulation.resource.common.util.processbar.ProgressInputStream;
 import io.minio.*;
-import io.minio.errors.ErrorResponseException;
-import io.minio.errors.InsufficientDataException;
-import io.minio.errors.InvalidResponseException;
-import io.minio.errors.XmlParserException;
+import io.minio.errors.*;
 import io.minio.http.Method;
+import io.minio.messages.Item;
 import jdk.nashorn.internal.runtime.regexp.joni.exception.InternalException;
 import org.springframework.web.multipart.MultipartFile;
 
@@ -19,6 +17,8 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.security.InvalidKeyException;
 import java.security.NoSuchAlgorithmException;
+import java.util.ArrayList;
+import java.util.List;
 
 public class MinioUtil {
 
@@ -38,22 +38,34 @@ public class MinioUtil {
         }
     }
 
-
     /**
-     * 获取预览路径
+     * 获取文件列表
      *
-     * @return 预览路径
+     * @param minioClient minio 客户端
+     * @param bucket      bucket 名称
+     * @param prefix      目录名
+     * @return 文件路径列表
      */
-    public static String getFileList(MinioClient minioClient, Method method, String bucket, String object) throws io.minio.errors.ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, io.minio.errors.InternalException {
-
+    public static List<String> listObjects(MinioClient minioClient, String bucket, String prefix) throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, io.minio.errors.InternalException {
+        Iterable<Result<Item>> objects = minioClient.listObjects(
+                ListObjectsArgs.builder()
+                        .bucket(bucket)
+                        .recursive(true)
+                        .prefix(prefix)
+                        .build()
+        );
+        List<String> result = new ArrayList<>();
+        for (Result<Item> next : objects) {
+            Item item = next.get();
+            String objectName = item.objectName();
+            result.add(objectName);
+        }
 
-        return minioClient.getPresignedObjectUrl(GetPresignedObjectUrlArgs.builder()
-                .method(method)
-                .bucket(bucket)
-                .object(object)
-                .build());
+        return result;
     }
 
+
+
     /**
      * 获取预览路径
      *

+ 2 - 3
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/configuration/kubernetes/KubernetesConfiguration.java

@@ -5,7 +5,6 @@ import io.kubernetes.client.util.ClientBuilder;
 import io.kubernetes.client.util.KubeConfig;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
-import org.springframework.util.ResourceUtils;
 
 import java.io.File;
 import java.io.FileReader;
@@ -16,9 +15,9 @@ public class KubernetesConfiguration {
 
     @Bean
     public ApiClient apiClient() throws IOException {
-        File config = ResourceUtils.getFile("classpath:kubernetes/config");  // 开发环境可用,生产环境不行,无法从jar 包读取
+//        File config = ResourceUtils.getFile("classpath:kubernetes/config");  // 开发环境可用,生产环境不行,无法从jar 包读取
 //        File config = new File("D:\\idea-project\\simulation-cloud\\simulation-resource-scheduler\\src\\main\\resources\\kubernetes\\config");  //windows
-//        File config = new File("/root/.kube/config");   //linux
+        File config = new File("/root/.kube/config");   //linux
 //
 //        ClassPathResource classPathResource = new ClassPathResource("kubernetes/config");
 //        InputStream inputStream =classPathResource.getInputStream();

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 41 - 22
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/consumer/ManualProjectConsumer.java


+ 1 - 1
simulation-resource-scheduler/src/main/java/com/css/simulation/resource/scheduler/controller/TaskController.java

@@ -27,7 +27,7 @@ public class TaskController {
         return hello;
     }
 
-    @PostMapping("/download")
+    @RequestMapping("/download")
     public void download(
             @RequestParam("filePath") String filePath,
             HttpServletResponse response

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

@@ -101,6 +101,8 @@ public class MinioUtil {
                 .build());
     }
 
+
+
     /**
      * 下载文件
      */

+ 2 - 2
simulation-resource-server/src/main/java/com/css/simulation/resource/scene/ctrl/HomePageController.java

@@ -45,8 +45,8 @@ public class HomePageController {
         Map<String,Integer> map = algorithmService.selectDetailsBySy();
         map.put("ConfigTotal", ConfigService.getConfigTotal());
         map.put("SceneNum", sceneNaturalService.querySceneNumBySy());
-        map.put("maxConcurrency", sceneNaturalService.querySceneNumBySy());
-        map.put("currentConcurrency", sceneNaturalService.querySceneNumBySy());
+        map.put("maxConcurrency", 1);
+        map.put("currentConcurrency", 1);
         return new ResponseBodyVO<>(ResponseBodyVO.Response.SUCCESS, map);
     }
 

Một số tệp đã không được hiển thị bởi vì quá nhiều tập tin thay đổi trong này khác