use of com.hazelcast.internal.json.JsonValue in project hazelcast by hazelcast.
the class GcpComputeApi method instances.
List<GcpAddress> instances(String project, String zone, Label label, String accessToken) {
String response = RestClient.create(urlFor(project, zone, label)).withHeader("Authorization", String.format("OAuth %s", accessToken)).get().getBody();
List<GcpAddress> result = new ArrayList<GcpAddress>();
for (JsonValue item : toJsonArray(Json.parse(response).asObject().get("items"))) {
if ("RUNNING".equals(item.asObject().get("status").asString())) {
String privateAddress = null;
String publicAddress = null;
for (JsonValue networkInterface : toJsonArray(item.asObject().get("networkInterfaces"))) {
privateAddress = networkInterface.asObject().getString("networkIP", null);
for (JsonValue accessConfig : toJsonArray(networkInterface.asObject().get("accessConfigs"))) {
publicAddress = accessConfig.asObject().getString("natIP", null);
}
}
if (privateAddress != null) {
result.add(new GcpAddress(privateAddress, publicAddress));
}
}
}
return result;
}
use of com.hazelcast.internal.json.JsonValue 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));
}
use of com.hazelcast.internal.json.JsonValue in project hazelcast by hazelcast.
the class MapPredicateJsonTest method testNestedQuery.
@Test
public void testNestedQuery() {
JsonObject object1 = Json.object();
JsonObject nested1 = Json.object();
JsonObject object2 = Json.object();
JsonObject nested2 = Json.object();
nested1.add("lim", 5);
nested2.add("lim", 6);
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.lim", 6));
assertEquals(1, vals.size());
assertTrue(vals.contains(p2));
}
use of com.hazelcast.internal.json.JsonValue 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));
}
use of com.hazelcast.internal.json.JsonValue 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"));
}
Aggregations