Monday Aug 18, 2008

LOTD #3: Rails 2.2 going multi-threaded


Rails 2.2 is slated to become multi-threaded. What does it mean for JRuby users ? Charles Nutter explains it:

Q/A: What Thread-Safe Rails Means

One of the key points from the blog is:

Rails deployments on JRuby will use 1/Nth the amount of memory they use now, where N is the number of thread-unsafe Rails instances currently required to handle concurrent requests. Even compared to green-threaded implementations running thread-safe Rails, it willl likely use 1/Mth the memory where M is the number of cores, since it can parallelize happily across cores with only "one" instance.

NetBeans development and GlassFish deployment already provide an ideal environment for Rails deployment.

All previous entries in this series are archived at LOTD.

Technorati: lotd rubyonrails jruby ruby netbeans glassfish

Monday Aug 04, 2008

JRuby on GlassFish v2 - screencast from community


Here is a (year old) community contributed video showing how to deploy a Ruby-on-Rails application on GlassFish v2 application server:


The presenter is not speaking and typing really fast, I wish there was a slower playback available :)

Anyway, thanks to Angsuman for the tip!

Screencast #Web9 shows how to deploy a Rails application as WAR in GlassFish v2. Some other relevant entries are:
And a lot more entries available here. Complete details about are available at JRuby in GlassFish wiki.

Let us know if you have published any artifacts related to GlassFish.

Technorati: rubyonrails jruby ruby glassfish youtube

Monday Jul 21, 2008

JRuby 1.1.3 released - Getting Started with GlassFish


JRuby 1.1.3 was released last week - download here. The highlights are:
  • 82 issues resolved since JRUby 1.1.2
  • RubyGem 1.2 (phew, finally Gem installation is much faster again :)
  • Bunch of Compatibility and Performance problems
Going forward, JRuby point releases will be on a 3-4 week frequency. And you can always checkout the trunk and build yourself.

Here are few simple steps to get you started:
  1. Download and unzip the distribution.
  2. Install Rails and GlassFish gem:

    ~/testbed/jruby-1.1.3 >./bin/jruby -S gem install rails glassfish --no-ri --no-rdoc
    JRuby limited openssl loaded. gem install jruby-openssl for full support.
    http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
    Successfully installed activesupport-2.1.0
    Successfully installed activerecord-2.1.0
    Successfully installed actionpack-2.1.0
    Successfully installed actionmailer-2.1.0
    Successfully installed activeresource-2.1.0
    Successfully installed rails-2.1.0
    Successfully installed glassfish-0.3.1-universal-java
    7 gems installed
  3. Create a new Rails app as:

    ~/testbed/jruby-1.1.3/samples/rails >../../bin/jruby -S rails helloworld -d mysql 
          create 
          create  app/controllers
          create  app/helpers
          create  app/models
          create  app/views/layouts
          create  config/environments
          create  config/initializers
          create  db
          create  doc
    . . .
          create  log/server.log
          create  log/production.log
          create  log/development.log
          create  log/test.log
  4. Run Rails application on GlassFish gem as:

    ~/testbed/jruby-1.1.3/samples/rails >../../bin/jruby -S glassfish_rails helloworld
    Jul 21, 2008 8:32:03 AM com.sun.enterprise.glassfish.bootstrap.ASMain main
    INFO: Launching GlassFish on HK2 platform
    Jul 21, 2008 8:32:03 AM com.sun.enterprise.glassfish.bootstrap.ASMainHK2 findDerbyClient
    INFO: Cannot find javadb client jar file, jdbc driver not available
    Jul 21, 2008 8:32:04 AM com.sun.enterprise.v3.services.impl.GrizzlyProxy start
    INFO: Listening on port 3000
    Jul 21, 2008 8:32:04 AM com.sun.enterprise.v3.services.impl.GrizzlyEmbeddedHttpConfigurator configureSSL
    WARNING: pewebcontainer.all_ssl_protocols_disabled
    Jul 21, 2008 8:32:04 AM com.sun.enterprise.v3.services.impl.GrizzlyEmbeddedHttpConfigurator configureSSL
    WARNING: pewebcontainer.all_ssl_ciphers_disabled
    Jul 21, 2008 8:32:04 AM com.sun.enterprise.v3.services.impl.GrizzlyProxy start
    INFO: Listening on port 3131
    Jul 21, 2008 8:32:04 AM com.sun.enterprise.v3.services.impl.GrizzlyProxy start
    INFO: Listening on port 3838
    Jul 21, 2008 8:32:04 AM com.sun.enterprise.v3.admin.adapter.AdminConsoleAdapter setContextRoot
    INFO: Admin Console Adapter: context root: /admin
    Jul 21, 2008 8:32:05 AM com.sun.grizzly.jruby.RailsAdapter startRubyRuntimePool
    INFO: Starting Rails instances
    Jul 21, 2008 8:32:09 AM 
    SEVERE: JRuby limited openssl loaded. gem install jruby-openssl for full support.
    http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
    Jul 21, 2008 8:32:10 AM com.sun.grizzly.jruby.RubyObjectPool$1 run
    INFO: JRuby and Rails instance instantiation took : 5623ms
    Jul 21, 2008 8:32:10 AM org.glassfish.scripting.rails.RailsDeployer load
    INFO: Loading application helloworld at /
    Jul 21, 2008 8:32:10 AM com.sun.enterprise.v3.server.AppServerStartup run
    INFO: Glassfish v3 started in 7046 ms
  5. Create a scaffold as:

  6. ~/testbed/jruby-1.1.3/samples/rails/helloworld >../../../bin/jruby script/generate scaffold runner distance:float minutes:integer
    JRuby limited openssl loaded. gem install jruby-openssl for full support.
    http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
          exists  app/models/
          exists  app/controllers/
          exists  app/helpers/
          create  app/views/runners
          exists  app/views/layouts/
          exists  test/functional/
          exists  test/unit/
          exists  public/stylesheets/
          create  app/views/runners/index.html.erb
          create  app/views/runners/show.html.erb
          create  app/views/runners/new.html.erb
          create  app/views/runners/edit.html.erb
          create  app/views/layouts/runners.html.erb
          create  public/stylesheets/scaffold.css
          create  app/controllers/runners_controller.rb
          create  test/functional/runners_controller_test.rb
          create  app/helpers/runners_helper.rb
           route  map.resources :runners
      dependency  model
          exists    app/models/
          exists    test/unit/
          exists    test/fixtures/
          create    app/models/runner.rb
          create    test/unit/runner_test.rb
          create    test/fixtures/runners.yml
          create    db/migrate
          create    db/migrate/20080721153737_create_runners.rb
  7. Start MySQL database, create and migrate the database:

    ~/testbed/jruby-1.1.3/samples/rails/helloworld >../../../bin/jruby -S rake db:create
    (in /Users/arungupta/testbed/jruby-1.1.3/samples/rails/helloworld)
    ~/testbed/jruby-1.1.3/samples/rails/helloworld >../../../bin/jruby -S rake db:migrate
    (in /Users/arungupta/testbed/jruby-1.1.3/samples/rails/helloworld)
    == 20080721154435 CreateRunners: migrating ====================================
    -- create_table(:runners)
       -> 0.0097s
    == 20080721154435 CreateRunners: migrated (0.0104s) ===========================

    Now "http://localhost:3000/runners" page is shown as:



    After adding couple of entries, the page looks like:



    Now, let's try to run the same application on GlassFish v3 stand-alone build.

    TOTD #33 explains how to build GlassFish v3 workspace. Alternatively nightly or promoted builds can be downloaded as well.

  8. Start the v3 server as:

    ~/testbed/glassfish/v3/snapshot/glassfish >java -DJRUBY_HOME=/Users/arungupta/testbed/jruby-1.1.3 -jar modules/glassfish-10.0-SNAPSHOT.jar
    Jul 21, 2008 9:40:41 AM com.sun.enterprise.glassfish.bootstrap.ASMain main
    INFO: Launching GlassFish on Apache Felix OSGi platform
    Jul 21, 2008 9:40:41 AM com.sun.enterprise.glassfish.bootstrap.ASMainOSGi getSharedRepos
    INFO: /Users/arungupta/testbed/glassfish/v3/snapshot/glassfish/domains/domain1/lib does not exist

    Welcome to Felix.
    =================

    . . .

    INFO: Started bundle org.glassfish.common.container-common [91]
    Jul 21, 2008 9:47:13 AM com.sun.enterprise.v3.admin.adapter.AdminConsoleAdapter setContextRoot
    INFO: Admin Console Adapter: context root: /admin
    Jul 21, 2008 9:47:13 AM OSGiModuleImpl loadClass
    INFO: Started bundle org.glassfish.deployment.deployment-common [71]
    Jul 21, 2008 9:47:13 AM com.sun.enterprise.v3.server.AppServerStartup run
    INFO: Glassfish v3 started in 1507 ms
  9. Deploy the application as:

    ~/testbed/jruby-1.1.3/samples/rails >~/testbed/glassfish/v3/snapshot/glassfish/bin/asadmin deploy helloworld

    Command deploy executed successfully.

    and the GlassFish console shows the following output:

    Jul 21, 2008 9:47:49 AM OSGiModuleImpl loadClass
    INFO: Started bundle org.glassfish.web.war-util [65]
    Jul 21, 2008 9:47:49 AM OSGiModuleImpl loadClass
    INFO: Started bundle org.glassfish.persistence.jpa-connector [25]
    Jul 21, 2008 9:47:49 AM OSGiModuleImpl loadClass
    INFO: Started bundle org.glassfish.scripting.gf-jruby-connector [13]
    Jul 21, 2008 9:47:49 AM OSGiModuleImpl loadClass
    INFO: Started bundle org.glassfish.core.security [22]
    Jul 21, 2008 9:47:49 AM OSGiModuleImpl loadClass
    INFO: Started bundle org.glassfish.web.gf-web-connector [86]
    Jul 21, 2008 9:47:49 AM OSGiModuleImpl loadClass
    INFO: Started bundle org.glassfish.connectors.gf-connectors-connector [53]
    Jul 21, 2008 9:47:49 AM com.sun.grizzly.jruby.RailsAdapter startRubyRuntimePool
    INFO: Starting Rails instances
    Jul 21, 2008 9:48:01 AM 
    SEVERE: JRuby limited openssl loaded. gem install jruby-openssl for full support.
    http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
    Jul 21, 2008 9:48:02 AM com.sun.grizzly.jruby.RubyObjectPool$1 run
    INFO: JRuby and Rails instance instantiation took : 12852ms
    Jul 21, 2008 9:48:02 AM org.glassfish.scripting.rails.RailsDeployer load
    INFO: Loading application helloworld at /helloworld
    Jul 21, 2008 9:48:02 AM com.sun.enterprise.v3.deployment.DeployCommand execute
    INFO: Deployment of helloworld done is 13326 ms

  10. The deployed application at "http://localhost:8080/helloworld/runners" looks like:



Rails powered by the GlassFish Application Server explain in detail about the several benefits of using GlassFish for Rails development and deployment. Rails/GlassFish Deployment Stories gives a good idea of how to structure your own application.

Are you using GlassFish for development or deployment of Rails ? Drop a comment on this blog.

Technorati: rubyonrails jruby ruby glassfish v3 gem

Friday Jul 11, 2008

Single Sign On using Sun Access Manager and JRuby

A couple of emails to achieve Single Sign On using Sun Access Manager in a Rails app - that's pretty cool! A brief summary of the solution is:

Warbler builds a war file out of your Rails app using jruby-rack. Drop your .jar libraries in the rails lib dir. Muck with your web.xml so you can make it use a filter. Drop the .war file on your server. Done. A little method called servlet_request is now magically available to you. Call servlet_request.getUserPrincipal : it's populated. It's not magic- it's JRuby!

Read complete details here. And guess what, this is deployed on GlassFish :)

The blog summarizes the power of Java and agility of JRuby/Rails:

Anyway, that's why JRuby is even more awesome. Let them write Java- I'll call it if I need it.

Technorati: rubyonrails jruby ruby glassfish accessmanager singlesignon sso stories

Monday Jul 07, 2008

GlassFish + JRuby + JRuby-Rack + Warbler = Blog Deployment Platform

Nick decided to walk the talk and upgraded his blog deployment platform from Mongrel to JRuby/GlassFish.

Read more details.

Yet another successful deployment of JRuby-on-Rails on GlassFish. Read other similar stories.

Technorati: rubyonrails jruby ruby glassfish stories

Tuesday Jul 01, 2008

TOTD #37: SQLite3 with Ruby-on-Rails on GlassFish Gem


The default database for Rails 2.0.x application is SQLite3. This database is bundled with Mac OSX Leopard and so makes it really easy to get started with Ruby-on-Rails. But it requires couple of additional steps if you are using JRuby.


TOTD #28 explains how to create a simple CRUD application using Rails 2.0.x. It uses MySQL database which is strongly recommended for deployment. This TOTD (Tip Of The Day) provides complete steps to run a Ruby-on-Rails application using JRuby and GlassFish Gem with the default database, i.e. SQLite3.
  1. Create a Rails application as:

    ~/samples/jruby >~/testbed/jruby-1.1.2/bin/jruby -S rails runner
          create 
          create  app/controllers
          create  app/helpers
          create  app/models
          create  app/views/layouts
    . . .
          create  log/server.log
          create  log/production.log
          create  log/development.log
          create  log/test.log

    The generated "database.yml" looks like:

    # SQLite version 3.x
    #   gem install sqlite3-ruby (not necessary on OS X Leopard)
    development:
      adapter: sqlite3
      database: db/development.sqlite3
      timeout: 5000

    # Warning: The database defined as "test" will be erased and
    # re-generated from your development database when you run "rake".
    # Do not set this db to the same as development or production.
    test:
      adapter: sqlite3
      database: db/test.sqlite3
      timeout: 5000

    production:
      adapter: sqlite3
      database: db/production.sqlite3
      timeout: 5000
  2. SQLite3 adapter is installed for the native Ruby bundled with Leopard. But in order to use SQLite3 with JRuby, you need to install SQLite3 JDBC adapter as shown below:

    ~/samples/jruby/runner >~/testbed/jruby-1.1.2/bin/jruby -S gem install activerecord-jdbcsqlite3-adapter
    JRuby limited openssl loaded. gem install jruby-openssl for full support.
    http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
    Successfully installed activerecord-jdbc-adapter-0.8.2
    Successfully installed jdbc-sqlite3-3.5.8
    Successfully installed activerecord-jdbcsqlite3-adapter-0.8.2
    3 gems installed
    Installing ri documentation for activerecord-jdbc-adapter-0.8.2...
    Installing ri documentation for jdbc-sqlite3-3.5.8...
    Installing ri documentation for activerecord-jdbcsqlite3-adapter-0.8.2...
    Installing RDoc documentation for activerecord-jdbc-adapter-0.8.2...
    Installing RDoc documentation for jdbc-sqlite3-3.5.8...
    Installing RDoc documentation for activerecord-jdbcsqlite3-adapter-0.8.2...
  3. Create a new file as "db/development.sqlite3". It can be easily created using the "touch" command. See the beauty of SQLite that "db:create" is not required :)
  4. Update the development section of "database.yml" such that it looks like:

    development:
      adapter: jdbcsqlite3
      database: db/development.sqlite3
      timeout: 5000
  5. Create a simple scaffold as shown below:

    ~/samples/jruby/runner >~/testbed/jruby-1.1.2/bin/jruby script/generate scaffold run distance:float minutes:integer
    JRuby limited openssl loaded. gem install jruby-openssl for full support.
    http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
          exists  app/models/
          exists  app/controllers/
          exists  app/helpers/
          create  app/views/runs
          exists  app/views/layouts/
          exists  test/functional/
          exists  test/unit/
          exists  public/stylesheets/
          create  app/views/runs/index.html.erb
          create  app/views/runs/show.html.erb
          create  app/views/runs/new.html.erb
          create  app/views/runs/edit.html.erb
          create  app/views/layouts/runs.html.erb
          create  public/stylesheets/scaffold.css
          create  app/controllers/runs_controller.rb
          create  test/functional/runs_controller_test.rb
          create  app/helpers/runs_helper.rb
           route  map.resources :runs
      dependency  model
          exists    app/models/
          exists    test/unit/
          exists    test/fixtures/
          create    app/models/run.rb
          create    test/unit/run_test.rb
          create    test/fixtures/runs.yml
          create    db/migrate
          create    db/migrate/20080630211244_create_runs.rb

    and run the migration as

    ~/samples/jruby/runner >~/testbed/jruby-1.1.2/bin/jruby -S rake db:migrate
    (in /Users/arungupta/samples/jruby/runner)
    == 20080630205502 CreateRuns: migrating =======================================
    -- create_table(:runs)
       -> 0.0410s
       -> 0 rows
    == 20080630205502 CreateRuns: migrated (0.0420s) ==============================
  6. A Rails application is deployed on GlassFish from it's parent directory. Therefore the application needs to be updated so taht exact location of database is specified. Basically you need to edit "database.yml" and the updated "development" fragment looks like:

    development:
      adapter: jdbcsqlite3
      database: runner/db/development.sqlite3
      timeout: 5000
  7. Run the application on GlassFish v3 gem as:

    ~/samples/jruby >~/testbed/jruby-1.1.2/bin/jruby -S glassfish_rails runner
    Jun 30, 2008 1:52:08 PM com.sun.enterprise.glassfish.bootstrap.ASMain main
    INFO: Launching GlassFish on HK2 platform
    Jun 30, 2008 1:52:08 PM com.sun.enterprise.glassfish.bootstrap.ASMainHK2 findDerbyClient
    INFO: Cannot find javadb client jar file, jdbc driver not available
    Jun 30, 2008 1:52:09 PM com.sun.enterprise.v3.services.impl.GrizzlyProxy start
    INFO: Listening on port 3000
    Jun 30, 2008 1:52:09 PM com.sun.enterprise.v3.services.impl.GrizzlyEmbeddedHttpConfigurator configureSSL
    WARNING: pewebcontainer.all_ssl_protocols_disabled
    Jun 30, 2008 1:52:09 PM com.sun.enterprise.v3.services.impl.GrizzlyEmbeddedHttpConfigurator configureSSL
    WARNING: pewebcontainer.all_ssl_ciphers_disabled
    Jun 30, 2008 1:52:09 PM com.sun.enterprise.v3.services.impl.GrizzlyProxy start
    INFO: Listening on port 3131
    Jun 30, 2008 1:52:09 PM com.sun.enterprise.v3.services.impl.GrizzlyProxy start
    INFO: Listening on port 3838
    Jun 30, 2008 1:52:09 PM com.sun.enterprise.v3.admin.adapter.AdminConsoleAdapter setContextRoot
    INFO: Admin Console Adapter: context root: /admin
    Jun 30, 2008 1:52:09 PM com.sun.grizzly.jruby.RailsAdapter startRubyRuntimePool
    INFO: Starting Rails instances
    Jun 30, 2008 1:52:16 PM  
    SEVERE: JRuby limited openssl loaded. gem install jruby-openssl for full support.
    http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
    Jun 30, 2008 1:52:17 PM com.sun.grizzly.jruby.RubyObjectPool$1 run
    INFO: JRuby and Rails instance instantiation took : 7998ms
    Jun 30, 2008 1:52:17 PM org.glassfish.scripting.rails.RailsDeployer load
    INFO: Loading application runner at /
    Jun 30, 2008 1:52:17 PM com.sun.enterprise.v3.server.AppServerStartup run
    INFO: Glassfish v3 started in 9430 ms

After adding couple of entries, "http://localhost:3000/runs" looks like:



So now you can use SQLite3 as your development database for Rails applications running on GlassFish v3 Gem.

Here are some useful pointers:

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


Technorati: totd rubyonrails jruby ruby sqlite sqlite3 glassfish v3 gem

Monday Jun 30, 2008

TOTD# 36: Writing First Test for a Rails Application

I've created a Rails "Hello World" app numerous times. But I decided to write a simple using the testing framework provided by Rails. This blog explains my experience of writing such a test.
  1. Create a "Hello World" app as:

    ~/samples/jruby/test >~/testbed/jruby-1.1.2/bin/jruby -S rails helloworld        
          create 
          create  app/controllers
          create  app/helpers
          create  app/models
          create  app/views/layouts
          create  config/environments
          create  config/initializers

    . . .

          create  log/production.log
          create  log/development.log
          create  log/test.log

    There is no "-d mysql" in the command because I don't expect this application to do any database access. The database access is disabled by following TOTD #26.
  2. I tried generating a new controller using the command:

    ~/samples/jruby/test/helloworld >~/testbed/jruby-1.1.2/bin/jruby script/generate controller home index

    and got the error:

    JRuby limited openssl loaded. gem install jruby-openssl for full support.
    http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
    /Users/arungupta/testbed/jruby-1.1.2/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:278:in `load_missing_constant': uninitialized constant ActiveRecord (NameError)
            from /Users/arungupta/testbed/jruby-1.1.2/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:467:in `const_missing'
            from /Users/arungupta/testbed/jruby-1.1.2/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:479:in `const_missing'
            from /Users/arungupta/samples/jruby/test/helloworld/config/initializers/new_rails_defaults.rb:5:in `/Users/arungupta/samples/jruby/test/helloworld/config/initializers/new_rails_defaults.rb'
            from /Users/arungupta/samples/jruby/test/helloworld/config/initializers/new_rails_defaults.rb:502:in `load'
            from /Users/arungupta/testbed/jruby-1.1.2/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:502:in `load'
            from /Users/arungupta/testbed/jruby-1.1.2/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:354:in `new_constants_in'
            from /Users/arungupta/testbed/jruby-1.1.2/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:502:in `load'
            from /Users/arungupta/testbed/jruby-1.1.2/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/initializer.rb:475:in `load_application_initializers'
             ... 8 levels...
            from /Users/arungupta/testbed/jruby-1.1.2/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/commands/generate.rb:27:in `require'
            from /Users/arungupta/testbed/jruby-1.1.2/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'
            from script/generate:3

    So even though database access has been explicitly disabled, there are still references to ActiveRecord. So I had to explicitly disable them by changing the code in "config/initializers/new_rails_defaults.rb" as:

    if defined?(ActiveRecord)
    # Include Active Record class name as root for JSON serialized output.
    ActiveRecord::Base.include_root_in_json = true

    # Store the full class name (including module namespace) in STI type column.
    ActiveRecord::Base.store_full_sti_class = true
    end

    and then the controller is easily generated as:

    ~/samples/jruby/test/helloworld >~/testbed/jruby-1.1.2/bin/jruby script/generate controller home index
    JRuby limited openssl loaded. gem install jruby-openssl for full support.
    http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
          exists  app/controllers/
          exists  app/helpers/
          create  app/views/home
          exists  test/functional/
          create  app/controllers/home_controller.rb
          create  test/functional/home_controller_test.rb
          create  app/helpers/home_helper.rb
          create  app/views/home/index.html.erb
  3. Run your application using GlassFish v3 gem as:

    ~/workspaces/glassfish-scripting/rails/v3/src/test/rails >~/testbed/jruby-1.1.2/bin/jruby -S glassfish_rails helloworld
    Jun 27, 2008 2:46:18 PM com.sun.enterprise.glassfish.bootstrap.ASMain main
    INFO: Launching GlassFish on HK2 platform
    Jun 27, 2008 2:46:18 PM com.sun.enterprise.glassfish.bootstrap.ASMainHK2 findDerbyClient
    INFO: Cannot find javadb client jar file, jdbc driver not available
    Jun 27, 2008 2:46:18 PM com.sun.enterprise.v3.services.impl.GrizzlyProxy start
    INFO: Listening on port 3000
    Jun 27, 2008 2:46:18 PM com.sun.enterprise.v3.services.impl.GrizzlyEmbeddedHttpConfigurator configureSSL
    WARNING: pewebcontainer.all_ssl_protocols_disabled
    Jun 27, 2008 2:46:18 PM com.sun.enterprise.v3.services.impl.GrizzlyEmbeddedHttpConfigurator configureSSL
    WARNING: pewebcontainer.all_ssl_ciphers_disabled
    Jun 27, 2008 2:46:19 PM com.sun.enterprise.v3.services.impl.GrizzlyProxy start
    INFO: Listening on port 3131
    Jun 27, 2008 2:46:19 PM com.sun.enterprise.v3.services.impl.GrizzlyProxy start
    INFO: Listening on port 3838
    Jun 27, 2008 2:46:19 PM com.sun.enterprise.v3.admin.adapter.AdminConsoleAdapter setContextRoot
    INFO: Admin Console Adapter: context root: /admin
    Jun 27, 2008 2:46:19 PM com.sun.grizzly.jruby.RailsAdapter startRubyRuntimePool
    INFO: Starting Rails instances
    Jun 27, 2008 2:46:24 PM  
    SEVERE: JRuby limited openssl loaded. gem install jruby-openssl for full support.
    http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
    Jun 27, 2008 2:46:24 PM com.sun.grizzly.jruby.RubyObjectPool$1 run
    INFO: JRuby and Rails instance instantiation took : 5169ms
    Jun 27, 2008 2:46:24 PM org.glassfish.scripting.rails.RailsDeployer load
    INFO: Loading application helloworld at /
    Jun 27, 2008 2:46:24 PM com.sun.enterprise.v3.server.AppServerStartup run
    INFO: Glassfish v3 started in 6419 ms
    Jun 27, 2008 2:46:28 PM com.sun.grizzly.jruby.RailsAdapter$Logger log
    INFO: 
  4. Chapter 9 in Rails Manual explains how to test controllers. Modify "test/functional/home_controller_test.rb" as:

    require 'home_controller'

    class HomeControllerTest < ActionController::TestCase
      def test_index
        get :index
        assert_response :success
      end

    end
  5. Run the test as:

    ~/workspaces/glassfish-scripting/rails/v3/src/test/rails/helloworld >~/testbed/jruby-1.1.2/bin/jruby -S rake test
    (in /Users/arungupta/workspaces/glassfish-scripting/rails/v3/src/test/rails/helloworld)
    /Users/arungupta/testbed/jruby-1.1.2/bin/jruby -Ilib:test "/Users/arungupta/testbed/jruby-1.1.2/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake/rake_test_loader.rb"  
    /Users/arungupta/testbed/jruby-1.1.2/bin/jruby -Ilib:test "/Users/arungupta/testbed/jruby-1.1.2/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake/rake_test_loader.rb" "test/functional/home_controller_test.rb"
    JRuby limited openssl loaded. gem install jruby-openssl for full support.
    http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
    Loaded suite /Users/arungupta/testbed/jruby-1.1.2/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake/rake_test_loader
    Started
    .
    Finished in 0.308 seconds.

    1 tests, 1 assertions, 0 failures, 0 errors
    /Users/arungupta/testbed/jruby-1.1.2/bin/jruby -Ilib:test "/Users/arungupta/testbed/jruby-1.1.2/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake/rake_test_loader.rb"

If you indeed are using database (which is the most common case anyway) then you can load data using Fixtures and then Test your Models.

Keep adding controller and models and testing them!

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

Technorati: rubyonrails jruby ruby glassfish totd

Tuesday Jun 24, 2008

Rails GlassFish Gem 0.3.1 now available

Vivek released 0.3.0 version of GlassFish Gem for Rails (a total of 11 issues fixed and resolved - RubyForge & GlassFish Issue Tracker) earlier. But that caused a regression on #4228. And so matching the agility expected by Rails developers, he quickly released 0.3.1. And a wee bit smaller too - 2.68MB for 0.3.1 instead of 2.69MB for 0.3.0.

If you have an existing version of the gem, then you just need to update it:

~/testbed/jruby-1.1 >bin/jruby -S gem update glassfish -r
JRuby limited openssl loaded. gem install jruby-openssl for full support.
http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
Updating installed gems...
Bulk updating Gem source index for: http://gems.rubyforge.org
Attempting remote update of glassfish
Successfully installed glassfish-0.3.1-universal-java
1 gem installed
Gems updated: glassfish

If the gem has never been installed, then you install it as:

~/testbed/jruby-1.1.2 >bin/jruby -S gem install glassfish
JRuby limited openssl loaded. gem install jruby-openssl for full support.
http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
Successfully installed glassfish-0.3.1-universal-java
1 gem installed

And make sure next time you have to update the gem instead of installing from scratch ;) For that, just install the gem this time and let us know your feedback on GlassFish Webtier Forum or Webtier Alias. If any of your Rails application do not work then please file bugs at GlassFish Issue Tracker ("V3" as "Found in Version:" and "jruby" as "Subcomponent:").

The gem installation may require to set "JAVA_MEM=-Xmx800m" because of the growing memory requirements. Otherwise you may get "Exception in thread "main" java.lang.OutOfMemoryError: Java heap space".

Try a simple scaffold application to see the output as shown below:


The startup output in the gem console (output from GlassFish) is:

~/testbed/jruby-1.1.2/samples/rails >../../bin/jruby -S glassfish_rails runner
Jun 24, 2008 11:04:51 PM com.sun.enterprise.glassfish.bootstrap.ASMain main
INFO: Launching GlassFish on HK2 platform
Jun 24, 2008 11:04:51 PM com.sun.enterprise.glassfish.bootstrap.ASMainHK2 findDerbyClient
INFO: Cannot find javadb client jar file, jdbc driver not available
Jun 24, 2008 11:04:52 PM com.sun.enterprise.v3.services.impl.GrizzlyProxy start
INFO: Listening on port 3000
Jun 24, 2008 11:04:52 PM com.sun.enterprise.v3.services.impl.GrizzlyEmbeddedHttpConfigurator configureSSL
WARNING: pewebcontainer.all_ssl_protocols_disabled
Jun 24, 2008 11:04:52 PM com.sun.enterprise.v3.services.impl.GrizzlyEmbeddedHttpConfigurator configureSSL
WARNING: pewebcontainer.all_ssl_ciphers_disabled
Jun 24, 2008 11:04:52 PM com.sun.enterprise.v3.services.impl.GrizzlyProxy start
INFO: Listening on port 3131
Jun 24, 2008 11:04:52 PM com.sun.enterprise.v3.services.impl.GrizzlyProxy start
INFO: Listening on port 3838
Jun 24, 2008 11:04:52 PM com.sun.enterprise.v3.admin.adapter.AdminConsoleAdapter setContextRoot
INFO: Admin Console Adapter: context root: /admin
Jun 24, 2008 11:04:52 PM com.sun.grizzly.jruby.RailsAdapter startRubyRuntimePool
INFO: Starting Rails instances
Jun 24, 2008 11:04:58 PM 
SEVERE: JRuby limited openssl loaded. gem install jruby-openssl for full support.
http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
Jun 24, 2008 11:04:59 PM com.sun.grizzly.jruby.RubyObjectPool$1 run
INFO: JRuby and Rails instance instantiation took : 6600ms
Jun 24, 2008 11:04:59 PM org.glassfish.scripting.rails.RailsDeployer load
INFO: Loading application runner at /
Jun 24, 2008 11:04:59 PM com.sun.enterprise.v3.server.AppServerStartup run
INFO: Glassfish v3 started in 7945 ms

and then the console is updated as more entries are added (output from Rails):

Jun 24, 2008 11:05:25 PM com.sun.grizzly.jruby.RailsAdapter$Logger log
INFO:

Processing DistancesController#index (for 0:0:0:0:0:0:0:1%0 at 2008-06-24 23:05:25) [GET]

Jun 24, 2008 11:05:25 PM com.sun.grizzly.jruby.RailsAdapter$Logger log
INFO:   Session ID: BAh7ByIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNo
SGFzaHsABjoKQHVzZWR7ADoMY3NyZl9pZCIlNTdhMGYxNjkxOTk5ZjI1ZjI4
OGZjODZjZjcxN2QyNzQ=--cbf4578767e5887d4b62bd249e7624dcb7d1cf90

Jun 24, 2008 11:05:25 PM com.sun.grizzly.jruby.RailsAdapter$Logger log
INFO:   Parameters: {"controller"=>"distances", "action"=>"index"}

Jun 24, 2008 11:05:25 PM com.sun.grizzly.jruby.RailsAdapter$Logger log
INFO: WARNING: You're using the Ruby-based MySQL library that ships with Rails. This library is not suited for production. Please install the C-based MySQL library instead (gem install mysql).

Jun 24, 2008 11:05:25 PM com.sun.grizzly.jruby.RailsAdapter$Logger log
INFO:   SQL (0.001000)   SET NAMES 'utf8'

Jun 24, 2008 11:05:25 PM com.sun.grizzly.jruby.RailsAdapter$Logger log
INFO:   SQL (0.001000)   SET SQL_AUTO_IS_NULL=0

Jun 24, 2008 11:05:25 PM com.sun.grizzly.jruby.RailsAdapter$Logger log
INFO:   Distance Load (0.003000)   SELECT \* FROM `distances`

Jun 24, 2008 11:05:25 PM com.sun.grizzly.jruby.RailsAdapter$Logger log
INFO: Rendering template within layouts/distances

. . .

Jun 24, 2008 11:05:48 PM com.sun.grizzly.jruby.RailsAdapter$Logger log
INFO:   Parameters: {"authenticity_token"=>"519436f2248515d901051acafe0726dfd88746f0", "distance"=>{"miles"=>"4", "run_at(1i)"=>"2008", "run_at(2i)"=>"6", "run_at(3i)"=>"24", "run_at(4i)"=>"07", "run_at(5i)"=>"00"}, "commit"=>"Create", "controller"=>"distances", "action"=>"create"}

Jun 24, 2008 11:05:48 PM com.sun.grizzly.jruby.RailsAdapter$Logger log
INFO:   Distance Columns (0.009000)   SHOW FIELDS FROM `distances`

Jun 24, 2008 11:05:48 PM com.sun.grizzly.jruby.RailsAdapter$Logger log
INFO:   SQL (0.000000)   BEGIN

Jun 24, 2008 11:05:48 PM com.sun.grizzly.jruby.RailsAdapter$Logger log
INFO:   Distance Create (0.000000)   INSERT INTO `distances` (`miles`, `run_at`, `created_at`, `updated_at`) VALUES(4.0, '2008-06-24 14:00:00', '2008-06-25 06:05:48', '2008-06-25 06:05:48')

Jun 24, 2008 11:05:48 PM com.sun.grizzly.jruby.RailsAdapter$Logger log
INFO:   SQL (0.002000)   COMMIT

. . .

Jun 24, 2008 11:06:09 PM com.sun.grizzly.jruby.RailsAdapter$Logger log
INFO:   Parameters: {"authenticity_token"=>"519436f2248515d901051acafe0726dfd88746f0", "distance"=>{"miles"=>"3.5", "run_at(1i)"=>"2008", "run_at(2i)"=>"6", "run_at(3i)"=>"23", "run_at(4i)"=>"06", "run_at(5i)"=>"55"}, "commit"=>"Create", "controller"=>"distances", "action"=>"create"}

Jun 24, 2008 11:06:09 PM com.sun.grizzly.jruby.RailsAdapter$Logger log
INFO:   Distance Columns (0.015000)   SHOW FIELDS FROM `distances`

Jun 24, 2008 11:06:09 PM com.sun.grizzly.jruby.RailsAdapter$Logger log
INFO:   SQL (0.000000)   BEGIN

Jun 24, 2008 11:06:09 PM com.sun.grizzly.jruby.RailsAdapter$Logger log
INFO:   Distance Create (0.000000)   INSERT INTO `distances` (`miles`, `run_at`, `created_at`, `updated_at`) VALUES(3.5, '2008-06-23 13:55:00', '2008-06-25 06:06:09', '2008-06-25 06:06:09')

Jun 24, 2008 11:06:09 PM com.sun.grizzly.jruby.RailsAdapter$Logger log
INFO:   SQL (0.001000)   COMMIT

Jun 24, 2008 11:06:09 PM com.sun.grizzly.jruby.RailsAdapter$Logger log
INFO: Redirected to http://localhost:3000/distances/5

. . .

Jun 24, 2008 11:06:10 PM com.sun.grizzly.jruby.RailsAdapter$Logger log
INFO:   Parameters: {"controller"=>"distances", "action"=>"index"}

Jun 24, 2008 11:06:10 PM com.sun.grizzly.jruby.RailsAdapter$Logger log
INFO:   Distance Load (0.003000)   SELECT \* FROM `distances`

Jun 24, 2008 11:06:10 PM com.sun.grizzly.jruby.RailsAdapter$Logger log
INFO: Rendering template within layouts/distances

Jun 24, 2008 11:06:10 PM com.sun.grizzly.jruby.RailsAdapter$Logger log
INFO: Rendering distances/index

Jun 24, 2008 11:06:10 PM com.sun.grizzly.jruby.RailsAdapter$Logger log
INFO:   Distance Columns (0.008000)   SHOW FIELDS FROM `distances`

Jun 24, 2008 11:06:11 PM com.sun.grizzly.jruby.RailsAdapter$Logger log
INFO: Completed in 0.05900 (16 reqs/sec) | Rendering: 0.03200 (54%) | DB: 0.01100 (18%) | 200 OK [http://localhost/distances]

Redmine seems to have issues with Rails 2.1. I'll play with some other applications later. But have you tried deploying your Rails application on GlassFish gem ? As mentioned above, let us know your feedback on GlassFish Webtier Forum or Webtier Alias and file bugs on GlassFish Issue Tracker.

Details about previous versions are available at 0.2.0, 0.1.2, 0.1.1, 0.1.0.

Technorati: glassfish v3 rubyonrails jruby ruby gem

Monday Jun 23, 2008

JRuby-on-Rails and MySQL on GlassFish on OpenSolaris in Virtual Box VM


My primary development machine is Mac OS Leopard on Intel Core 2 Duo (read osxtips). But the beauty of virtualization is that I can run multiple Operating Systems on a single powerful machine. And what better virtualization product than Virtual Box. And  Open Solaris has crossed leaps and boundaries making installation and getting started extremely simple :)

So here is an application stack that I tried:


Rails 2.1 + My SQL 5.0.51a



JRuby 1.1.2



GlassFish v3 TP2


OpenSolaris 2008.05


Virtual Box 1.6.2



Mac OSX Leopard




Intel 2.4 G Hz Core 2 Duo

You can easily deploy your Rails applications using MySQL database on GlassFish installed on OpenSolaris in a Virtual Box VM on Mac OS Leopard running on an Intel 2 Duo processor machine. Overall a happy experience :)

The complete instructions to install OpenSolaris using Virtual Box are very useful.

Here are basic steps ...

Create a new VM (settings given in the instructions):



Once all the options are chosen, the generated VM settings are shown as below:



Booting the Virtual Machine from the Live CD shows the following GRUB:



Pick the default options (GRUB, Keyboard & Language) and then the following default screen is shown:



Read and Close the license screen. And then click on the "Install Open Solaris" icon to continue the installation process. This step is important otherwise you'll keep booting from LiveCD every time (I messed up on this few times ;).



After choosing the Region, Location & Timezone and taking other defaults, the summarized installation options are shown:



And finally the installation is complete:



After the installation is complete, shutdown the VM by either selecting "System, Shut Down..." or click on the X on the VM window and selecting "Power off the machine". Change the boot sequence order to bring "Hard Disk" at the top by clicking on "Settings", "Advanced" tab and changing the order as shown below.



And finally, you can easily deploy a Rails 2.1 application on this newly configured machine as explained in Rails 2.1 on GlassFish.  TOTD #35 explains how Rails Database connection need to be configured on Solaris.
The final output of the application looks like:




Here are some pointers for you to get started:
Did you know the 3 keywords for GlassFish v3 - Modularity (OSGi compliant), Extensiblity (non-Java apps) & Emebeddability (runs in-VM) ? Read more on GlassFish v3 main page.

Stay in touch with us by posting your questions/comments/concerns to GlassFish Web Tier Forum or webtier@glassfish.

Technorati: rubyonrails jruby ruby opensolaris virtualbox mac glassfish v3

Sunday Jun 22, 2008

TOTD #35: Rails Database Connection on Solaris

Are you deploying your JRuby-on-Rails applications on Solaris (or any variety of Unix) and not able to connect to the database ?

I experienced it last week so thought of sharing the tip here. Luckily it's really simple.

Here is the default generated "config/database.yml"

development:
  adapter: mysql
  encoding: utf8
  database: runner_development
  username: root
  password:
  socket: /tmp/mysql.sock

The only required change is to add "host: 127.0.01" for the required database configuration. The updated fragment is shown below (with change highlighted):

development:
  adapter: mysql
  encoding: utf8
  database: runner_development
  username: root
  password:
  socket: /tmp/mysql.sock
  host: 127.0.01

Even though "host" is required for TCP connections but the database connection does not seem to work without this entry. The exact same application works without "host" entry on Windows and Mac OS.

Alternatively, you can always install the JDBC adapter as explained here.

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

Technorati: totd rubyonrails jruby ruby opensolaris mysql
About

profile image
Arun Gupta is a technology enthusiast, a passionate runner, author, and a community guy who works for Oracle Corp.


Java EE 7 Samples

Stay Connected

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today