@Override public boolean conditionMet() { return result.listings().isDone(); } }, "Timed out waiting for listTopics to complete");
TestUtils.assertFutureError(result.listings(), TimeoutException.class); log.info("Verified the error result of AdminClient#listTopics");
/** * Get information about all topics in Kafka. * @return Set of topics found in Kafka. */ public List<TopicListing> getTopics() { try (final AdminClient adminClient = getAdminClient()) { return new ArrayList<>(adminClient.listTopics().listings().get()); } catch (final InterruptedException | ExecutionException e) { throw new RuntimeException(e.getMessage(), e); } }
/** * Lists non-internal topics in a cluster. * * @param timeoutMillis The timeout to wait for. * @return A set of topic names. * @throws ExecutionException If an unexpected error occurred. * @throws InterruptedException If the thread was interrupted. * @throws TimeoutException If a timeout occurred. */ public Set<String> listTopics(int timeoutMillis) throws ExecutionException, TimeoutException, InterruptedException { return runWithRetry(() -> { final ListTopicsResult result = admin.listTopics(new ListTopicsOptions().timeoutMs(timeoutMillis)); awaitFutures(timeoutMillis, result.listings()); final Collection<TopicListing> listings = result.listings().get(); return listings.stream().map(TopicListing::name).collect(Collectors.toSet()); }); }
@Override boolean runInternal(StopWatch stopWatch) throws InterruptedException, ExecutionException { stopWatch.start("adminClient.listTopics()"); Collection<String> topicNames = adminClient.listTopics().listings().get() .stream().map(TopicListing::name).filter(this::shouldCollectEvent).collect(Collectors.toList()); topicsMap.removeAll(new RemoveTopicPredicate(topicNames)); DescribeTopicsResult describeTopicsResult = adminClient.describeTopics(topicNames); describeTopicsResult.all().get().forEach( (topic, topicDescription) -> topicsMap.executeOnKey(topic, new SetTopicPartitionsProcessor( topicDescription.partitions().stream().map(TopicPartitionInfo::partition).collect(Collectors.toList())) ) ); metaMap.set(this.getName() + TopicServiceScheduler.LAST_SUCCESS_PREFIX, System.currentTimeMillis()); log.debug("Topics:" + topicsMap.entrySet()); log.debug(stopWatch.prettyPrint()); return true; }
/** * Retrieve all available topics within cluster. Includes internal topics. */ public TopicList getAvailableTopics() { final List<org.sourcelab.kafka.webview.ui.manager.kafka.dto.TopicListing> topicListings = new ArrayList<>(); try { // We want to show all topics, including internal topics. final ListTopicsOptions listTopicsOptions = new ListTopicsOptions().listInternal(true); final Collection<TopicListing> results = adminClient .listTopics(listTopicsOptions) .listings() .get(); for (final TopicListing entry: results) { topicListings.add( new org.sourcelab.kafka.webview.ui.manager.kafka.dto.TopicListing(entry.name(), entry.isInternal()) ); } return new TopicList(topicListings); } catch (InterruptedException | ExecutionException e) { // TODO Handle throw new RuntimeException(e.getMessage(), e); } }