Search in sources :

Example 1 with ConsulService

use of com.weibo.api.motan.registry.consul.ConsulService 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 2 with ConsulService

use of com.weibo.api.motan.registry.consul.ConsulService in project motan by weibocom.

the class ConsulEcwidClient method lookupHealthService.

@Override
public ConsulResponse<List<ConsulService>> lookupHealthService(String serviceName, long lastConsulIndex) {
    QueryParams queryParams = new QueryParams(ConsulConstants.CONSUL_BLOCK_TIME_SECONDS, lastConsulIndex);
    Response<List<HealthService>> orgResponse = client.getHealthServices(serviceName, true, queryParams);
    ConsulResponse<List<ConsulService>> newResponse = null;
    if (orgResponse != null && orgResponse.getValue() != null && !orgResponse.getValue().isEmpty()) {
        List<HealthService> HealthServices = orgResponse.getValue();
        List<ConsulService> ConsulServices = new ArrayList<ConsulService>(HealthServices.size());
        for (HealthService orgService : HealthServices) {
            try {
                ConsulService newService = convertToConsulService(orgService);
                ConsulServices.add(newService);
            } catch (Exception e) {
                String servcieid = "null";
                if (orgService.getService() != null) {
                    servcieid = orgService.getService().getId();
                }
                LoggerUtil.error("convert consul service fail. org consulservice:" + servcieid, e);
            }
        }
        if (!ConsulServices.isEmpty()) {
            newResponse = new ConsulResponse<List<ConsulService>>();
            newResponse.setValue(ConsulServices);
            newResponse.setConsulIndex(orgResponse.getConsulIndex());
            newResponse.setConsulLastContact(orgResponse.getConsulLastContact());
            newResponse.setConsulKnownLeader(orgResponse.isConsulKnownLeader());
        }
    }
    return newResponse;
}
Also used : HealthService(com.ecwid.consul.v1.health.model.HealthService) ArrayList(java.util.ArrayList) QueryParams(com.ecwid.consul.v1.QueryParams) ArrayList(java.util.ArrayList) List(java.util.List) ConsulService(com.weibo.api.motan.registry.consul.ConsulService)

Aggregations

HealthService (com.ecwid.consul.v1.health.model.HealthService)2 ConsulService (com.weibo.api.motan.registry.consul.ConsulService)2 QueryParams (com.ecwid.consul.v1.QueryParams)1 NewService (com.ecwid.consul.v1.agent.model.NewService)1 Service (com.ecwid.consul.v1.health.model.HealthService.Service)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1