use of com.ctrip.framework.dal.cluster.client.exception.ClusterConfigException in project dal by ctripcorp.
the class DefaultIdGeneratorConfigXMLParser method parse.
private ClusterIdGeneratorConfig parse(String clusterName, Document doc) {
Element root = doc.getDocumentElement();
if (root == null || !ClusterConfigXMLConstants.ID_GENERATORS.equalsIgnoreCase(root.getTagName()))
throw new ClusterConfigException("root element should be <IdGenerators>");
List<Node> idGeneratorNodes = getChildNodes(root, ID_GENERATOR);
if (idGeneratorNodes.size() > 1)
throw new DalRuntimeException("the count of <IdGenerator> nodes should be only one");
if (idGeneratorNodes.size() == 0)
throw new DalRuntimeException("<IdGenerator> node does not exist");
return parse(clusterName, idGeneratorNodes.get(0));
}
use of com.ctrip.framework.dal.cluster.client.exception.ClusterConfigException in project dal by ctripcorp.
the class ClusterConfigXMLParser method parse.
@Override
public ClusterConfig parse(String content, DalConfigCustomizedOption customizedOption) {
StringReader reader = new StringReader(content);
InputSource source = new InputSource(reader);
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
Document doc = factory.newDocumentBuilder().parse(source);
return parse(doc, customizedOption);
} catch (Throwable t) {
throw new ClusterConfigException("parse cluster config error", t);
}
}
use of com.ctrip.framework.dal.cluster.client.exception.ClusterConfigException in project dal by ctripcorp.
the class ClusterConfigImpl method setDefaultStrategy.
public void setDefaultStrategy(ShardStrategy shardStrategy) {
if (shardStrategy == null)
return;
if (defaultShardStrategy != null)
throw new ClusterConfigException("default shard strategy already defined");
defaultShardStrategy = shardStrategy;
addShardStrategy(shardStrategy);
}
use of com.ctrip.framework.dal.cluster.client.exception.ClusterConfigException in project dal by ctripcorp.
the class ClusterConfigXMLParser method parse.
private ClusterConfig parse(Document doc, DalConfigCustomizedOption customizedOption) throws IOException {
Element root = doc.getDocumentElement();
if (root == null || !DAL.equalsIgnoreCase(root.getTagName()))
throw new ClusterConfigException("root element should be <DAL>");
Node clusterNode = getChildNode(root, CLUSTER);
if (clusterNode == null)
throw new ClusterConfigException("cluster element not found");
return parseCluster(clusterNode, customizedOption);
}
use of com.ctrip.framework.dal.cluster.client.exception.ClusterConfigException in project dal by ctripcorp.
the class ClusterConfigXMLParser method parseCluster.
private ClusterConfig parseCluster(Node clusterNode, DalConfigCustomizedOption customizedOption) throws IOException {
String name = getAttribute(clusterNode, NAME);
if (StringUtils.isEmpty(name))
throw new ClusterConfigException("cluster name undefined");
ClusterType clusterType = ClusterType.NORMAL;
String clusterTypeText = getAttribute(clusterNode, TYPE);
if (!StringUtils.isEmpty(clusterTypeText))
clusterType = ClusterType.parse(clusterTypeText);
DatabaseCategory dbCategory = DatabaseCategory.parse(getAttribute(clusterNode, DB_CATEGORY));
int version = Integer.parseInt(getAttribute(clusterNode, VERSION));
ClusterConfigImpl clusterConfig = new ClusterConfigImpl(name, clusterType, dbCategory, version);
clusterConfig.setCustomizedOption(customizedOption);
Node databaseShardsNode = getChildNode(clusterNode, DATABASE_SHARDS);
if (databaseShardsNode != null) {
List<Node> databaseShardNodes = getChildNodes(databaseShardsNode, DATABASE_SHARD);
for (Node databaseShardNode : databaseShardNodes) parseDatabaseShard(clusterConfig, databaseShardNode);
}
Node shardStrategiesNode = getChildNode(clusterNode, SHARD_STRATEGIES);
if (shardStrategiesNode != null)
parseShardStrategies(clusterConfig, shardStrategiesNode);
Node idGeneratorsNode = getChildNode(clusterNode, ID_GENERATORS);
if (idGeneratorsNode != null)
parseIdGenerators(clusterConfig, idGeneratorsNode);
Node routeStrategiesNode = getChildNode(clusterNode, ROUTE_STRATEGIES);
if (!StringUtils.isEmpty(customizedOption.getRouteStrategy())) {
initRouteStrategy(clusterConfig, customizedOption);
} else if (routeStrategiesNode != null)
parseRouteStrategies(clusterConfig, routeStrategiesNode);
else
initRouteStrategy(clusterConfig);
parseDrcConfig(clusterConfig, clusterNode);
return clusterConfig;
}
Aggregations