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

Add additional JVM parameters [ECR-1769] #342

Merged
merged 20 commits into from
Jul 17, 2018

Conversation

vitvakatu
Copy link
Contributor

@vitvakatu vitvakatu commented Jul 4, 2018

Overview

Add additional user-specified JVM parameters, remove debug setting.


See: https://jira.bf.local/browse/ECR-1769

Definition of Done

@vitvakatu vitvakatu self-assigned this Jul 4, 2018
@vitvakatu vitvakatu requested a review from dmitry-timofeev July 4, 2018 20:06
Copy link
Contributor

@dmitry-timofeev dmitry-timofeev left a comment

Choose a reason for hiding this comment

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

I'd add some tests.

Also, have you explored _JAVA_OPTIONS environment variable that Travis apparently uses? I've seen message from the JVM like picked up _JAVA_OPTIONS=…. I wonder if it works in our case.

/// Additional parameters for JVM.
///
/// Passed directly to JVM while initializing EJB runtime.
/// Parameters must not have dash at the beginning.
Copy link
Contributor

Choose a reason for hiding this comment

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

What will happen if a user passes one? Do we check it anywhere and show a descriptive error message?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Probably good catch! In case of invalid parameter JVM will return pretty descriptive error message

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's impossible to pass a parameter with a dash (Exonum core considers it as an unknown cmd flag)

@@ -58,8 +58,9 @@ impl JavaServiceRuntime {
fn create_java_vm(config: JvmConfig) -> JavaVM {

This comment was marked as resolved.

#[derive(Debug, Clone, Copy)]
pub enum UserParameterError {
/// Trying to specify a parameter that is set by EJB internally.
ForbiddenParameter,
Copy link
Contributor

Choose a reason for hiding this comment

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

How is that displayed to the user? Can we include a parameter that they shall use instead in the error message?

Copy link
Contributor Author

@vitvakatu vitvakatu Jul 5, 2018

Choose a reason for hiding this comment

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

Good idea, I will improve this

@vitvakatu
Copy link
Contributor Author

Lol. As I thought, forbidding _JAVA_OPTIONS failed service_bootstrap test on Travis.

@dmitry-timofeev dmitry-timofeev added the work-in-progress 👷‍♂️ Do not expect reviewers to provide any feedback on WIP PRs — please ask for it explicitly! label Jul 9, 2018
/// TODO
/// Panics if `_JAVA_OPTIONS` environmental variable is set.
pub fn panic_if_java_options() {
if env::var("_JAVA_OPTIONS").is_ok() {
Copy link
Contributor

Choose a reason for hiding this comment

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

I remember you wrote me there are several of them?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, only _JAVA_OPTIONS is important for us, cause only this variable can overwrite command-line args

@dmitry-timofeev
Copy link
Contributor

Marking as wip until tests are added

@vitvakatu vitvakatu removed the work-in-progress 👷‍♂️ Do not expect reviewers to provide any feedback on WIP PRs — please ask for it explicitly! label Jul 10, 2018
@vitvakatu
Copy link
Contributor Author

@dmitry-timofeev do we need any other tests?

@@ -7,7 +7,7 @@ use exonum::node::NodeConfig;
use failure;
use toml::Value;

const EJB_DEBUG: &str = "EJB_DEBUG";
const EJB_USER_PARAMETERS: &str = "EJB_USER_PARAMETERS";
Copy link
Contributor

Choose a reason for hiding this comment

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

JVM_ARGUMENTS?
(EJB_USER_PARAMETERS suggests that these are parameters of EJB).

false,
"Debug mode for JVM.",
"Additional parameters for JVM.",
Copy link
Contributor

Choose a reason for hiding this comment

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

Will it be shown in help? If so, I'd document that these parameters must not have a leading dash (-), e.g., Xmx2G.

}

fn check_not_forbidden(user_parameter: &str) -> Result<(), ForbiddenParameterError> {
if user_parameter.contains("Djava.class.path")
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 contains to restrictive (what if I want to specify a custom property, e.g., -Dfoo.bar=bazDjava.class.path)? Maybe starts_with?

let validation_result = validate_and_convert("Xdebug");
assert_eq!(validation_result, Ok("-Xdebug".to_string()));

let validation_result = validate_and_convert("Duser.parameter");
Copy link
Contributor

Choose a reason for hiding this comment

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

Split into two tests to keep them focused?

pub fn panic_if_java_options() {
if env::var("_JAVA_OPTIONS").is_ok() {
panic!(
"_JAVA_OPTIONS environmental variable is set. \
Copy link
Contributor

Choose a reason for hiding this comment

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

environment

if env::var("_JAVA_OPTIONS").is_ok() {
panic!(
"_JAVA_OPTIONS environmental variable is set. \
Due to the fact that it will overwrite any JVM setting, \
Copy link
Contributor

Choose a reason for hiding this comment

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

any JVM settings

Due to the fact that it will overwrite any JVM setting, \
including ones set by EJB internally, this variable is \
forbidden for EJB applications.\n\
It is recommend to use `--ejb-jvm-args` command-line \
Copy link
Contributor

Choose a reason for hiding this comment

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

It is recommended

@dmitry-timofeev dmitry-timofeev merged commit 72fd7b1 into exonum:master Jul 17, 2018
@vitvakatu vitvakatu deleted the ECR-1769 branch July 18, 2018 07:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants