diff --git a/o2server/configSample/externalStorageSources.json b/o2server/configSample/externalStorageSources.json index 0ba3824efc91b37df9baa89316153206ea8e1ec5..8f1afa4b31b207b1ff1cfbae652c5628815cca64 100755 --- a/o2server/configSample/externalStorageSources.json +++ b/o2server/configSample/externalStorageSources.json @@ -10,17 +10,7 @@ "enable": true, "weight": 100.0, "name": "251", - "deepPath": false, - "###protocol": "协议,可选值ftp、sftp、webdav、file、hdfs、ali", - "###username": "登录用户名.###", - "###password": "登录密码.###", - "###host": "主机地址.###", - "###port": "端口.###", - "###prefix": "前缀路径.###", - "###enable": "是否启用###", - "###weight": "设置权重.###", - "###name": "存储节点名,对应存储名称,谨慎修改.###", - "###deepPath": "是否使用更深的路径.###" + "deepPath": false } ], "processPlatform": [ @@ -34,17 +24,7 @@ "enable": true, "weight": 100.0, "name": "251", - "deepPath": false, - "###protocol": "协议,可选值ftp、sftp、webdav、file、hdfs、ali", - "###username": "登录用户名.###", - "###password": "登录密码.###", - "###host": "主机地址.###", - "###port": "端口.###", - "###prefix": "前缀路径.###", - "###enable": "是否启用###", - "###weight": "设置权重.###", - "###name": "存储节点名,对应存储名称,谨慎修改.###", - "###deepPath": "是否使用更深的路径.###" + "deepPath": false } ], "mind": [ @@ -58,17 +38,7 @@ "enable": true, "weight": 100.0, "name": "251", - "deepPath": false, - "###protocol": "协议,可选值ftp、sftp、webdav、file、hdfs、ali", - "###username": "登录用户名.###", - "###password": "登录密码.###", - "###host": "主机地址.###", - "###port": "端口.###", - "###prefix": "前缀路径.###", - "###enable": "是否启用###", - "###weight": "设置权重.###", - "###name": "存储节点名,对应存储名称,谨慎修改.###", - "###deepPath": "是否使用更深的路径.###" + "deepPath": false } ], "meeting": [ @@ -82,17 +52,7 @@ "enable": true, "weight": 100.0, "name": "251", - "deepPath": false, - "###protocol": "协议,可选值ftp、sftp、webdav、file、hdfs、ali", - "###username": "登录用户名.###", - "###password": "登录密码.###", - "###host": "主机地址.###", - "###port": "端口.###", - "###prefix": "前缀路径.###", - "###enable": "是否启用###", - "###weight": "设置权重.###", - "###name": "存储节点名,对应存储名称,谨慎修改.###", - "###deepPath": "是否使用更深的路径.###" + "deepPath": false } ], "calendar": [ @@ -106,17 +66,7 @@ "enable": true, "weight": 100.0, "name": "251", - "deepPath": false, - "###protocol": "协议,可选值ftp、sftp、webdav、file、hdfs、ali", - "###username": "登录用户名.###", - "###password": "登录密码.###", - "###host": "主机地址.###", - "###port": "端口.###", - "###prefix": "前缀路径.###", - "###enable": "是否启用###", - "###weight": "设置权重.###", - "###name": "存储节点名,对应存储名称,谨慎修改.###", - "###deepPath": "是否使用更深的路径.###" + "deepPath": false } ], "okr": [ @@ -130,17 +80,7 @@ "enable": true, "weight": 100.0, "name": "251", - "deepPath": false, - "###protocol": "协议,可选值ftp、sftp、webdav、file、hdfs、ali", - "###username": "登录用户名.###", - "###password": "登录密码.###", - "###host": "主机地址.###", - "###port": "端口.###", - "###prefix": "前缀路径.###", - "###enable": "是否启用###", - "###weight": "设置权重.###", - "###name": "存储节点名,对应存储名称,谨慎修改.###", - "###deepPath": "是否使用更深的路径.###" + "deepPath": false } ], "cms": [ @@ -154,17 +94,7 @@ "enable": true, "weight": 100.0, "name": "251", - "deepPath": false, - "###protocol": "协议,可选值ftp、sftp、webdav、file、hdfs、ali", - "###username": "登录用户名.###", - "###password": "登录密码.###", - "###host": "主机地址.###", - "###port": "端口.###", - "###prefix": "前缀路径.###", - "###enable": "是否启用###", - "###weight": "设置权重.###", - "###name": "存储节点名,对应存储名称,谨慎修改.###", - "###deepPath": "是否使用更深的路径.###" + "deepPath": false } ], "bbs": [ @@ -178,17 +108,7 @@ "enable": true, "weight": 100.0, "name": "251", - "deepPath": false, - "###protocol": "协议,可选值ftp、sftp、webdav、file、hdfs、ali", - "###username": "登录用户名.###", - "###password": "登录密码.###", - "###host": "主机地址.###", - "###port": "端口.###", - "###prefix": "前缀路径.###", - "###enable": "是否启用###", - "###weight": "设置权重.###", - "###name": "存储节点名,对应存储名称,谨慎修改.###", - "###deepPath": "是否使用更深的路径.###" + "deepPath": false } ], "report": [ @@ -202,17 +122,7 @@ "enable": true, "weight": 100.0, "name": "251", - "deepPath": false, - "###protocol": "协议,可选值ftp、sftp、webdav、file、hdfs、ali", - "###username": "登录用户名.###", - "###password": "登录密码.###", - "###host": "主机地址.###", - "###port": "端口.###", - "###prefix": "前缀路径.###", - "###enable": "是否启用###", - "###weight": "设置权重.###", - "###name": "存储节点名,对应存储名称,谨慎修改.###", - "###deepPath": "是否使用更深的路径.###" + "deepPath": false } ], "strategyDeploy": [ @@ -226,17 +136,7 @@ "enable": true, "weight": 100.0, "name": "251", - "deepPath": false, - "###protocol": "协议,可选值ftp、sftp、webdav、file、hdfs、ali", - "###username": "登录用户名.###", - "###password": "登录密码.###", - "###host": "主机地址.###", - "###port": "端口.###", - "###prefix": "前缀路径.###", - "###enable": "是否启用###", - "###weight": "设置权重.###", - "###name": "存储节点名,对应存储名称,谨慎修改.###", - "###deepPath": "是否使用更深的路径.###" + "deepPath": false } ], "teamwork": [ @@ -250,17 +150,7 @@ "enable": true, "weight": 100.0, "name": "251", - "deepPath": false, - "###protocol": "协议,可选值ftp、sftp、webdav、file、hdfs、ali", - "###username": "登录用户名.###", - "###password": "登录密码.###", - "###host": "主机地址.###", - "###port": "端口.###", - "###prefix": "前缀路径.###", - "###enable": "是否启用###", - "###weight": "设置权重.###", - "###name": "存储节点名,对应存储名称,谨慎修改.###", - "###deepPath": "是否使用更深的路径.###" + "deepPath": false } ], "structure": [ @@ -274,17 +164,21 @@ "enable": true, "weight": 100.0, "name": "251", - "deepPath": false, - "###protocol": "协议,可选值ftp、sftp、webdav、file、hdfs、ali", - "###username": "登录用户名.###", - "###password": "登录密码.###", - "###host": "主机地址.###", - "###port": "端口.###", - "###prefix": "前缀路径.###", - "###enable": "是否启用###", - "###weight": "设置权重.###", - "###name": "存储节点名,对应存储名称,谨慎修改.###", - "###deepPath": "是否使用更深的路径.###" + "deepPath": false + } + ], + "im": [ + { + "protocol": "webdav", + "username": "admin", + "password": "admin", + "host": "127.0.0.1", + "port": 8080.0, + "prefix": "", + "enable": true, + "weight": 100.0, + "name": "251", + "deepPath": false } ], "general": [ @@ -298,17 +192,23 @@ "enable": true, "weight": 100.0, "name": "251", - "deepPath": false, - "###protocol": "协议,可选值ftp、sftp、webdav、file、hdfs、ali", - "###username": "登录用户名.###", - "###password": "登录密码.###", - "###host": "主机地址.###", - "###port": "端口.###", - "###prefix": "前缀路径.###", - "###enable": "是否启用###", - "###weight": "设置权重.###", - "###name": "存储节点名,对应存储名称,谨慎修改.###", - "###deepPath": "是否使用更深的路径.###" + "deepPath": false } - ] + ], + "custom": [ + { + "protocol": "webdav", + "username": "admin", + "password": "admin", + "host": "127.0.0.1", + "port": 8080.0, + "prefix": "", + "enable": true, + "weight": 100.0, + "name": "251", + "deepPath": false + } + ], + "store": {}, + "###extension": "扩展设置.###" } \ No newline at end of file diff --git a/o2server/x_base_core_project/src/main/java/com/x/base/core/project/build/CreateConfigSample.java b/o2server/x_base_core_project/src/main/java/com/x/base/core/project/build/CreateConfigSample.java index a9fe5f023eedce01c3906e55df5be4308cc9dc62..ac44f39ef17bf281ff1aecba808696d1a5ceb6c7 100644 --- a/o2server/x_base_core_project/src/main/java/com/x/base/core/project/build/CreateConfigSample.java +++ b/o2server/x_base_core_project/src/main/java/com/x/base/core/project/build/CreateConfigSample.java @@ -27,6 +27,7 @@ import com.x.base.core.project.config.ConfigObject; import com.x.base.core.project.config.Dingding; import com.x.base.core.project.config.DumpRestoreData; import com.x.base.core.project.config.Exmail; +import com.x.base.core.project.config.ExternalStorageSources; import com.x.base.core.project.config.General; import com.x.base.core.project.config.HuaweiPushConfig; import com.x.base.core.project.config.JpushConfig; @@ -44,8 +45,6 @@ import com.x.base.core.project.config.WeLink; import com.x.base.core.project.config.WorkTime; import com.x.base.core.project.config.ZhengwuDingding; import com.x.base.core.project.gson.XGsonBuilder; -import com.x.base.core.project.logger.Logger; -import com.x.base.core.project.logger.LoggerFactory; import com.x.base.core.project.tools.DefaultCharset; /** @@ -69,6 +68,7 @@ public class CreateConfigSample { classes.add(Dingding.class); classes.add(DumpRestoreData.class); classes.add(Exmail.class); + classes.add(ExternalStorageSources.class); classes.add(HuaweiPushConfig.class); classes.add(JpushConfig.class); // classes.add(Meeting.class); diff --git a/o2server/x_base_core_project/src/main/java/com/x/base/core/project/config/ExternalStorageSource.java b/o2server/x_base_core_project/src/main/java/com/x/base/core/project/config/ExternalStorageSource.java index 32cdb16bd455eaf7ffe851c3b28a16253d340cf9..89069ce516e417a10730c8200ce5504c0c51ca32 100644 --- a/o2server/x_base_core_project/src/main/java/com/x/base/core/project/config/ExternalStorageSource.java +++ b/o2server/x_base_core_project/src/main/java/com/x/base/core/project/config/ExternalStorageSource.java @@ -9,6 +9,7 @@ import com.x.base.core.project.tools.Crypto; /** * 第三方附件存储配置 + * * @author sword */ public class ExternalStorageSource extends ConfigObject { @@ -46,6 +47,7 @@ public class ExternalStorageSource extends ConfigObject { public static final Boolean DEFAULT_ENABLE = true; public static final String DEFAULT_NAME = "251"; public static final Boolean DEFAULT_DEEPPATH = false; + public static final String DEFAULT_STORE = ""; @FieldDescribe("协议,可选值ftp、sftp、webdav、file、hdfs、ali") private StorageProtocol protocol; @@ -67,6 +69,12 @@ public class ExternalStorageSource extends ConfigObject { private String name; @FieldDescribe("是否使用更深的路径.") private Boolean deepPath; + @FieldDescribe("配置名称.") + private String store; + + public String getStore() { + return StringUtils.isBlank(this.store) ? DEFAULT_STORE : this.store; + } public StorageProtocol getProtocol() { return protocol; @@ -111,4 +119,42 @@ public class ExternalStorageSource extends ConfigObject { return BooleanUtils.isTrue(this.deepPath); } + public void setProtocol(StorageProtocol protocol) { + this.protocol = protocol; + } + + public void setUsername(String username) { + this.username = username; + } + + public void setPassword(String password) { + this.password = password; + } + + public void setHost(String host) { + this.host = host; + } + + public void setPort(Integer port) { + this.port = port; + } + + public void setPrefix(String prefix) { + this.prefix = prefix; + } + + public void setWeight(Integer weight) { + this.weight = weight; + } + + public void setName(String name) { + this.name = name; + } + + public void setStore(String store) { + this.store = store; + } + + + } diff --git a/o2server/x_base_core_project/src/main/java/com/x/base/core/project/config/ExternalStorageSources.java b/o2server/x_base_core_project/src/main/java/com/x/base/core/project/config/ExternalStorageSources.java index 78c411229385d9e0a755c75f3665e401d503a66f..45c5a25158b56a685732bcbbf27af15bca173414 100644 --- a/o2server/x_base_core_project/src/main/java/com/x/base/core/project/config/ExternalStorageSources.java +++ b/o2server/x_base_core_project/src/main/java/com/x/base/core/project/config/ExternalStorageSources.java @@ -1,23 +1,287 @@ package com.x.base.core.project.config; +import java.util.List; +import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.CopyOnWriteArrayList; +import com.x.base.core.entity.StorageProtocol; import com.x.base.core.entity.StorageType; +import com.x.base.core.project.annotation.FieldDescribe; -public class ExternalStorageSources extends ConcurrentHashMap> { +public class ExternalStorageSources extends ConfigObject { private static final long serialVersionUID = 8229115124625865737L; public static ExternalStorageSources defaultInstance() { ExternalStorageSources externalStorages = new ExternalStorageSources(); - + externalStorages.getFile(); + externalStorages.getMind(); + externalStorages.getMeeting(); + externalStorages.getProcessPlatform(); + externalStorages.getCalendar(); + externalStorages.getOkr(); + externalStorages.getCms(); + externalStorages.getBbs(); + externalStorages.getReport(); + externalStorages.getStrategyDeploy(); + externalStorages.getTeamwork(); + externalStorages.getStructure(); + externalStorages.getIm(); + externalStorages.getGeneral(); + externalStorages.getCustom(); + externalStorages.getStore(); return externalStorages; } public ExternalStorageSources() { super(); + + } + + private CopyOnWriteArrayList file; + private CopyOnWriteArrayList processPlatform; + private CopyOnWriteArrayList mind; + private CopyOnWriteArrayList meeting; + private CopyOnWriteArrayList calendar; + private CopyOnWriteArrayList okr; + private CopyOnWriteArrayList cms; + private CopyOnWriteArrayList bbs; + private CopyOnWriteArrayList report; + private CopyOnWriteArrayList strategyDeploy; + private CopyOnWriteArrayList teamwork; + private CopyOnWriteArrayList structure; + private CopyOnWriteArrayList im; + private CopyOnWriteArrayList general; + private CopyOnWriteArrayList custom; + + private ConcurrentHashMap store; + + public Map getStore() { + if (null == this.store) { + this.store = new ConcurrentHashMap<>(); + } + return this.store; + } + + public List get(StorageType storageType) { + switch (storageType) { + case file: + return this.getFile(); + case processPlatform: + return this.getProcessPlatform(); + case mind: + return this.getMind(); + case meeting: + return this.getMeeting(); + case calendar: + return this.getCalendar(); + case okr: + return this.getOkr(); + case cms: + return this.getCms(); + case bbs: + return this.getBbs(); + case report: + return this.getReport(); + case strategyDeploy: + return this.getStrategyDeploy(); + case teamwork: + return this.getTeamwork(); + case structure: + return this.getStructure(); + case im: + return this.getIm(); + case general: + return this.getGeneral(); + case custom: + default: + return this.getCustom(); + } + } + + public List getFile() { + if (null == this.file) { + this.file = new CopyOnWriteArrayList<>(); + this.file.add(new ExternalStorageSource()); + } + return this.file; + } + + public List getMind() { + if (null == this.mind) { + this.mind = new CopyOnWriteArrayList<>(); + this.mind.add(new ExternalStorageSource()); + } + return this.mind; + } + + public List getMeeting() { + if (null == this.meeting) { + this.meeting = new CopyOnWriteArrayList<>(); + this.meeting.add(new ExternalStorageSource()); + } + return this.meeting; } + public List getProcessPlatform() { + if (null == this.processPlatform) { + this.processPlatform = new CopyOnWriteArrayList<>(); + this.processPlatform.add(new ExternalStorageSource()); + } + return this.processPlatform; + } + + public List getCalendar() { + if (null == this.calendar) { + this.calendar = new CopyOnWriteArrayList<>(); + this.calendar.add(new ExternalStorageSource()); + } + return this.calendar; + } + + public List getOkr() { + if (null == this.okr) { + this.okr = new CopyOnWriteArrayList<>(); + this.okr.add(new ExternalStorageSource()); + } + return this.okr; + } + + public List getCms() { + if (null == this.cms) { + this.cms = new CopyOnWriteArrayList<>(); + this.cms.add(new ExternalStorageSource()); + } + return this.cms; + } + + public List getBbs() { + if (null == this.bbs) { + this.bbs = new CopyOnWriteArrayList<>(); + this.bbs.add(new ExternalStorageSource()); + } + return this.bbs; + } + + public List getReport() { + if (null == this.report) { + this.report = new CopyOnWriteArrayList<>(); + this.report.add(new ExternalStorageSource()); + } + return this.report; + } + + public List getStrategyDeploy() { + if (null == this.strategyDeploy) { + this.strategyDeploy = new CopyOnWriteArrayList<>(); + this.strategyDeploy.add(new ExternalStorageSource()); + } + return this.strategyDeploy; + } + + public List getTeamwork() { + if (null == this.teamwork) { + this.teamwork = new CopyOnWriteArrayList<>(); + this.teamwork.add(new ExternalStorageSource()); + } + return this.teamwork; + } + + public List getStructure() { + if (null == this.structure) { + this.structure = new CopyOnWriteArrayList<>(); + this.structure.add(new ExternalStorageSource()); + } + return this.structure; + } + + public List getIm() { + if (null == this.im) { + this.im = new CopyOnWriteArrayList<>(); + this.im.add(new ExternalStorageSource()); + } + return this.im; + } + + public List getGeneral() { + if (null == this.general) { + this.general = new CopyOnWriteArrayList<>(); + this.general.add(new ExternalStorageSource()); + } + return this.general; + } + + public List getCustom() { + if (null == this.custom) { + this.custom = new CopyOnWriteArrayList<>(); + this.custom.add(new ExternalStorageSource()); + } + return this.custom; + } + + public static class Store { + + private StorageProtocol protocol; + @FieldDescribe("登录用户名.") + private String username; + @FieldDescribe("登录密码.") + private String password; + @FieldDescribe("主机地址或阿里云endpoint.") + private String host; + @FieldDescribe("端口.") + private Integer port; + @FieldDescribe("存储节点名,对应存储名称,阿里云为bucket(桶)名称.") + private String name; + + public StorageProtocol getProtocol() { + return protocol; + } + + public void setProtocol(StorageProtocol protocol) { + this.protocol = protocol; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public String getHost() { + return host; + } + + public void setHost(String host) { + this.host = host; + } + + public Integer getPort() { + return port; + } + + public void setPort(Integer port) { + this.port = port; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + } } diff --git a/o2server/x_base_core_project/src/main/java/com/x/base/core/project/config/StorageMappings.java b/o2server/x_base_core_project/src/main/java/com/x/base/core/project/config/StorageMappings.java index c3bffda39358e5ef28b3b094f4b79e8c4f54246d..b2c3ea495e3be12a65d2a74f0d199443c8c31472 100644 --- a/o2server/x_base_core_project/src/main/java/com/x/base/core/project/config/StorageMappings.java +++ b/o2server/x_base_core_project/src/main/java/com/x/base/core/project/config/StorageMappings.java @@ -1,5 +1,6 @@ package com.x.base.core.project.config; +import java.security.SecureRandom; import java.util.Random; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.CopyOnWriteArrayList; @@ -17,20 +18,52 @@ public class StorageMappings extends ConcurrentHashMap> entry : externalStorageSources +// .entrySet()) { +// CopyOnWriteArrayList list = new CopyOnWriteArrayList<>(); +// for (ExternalStorageSource externalStorageSource : entry.getValue()) { +// if (BooleanUtils.isTrue(externalStorageSource.getEnable())) { +// StorageMapping storageMapping = new StorageMapping(externalStorageSource); +// list.add(storageMapping); +// } +// this.put(entry.getKey(), list); +// } +// } +// } + public StorageMappings(ExternalStorageSources externalStorageSources) { - for (Entry> entry : externalStorageSources - .entrySet()) { + for (StorageType o : StorageType.values()) { CopyOnWriteArrayList list = new CopyOnWriteArrayList<>(); - for (ExternalStorageSource externalStorageSource : entry.getValue()) { + for (ExternalStorageSource externalStorageSource : externalStorageSources.get(o)) { if (BooleanUtils.isTrue(externalStorageSource.getEnable())) { + fillWithStore(externalStorageSources, externalStorageSource); StorageMapping storageMapping = new StorageMapping(externalStorageSource); list.add(storageMapping); } - this.put(entry.getKey(), list); + } + this.put(o, list); + } + } + + private void fillWithStore(ExternalStorageSources externalStorageSources, + ExternalStorageSource externalStorageSource) { + String key = externalStorageSource.getStore(); + if (StringUtils.isNotBlank(key)) { + ExternalStorageSources.Store store = externalStorageSources.getStore().get(key); + if (null != store) { + externalStorageSource.setHost(store.getHost()); + externalStorageSource.setName(store.getName()); + externalStorageSource.setPassword(store.getPassword()); + externalStorageSource.setUsername(store.getUsername()); + externalStorageSource.setPort(store.getPort()); + externalStorageSource.setProtocol(store.getProtocol()); } } } @@ -39,7 +72,7 @@ public class StorageMappings extends ConcurrentHashMap()); + this.put(o, new CopyOnWriteArrayList<>()); } StorageServers storageServers = nodeConfigs.storageServers(); for (Entry en : storageServers.entrySet()) { @@ -62,20 +95,20 @@ public class StorageMappings extends ConcurrentHashMap StorageType getStorageType(Class clz) throws Exception { + private StorageType getStorageType(Class clz) { Storage o = clz.getAnnotation(Storage.class); if (null == o) { - throw new Exception( + throw new IllegalStateException( "can not find " + Storage.class.getName() + " annotation in class: " + clz.getName() + "."); } StorageType type = o.type(); if (null == type) { - throw new Exception("can not find storageType in class: " + clz.getName() + "."); + throw new IllegalStateException("can not find storageType in class: " + clz.getName() + "."); } return type; } - public StorageMapping get(Class clz, String name) throws Exception { + public StorageMapping get(Class clz, String name) { StorageType type = this.getStorageType(clz); return this.get(type, name); } @@ -94,18 +127,17 @@ public class StorageMappings extends ConcurrentHashMap StorageMapping random(Class clz) throws Exception { + public StorageMapping random(Class clz) { StorageType type = this.getStorageType(clz); return this.random(type); } - private StorageMapping random(StorageType type) throws Exception { + private StorageMapping random(StorageType type) { CopyOnWriteArrayList list = this.get(type); if (ListTools.isEmpty(list)) { - throw new Exception("can not get storage of " + type); + throw new IllegalStateException("can not get storage of " + type); } int total = 0; - Random random = new Random(); for (StorageMapping o : list) { total += o.getWeight(); } @@ -117,6 +149,6 @@ public class StorageMappings extends ConcurrentHashMap) cls, so.getStorage());