use of com.linkedin.d2.DarkClusterStrategyName in project rest.li by linkedin.
the class DarkClustersConverter method toProperties.
@SuppressWarnings("unchecked")
public static Map<String, Object> toProperties(DarkClusterConfigMap config) {
if (config == null) {
return Collections.emptyMap();
} else {
Map<String, Object> darkProps = new HashMap<>();
for (Map.Entry<String, DarkClusterConfig> entry : config.entrySet()) {
String darkClusterName = entry.getKey();
DarkClusterConfig darkClusterConfig = entry.getValue();
Map<String, Object> prop = new HashMap<>();
if (darkClusterConfig.hasMultiplier()) {
prop.put(PropertyKeys.DARK_CLUSTER_MULTIPLIER, darkClusterConfig.getMultiplier().toString());
}
if (darkClusterConfig.hasDispatcherOutboundTargetRate()) {
prop.put(PropertyKeys.DARK_CLUSTER_OUTBOUND_TARGET_RATE, darkClusterConfig.getDispatcherOutboundTargetRate().toString());
}
if (darkClusterConfig.hasDispatcherMaxRequestsToBuffer()) {
prop.put(PropertyKeys.DARK_CLUSTER_MAX_REQUESTS_TO_BUFFER, darkClusterConfig.getDispatcherMaxRequestsToBuffer().toString());
}
if (darkClusterConfig.hasDispatcherBufferedRequestExpiryInSeconds()) {
prop.put(PropertyKeys.DARK_CLUSTER_BUFFERED_REQUEST_EXPIRY_IN_SECONDS, darkClusterConfig.getDispatcherBufferedRequestExpiryInSeconds().toString());
}
if (darkClusterConfig.hasDarkClusterStrategyPrioritizedList()) {
DarkClusterStrategyNameArray strategyNameArray = darkClusterConfig.getDarkClusterStrategyPrioritizedList();
List<String> strategyList = new ArrayList<>();
for (DarkClusterStrategyName type : strategyNameArray) {
strategyList.add(type.toString());
}
prop.put(PropertyKeys.DARK_CLUSTER_STRATEGY_LIST, strategyList);
}
if (darkClusterConfig.hasTransportClientProperties()) {
prop.put(PropertyKeys.DARK_CLUSTER_TRANSPORT_CLIENT_PROPERTIES, TransportClientPropertiesConverter.toProperties(darkClusterConfig.getTransportClientProperties()));
}
darkProps.put(darkClusterName, prop);
}
return darkProps;
}
}
use of com.linkedin.d2.DarkClusterStrategyName 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();
}
use of com.linkedin.d2.DarkClusterStrategyName in project rest.li by linkedin.
the class DarkClustersConverterTest method testBadStrategies.
@Test
public void testBadStrategies() {
Map<String, Object> props = new HashMap<>();
List<String> myStrategyList = new ArrayList<>();
myStrategyList.add("RELATIVE_TRAFFIC");
myStrategyList.add("BLAH_BLAH");
Map<String, Object> darkClusterMap = new HashMap<>();
darkClusterMap.put(PropertyKeys.DARK_CLUSTER_STRATEGY_LIST, myStrategyList);
props.put(DARK_CLUSTER_KEY, darkClusterMap);
DarkClusterConfigMap configMap = DarkClustersConverter.toConfig(props);
DarkClusterStrategyNameArray strategyList = configMap.get(DARK_CLUSTER_KEY).getDarkClusterStrategyPrioritizedList();
Assert.assertEquals(strategyList.get(0), DarkClusterStrategyName.RELATIVE_TRAFFIC, "first strategy should be RELATIVE_TRAFFIC");
// the bad strategy BLAH_BLAH gets converted to unknown on access
Assert.assertEquals(strategyList.get(1), DarkClusterStrategyName.$UNKNOWN, "second strategy should be unknown");
}
Aggregations