提交 26694132 编写于 作者: O o2null

Merge branch 'feature/messages' into 'develop'

更新externalStorageSources

See merge request o2oa/o2oa!868
......@@ -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
......@@ -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);
......
......@@ -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;
}
}
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<StorageType, CopyOnWriteArrayList<ExternalStorageSource>> {
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<ExternalStorageSource> file;
private CopyOnWriteArrayList<ExternalStorageSource> processPlatform;
private CopyOnWriteArrayList<ExternalStorageSource> mind;
private CopyOnWriteArrayList<ExternalStorageSource> meeting;
private CopyOnWriteArrayList<ExternalStorageSource> calendar;
private CopyOnWriteArrayList<ExternalStorageSource> okr;
private CopyOnWriteArrayList<ExternalStorageSource> cms;
private CopyOnWriteArrayList<ExternalStorageSource> bbs;
private CopyOnWriteArrayList<ExternalStorageSource> report;
private CopyOnWriteArrayList<ExternalStorageSource> strategyDeploy;
private CopyOnWriteArrayList<ExternalStorageSource> teamwork;
private CopyOnWriteArrayList<ExternalStorageSource> structure;
private CopyOnWriteArrayList<ExternalStorageSource> im;
private CopyOnWriteArrayList<ExternalStorageSource> general;
private CopyOnWriteArrayList<ExternalStorageSource> custom;
private ConcurrentHashMap<String, Store> store;
public Map<String, Store> getStore() {
if (null == this.store) {
this.store = new ConcurrentHashMap<>();
}
return this.store;
}
public List<ExternalStorageSource> 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<ExternalStorageSource> getFile() {
if (null == this.file) {
this.file = new CopyOnWriteArrayList<>();
this.file.add(new ExternalStorageSource());
}
return this.file;
}
public List<ExternalStorageSource> getMind() {
if (null == this.mind) {
this.mind = new CopyOnWriteArrayList<>();
this.mind.add(new ExternalStorageSource());
}
return this.mind;
}
public List<ExternalStorageSource> getMeeting() {
if (null == this.meeting) {
this.meeting = new CopyOnWriteArrayList<>();
this.meeting.add(new ExternalStorageSource());
}
return this.meeting;
}
public List<ExternalStorageSource> getProcessPlatform() {
if (null == this.processPlatform) {
this.processPlatform = new CopyOnWriteArrayList<>();
this.processPlatform.add(new ExternalStorageSource());
}
return this.processPlatform;
}
public List<ExternalStorageSource> getCalendar() {
if (null == this.calendar) {
this.calendar = new CopyOnWriteArrayList<>();
this.calendar.add(new ExternalStorageSource());
}
return this.calendar;
}
public List<ExternalStorageSource> getOkr() {
if (null == this.okr) {
this.okr = new CopyOnWriteArrayList<>();
this.okr.add(new ExternalStorageSource());
}
return this.okr;
}
public List<ExternalStorageSource> getCms() {
if (null == this.cms) {
this.cms = new CopyOnWriteArrayList<>();
this.cms.add(new ExternalStorageSource());
}
return this.cms;
}
public List<ExternalStorageSource> getBbs() {
if (null == this.bbs) {
this.bbs = new CopyOnWriteArrayList<>();
this.bbs.add(new ExternalStorageSource());
}
return this.bbs;
}
public List<ExternalStorageSource> getReport() {
if (null == this.report) {
this.report = new CopyOnWriteArrayList<>();
this.report.add(new ExternalStorageSource());
}
return this.report;
}
public List<ExternalStorageSource> getStrategyDeploy() {
if (null == this.strategyDeploy) {
this.strategyDeploy = new CopyOnWriteArrayList<>();
this.strategyDeploy.add(new ExternalStorageSource());
}
return this.strategyDeploy;
}
public List<ExternalStorageSource> getTeamwork() {
if (null == this.teamwork) {
this.teamwork = new CopyOnWriteArrayList<>();
this.teamwork.add(new ExternalStorageSource());
}
return this.teamwork;
}
public List<ExternalStorageSource> getStructure() {
if (null == this.structure) {
this.structure = new CopyOnWriteArrayList<>();
this.structure.add(new ExternalStorageSource());
}
return this.structure;
}
public List<ExternalStorageSource> getIm() {
if (null == this.im) {
this.im = new CopyOnWriteArrayList<>();
this.im.add(new ExternalStorageSource());
}
return this.im;
}
public List<ExternalStorageSource> getGeneral() {
if (null == this.general) {
this.general = new CopyOnWriteArrayList<>();
this.general.add(new ExternalStorageSource());
}
return this.general;
}
public List<ExternalStorageSource> 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;
}
}
}
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<StorageType, CopyOnWriteA
private static final long serialVersionUID = 2056028069887353406L;
private Random random = new SecureRandom();
public StorageMappings() {
super();
}
// public StorageMappings(ExternalStorageSources externalStorageSources) {
// for (Entry<StorageType, CopyOnWriteArrayList<ExternalStorageSource>> entry : externalStorageSources
// .entrySet()) {
// CopyOnWriteArrayList<StorageMapping> 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<StorageType, CopyOnWriteArrayList<ExternalStorageSource>> entry : externalStorageSources
.entrySet()) {
for (StorageType o : StorageType.values()) {
CopyOnWriteArrayList<StorageMapping> 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<StorageType, CopyOnWriteA
super();
/** 填充空值 */
for (StorageType o : StorageType.values()) {
this.put(o, new CopyOnWriteArrayList<StorageMapping>());
this.put(o, new CopyOnWriteArrayList<>());
}
StorageServers storageServers = nodeConfigs.storageServers();
for (Entry<String, StorageServer> en : storageServers.entrySet()) {
......@@ -62,20 +95,20 @@ public class StorageMappings extends ConcurrentHashMap<StorageType, CopyOnWriteA
}
}
private <T extends StorageObject> StorageType getStorageType(Class<T> clz) throws Exception {
private <T extends StorageObject> StorageType getStorageType(Class<T> 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 <T extends StorageObject> StorageMapping get(Class<T> clz, String name) throws Exception {
public <T extends StorageObject> StorageMapping get(Class<T> clz, String name) {
StorageType type = this.getStorageType(clz);
return this.get(type, name);
}
......@@ -94,18 +127,17 @@ public class StorageMappings extends ConcurrentHashMap<StorageType, CopyOnWriteA
return storageMapping;
}
public <T extends StorageObject> StorageMapping random(Class<T> clz) throws Exception {
public <T extends StorageObject> StorageMapping random(Class<T> clz) {
StorageType type = this.getStorageType(clz);
return this.random(type);
}
private StorageMapping random(StorageType type) throws Exception {
private StorageMapping random(StorageType type) {
CopyOnWriteArrayList<StorageMapping> 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<StorageType, CopyOnWriteA
return o;
}
}
throw new Exception("randomWithWeight error can not get available storage.");
throw new IllegalStateException("randomWithWeight error can not get available storage.");
}
}
\ No newline at end of file
......@@ -265,7 +265,8 @@ public class RestoreData {
if (ListTools.isNotEmpty(list)) {
em.getTransaction().begin();
for (T t : list) {
if (StorageObject.class.isAssignableFrom(cls)) {
if (BooleanUtils.isTrue(Config.dumpRestoreData().getAttachStorage())
&& StorageObject.class.isAssignableFrom(cls)) {
StorageObject so = (StorageObject) t;
@SuppressWarnings("unchecked")
StorageMapping mapping = storageMappings.get((Class<StorageObject>) cls, so.getStorage());
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册