Search in sources :

Example 1 with BackupRequestsStrategyFromConfig

use of com.linkedin.d2.backuprequests.BackupRequestsStrategyFromConfig in project rest.li by linkedin.

the class BackupRequestsClient method getStrategyAfterUpdate.

/*private*/
Optional<TrackingBackupRequestsStrategy> getStrategyAfterUpdate(final String serviceName, final String operation) {
    Map<String, BackupRequestsStrategyFromConfig> strategiesForOperation = _strategies.get(serviceName);
    if (strategiesForOperation != null) {
        BackupRequestsStrategyFromConfig backupRequestsStrategyFromConfig = strategiesForOperation.get(operation);
        if (backupRequestsStrategyFromConfig != null) {
            return backupRequestsStrategyFromConfig.getStrategy();
        }
    }
    LOG.debug("No backup requests strategy found");
    return Optional.empty();
}
Also used : ByteString(com.linkedin.data.ByteString) BackupRequestsStrategyFromConfig(com.linkedin.d2.backuprequests.BackupRequestsStrategyFromConfig)

Example 2 with BackupRequestsStrategyFromConfig

use of com.linkedin.d2.backuprequests.BackupRequestsStrategyFromConfig in project rest.li by linkedin.

the class BackupRequestsClient method updateBackupRequestsStrategyFromConfig.

private BackupRequestsStrategyFromConfig updateBackupRequestsStrategyFromConfig(String serviceName, String operation, BackupRequestsStrategyFromConfig existing, Map<String, Object> config) {
    if (existing == null) {
        BackupRequestsStrategyFromConfig newOne = new BackupRequestsStrategyFromConfig(config);
        newOne.getStrategy().ifPresent(statsProvider -> _statsConsumer.ifPresent(consumer -> consumer.addStatsProvider(serviceName, operation, statsProvider)));
        return newOne;
    } else {
        BackupRequestsStrategyFromConfig newOne = existing.update(config);
        if (newOne != existing) {
            // reference inequality
            _statsConsumer.ifPresent(consumer -> {
                existing.getStrategy().ifPresent(statsProvider -> {
                    consumer.removeStatsProvider(serviceName, operation, statsProvider);
                    // Make sure latencies for all outstanding requests get recorded
                    FinalSweepLatencyNotification fsln = new FinalSweepLatencyNotification(serviceName, operation, statsProvider);
                    _finalSweepLatencyNotification.put(fsln, fsln);
                });
                newOne.getStrategy().ifPresent(statsProvider -> consumer.addStatsProvider(serviceName, operation, statsProvider));
            });
        }
        return newOne;
    }
}
Also used : ScheduledFuture(java.util.concurrent.ScheduledFuture) FutureCallback(com.linkedin.common.callback.FutureCallback) NamedThreadFactory(com.linkedin.r2.util.NamedThreadFactory) LoggerFactory(org.slf4j.LoggerFactory) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Callback(com.linkedin.common.callback.Callback) D2ClientDelegator(com.linkedin.d2.balancer.D2ClientDelegator) TrackingBackupRequestsStrategy(com.linkedin.d2.backuprequests.TrackingBackupRequestsStrategy) StreamRequest(com.linkedin.r2.message.stream.StreamRequest) RestResponse(com.linkedin.r2.message.rest.RestResponse) BackupRequestsStrategyFromConfig(com.linkedin.d2.backuprequests.BackupRequestsStrategyFromConfig) BackupRequestsStrategyStatsProvider(com.linkedin.d2.backuprequests.BackupRequestsStrategyStatsProvider) Future(java.util.concurrent.Future) ExcludedHostHints(com.linkedin.d2.balancer.strategies.LoadBalancerStrategy.ExcludedHostHints) Request(com.linkedin.r2.message.Request) BackupRequestsStrategyStatsConsumer(com.linkedin.d2.backuprequests.BackupRequestsStrategyStatsConsumer) ByteString(com.linkedin.data.ByteString) StreamResponse(com.linkedin.r2.message.stream.StreamResponse) Map(java.util.Map) FullEntityObserver(com.linkedin.r2.message.stream.entitystream.FullEntityObserver) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) URI(java.net.URI) RestRequest(com.linkedin.r2.message.rest.RestRequest) ByteStringWriter(com.linkedin.r2.message.stream.entitystream.ByteStringWriter) Logger(org.slf4j.Logger) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) PropertyKeys(com.linkedin.d2.balancer.properties.PropertyKeys) Collectors(java.util.stream.Collectors) TimeUnit(java.util.concurrent.TimeUnit) EntityStreams(com.linkedin.r2.message.stream.entitystream.EntityStreams) List(java.util.List) R2Constants(com.linkedin.r2.filter.R2Constants) RequestContext(com.linkedin.r2.message.RequestContext) AbstractHistogram(org.HdrHistogram.AbstractHistogram) None(com.linkedin.common.util.None) D2Client(com.linkedin.d2.balancer.D2Client) D2ClientConfig(com.linkedin.d2.balancer.D2ClientConfig) KeyMapper(com.linkedin.d2.balancer.KeyMapper) LoadBalancer(com.linkedin.d2.balancer.LoadBalancer) Optional(java.util.Optional) ServiceProperties(com.linkedin.d2.balancer.properties.ServiceProperties) ServiceUnavailableException(com.linkedin.d2.balancer.ServiceUnavailableException) LoadBalancerUtil(com.linkedin.d2.balancer.util.LoadBalancerUtil) BackupRequestsStrategyFromConfig(com.linkedin.d2.backuprequests.BackupRequestsStrategyFromConfig)

Aggregations

BackupRequestsStrategyFromConfig (com.linkedin.d2.backuprequests.BackupRequestsStrategyFromConfig)2 ByteString (com.linkedin.data.ByteString)2 Callback (com.linkedin.common.callback.Callback)1 FutureCallback (com.linkedin.common.callback.FutureCallback)1 None (com.linkedin.common.util.None)1 BackupRequestsStrategyStatsConsumer (com.linkedin.d2.backuprequests.BackupRequestsStrategyStatsConsumer)1 BackupRequestsStrategyStatsProvider (com.linkedin.d2.backuprequests.BackupRequestsStrategyStatsProvider)1 TrackingBackupRequestsStrategy (com.linkedin.d2.backuprequests.TrackingBackupRequestsStrategy)1 D2Client (com.linkedin.d2.balancer.D2Client)1 D2ClientConfig (com.linkedin.d2.balancer.D2ClientConfig)1 D2ClientDelegator (com.linkedin.d2.balancer.D2ClientDelegator)1 KeyMapper (com.linkedin.d2.balancer.KeyMapper)1 LoadBalancer (com.linkedin.d2.balancer.LoadBalancer)1 ServiceUnavailableException (com.linkedin.d2.balancer.ServiceUnavailableException)1 PropertyKeys (com.linkedin.d2.balancer.properties.PropertyKeys)1 ServiceProperties (com.linkedin.d2.balancer.properties.ServiceProperties)1 ExcludedHostHints (com.linkedin.d2.balancer.strategies.LoadBalancerStrategy.ExcludedHostHints)1 LoadBalancerUtil (com.linkedin.d2.balancer.util.LoadBalancerUtil)1 R2Constants (com.linkedin.r2.filter.R2Constants)1 Request (com.linkedin.r2.message.Request)1