Remove netflix dependencies

There's no need to depend on netflix libraries but the sample was
using Ribbon, so we took that out so that the release can be
independent.
This commit is contained in:
Dave Syer
2016-04-18 11:57:27 +01:00
parent d8aa50eb85
commit bdd196bda3
10 changed files with 192 additions and 216 deletions

View File

@@ -58,8 +58,8 @@ import com.fasterxml.jackson.databind.ObjectMapper;
* CloudFoundryClient cloudFoundryClient(
* @Value("${MY_CUSTOM_CF_API:https://api.run.pivotal.io}") String api,
* CloudCredentials cc) throws MalformedURLException {
* CloudFoundryClient cloudFoundryClient = new CloudFoundryClient(cc, URI.create(api)
* .toURL());
* CloudFoundryClient cloudFoundryClient = new CloudFoundryClient(cc,
* URI.create(api).toURL());
* cloudFoundryClient.login();
* return cloudFoundryClient;
* }
@@ -123,23 +123,22 @@ public class CloudFoundryDiscoveryClient implements DiscoveryClient {
try {
CloudApplication application = this.cloudFoundryClient
.getApplication(this.vcapApplicationName);
serviceInstances = this
.createServiceInstancesFromCloudApplications(Collections
.singletonList(application));
serviceInstances = this.createServiceInstancesFromCloudApplications(
Collections.singletonList(application));
}
catch (Exception e) {
log.warn("Could not determine local service instance: " + e.getClass() + " ("
+ e.getMessage() + ")");
}
return serviceInstances != null && serviceInstances.size() > 0 ? serviceInstances
.iterator().next() : null;
return serviceInstances != null && serviceInstances.size() > 0
? serviceInstances.iterator().next() : null;
}
@Override
public List<ServiceInstance> getInstances(String s) {
CloudApplication applications = this.cloudFoundryClient.getApplication(s);
return this.createServiceInstancesFromCloudApplications(Collections
.singletonList(applications));
return this.createServiceInstancesFromCloudApplications(
Collections.singletonList(applications));
}
private boolean isRunning(CloudApplication ca) {
@@ -192,7 +191,9 @@ public class CloudFoundryDiscoveryClient implements DiscoveryClient {
}
public CloudFoundryServiceInstance(CloudApplication ca) {
super(ca.getName(), ca.getUris().iterator().next(), 80, false);
super(ca.getName(),
ca.getUris().isEmpty() ? "localhost" : ca.getUris().iterator().next(),
80, false);
this.cloudApplication = ca;
}

View File

@@ -40,21 +40,29 @@ import org.springframework.core.env.Environment;
public class CloudFoundryDiscoveryClientConfiguration {
@Autowired
private CloudFoundryDiscoveryProperties cloudFoundryDiscoveryProperties;
private CloudFoundryDiscoveryProperties discovery;
@Bean
@ConditionalOnMissingBean(CloudCredentials.class)
public CloudCredentials cloudCredentials() {
return new CloudCredentials(this.cloudFoundryDiscoveryProperties.getEmail(),
this.cloudFoundryDiscoveryProperties.getPassword());
return new CloudCredentials(this.discovery.getEmail(),
this.discovery.getPassword());
}
@Bean
@ConditionalOnMissingBean(CloudFoundryClient.class)
public CloudFoundryClient cloudFoundryClient(CloudCredentials cc)
throws MalformedURLException {
CloudFoundryClient cloudFoundryClient = new CloudFoundryClient(cc, URI.create(
this.cloudFoundryDiscoveryProperties.getUrl()).toURL());
CloudFoundryClient cloudFoundryClient;
if (discovery.getOrg() != null && discovery.getSpace() != null) {
cloudFoundryClient = new CloudFoundryClient(cc,
URI.create(this.discovery.getUrl()).toURL(), discovery.getOrg(),
discovery.getSpace());
}
else {
cloudFoundryClient = new CloudFoundryClient(cc,
URI.create(this.discovery.getUrl()).toURL());
}
cloudFoundryClient.login();
return cloudFoundryClient;
}

View File

@@ -39,6 +39,16 @@ public class CloudFoundryDiscoveryProperties {
*/
private String password;
/**
* Organization name to authenticate with (default to user's default).
*/
private String org;
/**
* Space name to authenticate with (default to user's default).
*/
private String space;
/**
* Flag to indicate that discovery is enabled.
*/
@@ -75,4 +85,20 @@ public class CloudFoundryDiscoveryProperties {
public void setPassword(String password) {
this.password = password;
}
public String getOrg() {
return org;
}
public void setOrg(String org) {
this.org = org;
}
public String getSpace() {
return space;
}
public void setSpace(String space) {
this.space = space;
}
}