Browse Source

Minio版本更新。支持MinioServer至RELEASE.2021-08-31T05-46-54Z版本。

yucheng 3 years ago
parent
commit
d2e9602009

+ 0 - 1
dmp-comp/dmp-file-starter/pom.xml

@@ -16,7 +16,6 @@
         <dependency>
             <groupId>io.minio</groupId>
             <artifactId>minio</artifactId>
-            <version>7.0.2</version>
         </dependency>
         <!-- fm 工具包 -->
         <dependency>

+ 6 - 7
dmp-comp/dmp-file-starter/src/main/java/com/persagy/dmp/storage/config/MinioConfig.java

@@ -1,8 +1,6 @@
 package com.persagy.dmp.storage.config;
 
-import com.persagy.dmp.common.exception.BusinessException;
 import io.minio.MinioClient;
-import io.minio.errors.MinioException;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
@@ -27,10 +25,11 @@ public class MinioConfig {
 
     @Bean
     public MinioClient minioClient() {
-        try {
-            return new MinioClient(url, accessKey, secretKey);
-        } catch (MinioException e) {
-            throw new BusinessException(e.getMessage(), e);
-        }
+//        try {
+//            return new MinioClient(url, accessKey, secretKey);
+            return MinioClient.builder().endpoint(url).credentials(accessKey, secretKey).build();
+//        } catch (MinioException e) {
+//            throw new BusinessException(e.getMessage(), e);
+//        }
     }
 }

+ 3 - 3
dmp-comp/dmp-file-starter/src/main/java/com/persagy/dmp/storage/service/impl/MinioExceptionHandler.java

@@ -31,9 +31,9 @@ public class MinioExceptionHandler {
         if(e instanceof InvalidResponseException) {
             throw new BusinessException("文件服务器密钥有误");
         }
-        if(e instanceof InvalidBucketNameException) {
-            throw new BusinessException("文件服务器-不合法的存储桶名称。");
-        }
+//        if(e instanceof InvalidBucketNameException) {
+//            throw new BusinessException("文件服务器-不合法的存储桶名称。");
+//        }
         if(e instanceof ErrorResponseException) {
             throw new BusinessException("文件服务器-执行失败异常。");
         }

+ 21 - 12
dmp-comp/dmp-file-starter/src/main/java/com/persagy/dmp/storage/service/impl/MinioStorageServiceImpl.java

@@ -4,9 +4,7 @@ import cn.hutool.core.util.StrUtil;
 import com.persagy.dmp.common.exception.BusinessException;
 import com.persagy.dmp.storage.constant.FileCommonConst;
 import com.persagy.dmp.storage.service.IFileStorageService;
-import io.minio.MinioClient;
-import io.minio.ObjectStat;
-import io.minio.PutObjectOptions;
+import io.minio.*;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 
@@ -35,8 +33,10 @@ public class MinioStorageServiceImpl implements IFileStorageService {
             // 确认桶是否存在
             bucketName = ensureBucket(bucketName);
             // 上传文件
-            PutObjectOptions options = new PutObjectOptions(input.available(), -1);
-            minioClient.putObject(bucketName, fileName, input, options);
+//            PutObjectOptions options = new PutObjectOptions(input.available(), -1);
+//            minioClient.putObject(bucketName, fileName, input, options);
+            minioClient.putObject(PutObjectArgs.builder().bucket(bucketName).object(fileName).
+                            stream(input, input.available(), -1).build());
         } catch (Exception e) {
             MinioExceptionHandler.handleException(e);
         }
@@ -52,7 +52,8 @@ public class MinioStorageServiceImpl implements IFileStorageService {
             // 确认桶是否存在
             bucketName = ensureBucket(bucketName);
             // 下载文件
-            return minioClient.getObject(bucketName, fileName);
+//            return minioClient.getObject(bucketName, fileName);
+            return minioClient.getObject(GetObjectArgs.builder().bucket(bucketName).object(fileName).build());
         } catch (Exception e) {
             MinioExceptionHandler.handleException(e);
         }
@@ -69,7 +70,9 @@ public class MinioStorageServiceImpl implements IFileStorageService {
             // 确认桶是否存在
             bucketName = ensureBucket(bucketName);
             // 下载文件
-            return minioClient.presignedGetObject(bucketName, fileName, FileCommonConst.URL_EXPIRES);
+//            return minioClient.presignedGetObject(bucketName, fileName, FileCommonConst.URL_EXPIRES);
+            return minioClient.getPresignedObjectUrl(GetPresignedObjectUrlArgs.builder()
+                    .bucket(bucketName).object(fileName).expiry(FileCommonConst.URL_EXPIRES).build());
         } catch (Exception e) {
             MinioExceptionHandler.handleException(e);
         }
@@ -86,7 +89,9 @@ public class MinioStorageServiceImpl implements IFileStorageService {
             // 确认桶是否存在
             bucketName = ensureBucket(bucketName);
             // 查看文件元数据
-            ObjectStat stat = minioClient.statObject(bucketName, fileName);
+//            ObjectStat stat = minioClient.statObject(bucketName, fileName);
+//            return stat != null;
+            StatObjectResponse stat = minioClient.statObject(StatObjectArgs.builder().bucket(bucketName).object(fileName).build());
             return stat != null;
         } catch (Exception e) {
             MinioExceptionHandler.handleException(e);
@@ -104,7 +109,8 @@ public class MinioStorageServiceImpl implements IFileStorageService {
             // 确认桶是否存在
             bucketName = ensureBucket(bucketName);
             // 删除文件
-            minioClient.removeObject(bucketName, fileName);
+//            minioClient.removeObject(bucketName, fileName);
+            minioClient.removeObject(RemoveObjectArgs.builder().bucket(bucketName).object(fileName).build());
         } catch (Exception e) {
             MinioExceptionHandler.handleException(e);
         }
@@ -120,7 +126,8 @@ public class MinioStorageServiceImpl implements IFileStorageService {
             // 确认桶是否存在
             bucketName = ensureBucket(bucketName);
             // 删除桶
-            minioClient.removeBucket(bucketName);
+//            minioClient.removeBucket(bucketName);
+            minioClient.removeBucket(RemoveBucketArgs.builder().bucket(bucketName).build());
         } catch (Exception e) {
             MinioExceptionHandler.handleException(e);
         }
@@ -138,12 +145,14 @@ public class MinioStorageServiceImpl implements IFileStorageService {
             bucketName = FileCommonConst.DEFAULT_BUCKET;
         }
         log.info("开始检查桶名:[{0}]是否存在", bucketName);
-        boolean isExist = minioClient.bucketExists(bucketName);
+//        boolean isExist = minioClient.bucketExists(bucketName);
+        boolean isExist = minioClient.bucketExists(BucketExistsArgs.builder().bucket(bucketName).build());
         if(isExist) {
             log.info("桶名:[{0}]已存在", bucketName);
             return bucketName;
         }
-        minioClient.makeBucket(bucketName);
+//        minioClient.makeBucket(bucketName);
+        minioClient.makeBucket(MakeBucketArgs.builder().bucket(bucketName).build());
         log.info("桶名:[{0}]不存在,创建成功", bucketName);
         return bucketName;
     }

+ 21 - 1
dmp-parent/pom.xml

@@ -39,7 +39,7 @@
         <tomcat-jdbc.version>9.0.31</tomcat-jdbc.version>
         <HikariCP.version>3.2.0</HikariCP.version>
         <mysql.version>8.0.15</mysql.version>
-        <guava.version>27.0.1-jre</guava.version>
+        <guava.version>30.0-jre</guava.version>
         <spring.version>5.1.15.RELEASE</spring.version>
         <spring-cloud-dependencies.version>Greenwich.SR6</spring-cloud-dependencies.version>
         <spring-data.version>2.1.17.RELEASE</spring-data.version>
@@ -50,6 +50,10 @@
         <fastjson.version>1.2.47</fastjson.version>
         <druid.version>1.1.22</druid.version>
         <hutool.version>5.5.8</hutool.version>
+        <!-- Minio -->
+        <minio.version>8.3.0</minio.version>
+        <okhttp.version>4.8.1</okhttp.version>
+        <kotlin.version>1.3.70</kotlin.version>
         <!-- Plugins -->
         <maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
         <spring-boot-maven-plugin.version>2.4.3</spring-boot-maven-plugin.version>
@@ -308,6 +312,22 @@
                 <artifactId>fastjson</artifactId>
                 <version>${fastjson.version}</version>
             </dependency>
+            <!-- Minio -->
+            <dependency>
+                <groupId>io.minio</groupId>
+                <artifactId>minio</artifactId>
+                <version>${minio.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>com.squareup.okhttp3</groupId>
+                <artifactId>okhttp</artifactId>
+                <version>${okhttp.version}</version>
+            </dependency>
+            <dependency>
+                <groupId>org.jetbrains.kotlin</groupId>
+                <artifactId>kotlin-stdlib-common</artifactId>
+                <version>${kotlin.version}</version>
+            </dependency>
         </dependencies>
     </dependencyManagement>