Skip to content
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

ISSUE-631 : Schema Registry numeric properties cannot be set via a property file #629

Merged
merged 3 commits into from
Dec 7, 2019

Conversation

heritamas
Copy link
Contributor

@heritamas heritamas commented Nov 28, 2019

During initialization property file is read into a Properties object and
validated against a predefined set of rules. However, it was implicitly
assumed, that property values can only String typed.

This fix adds the necessary conversion beside the already existing validation.

FIxes #631

@heritamas heritamas requested a review from guruchai November 29, 2019 12:24
@heritamas heritamas marked this pull request as ready for review November 29, 2019 12:24
@raju-saravanan raju-saravanan changed the title [CSP-636] Schema Registry numeric properties cannot be set via a prop… ISSUE-631 : Schema Registry numeric properties cannot be set via a prop… Dec 3, 2019
@raju-saravanan raju-saravanan changed the title ISSUE-631 : Schema Registry numeric properties cannot be set via a prop… ISSUE-631 : Schema Registry numeric properties cannot be set via a property file Dec 3, 2019
Copy link
Collaborator

@raju-saravanan raju-saravanan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @heritamas for raising this PR. Overall LGTM, left a few minor comments.

…erty file

During initialization property file is read into a Properties object and
validated against a predefined set of rules. However, it was implicitly
assumed, that property values can only String typed.

This fix adds the necessary conversion beside the already existing validation.
Copy link
Contributor

@kamalcph kamalcph left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

…erty file

Specific ConfigTypeConversionException type added to signal different conversion problems.
Conversions are made more explicit, errors are signaled via exceptions.
Copy link
Collaborator

@raju-saravanan raju-saravanan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 LGTM, thanks @heritamas for the PR. I will merge this PR once the exception class has been updated with the license header.

@kamalcph
Copy link
Contributor

kamalcph commented Dec 6, 2019

@heritamas @raju-saravanan

I usually avoid taking extra fields if it can be inferred from other fields. Can we avoid using the Converter and use the Type field instead? I was thinking something like below in ConfigEntry class:

    @SuppressWarnings("unchecked")
    public static <T> T parseValue(Class<T> clazz, Object value) {
        if (clazz.equals(String.class)) {
            return (T) String.valueOf(value);
        } else if (clazz.equals(Integer.class)) {
            try {
                return (T) Integer.valueOf(value.toString());
            } catch (NumberFormatException ex) {
                throw new ConfigTypeConversionException(ex.getMessage(), ex);
            }
        } else if (clazz.equals(Long.class)) {
            return (T) Long.valueOf(value.toString());
        } else {
            throw new ConfigTypeConversionException("Found " + value.getClass() + " instead of " + clazz + " for value: " + value);
        }
    }

finalValue = ConfigEntry.parseValue(configEntry.type(), value);

I'm fine with both approaches.

@heritamas
Copy link
Contributor Author

@kamalcph , regarding your comment:
I feel, whatever approach we choose, it would not be elegant, or clean - class casting would remain somewhere in the code.

Would it worth to refactor Property handling to a typed solution, like this?

@kamalcph
Copy link
Contributor

kamalcph commented Dec 6, 2019

Adding a new dependency may not worth it. Let's go with your approach.

@raju-saravanan
Copy link
Collaborator

raju-saravanan commented Dec 6, 2019

@heritamas and @kamalcph I gonna go ahead and merge this PR.

@raju-saravanan raju-saravanan merged commit 5be4f6a into hortonworks:master Dec 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Schema Registry numeric properties cannot be set via a property file
3 participants