-
Notifications
You must be signed in to change notification settings - Fork 281
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
Yingjianw/additional safety rollout #602
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8317b70
safety flag to control the parent child relationship rollout
c91c57e
Add validaton to prevent creating another new name with a different uuid
084e314
add search endpoint for getParents
9bd01c5
moveConfig out to oss
17ad8a2
default flags to false
133d10a
use limit 1 to speed up check exist query
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
119 changes: 119 additions & 0 deletions
119
.../java/com/netflix/metacat/common/server/properties/ParentChildRelationshipProperties.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,119 @@ | ||
package com.netflix.metacat.common.server.properties; | ||
|
||
import lombok.Data; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.core.env.Environment; | ||
|
||
import javax.annotation.Nullable; | ||
import java.util.Arrays; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* Parent Child Relationship service properties. | ||
* | ||
* @author yingjianw | ||
*/ | ||
@Data | ||
@Slf4j | ||
public class ParentChildRelationshipProperties { | ||
private static final String MAX_ALLOW_PER_TABLE_PER_REL_PROPERTY_NAME = | ||
"metacat.parentChildRelationshipProperties.maxAllowPerTablePerRelConfig"; | ||
private static final String MAX_ALLOW_PER_DB_PER_REL_PROPERTY_NAME = | ||
"metacat.parentChildRelationshipProperties.maxAllowPerDBPerRelConfig"; | ||
private static final String DEFAULT_MAX_ALLOW_PER_REL_PROPERTY_NAME = | ||
"metacat.parentChildRelationshipProperties.defaultMaxAllowPerRelConfig"; | ||
private boolean createEnabled; | ||
private boolean getEnabled; | ||
private boolean renameEnabled; | ||
private boolean dropEnabled; | ||
private int maxAllow = 5; | ||
private Map<String, Map<String, Integer>> maxAllowPerTablePerRelType = new HashMap<>(); | ||
private Map<String, Map<String, Integer>> maxAllowPerDBPerRelType = new HashMap<>(); | ||
private Map<String, Integer> defaultMaxAllowPerRelType = new HashMap<>(); | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param env Spring environment | ||
*/ | ||
public ParentChildRelationshipProperties(@Nullable final Environment env) { | ||
if (env != null) { | ||
setMaxAllowPerTablePerRelType( | ||
env.getProperty(MAX_ALLOW_PER_TABLE_PER_REL_PROPERTY_NAME, String.class, "") | ||
); | ||
setMaxAllowPerDBPerRelType( | ||
env.getProperty(MAX_ALLOW_PER_DB_PER_REL_PROPERTY_NAME, String.class, "") | ||
); | ||
setDefaultMaxAllowPerRelType( | ||
env.getProperty(DEFAULT_MAX_ALLOW_PER_REL_PROPERTY_NAME, String.class, "") | ||
); | ||
} | ||
} | ||
|
||
/** | ||
* setMaxAllowPerTablePerRelType based on String config. | ||
* | ||
* @param configStr configString | ||
*/ | ||
public void setMaxAllowPerTablePerRelType(@Nullable final String configStr) { | ||
if (configStr == null || configStr.isEmpty()) { | ||
return; | ||
} | ||
try { | ||
this.maxAllowPerTablePerRelType = parseNestedConfigString(configStr); | ||
} catch (Exception e) { | ||
log.error("Fail to apply configStr = {} for maxAllowPerTablePerRelType", configStr, e); | ||
} | ||
} | ||
|
||
/** | ||
* setMaxAllowPerDBPerRelType based on String config. | ||
* | ||
* @param configStr configString | ||
*/ | ||
public void setMaxAllowPerDBPerRelType(@Nullable final String configStr) { | ||
if (configStr == null || configStr.isEmpty()) { | ||
return; | ||
} | ||
try { | ||
this.maxAllowPerDBPerRelType = parseNestedConfigString(configStr); | ||
} catch (Exception e) { | ||
log.error("Fail to apply configStr = {} for maxCloneAllowPerDBPerRelType", configStr); | ||
} | ||
} | ||
/** | ||
* setMaxCloneAllowPerDBPerRelType based on String config. | ||
* | ||
* @param configStr configString | ||
*/ | ||
public void setDefaultMaxAllowPerRelType(@Nullable final String configStr) { | ||
if (configStr == null || configStr.isEmpty()) { | ||
return; | ||
} | ||
try { | ||
this.defaultMaxAllowPerRelType = | ||
Arrays.stream(configStr.split(";")) | ||
.map(entry -> entry.split(",")) | ||
.collect(Collectors.toMap( | ||
parts -> parts[0], | ||
parts -> Integer.parseInt(parts[1]) | ||
)); | ||
} catch (Exception e) { | ||
log.error("Fail to apply configStr = {} for defaultMaxAllowPerRelType", configStr); | ||
} | ||
} | ||
|
||
private Map<String, Map<String, Integer>> parseNestedConfigString(final String configStr) { | ||
return Arrays.stream(configStr.split(";")) | ||
.map(entry -> entry.split(",")) | ||
.collect(Collectors.groupingBy( | ||
parts -> parts[0], | ||
Collectors.toMap( | ||
parts -> parts[1], | ||
parts -> Integer.parseInt(parts[2]) | ||
) | ||
)); | ||
} | ||
} |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
one the one hand, i would suggest we rename this to
getParent
since we are enforcing the one-parent-per-child rule and its a little confusing as the name implies we can expect more than one results. on the other hand, this API does technically return more than one result, so we would need to have a different return type to make this change. i have a weak preference to rename it and change the contract despite it becoming less flexible, but its up to youThere 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.
If the api stays having multiple return values then plural is better so that the correspondence holds, otherwise singular. There is no current use case for multiple parents but keeping the flexibility is reasonable.
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 was thinking the same thing before the implementation but ultimately choose to have the api flexibile that can return multiple parents.
Another benefit is if indeed somehow we end up with two parents on the same child table due to db isolation issues, we can still get them instead of just one.