Merge pull request #27 from OlgaMaciaszek/gh-304-add-discovery-clients-order-support
Gh 304 add discovery clients order support
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 CloudFoundryDiscoveryProperties cloudFoundryDiscoveryProperties;
|
||||
|
||||
private final String description = "Cloud Foundry " + DiscoveryClient.class.getName() + " implementation";
|
||||
|
||||
CloudFoundryDiscoveryClient(CloudFoundryOperations cloudFoundryOperations,
|
||||
CloudFoundryService svc) {
|
||||
CloudFoundryService svc,
|
||||
CloudFoundryDiscoveryProperties cloudFoundryDiscoveryProperties) {
|
||||
this.cloudFoundryService = svc;
|
||||
this.cloudFoundryOperations = cloudFoundryOperations;
|
||||
this.cloudFoundryDiscoveryProperties = cloudFoundryDiscoveryProperties;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -89,4 +94,9 @@ public class CloudFoundryDiscoveryClient implements DiscoveryClient {
|
||||
.blockOptional()
|
||||
.orElse(new ArrayList<>());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return this.cloudFoundryDiscoveryProperties.getOrder();
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.springframework.cloud.cloudfoundry.discovery;
|
||||
|
||||
import org.cloudfoundry.operations.CloudFoundryOperations;
|
||||
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
@@ -37,8 +38,9 @@ public class CloudFoundryDiscoveryClientConfiguration {
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(CloudFoundryDiscoveryClient.class)
|
||||
public CloudFoundryDiscoveryClient cloudFoundryDiscoveryClient(
|
||||
CloudFoundryOperations cf, CloudFoundryService svc) {
|
||||
return new CloudFoundryDiscoveryClient(cf, svc);
|
||||
CloudFoundryOperations cf, CloudFoundryService svc,
|
||||
CloudFoundryDiscoveryProperties cloudFoundryDiscoveryProperties) {
|
||||
return new CloudFoundryDiscoveryClient(cf, svc, cloudFoundryDiscoveryProperties);
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright 2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.cloudfoundry.discovery;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.core.Ordered;
|
||||
|
||||
/**
|
||||
* 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 CloudFoundryDiscoveryClientProperties {
|
||||
|
||||
private int order = Ordered.LOWEST_PRECEDENCE;
|
||||
|
||||
public int getOrder() {
|
||||
return this.order;
|
||||
}
|
||||
|
||||
public void setOrder(int order) {
|
||||
this.order = order;
|
||||
}
|
||||
}
|
||||
@@ -40,6 +40,11 @@ public class CloudFoundryDiscoveryProperties {
|
||||
*/
|
||||
private int defaultServerPort = 80;
|
||||
|
||||
/**
|
||||
* Order of the discovery client used by `CompositeDiscoveryClient` for sorting available clients.
|
||||
*/
|
||||
private int order = 0;
|
||||
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
@@ -64,12 +69,21 @@ public class CloudFoundryDiscoveryProperties {
|
||||
this.defaultServerPort = defaultServerPort;
|
||||
}
|
||||
|
||||
public int getOrder() {
|
||||
return order;
|
||||
}
|
||||
|
||||
public void setOrder(int order) {
|
||||
this.order = order;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CloudFoundryDiscoveryProperties{" +
|
||||
"enabled=" + enabled +
|
||||
", heartbeatFrequency=" + heartbeatFrequency +
|
||||
", defaultServerPort=" + defaultServerPort +
|
||||
", order=" + order +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 CloudFoundryDiscoveryProperties());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user