From 64626fd2affc51ca759fd49e3e5268ae4271b2b5 Mon Sep 17 00:00:00 2001 From: yanhuqing666 Date: Wed, 5 Jul 2017 13:28:12 +0800 Subject: [PATCH] add obfuscate --- .gitignore | 2 + Release_Note.md | 22 +- .../backend/mysql/store/fs/FilePathDisk.java | 5 +- .../java/io/mycat/cache/CacheService.java | 4 +- .../config/loader/xml/XMLRuleLoader.java | 5 +- .../config/loader/xml/XMLSchemaLoader.java | 5 +- .../config/loader/xml/XMLServerLoader.java | 5 +- .../loader/zkprocess/comm/ZkConfig.java | 3 +- .../zkprocess/parse/XmlProcessBase.java | 3 +- .../xmltozk/listen/EcachesxmlTozkLoader.java | 3 +- .../xmltozk/listen/RulesxmlTozkLoader.java | 3 +- .../xmltozk/listen/SequenceTozkLoader.java | 3 +- .../xmltozk/listen/ServerxmlTozkLoader.java | 3 +- .../zktoxml/listen/EcacheszkToxmlLoader.java | 7 +- .../zktoxml/listen/RuleszkToxmlLoader.java | 7 +- .../zktoxml/listen/SchemaszkToxmlLoader.java | 4 +- .../listen/SequenceTopropertiesLoader.java | 4 +- .../zktoxml/listen/ServerzkToxmlLoader.java | 7 +- .../io/mycat/config/model/FirewallConfig.java | 3 +- .../manager/handler/ConfFileHandler.java | 7 +- .../environment/EnvironmentInformation.java | 338 ------------------ .../route/function/AutoPartitionByLong.java | 4 +- .../route/function/PartitionByFileMap.java | 5 +- .../route/function/PartitionByPattern.java | 3 +- .../io/mycat/route/util/PropertiesUtil.java | 4 +- src/main/java/io/mycat/util/ResourceUtil.java | 21 ++ .../util/dataMigrator/ConfigComparer.java | 5 +- ushard.xml | 37 ++ 28 files changed, 131 insertions(+), 391 deletions(-) delete mode 100644 src/main/java/io/mycat/memory/environment/EnvironmentInformation.java create mode 100644 src/main/java/io/mycat/util/ResourceUtil.java diff --git a/.gitignore b/.gitignore index 3769c58e2..1e6dbfc84 100644 --- a/.gitignore +++ b/.gitignore @@ -120,3 +120,5 @@ src/main/resources/zkconf/schema.xml src/main/resources/zkconf/rule.xml conf/dnindex.properties version.txt +copyResources.bat +dependency-reduced-pom.xml \ No newline at end of file diff --git a/Release_Note.md b/Release_Note.md index 757eef3b6..3643ea9f0 100644 --- a/Release_Note.md +++ b/Release_Note.md @@ -33,16 +33,18 @@ ID= 63位二进制 (9(线程ID) +5(实例ID)+4(机房ID)+6(重复累加) +39(毫 #### 3.4 server.xml 3.4.1 mycatNodeId 改为serverNodeId -## 4.ushard分支 #117 +## 4.ushard分支 #117 +如果不需要混淆成字母类(eg:A.class),maven编译增加参数: +-Dneed.obfuscate=false ,默认为true #### 4.1 客户端登录信息 -显示ushard +显示ushard相关字样 #### 4.2 注解 -原本用mycat的请用ushard -#### 4.3 自增函数 -dbseq.sql 已经重新生成,mycat已经用ushard替换 +注解内部原本用mycat的改为ushard +#### 4.3 全局序列 +数据库方式全局序列需要的dbseq.sql 已经重新生成,mycat已经用ushard替换,表结构相关名称改变 #### 4.4 配置 ##### 4.4.1 xml的使用规约 -例如:server的根节点写法是: +mycat改为ushard ,例如:server的根节点写法是: ``` @@ -79,9 +81,11 @@ io.mycat.route.function.PartitionByFileMap(枚举方式) io.mycat.route.function.AutoPartitionByLong(数字范围) io.mycat.route.function.PartitionByDate(日期分区) io.mycat.route.function.PartitionByPattern(取模范围约束) - -#### 4.5 日志 -日志路径logs/ushard.log 里面涉及到的包名从io.mycat 改为com.actionsky.com +#### 4.5 全局表检查 +启用全局表检查时候,列名由_mycat_op_time改为_ushard_op_time +#### 4.6 日志 +日志路径logs/ushard.log。 +里面涉及到的包名从io.mycat 改为com.actionsky.com ------ diff --git a/src/main/java/io/mycat/backend/mysql/store/fs/FilePathDisk.java b/src/main/java/io/mycat/backend/mysql/store/fs/FilePathDisk.java index f2b665408..353074544 100644 --- a/src/main/java/io/mycat/backend/mysql/store/fs/FilePathDisk.java +++ b/src/main/java/io/mycat/backend/mysql/store/fs/FilePathDisk.java @@ -19,6 +19,7 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.LockSupport; import io.mycat.config.ErrorCode; +import io.mycat.util.ResourceUtil; import io.mycat.util.exception.TmpFileException; /** @@ -277,9 +278,9 @@ public class FilePathDisk extends FilePath { if (!fileName.startsWith("/")) { fileName = "/" + fileName; } - InputStream in = getClass().getResourceAsStream(fileName); + InputStream in = ResourceUtil.getResourceAsStream(fileName); if (in == null) { - in = Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName); + in = ResourceUtil.getResourceAsStreamForCurrentThread(fileName); } if (in == null) { throw new FileNotFoundException("resource " + fileName); diff --git a/src/main/java/io/mycat/cache/CacheService.java b/src/main/java/io/mycat/cache/CacheService.java index c8023285b..bb3cadec3 100644 --- a/src/main/java/io/mycat/cache/CacheService.java +++ b/src/main/java/io/mycat/cache/CacheService.java @@ -26,6 +26,7 @@ package io.mycat.cache; import io.mycat.cache.impl.EnchachePooFactory; import io.mycat.cache.impl.LevelDBCachePooFactory; import io.mycat.cache.impl.MapDBCachePooFactory; +import io.mycat.util.ResourceUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -67,8 +68,7 @@ public class CacheService { private void init(boolean isLowerCaseTableNames) throws Exception { Properties props = new Properties(); - props.load(CacheService.class - .getResourceAsStream("/cacheservice.properties")); + props.load(ResourceUtil.getResourceAsStream("/cacheservice.properties")); final String poolFactoryPref = "factory."; final String poolKeyPref = "pool."; final String layedPoolKeyPref = "layedpool."; diff --git a/src/main/java/io/mycat/config/loader/xml/XMLRuleLoader.java b/src/main/java/io/mycat/config/loader/xml/XMLRuleLoader.java index d873d2b2e..19b5d3ba0 100644 --- a/src/main/java/io/mycat/config/loader/xml/XMLRuleLoader.java +++ b/src/main/java/io/mycat/config/loader/xml/XMLRuleLoader.java @@ -32,6 +32,7 @@ import java.util.HashMap; import java.util.Map; import io.mycat.route.function.*; +import io.mycat.util.ResourceUtil; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; @@ -80,8 +81,8 @@ public class XMLRuleLoader { InputStream dtd = null; InputStream xml = null; try { - dtd = XMLRuleLoader.class.getResourceAsStream(dtdFile); - xml = XMLRuleLoader.class.getResourceAsStream(xmlFile); + dtd = ResourceUtil.getResourceAsStream(dtdFile); + xml = ResourceUtil.getResourceAsStream(xmlFile); //读取出语意树 Element root = ConfigUtil.getDocument(dtd, xml) .getDocumentElement(); diff --git a/src/main/java/io/mycat/config/loader/xml/XMLSchemaLoader.java b/src/main/java/io/mycat/config/loader/xml/XMLSchemaLoader.java index 05303af11..fb31dacb3 100644 --- a/src/main/java/io/mycat/config/loader/xml/XMLSchemaLoader.java +++ b/src/main/java/io/mycat/config/loader/xml/XMLSchemaLoader.java @@ -37,6 +37,7 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Set; +import io.mycat.util.ResourceUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.w3c.dom.Element; @@ -129,8 +130,8 @@ public class XMLSchemaLoader implements SchemaLoader { InputStream dtd = null; InputStream xml = null; try { - dtd = XMLSchemaLoader.class.getResourceAsStream(dtdFile); - xml = XMLSchemaLoader.class.getResourceAsStream(xmlFile); + dtd = ResourceUtil.getResourceAsStream(dtdFile); + xml = ResourceUtil.getResourceAsStream(xmlFile); Element root = ConfigUtil.getDocument(dtd, xml).getDocumentElement(); //先加载所有的DataHost loadDataHosts(root); diff --git a/src/main/java/io/mycat/config/loader/xml/XMLServerLoader.java b/src/main/java/io/mycat/config/loader/xml/XMLServerLoader.java index 45bb6fc21..31a7625b5 100644 --- a/src/main/java/io/mycat/config/loader/xml/XMLServerLoader.java +++ b/src/main/java/io/mycat/config/loader/xml/XMLServerLoader.java @@ -33,6 +33,7 @@ import io.mycat.config.util.ConfigException; import io.mycat.config.util.ConfigUtil; import io.mycat.config.util.ParameterMapping; import io.mycat.util.DecryptUtil; +import io.mycat.util.ResourceUtil; import io.mycat.util.SplitUtil; import org.w3c.dom.Element; import org.w3c.dom.Node; @@ -77,8 +78,8 @@ public class XMLServerLoader { InputStream dtd = null; InputStream xml = null; try { - dtd = XMLServerLoader.class.getResourceAsStream("/server.dtd"); - xml = XMLServerLoader.class.getResourceAsStream("/server.xml"); + dtd = ResourceUtil.getResourceAsStream("/server.dtd"); + xml = ResourceUtil.getResourceAsStream("/server.xml"); Element root = ConfigUtil.getDocument(dtd, xml).getDocumentElement(); //加载System标签 diff --git a/src/main/java/io/mycat/config/loader/zkprocess/comm/ZkConfig.java b/src/main/java/io/mycat/config/loader/zkprocess/comm/ZkConfig.java index 13a25f568..6968ba554 100644 --- a/src/main/java/io/mycat/config/loader/zkprocess/comm/ZkConfig.java +++ b/src/main/java/io/mycat/config/loader/zkprocess/comm/ZkConfig.java @@ -4,6 +4,7 @@ import java.io.IOException; import java.io.InputStream; import java.util.Properties; +import io.mycat.util.ResourceUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -103,7 +104,7 @@ public class ZkConfig { private static Properties LoadMyidPropersites() { Properties pros = new Properties(); - try (InputStream configIS = ZkConfig.class.getResourceAsStream(ZK_CONFIG_FILE_NAME)) { + try (InputStream configIS = ResourceUtil.getResourceAsStream(ZK_CONFIG_FILE_NAME)) { if (configIS == null) { return null; } diff --git a/src/main/java/io/mycat/config/loader/zkprocess/parse/XmlProcessBase.java b/src/main/java/io/mycat/config/loader/zkprocess/parse/XmlProcessBase.java index 32958af2b..53de5c829 100644 --- a/src/main/java/io/mycat/config/loader/zkprocess/parse/XmlProcessBase.java +++ b/src/main/java/io/mycat/config/loader/zkprocess/parse/XmlProcessBase.java @@ -23,6 +23,7 @@ import javax.xml.stream.XMLStreamReader; import javax.xml.transform.stream.StreamSource; import io.mycat.config.Versions; +import io.mycat.util.ResourceUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -185,7 +186,7 @@ public class XmlProcessBase { */ public Object baseParseXmlToBean(String fileName) throws JAXBException, XMLStreamException { // 搜索当前转化的文件 - InputStream inputStream = XmlProcessBase.class.getResourceAsStream(fileName); + InputStream inputStream = ResourceUtil.getResourceAsStream(fileName); // 如果能够搜索到文件 if (inputStream != null) { diff --git a/src/main/java/io/mycat/config/loader/zkprocess/xmltozk/listen/EcachesxmlTozkLoader.java b/src/main/java/io/mycat/config/loader/zkprocess/xmltozk/listen/EcachesxmlTozkLoader.java index aadeef954..3939c2780 100644 --- a/src/main/java/io/mycat/config/loader/zkprocess/xmltozk/listen/EcachesxmlTozkLoader.java +++ b/src/main/java/io/mycat/config/loader/zkprocess/xmltozk/listen/EcachesxmlTozkLoader.java @@ -5,6 +5,7 @@ import static com.google.common.base.Preconditions.checkNotNull; import java.io.IOException; import java.io.InputStream; +import io.mycat.util.ResourceUtil; import org.apache.curator.framework.CuratorFramework; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -139,7 +140,7 @@ public class EcachesxmlTozkLoader extends ZkMultLoader implements NotifyService String path = ZookeeperPath.ZK_LOCAL_CFG_PATH.getKey() + name; // 加载数据 - InputStream input = EcachesxmlTozkLoader.class.getResourceAsStream(path); + InputStream input = ResourceUtil.getResourceAsStream(path); checkNotNull(input, "read SeqFile file curr Path :" + path + " is null! must is not null"); diff --git a/src/main/java/io/mycat/config/loader/zkprocess/xmltozk/listen/RulesxmlTozkLoader.java b/src/main/java/io/mycat/config/loader/zkprocess/xmltozk/listen/RulesxmlTozkLoader.java index 1e4e23a04..f796e2930 100644 --- a/src/main/java/io/mycat/config/loader/zkprocess/xmltozk/listen/RulesxmlTozkLoader.java +++ b/src/main/java/io/mycat/config/loader/zkprocess/xmltozk/listen/RulesxmlTozkLoader.java @@ -7,6 +7,7 @@ import java.io.InputStream; import java.util.ArrayList; import java.util.List; +import io.mycat.util.ResourceUtil; import org.apache.curator.framework.CuratorFramework; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -175,7 +176,7 @@ public class RulesxmlTozkLoader extends ZkMultLoader implements NotifyService { String path = ZookeeperPath.ZK_LOCAL_CFG_PATH.getKey() + name; // 加载数据 - InputStream input = RulesxmlTozkLoader.class.getResourceAsStream(path); + InputStream input = ResourceUtil.getResourceAsStream(path); checkNotNull(input, "read Map file curr Path :" + path + " is null! must is not null"); diff --git a/src/main/java/io/mycat/config/loader/zkprocess/xmltozk/listen/SequenceTozkLoader.java b/src/main/java/io/mycat/config/loader/zkprocess/xmltozk/listen/SequenceTozkLoader.java index 8da3c236d..6c48ae687 100644 --- a/src/main/java/io/mycat/config/loader/zkprocess/xmltozk/listen/SequenceTozkLoader.java +++ b/src/main/java/io/mycat/config/loader/zkprocess/xmltozk/listen/SequenceTozkLoader.java @@ -3,6 +3,7 @@ package io.mycat.config.loader.zkprocess.xmltozk.listen; import java.io.IOException; import java.io.InputStream; +import io.mycat.util.ResourceUtil; import org.apache.curator.framework.CuratorFramework; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -168,7 +169,7 @@ public class SequenceTozkLoader extends ZkMultLoader implements NotifyService { String path = ZookeeperPath.ZK_LOCAL_CFG_PATH.getKey() + name; // 加载数据 - InputStream input = SequenceTozkLoader.class.getResourceAsStream(path); + InputStream input = ResourceUtil.getResourceAsStream(path); if (null != input) { diff --git a/src/main/java/io/mycat/config/loader/zkprocess/xmltozk/listen/ServerxmlTozkLoader.java b/src/main/java/io/mycat/config/loader/zkprocess/xmltozk/listen/ServerxmlTozkLoader.java index a6e09c79a..5139fb525 100644 --- a/src/main/java/io/mycat/config/loader/zkprocess/xmltozk/listen/ServerxmlTozkLoader.java +++ b/src/main/java/io/mycat/config/loader/zkprocess/xmltozk/listen/ServerxmlTozkLoader.java @@ -4,6 +4,7 @@ import java.io.IOException; import java.io.InputStream; import java.util.List; +import io.mycat.util.ResourceUtil; import org.apache.curator.framework.CuratorFramework; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -194,7 +195,7 @@ public class ServerxmlTozkLoader extends ZkMultLoader implements NotifyService { String path = ZookeeperPath.ZK_LOCAL_CFG_PATH.getKey() + name; // 加载数据 - InputStream input = SequenceTozkLoader.class.getResourceAsStream(path); + InputStream input = ResourceUtil.getResourceAsStream(path); if (null != input) { diff --git a/src/main/java/io/mycat/config/loader/zkprocess/zktoxml/listen/EcacheszkToxmlLoader.java b/src/main/java/io/mycat/config/loader/zkprocess/zktoxml/listen/EcacheszkToxmlLoader.java index 62c1cc9b1..cf7ab7639 100644 --- a/src/main/java/io/mycat/config/loader/zkprocess/zktoxml/listen/EcacheszkToxmlLoader.java +++ b/src/main/java/io/mycat/config/loader/zkprocess/zktoxml/listen/EcacheszkToxmlLoader.java @@ -7,6 +7,7 @@ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; +import io.mycat.util.ResourceUtil; import org.apache.curator.framework.CuratorFramework; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -134,8 +135,7 @@ public class EcacheszkToxmlLoader extends ZkMultLoader implements NotifyService Ehcache ehcache = parseJsonEhcacheService.parseJsonToBean(ehcacheZkDirectory.getDataValue()); - String outputPath = EcacheszkToxmlLoader.class.getClassLoader() - .getResource(ZookeeperPath.ZK_LOCAL_WRITE_PATH.getKey()).getPath(); + String outputPath = ResourceUtil.getResourcePathFromRoot(ZookeeperPath.ZK_LOCAL_WRITE_PATH.getKey()); outputPath=new File(outputPath).getPath()+File.separator; outputPath += EHCACHE_NAME; @@ -172,8 +172,7 @@ public class EcacheszkToxmlLoader extends ZkMultLoader implements NotifyService private void writeCacheservice(String name, String value) { // 加载数据 - String path = RuleszkToxmlLoader.class.getClassLoader().getResource(ZookeeperPath.ZK_LOCAL_WRITE_PATH.getKey()) - .getPath(); + String path = ResourceUtil.getResourcePathFromRoot(ZookeeperPath.ZK_LOCAL_WRITE_PATH.getKey()); checkNotNull(path, "write ecache file curr Path :" + path + " is null! must is not null"); path=new File(path).getPath()+File.separator; diff --git a/src/main/java/io/mycat/config/loader/zkprocess/zktoxml/listen/RuleszkToxmlLoader.java b/src/main/java/io/mycat/config/loader/zkprocess/zktoxml/listen/RuleszkToxmlLoader.java index 5b11eec5b..0cd040e8b 100644 --- a/src/main/java/io/mycat/config/loader/zkprocess/zktoxml/listen/RuleszkToxmlLoader.java +++ b/src/main/java/io/mycat/config/loader/zkprocess/zktoxml/listen/RuleszkToxmlLoader.java @@ -11,6 +11,7 @@ import java.util.List; import io.mycat.MycatServer; import io.mycat.manager.response.ReloadConfig; +import io.mycat.util.ResourceUtil; import org.apache.curator.framework.CuratorFramework; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -129,8 +130,7 @@ public class RuleszkToxmlLoader extends ZkMultLoader implements NotifyService { LOGGER.info("RuleszkToxmlLoader notifyProcess write mapFile is success "); // 数配制信息写入文件 - String path = RuleszkToxmlLoader.class.getClassLoader().getResource(ZookeeperPath.ZK_LOCAL_WRITE_PATH.getKey()) - .getPath(); + String path = ResourceUtil.getResourcePathFromRoot(ZookeeperPath.ZK_LOCAL_WRITE_PATH.getKey()); path=new File(path).getPath()+File.separator; path =path+WRITEPATH; @@ -244,8 +244,7 @@ public class RuleszkToxmlLoader extends ZkMultLoader implements NotifyService { private void writeMapFile(String name, String value) { // 加载数据 - String path = RuleszkToxmlLoader.class.getClassLoader().getResource(ZookeeperPath.ZK_LOCAL_WRITE_PATH.getKey()) - .getPath(); + String path = ResourceUtil.getResourcePathFromRoot(ZookeeperPath.ZK_LOCAL_WRITE_PATH.getKey()); checkNotNull(path, "write Map file curr Path :" + path + " is null! must is not null"); path=new File(path).getPath()+File.separator; diff --git a/src/main/java/io/mycat/config/loader/zkprocess/zktoxml/listen/SchemaszkToxmlLoader.java b/src/main/java/io/mycat/config/loader/zkprocess/zktoxml/listen/SchemaszkToxmlLoader.java index 3d2f42ebf..14f1144ef 100644 --- a/src/main/java/io/mycat/config/loader/zkprocess/zktoxml/listen/SchemaszkToxmlLoader.java +++ b/src/main/java/io/mycat/config/loader/zkprocess/zktoxml/listen/SchemaszkToxmlLoader.java @@ -5,6 +5,7 @@ import java.util.List; import io.mycat.MycatServer; import io.mycat.manager.response.ReloadConfig; +import io.mycat.util.ResourceUtil; import org.apache.curator.framework.CuratorFramework; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -122,8 +123,7 @@ public class SchemaszkToxmlLoader extends ZkMultLoader implements NotifyService LOGGER.info("SchemasLoader notifyProcess zk to object zk schema Object :" + schema); - String path = SchemaszkToxmlLoader.class.getClassLoader() - .getResource(ZookeeperPath.ZK_LOCAL_WRITE_PATH.getKey()).getPath(); + String path = ResourceUtil.getResourcePathFromRoot(ZookeeperPath.ZK_LOCAL_WRITE_PATH.getKey()); path=new File(path).getPath()+File.separator; path += WRITEPATH; diff --git a/src/main/java/io/mycat/config/loader/zkprocess/zktoxml/listen/SequenceTopropertiesLoader.java b/src/main/java/io/mycat/config/loader/zkprocess/zktoxml/listen/SequenceTopropertiesLoader.java index 5981ae737..980242d56 100644 --- a/src/main/java/io/mycat/config/loader/zkprocess/zktoxml/listen/SequenceTopropertiesLoader.java +++ b/src/main/java/io/mycat/config/loader/zkprocess/zktoxml/listen/SequenceTopropertiesLoader.java @@ -9,6 +9,7 @@ import java.io.IOException; import io.mycat.MycatServer; import io.mycat.manager.response.ReloadConfig; +import io.mycat.util.ResourceUtil; import org.apache.curator.framework.CuratorFramework; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -268,8 +269,7 @@ public class SequenceTopropertiesLoader extends ZkMultLoader implements NotifySe private void writeMapFile(String name, String value) { // 加载数据 - String path = RuleszkToxmlLoader.class.getClassLoader().getResource(ZookeeperPath.ZK_LOCAL_WRITE_PATH.getKey()) - .getPath(); + String path = ResourceUtil.getResourcePathFromRoot(ZookeeperPath.ZK_LOCAL_WRITE_PATH.getKey()); checkNotNull(path, "write Map file curr Path :" + path + " is null! must is not null"); diff --git a/src/main/java/io/mycat/config/loader/zkprocess/zktoxml/listen/ServerzkToxmlLoader.java b/src/main/java/io/mycat/config/loader/zkprocess/zktoxml/listen/ServerzkToxmlLoader.java index c868f8509..2b7d85dbe 100644 --- a/src/main/java/io/mycat/config/loader/zkprocess/zktoxml/listen/ServerzkToxmlLoader.java +++ b/src/main/java/io/mycat/config/loader/zkprocess/zktoxml/listen/ServerzkToxmlLoader.java @@ -11,6 +11,7 @@ import java.util.List; import io.mycat.MycatServer; import io.mycat.config.loader.zkprocess.comm.ZkConfig; import io.mycat.manager.response.ReloadConfig; +import io.mycat.util.ResourceUtil; import org.apache.curator.framework.CuratorFramework; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -138,8 +139,7 @@ public class ServerzkToxmlLoader extends ZkMultLoader implements NotifyService { LOGGER.info("ServerzkToxmlLoader notifyProcess zk to object zk server Object :" + server); // 数配制信息写入文件 - String path = ServerzkToxmlLoader.class.getClassLoader().getResource(ZookeeperPath.ZK_LOCAL_WRITE_PATH.getKey()) - .getPath(); + String path = ResourceUtil.getResourcePathFromRoot(ZookeeperPath.ZK_LOCAL_WRITE_PATH.getKey()); path=new File(path).getPath()+File.separator; path += WRITEPATH; @@ -248,8 +248,7 @@ public class ServerzkToxmlLoader extends ZkMultLoader implements NotifyService { private void writeProperties(String name, String value) { // 加载数据 - String path = RuleszkToxmlLoader.class.getClassLoader().getResource(ZookeeperPath.ZK_LOCAL_WRITE_PATH.getKey()) - .getPath(); + String path = ResourceUtil.getResourcePathFromRoot(ZookeeperPath.ZK_LOCAL_WRITE_PATH.getKey()); checkNotNull(path, "write properties curr Path :" + path + " is null! must is not null"); diff --git a/src/main/java/io/mycat/config/model/FirewallConfig.java b/src/main/java/io/mycat/config/model/FirewallConfig.java index 42ab99f4e..a0c7ccfef 100644 --- a/src/main/java/io/mycat/config/model/FirewallConfig.java +++ b/src/main/java/io/mycat/config/model/FirewallConfig.java @@ -35,6 +35,7 @@ import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; +import io.mycat.util.ResourceUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.w3c.dom.Document; @@ -200,7 +201,7 @@ public final class FirewallConfig { public InputSource resolveEntity(java.lang.String publicId, java.lang.String systemId) throws SAXException, java.io.IOException{ if (systemId.contains("server.dtd")){ //InputSource is = new InputSource(new ByteArrayInputStream("".getBytes())); - InputStream dtd = XMLServerLoader.class.getResourceAsStream("/server.dtd"); + InputStream dtd = ResourceUtil.getResourceAsStream("/server.dtd"); InputSource is = new InputSource(dtd); return is; } else { diff --git a/src/main/java/io/mycat/manager/handler/ConfFileHandler.java b/src/main/java/io/mycat/manager/handler/ConfFileHandler.java index afc4a8c4e..c9b61bc3d 100644 --- a/src/main/java/io/mycat/manager/handler/ConfFileHandler.java +++ b/src/main/java/io/mycat/manager/handler/ConfFileHandler.java @@ -39,6 +39,7 @@ import java.util.Date; import javax.xml.parsers.ParserConfigurationException; +import io.mycat.util.ResourceUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.xml.sax.SAXException; @@ -134,20 +135,20 @@ public final class ConfFileHandler { InputStream dtdStream = new ByteArrayInputStream(new byte[0]); File confDir = new File(SystemConfig.getHomePath(), "conf"); if (xmlFileName.equals("schema.xml")) { - dtdStream = MycatServer.class.getResourceAsStream("/schema.dtd"); + dtdStream = ResourceUtil.getResourceAsStream("/schema.dtd"); if (dtdStream == null) { dtdStream = new ByteArrayInputStream(readFileByBytes(new File( confDir, "schema.dtd"))); } } else if (xmlFileName.equals("server.xml")) { - dtdStream = MycatServer.class.getResourceAsStream("/server.dtd"); + dtdStream = ResourceUtil.getResourceAsStream("/server.dtd"); if (dtdStream == null) { dtdStream = new ByteArrayInputStream(readFileByBytes(new File( confDir, "server.dtd"))); } } else if (xmlFileName.equals("rule.xml")) { - dtdStream = MycatServer.class.getResourceAsStream("/rule.dtd"); + dtdStream = ResourceUtil.getResourceAsStream("/rule.dtd"); if (dtdStream == null) { dtdStream = new ByteArrayInputStream(readFileByBytes(new File( confDir, "rule.dtd"))); diff --git a/src/main/java/io/mycat/memory/environment/EnvironmentInformation.java b/src/main/java/io/mycat/memory/environment/EnvironmentInformation.java deleted file mode 100644 index 5a750eb75..000000000 --- a/src/main/java/io/mycat/memory/environment/EnvironmentInformation.java +++ /dev/null @@ -1,338 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.mycat.memory.environment; - - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.InputStream; -import java.lang.management.ManagementFactory; -import java.lang.management.OperatingSystemMXBean; -import java.lang.management.RuntimeMXBean; -import java.lang.reflect.Method; -import java.util.List; -import java.util.Properties; - -/** - * Utility class that gives access to the execution environment of the JVM, like - * the executing user, startup options, or the JVM version. - */ -public class EnvironmentInformation { - - private static final Logger LOG = LoggerFactory.getLogger(EnvironmentInformation.class); - - public static final String UNKNOWN = ""; - - /** - * Returns the version of the code as String. If version == null, then the JobManager does not run from a - * Maven build. An example is a source code checkout, compile, and run from inside an IDE. - * - * @return The version string. - */ - public static String getVersion() { - String version = EnvironmentInformation.class.getPackage().getImplementationVersion(); - return version != null ? version : UNKNOWN; - } - - /** - * Returns the code revision (commit and commit date) of Flink, as generated by the Maven builds. - * - * @return The code revision. - */ - public static RevisionInformation getRevisionInformation() { - String revision = UNKNOWN; - String commitDate = UNKNOWN; - try (InputStream propFile = EnvironmentInformation.class.getClassLoader().getResourceAsStream(".version.properties")) { - if (propFile != null) { - Properties properties = new Properties(); - properties.load(propFile); - String propRevision = properties.getProperty("git.commit.id.abbrev"); - String propCommitDate = properties.getProperty("git.commit.time"); - revision = propRevision != null ? propRevision : UNKNOWN; - commitDate = propCommitDate != null ? propCommitDate : UNKNOWN; - } - } catch (Throwable t) { - if (LOG.isDebugEnabled()) { - LOG.debug("Cannot determine code revision: Unable to read version property file.", t); - } else { - LOG.info("Cannot determine code revision: Unable to read version property file."); - } - } - - return new RevisionInformation(revision, commitDate); - } - - /** - * Gets the name of the user that is running the JVM. - * - * @return The name of the user that is running the JVM. - */ - public static String getUserRunning() { - String user = System.getProperty("user.name"); - if (user == null) { - user = UNKNOWN; - if (LOG.isDebugEnabled()) { - LOG.debug("Cannot determine user/group information for the current user."); - } - } - return user; - } - - /** - * The maximum JVM heap size, in bytes. - * - * @return The maximum JVM heap size, in bytes. - */ - public static long getMaxJvmHeapMemory() { - long maxMemory = Runtime.getRuntime().maxMemory(); - - if (maxMemory == Long.MAX_VALUE) { - // amount of free memory unknown - try { - // workaround for Oracle JDK - OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean(); - Class clazz = Class.forName("com.sun.management.OperatingSystemMXBean"); - Method method = clazz.getMethod("getTotalPhysicalMemorySize"); - maxMemory = (Long) method.invoke(operatingSystemMXBean) / 4; - } - catch (Throwable e) { - throw new RuntimeException("Could not determine the amount of free memory.\n" + - "Please set the maximum memory for the JVM, e.g. -Xmx512M for 512 megabytes."); - } - } - - return maxMemory; - } - - /** - * Gets an estimate of the size of the free heap memory. - * - * NOTE: This method is heavy-weight. It triggers a garbage collection to reduce fragmentation and get - * a better estimate at the size of free memory. It is typically more accurate than the plain version - * {@link #getSizeOfFreeHeapMemory()}. - * - * @return An estimate of the size of the free heap memory, in bytes. - */ - public static long getSizeOfFreeHeapMemoryWithDefrag() { - // trigger a garbage collection, to reduce fragmentation - System.gc(); - - return getSizeOfFreeHeapMemory(); - } - - /** - * Gets an estimate of the size of the free heap memory. The estimate may vary, depending on the current - * level of memory fragmentation and the number of dead objects. For a better (but more heavy-weight) - * estimate, use {@link #getSizeOfFreeHeapMemoryWithDefrag()}. - * - * @return An estimate of the size of the free heap memory, in bytes. - */ - public static long getSizeOfFreeHeapMemory() { - Runtime r = Runtime.getRuntime(); - long maxMemory = r.maxMemory(); - - if (maxMemory == Long.MAX_VALUE) { - // amount of free memory unknown - try { - // workaround for Oracle JDK - OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean(); - Class clazz = Class.forName("com.sun.management.OperatingSystemMXBean"); - Method method = clazz.getMethod("getTotalPhysicalMemorySize"); - maxMemory = (Long) method.invoke(operatingSystemMXBean) / 4; - } catch (Throwable e) { - throw new RuntimeException("Could not determine the amount of free memory.\n" + - "Please set the maximum memory for the JVM, e.g. -Xmx512M for 512 megabytes."); - } - } - - return maxMemory - r.totalMemory() + r.freeMemory(); - } - - /** - * Gets the version of the JVM in the form "VM_Name - Vendor - Spec/Version". - * - * @return The JVM version. - */ - public static String getJvmVersion() { - try { - final RuntimeMXBean bean = ManagementFactory.getRuntimeMXBean(); - return bean.getVmName() + " - " + bean.getVmVendor() + " - " + bean.getSpecVersion() + '/' + bean.getVmVersion(); - } - catch (Throwable t) { - return UNKNOWN; - } - } - - /** - * Gets the system parameters and environment parameters that were passed to the JVM on startup. - * - * @return The options passed to the JVM on startup. - */ - public static String getJvmStartupOptions() { - try { - final RuntimeMXBean bean = ManagementFactory.getRuntimeMXBean(); - final StringBuilder bld = new StringBuilder(); - - for (String s : bean.getInputArguments()) { - bld.append(s).append(' '); - } - - return bld.toString(); - } - catch (Throwable t) { - return UNKNOWN; - } - } - - /** - * Gets the system parameters and environment parameters that were passed to the JVM on startup. - * - * @return The options passed to the JVM on startup. - */ - public static String[] getJvmStartupOptionsArray() { - try { - RuntimeMXBean bean = ManagementFactory.getRuntimeMXBean(); - List options = bean.getInputArguments(); - return options.toArray(new String[options.size()]); - } - catch (Throwable t) { - return new String[0]; - } - } - - /** - * Gets the directory for temporary files, as returned by the JVM system property "java.io.tmpdir". - * - * @return The directory for temporary files. - */ - public static String getTemporaryFileDirectory() { - return System.getProperty("java.io.tmpdir"); - } - - /** - * Tries to retrieve the maximum number of open file handles. This method will only work on - * UNIX-based operating systems with Sun/Oracle Java versions. - * - *

If the number of max open file handles cannot be determined, this method returns {@code -1}.

- * - * @return The limit of open file handles, or {@code -1}, if the limit could not be determined. - */ - public static long getOpenFileHandlesLimit() { - Class sunBeanClass; - try { - sunBeanClass = Class.forName("com.sun.management.UnixOperatingSystemMXBean"); - } - catch (ClassNotFoundException e) { - return -1L; - } - - try { - Method fhLimitMethod = sunBeanClass.getMethod("getMaxFileDescriptorCount"); - Object result = fhLimitMethod.invoke(ManagementFactory.getOperatingSystemMXBean()); - return (Long) result; - } - catch (Throwable t) { - LOG.warn("Unexpected error when accessing file handle limit", t); - return -1L; - } - } - - /** - * Logs a information about the environment, like code revision, current user, java version, - * and JVM parameters. - * - * @param log The logger to log the information to. - * @param componentName The component name to mention in the log. - * @param commandLineArgs The arguments accompanying the starting the component. - */ - public static void logEnvironmentInfo(Logger log, String componentName, String[] commandLineArgs) { - if (log.isInfoEnabled()) { - RevisionInformation rev = getRevisionInformation(); - String version = getVersion(); - - String user = getUserRunning(); - - String jvmVersion = getJvmVersion(); - String[] options = getJvmStartupOptionsArray(); - - String javaHome = System.getenv("JAVA_HOME"); - - long maxHeapMegabytes = getMaxJvmHeapMemory() >>> 20; - - log.info("--------------------------------------------------------------------------------"); - log.info(" Starting " + componentName + " (Version: " + version + ", " - + "Rev:" + rev.commitId + ", " + "Date:" + rev.commitDate + ")"); - log.info(" Current user: " + user); - log.info(" JVM: " + jvmVersion); - log.info(" Maximum heap size: " + maxHeapMegabytes + " MiBytes"); - log.info(" JAVA_HOME: " + (javaHome == null ? "(not set)" : javaHome)); - - - if (options.length == 0) { - log.info(" JVM Options: (none)"); - } - else { - log.info(" JVM Options:"); - for (String s: options) { - log.info(" " + s); - } - } - - if (commandLineArgs == null || commandLineArgs.length == 0) { - log.info(" Program Arguments: (none)"); - } - else { - log.info(" Program Arguments:"); - for (String s: commandLineArgs) { - log.info(" " + s); - } - } - - log.info(" Classpath: " + System.getProperty("java.class.path")); - - log.info("--------------------------------------------------------------------------------"); - } - } - - // -------------------------------------------------------------------------------------------- - - /** Don't instantiate this class */ - private EnvironmentInformation() {} - - // -------------------------------------------------------------------------------------------- - - /** - * Revision information encapsulates information about the source code revision of the Flink - * code. - */ - public static class RevisionInformation { - - /** The git commit id (hash) */ - public final String commitId; - - /** The git commit date */ - public final String commitDate; - - public RevisionInformation(String commitId, String commitDate) { - this.commitId = commitId; - this.commitDate = commitDate; - } - } -} diff --git a/src/main/java/io/mycat/route/function/AutoPartitionByLong.java b/src/main/java/io/mycat/route/function/AutoPartitionByLong.java index b07fe14aa..d1fb87335 100644 --- a/src/main/java/io/mycat/route/function/AutoPartitionByLong.java +++ b/src/main/java/io/mycat/route/function/AutoPartitionByLong.java @@ -29,6 +29,7 @@ import java.io.InputStreamReader; import java.util.LinkedList; import io.mycat.config.model.rule.RuleAlgorithm; +import io.mycat.util.ResourceUtil; /** * auto partition by Long ,can be used in auto increment primary key partition @@ -137,8 +138,7 @@ public class AutoPartitionByLong extends AbstractPartitionAlgorithm implements R BufferedReader in = null; try { // FileInputStream fin = new FileInputStream(new File(fileMapPath)); - InputStream fin = this.getClass().getClassLoader() - .getResourceAsStream(mapFile); + InputStream fin = ResourceUtil.getResourceAsStreamFromRoot(mapFile); if (fin == null) { throw new RuntimeException("can't find class resource file " + mapFile); diff --git a/src/main/java/io/mycat/route/function/PartitionByFileMap.java b/src/main/java/io/mycat/route/function/PartitionByFileMap.java index 296007f18..cfba3020f 100644 --- a/src/main/java/io/mycat/route/function/PartitionByFileMap.java +++ b/src/main/java/io/mycat/route/function/PartitionByFileMap.java @@ -32,6 +32,7 @@ import java.util.Map; import java.util.Set; import io.mycat.config.model.rule.RuleAlgorithm; +import io.mycat.util.ResourceUtil; /** * @@ -114,8 +115,8 @@ public class PartitionByFileMap extends AbstractPartitionAlgorithm implements Ru BufferedReader in = null; try { // FileInputStream fin = new FileInputStream(new File(fileMapPath)); - InputStream fin = this.getClass().getClassLoader() - .getResourceAsStream(mapFile); + + InputStream fin = ResourceUtil.getResourceAsStreamFromRoot(mapFile); if (fin == null) { throw new RuntimeException("can't find class resource file " + mapFile); diff --git a/src/main/java/io/mycat/route/function/PartitionByPattern.java b/src/main/java/io/mycat/route/function/PartitionByPattern.java index dd5d3873a..87eb84161 100644 --- a/src/main/java/io/mycat/route/function/PartitionByPattern.java +++ b/src/main/java/io/mycat/route/function/PartitionByPattern.java @@ -31,6 +31,7 @@ import java.util.HashSet; import java.util.regex.Pattern; import io.mycat.config.model.rule.RuleAlgorithm; +import io.mycat.util.ResourceUtil; /** * auto partition by Long @@ -187,7 +188,7 @@ public class PartitionByPattern extends AbstractPartitionAlgorithm implements Ru BufferedReader in = null; try { // FileInputStream fin = new FileInputStream(new File(fileMapPath)); - InputStream fin = this.getClass().getClassLoader().getResourceAsStream(mapFile); + InputStream fin = ResourceUtil.getResourceAsStreamFromRoot(mapFile); if (fin == null) { throw new RuntimeException("can't find class resource file " + mapFile); } diff --git a/src/main/java/io/mycat/route/util/PropertiesUtil.java b/src/main/java/io/mycat/route/util/PropertiesUtil.java index 0f2b12413..ae3da6a42 100644 --- a/src/main/java/io/mycat/route/util/PropertiesUtil.java +++ b/src/main/java/io/mycat/route/util/PropertiesUtil.java @@ -1,5 +1,7 @@ package io.mycat.route.util; +import io.mycat.util.ResourceUtil; + import java.io.IOException; import java.io.InputStream; import java.util.Enumeration; @@ -15,7 +17,7 @@ import java.util.Properties; public class PropertiesUtil { public static Properties loadProps(String propsFile){ Properties props = new Properties(); - InputStream inp = Thread.currentThread().getContextClassLoader().getResourceAsStream(propsFile); + InputStream inp = ResourceUtil.getResourceAsStreamForCurrentThread(propsFile); if (inp == null) { throw new java.lang.RuntimeException("time sequnce properties not found " + propsFile); diff --git a/src/main/java/io/mycat/util/ResourceUtil.java b/src/main/java/io/mycat/util/ResourceUtil.java new file mode 100644 index 000000000..1361883fe --- /dev/null +++ b/src/main/java/io/mycat/util/ResourceUtil.java @@ -0,0 +1,21 @@ +package io.mycat.util; + +import java.io.InputStream; + +/** + * Created by huqing.yan on 2017/7/5. + */ +public class ResourceUtil { + public static InputStream getResourceAsStream(String name){ + return ResourceUtil.class.getResourceAsStream(name); + } + public static InputStream getResourceAsStreamForCurrentThread(String name){ + return Thread.currentThread().getContextClassLoader().getResourceAsStream(name); + } + public static String getResourcePathFromRoot(String path){ + return ResourceUtil.class.getClassLoader().getResource(path).getPath(); + } + public static InputStream getResourceAsStreamFromRoot(String path){ + return ResourceUtil.class.getClassLoader().getResourceAsStream(path); + } +} diff --git a/src/main/java/io/mycat/util/dataMigrator/ConfigComparer.java b/src/main/java/io/mycat/util/dataMigrator/ConfigComparer.java index bb39e1123..363a486c7 100644 --- a/src/main/java/io/mycat/util/dataMigrator/ConfigComparer.java +++ b/src/main/java/io/mycat/util/dataMigrator/ConfigComparer.java @@ -10,6 +10,7 @@ import java.util.Map.Entry; import java.util.Properties; import java.util.Set; +import io.mycat.util.ResourceUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -104,7 +105,7 @@ public class ConfigComparer { dnIndexProps = loadDnIndexProps(); } try{ - pro.load(ConfigComparer.class.getResourceAsStream(TABLES_FILE)); + pro.load(ResourceUtil.getResourceAsStream(TABLES_FILE)); }catch(Exception e){ throw new ConfigException("tablesFile.properties read fail!"); } @@ -242,7 +243,7 @@ public class ConfigComparer { Properties prop = new Properties(); InputStream is = null; try { - is = ConfigComparer.class.getResourceAsStream(DN_INDEX_FILE); + is = ResourceUtil.getResourceAsStream(DN_INDEX_FILE); prop.load(is); } catch (Exception e) { throw new ConfigException("please check file \"dnindex.properties\" "+e.getMessage()); diff --git a/ushard.xml b/ushard.xml index 950661039..3410cd2c1 100644 --- a/ushard.xml +++ b/ushard.xml @@ -18,6 +18,7 @@ UTF-8 + true @@ -786,6 +787,42 @@ + + + com.github.wvengen + proguard-maven-plugin + + + package + + proguard + + + + + ${need.obfuscate} + + + + + + + + + + + + + + + + ${project.build.finalName}.jar + ${project.build.finalName}.jar + + ${java.home}/lib/rt.jar + + + org.codehaus.mojo