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

[PAYARA-3909] - Can't Use Any of the Variable Types in JDBC Connection Pool Settings #4075

Merged
merged 10 commits into from Jul 18, 2019

Conversation

cubastanley
Copy link
Contributor

It is desired that variable types can be used in place of set values in JDBC connection pool settings (i.e. set maxPoolSize = ${MAX_POOL_SIZE_PROPERTY}) - this was previously not possible due to the validation process of JDBC connection pool properties (results in a NumberFormatException trying to parse an incorrect format string to an Integer) - the changes in this PR get around that

@cubastanley
Copy link
Contributor Author

Jenkins test please

Copy link
Contributor

@AlanRoth AlanRoth left a comment

Choose a reason for hiding this comment

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

byootiful

@cubastanley
Copy link
Contributor Author

Jenkins test please

*
* @return possible object is
* {@link String }
*/
@Attribute (defaultValue="32")
@Min(value=1)
@Max(value=Integer.MAX_VALUE)
String getMaxPoolSize();
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't removing the min/max value begging for illegal values to be configured? Shouldn't they be at least checked for in code somewhere? Or rather keep them and extend validation to allow for variables whose value may be validated as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree it is a rather risky move, although as far as I'm aware these annotations will always cause a validation exception in the event that a user tries to input a string that cannot be parsed to an Integer (as would be the case with a system variable name) I've altered the basic check in the implementation of JdbcConnectionPool so as to prevent the value from being below 1 but I do agree that it isn't the safest situation

Copy link
Contributor

Choose a reason for hiding this comment

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

I think @svendiedrichsen has a good point here. Surely extending the mechanism isn't part of the task as originally requested but if we don't include this or make it a precondition of this PR we introduce room for error that might never be closed again even when we would like to see this happen in the near future.

@svendiedrichsen
Copy link
Contributor

svendiedrichsen commented Jul 6, 2019

How about supporting the existing variable mechanism and its different types here: https://docs.payara.fish/documentation/payara-server/server-configuration/var-substitution/

Would thus automatically support MicroProfile config.

@cubastanley
Copy link
Contributor Author

Jenkins test please


//By this point it should be the case that the value is always castable
//to an integer
maxPoolSizeValue = Integer.parseInt(maxPoolSize);
Copy link
Member

Choose a reason for hiding this comment

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

This will cause NumberFormatException if the string does not have the appropriate numeric value.

default:
//We got a system variable as no split occured
if (systemProps.getProperty(variableReference[0]) != null && !systemProps.getProperty(variableReference[0]).isEmpty()) {
return systemProps.getProperty(variableReference[0]);
Copy link
Member

Choose a reason for hiding this comment

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

Can't you just simply use System.getProperty(variableToRetrieve) here.

@cubastanley
Copy link
Contributor Author

Jenkins Test Please

@cubastanley cubastanley requested a review from MeroRai July 17, 2019 10:15
Copy link
Contributor

@jbee jbee left a comment

Choose a reason for hiding this comment

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

Needs some cleanup.

switch(variableReference[0]) {
case "ENV":
//Check environment variables for requested value
if (System.getenv(variableReference[1]) != null && !System.getenv(variableReference[1]).isEmpty()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

System.getenv(variableReference[1]) should be extracted to local var

case "MPCONFIG":
//Check microprofile config for requested value
Config config = ConfigProvider.getConfig();
if (config.getValue(variableReference[1], String.class) != null && !config.getValue(variableReference[1], String.class).isEmpty()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

config.getValue(variableReference[1], String.class) should be extracted to local var

break;
default:
//We got a system variable as no split occured
if (System.getProperty(variableReference[0]) != null && !System.getProperty(variableReference[0]).isEmpty()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

local var

if(steadyPoolSize == null) {

int maxPoolSizeValue = 0;
int steadyPoolSizeValue = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

It should be possible to add a helper function where the min/max/default and actual value go in and the successfully parsed or resolved value comes out that can be used for both of these. Essentially making a method that does the extended version of that the annotations did semantically.

@cubastanley cubastanley requested a review from jbee July 17, 2019 12:11
@cubastanley
Copy link
Contributor Author

Jenkins Test Please

@cubastanley cubastanley merged commit 6730580 into payara:master Jul 18, 2019
@arjantijms arjantijms added this to the 5.193 milestone Jul 18, 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.

None yet

6 participants