Skip to content

Commit 69f2713

Browse files
authored
[#1280] config-center firstpull config support retry 3 times (#1283)
1 parent 57e60be commit 69f2713

File tree

1 file changed

+39
-6
lines changed
  • spring-cloud-huawei-service-engine/service-engine-config/src/main/java/com/huaweicloud/config

1 file changed

+39
-6
lines changed

spring-cloud-huawei-service-engine/service-engine-config/src/main/java/com/huaweicloud/config/ConfigService.java

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,8 @@ private void initServiceCenterConfig(BootstrapProperties bootstrapProperties,
154154
ConfigCenterClient configCenterClient = new ConfigCenterClient(addressManager, httpTransport);
155155

156156
queryConfigurationsRequest = createQueryConfigurationsRequest(bootstrapProperties);
157-
QueryConfigurationsResponse response = configCenterClient
158-
.queryConfigurations(queryConfigurationsRequest, addressManager.address());
159-
if (response.isChanged()) {
160-
configConverter.updateData(response.getConfigurations());
161-
}
162-
queryConfigurationsRequest.setRevision(response.getRevision());
157+
firstPull(bootstrapProperties.getConfigBootstrapProperties(), configCenterClient, queryConfigurationsRequest,
158+
addressManager);
163159
ConfigCenterConfiguration configCenterConfiguration = createConfigCenterConfiguration(
164160
bootstrapProperties.getConfigBootstrapProperties());
165161
ConfigCenterManager configCenterManager = new ConfigCenterManager(configCenterClient, EventManager.getEventBus(),
@@ -168,6 +164,43 @@ private void initServiceCenterConfig(BootstrapProperties bootstrapProperties,
168164
configCenterManager.startConfigCenterManager();
169165
}
170166

167+
public void firstPull(ConfigBootstrapProperties configProperties, ConfigCenterClient configCenterClient,
168+
QueryConfigurationsRequest queryConfigurationsRequest, ConfigCenterAddressManager addressManager) {
169+
try {
170+
firstQueryConfigurations(configCenterClient, queryConfigurationsRequest, addressManager);
171+
} catch (Exception e) {
172+
if (configProperties.isFirstPullRequired()) {
173+
throw e;
174+
} else {
175+
LOGGER.warn("first pull failed!");
176+
}
177+
}
178+
}
179+
180+
private void firstQueryConfigurations(ConfigCenterClient configCenterClient, QueryConfigurationsRequest queryConfigurationsRequest,
181+
ConfigCenterAddressManager addressManager) {
182+
int index = 0;
183+
while (index < 3) {
184+
String address = addressManager.address();
185+
try {
186+
QueryConfigurationsResponse response = configCenterClient.queryConfigurations(queryConfigurationsRequest,
187+
address);
188+
if (response.isChanged()) {
189+
configConverter.updateData(response.getConfigurations());
190+
}
191+
queryConfigurationsRequest.setRevision(response.getRevision());
192+
break;
193+
} catch (Exception e) {
194+
if (index == 2) {
195+
throw e;
196+
}
197+
LOGGER.warn("config-center firstQueryConfigurations failed, config address {} and ignore {}", address,
198+
e.getMessage());
199+
}
200+
index++;
201+
}
202+
}
203+
171204
private ConfigCenterConfiguration createConfigCenterConfiguration(ConfigBootstrapProperties configProperties) {
172205
ConfigCenterConfiguration configCenterConfiguration = new ConfigCenterConfiguration();
173206
configCenterConfiguration.setRefreshIntervalInMillis(configProperties.getConfigCenter().getRefreshInterval());

0 commit comments

Comments
 (0)