diff --git a/spring-cloud-huawei-parents/pom.xml b/spring-cloud-huawei-parents/pom.xml index 9e768b182..1a43bc1e4 100644 --- a/spring-cloud-huawei-parents/pom.xml +++ b/spring-cloud-huawei-parents/pom.xml @@ -179,7 +179,7 @@ io.fabric8 docker-maven-plugin - 0.20.0 + 0.44.0 diff --git a/spring-cloud-huawei-service-engine/service-engine-config/src/main/java/com/huaweicloud/config/ConfigService.java b/spring-cloud-huawei-service-engine/service-engine-config/src/main/java/com/huaweicloud/config/ConfigService.java index c5d7b1ccb..1763b9383 100644 --- a/spring-cloud-huawei-service-engine/service-engine-config/src/main/java/com/huaweicloud/config/ConfigService.java +++ b/spring-cloud-huawei-service-engine/service-engine-config/src/main/java/com/huaweicloud/config/ConfigService.java @@ -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(), @@ -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());