Search in sources :

Example 76 with ClusterProperties

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);
}
Also used : DarkClusterConfigMap(com.linkedin.d2.DarkClusterConfigMap) DarkClusterConfig(com.linkedin.d2.DarkClusterConfig) Test(org.testng.annotations.Test)

Example 77 with ClusterProperties

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;
}
Also used : ClusterProperties(com.linkedin.d2.balancer.properties.ClusterProperties)

Example 78 with ClusterProperties

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()) + ']');
    }
}
Also used : HashMap(java.util.HashMap) ServiceUnavailableException(com.linkedin.d2.balancer.ServiceUnavailableException) URI(java.net.URI) LoadBalancerState(com.linkedin.d2.balancer.LoadBalancerState) ServiceProperties(com.linkedin.d2.balancer.properties.ServiceProperties) PartitionAccessor(com.linkedin.d2.balancer.util.partitions.PartitionAccessor) UriProperties(com.linkedin.d2.balancer.properties.UriProperties) Ring(com.linkedin.d2.balancer.util.hashing.Ring) ClusterProperties(com.linkedin.d2.balancer.properties.ClusterProperties)

Example 79 with ClusterProperties

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);
    });
}
Also used : DarkClusterConfigMap(com.linkedin.d2.DarkClusterConfigMap) ClusterProperties(com.linkedin.d2.balancer.properties.ClusterProperties) TimeoutCallback(com.linkedin.r2.transport.http.client.TimeoutCallback)

Aggregations

ClusterProperties (com.linkedin.d2.balancer.properties.ClusterProperties)72 HashMap (java.util.HashMap)51 ServiceProperties (com.linkedin.d2.balancer.properties.ServiceProperties)49 Test (org.testng.annotations.Test)47 ArrayList (java.util.ArrayList)42 UriProperties (com.linkedin.d2.balancer.properties.UriProperties)41 URI (java.net.URI)38 Map (java.util.Map)32 PartitionData (com.linkedin.d2.balancer.properties.PartitionData)24 DegraderLoadBalancerTest (com.linkedin.d2.balancer.strategies.degrader.DegraderLoadBalancerTest)24 List (java.util.List)20 NullStateListenerCallback (com.linkedin.d2.balancer.LoadBalancerState.NullStateListenerCallback)18 LoadBalancerStrategy (com.linkedin.d2.balancer.strategies.LoadBalancerStrategy)18 None (com.linkedin.common.util.None)16 TransportClientFactory (com.linkedin.r2.transport.common.TransportClientFactory)16 FutureCallback (com.linkedin.common.callback.FutureCallback)15 HashSet (java.util.HashSet)14 DarkClusterConfigMap (com.linkedin.d2.DarkClusterConfigMap)13 RequestContext (com.linkedin.r2.message.RequestContext)13 ClusterPropertiesJsonSerializer (com.linkedin.d2.balancer.properties.ClusterPropertiesJsonSerializer)12