public static void fromJson(Iterable<java.util.Map.Entry<String, Object>> json, ServiceQueryOptions obj) { for (java.util.Map.Entry<String, Object> member : json) { switch (member.getKey()) { case "blockingOptions": if (member.getValue() instanceof JsonObject) { obj.setBlockingOptions(new io.vertx.ext.consul.BlockingQueryOptions((JsonObject)member.getValue())); } break; case "near": if (member.getValue() instanceof String) { obj.setNear((String)member.getValue()); } break; case "tag": if (member.getValue() instanceof String) { obj.setTag((String)member.getValue()); } break; } } }
public static void toJson(ServiceQueryOptions obj, java.util.Map<String, Object> json) { if (obj.getBlockingOptions() != null) { json.put("blockingOptions", obj.getBlockingOptions().toJson()); } if (obj.getNear() != null) { json.put("near", obj.getNear()); } if (obj.getTag() != null) { json.put("tag", obj.getTag()); } } }
@Override public void getRecords(Handler<AsyncResult<List<Record>>> resultHandler) { Future<ServiceList> nameList = Future.future(); client.catalogServices(nameList); nameList.map(ServiceList::getList) .map(l -> { List<Future> recordFutureList = new ArrayList<>(); l.forEach(s -> { if (!"consul".equals(s.getName())) { ServiceQueryOptions opt = new ServiceQueryOptions(); if (!s.getTags().isEmpty()) { opt.setTag(s.getTags().get(0)); } Future<ServiceList> serviceList = Future.future(); client.catalogServiceNodesWithOptions(s.getName(), opt, serviceList); recordFutureList.add(serviceList); } }); return recordFutureList; }) .compose(CompositeFuture::all) .map(c -> c.<ServiceList>list().stream().flatMap(l -> l.getList().stream()).map(this::serviceToRecord).collect(Collectors.toList())) .compose(CompositeFuture::all) .map(c -> c.list().stream().map(o -> (Record) o).collect(Collectors.toList())) .setHandler(resultHandler); }
assertTrue(ids.contains("id2")); ServiceQueryOptions opts2 = new ServiceQueryOptions().setTag("tag2"); ServiceEntryList list2 = getAsync(h -> ctx.readClient().healthServiceNodesWithOptions("service", true, opts2, h)); assertEquals(list2.getList().size(), 1); ServiceQueryOptions options = new ServiceQueryOptions() .setBlockingOptions(new BlockingQueryOptions().setIndex(idx)); ctx.readClient().healthServiceNodesWithOptions("service", true, options, h -> { waitComplete(vertx, fut, h.result().getIndex(), h.result().getList().size() == 1);
public static io.vertx.ext.consul.ConsulClient catalogServiceNodesWithOptions(io.vertx.ext.consul.ConsulClient j_receiver, java.lang.String service, java.util.Map<String, Object> options, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.util.Map<String, Object>>> resultHandler) { io.vertx.core.impl.ConversionHelper.fromObject(j_receiver.catalogServiceNodesWithOptions(service, options != null ? new io.vertx.ext.consul.ServiceQueryOptions(io.vertx.core.impl.ConversionHelper.toJsonObject(options)) : null, resultHandler != null ? new io.vertx.core.Handler<io.vertx.core.AsyncResult<io.vertx.ext.consul.ServiceList>>() { public void handle(io.vertx.core.AsyncResult<io.vertx.ext.consul.ServiceList> ar) { resultHandler.handle(ar.map(event -> event != null ? io.vertx.core.impl.ConversionHelper.fromJsonObject(event.toJson()) : null)); } } : null)); return j_receiver; } public static io.vertx.ext.consul.ConsulClient catalogNodes(io.vertx.ext.consul.ConsulClient j_receiver, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.util.Map<String, Object>>> resultHandler) {
@Override void wait(long index, Handler<AsyncResult<State<ServiceEntryList>>> handler) { BlockingQueryOptions bOpts = new BlockingQueryOptions().setWait(BLOCKING_WAIT).setIndex(index); ServiceQueryOptions sOpts = new ServiceQueryOptions().setBlockingOptions(bOpts); consulClient.healthServiceNodesWithOptions(service, false, sOpts, h -> handler.handle(h.map(services -> new State<ServiceEntryList>(services, services.getIndex())))); } }
checkService(tc, nodeServices.getList(), serviceName, opts); Async async = tc.async(2); ServiceQueryOptions knownOpts = new ServiceQueryOptions().setTag(opts.getTags().get(0)); ctx.writeClient().catalogServiceNodesWithOptions(serviceName, knownOpts, tc.asyncAssertSuccess(nodeServicesWithKnownTag -> { tc.assertEquals(1, nodeServicesWithKnownTag.getList().size()); async.countDown(); })); ServiceQueryOptions unknownOpts = new ServiceQueryOptions().setTag("unknownTag"); ctx.writeClient().catalogServiceNodesWithOptions(serviceName, unknownOpts, tc.asyncAssertSuccess(nodeServicesWithUnknownTag -> { tc.assertEquals(0, nodeServicesWithUnknownTag.getList().size());
public static io.vertx.ext.consul.ConsulClient healthServiceNodesWithOptions(io.vertx.ext.consul.ConsulClient j_receiver, java.lang.String service, boolean passing, java.util.Map<String, Object> options, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.util.Map<String, Object>>> resultHandler) { io.vertx.core.impl.ConversionHelper.fromObject(j_receiver.healthServiceNodesWithOptions(service, passing, options != null ? new io.vertx.ext.consul.ServiceQueryOptions(io.vertx.core.impl.ConversionHelper.toJsonObject(options)) : null, resultHandler != null ? new io.vertx.core.Handler<io.vertx.core.AsyncResult<io.vertx.ext.consul.ServiceEntryList>>() { public void handle(io.vertx.core.AsyncResult<io.vertx.ext.consul.ServiceEntryList> ar) { resultHandler.handle(ar.map(event -> event != null ? io.vertx.core.impl.ConversionHelper.fromJsonObject(event.toJson()) : null)); } } : null)); return j_receiver; } public static io.vertx.ext.consul.ConsulClient catalogServices(io.vertx.ext.consul.ConsulClient j_receiver, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.util.Map<String, Object>>> resultHandler) {
public static io.vertx.ext.consul.ConsulService healthServiceNodesWithOptions(io.vertx.ext.consul.ConsulService j_receiver, java.lang.String service, boolean passing, java.util.Map<String, Object> options, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.util.Map<String, Object>>> resultHandler) { io.vertx.core.impl.ConversionHelper.fromObject(j_receiver.healthServiceNodesWithOptions(service, passing, options != null ? new io.vertx.ext.consul.ServiceQueryOptions(io.vertx.core.impl.ConversionHelper.toJsonObject(options)) : null, resultHandler != null ? new io.vertx.core.Handler<io.vertx.core.AsyncResult<io.vertx.ext.consul.ServiceEntryList>>() { public void handle(io.vertx.core.AsyncResult<io.vertx.ext.consul.ServiceEntryList> ar) { resultHandler.handle(ar.map(event -> event != null ? io.vertx.core.impl.ConversionHelper.fromJsonObject(event.toJson()) : null)); } } : null)); return j_receiver; } public static io.vertx.ext.consul.ConsulService catalogServiceNodes(io.vertx.ext.consul.ConsulService j_receiver, java.lang.String service, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.util.Map<String, Object>>> resultHandler) {
@Override public ConsulClient catalogServiceNodesWithOptions(String service, ServiceQueryOptions options, Handler<AsyncResult<ServiceList>> resultHandler) { Query query = options == null ? null : Query.of("tag", options.getTag()).put("near", options.getNear()).put(options.getBlockingOptions()); requestArray(HttpMethod.GET, "/v1/catalog/service/" + urlEncode(service), query, null, resultHandler, (arr, headers) -> { List<Service> list = arr.stream().map(obj -> new Service((JsonObject) obj)).collect(Collectors.toList()); return new ServiceList().setList(list).setIndex(Long.parseLong(headers.get(INDEX_HEADER))); }); return this; }
public static io.vertx.ext.consul.ConsulService catalogServiceNodesWithOptions(io.vertx.ext.consul.ConsulService j_receiver, java.lang.String service, java.util.Map<String, Object> options, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.util.Map<String, Object>>> resultHandler) { io.vertx.core.impl.ConversionHelper.fromObject(j_receiver.catalogServiceNodesWithOptions(service, options != null ? new io.vertx.ext.consul.ServiceQueryOptions(io.vertx.core.impl.ConversionHelper.toJsonObject(options)) : null, resultHandler != null ? new io.vertx.core.Handler<io.vertx.core.AsyncResult<io.vertx.ext.consul.ServiceList>>() { public void handle(io.vertx.core.AsyncResult<io.vertx.ext.consul.ServiceList> ar) { resultHandler.handle(ar.map(event -> event != null ? io.vertx.core.impl.ConversionHelper.fromJsonObject(event.toJson()) : null)); } } : null)); return j_receiver; } public static io.vertx.ext.consul.ConsulService catalogNodes(io.vertx.ext.consul.ConsulService j_receiver, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.util.Map<String, Object>>> resultHandler) {
@Override public ConsulClient healthServiceNodesWithOptions(String service, boolean passing, ServiceQueryOptions options, Handler<AsyncResult<ServiceEntryList>> resultHandler) { Query query = new Query().put("passing", passing ? 1 : null); if (options != null) { query.put(options.getBlockingOptions()).put("near", options.getNear()).put("tag", options.getTag()); } requestArray(HttpMethod.GET, "/v1/health/service/" + urlEncode(service), query, null, resultHandler, (arr, headers) -> { List<ServiceEntry> list = arr.stream().map(obj -> ServiceEntryParser.parse((JsonObject) obj)).collect(Collectors.toList()); return new ServiceEntryList().setList(list).setIndex(Long.parseLong(headers.get(INDEX_HEADER))); }); return this; }