use of com.linkedin.d2.balancer.properties.ClusterProperties 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.balancer.properties.ClusterProperties in project rest.li by linkedin.
the class ClusterAwareTransportClient method getValidator.
/**
* Since the validator has validationStrings build in, the only time it needs to update is when the validationStrings
* change. So we always use the cached validator unless the clusterProperties change. This avoid repeatedly creating
* new sslSessionValidator object.
*/
private SslSessionValidator getValidator() {
ClusterInfoItem clusterInfoItem = _clusterInfo.get(_clusterName);
if (clusterInfoItem == null || clusterInfoItem.getClusterPropertiesItem() == null) {
return null;
}
long cachedVersion = _cachedClusterVersion.get();
long currentVersion = clusterInfoItem.getClusterPropertiesItem().getVersion();
if (currentVersion > cachedVersion && _cachedClusterVersion.updateAndGet(prev -> clusterInfoItem.getClusterPropertiesItem().getVersion()) > cachedVersion) {
ClusterProperties clusterProperties = clusterInfoItem.getClusterPropertiesItem().getProperty();
if (clusterProperties != null) {
_cachedSslSessionValidator = _sslSessionValidatorFactory.getSessionValidator(clusterProperties.getSslSessionValidationStrings());
}
}
return _cachedSslSessionValidator;
}
use of com.linkedin.d2.balancer.properties.ClusterProperties in project rest.li by linkedin.
the class SimpleLoadBalancer method getRings.
public Map<Integer, Ring<URI>> getRings(URI serviceUri) throws ServiceUnavailableException {
ServiceProperties service = listenToServiceAndCluster(serviceUri);
String serviceName = service.getServiceName();
String clusterName = service.getClusterName();
ClusterProperties cluster = getClusterProperties(serviceName, clusterName);
LoadBalancerStateItem<UriProperties> uriItem = getUriItem(serviceName, clusterName, cluster);
UriProperties uris = uriItem.getProperty();
List<LoadBalancerState.SchemeStrategyPair> orderedStrategies = _state.getStrategiesForService(serviceName, service.getPrioritizedSchemes());
if (!orderedStrategies.isEmpty()) {
final PartitionAccessor accessor = getPartitionAccessor(serviceName, clusterName);
int maxPartitionId = accessor.getMaxPartitionId();
Map<Integer, Ring<URI>> ringMap = new HashMap<>((maxPartitionId + 1) * 2);
for (int partitionId = 0; partitionId <= maxPartitionId; partitionId++) {
for (LoadBalancerState.SchemeStrategyPair pair : orderedStrategies) {
TrackerClientSubsetItem subsetItem = getPotentialClients(serviceName, service, cluster, uris, pair.getScheme(), partitionId, uriItem.getVersion());
Ring<URI> ring = pair.getStrategy().getRing(uriItem.getVersion(), partitionId, subsetItem.getWeightedSubset(), subsetItem.shouldForceUpdate());
// ring will never be null; it can be empty
ringMap.put(partitionId, ring);
if (!ring.isEmpty()) {
// don't fallback to the next strategy if there are already hosts in the current one
break;
}
}
}
return ringMap;
} else {
throw new ServiceUnavailableException(serviceName, "PEGA_1003. Unable to find a load balancer strategy" + "Server Schemes: [" + String.join(", ", service.getPrioritizedSchemes()) + ']');
}
}
use of com.linkedin.d2.balancer.properties.ClusterProperties in project rest.li by linkedin.
the class SimpleLoadBalancer method getDarkClusterConfigMap.
@Override
public void getDarkClusterConfigMap(String clusterName, Callback<DarkClusterConfigMap> callback) {
Callback<DarkClusterConfigMap> wrappedCallback = new TimeoutCallback<>(_executor, _timeout, _unit, callback);
_state.listenToCluster(clusterName, (type, name) -> {
ClusterProperties clusterProperties = _state.getClusterProperties(clusterName).getProperty();
DarkClusterConfigMap darkClusterConfigMap = clusterProperties != null ? clusterProperties.accessDarkClusters() : new DarkClusterConfigMap();
wrappedCallback.onSuccess(darkClusterConfigMap);
});
}
Aggregations