use of com.linkedin.d2.DarkClusterConfig 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.DarkClusterConfig in project rest.li by linkedin.
the class MockClusterInfoProvider method addDarkClusterConfig.
/**
* add the ability to add a dark cluster to a source cluster's darkClusterConfigMap
*/
void addDarkClusterConfig(String sourceClusterName, String darkClusterName, DarkClusterConfig darkClusterConfig) {
DarkClusterConfigMap darkClusterConfigMap = (lookupMap.containsKey(sourceClusterName)) ? lookupMap.get(sourceClusterName) : new DarkClusterConfigMap();
darkClusterConfigMap.put(darkClusterName, darkClusterConfig);
lookupMap.put(sourceClusterName, darkClusterConfigMap);
}
use of com.linkedin.d2.DarkClusterConfig in project rest.li by linkedin.
the class DarkClustersConverter method toConfig.
public static DarkClusterConfigMap toConfig(Map<String, Object> properties) {
DarkClusterConfigMap configMap = new DarkClusterConfigMap();
for (Map.Entry<String, Object> entry : properties.entrySet()) {
String darkClusterName = entry.getKey();
DarkClusterConfig darkClusterConfig = new DarkClusterConfig();
@SuppressWarnings("unchecked") Map<String, Object> props = (Map<String, Object>) entry.getValue();
if (props.containsKey(PropertyKeys.DARK_CLUSTER_MULTIPLIER)) {
darkClusterConfig.setMultiplier(PropertyUtil.coerce(props.get(PropertyKeys.DARK_CLUSTER_MULTIPLIER), Float.class));
} else {
// to maintain backwards compatibility with previously ser/de, set the default on deserialization
darkClusterConfig.setMultiplier(DARK_CLUSTER_DEFAULT_MULTIPLIER);
}
if (props.containsKey(PropertyKeys.DARK_CLUSTER_OUTBOUND_TARGET_RATE)) {
darkClusterConfig.setDispatcherOutboundTargetRate(PropertyUtil.coerce(props.get(PropertyKeys.DARK_CLUSTER_OUTBOUND_TARGET_RATE), Float.class));
} else {
darkClusterConfig.setDispatcherOutboundTargetRate(DARK_CLUSTER_DEFAULT_TARGET_RATE);
}
if (props.containsKey(PropertyKeys.DARK_CLUSTER_MAX_REQUESTS_TO_BUFFER)) {
darkClusterConfig.setDispatcherMaxRequestsToBuffer(PropertyUtil.coerce(props.get(PropertyKeys.DARK_CLUSTER_MAX_REQUESTS_TO_BUFFER), Integer.class));
} else {
darkClusterConfig.setDispatcherMaxRequestsToBuffer(DARK_CLUSTER_DEFAULT_MAX_REQUESTS_TO_BUFFER);
}
if (props.containsKey(PropertyKeys.DARK_CLUSTER_BUFFERED_REQUEST_EXPIRY_IN_SECONDS)) {
darkClusterConfig.setDispatcherBufferedRequestExpiryInSeconds(PropertyUtil.coerce(props.get(PropertyKeys.DARK_CLUSTER_BUFFERED_REQUEST_EXPIRY_IN_SECONDS), Integer.class));
} else {
darkClusterConfig.setDispatcherBufferedRequestExpiryInSeconds(DARK_CLUSTER_DEFAULT_BUFFERED_REQUEST_EXPIRY_IN_SECONDS);
}
if (props.containsKey(PropertyKeys.DARK_CLUSTER_STRATEGY_LIST)) {
DataList dataList = new DataList();
@SuppressWarnings("unchecked") List<String> strategyList = (List<String>) props.get(PropertyKeys.DARK_CLUSTER_STRATEGY_LIST);
dataList.addAll(strategyList);
DarkClusterStrategyNameArray darkClusterStrategyNameArray = new DarkClusterStrategyNameArray(dataList);
darkClusterConfig.setDarkClusterStrategyPrioritizedList(darkClusterStrategyNameArray);
}
if (props.containsKey(PropertyKeys.DARK_CLUSTER_TRANSPORT_CLIENT_PROPERTIES)) {
@SuppressWarnings("unchecked") D2TransportClientProperties transportClientProperties = TransportClientPropertiesConverter.toConfig((Map<String, Object>) props.get(PropertyKeys.DARK_CLUSTER_TRANSPORT_CLIENT_PROPERTIES));
darkClusterConfig.setTransportClientProperties(transportClientProperties);
}
configMap.put(darkClusterName, darkClusterConfig);
}
return configMap;
}
use of com.linkedin.d2.DarkClusterConfig in project rest.li by linkedin.
the class ClusterPropertiesSerializerTest method test2DarkClusterJsonSerializer.
@Test
public void test2DarkClusterJsonSerializer() throws PropertySerializationException {
ClusterPropertiesJsonSerializer jsonSerializer = new ClusterPropertiesJsonSerializer();
DarkClusterConfig darkCluster1 = new DarkClusterConfig().setMultiplier(1.5f).setDispatcherBufferedRequestExpiryInSeconds(10).setDispatcherMaxRequestsToBuffer(100).setDispatcherOutboundTargetRate(50);
DarkClusterConfigMap darkClusterConfigMap = new DarkClusterConfigMap();
darkClusterConfigMap.put(DARK_CLUSTER1_KEY, darkCluster1);
DarkClusterConfig darkCluster2 = new DarkClusterConfig().setDispatcherBufferedRequestExpiryInSeconds(10).setDispatcherMaxRequestsToBuffer(100).setDispatcherOutboundTargetRate(50).setMultiplier(0);
darkClusterConfigMap.put(DARK_CLUSTER2_KEY, darkCluster2);
ClusterProperties property = new ClusterProperties("test", new ArrayList<>(), new HashMap<>(), new HashSet<>(), NullPartitionProperties.getInstance(), Arrays.asList("principal1", "principal2"), DarkClustersConverter.toProperties(darkClusterConfigMap), false);
assertEquals(jsonSerializer.fromBytes(jsonSerializer.toBytes(property)), property);
}
use of com.linkedin.d2.DarkClusterConfig in project rest.li by linkedin.
the class DarkClustersConverterTest method testDarkClustersConverterDefaults.
@Test
public void testDarkClustersConverterDefaults() {
DarkClusterConfigMap configMap = new DarkClusterConfigMap();
DarkClusterConfig config = new DarkClusterConfig();
configMap.put(DARK_CLUSTER_KEY, config);
DarkClusterConfig resultConfig = DarkClustersConverter.toConfig(DarkClustersConverter.toProperties(configMap)).get(DARK_CLUSTER_KEY);
Assert.assertEquals(resultConfig.getMultiplier(), DARK_CLUSTER_DEFAULT_MULTIPLIER);
Assert.assertEquals(resultConfig.getDispatcherOutboundTargetRate(), DARK_CLUSTER_DEFAULT_TARGET_RATE);
Assert.assertEquals((int) resultConfig.getDispatcherMaxRequestsToBuffer(), DARK_CLUSTER_DEFAULT_MAX_REQUESTS_TO_BUFFER);
Assert.assertEquals((int) resultConfig.getDispatcherBufferedRequestExpiryInSeconds(), DARK_CLUSTER_DEFAULT_BUFFERED_REQUEST_EXPIRY_IN_SECONDS);
Assert.assertEquals(resultConfig.getDarkClusterStrategyPrioritizedList().size(), 1, "default strategy list should be size 1");
Assert.assertFalse(resultConfig.hasTransportClientProperties(), "default shouldn't have transportProperties");
}
Aggregations