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;
}
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();
}
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();
}
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);
}
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();
}
Aggregations