use of com.ecwid.consul.v1.QueryParams in project motan by weibocom.
the class ConsulRegistryService method getNodes.
@Override
public List<JSONObject> getNodes(String dcGroup, String service, String nodeType) {
List<JSONObject> results = new ArrayList<JSONObject>();
List<Check> checks = consulClient.getHealthChecksForService(getGroupName(dcGroup), new QueryParams(getDcName(dcGroup))).getValue();
for (Check check : checks) {
String serviceId = check.getServiceId();
String[] strings = serviceId.split("-");
if (strings[1].equals(service)) {
Check.CheckStatus status = check.getStatus();
JSONObject node = new JSONObject();
if (nodeType.equals(status.toString())) {
node.put("host", strings[0]);
node.put("info", null);
results.add(node);
}
}
}
return results;
}
use of com.ecwid.consul.v1.QueryParams in project spring-cloud-consul by spring-cloud.
the class EventService method watch.
public List<Event> watch(Long lastIndex) {
// TODO: parameterized or configurable watch time
long index = -1;
if (lastIndex != null) {
index = lastIndex;
}
int eventTimeout = 5;
if (properties != null) {
eventTimeout = properties.getEventTimeout();
}
Response<List<Event>> watch = consul.eventList(new QueryParams(eventTimeout, index));
return filterEvents(readEvents(watch), lastIndex);
}
use of com.ecwid.consul.v1.QueryParams in project spring-cloud-consul by spring-cloud.
the class ConsulCatalogWatch method catalogServicesWatch.
@Scheduled(fixedDelayString = "${spring.cloud.consul.discovery.catalogServicesWatchDelay:30000}")
public void catalogServicesWatch() {
try {
long index = -1;
if (catalogServicesIndex.get() != null) {
index = catalogServicesIndex.get().longValue();
}
Response<Map<String, List<String>>> response = consul.getCatalogServices(new QueryParams(properties.getCatalogServicesWatchTimeout(), index));
Long consulIndex = response.getConsulIndex();
if (consulIndex != null) {
catalogServicesIndex.set(BigInteger.valueOf(consulIndex));
}
log.trace("Received services update from consul: {}, index: {}", response.getValue(), consulIndex);
publisher.publishEvent(new HeartbeatEvent(this, consulIndex));
} catch (Exception e) {
log.error("Error watching Consul CatalogServices", e);
}
}
use of com.ecwid.consul.v1.QueryParams 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.QueryParams in project spring-cloud-consul by spring-cloud.
the class ConsulDiscoveryClientTests method getInstancesForServiceRespectsQueryParams.
@Test
public void getInstancesForServiceRespectsQueryParams() {
Response<List<String>> catalogDatacenters = consulClient.getCatalogDatacenters();
List<String> dataCenterList = catalogDatacenters.getValue();
assertFalse("no data centers found", dataCenterList.isEmpty());
List<ServiceInstance> instances = discoveryClient.getInstances("consul", new QueryParams(dataCenterList.get(0)));
assertFalse("instances was empty", instances.isEmpty());
ServiceInstance instance = instances.get(0);
assertIpAddress(instance);
}
Aggregations