Merge branch 'master' into consul-client
Conflicts: spring-cloud-consul-core/pom.xml spring-cloud-consul-core/src/main/java/org/springframework/cloud/consul/client/EventService.java spring-cloud-consul-core/src/main/java/org/springframework/cloud/consul/model/Event.java spring-cloud-consul-core/src/main/java/org/springframework/cloud/consul/model/KeyValue.java spring-cloud-consul-core/src/test/java/org/springframework/cloud/consul/client/AgentClientIT.java spring-cloud-consul-discovery/pom.xml spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/ConsulDiscoveryClient.java spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/ConsulLoadBalancerClient.java spring-cloud-consul-discovery/src/main/java/org/springframework/cloud/consul/discovery/ConsulServerList.java
This commit is contained in:
5
pom.xml
5
pom.xml
@@ -170,11 +170,6 @@
|
||||
<version>1.12.6</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<version>18.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
|
||||
@@ -35,10 +35,6 @@
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
||||
@@ -35,10 +35,6 @@
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
||||
@@ -44,10 +44,6 @@
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
||||
@@ -47,14 +47,6 @@
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
||||
@@ -1,20 +1,16 @@
|
||||
package org.springframework.cloud.consul.discovery;
|
||||
|
||||
import com.ecwid.consul.v1.ConsulClient;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Lists;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cloud.client.DefaultServiceInstance;
|
||||
import org.springframework.cloud.client.ServiceInstance;
|
||||
import org.springframework.cloud.client.discovery.DiscoveryClient;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.google.common.collect.Iterables.*;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
@@ -33,7 +29,7 @@ public class ConsulDiscoveryClient implements DiscoveryClient {
|
||||
|
||||
@Override
|
||||
public ServiceInstance getLocalServiceInstance() {
|
||||
/*Map<String, Service> services = agentClient.getServices();
|
||||
/*FIXME: Map<String, Service> services = agentClient.getServices();
|
||||
Service service = services.get(context.getId());
|
||||
if (service == null) {
|
||||
throw new IllegalStateException("Unable to locate service in consul agent: "+context.getId());
|
||||
@@ -52,42 +48,32 @@ public class ConsulDiscoveryClient implements DiscoveryClient {
|
||||
|
||||
@Override
|
||||
public List<ServiceInstance> getInstances(final String serviceId) {
|
||||
/*List<ServiceNode> nodes = catalogClient.getServiceNodes(serviceId);
|
||||
Iterable<ServiceInstance> instances = transform(nodes, new Function<ServiceNode, ServiceInstance>() {
|
||||
@Nullable
|
||||
@Override
|
||||
public ServiceInstance apply(@Nullable ServiceNode node) {
|
||||
return new DefaultServiceInstance(serviceId, node.getNode(), node.getServicePort());
|
||||
}
|
||||
});
|
||||
//FIXME: List<ServiceNode> nodes = catalogClient.getServiceNodes(serviceId);
|
||||
List<ServiceInstance> instances = new ArrayList<>();
|
||||
/*for (ServiceNode node : nodes) {
|
||||
instances.add(new DefaultServiceInstance(serviceId, node.getNode(), node.getServicePort()));
|
||||
}*/
|
||||
|
||||
return Lists.newArrayList(instances);*/
|
||||
return Lists.newArrayList();
|
||||
return instances;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ServiceInstance> getAllInstances() {
|
||||
/*Iterable<ServiceInstance> instances = transform(concat(transform(catalogClient.getServices().keySet(), new Function<String, List<ServiceNode>>() {
|
||||
@Nullable
|
||||
@Override
|
||||
public List<ServiceNode> apply(@Nullable String input) {
|
||||
return catalogClient.getServiceNodes(input);
|
||||
}
|
||||
})), new Function<ServiceNode, ServiceInstance>() {
|
||||
@Nullable
|
||||
@Override
|
||||
public ServiceInstance apply(@Nullable ServiceNode input) {
|
||||
return new DefaultServiceInstance(input.getServiceName(), input.getNode(), input.getServicePort());
|
||||
}
|
||||
});
|
||||
List<ServiceInstance> instances = new ArrayList<>();
|
||||
|
||||
return Lists.newArrayList(instances);*/
|
||||
return Lists.newArrayList();
|
||||
/*FIXME: for (String serviceId : catalogClient.getServices().keySet()) {
|
||||
List<ServiceNode> serviceNodes = catalogClient.getServiceNodes(serviceId);
|
||||
if (serviceNodes != null) {
|
||||
for (ServiceNode node : serviceNodes) {
|
||||
instances.add(new DefaultServiceInstance(node.getServiceName(), node.getNode(), node.getServicePort()));
|
||||
}
|
||||
}
|
||||
}*/
|
||||
return instances;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getServices() {
|
||||
//return Lists.newArrayList(catalogClient.getServices().keySet());
|
||||
return Lists.newArrayList();
|
||||
return new ArrayList<>();//FIXME: catalogClient.getServices().keySet());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package org.springframework.cloud.consul.discovery;
|
||||
|
||||
import com.ecwid.consul.v1.ConsulClient;
|
||||
import com.google.common.base.Throwables;
|
||||
import com.netflix.client.config.DefaultClientConfigImpl;
|
||||
import com.netflix.client.config.IClientConfig;
|
||||
import com.netflix.loadbalancer.*;
|
||||
@@ -15,6 +14,8 @@ import org.springframework.web.util.UriComponentsBuilder;
|
||||
import java.net.URI;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import static org.springframework.util.ReflectionUtils.rethrowRuntimeException;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
@@ -57,7 +58,7 @@ public class ConsulLoadBalancerClient implements LoadBalancerClient {
|
||||
try {
|
||||
return request.apply(choose(serviceId));
|
||||
} catch (Exception e) {
|
||||
Throwables.propagate(e);
|
||||
rethrowRuntimeException(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,18 +4,13 @@ import com.ecwid.consul.v1.ConsulClient;
|
||||
import com.ecwid.consul.v1.QueryParams;
|
||||
import com.ecwid.consul.v1.Response;
|
||||
import com.ecwid.consul.v1.catalog.model.CatalogService;
|
||||
import com.google.common.base.Function;
|
||||
import com.netflix.client.config.IClientConfig;
|
||||
import com.netflix.loadbalancer.AbstractServerList;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static com.google.common.collect.Collections2.transform;
|
||||
import static com.google.common.collect.Lists.newArrayList;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
@@ -60,15 +55,13 @@ public class ConsulServerList extends AbstractServerList<ConsulServer> {
|
||||
if (response.getValue() == null || response.getValue().isEmpty()) {
|
||||
return Collections.EMPTY_LIST;
|
||||
}
|
||||
Collection<ConsulServer> servers = transform(response.getValue(), new Function<CatalogService, ConsulServer>() {
|
||||
@Nullable
|
||||
@Override
|
||||
public ConsulServer apply(@Nullable CatalogService service) {
|
||||
ConsulServer server = new ConsulServer(service);
|
||||
return server;
|
||||
}
|
||||
});
|
||||
|
||||
return newArrayList(servers);
|
||||
List<ConsulServer> servers = new ArrayList<>();
|
||||
for (ServiceNode node : nodes) {
|
||||
ConsulServer server = new ConsulServer(node);
|
||||
servers.add(server);
|
||||
}
|
||||
|
||||
return servers;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,10 +52,6 @@
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user