-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ability to bless (not terminate) topics by name/regex (#18)
Co-authored-by: Sverre H. Huseby <shh+github@thathost.com>
- Loading branch information
Showing
5 changed files
with
72 additions
and
2 deletions.
There are no files selected for viewing
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
34 changes: 34 additions & 0 deletions
34
src/main/java/io/statnett/k3a/topicterminator/strategy/BlessedTopic.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,34 @@ | ||
package io.statnett.k3a.topicterminator.strategy; | ||
|
||
import org.apache.kafka.clients.admin.AdminClient; | ||
|
||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.Set; | ||
import java.util.regex.Pattern; | ||
import java.util.stream.Collectors; | ||
|
||
public class BlessedTopic implements ReservedTopic { | ||
private final Set<String> allNames; | ||
private final Collection<Pattern> patterns; | ||
|
||
public BlessedTopic(Set<String> allNames, Collection<Pattern> patterns) { | ||
this.allNames = allNames; | ||
this.patterns = patterns; | ||
} | ||
|
||
@Override | ||
public Set<String> getNames(AdminClient client) { | ||
if (patterns == null || patterns.isEmpty()) { | ||
return Collections.emptySet(); | ||
} | ||
return allNames.stream() | ||
.filter(this::isBlessed) | ||
.collect(Collectors.toSet()); | ||
} | ||
|
||
private boolean isBlessed(String topicName) { | ||
return patterns.stream() | ||
.anyMatch(pattern -> pattern.matcher(topicName).matches()); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
app: | ||
dry-run: false | ||
blessed-topics: ^blessed.*,topic-foo |