public synchronized static ServiceType get(String type) { load(); for (ServiceType next : types) { if (next.name().equalsIgnoreCase(type)) { return next; } } return null; } }
@Override public ServiceReference getReferenceWithConfiguration(Record record, JsonObject configuration) { ServiceReference reference = ServiceTypes.get(record).get(vertx, this, record, configuration); bindings.add(reference); sendBindEvent(reference); return reference; }
public synchronized static ServiceType get(String type) { load(); for (ServiceType next : types) { if (next.name().equalsIgnoreCase(type)) { return next; } } return null; } }
@Override public ServiceReference getReferenceWithConfiguration(Record record, JsonObject configuration) { ServiceReference reference = ServiceTypes.get(record).get(vertx, this, record, configuration); bindings.add(reference); sendBindEvent(reference); return reference; }
private Future serviceToRecord(Service service) { //use the checks to set the record status Future<CheckList> checkListFuture = Future.future(); client.healthChecks(service.getName(), checkListFuture); return checkListFuture.map(cl -> cl.getList().stream().map(Check::getStatus).allMatch(CheckStatus.PASSING::equals)) .map(st -> st ? new Record().setStatus(Status.UP) : new Record().setStatus(Status.DOWN)) .map(record -> { record.setMetadata(new JsonObject()); record.setLocation(new JsonObject()); record.setName(service.getName()); record.setRegistration(service.getId()); List<String> tags = service.getTags(); record.setType(ServiceType.UNKNOWN); ServiceTypes.all().forEachRemaining(type -> { if (service.getTags().contains(type.name())) { record.setType(type.name()); tags.remove(type.name()); } }); //retrieve the metadata object tags.stream().filter(t -> t.startsWith("metadata:")).map(s -> s.substring("metadata:".length())).map(JsonObject::new).forEach(json -> record.getMetadata().mergeIn(json)); //retrieve the location object tags.stream().filter(t -> t.startsWith("location:")).map(s -> s.substring("location:".length())).map(JsonObject::new).forEach(json -> record.getLocation().mergeIn(json)); record.getMetadata().put("tags", new JsonArray(tags.stream().filter(t -> !t.startsWith("metadata:") && !t.startsWith("location:")).collect(Collectors.toList()))); 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 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; }