use of com.recurly.v3.QueryParams in project spring-cloud-consul by spring-cloud.
the class ConsulCatalogWatch method catalogServicesWatch.
@Timed("consul.watch-catalog-services")
public void catalogServicesWatch() {
try {
long index = -1;
if (this.catalogServicesIndex.get() != null) {
index = this.catalogServicesIndex.get().longValue();
}
CatalogServicesRequest request = CatalogServicesRequest.newBuilder().setQueryParams(new QueryParams(this.properties.getCatalogServicesWatchTimeout(), index)).setToken(this.properties.getAclToken()).build();
Response<Map<String, List<String>>> response = this.consul.getCatalogServices(request);
Long consulIndex = response.getConsulIndex();
if (consulIndex != null) {
this.catalogServicesIndex.set(BigInteger.valueOf(consulIndex));
}
if (log.isTraceEnabled()) {
log.trace("Received services update from consul: " + response.getValue() + ", index: " + consulIndex);
}
this.publisher.publishEvent(new HeartbeatEvent(this, consulIndex));
} catch (Exception e) {
log.error("Error watching Consul CatalogServices", e);
}
}
use of com.recurly.v3.QueryParams in project spring-cloud-consul by spring-cloud.
the class ConsulDiscoveryClientTests method getInstancesForServiceRespectsQueryParams.
@Test
public void getInstancesForServiceRespectsQueryParams() {
Response<List<String>> catalogDatacenters = this.consulClient.getCatalogDatacenters();
List<String> dataCenterList = catalogDatacenters.getValue();
assertThat(dataCenterList.isEmpty()).as("no data centers found").isFalse();
List<ServiceInstance> instances = this.discoveryClient.getInstances("testConsulDiscovery", new QueryParams(dataCenterList.get(0)));
assertThat(instances.isEmpty()).as("instances was empty").isFalse();
ServiceInstance instance = instances.get(0);
assertIpAddress(instance);
}
use of com.recurly.v3.QueryParams in project motan by weibocom.
the class ConsulRegistryService method getGroups.
@Override
public List<String> getGroups() {
List<String> groups = new ArrayList<String>();
for (String dc : getDatacenters()) {
QueryParams queryParams = new QueryParams(dc);
Map<String, List<String>> serviceMap = consulClient.getCatalogServices(queryParams).getValue();
serviceMap.remove("consul");
for (String service : serviceMap.keySet()) {
groups.add(formatGroupName(dc, service));
}
}
return groups;
}
use of com.recurly.v3.QueryParams 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;
}
use of com.recurly.v3.QueryParams in project spring-cloud-consul by spring-cloud.
the class ConfigWatch method watchConfigKeyValues.
@Timed("consul.watch-config-keys")
public void watchConfigKeyValues() {
if (!this.running.get()) {
return;
}
for (String context : this.consulIndexes.keySet()) {
// are FILES)
if (this.properties.getFormat() != FILES && !context.endsWith("/")) {
context = context + "/";
}
try {
Long currentIndex = this.consulIndexes.get(context);
if (currentIndex == null) {
currentIndex = -1L;
}
if (log.isTraceEnabled()) {
log.trace("watching consul for context '" + context + "' with index " + currentIndex);
}
// use the consul ACL token if found
String aclToken = this.properties.getAclToken();
if (StringUtils.isEmpty(aclToken)) {
aclToken = null;
}
Response<List<GetValue>> response = this.consul.getKVValues(context, aclToken, new QueryParams(this.properties.getWatch().getWaitTime(), currentIndex));
// 200, reducing churn if there wasn't anything
if (response.getValue() != null && !response.getValue().isEmpty()) {
Long newIndex = response.getConsulIndex();
if (newIndex != null && !newIndex.equals(currentIndex)) {
// time (-1) so index can be primed
if (!this.consulIndexes.containsValue(newIndex) && !currentIndex.equals(-1L)) {
if (log.isTraceEnabled()) {
log.trace("Context " + context + " has new index " + newIndex);
}
RefreshEventData data = new RefreshEventData(context, currentIndex, newIndex);
this.publisher.publishEvent(new RefreshEvent(this, data, data.toString()));
} else if (log.isTraceEnabled()) {
log.trace("Event for index already published for context " + context);
}
this.consulIndexes.put(context, newIndex);
} else if (log.isTraceEnabled()) {
log.trace("Same index for context " + context);
}
} else if (log.isTraceEnabled()) {
log.trace("No value for context " + context);
}
} catch (Exception e) {
// only fail fast on the initial query, otherwise just log the error
if (this.firstTime && this.properties.isFailFast()) {
log.error("Fail fast is set and there was an error reading configuration from consul.");
ReflectionUtils.rethrowRuntimeException(e);
} else if (log.isTraceEnabled()) {
log.trace("Error querying consul Key/Values for context '" + context + "'", e);
} else if (log.isWarnEnabled()) {
// simplified one line log message in the event of an agent
// failure
log.warn("Error querying consul Key/Values for context '" + context + "'. Message: " + e.getMessage());
}
}
}
this.firstTime = false;
}
Aggregations