-
Notifications
You must be signed in to change notification settings - Fork 3.8k
/
DefaultEurekaClientConfig.java
530 lines (472 loc) · 16.5 KB
/
DefaultEurekaClientConfig.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
/*
* Copyright 2012 Netflix, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.netflix.discovery;
import javax.annotation.Nullable;
import javax.inject.Singleton;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import com.google.inject.ProvidedBy;
import com.netflix.appinfo.EurekaAccept;
import com.netflix.config.DynamicPropertyFactory;
import com.netflix.config.DynamicStringProperty;
import com.netflix.discovery.internal.util.Archaius1Utils;
import com.netflix.discovery.providers.DefaultEurekaClientConfigProvider;
import com.netflix.discovery.shared.transport.DefaultEurekaTransportConfig;
import com.netflix.discovery.shared.transport.EurekaTransportConfig;
import static com.netflix.discovery.PropertyBasedClientConfigConstants.*;
/**
*
* A default implementation of eureka client configuration as required by
* {@link EurekaClientConfig}.
*
* <p>
* The information required for configuring eureka client is provided in a
* configuration file.The configuration file is searched for in the classpath
* with the name specified by the property <em>eureka.client.props</em> and with
* the suffix <em>.properties</em>. If the property is not specified,
* <em>eureka-client.properties</em> is assumed as the default.The properties
* that are looked up uses the <em>namespace</em> passed on to this class.
* </p>
*
* <p>
* If the <em>eureka.environment</em> property is specified, additionally
* <em>eureka-client-<eureka.environment>.properties</em> is loaded in addition
* to <em>eureka-client.properties</em>.
* </p>
*
* @author Karthik Ranganathan
*
*/
@Singleton
@ProvidedBy(DefaultEurekaClientConfigProvider.class)
public class DefaultEurekaClientConfig implements EurekaClientConfig {
/**
* @deprecated 2016-08-29 use {@link com.netflix.discovery.CommonConstants#DEFAULT_CONFIG_NAMESPACE}
*/
@Deprecated
public static final String DEFAULT_NAMESPACE = CommonConstants.DEFAULT_CONFIG_NAMESPACE + ".";
public static final String DEFAULT_ZONE = "defaultZone";
public static final String URL_SEPARATOR = "\\s*,\\s*";
private final String namespace;
private final DynamicPropertyFactory configInstance;
private final EurekaTransportConfig transportConfig;
public DefaultEurekaClientConfig() {
this(CommonConstants.DEFAULT_CONFIG_NAMESPACE);
}
public DefaultEurekaClientConfig(String namespace) {
this.namespace = namespace.endsWith(".")
? namespace
: namespace + ".";
this.configInstance = Archaius1Utils.initConfig(CommonConstants.CONFIG_FILE_NAME);
this.transportConfig = new DefaultEurekaTransportConfig(namespace, configInstance);
}
/*
* (non-Javadoc)
*
* @see
* com.netflix.discovery.EurekaClientConfig#getRegistryFetchIntervalSeconds
* ()
*/
@Override
public int getRegistryFetchIntervalSeconds() {
return configInstance.getIntProperty(
namespace + REGISTRY_REFRESH_INTERVAL_KEY, 30).get();
}
/*
* (non-Javadoc)
*
* @see com.netflix.discovery.EurekaClientConfig#
* getInstanceInfoReplicationIntervalSeconds()
*/
@Override
public int getInstanceInfoReplicationIntervalSeconds() {
return configInstance.getIntProperty(
namespace + REGISTRATION_REPLICATION_INTERVAL_KEY, 30).get();
}
@Override
public int getInitialInstanceInfoReplicationIntervalSeconds() {
return configInstance.getIntProperty(
namespace + INITIAL_REGISTRATION_REPLICATION_DELAY_KEY, 40).get();
}
/*
* (non-Javadoc)
*
* @see com.netflix.discovery.EurekaClientConfig#getDnsPollIntervalSeconds()
*/
@Override
public int getEurekaServiceUrlPollIntervalSeconds() {
return configInstance.getIntProperty(
namespace + EUREKA_SERVER_URL_POLL_INTERVAL_KEY, 5 * 60 * 1000).get() / 1000;
}
/*
* (non-Javadoc)
*
* @see com.netflix.discovery.EurekaClientConfig#getProxyHost()
*/
@Override
public String getProxyHost() {
return configInstance.getStringProperty(
namespace + EUREKA_SERVER_PROXY_HOST_KEY, null).get();
}
/*
* (non-Javadoc)
*
* @see com.netflix.discovery.EurekaClientConfig#getProxyPort()
*/
@Override
public String getProxyPort() {
return configInstance.getStringProperty(
namespace + EUREKA_SERVER_PROXY_PORT_KEY, null).get();
}
@Override
public String getProxyUserName() {
return configInstance.getStringProperty(
namespace + EUREKA_SERVER_PROXY_USERNAME_KEY, null).get();
}
@Override
public String getProxyPassword() {
return configInstance.getStringProperty(
namespace + EUREKA_SERVER_PROXY_PASSWORD_KEY, null).get();
}
/*
* (non-Javadoc)
*
* @see com.netflix.discovery.EurekaClientConfig#shouldGZipContent()
*/
@Override
public boolean shouldGZipContent() {
return configInstance.getBooleanProperty(
namespace + EUREKA_SERVER_GZIP_CONTENT_KEY, true).get();
}
/*
* (non-Javadoc)
*
* @see com.netflix.discovery.EurekaClientConfig#getDSServerReadTimeout()
*/
@Override
public int getEurekaServerReadTimeoutSeconds() {
return configInstance.getIntProperty(
namespace + EUREKA_SERVER_READ_TIMEOUT_KEY, 8).get();
}
/*
* (non-Javadoc)
*
* @see com.netflix.discovery.EurekaClientConfig#getDSServerConnectTimeout()
*/
@Override
public int getEurekaServerConnectTimeoutSeconds() {
return configInstance.getIntProperty(
namespace + EUREKA_SERVER_CONNECT_TIMEOUT_KEY, 5).get();
}
/*
* (non-Javadoc)
*
* @see com.netflix.discovery.EurekaClientConfig#getBackupRegistryImpl()
*/
@Override
public String getBackupRegistryImpl() {
return configInstance.getStringProperty(namespace + BACKUP_REGISTRY_CLASSNAME_KEY,
null).get();
}
/*
* (non-Javadoc)
*
* @see
* com.netflix.discovery.EurekaClientConfig#getDSServerTotalMaxConnections()
*/
@Override
public int getEurekaServerTotalConnections() {
return configInstance.getIntProperty(
namespace + EUREKA_SERVER_MAX_CONNECTIONS_KEY, 200).get();
}
/*
* (non-Javadoc)
*
* @see
* com.netflix.discovery.EurekaClientConfig#getDSServerConnectionsPerHost()
*/
@Override
public int getEurekaServerTotalConnectionsPerHost() {
return configInstance.getIntProperty(
namespace + EUREKA_SERVER_MAX_CONNECTIONS_PER_HOST_KEY, 50).get();
}
/*
* (non-Javadoc)
*
* @see com.netflix.discovery.EurekaClientConfig#getDSServerURLContext()
*/
@Override
public String getEurekaServerURLContext() {
return configInstance.getStringProperty(
namespace + EUREKA_SERVER_URL_CONTEXT_KEY,
configInstance.getStringProperty(namespace + EUREKA_SERVER_FALLBACK_URL_CONTEXT_KEY, null)
.get()).get();
}
/*
* (non-Javadoc)
*
* @see com.netflix.discovery.EurekaClientConfig#getDSServerPort()
*/
@Override
public String getEurekaServerPort() {
return configInstance.getStringProperty(
namespace + EUREKA_SERVER_PORT_KEY,
configInstance.getStringProperty(namespace + EUREKA_SERVER_FALLBACK_PORT_KEY, null)
.get()).get();
}
/*
* (non-Javadoc)
*
* @see com.netflix.discovery.EurekaClientConfig#getDSServerDomain()
*/
@Override
public String getEurekaServerDNSName() {
return configInstance.getStringProperty(
namespace + EUREKA_SERVER_DNS_NAME_KEY,
configInstance
.getStringProperty(namespace + EUREKA_SERVER_FALLBACK_DNS_NAME_KEY, null)
.get()).get();
}
/*
* (non-Javadoc)
*
* @see com.netflix.discovery.EurekaClientConfig#shouldUseDns()
*/
@Override
public boolean shouldUseDnsForFetchingServiceUrls() {
return configInstance.getBooleanProperty(namespace + SHOULD_USE_DNS_KEY,
false).get();
}
/*
* (non-Javadoc)
*
* @see
* com.netflix.discovery.EurekaClientConfig#getDiscoveryRegistrationEnabled()
*/
@Override
public boolean shouldRegisterWithEureka() {
return configInstance.getBooleanProperty(
namespace + REGISTRATION_ENABLED_KEY, true).get();
}
/*
* (non-Javadoc)
*
* @see
* com.netflix.discovery.EurekaClientConfig#shouldUnregisterOnShutdown()
*/
@Override
public boolean shouldUnregisterOnShutdown() {
return configInstance.getBooleanProperty(
namespace + SHOULD_UNREGISTER_ON_SHUTDOWN_KEY, true).get();
}
/*
* (non-Javadoc)
*
* @see com.netflix.discovery.EurekaClientConfig#shouldPreferSameZoneDS()
*/
@Override
public boolean shouldPreferSameZoneEureka() {
return configInstance.getBooleanProperty(namespace + SHOULD_PREFER_SAME_ZONE_SERVER_KEY,
true).get();
}
@Override
public boolean allowRedirects() {
return configInstance.getBooleanProperty(namespace + SHOULD_ALLOW_REDIRECTS_KEY, false).get();
}
/*
* (non-Javadoc)
*
* @see com.netflix.discovery.EurekaClientConfig#shouldLogDeltaDiff()
*/
@Override
public boolean shouldLogDeltaDiff() {
return configInstance.getBooleanProperty(
namespace + SHOULD_LOG_DELTA_DIFF_KEY, false).get();
}
/*
* (non-Javadoc)
*
* @see com.netflix.discovery.EurekaClientConfig#shouldDisableDelta()
*/
@Override
public boolean shouldDisableDelta() {
return configInstance.getBooleanProperty(namespace + SHOULD_DISABLE_DELTA_KEY,
false).get();
}
@Nullable
@Override
public String fetchRegistryForRemoteRegions() {
return configInstance.getStringProperty(namespace + SHOULD_FETCH_REMOTE_REGION_KEY, null).get();
}
/*
* (non-Javadoc)
*
* @see com.netflix.discovery.EurekaClientConfig#getRegion()
*/
@Override
public String getRegion() {
DynamicStringProperty defaultEurekaRegion = configInstance.getStringProperty(CLIENT_REGION_FALLBACK_KEY, Values.DEFAULT_CLIENT_REGION);
return configInstance.getStringProperty(namespace + CLIENT_REGION_KEY, defaultEurekaRegion.get()).get();
}
/*
* (non-Javadoc)
*
* @see com.netflix.discovery.EurekaClientConfig#getAvailabilityZones()
*/
@Override
public String[] getAvailabilityZones(String region) {
return configInstance
.getStringProperty(
namespace + region + "." + CONFIG_AVAILABILITY_ZONE_PREFIX,
DEFAULT_ZONE).get().split(URL_SEPARATOR);
}
/*
* (non-Javadoc)
*
* @see
* com.netflix.discovery.EurekaClientConfig#getEurekaServerServiceUrls()
*/
@Override
public List<String> getEurekaServerServiceUrls(String myZone) {
String serviceUrls = configInstance.getStringProperty(
namespace + CONFIG_EUREKA_SERVER_SERVICE_URL_PREFIX + "." + myZone, null).get();
if (serviceUrls == null || serviceUrls.isEmpty()) {
serviceUrls = configInstance.getStringProperty(
namespace + CONFIG_EUREKA_SERVER_SERVICE_URL_PREFIX + ".default", null).get();
}
if (serviceUrls != null) {
return Arrays.asList(serviceUrls.split(URL_SEPARATOR));
}
return new ArrayList<String>();
}
/*
* (non-Javadoc)
*
* @see
* com.netflix.discovery.EurekaClientConfig#shouldFilterOnlyUpInstances()
*/
@Override
public boolean shouldFilterOnlyUpInstances() {
return configInstance.getBooleanProperty(
namespace + SHOULD_FILTER_ONLY_UP_INSTANCES_KEY, true).get();
}
/*
* (non-Javadoc)
*
* @see
* com.netflix.discovery.EurekaClientConfig#getEurekaConnectionIdleTimeout()
*/
@Override
public int getEurekaConnectionIdleTimeoutSeconds() {
return configInstance.getIntProperty(
namespace + EUREKA_SERVER_CONNECTION_IDLE_TIMEOUT_KEY, 45)
.get();
}
@Override
public boolean shouldFetchRegistry() {
return configInstance.getBooleanProperty(
namespace + FETCH_REGISTRY_ENABLED_KEY, true).get();
}
@Override
public boolean shouldEnforceFetchRegistryAtInit() {
return configInstance.getBooleanProperty(
namespace + SHOULD_ENFORCE_FETCH_REGISTRY_AT_INIT_KEY, false).get();
}
/*
* (non-Javadoc)
*
* @see com.netflix.discovery.EurekaClientConfig#getRegistryRefreshSingleVipAddress()
*/
@Override
public String getRegistryRefreshSingleVipAddress() {
return configInstance.getStringProperty(
namespace + FETCH_SINGLE_VIP_ONLY_KEY, null).get();
}
/**
* (non-Javadoc)
*
* @see com.netflix.discovery.EurekaClientConfig#getHeartbeatExecutorThreadPoolSize()
*/
@Override
public int getHeartbeatExecutorThreadPoolSize() {
return configInstance.getIntProperty(
namespace + HEARTBEAT_THREADPOOL_SIZE_KEY, Values.DEFAULT_EXECUTOR_THREAD_POOL_SIZE).get();
}
@Override
public int getHeartbeatExecutorExponentialBackOffBound() {
return configInstance.getIntProperty(
namespace + HEARTBEAT_BACKOFF_BOUND_KEY, Values.DEFAULT_EXECUTOR_THREAD_POOL_BACKOFF_BOUND).get();
}
/**
* (non-Javadoc)
*
* @see com.netflix.discovery.EurekaClientConfig#getCacheRefreshExecutorThreadPoolSize()
*/
@Override
public int getCacheRefreshExecutorThreadPoolSize() {
return configInstance.getIntProperty(
namespace + CACHEREFRESH_THREADPOOL_SIZE_KEY, Values.DEFAULT_EXECUTOR_THREAD_POOL_SIZE).get();
}
@Override
public int getCacheRefreshExecutorExponentialBackOffBound() {
return configInstance.getIntProperty(
namespace + CACHEREFRESH_BACKOFF_BOUND_KEY, Values.DEFAULT_EXECUTOR_THREAD_POOL_BACKOFF_BOUND).get();
}
@Override
public String getDollarReplacement() {
return configInstance.getStringProperty(
namespace + CONFIG_DOLLAR_REPLACEMENT_KEY, Values.CONFIG_DOLLAR_REPLACEMENT).get();
}
@Override
public String getEscapeCharReplacement() {
return configInstance.getStringProperty(
namespace + CONFIG_ESCAPE_CHAR_REPLACEMENT_KEY, Values.CONFIG_ESCAPE_CHAR_REPLACEMENT).get();
}
@Override
public boolean shouldOnDemandUpdateStatusChange() {
return configInstance.getBooleanProperty(
namespace + SHOULD_ONDEMAND_UPDATE_STATUS_KEY, true).get();
}
@Override
public boolean shouldEnforceRegistrationAtInit() {
return configInstance.getBooleanProperty(
namespace + SHOULD_ENFORCE_REGISTRATION_AT_INIT, false).get();
}
@Override
public String getEncoderName() {
return configInstance.getStringProperty(
namespace + CLIENT_ENCODER_NAME_KEY, null).get();
}
@Override
public String getDecoderName() {
return configInstance.getStringProperty(
namespace + CLIENT_DECODER_NAME_KEY, null).get();
}
@Override
public String getClientDataAccept() {
return configInstance.getStringProperty(
namespace + CLIENT_DATA_ACCEPT_KEY, EurekaAccept.full.name()).get();
}
@Override
public String getExperimental(String name) {
return configInstance.getStringProperty(namespace + CONFIG_EXPERIMENTAL_PREFIX + "." + name, null).get();
}
@Override
public EurekaTransportConfig getTransportConfig() {
return transportConfig;
}
}