Search in sources :

Example 1 with ClusterRuntimeException

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);
    }
}
Also used : DefaultClusterRouteStrategyConfig(com.ctrip.framework.dal.cluster.client.multihost.DefaultClusterRouteStrategyConfig) ClusterRuntimeException(com.ctrip.framework.dal.cluster.client.exception.ClusterRuntimeException)

Example 2 with ClusterRuntimeException

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));
    }
}
Also used : ClusterRuntimeException(com.ctrip.framework.dal.cluster.client.exception.ClusterRuntimeException) Properties(java.util.Properties)

Example 3 with ClusterRuntimeException

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);
    }
}
Also used : InputSource(org.xml.sax.InputSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) StringReader(java.io.StringReader) ClusterRuntimeException(com.ctrip.framework.dal.cluster.client.exception.ClusterRuntimeException)

Example 4 with ClusterRuntimeException

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);
    }
}
Also used : ClusterIdGeneratorConfig(com.ctrip.framework.dal.cluster.client.sharding.idgen.ClusterIdGeneratorConfig) ClusterRuntimeException(com.ctrip.framework.dal.cluster.client.exception.ClusterRuntimeException)

Example 5 with ClusterRuntimeException

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);
        }
    }
}
Also used : ShardStrategy(com.ctrip.framework.dal.cluster.client.sharding.strategy.ShardStrategy) ModShardStrategy(com.ctrip.framework.dal.cluster.client.sharding.strategy.ModShardStrategy) ClusterRuntimeException(com.ctrip.framework.dal.cluster.client.exception.ClusterRuntimeException)

Aggregations

ClusterRuntimeException (com.ctrip.framework.dal.cluster.client.exception.ClusterRuntimeException)7 PropertyAccessor (com.ctrip.framework.dal.cluster.client.base.PropertyAccessor)1 DefaultClusterRouteStrategyConfig (com.ctrip.framework.dal.cluster.client.multihost.DefaultClusterRouteStrategyConfig)1 ClusterIdGeneratorConfig (com.ctrip.framework.dal.cluster.client.sharding.idgen.ClusterIdGeneratorConfig)1 ModShardStrategy (com.ctrip.framework.dal.cluster.client.sharding.strategy.ModShardStrategy)1 ShardStrategy (com.ctrip.framework.dal.cluster.client.sharding.strategy.ShardStrategy)1 StringReader (java.io.StringReader)1 HashSet (java.util.HashSet)1 Properties (java.util.Properties)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 InputSource (org.xml.sax.InputSource)1