Skip to content

Commit

Permalink
[#1280] config-center firstpull config support retry 3 times (#1281)
Browse files Browse the repository at this point in the history
  • Loading branch information
chengyouling authored Jun 18, 2024
1 parent 11f7590 commit bb21403
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 7 deletions.
2 changes: 1 addition & 1 deletion spring-cloud-huawei-parents/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.20.0</version>
<version>0.44.0</version>
</plugin>
</plugins>
</pluginManagement>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,8 @@ private void initServiceCenterConfig(BootstrapProperties bootstrapProperties,
ConfigCenterClient configCenterClient = new ConfigCenterClient(addressManager, httpTransport);

queryConfigurationsRequest = createQueryConfigurationsRequest(bootstrapProperties);
QueryConfigurationsResponse response = configCenterClient
.queryConfigurations(queryConfigurationsRequest, addressManager.address());
if (response.isChanged()) {
configConverter.updateData(response.getConfigurations());
}
queryConfigurationsRequest.setRevision(response.getRevision());
firstPull(bootstrapProperties.getConfigBootstrapProperties(), configCenterClient, queryConfigurationsRequest,
addressManager);
ConfigCenterConfiguration configCenterConfiguration = createConfigCenterConfiguration(
bootstrapProperties.getConfigBootstrapProperties());
ConfigCenterManager configCenterManager = new ConfigCenterManager(configCenterClient, EventManager.getEventBus(),
Expand All @@ -168,6 +164,43 @@ private void initServiceCenterConfig(BootstrapProperties bootstrapProperties,
configCenterManager.startConfigCenterManager();
}

public void firstPull(ConfigBootstrapProperties configProperties, ConfigCenterClient configCenterClient,
QueryConfigurationsRequest queryConfigurationsRequest, ConfigCenterAddressManager addressManager) {
try {
firstQueryConfigurations(configCenterClient, queryConfigurationsRequest, addressManager);
} catch (Exception e) {
if (configProperties.isFirstPullRequired()) {
throw e;
} else {
LOGGER.warn("first pull failed!");
}
}
}

private void firstQueryConfigurations(ConfigCenterClient configCenterClient, QueryConfigurationsRequest queryConfigurationsRequest,
ConfigCenterAddressManager addressManager) {
int index = 0;
while (index < 3) {
String address = addressManager.address();
try {
QueryConfigurationsResponse response = configCenterClient.queryConfigurations(queryConfigurationsRequest,
address);
if (response.isChanged()) {
configConverter.updateData(response.getConfigurations());
}
queryConfigurationsRequest.setRevision(response.getRevision());
break;
} catch (Exception e) {
if (index == 2) {
throw e;
}
LOGGER.warn("config-center firstQueryConfigurations failed, config address {} and ignore {}", address,
e.getMessage());
}
index++;
}
}

private ConfigCenterConfiguration createConfigCenterConfiguration(ConfigBootstrapProperties configProperties) {
ConfigCenterConfiguration configCenterConfiguration = new ConfigCenterConfiguration();
configCenterConfiguration.setRefreshIntervalInMillis(configProperties.getConfigCenter().getRefreshInterval());
Expand Down

0 comments on commit bb21403

Please sign in to comment.