-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* WIP metadataClient impl * WIP metadataClient API impl; finished listOffsets * Minor code cleanups * Add test for listConsumerGroupOffsets * Try to fix test * Add javadocs * Address comments
- Loading branch information
Showing
15 changed files
with
1,115 additions
and
2 deletions.
There are no files selected for viewing
453 changes: 453 additions & 0 deletions
453
...tegration-test/src/test/java/com/pinterest/psc/metadata/client/TestPscMetadataClient.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
psc/src/main/java/com/pinterest/psc/metadata/MetadataUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.pinterest.psc.metadata; | ||
|
||
import com.google.common.annotations.VisibleForTesting; | ||
import com.pinterest.psc.common.TopicRn; | ||
import com.pinterest.psc.common.TopicUri; | ||
|
||
/** | ||
* Utility class for common metadata logic | ||
*/ | ||
public class MetadataUtils { | ||
|
||
@VisibleForTesting | ||
public static TopicRn createTopicRn(TopicUri topicUri, String topicName) { | ||
return new TopicRn( | ||
topicUri.getTopicRn().getTopicRnPrefixString() + topicName, | ||
topicUri.getTopicRn().getTopicRnPrefixString(), | ||
topicUri.getTopicRn().getStandard(), | ||
topicUri.getTopicRn().getService(), | ||
topicUri.getTopicRn().getEnvironment(), | ||
topicUri.getTopicRn().getCloud(), | ||
topicUri.getTopicRn().getRegion(), | ||
topicUri.getTopicRn().getClassifier(), | ||
topicUri.getTopicRn().getCluster(), | ||
topicName | ||
); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
psc/src/main/java/com/pinterest/psc/metadata/TopicRnMetadata.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.pinterest.psc.metadata; | ||
|
||
import com.pinterest.psc.common.TopicRn; | ||
import com.pinterest.psc.common.TopicUriPartition; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Metadata for a {@link TopicRn}, including the list of its partitions | ||
*/ | ||
public class TopicRnMetadata { | ||
|
||
private final TopicRn topicRn; | ||
private final List<TopicUriPartition> topicUriPartitions; | ||
|
||
public TopicRnMetadata(TopicRn topicRn, List<TopicUriPartition> topicUriPartitions) { | ||
this.topicRn = topicRn; | ||
this.topicUriPartitions = topicUriPartitions; | ||
} | ||
|
||
public TopicRn getTopicRn() { | ||
return topicRn; | ||
} | ||
|
||
public List<TopicUriPartition> getTopicUriPartitions() { | ||
return topicUriPartitions; | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
psc/src/main/java/com/pinterest/psc/metadata/client/PscBackendMetadataClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package com.pinterest.psc.metadata.client; | ||
|
||
import com.google.common.annotations.VisibleForTesting; | ||
import com.pinterest.psc.common.MessageId; | ||
import com.pinterest.psc.common.ServiceDiscoveryConfig; | ||
import com.pinterest.psc.common.TopicRn; | ||
import com.pinterest.psc.common.TopicUri; | ||
import com.pinterest.psc.common.TopicUriPartition; | ||
import com.pinterest.psc.config.PscConfigurationInternal; | ||
import com.pinterest.psc.discovery.ServiceDiscoveryManager; | ||
import com.pinterest.psc.environment.Environment; | ||
import com.pinterest.psc.exception.startup.ConfigurationException; | ||
import com.pinterest.psc.metadata.TopicRnMetadata; | ||
|
||
import java.time.Duration; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.concurrent.ExecutionException; | ||
import java.util.concurrent.TimeoutException; | ||
|
||
/** | ||
* An abstract class that defines the interface for metadata queries and operations. Specific implementations | ||
* of this class should be created for each backend, such as Kafka, MemQ, etc. | ||
*/ | ||
public abstract class PscBackendMetadataClient implements AutoCloseable { | ||
|
||
protected TopicUri topicUri; | ||
protected PscConfigurationInternal pscConfigurationInternal; | ||
protected ServiceDiscoveryConfig discoveryConfig; | ||
|
||
public void initialize(TopicUri topicUri, Environment env, PscConfigurationInternal pscConfigurationInternal) throws ConfigurationException { | ||
this.topicUri = topicUri; | ||
this.pscConfigurationInternal = pscConfigurationInternal; | ||
this.discoveryConfig = | ||
ServiceDiscoveryManager.getServiceDiscoveryConfig(env, pscConfigurationInternal.getDiscoveryConfiguration(), topicUri); | ||
} | ||
|
||
public abstract List<TopicRn> listTopicRns(Duration duration) | ||
throws ExecutionException, InterruptedException, TimeoutException; | ||
|
||
public abstract Map<TopicRn, TopicRnMetadata> describeTopicRns( | ||
Collection<TopicRn> topicRns, | ||
Duration duration | ||
) throws ExecutionException, InterruptedException, TimeoutException; | ||
|
||
public abstract Map<TopicUriPartition, Long> listOffsets( | ||
Map<TopicUriPartition, PscMetadataClient.MetadataClientOption> topicRnsAndOptions, | ||
Duration duration | ||
) throws ExecutionException, InterruptedException, TimeoutException; | ||
|
||
public abstract Map<TopicUriPartition, Long> listOffsetsForConsumerGroup( | ||
String consumerGroupId, | ||
Collection<TopicUriPartition> topicUriPartitions, | ||
Duration duration | ||
) throws ExecutionException, InterruptedException, TimeoutException; | ||
|
||
public abstract void close() throws Exception; | ||
|
||
@VisibleForTesting | ||
protected TopicUri getTopicUri() { | ||
return topicUri; | ||
} | ||
} |
Oops, something went wrong.