use of io.mycat.config.util.ConfigException in project Mycat-Server by MyCATApache.
the class ConfigComparer method checkRuleConfig.
//校验前后路由规则是否一致
private void checkRuleConfig(RuleConfig oldRC, RuleConfig newRC, String schemaName, String tableName) {
if (!oldRC.getColumn().equalsIgnoreCase(newRC.getColumn())) {
throw new ConfigException(schemaName + ":" + tableName + " old & new partition column is not same!");
}
AbstractPartitionAlgorithm oldAlg = oldRC.getRuleAlgorithm();
AbstractPartitionAlgorithm newAlg = newRC.getRuleAlgorithm();
//判断路由算法前后是否一致
if (!oldAlg.getClass().isAssignableFrom(newAlg.getClass())) {
throw new ConfigException(schemaName + ":" + tableName + " old & new rule Algorithm is not same!");
}
}
use of io.mycat.config.util.ConfigException in project Mycat-Server by MyCATApache.
the class ConfigComparer method loadMigratorTable.
private void loadMigratorTable(TableConfig oldTable, TableConfig newTable, String schemaName, String tableName) {
//禁止配置非拆分表
if (oldTable == null || newTable == null) {
throw new ConfigException("please check tableFile.properties,make sure " + schemaName + ":" + tableName + " is sharding table ");
}
//忽略全局表
if (oldTable.isGlobalTable() || newTable.isGlobalTable()) {
String message = "global table: " + schemaName + ":" + tableName + " is ignore!";
System.out.println("Warn: " + message);
LOGGER.warn(message);
} else {
List<DataNode> oldDN = getDataNodes(oldTable, oldDataNodes, oldDataHosts);
List<DataNode> newDN = getDataNodes(newTable, newDataNodes, newDataHosts);
//忽略数据节点分布没有发生变化的表
if (isNeedMigrate(oldDN, newDN)) {
checkRuleConfig(oldTable.getRule(), newTable.getRule(), schemaName, tableName);
RuleConfig newRC = newTable.getRule();
TableMigrateInfo tmi = new TableMigrateInfo(schemaName, tableName, oldDN, newDN, newRC.getRuleAlgorithm(), newRC.getColumn());
migratorTables.add(tmi);
} else {
String message = schemaName + ":" + tableName + " is ignore,no need to migrate!";
LOGGER.warn(message);
System.out.println("Warn: " + message);
}
}
}
use of io.mycat.config.util.ConfigException in project Mycat-Server by MyCATApache.
the class ConfigComparer method loadTablesFile.
private void loadTablesFile() throws Exception {
Properties pro = new Properties();
if (!isAwaysUseMaster) {
dnIndexProps = loadDnIndexProps();
}
try {
pro.load(ConfigComparer.class.getResourceAsStream(TABLES_FILE));
} catch (Exception e) {
throw new ConfigException("tablesFile.properties read fail!");
}
Iterator<Entry<Object, Object>> it = pro.entrySet().iterator();
while (it.hasNext()) {
Entry<Object, Object> entry = it.next();
String schemaName = entry.getKey().toString();
String tables = entry.getValue().toString();
loadMigratorTables(schemaName, getTables(tables));
}
}
use of io.mycat.config.util.ConfigException in project Mycat-Server by MyCATApache.
the class ConfigInitializer method initDataNodes.
private Map<String, PhysicalDBNode> initDataNodes(ConfigLoader configLoader) {
Map<String, DataNodeConfig> nodeConfs = configLoader.getDataNodes();
Map<String, PhysicalDBNode> nodes = new HashMap<String, PhysicalDBNode>(nodeConfs.size());
for (DataNodeConfig conf : nodeConfs.values()) {
PhysicalDBPool pool = this.dataHosts.get(conf.getDataHost());
if (pool == null) {
throw new ConfigException("dataHost not exists " + conf.getDataHost());
}
PhysicalDBNode dataNode = new PhysicalDBNode(conf.getName(), conf.getDatabase(), pool);
nodes.put(dataNode.getName(), dataNode);
}
return nodes;
}
use of io.mycat.config.util.ConfigException in project Mycat-Server by MyCATApache.
the class XMLServerLoader method loadFirewall.
/**
* 初始载入配置获取防火墙配置,配置防火墙方法之一,一共有两处,另一处:
* @see FirewallConfig
*
* @modification 修改增加网段白名单
* @date 2016/12/8
* @modifiedBy Hash Zhang
*/
private void loadFirewall(Element root) throws IllegalAccessException, InvocationTargetException {
NodeList list = root.getElementsByTagName("host");
Map<String, List<UserConfig>> whitehost = new HashMap<>();
Map<Pattern, List<UserConfig>> whitehostMask = new HashMap<>();
for (int i = 0, n = list.getLength(); i < n; i++) {
Node node = list.item(i);
if (node instanceof Element) {
Element e = (Element) node;
String host = e.getAttribute("host").trim();
String userStr = e.getAttribute("user").trim();
if (this.firewall.existsHost(host)) {
throw new ConfigException("host duplicated : " + host);
}
String[] users = userStr.split(",");
List<UserConfig> userConfigs = new ArrayList<UserConfig>();
for (String user : users) {
UserConfig uc = this.users.get(user);
if (null == uc) {
throw new ConfigException("[user: " + user + "] doesn't exist in [host: " + host + "]");
}
if (uc.getSchemas() == null || uc.getSchemas().size() == 0) {
throw new ConfigException("[host: " + host + "] contains one root privileges user: " + user);
}
userConfigs.add(uc);
}
if (host.contains("*") || host.contains("%")) {
whitehostMask.put(FirewallConfig.getMaskPattern(host), userConfigs);
} else {
whitehost.put(host, userConfigs);
}
}
}
firewall.setWhitehost(whitehost);
firewall.setWhitehostMask(whitehostMask);
WallConfig wallConfig = new WallConfig();
NodeList blacklist = root.getElementsByTagName("blacklist");
for (int i = 0, n = blacklist.getLength(); i < n; i++) {
Node node = blacklist.item(i);
if (node instanceof Element) {
Element e = (Element) node;
String check = e.getAttribute("check");
if (null != check) {
firewall.setCheck(Boolean.parseBoolean(check));
}
Map<String, Object> props = ConfigUtil.loadElements((Element) node);
ParameterMapping.mapping(wallConfig, props);
}
}
firewall.setWallConfig(wallConfig);
firewall.init();
}
Aggregations