public static void fromJson(Iterable<java.util.Map.Entry<String, Object>> json, CheckQueryOptions 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; } } }
public static void toJson(CheckQueryOptions 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()); } } }
@Test public void healthState() throws InterruptedException { String serviceName = randomAlphaString(10); ServiceOptions opts = new ServiceOptions() .setName(serviceName) .setId(serviceName) .setCheckOptions(new CheckOptions().setTtl("1m")); runAsync(h -> ctx.writeClient().registerService(opts, h)); CheckList list1 = getAsync(h -> ctx.readClient().healthState(HealthState.CRITICAL, h)); CountDownLatch latch = new CountDownLatch(1); waitBlockingQuery(latch, 10, list1.getIndex(), (idx, fut) -> { CheckQueryOptions options = new CheckQueryOptions() .setBlockingOptions(new BlockingQueryOptions().setIndex(idx)); ctx.readClient().healthStateWithOptions(HealthState.PASSING, options, h -> { List<String> names = h.result().getList().stream().map(Check::getServiceName).collect(Collectors.toList()); waitComplete(vertx, fut, h.result().getIndex(), names.contains(serviceName)); }); }); runAsync(h -> ctx.writeClient().passCheck("service:" + serviceName, h)); awaitLatch(latch); runAsync(h -> ctx.writeClient().deregisterService(serviceName, h)); }
public static io.vertx.ext.consul.ConsulService healthStateWithOptions(io.vertx.ext.consul.ConsulService j_receiver, io.vertx.ext.consul.HealthState healthState, java.util.Map<String, Object> checkQueryOptions, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.util.Map<String, Object>>> handler) { io.vertx.core.impl.ConversionHelper.fromObject(j_receiver.healthStateWithOptions(healthState, checkQueryOptions != null ? new io.vertx.ext.consul.CheckQueryOptions(io.vertx.core.impl.ConversionHelper.toJsonObject(checkQueryOptions)) : null, handler != null ? new io.vertx.core.Handler<io.vertx.core.AsyncResult<io.vertx.ext.consul.CheckList>>() { public void handle(io.vertx.core.AsyncResult<io.vertx.ext.consul.CheckList> ar) { handler.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 healthServiceNodes(io.vertx.ext.consul.ConsulService j_receiver, java.lang.String service, boolean passing, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.util.Map<String, Object>>> resultHandler) {
CheckQueryOptions options = new CheckQueryOptions() .setBlockingOptions(new BlockingQueryOptions().setIndex(idx)); ctx.readClient().healthChecksWithOptions("serviceName", options, h -> { List<String> ids = h.result().getList().stream().map(Check::getId).collect(Collectors.toList());
public static io.vertx.ext.consul.ConsulService healthChecksWithOptions(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.healthChecksWithOptions(service, options != null ? new io.vertx.ext.consul.CheckQueryOptions(io.vertx.core.impl.ConversionHelper.toJsonObject(options)) : null, resultHandler != null ? new io.vertx.core.Handler<io.vertx.core.AsyncResult<io.vertx.ext.consul.CheckList>>() { public void handle(io.vertx.core.AsyncResult<io.vertx.ext.consul.CheckList> 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 healthState(io.vertx.ext.consul.ConsulService j_receiver, io.vertx.ext.consul.HealthState healthState, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.util.Map<String, Object>>> handler) {
public static io.vertx.ext.consul.ConsulClient healthStateWithOptions(io.vertx.ext.consul.ConsulClient j_receiver, io.vertx.ext.consul.HealthState healthState, 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.healthStateWithOptions(healthState, options != null ? new io.vertx.ext.consul.CheckQueryOptions(io.vertx.core.impl.ConversionHelper.toJsonObject(options)) : null, resultHandler != null ? new io.vertx.core.Handler<io.vertx.core.AsyncResult<io.vertx.ext.consul.CheckList>>() { public void handle(io.vertx.core.AsyncResult<io.vertx.ext.consul.CheckList> 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 healthServiceNodes(io.vertx.ext.consul.ConsulClient j_receiver, java.lang.String service, boolean passing, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.util.Map<String, Object>>> resultHandler) {
@Override public ConsulClient healthStateWithOptions(HealthState healthState, CheckQueryOptions options, Handler<AsyncResult<CheckList>> resultHandler) { Query query = options == null ? null : Query.of("near", options.getNear()).put(options.getBlockingOptions()); requestArray(HttpMethod.GET, "/v1/health/state/" + healthState.key, query, null, resultHandler, (arr, headers) -> { List<Check> list = arr.stream().map(obj -> CheckParser.parse((JsonObject) obj)).collect(Collectors.toList()); return new CheckList().setList(list).setIndex(Long.parseLong(headers.get(INDEX_HEADER))); }); return this; }
public static io.vertx.ext.consul.ConsulClient healthChecksWithOptions(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.healthChecksWithOptions(service, options != null ? new io.vertx.ext.consul.CheckQueryOptions(io.vertx.core.impl.ConversionHelper.toJsonObject(options)) : null, resultHandler != null ? new io.vertx.core.Handler<io.vertx.core.AsyncResult<io.vertx.ext.consul.CheckList>>() { public void handle(io.vertx.core.AsyncResult<io.vertx.ext.consul.CheckList> 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 healthState(io.vertx.ext.consul.ConsulClient j_receiver, io.vertx.ext.consul.HealthState healthState, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.util.Map<String, Object>>> resultHandler) {
@Override public ConsulClient healthChecksWithOptions(String service, CheckQueryOptions options, Handler<AsyncResult<CheckList>> resultHandler) { Query query = options == null ? null : Query.of("near", options.getNear()).put(options.getBlockingOptions()); requestArray(HttpMethod.GET, "/v1/health/checks/" + urlEncode(service), query, null, resultHandler, (arr, headers) -> { List<Check> list = arr.stream().map(obj -> CheckParser.parse((JsonObject) obj)).collect(Collectors.toList()); return new CheckList().setList(list).setIndex(Long.parseLong(headers.get(INDEX_HEADER))); }); return this; }