Search in sources :

Example 1 with DatabaseConfigImpl

use of com.ctrip.framework.dal.cluster.client.config.DatabaseConfigImpl 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;
}
Also used : DefaultClusterRouteStrategyConfig(com.ctrip.framework.dal.cluster.client.multihost.DefaultClusterRouteStrategyConfig) DatabaseShardConfigImpl(com.ctrip.framework.dal.cluster.client.config.DatabaseShardConfigImpl) DatabaseConfigImpl(com.ctrip.framework.dal.cluster.client.config.DatabaseConfigImpl)

Example 2 with DatabaseConfigImpl

use of com.ctrip.framework.dal.cluster.client.config.DatabaseConfigImpl 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;
}
Also used : DefaultClusterRouteStrategyConfig(com.ctrip.framework.dal.cluster.client.multihost.DefaultClusterRouteStrategyConfig) DatabaseShardConfigImpl(com.ctrip.framework.dal.cluster.client.config.DatabaseShardConfigImpl) DBModel(com.ctrip.platform.dal.common.enums.DBModel) DatabaseConfigImpl(com.ctrip.framework.dal.cluster.client.config.DatabaseConfigImpl) HostSpec(com.ctrip.framework.dal.cluster.client.base.HostSpec)

Example 3 with DatabaseConfigImpl

use of com.ctrip.framework.dal.cluster.client.config.DatabaseConfigImpl in project dal by ctripcorp.

the class DummyDatabaseTest method setUp.

@Before
public void setUp() throws Exception {
    clusterConfig = new ClusterConfigImpl("name", DatabaseCategory.CUSTOM, 12);
    shardConfig = new DatabaseShardConfigImpl(clusterConfig, 0);
    shardConfig.setMasterDomain(MASTER_DOMAIN);
    shardConfig.setSlaveDomain(SLAVE_DOMAIN);
    databaseConfig = new DatabaseConfigImpl(shardConfig);
    dummyDatabase = new DummyDatabase(databaseConfig);
}
Also used : DatabaseShardConfigImpl(com.ctrip.framework.dal.cluster.client.config.DatabaseShardConfigImpl) DatabaseConfigImpl(com.ctrip.framework.dal.cluster.client.config.DatabaseConfigImpl) ClusterConfigImpl(com.ctrip.framework.dal.cluster.client.config.ClusterConfigImpl) Before(org.junit.Before)

Example 4 with DatabaseConfigImpl

use of com.ctrip.framework.dal.cluster.client.config.DatabaseConfigImpl in project dal by ctripcorp.

the class ClusterDataBaseAdapterTest method setUp.

@Before
public void setUp() throws Exception {
    clusterConfig = new ClusterConfigImpl(CLUSTER_NAME, DatabaseCategory.CUSTOM, 12);
    databaseShardConfig = new DatabaseShardConfigImpl(clusterConfig, 0);
    databaseShardConfig.setMasterDomain(MASTER_DOMAIN);
    databaseShardConfig.setSlaveDomain(SLAVE_DOMAIN);
    databaseConfig = new DatabaseConfigImpl(databaseShardConfig);
    databaseShardConfig.addDatabaseConfig(databaseConfig);
    clusterConfig.addDatabaseShardConfig(databaseShardConfig);
    cluster = clusterConfig.generate();
    clusterDataBaseAdapter = new ClusterDataBaseAdapter(cluster);
}
Also used : DatabaseShardConfigImpl(com.ctrip.framework.dal.cluster.client.config.DatabaseShardConfigImpl) DatabaseConfigImpl(com.ctrip.framework.dal.cluster.client.config.DatabaseConfigImpl) ClusterConfigImpl(com.ctrip.framework.dal.cluster.client.config.ClusterConfigImpl) Before(org.junit.Before)

Aggregations

DatabaseConfigImpl (com.ctrip.framework.dal.cluster.client.config.DatabaseConfigImpl)4 DatabaseShardConfigImpl (com.ctrip.framework.dal.cluster.client.config.DatabaseShardConfigImpl)4 ClusterConfigImpl (com.ctrip.framework.dal.cluster.client.config.ClusterConfigImpl)2 DefaultClusterRouteStrategyConfig (com.ctrip.framework.dal.cluster.client.multihost.DefaultClusterRouteStrategyConfig)2 Before (org.junit.Before)2 HostSpec (com.ctrip.framework.dal.cluster.client.base.HostSpec)1 DBModel (com.ctrip.platform.dal.common.enums.DBModel)1