-
-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b454698
commit 89321ac
Showing
6 changed files
with
102 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,8 +51,11 @@ | |
import com.google.common.net.UrlEscapers; | ||
import com.google.common.util.concurrent.RateLimiter; | ||
import com.google.gson.Gson; | ||
|
||
import java.util.*; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Properties; | ||
import java.util.concurrent.Executors; | ||
import java.util.concurrent.ScheduledExecutorService; | ||
import java.util.concurrent.TimeUnit; | ||
|
@@ -64,7 +67,9 @@ | |
* @author Jason Song([email protected]) | ||
*/ | ||
public class RemoteConfigRepository extends AbstractConfigRepository { | ||
private static final Logger logger = DeferredLoggerFactory.getLogger(RemoteConfigRepository.class); | ||
|
||
private static final Logger logger = DeferredLoggerFactory.getLogger( | ||
RemoteConfigRepository.class); | ||
private static final Joiner STRING_JOINER = Joiner.on(ConfigConsts.CLUSTER_NAMESPACE_SEPARATOR); | ||
private static final Joiner.MapJoiner MAP_JOINER = Joiner.on("&").withKeyValueSeparator("="); | ||
private static final Escaper pathEscaper = UrlEscapers.urlPathSegmentEscaper(); | ||
|
@@ -93,7 +98,7 @@ public class RemoteConfigRepository extends AbstractConfigRepository { | |
/** | ||
* Constructor. | ||
* | ||
* @param appId the appId | ||
* @param appId the appId | ||
* @param namespace the namespace | ||
*/ | ||
public RemoteConfigRepository(String appId, String namespace) { | ||
|
@@ -108,7 +113,8 @@ public RemoteConfigRepository(String appId, String namespace) { | |
m_remoteMessages = new AtomicReference<>(); | ||
m_loadConfigRateLimiter = RateLimiter.create(m_configUtil.getLoadConfigQPS()); | ||
m_configNeedForceRefresh = new AtomicBoolean(true); | ||
m_loadConfigFailSchedulePolicy = new ExponentialSchedulePolicy(m_configUtil.getOnErrorRetryInterval(), | ||
m_loadConfigFailSchedulePolicy = new ExponentialSchedulePolicy( | ||
m_configUtil.getOnErrorRetryInterval(), | ||
m_configUtil.getOnErrorRetryInterval() * 8); | ||
this.schedulePeriodicRefresh(); | ||
this.scheduleLongPollingRefresh(); | ||
|
@@ -119,7 +125,7 @@ public Properties getConfig() { | |
if (m_configCache.get() == null) { | ||
long start = System.currentTimeMillis(); | ||
this.sync(); | ||
Tracer.logEvent(APOLLO_CLIENT_NAMESPACE_FIRST_LOAD_SPEND+":"+m_namespace, | ||
Tracer.logEvent(APOLLO_CLIENT_NAMESPACE_FIRST_LOAD_SPEND + ":" + m_namespace, | ||
String.valueOf(System.currentTimeMillis() - start)); | ||
} | ||
return transformApolloConfigToProperties(m_configCache.get()); | ||
|
@@ -142,7 +148,8 @@ private void schedulePeriodicRefresh() { | |
new Runnable() { | ||
@Override | ||
public void run() { | ||
Tracer.logEvent(APOLLO_CONFIGSERVICE, String.format("periodicRefresh: %s", m_namespace)); | ||
Tracer.logEvent(APOLLO_CONFIGSERVICE, | ||
String.format("periodicRefresh: %s", m_namespace)); | ||
logger.debug("refresh config for namespace: {}", m_namespace); | ||
trySync(); | ||
Tracer.logEvent(APOLLO_CLIENT_VERSION, Apollo.VERSION); | ||
|
@@ -167,7 +174,7 @@ protected synchronized void sync() { | |
} | ||
|
||
if (current != null) { | ||
Tracer.logEvent(String.format(APOLLO_CLIENT_CONFIGS+"%s", current.getNamespaceName()), | ||
Tracer.logEvent(String.format(APOLLO_CLIENT_CONFIGS + "%s", current.getNamespaceName()), | ||
current.getReleaseKey()); | ||
} | ||
|
||
|
@@ -218,7 +225,8 @@ private ApolloConfig loadApolloConfig() { | |
if (onErrorSleepTime > 0) { | ||
logger.warn( | ||
"Load config failed, will retry in {} {}. appId: {}, cluster: {}, namespaces: {}", | ||
onErrorSleepTime, m_configUtil.getOnErrorRetryIntervalTimeUnit(), appId, cluster, m_namespace); | ||
onErrorSleepTime, m_configUtil.getOnErrorRetryIntervalTimeUnit(), appId, cluster, | ||
m_namespace); | ||
|
||
try { | ||
m_configUtil.getOnErrorRetryIntervalTimeUnit().sleep(onErrorSleepTime); | ||
|
@@ -228,7 +236,7 @@ private ApolloConfig loadApolloConfig() { | |
} | ||
|
||
url = assembleQueryConfigUrl(configService.getHomepageUrl(), appId, cluster, m_namespace, | ||
dataCenter, m_remoteMessages.get(), m_configCache.get()); | ||
dataCenter, m_remoteMessages.get(), m_configCache.get()); | ||
|
||
logger.debug("Loading config from {}", url); | ||
|
||
|
@@ -286,13 +294,14 @@ private ApolloConfig loadApolloConfig() { | |
appId, cluster, m_namespace); | ||
statusCodeException = new ApolloConfigStatusCodeException(ex.getStatusCode(), | ||
message); | ||
Tracer.logEvent(APOLLO_CLIENT_NAMESPACE_NOT_FOUND,m_namespace); | ||
Tracer.logEvent(APOLLO_CLIENT_NAMESPACE_NOT_FOUND, m_namespace); | ||
|
||
} | ||
Tracer.logEvent(APOLLO_CONFIG_EXCEPTION, ExceptionUtil.getDetailMessage(statusCodeException)); | ||
Tracer.logEvent(APOLLO_CONFIG_EXCEPTION, | ||
ExceptionUtil.getDetailMessage(statusCodeException)); | ||
transaction.setStatus(statusCodeException); | ||
exception = statusCodeException; | ||
if(ex.getStatusCode() == 404) { | ||
if (ex.getStatusCode() == 404) { | ||
break retryLoopLabel; | ||
} | ||
} catch (Throwable ex) { | ||
|
@@ -316,7 +325,7 @@ private ApolloConfig loadApolloConfig() { | |
} | ||
|
||
String assembleQueryConfigUrl(String uri, String appId, String cluster, String namespace, | ||
String dataCenter, ApolloNotificationMessages remoteMessages, ApolloConfig previousConfig) { | ||
String dataCenter, ApolloNotificationMessages remoteMessages, ApolloConfig previousConfig) { | ||
|
||
String path = "configs/%s/%s/%s"; | ||
List<String> pathParams = | ||
|
@@ -361,7 +370,8 @@ private void scheduleLongPollingRefresh() { | |
remoteConfigLongPollService.submit(m_appId, m_namespace, this); | ||
} | ||
|
||
public void onLongPollNotified(ServiceDTO longPollNotifiedServiceDto, ApolloNotificationMessages remoteMessages) { | ||
public void onLongPollNotified(ServiceDTO longPollNotifiedServiceDto, | ||
ApolloNotificationMessages remoteMessages) { | ||
m_longPollServiceDto.set(longPollNotifiedServiceDto); | ||
m_remoteMessages.set(remoteMessages); | ||
m_executorService.submit(new Runnable() { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.