Merge "getTokenToEndpointMap should be sorted by the API" from Amnon

"This series change getTokenToEndpointMap implementation, so that the result
 will be sorted by the API.

 The API returns the tokens sorted according to their type. The APIClient helper
 method was change to keep the original order and getTokenToEndpointMap was
 change so it will return the map as is, without re-sorting it."
This commit is contained in:
Pekka Enberg 2016-12-30 14:14:48 +02:00
commit cc8f5e275b
2 changed files with 3 additions and 11 deletions

View File

@ -10,6 +10,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@ -406,7 +407,7 @@ public class APIClient {
}
JsonReader reader = getReader(string, queryParams);
JsonArray arr = reader.readArray();
Map<String, String> map = new HashMap<String, String>();
Map<String, String> map = new LinkedHashMap<String, String>();
for (int i = 0; i < arr.size(); i++) {
JsonObject obj = arr.getJsonObject(i);
if (obj.containsKey("key") && obj.containsKey("value")) {

View File

@ -371,16 +371,7 @@ public class StorageService extends MetricsMBean implements StorageServiceMBean,
@Override
public Map<String, String> getTokenToEndpointMap() {
log(" getTokenToEndpointMap()");
Map<String, String> mapInetAddress = client.getMapStrValue("/storage_service/tokens_endpoint");
// in order to preserve tokens in ascending order, we use LinkedHashMap
// here
Map<String, String> mapString = new LinkedHashMap<>(mapInetAddress.size());
List<String> tokens = new ArrayList<>(mapInetAddress.keySet());
Collections.sort(tokens);
for (String token : tokens) {
mapString.put(token, mapInetAddress.get(token));
}
return mapString;
return client.getMapStrValue("/storage_service/tokens_endpoint");
}
/** Retrieve this hosts unique ID */