use of com.linkedin.darkcluster.api.BaseDarkClusterDispatcher in project rest.li by linkedin.
the class DarkClusterStrategyFactoryImpl method createStrategy.
/**
* In the future, additional strategies can be added, and the logic here can choose the appropriate one based on the config values.
*/
private DarkClusterStrategy createStrategy(String darkClusterName, DarkClusterConfig darkClusterConfig) {
if (darkClusterConfig.hasDarkClusterStrategyPrioritizedList()) {
DarkClusterStrategyNameArray strategyList = darkClusterConfig.getDarkClusterStrategyPrioritizedList();
for (com.linkedin.d2.DarkClusterStrategyName darkClusterStrategyName : strategyList) {
switch(darkClusterStrategyName) {
case RELATIVE_TRAFFIC:
if (RelativeTrafficMultiplierDarkClusterStrategy.isValidConfig(darkClusterConfig)) {
BaseDarkClusterDispatcher baseDarkClusterDispatcher = new BaseDarkClusterDispatcherImpl(darkClusterName, _darkClusterDispatcher, _notifier, _verifierManager);
return new RelativeTrafficMultiplierDarkClusterStrategy(_sourceClusterName, darkClusterName, darkClusterConfig.getMultiplier(), baseDarkClusterDispatcher, _notifier, _facilities.getClusterInfoProvider(), _random);
}
break;
case IDENTICAL_TRAFFIC:
if (IdenticalTrafficMultiplierDarkClusterStrategy.isValidConfig(darkClusterConfig)) {
BaseDarkClusterDispatcher baseDarkClusterDispatcher = new BaseDarkClusterDispatcherImpl(darkClusterName, _darkClusterDispatcher, _notifier, _verifierManager);
return new IdenticalTrafficMultiplierDarkClusterStrategy(_sourceClusterName, darkClusterName, darkClusterConfig.getMultiplier(), baseDarkClusterDispatcher, _notifier, _facilities.getClusterInfoProvider(), _random);
}
break;
case CONSTANT_QPS:
if (_rateLimiterSupplier == null) {
LOG.error("Dark Cluster {} configured to use CONSTANT_QPS strategy, but no rate limiter provided during instantiation. " + "No Dark Cluster strategy will be used!", darkClusterName);
break;
}
if (ConstantQpsDarkClusterStrategy.isValidConfig(darkClusterConfig)) {
BaseDarkClusterDispatcher baseDarkClusterDispatcher = new BaseDarkClusterDispatcherImpl(darkClusterName, _darkClusterDispatcher, _notifier, _verifierManager);
ConstantQpsRateLimiter rateLimiter = _rateLimiterSupplier.get();
rateLimiter.setBufferCapacity(darkClusterConfig.getDispatcherMaxRequestsToBuffer());
rateLimiter.setBufferTtl(darkClusterConfig.getDispatcherBufferedRequestExpiryInSeconds(), ChronoUnit.SECONDS);
return new ConstantQpsDarkClusterStrategy(_sourceClusterName, darkClusterName, darkClusterConfig.getDispatcherOutboundTargetRate(), baseDarkClusterDispatcher, _notifier, _facilities.getClusterInfoProvider(), rateLimiter);
}
break;
default:
break;
}
}
}
return new NoOpDarkClusterStrategy();
}
Aggregations