Search in sources :

Example 6 with JsonValue

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

the class KubernetesApiEndpointSlicesProvider method extractNodes.

@Override
public Map<EndpointAddress, String> extractNodes(JsonObject jsonObject, List<EndpointAddress> privateAddresses) {
    Map<EndpointAddress, String> result = new HashMap<>();
    Set<EndpointAddress> left = new HashSet<>(privateAddresses);
    for (JsonValue item : toJsonArray(jsonObject.get("items"))) {
        List<Integer> ports = new ArrayList<>();
        for (JsonValue port : toJsonArray(item.asObject().get("ports"))) {
            ports.add(port.asObject().get("port").asInt());
        }
        for (JsonValue endpoint : toJsonArray(item.asObject().get("endpoints"))) {
            JsonObject endpointObject = endpoint.asObject();
            String nodeName = convertToString(endpointObject.get("nodeName"));
            Map<EndpointAddress, String> nodes = extractNodes(endpointObject.get("addresses"), ports, nodeName);
            for (Map.Entry<EndpointAddress, String> nodeEntry : nodes.entrySet()) {
                EndpointAddress address = nodeEntry.getKey();
                if (privateAddresses.contains(address)) {
                    result.put(address, nodes.get(address));
                    left.remove(address);
                }
            }
        }
    }
    if (!left.isEmpty()) {
        // At least one Hazelcast Member POD does not have 'nodeName' assigned.
        throw noNodeNameAssignedException(left);
    }
    return result;
}
Also used : HashMap(java.util.HashMap) JsonValue(com.hazelcast.internal.json.JsonValue) ArrayList(java.util.ArrayList) JsonObject(com.hazelcast.internal.json.JsonObject) KubernetesApiProvider.convertToString(com.hazelcast.kubernetes.KubernetesApiProvider.convertToString) HashMap(java.util.HashMap) Map(java.util.Map) EndpointAddress(com.hazelcast.kubernetes.KubernetesClient.EndpointAddress) HashSet(java.util.HashSet)

Example 7 with JsonValue

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

the class KubernetesApiEndpointSlicesProvider method parseEndpointSlices.

private List<Endpoint> parseEndpointSlices(JsonValue jsonValue) {
    List<KubernetesClient.Endpoint> addresses = new ArrayList<>();
    Integer endpointPort = extractPort(jsonValue);
    for (JsonValue endpoint : toJsonArray(jsonValue.asObject().get("endpoints"))) {
        JsonValue ready = endpoint.asObject().get("conditions").asObject().get("ready");
        Map<String, String> additionalProperties = extractAdditionalPropertiesFrom(endpoint);
        for (JsonValue address : toJsonArray(endpoint.asObject().get("addresses"))) {
            addresses.add(new Endpoint(new EndpointAddress(address.asString(), endpointPort), ready.asBoolean(), additionalProperties));
        }
    }
    return addresses;
}
Also used : Endpoint(com.hazelcast.kubernetes.KubernetesClient.Endpoint) ArrayList(java.util.ArrayList) JsonValue(com.hazelcast.internal.json.JsonValue) KubernetesApiProvider.convertToString(com.hazelcast.kubernetes.KubernetesApiProvider.convertToString) EndpointAddress(com.hazelcast.kubernetes.KubernetesClient.EndpointAddress)

Example 8 with JsonValue

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

the class KubernetesClient method extractZone.

private static String extractZone(JsonObject nodeJson) {
    JsonObject labels = nodeJson.get("metadata").asObject().get("labels").asObject();
    List<String> zoneLabels = asList("topology.kubernetes.io/zone", "failure-domain.kubernetes.io/zone", "failure-domain.beta.kubernetes.io/zone");
    for (String zoneLabel : zoneLabels) {
        JsonValue zone = labels.get(zoneLabel);
        if (zone != null) {
            return toString(zone);
        }
    }
    return null;
}
Also used : JsonValue(com.hazelcast.internal.json.JsonValue) JsonObject(com.hazelcast.internal.json.JsonObject)

Example 9 with JsonValue

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

the class KubernetesClient method extractLoadBalancerAddress.

private static String extractLoadBalancerAddress(JsonObject serviceResponse) {
    JsonObject ingress = serviceResponse.get("status").asObject().get("loadBalancer").asObject().get("ingress").asArray().get(0).asObject();
    JsonValue address = ingress.get("ip");
    if (address == null) {
        address = ingress.get("hostname");
    }
    return address.asString();
}
Also used : JsonValue(com.hazelcast.internal.json.JsonValue) JsonObject(com.hazelcast.internal.json.JsonObject)

Example 10 with JsonValue

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

the class KubernetesClient method parsePodsList.

private static List<Endpoint> parsePodsList(JsonObject podsListJson) {
    List<Endpoint> addresses = new ArrayList<>();
    for (JsonValue item : toJsonArray(podsListJson.get("items"))) {
        JsonObject status = item.asObject().get("status").asObject();
        String ip = toString(status.get("podIP"));
        if (ip != null) {
            Integer port = extractContainerPort(item);
            addresses.add(new Endpoint(new EndpointAddress(ip, port), isReady(status)));
        }
    }
    return addresses;
}
Also used : ArrayList(java.util.ArrayList) JsonValue(com.hazelcast.internal.json.JsonValue) JsonObject(com.hazelcast.internal.json.JsonObject)

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