Search in sources :

Example 1 with ConfigException

use of com.actiontech.dble.config.util.ConfigException in project dble by actiontech.

the class ConfigInitializer method initDataNodes.

private Map<String, PhysicalDBNode> initDataNodes(SchemaLoader schemaLoader) {
    Map<String, DataNodeConfig> nodeConf = schemaLoader.getDataNodes();
    Map<String, PhysicalDBNode> nodes = new HashMap<>(nodeConf.size());
    for (DataNodeConfig conf : nodeConf.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(com.actiontech.dble.backend.datasource.PhysicalDBNode) PhysicalDBPool(com.actiontech.dble.backend.datasource.PhysicalDBPool) ConfigException(com.actiontech.dble.config.util.ConfigException)

Example 2 with ConfigException

use of com.actiontech.dble.config.util.ConfigException in project dble by actiontech.

the class ConfigInitializer method selfChecking0.

private void selfChecking0() throws ConfigException {
    // 2.schema's conf is not empty
    if (users == null || users.isEmpty()) {
        throw new ConfigException("SelfCheck### user all node is empty!");
    } else {
        for (UserConfig uc : users.values()) {
            if (uc == null) {
                throw new ConfigException("SelfCheck### users node within the item is empty!");
            }
            if (!uc.isManager()) {
                Set<String> authSchemas = uc.getSchemas();
                if (authSchemas == null) {
                    throw new ConfigException("SelfCheck### user " + uc.getName() + "referred schemas is empty!");
                }
                for (String schema : authSchemas) {
                    if (!schemas.containsKey(schema)) {
                        String errMsg = "SelfCheck###  schema " + schema + " referred by user " + uc.getName() + " is not exist!";
                        throw new ConfigException(errMsg);
                    }
                }
            }
        }
    }
    // check schema
    for (SchemaConfig sc : schemas.values()) {
        if (null == sc) {
            throw new ConfigException("SelfCheck### schema all node is empty!");
        } else {
            // check dataNode / dataHost
            if (this.dataNodes != null && this.dataHosts != null) {
                Set<String> dataNodeNames = sc.getAllDataNodes();
                for (String dataNodeName : dataNodeNames) {
                    PhysicalDBNode node = this.dataNodes.get(dataNodeName);
                    if (node == null) {
                        throw new ConfigException("SelfCheck### schema dataNode is empty!");
                    }
                }
            }
        }
    }
    deleteRedundancyConf();
    checkWriteHost();
}
Also used : PhysicalDBNode(com.actiontech.dble.backend.datasource.PhysicalDBNode) ConfigException(com.actiontech.dble.config.util.ConfigException)

Example 3 with ConfigException

use of com.actiontech.dble.config.util.ConfigException in project dble by actiontech.

the class FirewallConfigLoader method load.

public void load(Element root, XMLServerLoader xsl, boolean isLowerCaseTableNames) throws IllegalAccessException, InvocationTargetException {
    FirewallConfig firewall = xsl.getFirewall();
    Map<String, UserConfig> users = xsl.getUsers();
    NodeList list = root.getElementsByTagName("host");
    Map<String, List<UserConfig>> whitehost = 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 (firewall.existsHost(host)) {
                throw new ConfigException("host duplicated : " + host);
            }
            String[] arrayUsers = userStr.split(",");
            List<UserConfig> userConfigs = new ArrayList<>();
            for (String user : arrayUsers) {
                UserConfig uc = users.get(user);
                if (null == uc) {
                    throw new ConfigException("[user: " + user + "] doesn't exist in [host: " + host + "]");
                }
                if (!uc.isManager() && (uc.getSchemas() == null || uc.getSchemas().size() == 0)) {
                    throw new ConfigException("[host: " + host + "] contains one root privileges user: " + user);
                }
                userConfigs.add(uc);
            }
            whitehost.put(host, userConfigs);
        }
    }
    firewall.setWhitehost(whitehost);
    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.setBlackListCheck(Boolean.parseBoolean(check));
            }
            Map<String, Object> props = ConfigUtil.loadElements((Element) node);
            ParameterMapping.mapping(wallConfig, props);
        }
    }
    firewall.setWallConfig(wallConfig);
    firewall.init();
}
Also used : HashMap(java.util.HashMap) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) ConfigException(com.actiontech.dble.config.util.ConfigException) WallConfig(com.alibaba.druid.wall.WallConfig) FirewallConfig(com.actiontech.dble.config.model.FirewallConfig) UserConfig(com.actiontech.dble.config.model.UserConfig) NodeList(org.w3c.dom.NodeList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 4 with ConfigException

use of com.actiontech.dble.config.util.ConfigException in project dble by actiontech.

the class XMLRuleLoader method loadRule.

private RuleConfig loadRule(Element element) throws SQLSyntaxErrorException {
    Element columnsEle = ConfigUtil.loadElement(element, "columns");
    String column = columnsEle.getTextContent();
    if (StringUtil.isEmpty(column)) {
        throw new ConfigException("no rule column is found");
    }
    String[] columns = SplitUtil.split(column, ',', true);
    if (columns.length > 1) {
        throw new ConfigException("table rule coulmns has multi values:" + columnsEle.getTextContent());
    }
    Element algorithmEle = ConfigUtil.loadElement(element, "algorithm");
    String algorithmName = algorithmEle.getTextContent();
    if (StringUtil.isEmpty(algorithmName)) {
        throw new ConfigException("algorithm is null or empty");
    }
    AbstractPartitionAlgorithm algorithm = functions.get(algorithmName);
    if (algorithm == null) {
        throw new ConfigException("can't find function of name :" + algorithmName);
    }
    return new RuleConfig(column.toUpperCase(), algorithmName, algorithm);
}
Also used : Element(org.w3c.dom.Element) ConfigException(com.actiontech.dble.config.util.ConfigException) RuleConfig(com.actiontech.dble.config.model.rule.RuleConfig) TableRuleConfig(com.actiontech.dble.config.model.rule.TableRuleConfig)

Example 5 with ConfigException

use of com.actiontech.dble.config.util.ConfigException in project dble by actiontech.

the class XMLRuleLoader method loadFunctions.

/**
 * @param root
 * @throws ClassNotFoundException
 * @throws InstantiationException
 * @throws IllegalAccessException
 * @throws InvocationTargetException
 */
private void loadFunctions(Element root) throws ClassNotFoundException, InstantiationException, IllegalAccessException, InvocationTargetException {
    NodeList list = root.getElementsByTagName("function");
    for (int i = 0, n = list.getLength(); i < n; ++i) {
        Node node = list.item(i);
        if (node instanceof Element) {
            Element e = (Element) node;
            String name = e.getAttribute("name");
            // check if the function is duplicate
            if (functions.containsKey(name)) {
                throw new ConfigException("rule function " + name + " duplicated!");
            }
            String clazz = e.getAttribute("class");
            // reflection
            AbstractPartitionAlgorithm function = createFunction(name, clazz);
            function.setName(name);
            ParameterMapping.mapping(function, ConfigUtil.loadElements(e));
            // init for AbstractPartitionAlgorithm
            function.init();
            functions.put(name, function);
        }
    }
    setFunctionAlias();
}
Also used : NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) ConfigException(com.actiontech.dble.config.util.ConfigException)

Aggregations

ConfigException (com.actiontech.dble.config.util.ConfigException)18 Element (org.w3c.dom.Element)14 NodeList (org.w3c.dom.NodeList)10 Node (org.w3c.dom.Node)6 IOException (java.io.IOException)4 PhysicalDBNode (com.actiontech.dble.backend.datasource.PhysicalDBNode)3 TableRuleConfig (com.actiontech.dble.config.model.rule.TableRuleConfig)3 InputStream (java.io.InputStream)3 PhysicalDBPool (com.actiontech.dble.backend.datasource.PhysicalDBPool)2 UserConfig (com.actiontech.dble.config.model.UserConfig)2 RuleConfig (com.actiontech.dble.config.model.rule.RuleConfig)2 PhysicalDatasource (com.actiontech.dble.backend.datasource.PhysicalDatasource)1 FirewallConfig (com.actiontech.dble.config.model.FirewallConfig)1 SystemConfig (com.actiontech.dble.config.model.SystemConfig)1 TableTypeEnum (com.actiontech.dble.config.model.TableConfig.TableTypeEnum)1 AbstractPartitionAlgorithm (com.actiontech.dble.route.function.AbstractPartitionAlgorithm)1 WallConfig (com.alibaba.druid.wall.WallConfig)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 SQLSyntaxErrorException (java.sql.SQLSyntaxErrorException)1 ArrayList (java.util.ArrayList)1