Search in sources :

Example 11 with JsonArray

use of com.hazelcast.internal.json.JsonArray in project hazelcast by hazelcast.

the class ElasticCatClient method nodes.

/**
 * Returns list of nodes currently in ES cluster
 */
public List<Node> nodes() {
    try {
        Request r = new Request("GET", "/_cat/nodes");
        r.addParameter("format", "json");
        r.addParameter("full_id", "true");
        r.addParameter("h", "id,ip,name,http_address,master");
        Response res = withRetry(() -> client.performRequest(r), retries);
        try (InputStreamReader reader = new InputStreamReader(res.getEntity().getContent(), UTF_8)) {
            JsonArray array = Json.parse(reader).asArray();
            List<Node> nodes = new ArrayList<>(array.size());
            for (JsonValue value : array) {
                Optional<Node> shard = convertToNode(value);
                shard.ifPresent(nodes::add);
            }
            LOG.fine("Nodes: " + nodes);
            return nodes;
        }
    } catch (IOException e) {
        throw new JetException("Could not get ES cluster nodes", e);
    }
}
Also used : Response(org.elasticsearch.client.Response) JsonArray(com.hazelcast.internal.json.JsonArray) InputStreamReader(java.io.InputStreamReader) Request(org.elasticsearch.client.Request) ArrayList(java.util.ArrayList) JsonValue(com.hazelcast.internal.json.JsonValue) IOException(java.io.IOException) JetException(com.hazelcast.jet.JetException)

Example 12 with JsonArray

use of com.hazelcast.internal.json.JsonArray in project hazelcast by hazelcast.

the class AwsEcsApi method createBodyDescribeTasks.

private String createBodyDescribeTasks(String cluster, List<String> taskArns) {
    JsonArray jsonArray = new JsonArray();
    taskArns.stream().map(Json::value).forEach(jsonArray::add);
    return new JsonObject().add("tasks", jsonArray).add("cluster", cluster).toString();
}
Also used : JsonArray(com.hazelcast.internal.json.JsonArray) JsonObject(com.hazelcast.internal.json.JsonObject)

Example 13 with JsonArray

use of com.hazelcast.internal.json.JsonArray in project hazelcast by hazelcast.

the class MapPredicateJsonTest method testSkipsScalarValuesInCaseOfAnyAndAttributeName.

@Test
public void testSkipsScalarValuesInCaseOfAnyAndAttributeName() {
    JsonArray array1 = Json.array(new int[] { 1, 2, 3, 5000 });
    JsonArray array2 = Json.array(new int[] { 1, 5000, 3, 5 });
    JsonArray array3 = Json.array(new int[] { 1, 5000, 30, 40 });
    array1.add(Json.object().add("innerAttribute", 5000));
    JsonValue value1 = Json.object().add("arr", array1);
    JsonValue value2 = Json.object().add("arr", array2);
    JsonValue value3 = Json.object().add("arr", array3);
    IMap<String, HazelcastJsonValue> map = instance.getMap(randomMapName());
    HazelcastJsonValue p1 = putJsonString(map, "one", value1);
    putJsonString(map, "two", value2);
    putJsonString(map, "three", value3);
    Collection<HazelcastJsonValue> vals = map.values(Predicates.equal("arr[any].innerAttribute", 5000));
    assertEquals(1, vals.size());
    assertTrue(vals.contains(p1));
}
Also used : JsonArray(com.hazelcast.internal.json.JsonArray) JsonValue(com.hazelcast.internal.json.JsonValue) HazelcastJsonValue(com.hazelcast.core.HazelcastJsonValue) HazelcastJsonValue(com.hazelcast.core.HazelcastJsonValue) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 14 with JsonArray

use of com.hazelcast.internal.json.JsonArray in project hazelcast by hazelcast.

the class MapPredicateJsonTest method testArrayInNestedQuery.

@Test
public void testArrayInNestedQuery() {
    JsonObject object1 = Json.object();
    JsonObject nested1 = Json.object();
    JsonObject object2 = Json.object();
    JsonObject nested2 = Json.object();
    JsonArray array1 = Json.array(new int[] { 1, 2, 3, 4, 5, 6 });
    JsonArray array2 = Json.array(new int[] { 10, 20, 30, 40, 50, 60 });
    nested1.add("arr", array1);
    nested2.add("arr", array2);
    object1.add("inner", nested1);
    object2.add("inner", nested2);
    IMap<String, JsonValue> map = instance.getMap(randomMapName());
    HazelcastJsonValue p1 = putJsonString(map, "one", object1);
    HazelcastJsonValue p2 = putJsonString(map, "two", object2);
    Collection<JsonValue> vals = map.values(Predicates.greaterEqual("inner.arr[2]", 20));
    assertEquals(1, vals.size());
    assertTrue(vals.contains(p2));
}
Also used : JsonArray(com.hazelcast.internal.json.JsonArray) JsonValue(com.hazelcast.internal.json.JsonValue) HazelcastJsonValue(com.hazelcast.core.HazelcastJsonValue) HazelcastJsonValue(com.hazelcast.core.HazelcastJsonValue) JsonObject(com.hazelcast.internal.json.JsonObject) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 15 with JsonArray

use of com.hazelcast.internal.json.JsonArray in project hazelcast by hazelcast.

the class MapPredicateJsonTest method testQueryOnArrayIndex.

@Test
public void testQueryOnArrayIndex() {
    JsonObject value1 = Json.object();
    JsonObject value2 = Json.object();
    JsonObject value3 = Json.object();
    JsonArray array1 = Json.array(new int[] { 1, 2, 3, 4, 5 });
    JsonArray array2 = Json.array(new int[] { 10, 20, 30, 40, 50 });
    JsonArray array3 = Json.array(new int[] { 100, 200, 300, 400, 500 });
    value1.add("numbers", array1);
    value2.add("numbers", array2);
    value3.add("numbers", array3);
    IMap<String, JsonValue> map = instance.getMap(randomMapName());
    HazelcastJsonValue p1 = putJsonString(map, "one", value1);
    HazelcastJsonValue p2 = putJsonString(map, "two", value2);
    HazelcastJsonValue p3 = putJsonString(map, "three", value3);
    Collection<String> vals = map.keySet(Predicates.greaterEqual("numbers[1]", 20));
    assertEquals(2, vals.size());
    assertTrue(vals.contains("two"));
    assertTrue(vals.contains("three"));
}
Also used : JsonArray(com.hazelcast.internal.json.JsonArray) JsonValue(com.hazelcast.internal.json.JsonValue) HazelcastJsonValue(com.hazelcast.core.HazelcastJsonValue) HazelcastJsonValue(com.hazelcast.core.HazelcastJsonValue) JsonObject(com.hazelcast.internal.json.JsonObject) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

JsonArray (com.hazelcast.internal.json.JsonArray)74 JsonObject (com.hazelcast.internal.json.JsonObject)42 Test (org.junit.Test)39 QuickTest (com.hazelcast.test.annotation.QuickTest)31 JsonValue (com.hazelcast.internal.json.JsonValue)28 HazelcastJsonValue (com.hazelcast.core.HazelcastJsonValue)10 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)10 CPMember (com.hazelcast.cp.CPMember)7 JsonUtil.getString (com.hazelcast.internal.util.JsonUtil.getString)7 SlowTest (com.hazelcast.test.annotation.SlowTest)7 HazelcastInstance (com.hazelcast.core.HazelcastInstance)6 ConnectionResponse (com.hazelcast.internal.ascii.HTTPCommunicator.ConnectionResponse)6 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)4 Address (com.hazelcast.cluster.Address)3 JetException (com.hazelcast.jet.JetException)3 InputStreamReader (java.io.InputStreamReader)3 Collection (java.util.Collection)3 Map (java.util.Map)3 Request (org.elasticsearch.client.Request)3