use of org.apache.kafka.streams.StreamsMetadata in project kafka by apache.
the class NamedTopologyIntegrationTest method verifyMetadataForTopology.
/**
* Validates that each metadata object has only partitions & state stores for its specific topology name and
* asserts that {@code left} and {@code right} differ only by {@link StreamsMetadata#hostInfo()}
*/
private void verifyMetadataForTopology(final String topologyName, final Collection<StreamsMetadata> left, final Collection<StreamsMetadata> right) {
assertThat(left.size(), equalTo(right.size()));
final Iterator<StreamsMetadata> leftIter = left.iterator();
final Iterator<StreamsMetadata> rightIter = right.iterator();
while (leftIter.hasNext()) {
final StreamsMetadataImpl leftMetadata = (StreamsMetadataImpl) leftIter.next();
final StreamsMetadataImpl rightMetadata = (StreamsMetadataImpl) rightIter.next();
verifyPartitionsAndStoresForTopology(topologyName, leftMetadata);
verifyPartitionsAndStoresForTopology(topologyName, rightMetadata);
assertThat(verifyEquivalentMetadataForHost(leftMetadata, rightMetadata), is(true));
}
}
use of org.apache.kafka.streams.StreamsMetadata in project kafka by apache.
the class StreamsMetadataState method getKeyQueryMetadataForKey.
private <K> KeyQueryMetadata getKeyQueryMetadataForKey(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));
}
HostInfo activeHost = UNKNOWN_HOST;
final Set<HostInfo> standbyHosts = new HashSet<>();
for (final StreamsMetadata streamsMetadata : allMetadata) {
final Set<String> activeStateStoreNames = streamsMetadata.stateStoreNames();
final Set<TopicPartition> topicPartitions = new HashSet<>(streamsMetadata.topicPartitions());
final Set<String> standbyStateStoreNames = streamsMetadata.standbyStateStoreNames();
final Set<TopicPartition> standbyTopicPartitions = new HashSet<>(streamsMetadata.standbyTopicPartitions());
topicPartitions.retainAll(matchingPartitions);
if (activeStateStoreNames.contains(storeName) && !topicPartitions.isEmpty()) {
activeHost = streamsMetadata.hostInfo();
}
standbyTopicPartitions.retainAll(matchingPartitions);
if (standbyStateStoreNames.contains(storeName) && !standbyTopicPartitions.isEmpty()) {
standbyHosts.add(streamsMetadata.hostInfo());
}
}
return new KeyQueryMetadata(activeHost, standbyHosts, partition);
}
use of org.apache.kafka.streams.StreamsMetadata in project kafka by apache.
the class StreamsMetadataState method getAllMetadataForTopology.
public synchronized Collection<StreamsMetadata> getAllMetadataForTopology(final String topologyName) {
Objects.requireNonNull(topologyName, "topologyName cannot be null");
if (!isInitialized()) {
return Collections.emptyList();
}
final ArrayList<StreamsMetadata> results = new ArrayList<>();
for (final StreamsMetadata metadata : allMetadata) {
final String metadataTopologyName = ((StreamsMetadataImpl) metadata).topologyName();
if (metadataTopologyName != null && metadataTopologyName.equals(topologyName)) {
results.add(metadata);
}
}
return results;
}
use of org.apache.kafka.streams.StreamsMetadata in project kafka by apache.
the class StreamsMetadataTest method shouldNotBeEqualIfDifferInHostInfo.
@Test
public void shouldNotBeEqualIfDifferInHostInfo() {
final StreamsMetadata differHostInfo = new StreamsMetadataImpl(new HostInfo("different", 122), STATE_STORE_NAMES, TOPIC_PARTITIONS, STAND_BY_STORE_NAMES, STANDBY_TOPIC_PARTITIONS);
assertThat(streamsMetadata, not(equalTo(differHostInfo)));
assertThat(streamsMetadata.hashCode(), not(equalTo(differHostInfo.hashCode())));
}
use of org.apache.kafka.streams.StreamsMetadata in project kafka by apache.
the class StreamsMetadataTest method shouldNotBeEqualIfDifferInStandByTopicPartitions.
@Test
public void shouldNotBeEqualIfDifferInStandByTopicPartitions() {
final StreamsMetadata differStandByTopicPartitions = new StreamsMetadataImpl(HOST_INFO, STATE_STORE_NAMES, TOPIC_PARTITIONS, STAND_BY_STORE_NAMES, mkSet(TP_0));
assertThat(streamsMetadata, not(equalTo(differStandByTopicPartitions)));
assertThat(streamsMetadata.hashCode(), not(equalTo(differStandByTopicPartitions.hashCode())));
}
Aggregations