Search in sources :

Example 16 with ConfigException

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

the class XMLSchemaLoader method checkRuleSuitTable.

/**
 * shard table datanode(2) < function count(3) and check failed
 */
private void checkRuleSuitTable(TableConfig tableConf) {
    AbstractPartitionAlgorithm function = tableConf.getRule().getRuleAlgorithm();
    int suitValue = function.suitableFor(tableConf);
    if (suitValue < 0) {
        throw new ConfigException("Illegal table conf : table [ " + tableConf.getName() + " ] rule function [ " + tableConf.getRule().getFunctionName() + " ] partition size : " + tableConf.getRule().getRuleAlgorithm().getPartitionNum() + " > table datanode size : " + tableConf.getDataNodes().size() + ", please make sure table datanode size = function partition size");
    } else if (suitValue > 0) {
        LOGGER.info("table conf : table [ {} ] rule function [ {} ] partition size : {} < table datanode size : {} , this cause some datanode to be redundant", new String[] { tableConf.getName(), tableConf.getRule().getFunctionName(), String.valueOf(tableConf.getRule().getRuleAlgorithm().getPartitionNum()), String.valueOf(tableConf.getDataNodes().size()) });
    } else {
    // table data node size == rule function partition size
    }
}
Also used : AbstractPartitionAlgorithm(com.actiontech.dble.route.function.AbstractPartitionAlgorithm) ConfigException(com.actiontech.dble.config.util.ConfigException)

Example 17 with ConfigException

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

the class XMLSchemaLoader method loadSchemas.

private void loadSchemas(Element root) {
    NodeList list = root.getElementsByTagName("schema");
    for (int i = 0, n = list.getLength(); i < n; i++) {
        Element schemaElement = (Element) list.item(i);
        String name = schemaElement.getAttribute("name");
        if (lowerCaseNames) {
            name = name.toLowerCase();
        }
        String dataNode = schemaElement.getAttribute("dataNode");
        String sqlMaxLimitStr = schemaElement.getAttribute("sqlMaxLimit");
        int sqlMaxLimit = -1;
        // sql result size limit
        if (sqlMaxLimitStr != null && !sqlMaxLimitStr.isEmpty()) {
            sqlMaxLimit = Integer.parseInt(sqlMaxLimitStr);
        }
        // check and add dataNode
        if (dataNode != null && !dataNode.isEmpty()) {
            List<String> dataNodeLst = new ArrayList<>(1);
            dataNodeLst.add(dataNode);
            checkDataNodeExists(dataNodeLst);
        } else {
            dataNode = null;
        }
        // load tables from schema
        Map<String, TableConfig> tables = loadTables(schemaElement, lowerCaseNames);
        if (schemas.containsKey(name)) {
            throw new ConfigException("schema " + name + " duplicated!");
        }
        // if schema has no default dataNode,it must contains at least one table
        if (dataNode == null && tables.size() == 0) {
            throw new ConfigException("schema " + name + " didn't config tables,so you must set dataNode property!");
        }
        SchemaConfig schemaConfig = new SchemaConfig(name, dataNode, tables, sqlMaxLimit);
        mergeFuncNodeERMap(schemaConfig);
        mergeFkERMap(schemaConfig);
        schemas.put(name, schemaConfig);
    }
    makeAllErRelations();
}
Also used : NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) ConfigException(com.actiontech.dble.config.util.ConfigException)

Example 18 with ConfigException

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

the class XMLSchemaLoader method load.

private void load(String dtdFile, String xmlFile) {
    InputStream dtd = null;
    InputStream xml = null;
    try {
        dtd = ResourceUtil.getResourceAsStream(dtdFile);
        xml = ResourceUtil.getResourceAsStream(xmlFile);
        Element root = ConfigUtil.getDocument(dtd, xml).getDocumentElement();
        loadDataHosts(root);
        loadDataNodes(root);
        loadSchemas(root);
    } catch (ConfigException e) {
        throw e;
    } catch (Exception e) {
        throw new ConfigException(e);
    } finally {
        if (dtd != null) {
            try {
                dtd.close();
            } catch (IOException e) {
            // ignore error
            }
        }
        if (xml != null) {
            try {
                xml.close();
            } catch (IOException e) {
            // ignore error
            }
        }
    }
}
Also used : InputStream(java.io.InputStream) Element(org.w3c.dom.Element) ConfigException(com.actiontech.dble.config.util.ConfigException) IOException(java.io.IOException) IOException(java.io.IOException) 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