Java Code Examples for com.netflix.client.config.IClientConfig#get()

The following examples show how to use com.netflix.client.config.IClientConfig#get() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultClientChannelManager.java    From zuul with Apache License 2.0 6 votes vote down vote up
protected DynamicServerListLoadBalancer<?> createLoadBalancer(IClientConfig clientConfig) {
    // Create and configure a loadbalancer for this vip.
    String loadBalancerClassName = clientConfig.get(NFLoadBalancerClassName, ZoneAwareLoadBalancer.class.getName());

    DynamicServerListLoadBalancer<?> lb;
    try {
        Class<?> clazz = Class.forName(loadBalancerClassName);
        lb = clazz.asSubclass(DynamicServerListLoadBalancer.class).getConstructor().newInstance();
        lb.initWithNiwsConfig(clientConfig);
    } catch (Exception e) {
        Throwables.throwIfUnchecked(e);
        throw new IllegalStateException("Could not instantiate LoadBalancer " + loadBalancerClassName, e);
    }

    return lb;
}
 
Example 2
Source File: LBClient.java    From feign with Apache License 2.0 6 votes vote down vote up
@Override
public RibbonResponse execute(RibbonRequest request, IClientConfig configOverride)
    throws IOException, ClientException {
  Request.Options options;
  if (configOverride != null) {
    options =
        new Request.Options(
            configOverride.get(CommonClientConfigKey.ConnectTimeout, connectTimeout),
            TimeUnit.MILLISECONDS,
            (configOverride.get(CommonClientConfigKey.ReadTimeout, readTimeout)),
            TimeUnit.MILLISECONDS,
            configOverride.get(CommonClientConfigKey.FollowRedirects, followRedirects));
  } else {
    options = new Request.Options(connectTimeout, TimeUnit.MILLISECONDS, readTimeout,
        TimeUnit.MILLISECONDS, true);
  }
  Response response = request.client().execute(request.toRequest(), options);
  if (retryableStatusCodes.contains(response.status())) {
    response.close();
    throw new ClientException(ClientException.ErrorType.SERVER_THROTTLED);
  }
  return new RibbonResponse(request.getUri(), response);
}
 
Example 3
Source File: LoadBalancingRxClientWithPoolOptions.java    From ribbon with Apache License 2.0 6 votes vote down vote up
public LoadBalancingRxClientWithPoolOptions(ILoadBalancer lb, IClientConfig config,
        RetryHandler retryHandler,
        PipelineConfigurator<O, I> pipelineConfigurator, ScheduledExecutorService poolCleanerScheduler) {
    super(lb, config, retryHandler, pipelineConfigurator);
    poolEnabled = config.get(CommonClientConfigKey.EnableConnectionPool, 
            DefaultClientConfigImpl.DEFAULT_ENABLE_CONNECTION_POOL);
    if (poolEnabled) {
        this.poolCleanerScheduler = poolCleanerScheduler;
        int maxTotalConnections = config.get(IClientConfigKey.Keys.MaxTotalConnections,
                DefaultClientConfigImpl.DEFAULT_MAX_TOTAL_CONNECTIONS);
        int maxConnections = config.get(Keys.MaxConnectionsPerHost, DefaultClientConfigImpl.DEFAULT_MAX_CONNECTIONS_PER_HOST);
        MaxConnectionsBasedStrategy perHostStrategy = new DynamicPropertyBasedPoolStrategy(maxConnections,
                config.getClientName() + "." + config.getNameSpace() + "." + CommonClientConfigKey.MaxConnectionsPerHost);
        globalStrategy = new DynamicPropertyBasedPoolStrategy(maxTotalConnections, 
                config.getClientName() + "." + config.getNameSpace() + "." + CommonClientConfigKey.MaxTotalConnections);
        poolStrategy = new CompositePoolLimitDeterminationStrategy(perHostStrategy, globalStrategy);
        idleConnectionEvictionMills = config.get(Keys.ConnIdleEvictTimeMilliSeconds, DefaultClientConfigImpl.DEFAULT_CONNECTIONIDLE_TIME_IN_MSECS);
    }
}
 
Example 4
Source File: AbstractServerList.java    From ribbon with Apache License 2.0 6 votes vote down vote up
/**
 * Get a ServerListFilter instance. It uses {@link ClientFactory#instantiateInstanceWithClientConfig(String, IClientConfig)}
 * which in turn uses reflection to initialize the filter instance. 
 * The filter class name is determined by the value of {@link CommonClientConfigKey#NIWSServerListFilterClassName}
 * in the {@link IClientConfig}. The default implementation is {@link ZoneAffinityServerListFilter}.
 */
public AbstractServerListFilter<T> getFilterImpl(IClientConfig niwsClientConfig) throws ClientException {
    String niwsServerListFilterClassName = null;
    try {
        niwsServerListFilterClassName = niwsClientConfig.get(
                        CommonClientConfigKey.NIWSServerListFilterClassName,
                        ZoneAffinityServerListFilter.class.getName());

        AbstractServerListFilter<T> abstractNIWSServerListFilter = 
                (AbstractServerListFilter<T>) ClientFactory.instantiateInstanceWithClientConfig(niwsServerListFilterClassName, niwsClientConfig);
        return abstractNIWSServerListFilter;
    } catch (Throwable e) {
        throw new ClientException(
                ClientException.ErrorType.CONFIGURATION,
                "Unable to get an instance of CommonClientConfigKey.NIWSServerListFilterClassName. Configured class:"
                        + niwsServerListFilterClassName, e);
    }
}
 
Example 5
Source File: BaseLoadBalancer.java    From ribbon with Apache License 2.0 5 votes vote down vote up
void initWithConfig(IClientConfig clientConfig, IRule rule, IPing ping, LoadBalancerStats stats) {
    this.config = clientConfig;
    this.name = clientConfig.getClientName();
    int pingIntervalTime = clientConfig.get(CommonClientConfigKey.NFLoadBalancerPingInterval, 30);
    int maxTotalPingTime = clientConfig.get(CommonClientConfigKey.NFLoadBalancerMaxTotalPingTime, 2);

    setPingInterval(pingIntervalTime);
    setMaxTotalPingTime(maxTotalPingTime);

    // cross associate with each other
    // i.e. Rule,Ping meet your container LB
    // LB, these are your Ping and Rule guys ...
    setRule(rule);
    setPing(ping);

    setLoadBalancerStats(stats);
    rule.setLoadBalancer(this);
    if (ping instanceof AbstractLoadBalancerPing) {
        ((AbstractLoadBalancerPing) ping).setLoadBalancer(this);
    }
    logger.info("Client: {} instantiated a LoadBalancer: {}", name, this);
    boolean enablePrimeConnections = clientConfig.getOrDefault(CommonClientConfigKey.EnablePrimeConnections);

    if (enablePrimeConnections) {
        this.setEnablePrimingConnections(true);
        PrimeConnections primeConnections = new PrimeConnections(
                this.getName(), clientConfig);
        this.setPrimeConnections(primeConnections);
    }
    init();

}
 
Example 6
Source File: LBClient.java    From feign with Apache License 2.0 5 votes vote down vote up
LBClient(ILoadBalancer lb, IClientConfig clientConfig) {
  super(lb, clientConfig);
  this.clientConfig = clientConfig;
  connectTimeout = clientConfig.get(CommonClientConfigKey.ConnectTimeout);
  readTimeout = clientConfig.get(CommonClientConfigKey.ReadTimeout);
  retryableStatusCodes = parseStatusCodes(clientConfig.get(LBClientFactory.RetryableStatusCodes));
  followRedirects = clientConfig.get(CommonClientConfigKey.FollowRedirects);
}
 
Example 7
Source File: ClientOptions.java    From ribbon with Apache License 2.0 5 votes vote down vote up
public static ClientOptions from(IClientConfig config) {
    ClientOptions options = new ClientOptions();
    for (IClientConfigKey key: IClientConfigKey.Keys.keys()) {
        Object value = config.get(key);
        if (value != null) {
            options.options.put(key, value);
        }
    }
    return options;
}
 
Example 8
Source File: AbstractLoadBalancerAwareClient.java    From ribbon with Apache License 2.0 5 votes vote down vote up
@Deprecated
protected boolean isRetriable(S request) {
    if (request.isRetriable()) {
        return true;            
    } else {
        boolean retryOkayOnOperation = okToRetryOnAllOperations;
        IClientConfig overriddenClientConfig = request.getOverrideConfig();
        if (overriddenClientConfig != null) {
            retryOkayOnOperation = overriddenClientConfig.get(CommonClientConfigKey.RequestSpecificRetryOn, okToRetryOnAllOperations);
        }
        return retryOkayOnOperation;
    }
}
 
Example 9
Source File: LoadBalancerBuilder.java    From ribbon with Apache License 2.0 5 votes vote down vote up
private static ServerList<Server> createServerListFromConfig(IClientConfig config, IClientConfigAware.Factory factory) {
    String serverListClassName = config.get(IClientConfigKey.Keys.NIWSServerListClassName);
    if (serverListClassName == null) {
        throw new IllegalArgumentException("NIWSServerListClassName is not specified in the config");
    }
    ServerList<Server> list;
    try {
        list = (ServerList<Server>) factory.create(serverListClassName, config);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return list;
}
 
Example 10
Source File: LoadBalancerContext.java    From ribbon with Apache License 2.0 5 votes vote down vote up
protected int getNumberRetriesOnSameServer(IClientConfig overriddenClientConfig) {
    int numRetries =  maxAutoRetries;
    if (overriddenClientConfig!=null){
        try {
            numRetries = overriddenClientConfig.get(CommonClientConfigKey.MaxAutoRetries, maxAutoRetries);
        } catch (Exception e) {
            logger.warn("Invalid maxRetries requested for RestClient:" + this.clientName);
        }
    }
    return numRetries;
}
 
Example 11
Source File: LoadBalancerContext.java    From ribbon with Apache License 2.0 5 votes vote down vote up
protected int getRetriesNextServer(IClientConfig overriddenClientConfig) {
    int numRetries = maxAutoRetriesNextServer;
    if (overriddenClientConfig != null) {
        numRetries = overriddenClientConfig.get(CommonClientConfigKey.MaxAutoRetriesNextServer, maxAutoRetriesNextServer);
    }
    return numRetries;
}
 
Example 12
Source File: TopologyServerList.java    From thorntail with Apache License 2.0 4 votes vote down vote up
@Override
public void initWithNiwsConfig(IClientConfig config) {
    this.appName = config.getClientName();
    this.isSecure = config.get(IClientConfigKey.Keys.IsSecure, false);
}
 
Example 13
Source File: WeightedResponseTimeRule.java    From ribbon with Apache License 2.0 4 votes vote down vote up
@Override
public void initWithNiwsConfig(IClientConfig clientConfig) {
    super.initWithNiwsConfig(clientConfig);
    serverWeightTaskTimerInterval = clientConfig.get(WEIGHT_TASK_TIMER_INTERVAL_CONFIG_KEY, DEFAULT_TIMER_INTERVAL);
}
 
Example 14
Source File: PollingServerListUpdater.java    From ribbon with Apache License 2.0 4 votes vote down vote up
private static long getRefreshIntervalMs(IClientConfig clientConfig) {
    return clientConfig.get(CommonClientConfigKey.ServerListRefreshInterval, LISTOFSERVERS_CACHE_REPEAT_INTERVAL);
}
 
Example 15
Source File: ResponseTimeWeightedRule.java    From ribbon with Apache License 2.0 4 votes vote down vote up
@Override
public void initWithNiwsConfig(IClientConfig clientConfig) {
    super.initWithNiwsConfig(clientConfig);
    serverWeightTaskTimerInterval = clientConfig.get(WEIGHT_TASK_TIMER_INTERVAL_CONFIG_KEY, DEFAULT_TIMER_INTERVAL);
}
 
Example 16
Source File: RequestAttempt.java    From zuul with Apache License 2.0 4 votes vote down vote up
public RequestAttempt(final Server server, final IClientConfig clientConfig, int attemptNumber, int readTimeout) {
    this.status = -1;
    this.attempt = attemptNumber;
    this.readTimeout = readTimeout;

    if (server != null) {
        this.host = server.getHost();
        this.port = server.getPort();
        this.availabilityZone = server.getZone();

        if (server instanceof DiscoveryEnabledServer) {
            InstanceInfo instanceInfo = ((DiscoveryEnabledServer) server).getInstanceInfo();
            this.app = instanceInfo.getAppName().toLowerCase();
            this.asg = instanceInfo.getASGName();
            this.instanceId = instanceInfo.getInstanceId();
            this.host = instanceInfo.getHostName();
            this.port = instanceInfo.getPort();

            if (server.getPort() == instanceInfo.getSecurePort()) {
                this.vip = instanceInfo.getSecureVipAddress();
            }
            else {
                this.vip = instanceInfo.getVIPAddress();
            }
            if (instanceInfo.getDataCenterInfo() instanceof AmazonInfo) {
                this.availabilityZone = ((AmazonInfo) instanceInfo.getDataCenterInfo()).getMetadata().get("availability-zone");
            }
        }
        else {
            final Server.MetaInfo metaInfo = server.getMetaInfo();
            if (metaInfo != null) {
                this.asg = metaInfo.getServerGroup();
                this.vip = metaInfo.getServiceIdForDiscovery();
                this.instanceId = metaInfo.getInstanceId();
            }
        }
        // HACK - get region by just removing the last char from zone.
        if (availabilityZone != null && availabilityZone.length() > 0) {
            region = availabilityZone.substring(0, availabilityZone.length() - 1);
        }
    }

    if (clientConfig != null) {
        this.connectTimeout = clientConfig.get(IClientConfigKey.Keys.ConnectTimeout);
    }
}
 
Example 17
Source File: TopologyServerList.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 4 votes vote down vote up
@Override
public void initWithNiwsConfig(IClientConfig config) {
    this.appName = config.getClientName();
    this.isSecure = config.get(IClientConfigKey.Keys.IsSecure, false);
}
 
Example 18
Source File: LoadBalancingRxClient.java    From ribbon with Apache License 2.0 3 votes vote down vote up
/**
 * Resolve the final property value from,
 * 1. Request specific configuration
 * 2. Default configuration
 * 3. Default value
 * 
 * @param key
 * @param requestConfig
 * @param defaultValue
 * @return
 */
protected <S> S getProperty(IClientConfigKey<S> key, @Nullable IClientConfig requestConfig, S defaultValue) {
    if (requestConfig != null && requestConfig.get(key) != null) {
        return requestConfig.get(key);
    } else {
        return clientConfig.get(key, defaultValue);
    }
}