mirror of
https://github.com/actiontech/dble.git
synced 2026-01-08 05:40:15 -06:00
add obfuscate
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -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
|
||||
@@ -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的根节点写法是:
|
||||
|
||||
```
|
||||
<!DOCTYPE ushard:server SYSTEM "server.dtd">
|
||||
@@ -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
|
||||
|
||||
------
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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.";
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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标签
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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");
|
||||
|
||||
|
||||
@@ -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");
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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");
|
||||
|
||||
|
||||
@@ -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");
|
||||
|
||||
|
||||
@@ -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("<?xml version=\"1.0\" encoding=\"UTF-8\"?>".getBytes()));
|
||||
InputStream dtd = XMLServerLoader.class.getResourceAsStream("/server.dtd");
|
||||
InputStream dtd = ResourceUtil.getResourceAsStream("/server.dtd");
|
||||
InputSource is = new InputSource(dtd);
|
||||
return is;
|
||||
} else {
|
||||
|
||||
@@ -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")));
|
||||
|
||||
@@ -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 = "<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<String> 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.
|
||||
*
|
||||
* <p>If the number of max open file handles cannot be determined, this method returns {@code -1}.</p>
|
||||
*
|
||||
* @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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
21
src/main/java/io/mycat/util/ResourceUtil.java
Normal file
21
src/main/java/io/mycat/util/ResourceUtil.java
Normal file
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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());
|
||||
|
||||
37
ushard.xml
37
ushard.xml
@@ -18,6 +18,7 @@
|
||||
<project.build.sourceEncoding>
|
||||
UTF-8
|
||||
</project.build.sourceEncoding>
|
||||
<need.obfuscate>true</need.obfuscate>
|
||||
</properties>
|
||||
<repositories>
|
||||
<repository>
|
||||
@@ -786,6 +787,42 @@
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>com.github.wvengen</groupId>
|
||||
<artifactId>proguard-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>proguard</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<obfuscate>${need.obfuscate}</obfuscate>
|
||||
<options>
|
||||
<option>-ignorewarnings</option> <!--忽略所有告警-->
|
||||
<option>-dontshrink</option> <!--不做 shrink -->
|
||||
<option>-dontoptimize</option> <!--不做 optimize -->
|
||||
<option>-dontskipnonpubliclibraryclasses</option>
|
||||
<option>-dontskipnonpubliclibraryclassmembers</option>
|
||||
<option>-keep class **.package-info</option><!--保持包注解类-->
|
||||
<option>-keepattributes Signature</option><!--JAXB NEED-->
|
||||
<option>-keepattributes SourceFile,LineNumberTable,*Annotation*</option><!--保持源码名与行号-->
|
||||
<option>-keepclassmembers enum com.actionsky.ushard.**{ *;}</option><!--保持枚举中的名子,确保枚举 valueOf 可以使用-->
|
||||
<option>-keep class com.actionsky.ushard.UshardStartup{*;}</option><!--启动类-->
|
||||
<option>-keep class com.actionsky.ushard.util.ResourceUtil{*;}</option><!--外部资源加载类-->
|
||||
<option>-keep class com.actionsky.ushard.route.function.**{*;}</option><!--算法加载-->
|
||||
<option>-keep class com.actionsky.ushard.config.model.SystemConfig{*;}</option><!--配置类-->
|
||||
</options>
|
||||
<injar>${project.build.finalName}.jar</injar>
|
||||
<outjar>${project.build.finalName}.jar</outjar>
|
||||
<libs>
|
||||
<lib>${java.home}/lib/rt.jar</lib>
|
||||
</libs>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<!-- -->
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
|
||||
Reference in New Issue
Block a user