Search in sources :

Example 16 with JsonValue

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

the class JsonUtil method getDouble.

/**
 * Returns a field in a Json object as a double.
 * Throws IllegalArgumentException if the field value is null.
 *
 * @param object the Json Object
 * @param field the field in the Json object to return
 * @return the Json field value as a double
 */
public static double getDouble(JsonObject object, String field) {
    final JsonValue value = object.get(field);
    throwExceptionIfNull(value, field);
    return value.asDouble();
}
Also used : JsonValue(com.hazelcast.internal.json.JsonValue)

Example 17 with JsonValue

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

the class JsonUtil method getString.

/**
 * Returns a field in a Json object as a string.
 * Throws IllegalArgumentException if the field value is null.
 *
 * @param object the Json Object
 * @param field the field in the Json object to return
 * @return the Json field value as a string
 */
public static String getString(JsonObject object, String field) {
    final JsonValue value = object.get(field);
    throwExceptionIfNull(value, field);
    return value.asString();
}
Also used : JsonValue(com.hazelcast.internal.json.JsonValue)

Example 18 with JsonValue

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

the class JsonUtil method getLong.

/**
 * Returns a field in a Json object as a long.
 * Throws IllegalArgumentException if the field value is null.
 *
 * @param object the Json Object
 * @param field the field in the Json object to return
 * @return the Json field value as a long
 */
public static long getLong(JsonObject object, String field) {
    final JsonValue value = object.get(field);
    throwExceptionIfNull(value, field);
    return value.asLong();
}
Also used : JsonValue(com.hazelcast.internal.json.JsonValue)

Example 19 with JsonValue

use of com.hazelcast.internal.json.JsonValue 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 20 with JsonValue

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

the class AzureComputeApi method parsePrivateIpResponse.

private Map<String, AzureNetworkInterface> parsePrivateIpResponse(String response) {
    Map<String, AzureNetworkInterface> interfaces = new HashMap<>();
    for (JsonValue item : toJsonArray(Json.parse(response).asObject().get("value"))) {
        Set<Tag> tagList = new HashSet<>();
        JsonObject tags = toJsonObject(item.asObject().get("tags"));
        for (String key : tags.asObject().names()) {
            tagList.add(new Tag(key, tags.asObject().getString(key, null)));
        }
        JsonObject properties = item.asObject().get("properties").asObject();
        if (properties.get("virtualMachine") != null) {
            for (JsonValue ipConfiguration : toJsonArray(properties.get("ipConfigurations"))) {
                JsonObject ipProps = ipConfiguration.asObject().get("properties").asObject();
                String privateIp = ipProps.getString("privateIPAddress", null);
                String publicIpId = toJsonObject(ipProps.get("publicIPAddress")).getString("id", null);
                if (!isNullOrEmptyAfterTrim(privateIp)) {
                    interfaces.put(privateIp, new AzureNetworkInterface(privateIp, publicIpId, tagList));
                }
            }
        }
    }
    return interfaces;
}
Also used : HashMap(java.util.HashMap) JsonValue(com.hazelcast.internal.json.JsonValue) JsonObject(com.hazelcast.internal.json.JsonObject) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Aggregations

JsonValue (com.hazelcast.internal.json.JsonValue)85 Test (org.junit.Test)36 JsonObject (com.hazelcast.internal.json.JsonObject)35 QuickTest (com.hazelcast.test.annotation.QuickTest)30 JsonArray (com.hazelcast.internal.json.JsonArray)28 HazelcastJsonValue (com.hazelcast.core.HazelcastJsonValue)25 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)20 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)8 HazelcastInstance (com.hazelcast.core.HazelcastInstance)6 KubernetesApiProvider.convertToString (com.hazelcast.kubernetes.KubernetesApiProvider.convertToString)6 EndpointAddress (com.hazelcast.kubernetes.KubernetesClient.EndpointAddress)6 HashSet (java.util.HashSet)6 ConnectionResponse (com.hazelcast.internal.ascii.HTTPCommunicator.ConnectionResponse)5 SlowTest (com.hazelcast.test.annotation.SlowTest)5 Address (com.hazelcast.cluster.Address)4 CPMember (com.hazelcast.cp.CPMember)4 IOException (java.io.IOException)4 JsonUtil.fromJsonObject (com.hazelcast.internal.util.JsonUtil.fromJsonObject)3 JsonUtil.getString (com.hazelcast.internal.util.JsonUtil.getString)3