diff --git a/o2server/configSample/externalStorageSources.json b/o2server/configSample/externalStorageSources.json index 8f1afa4b31b207b1ff1cfbae652c5628815cca64..5f2d727d43a96ace67ba065bfc2b7a1b2ed4a98e 100755 --- a/o2server/configSample/externalStorageSources.json +++ b/o2server/configSample/externalStorageSources.json @@ -1,214 +1,58 @@ { "file": [ - { - "protocol": "webdav", - "username": "admin", - "password": "admin", - "host": "127.0.0.1", - "port": 8080.0, - "prefix": "", - "enable": true, - "weight": 100.0, - "name": "251", - "deepPath": false - } + {} ], "processPlatform": [ - { - "protocol": "webdav", - "username": "admin", - "password": "admin", - "host": "127.0.0.1", - "port": 8080.0, - "prefix": "", - "enable": true, - "weight": 100.0, - "name": "251", - "deepPath": false - } + {} ], "mind": [ - { - "protocol": "webdav", - "username": "admin", - "password": "admin", - "host": "127.0.0.1", - "port": 8080.0, - "prefix": "", - "enable": true, - "weight": 100.0, - "name": "251", - "deepPath": false - } + {} ], "meeting": [ - { - "protocol": "webdav", - "username": "admin", - "password": "admin", - "host": "127.0.0.1", - "port": 8080.0, - "prefix": "", - "enable": true, - "weight": 100.0, - "name": "251", - "deepPath": false - } + {} ], "calendar": [ - { - "protocol": "webdav", - "username": "admin", - "password": "admin", - "host": "127.0.0.1", - "port": 8080.0, - "prefix": "", - "enable": true, - "weight": 100.0, - "name": "251", - "deepPath": false - } + {} ], "okr": [ - { - "protocol": "webdav", - "username": "admin", - "password": "admin", - "host": "127.0.0.1", - "port": 8080.0, - "prefix": "", - "enable": true, - "weight": 100.0, - "name": "251", - "deepPath": false - } + {} ], "cms": [ - { - "protocol": "webdav", - "username": "admin", - "password": "admin", - "host": "127.0.0.1", - "port": 8080.0, - "prefix": "", - "enable": true, - "weight": 100.0, - "name": "251", - "deepPath": false - } + {} ], "bbs": [ - { - "protocol": "webdav", - "username": "admin", - "password": "admin", - "host": "127.0.0.1", - "port": 8080.0, - "prefix": "", - "enable": true, - "weight": 100.0, - "name": "251", - "deepPath": false - } + {} ], "report": [ - { - "protocol": "webdav", - "username": "admin", - "password": "admin", - "host": "127.0.0.1", - "port": 8080.0, - "prefix": "", - "enable": true, - "weight": 100.0, - "name": "251", - "deepPath": false - } + {} ], "strategyDeploy": [ - { - "protocol": "webdav", - "username": "admin", - "password": "admin", - "host": "127.0.0.1", - "port": 8080.0, - "prefix": "", - "enable": true, - "weight": 100.0, - "name": "251", - "deepPath": false - } + {} ], "teamwork": [ - { - "protocol": "webdav", - "username": "admin", - "password": "admin", - "host": "127.0.0.1", - "port": 8080.0, - "prefix": "", - "enable": true, - "weight": 100.0, - "name": "251", - "deepPath": false - } + {} ], "structure": [ - { - "protocol": "webdav", - "username": "admin", - "password": "admin", - "host": "127.0.0.1", - "port": 8080.0, - "prefix": "", - "enable": true, - "weight": 100.0, - "name": "251", - "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": [ - { - "protocol": "webdav", - "username": "admin", - "password": "admin", - "host": "127.0.0.1", - "port": 8080.0, - "prefix": "", - "enable": true, - "weight": 100.0, - "name": "251", - "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": {}, + {} + ], + "store": { + "demo": { + "protocol": "hdfs", + "username": "", + "password": "", + "host": "hdfs://127.0.0.1", + "port": 9000.0, + "name": "" + } + }, "###extension": "扩展设置.###" } \ No newline at end of file diff --git a/o2server/x_base_core_project/src/main/java/com/x/base/core/project/config/Config.java b/o2server/x_base_core_project/src/main/java/com/x/base/core/project/config/Config.java index e3f8aac7ca5fca6b8ac894c6f5dfbdca2108b631..51d693b9bcbb033d2420871b62b2435289ee6ddc 100644 --- a/o2server/x_base_core_project/src/main/java/com/x/base/core/project/config/Config.java +++ b/o2server/x_base_core_project/src/main/java/com/x/base/core/project/config/Config.java @@ -131,6 +131,7 @@ public class Config { public static final String DIR_JVM = "jvm"; public static final String DIR_LOCAL = "local"; public static final String DIR_LOCAL_BACKUP = "local/backup"; + public static final String DIR_LOCAL_DUMP = "local/dump"; public static final String DIR_LOCAL_REPOSITORY = "local/repository"; public static final String DIR_LOCAL_UPDATE = "local/update"; public static final String DIR_LOCAL_TEMP = "local/temp"; @@ -469,14 +470,13 @@ public class Config { return new File(base(), DIR_STORE); } - public static File dir_store(Boolean force) throws Exception { + public static File dir_store(boolean force) throws Exception { File dir = new File(base(), DIR_STORE); - if (force) { - if ((!dir.exists()) || dir.isFile()) { - FileUtils.forceMkdir(dir); - } + if (force && ((!dir.exists()) || dir.isFile())) { + FileUtils.forceMkdir(dir); } return dir; + } public static File dir_store_jars() throws Exception { @@ -1218,19 +1218,6 @@ public class Config { } } -// private Organization organization; -// -// public static synchronized Organization organization() throws Exception { -// if (null == instance().organization) { -// Organization obj = BaseTools.readConfigObject(PATH_CONFIG_ORGANIZATION, Organization.class); -// if (null == obj) { -// obj = Organization.defaultInstance(); -// } -// instance().organization = obj; -// } -// return instance().organization; -// } - public static Object resource(String name) throws Exception { return initialContext().lookup(name); } @@ -1253,11 +1240,6 @@ public class Config { ConcurrentHashMap map = (ConcurrentHashMap) initialContext() .lookup(RESOURCE_NODE_APPLICATIONS); return (JsonElement) map.get(RESOURCE_NODE_APPLICATIONS); -// Object o = initialContext().lookup(RESOURCE_NODE_APPLICATIONS); -// if (null != o) { -// return (JsonElement) o; -// } -// return null; } @SuppressWarnings("unchecked") @@ -1265,7 +1247,6 @@ public class Config { ConcurrentHashMap map = (ConcurrentHashMap) initialContext() .lookup(RESOURCE_NODE_APPLICATIONS); map.put(RESOURCE_NODE_APPLICATIONS, jsonElement); - // initialContext().rebind(RESOURCE_NODE_APPLICATIONS, jsonElement); } @SuppressWarnings("unchecked") @@ -1273,11 +1254,6 @@ public class Config { ConcurrentHashMap map = (ConcurrentHashMap) initialContext() .lookup(RESOURCE_NODE_APPLICATIONS); return (Date) map.get(RESOURCE_NODE_APPLICATIONSTIMESTAMP); - // Object o = initialContext().lookup(RESOURCE_NODE_APPLICATIONSTIMESTAMP); -// if (null != o) { -// return (Date) o; -// } -// return null; } @SuppressWarnings("unchecked") @@ -1285,7 +1261,6 @@ public class Config { ConcurrentHashMap map = (ConcurrentHashMap) initialContext() .lookup(RESOURCE_NODE_APPLICATIONS); map.put(RESOURCE_NODE_APPLICATIONSTIMESTAMP, date); - // initialContext().rebind(RESOURCE_NODE_APPLICATIONSTIMESTAMP, date); } @SuppressWarnings("unchecked") @@ -1293,11 +1268,6 @@ public class Config { ConcurrentHashMap map = (ConcurrentHashMap) initialContext() .lookup(RESOURCE_NODE_APPLICATIONS); return (String) map.get(RESOURCE_NODE_CENTERSPRIMARYNODE); -// Object o = initialContext().lookup()RESOURCE_NODE_CENTERSPRIMARYNODE; -// if (null != o) { -// return (String) o; -// } -// return null; } @SuppressWarnings("unchecked") @@ -1312,11 +1282,6 @@ public class Config { ConcurrentHashMap map = (ConcurrentHashMap) initialContext() .lookup(RESOURCE_NODE_APPLICATIONS); return (Integer) map.get(RESOURCE_NODE_CENTERSPRIMARYPORT); - // Object o = initialContext().lookup(RESOURCE_NODE_CENTERSPRIMARYPORT); -// if (null != o) { -// return (Integer) o; -// } -// return null; } @SuppressWarnings("unchecked") @@ -1324,7 +1289,6 @@ public class Config { ConcurrentHashMap map = (ConcurrentHashMap) initialContext() .lookup(RESOURCE_NODE_APPLICATIONS); map.put(RESOURCE_NODE_CENTERSPRIMARYPORT, port); - // initialContext().rebind(RESOURCE_NODE_CENTERSPRIMARYPORT, port); } @SuppressWarnings("unchecked") @@ -1332,11 +1296,6 @@ public class Config { ConcurrentHashMap map = (ConcurrentHashMap) initialContext() .lookup(RESOURCE_NODE_APPLICATIONS); return (Boolean) map.get(RESOURCE_NODE_CENTERSPRIMARYSSLENABLE); - // Object o = initialContext().lookup(RESOURCE_NODE_CENTERSPRIMARYSSLENABLE); -// if (null != o) { -// return (Boolean) o; -// } -// return null; } @SuppressWarnings("unchecked") @@ -1344,7 +1303,6 @@ public class Config { ConcurrentHashMap map = (ConcurrentHashMap) initialContext() .lookup(RESOURCE_NODE_APPLICATIONS); map.put(RESOURCE_NODE_CENTERSPRIMARYSSLENABLE, sslEnable); - // initialContext().rebind(RESOURCE_NODE_CENTERSPRIMARYSSLENABLE, sslEnable); } public static synchronized ExecutorService[] resource_node_processPlatformExecutors() throws Exception { @@ -1425,7 +1383,7 @@ public class Config { return command_java_path().startsWith(dir_jvm().toPath().resolve(OS_MACOS + "_" + JAVAVERSION_JAVA11)); } - public static Path path_commons_hadoop_windows(boolean force) throws Exception { + public static Path path_commons_hadoop_windows(boolean force) throws IOException, URISyntaxException { Path path = Paths.get(base(), DIR_COMMONS_HADOOP_WINDOWS); if ((!Files.exists(path)) && force) { Files.createDirectories(path); @@ -1433,7 +1391,7 @@ public class Config { return path; } - public static Path path_commons_hadoop_linux(boolean force) throws Exception { + public static Path path_commons_hadoop_linux(boolean force) throws IOException, URISyntaxException { Path path = Paths.get(base(), DIR_COMMONS_HADOOP_LINUX); if ((!Files.exists(path)) && force) { Files.createDirectories(path); @@ -1441,7 +1399,7 @@ public class Config { return path; } - public static Path path_commons_hadoop_aix(boolean force) throws Exception { + public static Path path_commons_hadoop_aix(boolean force) throws IOException, URISyntaxException { Path path = Paths.get(base(), DIR_COMMONS_HADOOP_AIX); if ((!Files.exists(path)) && force) { Files.createDirectories(path); @@ -1449,7 +1407,7 @@ public class Config { return path; } - public static Path path_commons_hadoop_macos(boolean force) throws Exception { + public static Path path_commons_hadoop_macos(boolean force) throws IOException, URISyntaxException { Path path = Paths.get(base(), DIR_COMMONS_HADOOP_MACOS); if ((!Files.exists(path)) && force) { Files.createDirectories(path); @@ -1457,7 +1415,7 @@ public class Config { return path; } - public static Path path_commons_hadoop_raspi(boolean force) throws Exception { + public static Path path_commons_hadoop_raspi(boolean force) throws IOException, URISyntaxException { Path path = Paths.get(base(), DIR_COMMONS_HADOOP_RASPI); if ((!Files.exists(path)) && force) { Files.createDirectories(path); @@ -1465,7 +1423,7 @@ public class Config { return path; } - public static Path path_commons_hadoop_arm(boolean force) throws Exception { + public static Path path_commons_hadoop_arm(boolean force) throws IOException, URISyntaxException { Path path = Paths.get(base(), DIR_COMMONS_HADOOP_ARM); if ((!Files.exists(path)) && force) { Files.createDirectories(path); @@ -1473,7 +1431,7 @@ public class Config { return path; } - public static Path path_commons_hadoop_mips(boolean force) throws Exception { + public static Path path_commons_hadoop_mips(boolean force) throws IOException, URISyntaxException { Path path = Paths.get(base(), DIR_COMMONS_HADOOP_MIPS); if ((!Files.exists(path)) && force) { Files.createDirectories(path); @@ -1481,4 +1439,12 @@ public class Config { return path; } + public static Path path_local_dump(boolean force) throws IOException, URISyntaxException { + Path path = Paths.get(base(), DIR_LOCAL_DUMP); + if ((!Files.exists(path)) && force) { + Files.createDirectories(path); + } + return path; + } + } 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 89069ce516e417a10730c8200ce5504c0c51ca32..d087c2a754f33d170b82fd40f1dd36ee1003c882 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 @@ -19,22 +19,20 @@ public class ExternalStorageSource extends ConfigObject { // 无需保存 private transient String _password; - public ExternalStorageSource() { - this.protocol = DEFAULT_PROTOCOL; - this.username = DEFAULT_USERNAME; - this.password = DEFAULT_PASSWORD; - this.host = DEFAULT_HOST; - this.port = DEFAULT_PORT; - this.prefix = DEFAULT_PREFIX; - this.enable = DEFAULT_ENABLE; - this.weight = DEFAULT_WEIGHT; - this.name = DEFAULT_NAME; - this.deepPath = DEFAULT_DEEPPATH; - } - public static ExternalStorageSource defaultInstance() { - return new ExternalStorageSource(); - + ExternalStorageSource o = new ExternalStorageSource(); + o.protocol = DEFAULT_PROTOCOL; + o.username = DEFAULT_USERNAME; + o.password = DEFAULT_PASSWORD; + o.host = DEFAULT_HOST; + o.port = DEFAULT_PORT; + o.prefix = DEFAULT_PREFIX; + o.enable = DEFAULT_ENABLE; + o.weight = DEFAULT_WEIGHT; + o.name = DEFAULT_NAME; + o.deepPath = DEFAULT_DEEPPATH; + o.store = DEFAULT_STORE; + return o; } public static final StorageProtocol DEFAULT_PROTOCOL = StorageProtocol.webdav; @@ -154,7 +152,5 @@ public class ExternalStorageSource extends ConfigObject { 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 45c5a25158b56a685732bcbbf27af15bca173414..c608b697904ee29f4227889266314157c12f0022 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 @@ -61,6 +61,14 @@ public class ExternalStorageSources extends ConfigObject { public Map getStore() { if (null == this.store) { this.store = new ConcurrentHashMap<>(); + Store s = new Store(); + s.setHost("hdfs://127.0.0.1"); + s.setName(""); + s.setUsername(""); + s.setPassword(""); + s.setProtocol(StorageProtocol.hdfs); + s.setPort(9000); + this.store.put("demo", s); } return this.store; } diff --git a/o2server/x_program_center/src/main/java/com/x/program/center/jaxrs/config/ActionListDumpData.java b/o2server/x_program_center/src/main/java/com/x/program/center/jaxrs/config/ActionListDumpData.java new file mode 100644 index 0000000000000000000000000000000000000000..7299578205173db3d8fa6aac63a82deff96ae63b --- /dev/null +++ b/o2server/x_program_center/src/main/java/com/x/program/center/jaxrs/config/ActionListDumpData.java @@ -0,0 +1,74 @@ +package com.x.program.center.jaxrs.config; + +import java.io.IOException; +import java.net.URISyntaxException; +import java.nio.file.DirectoryStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; +import java.util.stream.Collectors; + +import org.apache.commons.lang3.BooleanUtils; +import org.apache.commons.lang3.StringUtils; + +import com.x.base.core.project.config.Config; +import com.x.base.core.project.gson.GsonPropertyObject; +import com.x.base.core.project.http.ActionResult; +import com.x.base.core.project.http.EffectivePerson; +import com.x.base.core.project.logger.Logger; +import com.x.base.core.project.logger.LoggerFactory; +import com.x.base.core.project.tools.DateTools; + +import io.swagger.v3.oas.annotations.media.Schema; + +public class ActionListDumpData extends BaseAction { + + private static final Logger LOGGER = LoggerFactory.getLogger(ActionListDumpData.class); + + private static final String DUMPDATA_PREFIX = "dumpData_"; + + ActionResult> execute(EffectivePerson effectivePerson) throws IOException, URISyntaxException { + + LOGGER.debug("execute:{}.", effectivePerson::getDistinguishedName); + + ActionResult> result = new ActionResult<>(); + + List wos = new ArrayList<>(); + + try (DirectoryStream stream = Files.newDirectoryStream(Config.path_local_dump(true))) { + for (Path path : stream) { + String fileName = path.getFileName().toString(); + if (StringUtils.startsWith(fileName, DUMPDATA_PREFIX) + && BooleanUtils.isTrue( + DateTools.isCompactDateTime(StringUtils.substringAfter(fileName, DUMPDATA_PREFIX))) + && Files.exists(path.resolve("catalog.json"))) { + Wo wo = new Wo(); + wo.setValue(fileName); + wos.add(wo); + } + } + } + result.setData(wos.stream().sorted(Comparator.comparing(Wo::getValue).reversed()).collect(Collectors.toList())); + return result; + } + + @Schema(name = "com.x.program.center.jaxrs.config.ActionListDumpData$Wo") + public static class Wo extends GsonPropertyObject { + + private static final long serialVersionUID = -7649649109954668631L; + + private String value; + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + } + +} diff --git a/o2server/x_program_center/src/main/java/com/x/program/center/jaxrs/config/ConfigAction.java b/o2server/x_program_center/src/main/java/com/x/program/center/jaxrs/config/ConfigAction.java index e840618479592b2d5df2ba363fe666eda453bb5f..f173a4e95a5effa88249fcbbc69375c680aadc0d 100644 --- a/o2server/x_program_center/src/main/java/com/x/program/center/jaxrs/config/ConfigAction.java +++ b/o2server/x_program_center/src/main/java/com/x/program/center/jaxrs/config/ConfigAction.java @@ -431,4 +431,24 @@ public class ConfigAction extends StandardJaxrsAction { asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result)); } + @Operation(summary = "列示所有数据备份.", operationId = OPERATIONID_PREFIX + "listDumpData", responses = { + @ApiResponse(content = { + @Content(array = @ArraySchema(schema = @Schema(implementation = ActionListDumpData.Wo.class))) }) }) + @JaxrsMethodDescribe(value = "列示所有数据备份.", action = ActionListDumpData.class) + @GET + @Path("list/dump/data") + @Produces(HttpMediaType.APPLICATION_JSON_UTF_8) + @Consumes(MediaType.APPLICATION_JSON) + public void listDumpData(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request) { + EffectivePerson effectivePerson = this.effectivePerson(request); + ActionResult> result = new ActionResult<>(); + try { + result = new ActionListDumpData().execute(effectivePerson); + } catch (Exception e) { + e.printStackTrace(); + result.error(e); + } + asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result)); + } + }