Merge branch '4.0.x'
This commit is contained in:
@@ -265,8 +265,23 @@ public class ConfigServerConfigDataLoader implements ConfigDataLoader<ConfigServ
|
||||
String name = properties.getName();
|
||||
String profile = resource.getProfiles();
|
||||
String token = properties.getToken();
|
||||
int noOfUrls = properties.getUri().length;
|
||||
if (noOfUrls > 1) {
|
||||
String[] uris;
|
||||
boolean discoveryEnabled = properties.getDiscovery().isEnabled();
|
||||
ConfigClientProperties bootstrapConfigClientProperties = context.getBootstrapContext()
|
||||
.get(ConfigClientProperties.class);
|
||||
// In the case where discovery is enabled we need to extract the config server
|
||||
// uris, username, and password
|
||||
// from the properties from the context. These are set in
|
||||
// ConfigServerInstanceMonitor.refresh which will only
|
||||
// be called the first time we fetch configuration.
|
||||
if (discoveryEnabled) {
|
||||
uris = bootstrapConfigClientProperties.getUri();
|
||||
}
|
||||
else {
|
||||
uris = properties.getUri();
|
||||
}
|
||||
int noOfUrls = uris.length;
|
||||
if (uris.length > 1) {
|
||||
logger.info("Multiple Config Server Urls found listed.");
|
||||
}
|
||||
|
||||
@@ -284,10 +299,19 @@ public class ConfigServerConfigDataLoader implements ConfigDataLoader<ConfigServ
|
||||
.get(ConfigClientRequestTemplateFactory.class);
|
||||
|
||||
for (int i = 0; i < noOfUrls; i++) {
|
||||
ConfigClientProperties.Credentials credentials = properties.getCredentials(i);
|
||||
String uri = credentials.getUri();
|
||||
String username = credentials.getUsername();
|
||||
String password = credentials.getPassword();
|
||||
String username;
|
||||
String password;
|
||||
String uri = uris[i];
|
||||
if (discoveryEnabled) {
|
||||
password = bootstrapConfigClientProperties.getPassword();
|
||||
username = bootstrapConfigClientProperties.getUsername();
|
||||
}
|
||||
else {
|
||||
ConfigClientProperties.Credentials credentials = properties.getCredentials(i);
|
||||
uri = credentials.getUri();
|
||||
username = credentials.getUsername();
|
||||
password = credentials.getPassword();
|
||||
}
|
||||
|
||||
logger.info("Fetching config from server at : " + uri);
|
||||
|
||||
|
||||
@@ -412,6 +412,28 @@ public class ConfigServerConfigDataLoaderTests {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void useDiscoveryUriIfEnabled() throws Exception {
|
||||
String[] uris = new String[] { "http://uritest:8888" };
|
||||
properties.setUri(uris);
|
||||
ConfigClientProperties.Discovery discovery = new ConfigClientProperties.Discovery();
|
||||
discovery.setEnabled(true);
|
||||
discovery.setServiceId("configservice");
|
||||
properties.setDiscovery(discovery);
|
||||
this.loader = new ConfigServerConfigDataLoader(destination -> logger);
|
||||
ClientHttpRequestFactory requestFactory = mock(ClientHttpRequestFactory.class);
|
||||
RestTemplate restTemplate = new RestTemplate(requestFactory);
|
||||
when(bootstrapContext.get(RestTemplate.class)).thenReturn(restTemplate);
|
||||
ConfigClientProperties bootstrapConfigClientProperties = new ConfigClientProperties();
|
||||
bootstrapConfigClientProperties.setDiscovery(discovery);
|
||||
bootstrapConfigClientProperties.setUri(new String[] { "http://configservice:8888" });
|
||||
when(bootstrapContext.get(ConfigClientProperties.class)).thenReturn(bootstrapConfigClientProperties);
|
||||
|
||||
mockRequestResponse(requestFactory, "http://configservice:8888", HttpStatus.OK);
|
||||
|
||||
assertThat(this.loader.load(context, resource)).isNotNull();
|
||||
}
|
||||
|
||||
@Disabled
|
||||
@Test
|
||||
// TODO Enable once we have
|
||||
|
||||
Reference in New Issue
Block a user