use of com.ecwid.consul.v1.health.model.HealthService in project spring-cloud-consul by spring-cloud.
the class ConsulDiscoveryClient method addInstancesToList.
private void addInstancesToList(List<ServiceInstance> instances, String serviceId, QueryParams queryParams) {
String aclToken = properties.getAclToken();
Response<List<HealthService>> services;
if (StringUtils.hasText(aclToken)) {
services = client.getHealthServices(serviceId, this.properties.getDefaultQueryTag(), this.properties.isQueryPassing(), queryParams, aclToken);
} else {
services = client.getHealthServices(serviceId, this.properties.getDefaultQueryTag(), this.properties.isQueryPassing(), queryParams);
}
for (HealthService service : services.getValue()) {
String host = findHost(service);
instances.add(new DefaultServiceInstance(serviceId, host, service.getService().getPort(), false, getMetadata(service)));
}
}
use of com.ecwid.consul.v1.health.model.HealthService in project spring-cloud-consul by spring-cloud.
the class HealthServiceServerListFilterTests method newServer.
private ConsulServer newServer(Check.CheckStatus checkStatus) {
HealthService healthService = new HealthService();
HealthService.Node node = new HealthService.Node();
node.setAddress("nodeaddr" + checkStatus.name());
node.setNode("nodenode" + checkStatus.name());
healthService.setNode(node);
HealthService.Service service = new HealthService.Service();
service.setAddress("serviceaddr" + checkStatus.name());
service.setId("serviceid" + checkStatus.name());
service.setPort(8080);
service.setService("serviceservice" + checkStatus.name());
healthService.setService(service);
ArrayList<Check> checks = new ArrayList<>();
Check check = new Check();
check.setStatus(checkStatus);
checks.add(check);
healthService.setChecks(checks);
return new ConsulServer(healthService);
}
use of com.ecwid.consul.v1.health.model.HealthService in project RestyPass by darren-fu.
the class CloudConsulServerContext method getServiceInstances.
@Override
protected List<ServerInstance> getServiceInstances(String serviceName) {
List<ServiceInstance> instances = new ArrayList<>();
Response<List<HealthService>> healthServices = consulClient.getHealthServices(serviceName, true, QueryParams.DEFAULT);
for (HealthService healthService : healthServices.getValue()) {
if (isPassingChecks(healthService)) {
String host = findHost(healthService);
instances.add(new DefaultServiceInstance(serviceName, host, healthService.getService().getPort(), false, getMetadata(healthService)));
}
}
return convertToServerInstanceList(instances);
}
use of com.ecwid.consul.v1.health.model.HealthService in project motan by weibocom.
the class ConsulEcwidClient method convertToConsulService.
private ConsulService convertToConsulService(HealthService healthService) {
ConsulService service = new ConsulService();
Service org = healthService.getService();
service.setAddress(org.getAddress());
service.setId(org.getId());
service.setName(org.getService());
service.setPort(org.getPort());
service.setTags(org.getTags());
return service;
}
use of com.ecwid.consul.v1.health.model.HealthService in project spring-cloud-consul by spring-cloud.
the class ConsulServerList method transformResponse.
/**
* Transforms the response from Consul in to a list of usable {@link ConsulServer}s.
*
* @param healthServices the initial list of servers from Consul. Guaranteed to be non-empty list
* @return ConsulServer instances
* @see ConsulServer#ConsulServer(HealthService)
*/
protected List<ConsulServer> transformResponse(List<HealthService> healthServices) {
List<ConsulServer> servers = new ArrayList<>();
for (HealthService service : healthServices) {
ConsulServer server = new ConsulServer(service);
if (server.getMetadata().containsKey(this.properties.getDefaultZoneMetadataName())) {
server.setZone(server.getMetadata().get(this.properties.getDefaultZoneMetadataName()));
}
servers.add(server);
}
return servers;
}
Aggregations