提交 248dd73b authored 作者: 李纤's avatar 李纤

修改minio连接

上级 d161fb17
......@@ -19,6 +19,7 @@ package org.apache.seatunnel.datasource.plugin.s3;
import com.amazonaws.services.dynamodbv2.xspec.S;
import io.minio.ListBucketsArgs;
import org.apache.commons.lang3.StringUtils;
import org.apache.seatunnel.api.configuration.util.OptionRule;
import org.apache.seatunnel.common.utils.SeaTunnelException;
import org.apache.seatunnel.datasource.plugin.api.DataSourceChannel;
......@@ -85,16 +86,18 @@ public class S3DatasourceChannel implements DataSourceChannel {
return tab;
// throw new MinioException("桶不存在");
}
Iterable<Result<Item>> results =
minioClient.listObjects(ListObjectsArgs.builder().bucket(database).build());
Iterable<Result<Item>> results = getFileByDir(minioClient, database, null);
results.forEach(
x -> {
try {
boolean dir = x.get().isDir();
if (!dir) {
String s = x.get().objectName();
if (!dir) {
tab.add(s);
}
// else{
// getAllFile(tab, getFileByDir(minioClient, database,s), minioClient, database);
// }
} catch (ErrorResponseException
| InsufficientDataException
| InternalException
......@@ -117,7 +120,42 @@ public class S3DatasourceChannel implements DataSourceChannel {
// datasource");
}
private void getAllFile(List<String> tab, Iterable<Result<Item>> results, MinioClient minioClient, String database) {
results.forEach(
x -> {
try {
boolean dir = x.get().isDir();
String s = x.get().objectName();
if (!dir) {
tab.add(s);
}else{
this.getAllFile(tab, getFileByDir(minioClient, database, s), minioClient, database);
}
} catch (ErrorResponseException
| InsufficientDataException
| InternalException
| InvalidKeyException
| InvalidResponseException
| IOException
| NoSuchAlgorithmException
| ServerException
| XmlParserException e) {
throw new RuntimeException(e);
}});
}
private Iterable<Result<Item>> getFileByDir(@NonNull MinioClient minioClient,@NonNull String bucket, String dir) {
Iterable<Result<Item>> results;
if (StringUtils.isNotEmpty(dir)) {
results = minioClient.listObjects(ListObjectsArgs.builder().bucket(bucket).build());
}
else{
results =
minioClient.listObjects(ListObjectsArgs.builder().bucket(bucket).prefix(dir).build());
}
return results;
}
@Override
public List<String> getDatabases(
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论