Search in sources :

Example 1 with HealthService

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)));
    }
}
Also used : DefaultServiceInstance(org.springframework.cloud.client.DefaultServiceInstance) HealthService(com.ecwid.consul.v1.health.model.HealthService) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with HealthService

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);
}
Also used : HealthService(com.ecwid.consul.v1.health.model.HealthService) Check(com.ecwid.consul.v1.health.model.Check) ArrayList(java.util.ArrayList) HealthService(com.ecwid.consul.v1.health.model.HealthService)

Example 3 with 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);
}
Also used : DefaultServiceInstance(org.springframework.cloud.client.DefaultServiceInstance) HealthService(com.ecwid.consul.v1.health.model.HealthService) DefaultServiceInstance(org.springframework.cloud.client.DefaultServiceInstance) ServiceInstance(org.springframework.cloud.client.ServiceInstance)

Example 4 with HealthService

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;
}
Also used : NewService(com.ecwid.consul.v1.agent.model.NewService) HealthService(com.ecwid.consul.v1.health.model.HealthService) ConsulService(com.weibo.api.motan.registry.consul.ConsulService) Service(com.ecwid.consul.v1.health.model.HealthService.Service) ConsulService(com.weibo.api.motan.registry.consul.ConsulService)

Example 5 with HealthService

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;
}
Also used : HealthService(com.ecwid.consul.v1.health.model.HealthService) ArrayList(java.util.ArrayList)

Aggregations

HealthService (com.ecwid.consul.v1.health.model.HealthService)6 ArrayList (java.util.ArrayList)4 ConsulService (com.weibo.api.motan.registry.consul.ConsulService)2 List (java.util.List)2 DefaultServiceInstance (org.springframework.cloud.client.DefaultServiceInstance)2 QueryParams (com.ecwid.consul.v1.QueryParams)1 NewService (com.ecwid.consul.v1.agent.model.NewService)1 Check (com.ecwid.consul.v1.health.model.Check)1 Service (com.ecwid.consul.v1.health.model.HealthService.Service)1 ServiceInstance (org.springframework.cloud.client.ServiceInstance)1