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
DGS-8783 Add rulesToMerge/rulesToRemove to tags API #2789
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,8 +15,12 @@ | |
|
||
package io.confluent.kafka.schemaregistry.rest.resources; | ||
|
||
import static io.confluent.kafka.schemaregistry.client.rest.entities.RuleSet.mergeRuleSets; | ||
|
||
import io.confluent.kafka.schemaregistry.client.rest.Versions; | ||
import io.confluent.kafka.schemaregistry.client.rest.entities.ErrorMessage; | ||
import io.confluent.kafka.schemaregistry.client.rest.entities.Rule; | ||
import io.confluent.kafka.schemaregistry.client.rest.entities.RuleSet; | ||
import io.confluent.kafka.schemaregistry.client.rest.entities.Schema; | ||
import io.confluent.kafka.schemaregistry.client.rest.entities.requests.RegisterSchemaRequest; | ||
import io.confluent.kafka.schemaregistry.client.rest.entities.requests.RegisterSchemaResponse; | ||
|
@@ -50,6 +54,7 @@ | |
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import io.swagger.v3.oas.annotations.tags.Tags; | ||
import java.util.stream.Collectors; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
|
@@ -624,18 +629,46 @@ public void modifyTags( | |
} | ||
schemaRegistry.getCompositeUpdateRequestHandler().handle(schema, request); | ||
|
||
if (request.getRuleSet() != null) { | ||
try { | ||
request.getRuleSet().validate(); | ||
} catch (RuleException e) { | ||
throw new RestInvalidRuleSetException(e.getMessage()); | ||
} | ||
} | ||
|
||
Map<String, String> headerProperties = requestHeaderBuilder.buildRequestHeaders( | ||
headers, schemaRegistry.config().whitelistHeaders()); | ||
RegisterSchemaResponse registerSchemaResponse; | ||
try { | ||
RuleSet ruleSet = request.getRuleSet(); | ||
if (request.getRulesToMerge() != null || request.getRulesToRemove() != null) { | ||
int oldVersion = request.getNewVersion() != null ? request.getNewVersion() - 1 : -1; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does -1 mean latest version? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes |
||
Schema oldSchema = schemaRegistry.get(subject, oldVersion, false); | ||
// Use the previous ruleSet instead of the passed in one | ||
ruleSet = oldSchema != null ? oldSchema.getRuleSet() : null; | ||
if (request.getRulesToMerge() != null) { | ||
ruleSet = mergeRuleSets(ruleSet, request.getRulesToMerge()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this change the ordering of the rules? If so does that matter? I remember you mentioning that the order of the ruse matter. It seems like merging the rules would remove any existing role that has the same name as any rule in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, this code will prefer the order of the |
||
} | ||
if (ruleSet != null && request.getRulesToRemove() != null) { | ||
List<String> rulesToRemove = request.getRulesToRemove(); | ||
List<Rule> migrationRules = ruleSet.getMigrationRules(); | ||
if (migrationRules != null) { | ||
migrationRules = migrationRules.stream() | ||
.filter(r -> !rulesToRemove.contains(r.getName())) | ||
.collect(Collectors.toList()); | ||
} | ||
List<Rule> domainRules = ruleSet.getDomainRules(); | ||
if (domainRules != null) { | ||
domainRules = domainRules.stream() | ||
.filter(r -> !rulesToRemove.contains(r.getName())) | ||
.collect(Collectors.toList()); | ||
} | ||
ruleSet = new RuleSet(migrationRules, domainRules); | ||
} | ||
request.setRuleSet(ruleSet); | ||
} | ||
|
||
if (request.getRuleSet() != null) { | ||
try { | ||
request.getRuleSet().validate(); | ||
} catch (RuleException e) { | ||
throw new RestInvalidRuleSetException(e.getMessage()); | ||
} | ||
} | ||
|
||
rayokota marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Schema result = | ||
schemaRegistry.modifySchemaTagsOrForward(subject, schema, request, headerProperties); | ||
registerSchemaResponse = new RegisterSchemaResponse(result); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not take List as a parameter? Or should we call it setRuleSetToMerge?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rulesToMerge
takes aRuleSet
, andrulesToRemove
takes a list of rule names. By "rules" I'm referring to the object semantically, not to the data structure that is passed in. I'd rather not call itruleSetToMerge
andruleNamesToRemove
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO I think
rulesToRemove
is better thanruleNamesToRemove
. But I thinkruleSetToMerge
might better thanrulesToMerge
. However, it seems like the field that the customer sets isrulesToMerge
. What do you think about changing that json field toruleSetToMerge
since it has the same attributes as the existingruleSet
field?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather keep it
rulesToMerge
. In any case, this API may be temporary.