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

(SERVER-297) Consolidate JRuby environment handling #582

Conversation

jeffmccune
Copy link
Contributor

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.

(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")))]
Copy link
Contributor Author

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.

@jeffmccune jeffmccune force-pushed the improve/master/SERVER-297_consolidate_env_handling branch 4 times, most recently from 646a2f8 to 6a44dd6 Compare June 3, 2015 00:11

(def JRubyMainStatusOrNil
(schema/either JRubyMainStatus
(schema/pred nil? 'nil?)))

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?

Copy link
Contributor Author

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.

@cprice404
Copy link

I think I'm +1, except for the questions about possibly DRY'ing up the ScriptingContainer/RubyInstanceConfig stuff a bit.

@jeffmccune jeffmccune force-pushed the improve/master/SERVER-297_consolidate_env_handling branch from 6a44dd6 to 791ba54 Compare June 3, 2015 19:24
@jeffmccune
Copy link
Contributor Author

I think I'm +1, except for the questions about possibly DRY'ing up the ScriptingContainer/RubyInstanceConfig stuff a bit.

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.

@jeffmccune jeffmccune force-pushed the improve/master/SERVER-297_consolidate_env_handling branch 3 times, most recently from 8a9b0b7 to 1813197 Compare June 4, 2015 23:37
@jeffmccune jeffmccune changed the title [FOR REVIEW] (SERVER-297) Consolidate JRuby environment handling (SERVER-297) Consolidate JRuby environment handling Jun 5, 2015
@jeffmccune
Copy link
Contributor Author

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))
Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor

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.

@jeffmccune jeffmccune force-pushed the improve/master/SERVER-297_consolidate_env_handling branch 2 times, most recently from 34ab169 to 586c8e7 Compare June 5, 2015 18:12
# the need to fix this once Beaker has been modified to make the paths to these
# commands available.
#
cli = "puppetserver"
Copy link
Contributor

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

Copy link
Contributor Author

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

@nwolfe
Copy link
Contributor

nwolfe commented Jun 5, 2015

👍 other than minor nitpick comments

Jeff McCune added 12 commits June 5, 2015 12:03
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.
@jeffmccune jeffmccune force-pushed the improve/master/SERVER-297_consolidate_env_handling branch from 79711eb to 46135d8 Compare June 5, 2015 19:11
@jeffmccune
Copy link
Contributor Author

@nwolfe I've addressed all of your comments. Thanks for the eye to detail.

nwolfe added a commit that referenced this pull request Jun 5, 2015
…solidate_env_handling

(SERVER-297) Consolidate JRuby environment handling
@nwolfe nwolfe merged commit 08695d2 into puppetlabs:master Jun 5, 2015
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

5 participants