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; } } }
@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); }
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());
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);