diff --git a/plugin.xml b/plugin.xml index 3217a81..9d0ca49 100644 --- a/plugin.xml +++ b/plugin.xml @@ -5,12 +5,13 @@ com.fanruan.fs yes no - 1.0 + 1.1.1 10.0 2020-01-27 richie [2020-06-12]初始化插件。
]]>
diff --git a/readme.md b/readme.md index 914aad6..6427b8b 100644 --- a/readme.md +++ b/readme.md @@ -1,3 +1,5 @@ # 文件服务器(S3协议) -能够使用支持S3协议的云存储,作为文件服务器 \ No newline at end of file +能够使用支持S3协议的云存储,作为文件服务器,安装好插件后在决策平台的智能运维->集群配置->文件一致性设置选项下,按下图设置即可: + +![ui](screenshots/s3.png) \ No newline at end of file diff --git a/screenshots/s3.png b/screenshots/s3.png new file mode 100644 index 0000000..ff4c381 Binary files /dev/null and b/screenshots/s3.png differ diff --git a/src/main/java/com/fanruan/fs/s3/repository/core/S3Config.java b/src/main/java/com/fanruan/fs/s3/repository/core/S3Config.java index fba835f..2512321 100644 --- a/src/main/java/com/fanruan/fs/s3/repository/core/S3Config.java +++ b/src/main/java/com/fanruan/fs/s3/repository/core/S3Config.java @@ -4,6 +4,8 @@ import com.fr.config.Identifier; import com.fr.config.holder.Conf; import com.fr.config.holder.factory.Holders; import com.fr.io.config.CommonRepoConfig; +import com.fr.io.context.info.GetConfig; +import com.fr.io.context.info.SetConfig; import com.fr.stable.StringUtils; /** @@ -32,42 +34,52 @@ public class S3Config extends CommonRepoConfig { @Identifier("bucket") private Conf bucket = Holders.simple(StringUtils.EMPTY); + @GetConfig("endPoint") public String getEndPoint() { return endPoint.get(); } + @SetConfig("endPoint") public void setEndPoint(String endPoint) { this.endPoint.set(endPoint); } + @GetConfig("region") public String getRegion() { return region.get(); } + @SetConfig("region") public void setRegion(String region) { this.region.set(region); } + @GetConfig("accessKeyId") public String getAccessKeyId() { return accessKeyId.get(); } + @SetConfig("accessKeyId") public void setAccessKeyId(String accessKeyId) { this.accessKeyId.set(accessKeyId); } + @GetConfig("accessKeySecret") public String getAccessKeySecret() { return accessKeySecret.get(); } + @SetConfig("accessKeySecret") public void setAccessKeySecret(String accessKeySecret) { this.accessKeySecret.set(accessKeySecret); } + @GetConfig("bucket") public String getBucket() { return bucket.get(); } + @SetConfig("bucket") public void setBucket(String bucket) { this.bucket.set(bucket); } diff --git a/src/main/java/com/fanruan/fs/s3/repository/core/S3ResourceRepository.java b/src/main/java/com/fanruan/fs/s3/repository/core/S3ResourceRepository.java index deb88ab..33540b3 100644 --- a/src/main/java/com/fanruan/fs/s3/repository/core/S3ResourceRepository.java +++ b/src/main/java/com/fanruan/fs/s3/repository/core/S3ResourceRepository.java @@ -13,7 +13,6 @@ import com.amazonaws.services.s3.model.PutObjectRequest; import com.amazonaws.services.s3.model.S3Object; import com.amazonaws.services.s3.model.S3ObjectSummary; import com.fanruan.api.log.LogKit; -import com.fanruan.api.util.StringKit; import com.fr.io.repository.FineFileEntry; import com.fr.io.repository.base.BaseResourceRepository; import com.fr.stable.Filter; @@ -32,15 +31,18 @@ import java.util.List; */ public class S3ResourceRepository extends BaseResourceRepository { + private static final String DELIMITER = "/"; + private final AmazonS3 s3; private final String bucket; + public S3ResourceRepository(String repoName, String workRoot, S3Config config) { super(repoName, workRoot); BasicAWSCredentials credentials = new BasicAWSCredentials(config.getAccessKeyId(), config.getAccessKeySecret()); this.s3 = AmazonS3ClientBuilder.standard() .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(config.getEndPoint(), config.getRegion())) - .withCredentials(new AWSStaticCredentialsProvider(credentials)).build(); + .withCredentials(new AWSStaticCredentialsProvider(credentials)).build(); this.bucket = config.getBucket(); } @@ -59,13 +61,22 @@ public class S3ResourceRepository extends BaseResourceRepository { @Override public FineFileEntry[] listEntry(String dir) { List result = new ArrayList<>(); + if (!dir.endsWith(DELIMITER)) { + dir += DELIMITER; + } ListObjectsRequest listObjectsRequest = new ListObjectsRequest().withBucketName(bucket) - .withPrefix(dir).withDelimiter("/"); + .withPrefix(dir).withDelimiter(DELIMITER); ObjectListing objectListing = s3.listObjects(listObjectsRequest); for (S3ObjectSummary summary : objectListing.getObjectSummaries()) { String key = summary.getKey(); result.add(s3Object2FileEntry(summary, key)); } + for (String prefix : objectListing.getCommonPrefixes()) { + FineFileEntry entry = new FineFileEntry(prefix); + entry.setDirectory(true); + result.add(entry); + } + return result.toArray(new FineFileEntry[0]); } @@ -98,13 +109,18 @@ public class S3ResourceRepository extends BaseResourceRepository { @Override public void write(String path, byte[] data) { - ObjectMetadata metadata = s3.getObject(bucket, path).getObjectMetadata(); + ObjectMetadata metadata; + try { + metadata = s3.getObjectMetadata(bucket, path); + } catch (Exception e) { + metadata = new ObjectMetadata(); + } s3.putObject(bucket, path, new ByteArrayInputStream(data), metadata); } @Override public boolean createFile(String path) { - PutObjectRequest request = new PutObjectRequest(bucket, path, StringKit.EMPTY); + PutObjectRequest request = new PutObjectRequest(bucket, path, new ByteArrayInputStream(new byte[0]), new ObjectMetadata()); try { s3.putObject(request); } catch (Exception e) { @@ -115,7 +131,7 @@ public class S3ResourceRepository extends BaseResourceRepository { @Override public boolean createDirectory(String path) { - PutObjectRequest request = new PutObjectRequest(bucket, path + "/", StringKit.EMPTY); + PutObjectRequest request = new PutObjectRequest(bucket, path + "/", new ByteArrayInputStream(new byte[0]), new ObjectMetadata()); try { s3.putObject(request); } catch (Exception e) { @@ -138,7 +154,7 @@ public class S3ResourceRepository extends BaseResourceRepository { @Override public boolean exist(String path) { try { - return s3.getObject(bucket, path) != null; + return s3.doesObjectExist(bucket, path); } catch (Exception e) { return false; } @@ -147,14 +163,22 @@ public class S3ResourceRepository extends BaseResourceRepository { @Override public String[] list(String dir, final Filter filter) { List result = new ArrayList<>(); + if (!dir.endsWith(DELIMITER)) { + dir += DELIMITER; + } ListObjectsRequest listObjectsRequest = new ListObjectsRequest().withBucketName(bucket) - .withPrefix(dir).withDelimiter("/"); + .withPrefix(dir).withDelimiter(DELIMITER); ObjectListing objectListing = s3.listObjects(listObjectsRequest); for (S3ObjectSummary objectSummary : objectListing.getObjectSummaries()) { if (filter.accept(objectSummary.getKey())) { result.add(objectSummary.getKey()); } } + for (String prefix : objectListing.getCommonPrefixes()) { + if (filter.accept(prefix)) { + result.add(prefix); + } + } return result.toArray(new String[0]); } diff --git a/src/main/resources/com/fanruan/fs/s3/repository/web/js/bundle.js b/src/main/resources/com/fanruan/fs/s3/repository/web/js/bundle.js index c5a1513..a05c533 100644 --- a/src/main/resources/com/fanruan/fs/s3/repository/web/js/bundle.js +++ b/src/main/resources/com/fanruan/fs/s3/repository/web/js/bundle.js @@ -70,7 +70,7 @@ BI.config("dec.constant.intelligence.cluster.file.server", function (items) { editorWidth: EDITOR_WIDTH, watermark: BI.i18nText("Plugin-S3_Input"), text: BI.i18nText("Plugin-S3_Access_Key_Id"), - value: this.model.port, + value: this.model.accessKeyId, ref: function (_ref) { self.portRow = _ref; }, @@ -87,7 +87,7 @@ BI.config("dec.constant.intelligence.cluster.file.server", function (items) { editorWidth: EDITOR_WIDTH, watermark: BI.i18nText("Plugin-S3_Access_Key_Secret"), text: BI.i18nText("Plugin-S3_Access_Key_Secret"), - value: this.model.accessKeySecret, + value: "******", listeners: [{ eventName: BI.Editor.EVENT_CHANGE, action: function () {