APIClient: Support for non pull APIMeter
APIMeter will be modified not to use pulling and to retrieve the derived information from the API. To support that the APIClient was changed so it would be able to cache json objects and histogram. Signed-off-by: Amnon Heiman <amnon@scylladb.com>
This commit is contained in:
parent
a028e59699
commit
adf466519f
@ -64,6 +64,14 @@ public class APIClient {
|
|||||||
return (value!= null && value.valid(duration))? value.stringValue() : null;
|
return (value!= null && value.valid(duration))? value.stringValue() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JsonObject getJsonObjectFromCache(String key, long duration) {
|
||||||
|
if (key == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
CacheEntry value = cache.get(key);
|
||||||
|
return (value!= null && value.valid(duration))? value.jsonObject() : null;
|
||||||
|
}
|
||||||
|
|
||||||
EstimatedHistogram getEstimatedHistogramFromCache(String key, long duration) {
|
EstimatedHistogram getEstimatedHistogramFromCache(String key, long duration) {
|
||||||
if (key == null) {
|
if (key == null) {
|
||||||
return null;
|
return null;
|
||||||
@ -654,20 +662,30 @@ public class APIClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public JsonObject getJsonObj(String string,
|
public JsonObject getJsonObj(String string,
|
||||||
MultivaluedMap<String, String> queryParams) {
|
MultivaluedMap<String, String> queryParams, long duration) {
|
||||||
if (string.equals("")) {
|
if (string.equals("")) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
JsonReader reader = getReader(string, queryParams);
|
String key = getCacheKey(string, queryParams, duration);
|
||||||
JsonObject res = reader.readObject();
|
JsonObject res = getJsonObjectFromCache(key, duration);
|
||||||
reader.close();
|
if (res != null) {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
JsonReader reader = getReader(string, queryParams);
|
||||||
public HistogramValues getHistogramValue(String url,
|
res = reader.readObject();
|
||||||
|
reader.close();
|
||||||
|
if (duration > 0) {
|
||||||
|
cache.put(key, new CacheEntry(res));
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
public JsonObject getJsonObj(String string,
|
||||||
MultivaluedMap<String, String> queryParams) {
|
MultivaluedMap<String, String> queryParams) {
|
||||||
|
return getJsonObj(string, queryParams, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HistogramValues json2histogram(JsonObject obj) {
|
||||||
HistogramValues res = new HistogramValues();
|
HistogramValues res = new HistogramValues();
|
||||||
JsonObject obj = getJsonObj(url, queryParams);
|
|
||||||
res.count = obj.getJsonNumber("count").longValue();
|
res.count = obj.getJsonNumber("count").longValue();
|
||||||
res.max = obj.getJsonNumber("max").longValue();
|
res.max = obj.getJsonNumber("max").longValue();
|
||||||
res.min = obj.getJsonNumber("min").longValue();
|
res.min = obj.getJsonNumber("min").longValue();
|
||||||
@ -684,6 +702,11 @@ public class APIClient {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public HistogramValues getHistogramValue(String url,
|
||||||
|
MultivaluedMap<String, String> queryParams) {
|
||||||
|
return json2histogram(getJsonObj(url, queryParams));
|
||||||
|
}
|
||||||
|
|
||||||
public HistogramValues getHistogramValue(String url) {
|
public HistogramValues getHistogramValue(String url) {
|
||||||
return getHistogramValue(url, null);
|
return getHistogramValue(url, null);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user