Skip to content
This repository has been archived by the owner on May 17, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1 from indeedeng/Ecwidgh-227
Browse files Browse the repository at this point in the history
support cached /health queries
  • Loading branch information
ovesh authored Oct 13, 2021
2 parents bf75a37 + bb83838 commit b485fee
Showing 1 changed file with 42 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public final class HealthServicesRequest implements ConsulRequest {
private final QueryParams queryParams;
private final String token;
private final Filter filter;
private final boolean cached;

private HealthServicesRequest(
String datacenter,
Expand All @@ -44,6 +45,29 @@ private HealthServicesRequest(
this.queryParams = queryParams;
this.token = token;
this.filter = filter;
cached = false;
}

private HealthServicesRequest(
String datacenter,
String near,
String[] tags,
Map<String, String> nodeMeta,
boolean passing,
QueryParams queryParams,
String token,
Filter filter,
boolean cached
) {
this.datacenter = datacenter;
this.near = near;
this.tags = tags;
this.nodeMeta = nodeMeta;
this.passing = passing;
this.queryParams = queryParams;
this.token = token;
this.filter = filter;
this.cached = cached;
}

public String getDatacenter() {
Expand Down Expand Up @@ -101,6 +125,7 @@ public static class Builder {
private boolean passing;
private QueryParams queryParams;
private String token;
private boolean cached;

private Builder() {
}
Expand Down Expand Up @@ -160,8 +185,16 @@ public Builder setToken(String token) {
return this;
}

/**
* Use cached queries, see https://www.consul.io/api-docs/features/caching
*/
public Builder setCached(boolean cached) {
this.cached = cached;
return this;
}

public HealthServicesRequest build() {
return new HealthServicesRequest(datacenter, near, tags, nodeMeta, passing, queryParams, token, filter);
return new HealthServicesRequest(datacenter, near, tags, nodeMeta, passing, queryParams, token, filter, cached);
}
}

Expand Down Expand Up @@ -203,6 +236,11 @@ public List<UrlParameters> asUrlParameters() {
params.add(new SingleUrlParameters("token", token));
}

if (cached) {
// any value is true
params.add(new SingleUrlParameters("cached", "1"));
}

return params;
}

Expand All @@ -222,12 +260,13 @@ public boolean equals(Object o) {
Objects.equals(filter, that.filter) &&
Objects.equals(nodeMeta, that.nodeMeta) &&
Objects.equals(queryParams, that.queryParams) &&
Objects.equals(token, that.token);
Objects.equals(token, that.token) &&
Objects.equals(cached, that.cached);
}

@Override
public int hashCode() {
int result = Objects.hash(datacenter, near, nodeMeta, passing, queryParams, token, filter);
int result = Objects.hash(datacenter, near, nodeMeta, passing, queryParams, token, filter, cached);
result = 31 * result + Arrays.hashCode(tags);
return result;
}
Expand Down

0 comments on commit b485fee

Please sign in to comment.