use of com.ctrip.framework.dal.cluster.client.exception.ClusterRuntimeException in project dal by ctripcorp.
the class ClusterConfigXMLParser method parseRouteStrategies.
private void parseRouteStrategies(ClusterConfigImpl clusterConfig, Node routeStrategiesNode) {
List<Node> routeStrategyNodes = getRouteStrategyNodes(routeStrategiesNode);
if (routeStrategyNodes.size() > 1)
throw new ClusterRuntimeException("multiple routeStrategies configured");
if (routeStrategyNodes.size() == 1) {
Node routeStrategyNode = routeStrategyNodes.get(0);
DefaultClusterRouteStrategyConfig routeStrategyConfig = new DefaultClusterRouteStrategyConfig(routeStrategyNode.getNodeName());
List<Node> propertyNodes = getChildNodes(routeStrategyNode, PROPERTY);
propertyNodes.forEach(node -> {
String propertyName = getAttribute(node, NAME);
String propertyValue = getAttribute(node, VALUE);
if (propertyName != null && propertyValue != null)
routeStrategyConfig.setProperty(propertyName, propertyValue);
});
clusterConfig.setRouteStrategyConfig(routeStrategyConfig);
}
}
use of com.ctrip.framework.dal.cluster.client.exception.ClusterRuntimeException in project dal by ctripcorp.
the class ClusterConfigXMLParser method parseDrcConfig.
private void parseDrcConfig(ClusterConfigImpl clusterConfig, Node clusterNode) throws IOException {
Node unitStrategyIdNode = getChildNode(clusterNode, UNIT_STRATEGY_ID);
if (unitStrategyIdNode != null) {
String unitStrategyIdText = unitStrategyIdNode.getTextContent();
if (!StringUtils.isEmpty(unitStrategyIdText)) {
try {
clusterConfig.setUnitStrategyId(Integer.parseInt(unitStrategyIdText));
} catch (NumberFormatException e) {
throw new ClusterRuntimeException("unitStrategyId should be a number", e);
}
}
}
Node zoneIdNode = getChildNode(clusterNode, ZONE_ID);
if (zoneIdNode != null) {
String zoneIdText = zoneIdNode.getTextContent();
if (!StringUtils.isEmpty(zoneIdText)) {
clusterConfig.setZoneId(zoneIdText);
}
}
Node customConfigNode = getChildNode(clusterNode, CUSTOM_CONFIG);
if (customConfigNode != null) {
String customConfigText = customConfigNode.getTextContent();
if (!StringUtils.isEmpty(customConfigText)) {
Properties properties = PropertiesUtils.toProperties(customConfigText);
clusterConfig.setCustomProperties(properties);
}
}
Node unitConsistencyStrategyNode = getChildNode(clusterNode, CONSISTENCY_TYPE);
// default consistency type is HIGH_AVAILABILITY
clusterConfig.setDrcConsistencyType(DrcConsistencyTypeEnum.HIGH_AVAILABILITY);
if (unitConsistencyStrategyNode != null) {
String unitConsistencyStrategyText = unitConsistencyStrategyNode.getTextContent();
clusterConfig.setDrcConsistencyType(DrcConsistencyTypeEnum.parse(unitConsistencyStrategyText));
}
}
use of com.ctrip.framework.dal.cluster.client.exception.ClusterRuntimeException in project dal by ctripcorp.
the class ClusterConfigXMLParser method buildXmlNode.
private Node buildXmlNode(String content) {
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 doc.getDocumentElement();
} catch (Throwable t) {
throw new ClusterRuntimeException("parse xml content error", t);
}
}
use of com.ctrip.framework.dal.cluster.client.exception.ClusterRuntimeException in project dal by ctripcorp.
the class ClusterConfigXMLParser method parseIdGenerators.
private void parseIdGenerators(ClusterConfigImpl clusterConfig, Node idGeneratorsNode) {
List<Node> idGeneratorNodes = getChildNodes(idGeneratorsNode, ID_GENERATOR);
if (idGeneratorNodes.size() > 1)
throw new ClusterRuntimeException("multiple idGenerators configured");
if (idGeneratorNodes.size() == 1) {
Node idGeneratorNode = idGeneratorNodes.get(0);
ClusterIdGeneratorConfig idGeneratorConfig = getIdGeneratorConfigXMLParser().parse(clusterConfig.getClusterName(), idGeneratorNode);
clusterConfig.setIdGeneratorConfig(idGeneratorConfig);
}
}
use of com.ctrip.framework.dal.cluster.client.exception.ClusterRuntimeException in project dal by ctripcorp.
the class ClusterConfigXMLParser method parseCustomStrategy.
private void parseCustomStrategy(ClusterConfigImpl clusterConfig, Node strategyNode) {
String className = getAttribute(strategyNode, CLASS);
try {
ShardStrategy strategy = instancingCustomShardStrategy(clusterConfig, className);
parseShardStrategy(clusterConfig, strategyNode, strategy);
} catch (Throwable t) {
if (!clusterConfig.getCustomizedOption().isIgnoreShardingResourceNotFound()) {
throw new ClusterRuntimeException("invalid custom strategy impl class", t);
}
}
}
Aggregations