Skip to content

Add plan name to deserialized topologies for validation uses #550

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 36 additions & 4 deletions src/main/java/com/purbon/kafka/topology/model/Topic.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ public Topic(
dataType,
config,
appConfig,
appConfig.getTopicPrefixFormat());
appConfig.getTopicPrefixFormat(),
null);
}

public Topic(
Expand All @@ -100,7 +101,34 @@ public Topic(
Optional<String> dataType,
Map<String, String> config,
Configuration appConfig) {
this(name, producers, consumers, dataType, config, appConfig, appConfig.getTopicPrefixFormat());
this(
name,
producers,
consumers,
dataType,
config,
appConfig,
appConfig.getTopicPrefixFormat(),
null);
}

public Topic(
String name,
List<Producer> producers,
List<Consumer> consumers,
Optional<String> dataType,
Map<String, String> config,
Configuration appConfig,
String plan) {
this(
name,
producers,
consumers,
dataType,
config,
appConfig,
appConfig.getTopicPrefixFormat(),
plan);
}

public Topic(
Expand All @@ -110,7 +138,8 @@ public Topic(
Optional<String> dataType,
Map<String, String> config,
Configuration appConfig,
String topicNamePattern) {
String topicNamePattern,
String plan) {
this.name = name;
this.dlqPrefix = ""; // this topic is not a dlq topic
this.producers = producers;
Expand All @@ -130,6 +159,8 @@ public Topic(
}
subjectNameStrategy = Optional.empty();
this.topicNamePattern = topicNamePattern;

this.plan = plan;
}

public SubjectNameStrategy getSubjectNameStrategy() {
Expand Down Expand Up @@ -219,7 +250,8 @@ public Topic clone() {
getDataType(),
getConfig(),
getAppConfig(),
topicNamePattern);
topicNamePattern,
getPlan());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,15 @@ public Topic deserialize(JsonParser parser, DeserializationContext context) thro
"Topic \"" + name + "\" references non-existing plan \"" + planLabel + "\"");
}
});
Topic topic = new Topic(name, producers, consumers, optionalDataType, config, this.config);
Topic topic =
new Topic(
name,
producers,
consumers,
optionalDataType,
config,
this.config,
optionalPlanLabel.isPresent() ? optionalPlanLabel.get().asText() : null);

Optional<SubjectNameStrategy> subjectNameStrategy =
Optional.ofNullable(rootNode.get("subject.name.strategy"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ public void testConfigUpdateWhenUsingCustomPlans() throws IOException {
config.put("bar", "3");
assertThat(topic.getConfig()).containsAllEntriesOf(config);

// should include the name of the plan for validation uses
assertThat(topic.getPlan()).isEqualTo("gold");

// should respect values from the original config if not present in the plan description
topic = map.get("barFoo");
assertThat(topic.getConfig()).containsEntry("replication.factor", "1");
Expand Down