-
Notifications
You must be signed in to change notification settings - Fork 19
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
Extract out IdGeneratorBase and Add NonceGenerator #43
Extract out IdGeneratorBase and Add NonceGenerator #43
Conversation
…hted-id-generation-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.
Class designs need to be redone.
...r-discovery-bundle/src/main/java/io/appform/ranger/discovery/bundle/id/GenerationResult.java
Show resolved
Hide resolved
@Slf4j | ||
public class IdGeneratorBase { | ||
|
||
private final int MINIMUM_ID_LENGTH; |
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.
static
public class IdGeneratorBase { | ||
|
||
private final int MINIMUM_ID_LENGTH; | ||
private final Pattern PATTERN; |
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.
static
private final Pattern PATTERN; | ||
@Getter | ||
private static int NODE_ID; | ||
protected final DateTimeFormatter DATE_TIME_FORMATTER; |
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.
don't use this naming pattern for non static
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.
Updated
} | ||
|
||
public synchronized void registerGlobalConstraints(final IdValidationConstraint... constraints) { | ||
registerGlobalConstraints(ImmutableList.copyOf(constraints)); |
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.
List.copyOf()
...ry-bundle/src/main/java/io/appform/ranger/discovery/bundle/id/generator/IdGeneratorBase.java
Show resolved
Hide resolved
|
||
public RandomNonceGenerator(final IdFormatter idFormatter) { | ||
super(idFormatter); | ||
RetryPolicy<GenerationResult> RETRY_POLICY = RetryPolicy.<GenerationResult>builder() |
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.
These things should all be moved to base. It needs to expose a very limited set of methods (one or two) to generate the id based on logic(random in this case)
} | ||
|
||
@Override | ||
public DateTime getDateTimeFromTime(final long time) { |
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.
what is this method, why is this public and why is it placed below private methods?
import lombok.Getter; | ||
|
||
@Getter | ||
@Builder |
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.
Remove builder here. All members should be populated.
|
||
private static final List<IdValidationConstraint> GLOBAL_CONSTRAINTS = new ArrayList<>(); | ||
private static int nodeId; | ||
private static final IdGeneratorBase baseGenerator = new IdGeneratorBase( |
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.
Too many comments already Havent reviewed this or any further file after this,
83841db
to
402b171
Compare
...ry-bundle/src/main/java/io/appform/ranger/discovery/bundle/id/generator/IdGeneratorBase.java
Show resolved
Hide resolved
47ea2e3
to
29cd86a
Compare
6833733
to
b83b806
Compare
protected final IdFormatter idFormatter; | ||
protected final NonceGeneratorBase nonceGenerator; | ||
|
||
public static void initialize(final int node) { |
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.
We can get rid of this and let the library initialise per instance of this class
ranger-discovery-bundle/src/main/java/io/appform/ranger/discovery/bundle/id/IdGenerator.java
Outdated
Show resolved
Hide resolved
ranger-discovery-bundle/src/main/java/io/appform/ranger/discovery/bundle/id/IdGenerator.java
Show resolved
Hide resolved
ranger-discovery-bundle/src/main/java/io/appform/ranger/discovery/bundle/id/IdGenerator.java
Outdated
Show resolved
Hide resolved
String prefix, | ||
final Domain domain, | ||
boolean skipGlobal) { | ||
private static Optional<Id> generateWithConstraints(String prefix, final Domain domain, boolean skipGlobal) { |
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.
Revert formatting why has the formatting been changed in multiple places? revert all of these
.skipGlobal(skipGlobal) | ||
.domain(domain.getDomain()) | ||
.idFormatter(domain.getIdFormatter()) | ||
.build()); |
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.
Revert all formatting changes
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.
Done
* @param idString String idString | ||
* @return ID if it could be generated | ||
*/ | ||
public Optional<Id> parse(final String idString) { |
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.
Remove this
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.
This will be used for parsing all IDs. This method will determine the formatter used for creation of that ID, then it will delegate the request to that specific formatter. Now that formatter will parse the ID
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.
This would be required. So there are two layers to parsing -
- To determine which formatter was used to generate this ID (in future plan is to add two digit unique identifier per formatter for this)
- Once formatter is defined, individual formatters would be invoked to further parse all related metadata from the ID
This method is only trying to identify the formatter. Rest would be done by individual formatters. We can probably move this method to a new class (say IDParsers)
*/ | ||
@SuppressWarnings("unused") | ||
@Slf4j | ||
public abstract class IdGeneratorBase { |
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 is this class abstract when there are no abstract functions and the constructor is public as well?
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.
Made the constructor protected
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.
@santanusinha Use case of using an abstract class here is to just be able to override constructor and nothing else
.map(generationResult -> this.getIdFromIdInfo(generationResult.getNonceInfo(), request.getPrefix(), request.getIdFormatter())); | ||
} | ||
|
||
public void setNodeId(int nodeId) { |
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 is this non-final?
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.
Made it final
No description provided.