private List<HostStoreInfo> mapInstancesToHostStoreInfo( final Collection<StreamsMetadata> metadatas) { return metadatas.stream().map(metadata -> new HostStoreInfo(metadata.host(), metadata.port(), metadata.stateStoreNames())) .collect(Collectors.toList()); }
/** * Find the metadata for the instance of this Kafka Streams Application that has the given * store and would have the given key if it exists. * @param store Store to find * @param key The key to find * @return {@link HostStoreInfo} */ public <K> HostStoreInfo streamsMetadataForStoreAndKey(final String store, final K key, final Serializer<K> serializer) { // Get metadata for the instances of this Kafka Streams application hosting the store and // potentially the value for key final StreamsMetadata metadata = streams.metadataForKey(store, key, serializer); if (metadata == null) { throw new NotFoundException(); } return new HostStoreInfo(metadata.host(), metadata.port(), metadata.stateStoreNames()); }
private <K> StreamsMetadata getStreamsMetadataForKey(final String storeName, final K key, final StreamPartitioner<? super K, ?> partitioner, final SourceTopicsInfo sourceTopicsInfo) { final Integer partition = partitioner.partition(sourceTopicsInfo.topicWithMostPartitions, key, null, sourceTopicsInfo.maxPartitions); final Set<TopicPartition> matchingPartitions = new HashSet<>(); for (final String sourceTopic : sourceTopicsInfo.sourceTopics) { matchingPartitions.add(new TopicPartition(sourceTopic, partition)); } for (final StreamsMetadata streamsMetadata : allMetadata) { final Set<String> stateStoreNames = streamsMetadata.stateStoreNames(); final Set<TopicPartition> topicPartitions = new HashSet<>(streamsMetadata.topicPartitions()); topicPartitions.retainAll(matchingPartitions); if (stateStoreNames.contains(storeName) && !topicPartitions.isEmpty()) { return streamsMetadata; } } return null; }
/** * Find all of the {@link StreamsMetadata}s for a given storeName * * @param storeName the storeName to find metadata for * @return A collection of {@link StreamsMetadata} that have the provided storeName */ public synchronized Collection<StreamsMetadata> getAllMetadataForStore(final String storeName) { Objects.requireNonNull(storeName, "storeName cannot be null"); if (!isInitialized()) { return Collections.emptyList(); } if (globalStores.contains(storeName)) { return allMetadata; } final List<String> sourceTopics = builder.stateStoreNameToSourceTopics().get(storeName); if (sourceTopics == null) { return Collections.emptyList(); } final ArrayList<StreamsMetadata> results = new ArrayList<>(); for (final StreamsMetadata metadata : allMetadata) { if (metadata.stateStoreNames().contains(storeName)) { results.add(metadata); } } return results; }