Adjust CloudFoundryDiscoveryClient to DiscoveryClient ordering functionality
in spring-cloud-commons.
This commit is contained in:
@@ -30,23 +30,28 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Cloud Foundry maintains a registry of running applications which we expose here as CloudFoundryService instances.
|
||||
* Cloud Foundry maintains a registry of running applications which we expose here as
|
||||
* CloudFoundryService instances.
|
||||
*
|
||||
* @author Josh Long
|
||||
* @author Spencer Gibb
|
||||
* @author Dave Syer
|
||||
* @author Olga Maciaszek-Sharma
|
||||
*/
|
||||
public class CloudFoundryDiscoveryClient implements DiscoveryClient {
|
||||
|
||||
private final CloudFoundryService cloudFoundryService;
|
||||
private final CloudFoundryOperations cloudFoundryOperations;
|
||||
private final CloudFoundryDiscoveryClientConfig discoveryClientConfig;
|
||||
|
||||
private final String description = "Cloud Foundry " + DiscoveryClient.class.getName() + " implementation";
|
||||
|
||||
CloudFoundryDiscoveryClient(CloudFoundryOperations cloudFoundryOperations,
|
||||
CloudFoundryService svc) {
|
||||
CloudFoundryService svc,
|
||||
CloudFoundryDiscoveryClientConfig discoveryClientConfig) {
|
||||
this.cloudFoundryService = svc;
|
||||
this.cloudFoundryOperations = cloudFoundryOperations;
|
||||
this.discoveryClientConfig = discoveryClientConfig;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -89,4 +94,9 @@ public class CloudFoundryDiscoveryClient implements DiscoveryClient {
|
||||
.blockOptional()
|
||||
.orElse(new ArrayList<>());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return discoveryClientConfig.getOrder();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package org.springframework.cloud.cloudfoundry.discovery;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
/**
|
||||
* Properties used for configuring the CloudFoundry implementation of
|
||||
* {@link org.springframework.cloud.client.discovery.DiscoveryClient}
|
||||
*
|
||||
* @author Olga Maciaszek-Sharma
|
||||
*/
|
||||
@ConfigurationProperties("spring.cloud.discovery.client.cloudfoundry")
|
||||
public class CloudFoundryDiscoveryClientConfig {
|
||||
|
||||
private int order;
|
||||
|
||||
public int getOrder() {
|
||||
return order;
|
||||
}
|
||||
|
||||
public void setOrder(int order) {
|
||||
this.order = order;
|
||||
}
|
||||
}
|
||||
@@ -34,11 +34,17 @@ import org.springframework.context.annotation.Configuration;
|
||||
@EnableConfigurationProperties(CloudFoundryDiscoveryProperties.class)
|
||||
public class CloudFoundryDiscoveryClientConfiguration {
|
||||
|
||||
@Bean
|
||||
public CloudFoundryDiscoveryClientConfig cloudFoundryDiscoveryClientConfig() {
|
||||
return new CloudFoundryDiscoveryClientConfig();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(CloudFoundryDiscoveryClient.class)
|
||||
public CloudFoundryDiscoveryClient cloudFoundryDiscoveryClient(
|
||||
CloudFoundryOperations cf, CloudFoundryService svc) {
|
||||
return new CloudFoundryDiscoveryClient(cf, svc);
|
||||
CloudFoundryOperations cf, CloudFoundryService svc,
|
||||
CloudFoundryDiscoveryClientConfig discoveryClientConfig) {
|
||||
return new CloudFoundryDiscoveryClient(cf, svc, discoveryClientConfig);
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -54,7 +54,8 @@ public class CloudFoundryDiscoveryClientTest {
|
||||
public void setUp() {
|
||||
this.ops = mock(CloudFoundryOperations.class);
|
||||
this.svc = mock(CloudFoundryService.class);
|
||||
this.cloudFoundryDiscoveryClient = new CloudFoundryDiscoveryClient(this.ops, this.svc);
|
||||
this.cloudFoundryDiscoveryClient = new CloudFoundryDiscoveryClient(this.ops, this.svc,
|
||||
new CloudFoundryDiscoveryClientConfig());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user