private static void manageUnknownService(Record record, JsonObject service, String type) { JsonObject spec = service.getJsonObject("spec"); JsonArray ports = spec.getJsonArray("ports"); if (ports != null && !ports.isEmpty()) { if (ports.size() > 1) { LOGGER.warn("More than one ports has been found for " + record.getName() + " - taking the " + "first one to build the record location"); } JsonObject port = ports.getJsonObject(0); JsonObject location = port.copy(); if (isExternalService(service)) { location.put("host", spec.getString("externalName")); } else { //Number or name of the port to access on the pods targeted by the service. Object targetPort = port.getValue("targetPort"); if (targetPort instanceof Integer) { location.put("internal-port", (Integer) targetPort); } location.put("host", spec.getString("clusterIP")); } record.setLocation(location).setType(type); } else { throw new IllegalStateException("Cannot extract the location from the service " + record + " - no port"); } }
private static void manageHttpService(Record record, JsonObject service) { JsonObject spec = service.getJsonObject("spec"); JsonArray ports = spec.getJsonArray("ports"); if (ports != null && !ports.isEmpty()) { if (ports.size() > 1) { LOGGER.warn("More than one port has been found for " + record.getName() + " - taking the first" + " one to extract the HTTP endpoint location"); } JsonObject port = ports.getJsonObject(0); Integer p = port.getInteger("port"); record.setType(HttpEndpoint.TYPE); HttpLocation location = new HttpLocation(port.copy()); if (isExternalService(service)) { location.setHost(spec.getString("externalName")); } else { location.setHost(spec.getString("clusterIP")); } if (isTrue(record.getMetadata().getString("ssl")) || p != null && p == 443) { location.setSsl(true); } record.setLocation(location.toJson()); } else { throw new IllegalStateException("Cannot extract the HTTP URL from the service " + record + " - no port"); } }