Search in sources :

Example 16 with ConfigException

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!");
    }
}
Also used : AbstractPartitionAlgorithm(io.mycat.route.function.AbstractPartitionAlgorithm) ConfigException(io.mycat.config.util.ConfigException)

Example 17 with ConfigException

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);
        }
    }
}
Also used : ConfigException(io.mycat.config.util.ConfigException) RuleConfig(io.mycat.config.model.rule.RuleConfig)

Example 18 with ConfigException

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));
    }
}
Also used : Entry(java.util.Map.Entry) ConfigException(io.mycat.config.util.ConfigException) Properties(java.util.Properties) IOException(java.io.IOException) ConfigException(io.mycat.config.util.ConfigException)

Example 19 with ConfigException

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;
}
Also used : PhysicalDBNode(io.mycat.backend.datasource.PhysicalDBNode) HashMap(java.util.HashMap) PhysicalDBPool(io.mycat.backend.datasource.PhysicalDBPool) ConfigException(io.mycat.config.util.ConfigException) DataNodeConfig(io.mycat.config.model.DataNodeConfig)

Example 20 with ConfigException

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();
}
Also used : Pattern(java.util.regex.Pattern) HashMap(java.util.HashMap) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) ConfigException(io.mycat.config.util.ConfigException) WallConfig(com.alibaba.druid.wall.WallConfig) UserConfig(io.mycat.config.model.UserConfig) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) List(java.util.List)

Aggregations

ConfigException (io.mycat.config.util.ConfigException)30 Element (org.w3c.dom.Element)16 NodeList (org.w3c.dom.NodeList)12 IOException (java.io.IOException)9 Node (org.w3c.dom.Node)8 HashMap (java.util.HashMap)5 TableConfig (io.mycat.config.model.TableConfig)4 RuleConfig (io.mycat.config.model.rule.RuleConfig)4 AbstractPartitionAlgorithm (io.mycat.route.function.AbstractPartitionAlgorithm)4 InputStream (java.io.InputStream)4 PhysicalDatasource (io.mycat.backend.datasource.PhysicalDatasource)3 DataNodeConfig (io.mycat.config.model.DataNodeConfig)3 TableRuleConfig (io.mycat.config.model.rule.TableRuleConfig)3 PhysicalDBNode (io.mycat.backend.datasource.PhysicalDBNode)2 PhysicalDBPool (io.mycat.backend.datasource.PhysicalDBPool)2 JDBCDatasource (io.mycat.backend.jdbc.JDBCDatasource)2 MySQLDataSource (io.mycat.backend.mysql.nio.MySQLDataSource)2 XMLSchemaLoader (io.mycat.config.loader.xml.XMLSchemaLoader)2 DBHostConfig (io.mycat.config.model.DBHostConfig)2 DataHostConfig (io.mycat.config.model.DataHostConfig)2