HttpEndpointReference(Vertx vertx, ServiceDiscovery discovery, Record record, JsonObject config) { super(vertx, discovery, record); this.config = config; this.location = new HttpLocation(record.getLocation()); }
case "endpoint": if (member.getValue() instanceof String) { obj.setEndpoint((String)member.getValue()); obj.setHost((String)member.getValue()); obj.setPort(((Number)member.getValue()).intValue()); obj.setRoot((String)member.getValue()); obj.setSsl((Boolean)member.getValue());
public static void toJson(HttpLocation obj, java.util.Map<String, Object> json) { if (obj.getEndpoint() != null) { json.put("endpoint", obj.getEndpoint()); } if (obj.getHost() != null) { json.put("host", obj.getHost()); } json.put("port", obj.getPort()); if (obj.getRoot() != null) { json.put("root", obj.getRoot()); } json.put("ssl", obj.isSsl()); } }
/** * Same as {@link #createRecord(String, String, int, String, JsonObject)} but let you configure whether or not the * service is using {@code https}. * * @param name the service name * @param ssl whether or not the service is using HTTPS * @param host the host (IP or DNS name), it must be the _public_ IP / name * @param port the port, it must be the _public_ port * @param root the path of the service, "/" if not set * @param metadata additional metadata * @return the created record */ static Record createRecord(String name, boolean ssl, String host, int port, String root, JsonObject metadata) { Objects.requireNonNull(name); Objects.requireNonNull(host); if (root == null) { root = "/"; } Record record = new Record().setName(name) .setType(TYPE) .setLocation(new HttpLocation() .setSsl(ssl).setHost(host).setPort(port).setRoot(root).toJson()); if (metadata != null) { record.setMetadata(metadata); } return record; }
private Record createRecord(Service service) { String address = service.getAddress(); int port = service.getPort(); JsonObject metadata = service.toJson(); if (service.getTags() != null) { service.getTags().forEach(tag -> metadata.put(tag, true)); } Record record = new Record() .setName(service.getName()) .setMetadata(metadata); // To determine the record type, check if we have a tag with a "type" name record.setType(ServiceType.UNKNOWN); ServiceTypes.all().forEachRemaining(type -> { if (metadata.getBoolean(type.name(), false)) { record.setType(type.name()); } }); JsonObject location = new JsonObject(); location.put("host", address); location.put("port", port); // Manage HTTP endpoint if (record.getType().equals("http-endpoint")) { if (metadata.getBoolean("ssl", false)) { location.put("ssl", true); } location = new HttpLocation(location).toJson(); } record.setLocation(location); return record; }
/** * Same as {@link #createRecord(String, String, int, String, JsonObject)} but let you configure whether or not the * service is using {@code https}. * * @param name the service name * @param ssl whether or not the service is using HTTPS * @param host the host (IP or DNS name), it must be the _public_ IP / name * @param port the port, it must be the _public_ port * @param root the path of the service, "/" if not set * @param metadata additional metadata * @return the created record */ static Record createRecord(String name, boolean ssl, String host, int port, String root, JsonObject metadata) { Objects.requireNonNull(name); Objects.requireNonNull(host); if (root == null) { root = "/"; } Record record = new Record().setName(name) .setType(TYPE) .setLocation(new HttpLocation() .setSsl(ssl).setHost(host).setPort(port).setRoot(root).toJson()); if (metadata != null) { record.setMetadata(metadata); } return record; }
private Record createRecord(Service service) { String address = service.getAddress(); int port = service.getPort(); JsonObject metadata = service.toJson(); if (service.getTags() != null) { service.getTags().forEach(tag -> metadata.put(tag, true)); } Record record = new Record() .setName(service.getName()) .setMetadata(metadata); // To determine the record type, check if we have a tag with a "type" name record.setType(ServiceType.UNKNOWN); ServiceTypes.all().forEachRemaining(type -> { if (metadata.getBoolean(type.name(), false)) { record.setType(type.name()); } }); JsonObject location = new JsonObject(); location.put("host", address); location.put("port", port); // Manage HTTP endpoint if (record.getType().equals("http-endpoint")) { if (metadata.getBoolean("ssl", false)) { location.put("ssl", true); } location = new HttpLocation(location).toJson(); } record.setLocation(location); return record; }
private static Record manageHttpService(Record record, ContainerPort port, Map<String, String> labels) { if (port.getPublicPort() == null || port.getPublicPort() == 0) { return null; } record.setType(HttpEndpoint.TYPE); HttpLocation location = new HttpLocation() .setHost(port.getIp()) .setPort(port.getPublicPort()); if (isTrue(labels, "ssl") || port.getPrivatePort() == 443) { location.setSsl(true); } return record.setLocation(location.toJson()); }
case "endpoint": if (member.getValue() instanceof String) { obj.setEndpoint((String)member.getValue()); obj.setHost((String)member.getValue()); obj.setPort(((Number)member.getValue()).intValue()); obj.setRoot((String)member.getValue()); obj.setSsl((Boolean)member.getValue());
HttpEndpointReference(Vertx vertx, ServiceDiscovery discovery, Record record, JsonObject config) { super(vertx, discovery, record); this.config = config; this.location = new HttpLocation(record.getLocation()); }
public static void toJson(HttpLocation obj, java.util.Map<String, Object> json) { if (obj.getEndpoint() != null) { json.put("endpoint", obj.getEndpoint()); } if (obj.getHost() != null) { json.put("host", obj.getHost()); } json.put("port", obj.getPort()); if (obj.getRoot() != null) { json.put("root", obj.getRoot()); } json.put("ssl", obj.isSsl()); } }
switch (type) { case "http-endpoint": HttpLocation http = new HttpLocation(); http.setHost(url.getHost()); http.setPort(url.getPort()); if (isTrue(variables, name + "_ENV_SSL")) { http.setSsl(true); record.setLocation(http.toJson()); break; default:
switch (type) { case "http-endpoint": HttpLocation http = new HttpLocation(); http.setHost(url.getHost()); http.setPort(url.getPort()); if (isTrue(variables, name + "_ENV_SSL")) { http.setSsl(true); record.setLocation(http.toJson()); break; default:
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"); } }