Search in sources :

Example 56 with JsonArray

use of javax.json.JsonArray in project scylla-jmx by scylladb.

the class APIClient method getMapStringListStrValue.

public Map<String, List<String>> getMapStringListStrValue(String string, MultivaluedMap<String, String> queryParams) {
    if (string.equals("")) {
        return null;
    }
    JsonReader reader = getReader(string, queryParams);
    JsonArray arr = reader.readArray();
    Map<String, List<String>> map = new HashMap<String, List<String>>();
    for (int i = 0; i < arr.size(); i++) {
        JsonObject obj = arr.getJsonObject(i);
        if (obj.containsKey("key") && obj.containsKey("value")) {
            map.put(obj.getString("key"), listStrFromJArr(obj.getJsonArray("value")));
        }
    }
    reader.close();
    return map;
}
Also used : JsonArray(javax.json.JsonArray) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) JsonReader(javax.json.JsonReader) JsonObject(javax.json.JsonObject) ArrayList(java.util.ArrayList) List(java.util.List) JsonString(javax.json.JsonString)

Example 57 with JsonArray

use of javax.json.JsonArray in project scylla-jmx by scylladb.

the class CompactionHistoryTabularData method from.

public static TabularData from(JsonArray resultSet) throws OpenDataException {
    TabularDataSupport result = new TabularDataSupport(TABULAR_TYPE);
    for (int i = 0; i < resultSet.size(); i++) {
        JsonObject row = resultSet.getJsonObject(i);
        String id = row.getString("id");
        String ksName = row.getString("ks");
        String cfName = row.getString("cf");
        long compactedAt = row.getJsonNumber("compacted_at").longValue();
        long bytesIn = row.getJsonNumber("bytes_in").longValue();
        long bytesOut = row.getJsonNumber("bytes_out").longValue();
        JsonArray merged = row.getJsonArray("rows_merged");
        StringBuilder sb = new StringBuilder();
        if (merged != null) {
            sb.append('{');
            for (int m = 0; m < merged.size(); m++) {
                JsonObject entry = merged.getJsonObject(m);
                if (m > 0) {
                    sb.append(',');
                }
                sb.append(entry.getString("key")).append(':').append(entry.getString("value"));
            }
            sb.append('}');
        }
        result.put(new CompositeDataSupport(COMPOSITE_TYPE, ITEM_NAMES, new Object[] { id, ksName, cfName, compactedAt, bytesIn, bytesOut, sb.toString() }));
    }
    return result;
}
Also used : JsonArray(javax.json.JsonArray) TabularDataSupport(javax.management.openmbean.TabularDataSupport) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) JsonObject(javax.json.JsonObject) JsonObject(javax.json.JsonObject)

Example 58 with JsonArray

use of javax.json.JsonArray in project scylla-jmx by scylladb.

the class FailureDetector method getPhiValues.

@Override
public TabularData getPhiValues() throws OpenDataException {
    final CompositeType ct = new CompositeType("Node", "Node", new String[] { "Endpoint", "PHI" }, new String[] { "IP of the endpoint", "PHI value" }, new OpenType[] { SimpleType.STRING, SimpleType.DOUBLE });
    final TabularDataSupport results = new TabularDataSupport(new TabularType("PhiList", "PhiList", ct, new String[] { "Endpoint" }));
    final JsonArray arr = client.getJsonArray("/failure_detector/endpoint_phi_values");
    for (JsonValue v : arr) {
        JsonObject o = (JsonObject) v;
        String endpoint = o.getString("endpoint");
        double phi = Double.parseDouble(o.getString("phi"));
        if (phi != Double.MIN_VALUE) {
            // returned values are scaled by PHI_FACTOR so that the are on
            // the same scale as PhiConvictThreshold
            final CompositeData data = new CompositeDataSupport(ct, new String[] { "Endpoint", "PHI" }, new Object[] { endpoint, phi * PHI_FACTOR });
            results.put(data);
        }
    }
    return results;
}
Also used : JsonArray(javax.json.JsonArray) TabularDataSupport(javax.management.openmbean.TabularDataSupport) TabularType(javax.management.openmbean.TabularType) CompositeData(javax.management.openmbean.CompositeData) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) JsonValue(javax.json.JsonValue) JsonObject(javax.json.JsonObject) CompositeType(javax.management.openmbean.CompositeType)

Example 59 with JsonArray

use of javax.json.JsonArray in project scylla-jmx by scylladb.

the class MessagingService method getDroppedMessages.

/**
 * dropped message counts for server lifetime
 */
@Override
public Map<String, Integer> getDroppedMessages() {
    log(" getDroppedMessages()");
    Map<String, Integer> res = new HashMap<String, Integer>();
    JsonArray arr = client.getJsonArray("/messaging_service/messages/dropped_by_ver");
    for (int i = 0; i < arr.size(); i++) {
        JsonObject obj = arr.getJsonObject(i);
        res.put(obj.getString("verb"), obj.getInt("count"));
    }
    return res;
}
Also used : JsonArray(javax.json.JsonArray) HashMap(java.util.HashMap) JsonObject(javax.json.JsonObject)

Example 60 with JsonArray

use of javax.json.JsonArray in project scylla-jmx by scylladb.

the class StorageService method getColumnFamilyPerKeyspace.

public Map<String, Set<String>> getColumnFamilyPerKeyspace() {
    Map<String, Set<String>> res = new HashMap<String, Set<String>>();
    JsonArray mbeans = client.getJsonArray("/column_family/");
    for (int i = 0; i < mbeans.size(); i++) {
        JsonObject mbean = mbeans.getJsonObject(i);
        String ks = mbean.getString("ks");
        String cf = mbean.getString("cf");
        if (!res.containsKey(ks)) {
            res.put(ks, new HashSet<String>());
        }
        res.get(ks).add(cf);
    }
    return res;
}
Also used : JsonArray(javax.json.JsonArray) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) JsonObject(javax.json.JsonObject)

Aggregations

JsonArray (javax.json.JsonArray)128 JsonObject (javax.json.JsonObject)97 Test (org.junit.Test)42 ArrayList (java.util.ArrayList)32 JsonReader (javax.json.JsonReader)31 HashMap (java.util.HashMap)29 JsonString (javax.json.JsonString)28 HashSet (java.util.HashSet)21 NameValuePair (org.apache.commons.httpclient.NameValuePair)20 Credentials (org.apache.commons.httpclient.Credentials)19 UsernamePasswordCredentials (org.apache.commons.httpclient.UsernamePasswordCredentials)19 StringReader (java.io.StringReader)18 HttpTest (org.apache.sling.commons.testing.integration.HttpTest)17 LinkedHashMap (java.util.LinkedHashMap)14 JsonValue (javax.json.JsonValue)11 Map (java.util.Map)10 JsonException (javax.json.JsonException)9 Response (javax.ws.rs.core.Response)9 IOException (java.io.IOException)7 JerseyTest (org.glassfish.jersey.test.JerseyTest)7