Просмотр исходного кода

修改启动脚本先行拷贝

zhourui 5 лет назад
Родитель
Сommit
24b86bdb80

+ 28 - 0
o2server/configSample/cache.json

@@ -0,0 +1,28 @@
+{
+  "type": "ehcache",
+  "redis": {
+    "host": "127.0.0.1",
+    "port": 6379.0,
+    "user": "",
+    "password": "",
+    "connectionTimeout": 3000.0,
+    "socketTimeout": 3000.0,
+    "sslEnable": false,
+    "index": 0.0,
+    "###host": "redis服务器地址###",
+    "###port": "redis服务器端口###",
+    "###user": "认证用户###",
+    "###password": "认证口令###",
+    "###connectionTimeout": "连接等待时间###",
+    "###socketTimeout": "response返回等待时间###",
+    "###sslEnable": "是否启用ssl###",
+    "###index": "数据库编号###"
+  },
+  "ehcache": {
+    "jmxEnable": false,
+    "###jmxEnable": "是否启用jmx###"
+  },
+  "###type": "缓存类型:ehcache,type###",
+  "###redis": "redis配置###",
+  "###ehcache": "ehcache配置###"
+}

+ 9 - 0
o2server/pom.xml

@@ -128,6 +128,10 @@
 			<groupId>org.apache.commons</groupId>
 			<artifactId>commons-text</artifactId>
 		</dependency>
+		<dependency>
+			<groupId>org.apache.commons</groupId>
+			<artifactId>commons-compress</artifactId>
+		</dependency>
 		<dependency>
 			<groupId>org.eclipse.jetty</groupId>
 			<artifactId>jetty-server</artifactId>
@@ -529,6 +533,11 @@
 				<artifactId>maven-model</artifactId>
 				<version>3.0</version>
 			</dependency>
+			<dependency>
+				<groupId>org.apache.commons</groupId>
+				<artifactId>commons-compress</artifactId>
+				<version>1.20</version>
+			</dependency>
 			<dependency>
 				<groupId>org.eclipse.jetty</groupId>
 				<artifactId>jetty-server</artifactId>

+ 7 - 5
o2server/x_base_core_project/src/main/java/com/x/base/core/project/build/CreateConfigSample.java

@@ -11,8 +11,14 @@ import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.lang3.reflect.FieldUtils;
+import org.apache.commons.lang3.reflect.MethodUtils;
+
 import com.x.base.core.project.annotation.FieldDescribe;
 import com.x.base.core.project.config.AppStyle;
+import com.x.base.core.project.config.Cache;
 import com.x.base.core.project.config.CenterServer;
 import com.x.base.core.project.config.ClientInit;
 import com.x.base.core.project.config.Collect;
@@ -42,11 +48,6 @@ import com.x.base.core.project.logger.Logger;
 import com.x.base.core.project.logger.LoggerFactory;
 import com.x.base.core.project.tools.DefaultCharset;
 
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.commons.lang3.reflect.FieldUtils;
-import org.apache.commons.lang3.reflect.MethodUtils;
-
 public class CreateConfigSample {
 
 	private static Logger logger = LoggerFactory.getLogger(CreateConfigSample.class);
@@ -79,6 +80,7 @@ public class CreateConfigSample {
 		classes.add(Vfs.class);
 		classes.add(WorkTime.class);
 		classes.add(ZhengwuDingding.class);
+		classes.add(Cache.class);
 
 		Collections.sort(classes, new Comparator<Class<?>>() {
 			public int compare(Class<?> c1, Class<?> c2) {

+ 43 - 0
o2server/x_base_core_project/src/main/java/com/x/base/core/project/tools/CompressTools.java

@@ -0,0 +1,43 @@
+package com.x.base.core.project.tools;
+
+import java.io.BufferedInputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
+import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream;
+import org.apache.commons.io.IOUtils;
+
+public class CompressTools {
+
+	private CompressTools() {
+	}
+
+	public static void unzip(Path zip, Path dir) throws IOException {
+		try (ZipArchiveInputStream inputStream = new ZipArchiveInputStream(
+				new BufferedInputStream(Files.newInputStream(zip)))) {
+			if (!Files.exists(dir)) {
+				Files.createDirectories(dir);
+			}
+			ZipArchiveEntry entry = null;
+			while ((entry = inputStream.getNextZipEntry()) != null) {
+				Path p = dir.resolve(Paths.get(entry.getName()));
+				if (entry.isDirectory()) {
+					if (!Files.exists(p)) {
+						Files.createDirectories(p);
+					}
+				} else {
+					if (!Files.exists(p)) {
+						Files.createFile(p);
+					}
+					try (OutputStream os = Files.newOutputStream(p)) {
+						IOUtils.copy(inputStream, os);
+					}
+				}
+			}
+		}
+	}
+}

+ 37 - 4
o2server/x_base_core_project/src/main/java/com/x/base/core/project/tools/PathTools.java

@@ -1,10 +1,11 @@
 package com.x.base.core.project.tools;
 
-public class PathTools {
+import java.nio.file.Files;
+import java.nio.file.Path;
 
-	private PathTools() {
-		// nothing
-	}
+import org.apache.commons.lang3.StringUtils;
+
+public class PathTools {
 
 	public static final String WEB_INF = "WEB-INF";
 	public static final String WEB_INF_WEB_XML = "WEB-INF/web.xml";
@@ -12,5 +13,37 @@ public class PathTools {
 	public static final String WEB_INF_LASTMODIFIED = "WEB-INF/lastModified";
 	public static final String META_INF = "META";
 	public static final String DOT_WAR = ".war";
+	public static final String DOT_JAR = ".jar";
+	public static final String DOT_ZIP = ".zip";
+	public static final String DOT_BAT = ".bat";
+	public static final String DOT_SH = ".sh";
+
+	public static boolean shOrBat(Path path) {
+		if (Files.exists(path) && (!Files.isDirectory(path))) {
+			return StringUtils.endsWithAny(path.getFileName().toString().toLowerCase(), DOT_BAT, DOT_SH);
+		}
+		return false;
+	}
+
+	public static boolean jarOrZip(Path path) {
+		if (Files.exists(path) && (!Files.isDirectory(path))) {
+			return StringUtils.endsWithAny(path.getFileName().toString().toLowerCase(), DOT_JAR, DOT_ZIP);
+		}
+		return false;
+	}
+
+	public static boolean jar(Path path) {
+		if (Files.exists(path) && (!Files.isDirectory(path))) {
+			return StringUtils.endsWith(path.getFileName().toString().toLowerCase(), DOT_JAR);
+		}
+		return false;
+	}
+
+	public static boolean war(Path path) {
+		if (Files.exists(path) && (!Files.isDirectory(path))) {
+			return StringUtils.endsWith(path.getFileName().toString().toLowerCase(), DOT_WAR);
+		}
+		return false;
+	}
 
 }

+ 35 - 31
o2server/x_console/src/main/java/com/x/server/console/action/UpdateFile.java

@@ -1,15 +1,22 @@
 package com.x.server.console.action;
 
 import java.io.File;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
 import java.util.Date;
+import java.util.stream.Stream;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.filefilter.FileFilterUtils;
+import org.apache.commons.io.filefilter.IOFileFilter;
+import org.apache.commons.io.filefilter.WildcardFileFilter;
 
 import com.x.base.core.project.config.Config;
 import com.x.base.core.project.logger.Logger;
 import com.x.base.core.project.logger.LoggerFactory;
 import com.x.base.core.project.tools.JarTools;
 
-import org.apache.commons.io.FileUtils;
-
 /**
  * @author Zhou Rui
  */
@@ -31,11 +38,9 @@ public class UpdateFile extends ActionBase {
 				logger.print("zip file not exist, path:{}.", path);
 				return false;
 			}
-			// if (backup) {
-			// 	this.backup();
-			// }
 			logger.print("update from file:{}.", file.getAbsolutePath());
 			this.unzip(file);
+			this.updateShell();
 			logger.print("update completed in {} seconds, restart server to continue update.",
 					((new Date()).getTime() - start.getTime()) / 1000);
 			return true;
@@ -45,32 +50,31 @@ public class UpdateFile extends ActionBase {
 		}
 	}
 
-	// private void backup() throws Exception {
-	// 	File dir = Config.dir_local_backup(true);
-	// 	String tag = DateTools.compact(new Date());
-	// 	File dest = new File(dir, tag + ".zip");
-	// 	logger.print("backup current version to {}.", dest.getAbsolutePath());
-	// 	List<File> files = new ArrayList<>();
-	// 	files.add(Config.dir_commons());
-	// 	files.add(Config.dir_config());
-	// 	files.add(Config.dir_configSample());
-	// 	files.add(Config.dir_localSample());
-	// 	files.add(Config.dir_jvm());
-	// 	files.add(Config.dir_servers());
-	// 	files.add(Config.dir_store());
-	// 	files.add(Config.dir_dynamic());
-	// 	files.add(Config.dir_custom());
-	// 	files.add(new File(Config.base(), "console.jar"));
-	// 	files.add(new File(Config.base(), "index.html"));
-	// 	files.add(new File(Config.base(), "version.o2"));
-	// 	FileFilter fileFilter = new RegexFileFilter(
-	// 			"^(start_|stop_|console_|service_)(aix|windows|linux|macos).(sh|bat)$");
-	// 	for (File _f : new File(Config.base()).listFiles(fileFilter)) {
-	// 		files.add(_f);
-	// 	}
-	// 	JarTools.jar(files, dest);
-	// 	logger.print("backup current version completed.");
-	// }
+	private void updateShell() throws Exception {
+		IOFileFilter filter = FileFilterUtils.or(new WildcardFileFilter("start_*.sh"),
+				new WildcardFileFilter("start_*.bat"), new WildcardFileFilter("stop_*.sh"),
+				new WildcardFileFilter("stop_*.bat"), new WildcardFileFilter("console_*.sh"),
+				new WildcardFileFilter("console_*.bat"), new WildcardFileFilter("service_*.bat"));
+		try (Stream<Path> stream = Files.list(Config.dir_local_update().toPath().resolve(Paths.get("o2server")))) {
+			stream.filter(o -> filter.accept(o.toFile())).forEach(o -> {
+				try {
+					copy(o);
+					Files.delete(o);
+				} catch (Exception e) {
+					logger.error(e);
+				}
+			});
+		}
+	}
+
+	private void copy(Path source) throws Exception {
+		Path target = Paths.get(Config.base(), source.getFileName().toString());
+		if (Files.exists(target)) {
+			Files.write(target, Files.readAllLines(source));
+		} else {
+			Files.copy(source, target);
+		}
+	}
 
 	private void unzip(File file) throws Exception {
 		File dir = Config.dir_local_update(true);

+ 45 - 0
o2server/x_query_service_processing/src/main/java/com/x/query/service/processing/jaxrs/test/ActionGroup1.java

@@ -0,0 +1,45 @@
+package com.x.query.service.processing.jaxrs.test;
+
+import javax.persistence.EntityManager;
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.CriteriaQuery;
+import javax.persistence.criteria.Root;
+
+import com.x.base.core.container.EntityManagerContainer;
+import com.x.base.core.container.factory.EntityManagerContainerFactory;
+import com.x.base.core.project.http.ActionResult;
+import com.x.base.core.project.http.EffectivePerson;
+import com.x.base.core.project.jaxrs.WrapBoolean;
+import com.x.base.core.project.logger.Logger;
+import com.x.base.core.project.logger.LoggerFactory;
+import com.x.base.core.project.utils.time.ClockStamp;
+import com.x.processplatform.core.entity.content.Work;
+import com.x.processplatform.core.entity.content.Work_;
+
+class ActionGroup1 extends BaseAction {
+
+	private static Logger logger = LoggerFactory.getLogger(ActionGroup1.class);
+
+	ActionResult<Wo> execute(EffectivePerson effectivePerson) throws Exception {
+		try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
+			ClockStamp.INIT("创建测试distinct代码.", "");
+
+			return new ActionResult<>();
+		}
+	}
+
+	private void id(EntityManagerContainer emc) throws Exception {
+		ClockStamp.STAMP("执行work的id distinct{}.", "开始");
+		EntityManager em = emc.get(Work.class);
+		CriteriaBuilder cb = em.getCriteriaBuilder();
+		CriteriaQuery<String> cq = cb.createQuery(String.class);
+		Root<Work> root = cq.from(Work.class);
+		cq.select(root.get(Work_.id)).distinct(true);
+		em.createQuery(cq).getResultList();
+		ClockStamp.STAMP("执行work的id distinct{}.", "结束");
+	}
+
+	public static class Wo extends WrapBoolean {
+	}
+
+}

+ 21 - 17
o2server/x_query_service_processing/src/main/java/com/x/query/service/processing/jaxrs/test/ActionGroup2.java

@@ -1,11 +1,9 @@
 package com.x.query.service.processing.jaxrs.test;
 
-import java.util.ArrayList;
-
-import javax.script.Bindings;
-import javax.script.ScriptContext;
-import javax.script.ScriptEngine;
-import javax.script.SimpleScriptContext;
+import javax.persistence.EntityManager;
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.CriteriaQuery;
+import javax.persistence.criteria.Root;
 
 import com.x.base.core.container.EntityManagerContainer;
 import com.x.base.core.container.factory.EntityManagerContainerFactory;
@@ -14,7 +12,9 @@ import com.x.base.core.project.http.EffectivePerson;
 import com.x.base.core.project.jaxrs.WrapBoolean;
 import com.x.base.core.project.logger.Logger;
 import com.x.base.core.project.logger.LoggerFactory;
-import com.x.base.core.project.script.ScriptFactory;
+import com.x.base.core.project.utils.time.ClockStamp;
+import com.x.processplatform.core.entity.content.Work;
+import com.x.processplatform.core.entity.content.Work_;
 
 class ActionGroup2 extends BaseAction {
 
@@ -22,19 +22,23 @@ class ActionGroup2 extends BaseAction {
 
 	ActionResult<Wo> execute(EffectivePerson effectivePerson) throws Exception {
 		try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
-			ActionResult<Wo> result = new ActionResult<>();
-			ScriptEngine engine = ScriptFactory.newScriptEngine();
-			ScriptContext scriptContext = new SimpleScriptContext();
-			Bindings bindings = scriptContext.getBindings(ScriptContext.ENGINE_SCOPE);
-			bindings.put("data", new ArrayList<>());
-			engine.setContext(scriptContext);
-			engine.eval("var o = this.data && this.data.length;");
-			Object o = engine.eval("o;");
-			System.out.println(o.getClass());
-			return result;
+			ClockStamp.INIT("创建测试distinct代码.", "");
+			job(emc);
+			return new ActionResult<>();
 		}
 	}
 
+	private void job(EntityManagerContainer emc) throws Exception {
+		ClockStamp.STAMP("执行work的job distinct{}.", "开始");
+		EntityManager em = emc.get(Work.class);
+		CriteriaBuilder cb = em.getCriteriaBuilder();
+		CriteriaQuery<String> cq = cb.createQuery(String.class);
+		Root<Work> root = cq.from(Work.class);
+		cq.select(root.get(Work_.id)).distinct(true);
+		em.createQuery(cq).getResultList();
+		ClockStamp.STAMP("执行work的job distinct{}.", "结束");
+	}
+
 	public static class Wo extends WrapBoolean {
 	}
 

+ 17 - 0
o2server/x_query_service_processing/src/main/java/com/x/query/service/processing/jaxrs/test/TestAction.java

@@ -81,6 +81,23 @@ public class TestAction extends StandardJaxrsAction {
 		asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
 	}
 
+	@JaxrsMethodDescribe(value = "执行group.", action = ActionGroup2.class)
+	@GET
+	@Path("group1")
+	@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
+	@Consumes(MediaType.APPLICATION_JSON)
+	public void group1(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request) {
+		ActionResult<ActionGroup1.Wo> result = new ActionResult<>();
+		EffectivePerson effectivePerson = this.effectivePerson(request);
+		try {
+			result = new ActionGroup1().execute(effectivePerson);
+		} catch (Exception e) {
+			logger.error(e, effectivePerson, request, null);
+			result.error(e);
+		}
+		asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
+	}
+
 	@JaxrsMethodDescribe(value = "执行group.", action = ActionGroup2.class)
 	@GET
 	@Path("group2")

+ 23 - 0
o2server/x_query_service_processing/src/main/webapp/describe/describe.json

@@ -727,6 +727,29 @@
             }
           ]
         },
+        {
+          "name": "group1",
+          "className": "com.x.query.service.processing.jaxrs.test.ActionGroup2",
+          "description": "执行group.",
+          "type": "GET",
+          "path": "jaxrs/test/group1",
+          "contentType": "application/json",
+          "resultContentType": "application/json; charset\u003dUTF-8",
+          "useJsonElementParameter": false,
+          "useStringParameter": false,
+          "pathParameters": [],
+          "formParameters": [],
+          "queryParameters": [],
+          "ins": [],
+          "outs": [
+            {
+              "name": "value",
+              "type": "Boolean",
+              "isCollection": false,
+              "description": "布尔值."
+            }
+          ]
+        },
         {
           "name": "group2",
           "className": "com.x.query.service.processing.jaxrs.test.ActionGroup2",

+ 1 - 1
o2server/x_query_service_processing/src/main/webapp/describe/sources/com/x/query/service/processing/jaxrs/neural/Learn.java

@@ -283,7 +283,7 @@ public class Learn {
 		cq.select(root).where(p).orderBy(cb.desc(root.get(InText_.count)));
 		Integer cutoff = MapTools.getInteger(model.getPropertyMap(), Model.PROPERTY_MLP_LEARNINTEXTCUTOFFSIZE,
 				Model.DEFAULT_MLP_LEARNINTEXTCUTOFFSIZE);
-		List<InText> os = em.createQuery(cq.distinct(true)).setMaxResults(cutoff).getResultList();
+		List<InText> os = em.createQuery(cq).setMaxResults(cutoff).getResultList();
 		InTextBag inTextBag = new InTextBag(os);
 		return inTextBag;
 	}

+ 21 - 17
o2server/x_query_service_processing/src/main/webapp/describe/sources/com/x/query/service/processing/jaxrs/test/ActionGroup2.java

@@ -1,11 +1,9 @@
 package com.x.query.service.processing.jaxrs.test;
 
-import java.util.ArrayList;
-
-import javax.script.Bindings;
-import javax.script.ScriptContext;
-import javax.script.ScriptEngine;
-import javax.script.SimpleScriptContext;
+import javax.persistence.EntityManager;
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.CriteriaQuery;
+import javax.persistence.criteria.Root;
 
 import com.x.base.core.container.EntityManagerContainer;
 import com.x.base.core.container.factory.EntityManagerContainerFactory;
@@ -14,7 +12,9 @@ import com.x.base.core.project.http.EffectivePerson;
 import com.x.base.core.project.jaxrs.WrapBoolean;
 import com.x.base.core.project.logger.Logger;
 import com.x.base.core.project.logger.LoggerFactory;
-import com.x.base.core.project.script.ScriptFactory;
+import com.x.base.core.project.utils.time.ClockStamp;
+import com.x.processplatform.core.entity.content.Work;
+import com.x.processplatform.core.entity.content.Work_;
 
 class ActionGroup2 extends BaseAction {
 
@@ -22,19 +22,23 @@ class ActionGroup2 extends BaseAction {
 
 	ActionResult<Wo> execute(EffectivePerson effectivePerson) throws Exception {
 		try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
-			ActionResult<Wo> result = new ActionResult<>();
-			ScriptEngine engine = ScriptFactory.newScriptEngine();
-			ScriptContext scriptContext = new SimpleScriptContext();
-			Bindings bindings = scriptContext.getBindings(ScriptContext.ENGINE_SCOPE);
-			bindings.put("data", new ArrayList<>());
-			engine.setContext(scriptContext);
-			engine.eval("var o = this.data && this.data.length;");
-			Object o = engine.eval("o;");
-			System.out.println(o.getClass());
-			return result;
+			ClockStamp.INIT("创建测试distinct代码.", "");
+			job(emc);
+			return new ActionResult<>();
 		}
 	}
 
+	private void job(EntityManagerContainer emc) throws Exception {
+		ClockStamp.STAMP("执行work的job distinct{}.", "开始");
+		EntityManager em = emc.get(Work.class);
+		CriteriaBuilder cb = em.getCriteriaBuilder();
+		CriteriaQuery<String> cq = cb.createQuery(String.class);
+		Root<Work> root = cq.from(Work.class);
+		cq.select(root.get(Work_.id)).distinct(true);
+		em.createQuery(cq).getResultList();
+		ClockStamp.STAMP("执行work的job distinct{}.", "结束");
+	}
+
 	public static class Wo extends WrapBoolean {
 	}
 

+ 17 - 0
o2server/x_query_service_processing/src/main/webapp/describe/sources/com/x/query/service/processing/jaxrs/test/TestAction.java

@@ -81,6 +81,23 @@ public class TestAction extends StandardJaxrsAction {
 		asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
 	}
 
+	@JaxrsMethodDescribe(value = "执行group.", action = ActionGroup2.class)
+	@GET
+	@Path("group1")
+	@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
+	@Consumes(MediaType.APPLICATION_JSON)
+	public void group1(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request) {
+		ActionResult<ActionGroup1.Wo> result = new ActionResult<>();
+		EffectivePerson effectivePerson = this.effectivePerson(request);
+		try {
+			result = new ActionGroup1().execute(effectivePerson);
+		} catch (Exception e) {
+			logger.error(e, effectivePerson, request, null);
+			result.error(e);
+		}
+		asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
+	}
+
 	@JaxrsMethodDescribe(value = "执行group.", action = ActionGroup2.class)
 	@GET
 	@Path("group2")