use of com.ctrip.framework.dal.cluster.client.multihost.DefaultClusterRouteStrategyConfig in project dal by ctripcorp.
the class ClusterConfigAdapter method buildNormalClusterConfig.
private ClusterConfig buildNormalClusterConfig(DalConnectionStringConfigure configure) {
ClusterConfigWithNoVersion clusterConfig = new ClusterConfigWithNoVersion(configure.getName(), ClusterType.NORMAL, DatabaseCategory.MYSQL);
DatabaseShardConfigImpl databaseShardConfig = new DatabaseShardConfigImpl(clusterConfig, 0);
DatabaseConfigImpl databaseConfig = new DatabaseConfigImpl(databaseShardConfig);
HostAndPort hostAndPort = ConnectionStringParser.parseHostPortFromURL(configure.getConnectionUrl());
databaseConfig.setIp(hostAndPort.getHost());
databaseConfig.setPort(hostAndPort.getPort());
databaseConfig.setDbName(provider.getDbName());
databaseConfig.setUid(configure.getUserName());
databaseConfig.setPwd(configure.getPassword());
databaseShardConfig.addDatabaseConfig(databaseConfig);
clusterConfig.addDatabaseShardConfig(databaseShardConfig);
// todo-lhj make configurable RouteStrategy of
clusterConfig.setRouteStrategyConfig(new DefaultClusterRouteStrategyConfig(RouteStrategyEnum.READ_MASTER.name()));
clusterConfig.setCustomizedOption(new DefaultDalConfigCustomizedOption());
return clusterConfig;
}
use of com.ctrip.framework.dal.cluster.client.multihost.DefaultClusterRouteStrategyConfig in project dal by ctripcorp.
the class ClusterConfigAdapter method buildMultiHostClusterConfig.
private ClusterConfig buildMultiHostClusterConfig(MultiHostConnectionStringConfigure configure) {
ClusterConfigWithNoVersion clusterConfig = new ClusterConfigWithNoVersion(configure.getName(), ClusterType.NORMAL, DatabaseCategory.MYSQL);
DatabaseShardConfigImpl databaseShardConfig = new DatabaseShardConfigImpl(clusterConfig, 0);
List<HostSpec> hosts = configure.getHosts();
hosts.forEach(host -> {
DatabaseConfigImpl databaseConfig = new DatabaseConfigImpl(databaseShardConfig);
databaseConfig.setIp(host.host());
databaseConfig.setPort(host.port());
databaseConfig.setZone(host.zone());
databaseConfig.setDbName(configure.getDbName());
databaseConfig.setUid(configure.getUserName());
databaseConfig.setPwd(configure.getPassword());
databaseShardConfig.addDatabaseConfig(databaseConfig);
});
clusterConfig.addDatabaseShardConfig(databaseShardConfig);
DBModel dbModel = configure.getDbModel();
String routeStrategyName = DBModel.MGR == dbModel ? RouteStrategyEnum.WRITE_ORDERED.getAlias() : RouteStrategyEnum.WRITE_CURRENT_ZONE_FIRST.getAlias();
DefaultClusterRouteStrategyConfig routeStrategy = new DefaultClusterRouteStrategyConfig(routeStrategyName);
if (configure.getZonesPriority() != null)
routeStrategy.setProperty(MultiMasterStrategy.ZONES_PRIORITY, configure.getZonesPriority());
if (configure.getFailoverTimeMS() != null)
routeStrategy.setProperty(MultiMasterStrategy.FAILOVER_TIME_MS, String.valueOf(configure.getFailoverTimeMS()));
if (configure.getBlacklistTimeoutMS() != null)
routeStrategy.setProperty(MultiMasterStrategy.BLACKLIST_TIMEOUT_MS, String.valueOf(configure.getBlacklistTimeoutMS()));
if (configure.getFixedValidatePeriodMS() != null)
routeStrategy.setProperty(MultiMasterStrategy.FIXED_VALIDATE_PERIOD_MS, String.valueOf(configure.getFixedValidatePeriodMS()));
clusterConfig.setRouteStrategyConfig(routeStrategy);
clusterConfig.setCustomizedOption(new DefaultDalConfigCustomizedOption());
return clusterConfig;
}
use of com.ctrip.framework.dal.cluster.client.multihost.DefaultClusterRouteStrategyConfig 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.multihost.DefaultClusterRouteStrategyConfig in project dal by ctripcorp.
the class ClusterConfigXMLParser method initRouteStrategy.
protected void initRouteStrategy(ClusterConfigImpl clusterConfig) {
DefaultClusterRouteStrategyConfig routeStrategyConfig = new DefaultClusterRouteStrategyConfig(RouteStrategyEnum.READ_MASTER.name());
clusterConfig.setRouteStrategyConfig(routeStrategyConfig);
}
use of com.ctrip.framework.dal.cluster.client.multihost.DefaultClusterRouteStrategyConfig in project dal by ctripcorp.
the class ClusterConfigXMLParser method initRouteStrategy.
protected void initRouteStrategy(ClusterConfigImpl clusterConfig, DalConfigCustomizedOption customizedOption) {
DefaultClusterRouteStrategyConfig routeStrategyConfig = new DefaultClusterRouteStrategyConfig(customizedOption.getRouteStrategy());
clusterConfig.setRouteStrategyConfig(routeStrategyConfig);
}
Aggregations