use of com.hazelcast.kubernetes.KubernetesClient.EndpointAddress in project hazelcast by hazelcast.
the class KubernetesApiEndpointProvider method extractServices.
public Map<EndpointAddress, String> extractServices(JsonObject endpointsListJson, List<EndpointAddress> privateAddresses) {
Map<EndpointAddress, String> result = new HashMap<>();
Set<EndpointAddress> left = new HashSet<>(privateAddresses);
for (JsonValue item : toJsonArray(endpointsListJson.get("items"))) {
String service = convertToString(item.asObject().get("metadata").asObject().get("name"));
List<Endpoint> endpoints = parseEndpoints(item);
// Service must point to exactly one endpoint address, otherwise the public IP would be ambiguous.
if (endpoints.size() == 1) {
EndpointAddress address = endpoints.get(0).getPrivateAddress();
if (privateAddresses.contains(address)) {
// If multiple services match the pod, then match service and pod names
if (!result.containsKey(address) || service.equals(extractTargetRefName(item))) {
result.put(address, service);
}
left.remove(address);
}
}
}
if (!left.isEmpty()) {
// At least one Hazelcast Member POD does not have a corresponding service.
throw noCorrespondingServicesException(left);
}
return result;
}
use of com.hazelcast.kubernetes.KubernetesClient.EndpointAddress in project hazelcast by hazelcast.
the class KubernetesApiEndpointProvider method extractNodes.
private Map<EndpointAddress, String> extractNodes(JsonValue addressesJson, List<Integer> ports) {
Map<EndpointAddress, String> result = new HashMap<>();
for (JsonValue address : toJsonArray(addressesJson)) {
String ip = address.asObject().get("ip").asString();
String nodeName = KubernetesApiProvider.convertToString(address.asObject().get("nodeName"));
for (Integer port : ports) {
result.put(new EndpointAddress(ip, port), nodeName);
}
}
return result;
}
use of com.hazelcast.kubernetes.KubernetesClient.EndpointAddress 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.kubernetes.KubernetesClient.EndpointAddress 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.kubernetes.KubernetesClient.EndpointAddress in project hazelcast by hazelcast.
the class KubernetesApiProviderTest method format.
private static List<String> format(Map<EndpointAddress, String> addresses) {
List<String> result = new ArrayList<>();
for (EndpointAddress address : addresses.keySet()) {
String ip = address.getIp();
Integer port = address.getPort();
String service = addresses.get(address);
result.add(toString(ip, port, service));
}
return result;
}
Aggregations