-->

March 20, 2009

TOTD #76: JRuby 1.2, Rails 2.3, GlassFish Gem 0.9.3, ActiveRecord JDBC Adapter 0.9.1 – can they work together ?

Categories: rails, totd, web2.0

Oh, what a week for the JRuby, Rails, and GlassFish enthusiasts!

JRuby 1.2, Rails 2.3, GlassFish Gem 0.9.3, and ActiveRecord JDBC Adapater 0.9.1 – all released earlier this week. This is an opportune moment to run the integration tests to ensure the latest JRuby and GlassFish versions work nicely with each other.

First, lets see whats there to get exicted in each release.

JRuby 1.2 introduces a new versioning scheme by jumping from 1.1.6 -> 1.2. JRUBY-3649 is an important fix for the Windows users. Improved Ruby 1.9 support, 3-6x faster parsing, and preliminary android support are some other highlights. 1052 revisions and 256 bugfixes since 1.1.6 (89 days ago) means close to 12 revisions / day and 3 bugfixes/day!

Rails 2.3 has a bunch of highlights ranging from Rack integration, nested forms, attributes, and transactions, reconnecting lost MySQL connections, Application controller renamed (make sure to “rake rails:update:action_controller” to update from an older version), faster boot time in dev mode using lazy loading, and many others. The Release Notes provide all the detailed information.

The GlassFish Gem with features like running as daemon,  rake-style configuration of JVM options, ability to “sudo install” gem and run as normal user and multi-level logging are all gearing towards adding more production-quality features. My favorite here is running as daemon since that brings the Gem one step closer to the Rails community.

Lets get back to running our tests #1, #2, #3, #4, and #5 for these released versions.

First, lets unzip JRuby 1.2 and install Rails 2.3, GlassFish Gem 0.9.3, and other gems as:

~/tools/jruby-1.2.0 >./bin/jruby -S gem install rails glassfish activerecord-jdbcmysql-adapter
JRuby limited openssl loaded. gem install jruby-openssl for full support.
http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
Successfully installed activesupport-2.3.2
Successfully installed activerecord-2.3.2
Successfully installed actionpack-2.3.2
Successfully installed actionmailer-2.3.2
Successfully installed activeresource-2.3.2
Successfully installed rails-2.3.2
Successfully installed rack-0.9.1
Successfully installed glassfish-0.9.3-universal-java
Successfully installed activerecord-jdbc-adapter-0.9.1
Successfully installed jdbc-mysql-5.0.4
Successfully installed activerecord-jdbcmysql-adapter-0.9.1
11 gems installed
Installing ri documentation for activesupport-2.3.2…
Installing ri documentation for activerecord-2.3.2…
Installing ri documentation for actionpack-2.3.2…
Installing ri documentation for actionmailer-2.3.2…
Installing ri documentation for activeresource-2.3.2…
Installing ri documentation for rack-0.9.1…
Installing ri documentation for glassfish-0.9.3-universal-java…
Installing ri documentation for activerecord-jdbc-adapter-0.9.1…
Installing ri documentation for jdbc-mysql-5.0.4…
Installing ri documentation for activerecord-jdbcmysql-adapter-0.9.1…
Installing RDoc documentation for activesupport-2.3.2…
Installing RDoc documentation for activerecord-2.3.2…
Installing RDoc documentation for actionpack-2.3.2…
Installing RDoc documentation for actionmailer-2.3.2…
Installing RDoc documentation for activeresource-2.3.2…
Installing RDoc documentation for rack-0.9.1…
Installing RDoc documentation for glassfish-0.9.3-universal-java…
Installing RDoc documentation for activerecord-jdbc-adapter-0.9.1…
Installing RDoc documentation for jdbc-mysql-5.0.4…
Installing RDoc documentation for activerecord-jdbcmysql-adapter-0.9.1…

If you have a previous version of GlassFish gem installed, then update it as:

~/tools/jruby-1.1.6 >./bin/jruby -S gem update glassfish
JRuby limited openssl loaded. gem install jruby-openssl for full support.
http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
Updating installed gems
Updating glassfish
Successfully installed glassfish-0.9.3-universal-java
Gems updated: glassfish

Similarly ActiveRecord gem can be updated as:

~/tools/jruby-1.1.6 >./bin/jruby -S gem update activerecord
JRuby limited openssl loaded. gem install jruby-openssl for full support.
http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
Updating installed gems
Updating activerecord-jdbc-adapter
Successfully installed activerecord-jdbc-adapter-0.9.1
Updating activerecord-jdbcmysql-adapter
Successfully installed activerecord-jdbcmysql-adapter-0.9.1
Updating activerecord-jdbcsqlite3-adapter
Successfully installed jdbc-sqlite3-3.6.3.054
Successfully installed activerecord-jdbcsqlite3-adapter-0.9.1
Updating merb_activerecord
Successfully installed merb_activerecord-1.0.0.1
Gems updated: activerecord-jdbc-adapter, activerecord-jdbcmysql-adapter, jdbc-sqlite3, activerecord-jdbcsqlite3-adapter, merb_activerecord

Running test #1 encounters JRUBY-3502, basically “db:create” is not working with JRuby 1.2.0, Rails 2.3.2 and MySQL ActiveRecord JDBC Adapter. However “db:create” works if JRuby 1.2.0 and Rails 2.2.2 are used. Alternatively SQLite3 ActiveRecord JDBC Adapter may be used. So first lets install SQLite3 JDBC adapter as:

~/tools/jruby-1.2.0 >./bin/jruby -S gem install activerecord-jdbcsqlite3-adapter
JRuby limited openssl loaded. gem install jruby-openss
l for full support.
http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
Successfully installed jdbc-sqlite3-3.6.3.054
Successfully installed activerecord-jdbcsqlite3-adapter-0.9.1
2 gems installed
Installing ri documentation for jdbc-sqlite3-3.6.3.054…
Installing ri documentation for activerecord-jdbcsqlite3-adapter-0.9.1…
Installing RDoc documentation for jdbc-sqlite3-3.6.3.054…
Installing RDoc documentation for activerecord-jdbcsqlite3-adapter-0.9.1…

Now lets recreate our application without specifying “-d mysql” switch as:

~/tools/jruby-1.2.0/samples/rails >../../bin/jruby -S rails runner
      create 
      create  app/controllers
      create  app/helpers
. . .
      create  log/production.log
      create  log/development.log
      create  log/test.log

In the generated “config/database.yml”, change the database adapter from:

development:
  adapter: sqlite3
  database: db/development.sqlite3
  pool: 5
  timeout: 5000

to

development:
  adapter: jdbcsqlite3
  database: db/development.sqlite3
  pool: 5
  timeout: 5000

The changes are highlighted in bold. Run the remainder of test #1.

The supported Rails version on GlassFish v3 Prelude is Rails 2.1 so we’ll stick with running a Rails 2.1 (instead of Rails 2.3.2) simple scaffold application but will use the latest JRuby 1.2.0. Running a Rails 2.3.2 on GlassFish v3 Prelude will encounter issue #7384. Please add your comments to the bug report if you are running GlassFish v3 Prelude in production and would like this bug to be fixed!

Rails 2.3.2 require workaround for a WAR-based deployment of a Rails application as expained here. This workaround is required only if you are using JRuby-Rack 0.9.1 or lower. A newer version of JRuby-Rack may solve these problems making these steps optional. The steps are anyway outlined below for convenience:

  1. Uncomment the following line from “config/initializers/session_initializers.rb”:

    ActionController::Base.session_store = :active_record_store
  2. Do “jruby -S warble config” to generate the template “config/warble.rb”, edit it and add the following line:
    config.webxml.jruby.session_store = ‘db’
  3. In “config/environment.rb”, add the following code:
     if defined?(JRUBY_VERSION)
     # hack to fix jruby-rack’s incompatibility with rails edge
     module ActionController
       module Session
         class JavaServletStore
           def initialize(app, options={}); end
           def call(env); end
         end
       end
     end
    end 

    just above the line ”Rails::Initializer.run do |config|”.

Always refer to JRuby/Rails 2.3.2 wiki for the latest information on these steps.

The deployment goes fine after making the changes but bringing up the scaffold page in the browser shows the following error message:

So commented the “jndi” and “driver” entry from “config/database.yml” such that the bundled MySQL JDBC Adapter is used instead. And then the test passes.

Here is a status report after running all the tests:

Test # Description Status
#1 Simple Scaffold using GlassFish Gem PASS (with workaround in JRUBY-3502)
#2 Simple Scaffold using GlassFish v3 Prelude PASS
#3 Simple Scaffold using GlassFish v3 FAIL (used workaround mentioned in JRUBY-3502,  issues #7266, #7270, #7271 still need to be fixed). PASS if the Application and Controller name are different.
#4 Simple Scaffold as WAR-based application on GlassFish v2.1 FAIL (issue #7385), PASS (with workaround in issue JRUBY-3515)
#5 Redmine using GlassFish Gem PASS

It’s certainly exciting to know that @grantmichaels is already using the latest version of GlassFish Gem and Rails in production :)

JRuby/GlassFish Wiki provide a list of other known JRuby/Rails/GlassFish deployments in production. Leave a comment on this blog if you are using it as well and we’ll be happy to add your name!

The complete set of tests are available using the tags rubyonrails+glassfish+integrationtest. So to answer the
title of this blog – YES, JRuby 1.2.0, Rails 2.3.2, GlassFish Gem 0.9.3, ActiveRecord JDBC Adapater 0.9.1 all work together with the restrictions stated above. GlassFish v3 is a moving target and the bugs will be fixed soon. JRUBY-3515 is what delayed this entry otherwise would’ve posted it much earlier ;-)

Please leave suggestions on other TOTD (Tip Of The Day) that you’d like to see. A complete archive of all tips is available here.

Technorati: totd rubyonrails glassfish v3 gem jruby sampleapp activerrecord redmine integrationtest

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • StumbleUpon
  • Technorati
  • Twitter
  • Slashdot
Related posts:
  1. TOTD #37: SQLite3 with Ruby-on-Rails on GlassFish Gem
  2. TOTD #70: JRuby and GlassFish Integration Test# 1: JRuby 1.2.0 RC1 + Rails 2.2.x + GlassFish Gem
  3. Getting Started with Edge Rails (2.2) using JRuby and GlassFish
  4. TOTD #110: JRuby on Rails application using Oracle on GlassFish
  5. TOTD #71: JRuby and GlassFish Integration Test #2: JRuby 1.2.0 RC1 + Rails 2.2.x + GlassFish v3 Prelude

1 Comment »

  1. [Trackback] Bookmarked your post over at Blog Bookmarker.com!

    Comment by lets active — March 21, 2009 @ 2:19 am

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WordPress
176546 visits from Sep 11, 2009