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;
}
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;
}
Aggregations