Search in sources :

Example 11 with HostSpec

use of com.ctrip.framework.dal.cluster.client.base.HostSpec in project dal by ctripcorp.

the class CompositeStrategyTransformerTest method visit.

@Test
public void visit() {
    CompositeRoundRobinStrategy localizedAccessStrategy = (CompositeRoundRobinStrategy) strategyContext.accept(strategyTransformer);
    Assert.assertTrue(!localizedAccessStrategy.isEmpty());
    HostSpec hostSpec1 = localizedAccessStrategy.pickNode(dalHints);
    // pick from local
    Assert.assertEquals(getRequestZone(), hostSpec1.zone());
    HostSpec hostSpec2 = localizedAccessStrategy.pickNode(dalHints);
    // pick from local
    Assert.assertEquals(getRequestZone(), hostSpec2.zone());
    HostSpec hostSpec_1 = new HostSpec(SHAOY_IP1, SHAOY_PORT1, SHAOY, true);
    HostSpec hostSpec_2 = new HostSpec(SHAOY_IP2, SHAOY_PORT2, SHAOY, true);
    boolean same = (hostSpec1.equals(hostSpec_1) && hostSpec2.equals(hostSpec_2)) || (hostSpec1.equals(hostSpec_2) && hostSpec2.equals(hostSpec_1));
    Assert.assertTrue(same);
    localizedAccessStrategy.dispose();
}
Also used : HostSpec(com.ctrip.framework.dal.cluster.client.base.HostSpec) Test(org.junit.Test)

Example 12 with HostSpec

use of com.ctrip.framework.dal.cluster.client.base.HostSpec in project dal by ctripcorp.

the class ReadCurrentZoneSlavesOnlyStrategy method init.

@Override
public void init(Set<HostSpec> hostSpecs, CaseInsensitiveProperties strategyProperties) {
    super.init(hostSpecs, strategyProperties);
    for (HostSpec hostSpec : hostSpecs) {
        if (!zoneToHost.containsKey(hostSpec.getTrimLowerCaseZone())) {
            List<HostSpec> hosts = new ArrayList<>();
            hosts.add(hostSpec);
            zoneToHost.put(hostSpec.getTrimLowerCaseZone(), hosts);
        } else {
            zoneToHost.get(hostSpec.getTrimLowerCaseZone()).add(hostSpec);
        }
    }
    if (StringUtils.isTrimmedEmpty(currentZone))
        throw new DalMetadataException(ZONE_MSG_LOST);
}
Also used : DalMetadataException(com.ctrip.framework.dal.cluster.client.exception.DalMetadataException) HostSpec(com.ctrip.framework.dal.cluster.client.base.HostSpec)

Example 13 with HostSpec

use of com.ctrip.framework.dal.cluster.client.base.HostSpec in project dal by ctripcorp.

the class ReadMasterZoneSlavesFirstStrategy method pickRead.

@Override
public HostSpec pickRead(DalHints dalHints) throws HostNotExpectedException {
    HostSpec hostSpec = hintsRoute(dalHints);
    if (hostSpec != null)
        return hostSpec;
    hostSpec = pickMasterZoneSlave();
    return hostSpec == null ? pickSlaveFirst() : hostSpec;
}
Also used : HostSpec(com.ctrip.framework.dal.cluster.client.base.HostSpec)

Example 14 with HostSpec

use of com.ctrip.framework.dal.cluster.client.base.HostSpec in project dal by ctripcorp.

the class ReadSlavesFirstStrategy method init.

@Override
public void init(Set<HostSpec> hostSpecs, CaseInsensitiveProperties strategyProperties) {
    this.hostSpecs = hostSpecs;
    this.strategyProperties = strategyProperties;
    List<HostSpec> masters = new ArrayList<>();
    List<HostSpec> slaves = new ArrayList<>();
    for (HostSpec hostSpec : hostSpecs) {
        if (hostSpec.isMaster())
            masters.add(hostSpec);
        else
            slaves.add(hostSpec);
    }
    hostMap.putIfAbsent(masterRole, masters);
    hostMap.putIfAbsent(slaveRole, slaves);
}
Also used : HostSpec(com.ctrip.framework.dal.cluster.client.base.HostSpec)

Example 15 with HostSpec

use of com.ctrip.framework.dal.cluster.client.base.HostSpec in project dal by ctripcorp.

the class OBStrategy method pickNode.

@Override
public HostSpec pickNode(DalHints hints) throws HostNotExpectedException {
    HostSpec hostSpec = delegate.pickNode(hints);
    LOGGER.logEvent(CAT_LOG_TYPE, CURRENT_HOST + hostSpec.toString(), cluster);
    return hostSpec;
}
Also used : HostSpec(com.ctrip.framework.dal.cluster.client.base.HostSpec)

Aggregations

HostSpec (com.ctrip.framework.dal.cluster.client.base.HostSpec)30 Test (org.junit.Test)11 DalMetadataException (com.ctrip.framework.dal.cluster.client.exception.DalMetadataException)5 SQLException (java.sql.SQLException)5 ConnectionString (com.ctrip.framework.dal.cluster.client.database.ConnectionString)3 Database (com.ctrip.framework.dal.cluster.client.database.Database)3 DalHints (com.ctrip.platform.dal.dao.DalHints)3 HashMap (java.util.HashMap)3 DataSourceConfigure (com.ctrip.platform.dal.dao.configure.DataSourceConfigure)2 RouteStrategy (com.ctrip.platform.dal.dao.datasource.cluster.strategy.RouteStrategy)2 Connection (java.sql.Connection)2 Map (java.util.Map)2 DatabaseConfigImpl (com.ctrip.framework.dal.cluster.client.config.DatabaseConfigImpl)1 DatabaseShardConfigImpl (com.ctrip.framework.dal.cluster.client.config.DatabaseShardConfigImpl)1 CustomDataSourceFactory (com.ctrip.framework.dal.cluster.client.extended.CustomDataSourceFactory)1 ClusterRouteStrategyConfig (com.ctrip.framework.dal.cluster.client.multihost.ClusterRouteStrategyConfig)1 DefaultClusterRouteStrategyConfig (com.ctrip.framework.dal.cluster.client.multihost.DefaultClusterRouteStrategyConfig)1 ReadCurrentZoneSlavesFirstStrategyTest (com.ctrip.framework.dal.cluster.client.shard.read.ReadCurrentZoneSlavesFirstStrategyTest)1 ReadCurrentZoneSlavesFirstStrategyTest.produceHostSpec (com.ctrip.framework.dal.cluster.client.shard.read.ReadCurrentZoneSlavesFirstStrategyTest.produceHostSpec)1 CaseInsensitiveProperties (com.ctrip.framework.dal.cluster.client.util.CaseInsensitiveProperties)1