Java Code Examples for io.vertx.servicediscovery.Record#setType()
The following examples show how to use
io.vertx.servicediscovery.Record#setType() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DockerService.java From vertx-service-discovery with Apache License 2.0 | 5 votes |
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()); }
Example 2
Source File: ConsulServiceImporter.java From vertx-service-discovery with Apache License 2.0 | 5 votes |
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; }
Example 3
Source File: KubernetesServiceImporter.java From vertx-service-discovery with Apache License 2.0 | 5 votes |
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"); } }
Example 4
Source File: ServiceTypesTest.java From vertx-service-discovery with Apache License 2.0 | 5 votes |
@Test(expected = IllegalArgumentException.class) public void unknown() { Record record = new Record(); record.setType(ServiceType.UNKNOWN); ServiceTypes.get(record); }
Example 5
Source File: ServiceTypesTest.java From vertx-service-discovery with Apache License 2.0 | 5 votes |
@Test(expected = IllegalArgumentException.class) public void notAKnownType() { Record record = new Record(); record.setType("bob"); ServiceTypes.get(record); }
Example 6
Source File: DockerLinksServiceImporter.java From vertx-service-discovery with Apache License 2.0 | 4 votes |
private Record createRecord(String name, Map<String, String> variables) throws URISyntaxException { Record record = new Record() .setName(name); // Add as metadata all entries variables.entrySet().forEach(entry -> { if (entry.getKey().startsWith(name + "_")) { String label = entry.getKey().substring((name + "_").length()); record.getMetadata().put(label, entry.getValue()); } }); String type = variables.get(name + "_ENV_SERVICE_TYPE"); if (type == null) { type = ServiceType.UNKNOWN; } else { LOGGER.info("Service type for " + name + " : " + type); } URI url = new URI(variables.get(name + "_PORT")); 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.setType(HttpEndpoint.TYPE); record.setLocation(http.toJson()); break; default: JsonObject location = new JsonObject(); location .put("endpoint", url.toString()) .put("port", url.getPort()) .put("host", url.getHost()) .put("proto", url.getScheme()); record.setType(type); record.setLocation(location); } return record; }