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
(SERVER-297) Consolidate JRuby environment handling #582
(SERVER-297) Consolidate JRuby environment handling #582
Conversation
(cons ruby-code-dir) | ||
(cons (str jruby-home "/lib/ruby/1.9")) | ||
(cons (str jruby-home "/lib/ruby/shared")) | ||
(cons (str jruby-home "/lib/ruby/1.9/site_ruby")))] |
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.
@camlow325 One question I had about this... The ticket says:
For Server 1.X only, add in the "front-loading" of the load path with embedded JRuby path libs, as is done for the irb subcommand today - see https://github.com/puppetlabs/puppet-server/blob/puppet-server-1.0.8/src/clj/puppetlabs/puppetserver/cli/irb.clj#L20-L24.
However, in the master branch both the irb
and ruby
commands, but not gem
front-load these three directories relative to JRUBY_HOME
. I left them in the consolidated implemenetation, but I was wondering if you could clarify the "for 1.X only" piece.
646a2f8
to
6a44dd6
Compare
|
||
(def JRubyMainStatusOrNil | ||
(schema/either JRubyMainStatus | ||
(schema/pred nil? 'nil?))) |
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 could just be schema/maybe JRubyMainStatus
, right?
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.
maybe
... I'm sure you're right, I just started writing schemas for functions so I'll check and fix it up if so.
I think I'm +1, except for the questions about possibly DRY'ing up the ScriptingContainer/RubyInstanceConfig stuff a bit. |
6a44dd6
to
791ba54
Compare
Cool, at this point the only thing that remains to change beyond addressing comments is to add 1 beaker test for each of the subcommands, which I hope to do today. I also have a TODO item to build packages off this topic branch and validate we don't run into the hipchat gem problem described in SERVER-538. If we do run into the issue my plan is to just pull out d7574cc. |
8a9b0b7
to
1813197
Compare
Acceptance test added, this should be ready now. No longer "for review" but still needs the normal review. Chris, this is largely the same as when you looked at it earlier. |
|
||
(def compat-version | ||
"The JRuby compatibility version to use" | ||
(CompatVersion/RUBY1_9)) |
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.
Are these extra parens necessary? Just curious, since we don't have them for compile-mode
above. I can't remember if there's a subtle difference
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.
Yes, CompatVersion/RUBY1_9 is a method, so we need to call it to get the value.
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.
Hmm, actually, it's not a method, it's an enum value ...
public enum CompatVersion {
RUBY1_8, RUBY1_9, RUBY2_0, BOTH;
... which means that the parens can be removed, I think. Should be same as accessing a field.
34ab169
to
586c8e7
Compare
# the need to fix this once Beaker has been modified to make the paths to these | ||
# commands available. | ||
# | ||
cli = "puppetserver" |
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.
Do we need this comment and cli
variable anymore? Let's just inline it below and delete this cruft if so
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.
Fixed up in b14b711 (SERVER-297) Add acceptance tests for env behavior
👍 other than minor nitpick comments |
Without this patch the manner in which environment variables are handled in the JRuby portions of puppet-server vary across the use cases of the `puppetserver {gem,irb,ruby}` command line utilities in addition to the service itself. This is a problem because the behaviors have not kept in sync with one another over time so there has been divergence at times, e.g. `puppetserver gem env` currently fails because PATH is unset in that scenario but set in others, e.g. the production service. This patch addresses the problem by consolidating all of the environment handling behavior into a single authoritative method. The behavior itself remains unchanged, GEM_HOME is set based on the config file value, PATH and HOME are the only variables allowed to flow through to JRuby unmodified, all other variables are filtered out, and JARS_REQUIRE and JARS_NO_REQUIRE are set appropriately. In addition to the environment handling, this patch also consolidates the JRuby load path handling in a similar fashion across the scenarios of command line utilities and the production service.
Fix this error: Caused by: clojure.lang.ExceptionInfo: Output of managed-load-path does not match schema: [(not (instance? java.lang.String a-java.io.File)) (not (instance? java.lang.String a-java.io.File)) (not (instance? java.lang.String a-java.io.File)) (not (instance? java.lang.String a-java.io.File)) (not (instance? java.lang.String a-java.io.File)) (not (instance? java.lang.String a-java.io.File))] at puppetlabs.services.jruby.jruby_puppet_internal$eval9067$managed_load_path__9068.invoke (jruby_puppet_internal.clj:69) puppetlabs.services.jruby.jruby_puppet_internal$prep_scripting_container.invoke (jruby_puppet_internal.clj:89) puppetlabs.services.jruby.jruby_puppet_internal$empty_scripting_container.invoke (jruby_puppet_internal.clj:101) puppetlabs.services.jruby.jruby_puppet_internal$create_scripting_container.invoke (jruby_puppet_internal.clj:117) puppetlabs.services.jruby.jruby_puppet_internal$eval9122$create_pool_instance_BANG___9123$fn__9124.invoke (jruby_puppet_internal.clj:156) puppetlabs.services.jruby.jruby_puppet_internal$eval9122$create_pool_instance_BANG___9123.invoke (jruby_puppet_internal.clj:141)
These defs moved over to jruby-puppet-internal in 23154f4 and are no longer used from jruby-puppet-core.
Without this patch the load path behavior is incorrect because the use of normalized and absolute paths is incompatible with the use of loading resources from a sealed jar. This patch addresses the problem by restoring the previous behavior of implicitly relying in JRuby's LoadService implementation. For more information, particularly on the combination and interaction of load path, class path, and ruby require, please see: https://github.com/jruby/jruby/blob/1.7.20/core/src/main/java/org/jruby/runtime/load/LoadService.java
Without this patch there are not tests covering the behavior of the irb, ruby, and gem JRuby subcommands. This patch addresses the problem by adding integration tests that assert against standard output and the exit status.
Without this patch there are duplicate entries for the system ruby library paths at the head of the $LOAD_PATH. This behavior exists to prevent accidentally loading libraries from the OS MRI copy of Ruby and was necessary back when puppetserver loaded puppet code from the OS ruby library paths. This is no longer necessary as puppet code is isolated in PC1 and exists outside of any Ruby library paths. This patch addresses the problem by removing the duplicate entries from the head of the LOAD_PATH restoring the default behavior of JRuby.
Without this patch the subcommand string given to the cli-run! command may not actually exist in the assumed directory of META-INF/jruby.home/bin/ This patch checks before trying to execute the given subcommand.
Addressing PR comments, sorted by using "find usages" in cursive.
Without this patch the initialization logic for the JRuby instances in new-main and prep-scripting-container are almost identical. This is a problem because they should be identical and the compatibility version and compile mode are not referenced in a way that changing one will also change the other. This patch addresses the problem by making the behavior identical without going so far as to providing a single function that operates on both classes of objects.
Without this patch there aren't any acceptance tests that validate the behavior of environment handling. This patch addresses the problem by adding a test for the irb and ruby commands. The gem command is already tested via the `gem env` command and is difficult to inspect the environment from since it doesn't evaluate arbitrary code like irb and ruby can.
79711eb
to
46135d8
Compare
@nwolfe I've addressed all of your comments. Thanks for the eye to detail. |
…solidate_env_handling (SERVER-297) Consolidate JRuby environment handling
Without this patch the manner in which environment variables are handled in the
JRuby portions of puppet-server vary across the use cases of the
puppetserver {gem,irb,ruby}
command line utilities in addition to the service itself. Thisis a problem because the behaviors have not kept in sync with one another over
time so there has been divergence at times, e.g.
puppetserver gem env
currently fails because PATH is unset in that scenario but set in others, e.g.
the production service.
This patch addresses the problem by consolidating all of the environment
handling behavior into a single authoritative method. The behavior itself
remains unchanged, GEM_HOME is set based on the config file value, PATH and
HOME are the only variables allowed to flow through to JRuby unmodified, all
other variables are filtered out, and JARS_REQUIRE and JARS_NO_REQUIRE are set
appropriately.
In addition to the environment handling, this patch also consolidates the JRuby
load path handling in a similar fashion across the scenarios of command line
utilities and the production service.