init
This commit is contained in:
parent
586d8048e7
commit
4a5ab6b0d9
@ -8,7 +8,7 @@ spring:
|
|||||||
master:
|
master:
|
||||||
url: jdbc:mysql://127.0.0.1/ry?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
|
url: jdbc:mysql://127.0.0.1/ry?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
|
||||||
username: root
|
username: root
|
||||||
password: 123456
|
password: WKY20031018
|
||||||
# 从库数据源
|
# 从库数据源
|
||||||
slave:
|
slave:
|
||||||
# 从数据源开关/默认关闭
|
# 从数据源开关/默认关闭
|
||||||
|
@ -31,5 +31,5 @@ minio:
|
|||||||
master:
|
master:
|
||||||
url: http://localhost:9000
|
url: http://localhost:9000
|
||||||
accessKey: root
|
accessKey: root
|
||||||
secretKey: 123456
|
secretKey: wky20031018
|
||||||
defaultBuket: ruoyi
|
defaultBuket: bim-model
|
||||||
|
@ -1,11 +1,17 @@
|
|||||||
package com.ruoyi.middleware.minio.config;
|
package com.ruoyi.middleware.minio.config;
|
||||||
|
|
||||||
|
import com.ruoyi.common.utils.StringUtils;
|
||||||
import io.minio.MinioClient;
|
import io.minio.MinioClient;
|
||||||
|
import io.minio.errors.*;
|
||||||
|
import io.minio.messages.Bucket;
|
||||||
import jakarta.annotation.PostConstruct;
|
import jakarta.annotation.PostConstruct;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.security.InvalidKeyException;
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
@ -30,27 +36,17 @@ public class MinioConfig {
|
|||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void init() {
|
public void init() {
|
||||||
List<MinioClientConfig.MinioClientEntity> collect = minioClientConfig.getSlave().stream().map(item -> {
|
List<MinioClientConfig.MinioClientEntity> collect = minioClientConfig.getSlave().stream().map(item -> {
|
||||||
try {
|
setClient(item);
|
||||||
item.setClient(MinioClient.builder().endpoint(item.getUrl())
|
isBuketExist(item);
|
||||||
.credentials(item.getAccessKey(), item.getSecretKey()).build());
|
|
||||||
} catch (Exception exception) {
|
|
||||||
item.setClient(MinioClient.builder().endpoint(item.getUrl()).build());
|
|
||||||
}
|
|
||||||
|
|
||||||
return item;
|
return item;
|
||||||
}).toList();
|
}).toList();
|
||||||
collect.forEach(item -> {
|
collect.forEach(item -> {
|
||||||
slaveClients.put(item.getName(), item);
|
slaveClients.put(item.getName(), item);
|
||||||
slaveClientsList.add(item);
|
slaveClientsList.add(item);
|
||||||
});
|
});
|
||||||
|
|
||||||
MinioClientConfig.MinioClientEntity master = minioClientConfig.getMaster();
|
MinioClientConfig.MinioClientEntity master = minioClientConfig.getMaster();
|
||||||
try {
|
setClient(master);
|
||||||
master.setClient(MinioClient.builder().endpoint(master.getUrl())
|
isBuketExist(master);
|
||||||
.credentials(master.getAccessKey(), master.getSecretKey()).build());
|
|
||||||
} catch (Exception exception) {
|
|
||||||
master.setClient(MinioClient.builder().endpoint(master.getUrl()).build());
|
|
||||||
}
|
|
||||||
masterClient = master;
|
masterClient = master;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,4 +70,43 @@ public class MinioConfig {
|
|||||||
return this.masterClient;
|
return this.masterClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void setClient(MinioClientConfig.MinioClientEntity entity){
|
||||||
|
try {
|
||||||
|
MinioClient build = MinioClient.builder().endpoint(entity.getUrl())
|
||||||
|
.credentials(entity.getAccessKey(), entity.getSecretKey()).build();
|
||||||
|
build.listBuckets();
|
||||||
|
entity.setClient(build);
|
||||||
|
} catch (Exception exception) {
|
||||||
|
MinioClient build = MinioClient.builder().endpoint(entity.getUrl()).build();
|
||||||
|
try {
|
||||||
|
build.listBuckets();
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
entity.setClient(build);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void isBuketExist(MinioClientConfig.MinioClientEntity entity) {
|
||||||
|
try {
|
||||||
|
String defaultBuket = entity.getDefaultBuket();
|
||||||
|
if(StringUtils.isEmpty(defaultBuket)){
|
||||||
|
throw new RuntimeException("defaultBuket without a default value ");
|
||||||
|
}
|
||||||
|
List<Bucket> buckets = entity.getClient().listBuckets();
|
||||||
|
if (buckets.isEmpty()) {
|
||||||
|
throw new RuntimeException("minioClient without any buket");
|
||||||
|
}
|
||||||
|
for (Bucket bucket : buckets) {
|
||||||
|
if (bucket.name().equals(entity.getDefaultBuket())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new RuntimeException("configured defaultBucket does not exist");
|
||||||
|
}catch (Exception e){
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user