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;
}
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;
}
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;
}
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();
}
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;
}
Aggregations