Added the instance id to the DefaultServiceInstance (#28)
Should be merged after spring-cloud/spring-cloud-commons#419 NB: Maybe not the best implementation but Cloud Foundry doesn't have the notion of instance ids, only instance indexes.
This commit is contained in:
@@ -38,6 +38,7 @@ import org.springframework.cloud.cloudfoundry.CloudFoundryService;
|
||||
* @author Spencer Gibb
|
||||
* @author Dave Syer
|
||||
* @author Olga Maciaszek-Sharma
|
||||
* @author Tim Ysewyn
|
||||
*/
|
||||
public class CloudFoundryDiscoveryClient implements DiscoveryClient {
|
||||
|
||||
@@ -70,6 +71,7 @@ public class CloudFoundryDiscoveryClient implements DiscoveryClient {
|
||||
|
||||
String applicationId = applicationDetail.getId();
|
||||
String applicationIndex = instanceDetail.getIndex();
|
||||
String instanceId = applicationId + "." + applicationIndex;
|
||||
String name = applicationDetail.getName();
|
||||
String url = applicationDetail.getUrls().size() > 0
|
||||
? applicationDetail.getUrls().get(0) : null;
|
||||
@@ -79,7 +81,7 @@ public class CloudFoundryDiscoveryClient implements DiscoveryClient {
|
||||
metadata.put("applicationId", applicationId);
|
||||
metadata.put("instanceId", applicationIndex);
|
||||
|
||||
return (ServiceInstance) new DefaultServiceInstance(name, url, 80, secure,
|
||||
return (ServiceInstance) new DefaultServiceInstance(instanceId, name, url, 80, secure,
|
||||
metadata);
|
||||
}).collectList().blockOptional().orElse(new ArrayList<>());
|
||||
}
|
||||
|
||||
@@ -92,6 +92,7 @@ public class CloudFoundryDiscoveryClientTest {
|
||||
List<ServiceInstance> instances = this.cloudFoundryDiscoveryClient
|
||||
.getInstances(this.hiServiceServiceId);
|
||||
assertThat(instances.size()).as("Wrong instances: " + instances).isEqualTo(1);
|
||||
assertThat(instances.get(0).getInstanceId()).as("Wrong instance ID").isEqualTo("id.0");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user