Browse Source

S3文件服务器

pull/1/head
richie 5 years ago
commit
967c867745
  1. 10
      .gitignore
  2. 122
      build.gradle
  3. 10
      encrypt.xml
  4. BIN
      lib/aws-java-sdk-core-1.11.801.jar
  5. BIN
      lib/aws-java-sdk-kms-1.11.801.jar
  6. BIN
      lib/aws-java-sdk-s3-1.11.801.jar
  7. BIN
      lib/commons-codec-1.11.jar
  8. BIN
      lib/commons-logging-1.2.jar
  9. BIN
      lib/finekit-10.0.jar
  10. BIN
      lib/httpclient-4.5.9.jar
  11. BIN
      lib/httpcore-4.4.11.jar
  12. BIN
      lib/ion-java-1.0.2.jar
  13. BIN
      lib/jackson-annotations-2.6.0.jar
  14. BIN
      lib/jackson-core-2.6.7.jar
  15. BIN
      lib/jackson-databind-2.6.7.3.jar
  16. BIN
      lib/jackson-dataformat-cbor-2.6.7.jar
  17. BIN
      lib/jmespath-java-1.11.801.jar
  18. BIN
      lib/joda-time-2.8.1.jar
  19. 27
      plugin.xml
  20. 3
      readme.md
  21. 25
      src/main/java/com/fanruan/fs/s3/repository/S3FactoryProvider.java
  22. 25
      src/main/java/com/fanruan/fs/s3/repository/S3FileServerResource.java
  23. 15
      src/main/java/com/fanruan/fs/s3/repository/S3LocaleFinder.java
  24. 73
      src/main/java/com/fanruan/fs/s3/repository/core/S3Config.java
  25. 39
      src/main/java/com/fanruan/fs/s3/repository/core/S3RepositoryFactory.java
  26. 39
      src/main/java/com/fanruan/fs/s3/repository/core/S3RepositoryProfile.java
  27. 115
      src/main/java/com/fanruan/fs/s3/repository/core/S3ResourceRepository.java
  28. 25
      src/main/java/com/fanruan/fs/s3/repository/web/S3FileServerComponent.java
  29. 5
      src/main/resources/com/fanruan/fs/s3/repository/locale/s3.properties
  30. 5
      src/main/resources/com/fanruan/fs/s3/repository/locale/s3_en_US.properties
  31. 5
      src/main/resources/com/fanruan/fs/s3/repository/locale/s3_zh_CN.properties
  32. 154
      src/main/resources/com/fanruan/fs/s3/repository/web/js/bundle.js

10
.gitignore vendored

@ -0,0 +1,10 @@
*.iml
.idea/
lib/report/*.jar
target/
.DS_Store
.gradle
build
local.properties
classes/
transform-classes/

122
build.gradle

@ -0,0 +1,122 @@
apply plugin: 'java'
ext {
/**
* jar的路径
* 1.jar需要打包到zip中,lib根目录下
* 2.jar仅仅是编译时需要lib下子目录下即可
*/
libPath = "$projectDir/../webroot/WEB-INF/lib"
/**
* class进行加密保护
*/
guard = false
def pluginInfo = getPluginInfo()
pluginPre = "fine-plugin"
pluginName = pluginInfo.id
pluginVersion = pluginInfo.version
outputPath = "$projectDir/../webroot/WEB-INF/plugins/plugin-" + pluginName + "-1.0/classes"
}
group = 'com.fr.plugin'
version = '10.0'
sourceCompatibility = '8'
sourceSets {
main {
java.outputDir = file(outputPath)
output.resourcesDir = file(outputPath)
}
}
ant.importBuild("encrypt.xml")
//ant变量
ant.projectDir = projectDir
ant.references["compile.classpath"] = ant.path {
fileset(dir: libPath, includes: '**/*.jar')
fileset(dir: ".",includes:"**/*.jar" )
}
classes.dependsOn('clean')
task copyFiles(type: Copy,dependsOn: 'classes'){
from outputPath
into "$projectDir/classes"
}
task preJar(type:Copy,dependsOn: guard ? 'compile_encrypt_javas' : 'compile_plain_javas'){
from "$projectDir/classes"
into "$projectDir/transform-classes"
include "**/*.*"
}
jar.dependsOn("preJar")
task makeJar(type: Jar,dependsOn: preJar){
from fileTree(dir: "$projectDir/transform-classes")
baseName pluginPre
appendix pluginName
version pluginVersion
destinationDir = file("$buildDir/libs")
doLast(){
delete file("$projectDir/classes")
delete file("$projectDir/transform-classes")
}
}
task copyFile(type: Copy,dependsOn: ["makeJar"]){
from "$buildDir/libs"
from("$projectDir/lib") {
include "*.jar"
}
from "$projectDir/plugin.xml"
into file("$buildDir/temp/plugin")
}
task zip(type:Zip,dependsOn:["copyFile"]){
from "$buildDir/temp/plugin"
destinationDir file("$buildDir/install")
baseName pluginPre
appendix pluginName
version pluginVersion
}
//build时包含哪些文件,
processResources {
// exclude everything
// *.css没效果
// exclude '**/*.css'
// except this file
// include 'xx.xml'
}
/*读取plugin.xml中的version*/
def getPluginInfo(){
def xmlFile = file("plugin.xml")
if (!xmlFile.exists()) {
return ["id":"none", "version":"1.0.0"]
}
def plugin = new XmlParser().parse(xmlFile)
def version = plugin.version[0].text()
def id = plugin.id[0].text()
return ["id":id,"version":version]
}
repositories {
mavenLocal()
maven {
url = uri('http://mvn.finedevelop.com/repository/maven-public/')
}
}
dependencies {
//使jar
implementation fileTree(dir: 'lib', include: ['**/*.jar'])
implementation fileTree(dir: libPath, include: ['**/*.jar'])
}

10
encrypt.xml

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project>
<target name="compile_javas" depends="copyFiles">
<echo message="编译${compile_files}下的Java文件"/>
<taskdef name="pretreatment" classname="com.fr.plugin.pack.PluginPretreatmentTask">
<classpath refid="compile.classpath"/>
</taskdef>
<pretreatment baseDir="${projectDir}"/>
</target>
</project>

BIN
lib/aws-java-sdk-core-1.11.801.jar

Binary file not shown.

BIN
lib/aws-java-sdk-kms-1.11.801.jar

Binary file not shown.

BIN
lib/aws-java-sdk-s3-1.11.801.jar

Binary file not shown.

BIN
lib/commons-codec-1.11.jar

Binary file not shown.

BIN
lib/commons-logging-1.2.jar

Binary file not shown.

BIN
lib/finekit-10.0.jar

Binary file not shown.

BIN
lib/httpclient-4.5.9.jar

Binary file not shown.

BIN
lib/httpcore-4.4.11.jar

Binary file not shown.

BIN
lib/ion-java-1.0.2.jar

Binary file not shown.

BIN
lib/jackson-annotations-2.6.0.jar

Binary file not shown.

BIN
lib/jackson-core-2.6.7.jar

Binary file not shown.

BIN
lib/jackson-databind-2.6.7.3.jar

Binary file not shown.

BIN
lib/jackson-dataformat-cbor-2.6.7.jar

Binary file not shown.

BIN
lib/jmespath-java-1.11.801.jar

Binary file not shown.

BIN
lib/joda-time-2.8.1.jar

Binary file not shown.

27
plugin.xml

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<plugin>
<id>com.fanruan.fs.s3.repository</id>
<name><![CDATA[S3资源仓库]]></name>
<main-package>com.fanruan.fs</main-package>
<active>yes</active>
<hidden>no</hidden>
<version>1.0</version>
<env-version>10.0</env-version>
<jartime>2020-01-27</jartime>
<vendor>richie</vendor>
<description><![CDATA[使用支持S3协议的云存储文件系统作为文件服务器。]]></description>
<change-notes><![CDATA[
[2020-06-12]初始化插件。<br/>
]]></change-notes>
<extra-core>
<LocaleFinder class="com.fanruan.fs.s3.repository.S3LocaleFinder"/>
</extra-core>
<extra-decision>
<WebResourceProvider class="com.fanruan.fs.s3.repository.S3FileServerResource"/>
</extra-decision>
<extra-core>
<ResourceRepositoryFactoryProvider class="com.fanruan.fs.s3.repository.S3FactoryProvider"/>
</extra-core>
<!--功能记录点类-->
<function-recorder class="com.fanruan.fs.s3.repository.S3FactoryProvider"/>
</plugin>

3
readme.md

@ -0,0 +1,3 @@
# 文件服务器(S3协议)
能够使用支持S3协议的云存储,作为文件服务器

25
src/main/java/com/fanruan/fs/s3/repository/S3FactoryProvider.java

@ -0,0 +1,25 @@
package com.fanruan.fs.s3.repository;
import com.fr.intelli.record.Focus;
import com.fr.io.base.provider.RepositoryFactoryProvider;
import com.fr.io.fun.AbstractRepositoryFactoryProvider;
import com.fanruan.fs.s3.repository.core.S3Config;
import com.fanruan.fs.s3.repository.core.S3RepositoryFactory;
import com.fr.record.analyzer.EnableMetrics;
/**
* @author richie
* @version 10.0
* Created by richie on 2020/6/15
*/
@EnableMetrics
public class S3FactoryProvider extends AbstractRepositoryFactoryProvider<S3Config> {
private static final S3RepositoryFactory factory = new S3RepositoryFactory();
@Override
@Focus(id="com.fanruan.fs.s3.repository", text="")
public RepositoryFactoryProvider<S3Config> getFactory() {
return factory;
}
}

25
src/main/java/com/fanruan/fs/s3/repository/S3FileServerResource.java

@ -0,0 +1,25 @@
package com.fanruan.fs.s3.repository;
import com.fr.decision.fun.impl.AbstractWebResourceProvider;
import com.fr.decision.web.MainComponent;
import com.fanruan.fs.s3.repository.web.S3FileServerComponent;
import com.fr.web.struct.Atom;
/**
* @author richie
* @version 10.0
* Created by richie on 2020/6/15
*/
public class S3FileServerResource extends AbstractWebResourceProvider {
@Override
public Atom attach() {
return MainComponent.KEY;
}
@Override
public Atom client() {
return S3FileServerComponent.KEY;
}
}

15
src/main/java/com/fanruan/fs/s3/repository/S3LocaleFinder.java

@ -0,0 +1,15 @@
package com.fanruan.fs.s3.repository;
import com.fr.stable.fun.impl.AbstractLocaleFinder;
/**
* @author richie
* @version 10.0
* Created by richie on 2020/6/15
*/
public class S3LocaleFinder extends AbstractLocaleFinder {
@Override
public String find() {
return "com/fanruan/fs/s3/repository/locale/s3";
}
}

73
src/main/java/com/fanruan/fs/s3/repository/core/S3Config.java

@ -0,0 +1,73 @@
package com.fanruan.fs.s3.repository.core;
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.stable.StringUtils;
/**
* @author richie
* @version 10.0
* Created by richie on 2020/6/15
*/
public class S3Config extends CommonRepoConfig {
public S3Config() {
super(S3RepositoryFactory.IDENTITY);
}
@Identifier("endPoint")
private Conf<String> endPoint = Holders.simple(StringUtils.EMPTY);
@Identifier("accessKeyId")
private Conf<String> accessKeyId = Holders.simple(StringUtils.EMPTY);
@Identifier("accessKeySecret")
private Conf<String> accessKeySecret = Holders.simple(StringUtils.EMPTY);
@Identifier("bucket")
private Conf<String> bucket = Holders.simple(StringUtils.EMPTY);
public String getEndPoint() {
return endPoint.get();
}
public void setEndPoint(String endPoint) {
this.endPoint.set(endPoint);
}
public String getAccessKeyId() {
return accessKeyId.get();
}
public void setAccessKeyId(String accessKeyId) {
this.accessKeyId.set(accessKeyId);
}
public String getAccessKeySecret() {
return accessKeySecret.get();
}
public void setAccessKeySecret(String accessKeySecret) {
this.accessKeySecret.set(accessKeySecret);
}
public String getBucket() {
return bucket.get();
}
public void setBucket(String bucket) {
this.bucket.set(bucket);
}
@Override
public S3Config clone() throws CloneNotSupportedException {
S3Config cloned = (S3Config) super.clone();
cloned.endPoint = (Conf<String>) endPoint.clone();
cloned.accessKeyId = (Conf<String>) accessKeyId.clone();
cloned.accessKeySecret = (Conf<String>) accessKeySecret.clone();
cloned.bucket = (Conf<String>) bucket.clone();
return cloned;
}
}

39
src/main/java/com/fanruan/fs/s3/repository/core/S3RepositoryFactory.java

@ -0,0 +1,39 @@
package com.fanruan.fs.s3.repository.core;
import com.fr.io.base.provider.impl.ConfigRepositoryFactory;
import com.fr.io.context.info.RepositoryProfile;
import com.fr.io.repository.ResourceRepository;
/**
* @author richie
* @version 10.0
* Created by richie on 2020/6/15
*/
public class S3RepositoryFactory extends ConfigRepositoryFactory<S3Config> {
static final String IDENTITY = "S3";
public S3RepositoryFactory() {
super(IDENTITY);
}
@Override
public Class<? extends RepositoryProfile<S3Config>> getProfileClass() {
return S3RepositoryProfile.class;
}
@Override
public Class<S3Config> getConfigClass() {
return S3Config.class;
}
@Override
public boolean verifyConfig(S3Config s3Config) {
return false;
}
@Override
public ResourceRepository produce(String repoName, String workRoot, S3Config config) {
return new S3ResourceRepository(repoName, workRoot, null, null);
}
}

39
src/main/java/com/fanruan/fs/s3/repository/core/S3RepositoryProfile.java

@ -0,0 +1,39 @@
package com.fanruan.fs.s3.repository.core;
import com.fr.config.Identifier;
import com.fr.config.holder.Conf;
import com.fr.config.holder.factory.Holders;
import com.fr.io.context.info.RepositoryProfile;
/**
* @author richie
* @version 10.0
* Created by richie on 2020/6/15
*/
public class S3RepositoryProfile extends RepositoryProfile<S3Config> {
public S3RepositoryProfile() {
}
@Identifier("s3Config")
private Conf<S3Config> s3Config = Holders.obj(null, S3Config.class);
@Override
public S3Config getConfig() {
return s3Config.get();
}
@Override
public void setConfig(S3Config s3Config) {
this.s3Config.set(s3Config);
}
@Override
public RepositoryProfile<S3Config> clone() throws CloneNotSupportedException {
S3RepositoryProfile cloned = (S3RepositoryProfile) super.clone();
cloned.s3Config = (Conf<S3Config>) s3Config.clone();
return cloned;
}
}

115
src/main/java/com/fanruan/fs/s3/repository/core/S3ResourceRepository.java

@ -0,0 +1,115 @@
package com.fanruan.fs.s3.repository.core;
import com.amazonaws.services.s3.AmazonS3;
import com.fanruan.api.log.LogKit;
import com.fr.io.repository.FineFileEntry;
import com.fr.io.repository.base.BaseResourceRepository;
import com.fr.stable.Filter;
import com.fr.workspace.resource.ResourceIOException;
import java.io.InputStream;
import java.net.URL;
/**
* @author richie
* @version 10.0
* Created by richie on 2020/6/15
*/
public class S3ResourceRepository extends BaseResourceRepository {
private AmazonS3 s3;
private String bucket;
public S3ResourceRepository(String repoName, String workRoot, AmazonS3 s3, String bucket) {
super(repoName, workRoot);
this.s3 = s3;
this.bucket = bucket;
}
@Override
public String getSeparator() {
return "/";
}
@Override
public FineFileEntry getEntry(String path) {
return null;
}
@Override
public FineFileEntry[] listEntry(String dir) {
return new FineFileEntry[0];
}
@Override
public URL getResource(String path) {
return null;
}
@Override
public InputStream read(String filePath) throws ResourceIOException {
return null;
}
@Override
public void write(String path, byte[] data) {
}
@Override
public boolean createFile(String path) {
return false;
}
@Override
public boolean createDirectory(String path) {
return false;
}
@Override
public boolean delete(String path) {
try {
s3.deleteObject(bucket, path);
} catch (Exception e) {
LogKit.error(e.getMessage(), e);
return false;
}
return true;
}
@Override
public boolean exist(String path) {
return s3.getObject(bucket, path) != null;
}
@Override
public String[] list(String dir, final Filter<String> filter) {
return new String[0];
}
@Override
public boolean isDirectory(String path) {
return false;
}
@Override
public long lastModified(String path) {
return s3.getObject(bucket, path).getObjectMetadata().getLastModified().getTime();
}
@Override
public long length(String path) {
return s3.getObject(bucket, path).getObjectMetadata().getContentLength();
}
@Override
public void shutDown() {
s3.shutdown();
}
@Override
public String getIdentity() {
return S3RepositoryFactory.IDENTITY;
}
}

25
src/main/java/com/fanruan/fs/s3/repository/web/S3FileServerComponent.java

@ -0,0 +1,25 @@
package com.fanruan.fs.s3.repository.web;
import com.fr.web.struct.Component;
import com.fr.web.struct.browser.RequestClient;
import com.fr.web.struct.category.ScriptPath;
/**
* @author richie
* @version 10.0
* Created by richie on 2020/6/15
*/
public class S3FileServerComponent extends Component {
public static S3FileServerComponent KEY = new S3FileServerComponent();
private S3FileServerComponent() {
}
@Override
public ScriptPath script(RequestClient req) {
return ScriptPath.build("com/fanruan/fs/s3/repository/web/js/bundle.js");
}
}

5
src/main/resources/com/fanruan/fs/s3/repository/locale/s3.properties

@ -0,0 +1,5 @@
Plugin-S3_Input=Please Input
Plugin-S3_End_Point=Endpoint
Plugin-S3_Access_Key_Id=AccessKeyId
Plugin-S3_Access_Key_Secret=AccessKeySecret
Plugin-S3_Bucket=Bucket

5
src/main/resources/com/fanruan/fs/s3/repository/locale/s3_en_US.properties

@ -0,0 +1,5 @@
Plugin-S3_Input=Please Input
Plugin-S3_End_Point=Endpoint
Plugin-S3_Access_Key_Id=AccessKeyId
Plugin-S3_Access_Key_Secret=AccessKeySecret
Plugin-S3_Bucket=Bucket

5
src/main/resources/com/fanruan/fs/s3/repository/locale/s3_zh_CN.properties

@ -0,0 +1,5 @@
Plugin-S3_Input=\u8BF7\u8F93\u5165
Plugin-S3_End_Point=Endpoint
Plugin-S3_Access_Key_Id=AccessKeyId
Plugin-S3_Access_Key_Secret=AccessKeySecret
Plugin-S3_Bucket=Bucket

154
src/main/resources/com/fanruan/fs/s3/repository/web/js/bundle.js

@ -0,0 +1,154 @@
BI.config("dec.constant.intelligence.cluster.file.server", function (items) {
items.push({
value: "S3", // 地址栏显示的hash值
id: "decision-intelligence-cluster-file-s3", // id
text: BI.i18nText(""), // 文字
cardType: "dec.intelligence.cluster.file.s3"
});
return items;
});
!(function () {
var LABEL_WIDTH = 116, EDITOR_WIDTH = 300;
var S3 = BI.inherit(BI.Widget, {
props: {
baseCls: "dec-cluster-ftp",
value: {}
},
_store: function () {
return BI.Models.getModel("dec.model.intelligence.cluster.file.s3", {
value: this.options.value
});
},
watch: {},
render: function () {
var self = this, o = this.options;
return {
type: "bi.vertical",
tgap: 15,
items: [
{
type: "dec.label.editor.item",
textWidth: LABEL_WIDTH,
editorWidth: EDITOR_WIDTH,
watermark: BI.i18nText("Plugin-S3_Input"),
text: BI.i18nText("Plugin-S3_End_Point"),
value: this.model.endPoint,
ref: function (_ref) {
self.endPointRow = _ref;
},
listeners: [{
eventName: BI.Editor.EVENT_CHANGE,
action: function () {
self.store.setEndPoint(this.getValue());
}
}]
}, {
type: "dec.label.editor.item",
textWidth: LABEL_WIDTH,
editorWidth: EDITOR_WIDTH,
watermark: BI.i18nText("Plugin-S3_Input"),
text: BI.i18nText("Plugin-S3_Access_Key_Id"),
value: this.model.port,
ref: function (_ref) {
self.portRow = _ref;
},
listeners: [{
eventName: BI.Editor.EVENT_CHANGE,
action: function () {
self.store.setAccessKeyId(this.getValue());
}
}]
},
{
type: "dec.label.editor.item",
textWidth: LABEL_WIDTH,
editorWidth: EDITOR_WIDTH,
watermark: BI.i18nText("Plugin-S3_Access_Key_Secret"),
text: BI.i18nText("Plugin-S3_Access_Key_Secret"),
value: this.model.accessKeySecret,
listeners: [{
eventName: BI.Editor.EVENT_CHANGE,
action: function () {
self.store.setAccessKeySecret(this.getValue());
}
}]
},
{
type: "dec.label.editor.item",
textWidth: LABEL_WIDTH,
editorWidth: EDITOR_WIDTH,
watermark: BI.i18nText("Plugin-S3_Bucket"),
text: BI.i18nText("Plugin-S3_Bucket"),
value: this.model.bucket,
listeners: [{
eventName: BI.Editor.EVENT_CHANGE,
action: function () {
self.store.setBucket(this.getValue());
}
}]
}]
};
},
getValue: function () {
return {
endPoint: this.model.endPoint,
accessKeyId: this.model.accessKeyId,
accessKeySecret: this.model.accessKeySecret,
bucket: this.model.bucket
};
},
});
BI.shortcut("dec.intelligence.cluster.file.s3", S3);
})();
!(function () {
var Model = BI.inherit(Fix.Model, {
state: function () {
var val = this.options.value;
return {
endPoint: val.endPoint,
accessKeyId: val.accessKeyId,
accessKeySecret: val.accessKeySecret,
bucket: val.bucket
};
},
computed: {
encodingArray: function () {
return BI.map(DecCst.EncodeConstants.ENCODING_ARRAY, function (i, v) {
return {
value: v
};
});
}
},
actions: {
setEndPoint: function (v) {
this.model.endPoint = v;
},
setAccessKeyId: function (v) {
this.model.accessKeyId = v;
},
setAccessKeySecret: function (v) {
this.model.accessKeySecret = v;
},
setBucket: function (v) {
this.model.bucket = v;
}
}
});
BI.model("dec.model.intelligence.cluster.file.s3", Model);
})();
Loading…
Cancel
Save