Merge "Support the changed load_map API" from Amnon

"The storage_service api was changed to return a map of string, double instead
 of formatted numbers.  This change update the JMX proxy to support this API.

 While going over the code a potential bug was found and was fix.

 The series adds method to the APIClient to return a map of string, double and
 uses that function to call the API."
This commit is contained in:
Pekka Enberg 2015-12-30 11:31:46 +02:00
commit cd910aafa9
2 changed files with 42 additions and 4 deletions

View File

@ -576,7 +576,7 @@ public class APIClient {
if (obj.get(k) instanceof JsonString) {
key = obj.getString(k);
} else {
val = obj.getInt(k);
val = obj.getJsonNumber(k).longValue();
}
}
if (val > 0 && !key.equals("")) {
@ -692,4 +692,37 @@ public class APIClient {
public long[] getEstimatedHistogramAsLongArrValue(String string) {
return getEstimatedHistogramAsLongArrValue(string, null);
}
public Map<String, Double> getMapStringDouble(String string,
MultivaluedMap<String, String> queryParams) {
if (string.equals("")) {
return null;
}
JsonReader reader = getReader(string, queryParams);
JsonArray arr = reader.readArray();
Map<String, Double> map = new HashMap<String, Double>();
for (int i = 0; i < arr.size(); i++) {
JsonObject obj = arr.getJsonObject(i);
Iterator<String> it = obj.keySet().iterator();
String key = "";
double val = -1;
while (it.hasNext()) {
String k = it.next();
if (obj.get(k) instanceof JsonString) {
key = obj.getString(k);
} else {
val = obj.getJsonNumber(k).doubleValue();
}
}
if (!key.equals("")) {
map.put(key, val);
}
}
reader.close();
return map;
}
public Map<String, Double> getMapStringDouble(String string) {
return getMapStringDouble(string, null);
}
}

View File

@ -366,15 +366,20 @@ public class StorageService extends NotificationBroadcasterSupport
/** Human-readable load value. Keys are IP addresses. */
public Map<String, String> getLoadMap() {
log(" getLoadMap()");
Map<String, String> load = c.getMapStrValue("/storage_service/load_map");
Map<String, Double> load = getLoadMapAsDouble();
Map<String, String> map = new HashMap<>();
for (Map.Entry<String, String> entry : load.entrySet())
for (Map.Entry<String, Double> entry : load.entrySet())
{
map.put(entry.getKey(), FileUtils.stringifyFileSize(Double.parseDouble(entry.getValue())));
map.put(entry.getKey(), FileUtils.stringifyFileSize(entry.getValue()));
}
return map;
}
public Map<String, Double> getLoadMapAsDouble() {
log(" getLoadMapAsDouble()");
return c.getMapStringDouble("/storage_service/load_map");
}
/**
* Return the generation value for this node.
*