Wednesday August 12, 2009
TOTD #92: Session Failover for Rails applications running on GlassFish
The GlassFish
High Availability
allows to setup a cluster of GlassFish instances and achieve highly
scalable architecture using in-memory session state replication. This
cluster can be very
easily created and tested using the "clusterjsp" sample
bundled with GlassFish. Here are some clustering related entries
published on this blog so far:
| ~/samples/jruby/session >~/tools/jruby/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 test/unit/helpers/ create app/controllers/home_controller.rb create test/functional/home_controller_test.rb create app/helpers/home_helper.rb create test/unit/helpers/home_helper_test.rb create app/views/home/index.html.erb |
| class HomeController < ApplicationController include Java def index @server_served = servlet_request.get_server_name @port = servlet_request.get_server_port @instance = java.lang.System.get_property "com.sun.aas.instanceName" @server_executed = java.net.InetAddress.get_local_host().get_host_name() @ip = java.net.InetAddress.get_local_host().get_host_address @session_id = servlet_request.session.get_id @session_created = servlet_request.session.get_creation_time @session_last_accessed = servlet_request.session.get_last_accessed_time @session_inactive = servlet_request.session.get_max_inactive_interval if (params[:name] != nil) servlet_request.session[params[:name]] = params[:value] end @session_values = "" value_names = servlet_request.session.get_attribute_names unless (value_names.has_more_elements) @session_values = "<br>No parameter entered for this request" else @session_values << "<UL>" while (value_names.has_more_elements) param = value_names.next_element unless (param.starts_with?("__")) value = servlet_request.session.get_attribute(param) @session_values << "<LI>" + param + " = " + value + "</LI>" end end @session_values << "</UL>" end end def adddata servlet_request.session.set_attribute(params[:name], params[:value]) render :action => "index" end def cleardata servlet_request.session.invalidate render :action => "index" end end |
| <h1>Home#index</h1> <p>Find me in app/views/home/index.html.erb</p> <B>HttpSession Information:</B> <UL> <LI>Served From Server: <b><%= @server_served %></b></LI> <LI>Server Port Number: <b><%= @port %></b></LI> <LI>Executed From Server: <b><%= @server_executed %></b></LI> <LI>Served From Server instance: <b><%= @instance %></b></LI> <LI>Executed Server IP Address: <b><%= @ip %></b></LI> <LI>Session ID: <b><%= @session_id %></b></LI> <LI>Session Created: <%= @session_created %></LI> <LI>Last Accessed: <%= @session_last_accessed %></LI> <LI>Session will go inactive in <b><%= @session_inactive %> seconds</b></LI> </UL> <BR> <% form_tag "/session/home/index" do %> <label for="name">Name of Session Attribute:</label> <%= text_field_tag :name, params[:name] %><br> <label for="value">Value of Session Attribute:</label> <%= text_field_tag :value, params[:value] %><br> <%= submit_tag "Add Session Data" %> <% end %> <% form_tag "/session/home/cleardata" do %> <%= submit_tag "Clear Session Data" %> <% end %> <% form_tag "/session/home/index" do %> <%= submit_tag "Reload Page" %> <% end %> <BR> <B>Data retrieved from the HttpSession: </B> <%= @session_values %> |
| ~/samples/jruby/session >~/tools/jruby/bin/jruby -S warble
war:webxml mkdir -p tmp/war/WEB-INF ~/samples/jruby/session >cp tmp/war/WEB-INF/web.xml config/ |
| <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> <web-app> |
| <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> |
| <distributable/> |
| ~/samples/jruby/session >~/tools/jruby/bin/jruby -S warble mkdir -p tmp/war/WEB-INF/gems/specifications cp /Users/arungupta/tools/jruby-1.3.0/lib/ruby/gems/1.8/specifications/rails-2.3.2.gemspec tmp/war/WEB-INF/gems/specifications/rails-2.3.2.gemspec . . . mkdir -p tmp/war/WEB-INF cp config/web.xml tmp/war/WEB-INF jar cf session.war -C tmp/war . |
| ~/samples/jruby/session >asadmin deploy --target wines --port 5048 --availabilityenabled=true session.war |








Posted by Arun Gupta in General | Comments[2]
|
|
|
|
|
Tuesday June 16, 2009
TOTD #84: Using Apache + mod_proxy_balancer to load balance Ruby-on-Rails running on GlassFish
TOTD
#81 explained how to install/configure nginx for
load-balancing/front-ending a cluster of Rails application running on GlassFish
Gem. Another popular approach in the Rails community is to
use Apache HTTPD
+ mod_proxy_balancer.
A user asked the exact details of this
setup on the GlassFish
Gem Forum. This Tip
Of The Day (TOTD) will
clearly explain the steps.
| LoadModule proxy_balancer_module libexec/apache2/mod_proxy_balancer.so |
| <Proxy balancer://glassfishgem> BalancerMember http://localhost:3000 BalancerMember http://localhost:3001 BalancerMember http://localhost:3002 </Proxy> |
| ProxyPass / balancer://glassfishgem/ CustomLog /var/log/glassfishgem.log/apache_access_log combined |
| CustomLog /var/log/glassfishgem.log/apache_access_log combined |
| ~/tools/jruby/rails/runner >../../bin/jruby -S glassfish -e
production -c myapp Starting GlassFish server at: 10.0.177.178:3000 in production environment... Writing log messages to: /Users/arungupta/tools/jruby-1.3.0/rails/runner/log/production.log. Press Ctrl+C to stop. . . . ~/tools/jruby/rails/runner >../../bin/jruby -S glassfish -e production -c myapp -p 3001 Starting GlassFish server at: 10.0.177.178:3001 in production environment... Writing log messages to: /Users/arungupta/tools/jruby-1.3.0/rails/runner/log/production.log. Press Ctrl+C to stop. . . . ~/tools/jruby/rails/runner >../../bin/jruby -S glassfish -e production -c myapp -p 3002 Starting GlassFish server at: 10.0.177.178:3002 in production environment... Writing log messages to: /Users/arungupta/tools/jruby-1.3.0/rails/runner/log/production.log. Press Ctrl+C to stop. |
| ProxyPass /myapp/
balancer://glassfishgem/myapp/ |
| LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\" \"%{BALANCER_WORKER_NAME}e\"" custom |
| CustomLog /var/log/glassfishgem.com/apache_access_log custom |
| ::1 - - [17/Jun/2009:10:53:53 -0700] "GET /runlogs
HTTP/1.1" 304 - "-" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5;
en-US; rv:1.9.0.11) Gecko/2009060214 Firefox/3.0.11"
"http://localhost:3002" ::1 - - [17/Jun/2009:10:54:04 -0700] "GET /runlogs HTTP/1.1" 200 621 "-" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.0.11) Gecko/2009060214 Firefox/3.0.11" "http://localhost:3000" ::1 - - [17/Jun/2009:10:54:05 -0700] "GET /runlogs HTTP/1.1" 304 - "-" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.0.11) Gecko/2009060214 Firefox/3.0.11" "http://localhost:3001" |
Posted by Arun Gupta in web2.0 | Comments[4]
|
|
|
|
|
Thursday April 30, 2009
TOTD #81: How to use nginx to load balance a cluster of GlassFish Gem ?
![]() |
nginx (pronounced as "engine-ex") is an open-source and high-performance HTTP server. It provides the common features such as reverse proxying with caching, load balancing, modular architecture using filters (gzipping, chunked responses, etc), virtual servers, flexible configuration and much more. |
| ~/tools
> curl -L -O http://sysoev.ru/nginx/nginx-0.6.36.tar.gz ~/tools > tar -xzf nginx-0.6.36.tar.gz ~/tools > curl -L -O http://downloads.sourceforge.net/pcre/pcre-7.7.tar.gz ~/tools > tar -xzf pcre-7.7.tar.gz ~/tools/nginx-0.6.36 > ./configure --prefix=/usr/local/nginx --sbin-path=/usr/sbin --with-debug --with-http_ssl_module --with-pcre=../pcre-7.7 ~/tools/nginx-0.6.36 > make ~/tools/nginx-0.6.36 > sudo make install ~/tools/nginx-0.6.36 > which nginx /usr/sbin/nginx |

| ~/samples/jruby >~/tools/jruby/bin/jruby -S rails
runner ~/samples/jruby/runner >~/tools/jruby/bin/jruby script/generate scaffold runlog miles:float minutes:integer ~/samples/jruby/runner >sed s/'adapter: sqlite3'/'adapter: jdbcsqlite3'/ <config/database.yml >config/database.yml.new ~/samples/jruby/runner >mv config/database.yml.new config/database.yml ~/samples/jruby/runner >~/tools/jruby/bin/jruby -S rake db:migrate |
| ~/samples/jruby/runner >~/tools/jruby/bin/jruby -S
glassfish Starting GlassFish server at: 192.168.1.145:3000 in development environment... Writing log messages to: /Users/arungupta/samples/jruby/runner/log/development.log. Press Ctrl+C to stop. |
| ~/samples/jruby/runner >~/tools/jruby/bin/jruby -S
glassfish -p 3001 Starting GlassFish server at: 192.168.1.145:3001 in development environment... Writing log messages to: /Users/arungupta/samples/jruby/runner/log/development.log. Press Ctrl+C to stop. |
| ~/samples/jruby/runner >~/tools/jruby/bin/jruby -S
glassfish -p 3002 Starting GlassFish server at: 192.168.1.145:3002 in development environment... Writing log messages to: /Users/arungupta/samples/jruby/runner/log/development.log. Press Ctrl+C to stop. |
| upstream
glassfish { server 127.0.0.1:3000; server 127.0.0.1:3001; server 127.0.0.1:3002; } |

| proxy_pass http://glassfish; |

| sudo
kill -15 `cat /usr/local/nginx/logs/nginx.pid` sudo nginx |

| log_format
main '$remote_addr - [$upstream_addr]
$remote_user [$time_local] $request ' '"$status" $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log logs/access.log main; |
| 127.0.0.1 - [127.0.0.1:3000]
- [29/Apr/2009:15:27:57 -0700] GET
/runlogs/ HTTP/1.1 "200" 3689 "-" "Mozilla/5.0 (Macintosh;
U; Intel Mac OS X 10_5_6; en-us) AppleWebKit/525.27.1 (KHTML, like
Gecko) Version/3.2.1 Safari/525.27.1" "-" 127.0.0.1 - [127.0.0.1:3001] - [29/Apr/2009:15:27:57 -0700] GET /favicon.ico HTTP/1.1 "200" 0 "http://localhost/runlogs/" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_6; en-us) AppleWebKit/525.27.1 (KHTML, like Gecko) Version/3.2.1 Safari/525.27.1" "-" 127.0.0.1 - [127.0.0.1:3002] - [29/Apr/2009:15:27:57 -0700] GET /stylesheets/scaffold.css?1240977992 HTTP/1.1 "200" 889 "http://localhost/runlogs/" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_6; en-us) AppleWebKit/525.27.1 (KHTML, like Gecko) Version/3.2.1 Safari/525.27.1" "-" |
| 127.0.0.1 - [127.0.0.1:3000]
- [29/Apr/2009:15:28:53 -0700] GET /runlogs/ HTTP/1.1 "200" 3689 "-"
"Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_6; en-us)
AppleWebKit/525.27.1 (KHTML, like Gecko) Version/3.2.1 Safari/525.27.1"
"-" 127.0.0.1 - [127.0.0.1:3002, 127.0.0.1:3000] - [29/Apr/2009:15:28:53 -0700] GET /favicon.ico HTTP/1.1 "200" 0 "http://localhost/runlogs/" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_6; en-us) AppleWebKit/525.27.1 (KHTML, like Gecko) Version/3.2.1 Safari/525.27.1" "-" 127.0.0.1 - [127.0.0.1:3001] - [29/Apr/2009:15:28:53 -0700] GET /stylesheets/scaffold.css?1240977992 HTTP/1.1 "200" 889 "http://localhost/runlogs/" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_6; en-us) AppleWebKit/525.27.1 (KHTML, like Gecko) Version/3.2.1 Safari/525.27.1" "-" |
Posted by Arun Gupta in web2.0 | Comments[8]
|
|
|
|
|
Friday March 20, 2009
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... |
| ~/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 |
| ~/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 |
| ~/tools/jruby-1.2.0 >./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 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... |
| ~/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 |
| development: adapter: sqlite3 database: db/development.sqlite3 pool: 5 timeout: 5000 |
| development: adapter: jdbcsqlite3 database: db/development.sqlite3 pool: 5 timeout: 5000 |
| ActionController::Base.session_store = :active_record_store |
| config.webxml.jruby.session_store = 'db' |
| 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 |
| 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 |
Posted by Arun Gupta in web2.0 | Comments[1]
|
|
|
|
|
Monday March 16, 2009
TOTD
#70, #71,
#72,
#73
shows four integration tests that can ensure
that the
latest JRuby and GlassFish versions work nicely with each other.
#70
showed how to create a trivial Rails application and run it using GlassFish
Gem. #71
showed how the same application can be deployed on GlassFish
v3 Prelude. #72
showed how to deploy the same application on GlassFish v3. #73
showed how to deploy a Rails application as WAR file and use the JDBC
connection pooling framework available in GlassFish.
The next set of tests ensure that some commonly used open source Rails
applications can be easily run using this setup. The first one is
Redmine - 0.8 is the stable release now. Redmine was first tried on
GlassFish a
few months ago. The steps have simplified since then :)
Lets begin integration test #5.
| /samples/jruby/redmine >svn co
http://redmine.rubyforge.org/svn/branches/0.8-stable redmine-0.8 A redmine-0.8/test A redmine-0.8/test/unit A redmine-0.8/test/unit/document_test.rb A redmine-0.8/test/unit/token_test.rb . . . A redmine-0.8/public/stylesheets/scm.css A redmine-0.8/public/stylesheets/application.css A redmine-0.8/public/favicon.ico U redmine-0.8 Checked out revision 2580. |
| ~/samples/jruby/redmine/redmine-0.8 >../jruby-1.2.0RC2/bin/jruby -S
rake db:create (in /Users/arungupta/samples/jruby/redmine/redmine-0.8) ~/samples/jruby/redmine/redmine-0.8 >../jruby-1.2.0RC2/bin/jruby -S rake db:migrate (in /Users/arungupta/samples/jruby/redmine/redmine-0.8) == 1 Setup: migrating ========================================================= -- create_table("attachments", {:force=>true}) -> 0.0880s -- create_table("auth_sources", {:force=>true}) -> 0.1430s . . . == 100 AddChangesetsUserId: migrating ========================================= -- add_column(:changesets, :user_id, :integer, {:default=>nil}) -> 0.0980s == 100 AddChangesetsUserId: migrated (0.0990s) ================================ == 101 PopulateChangesetsUserId: migrating ==================================== == 101 PopulateChangesetsUserId: migrated (0.0030s) =========================== |
| ~/samples/jruby/redmine/redmine-0.8 >../jruby-1.2.0RC2/bin/jruby -S
glassfish Mar 13, 2009 11:14:59 AM com.sun.enterprise.glassfish.bootstrap.ASMainStatic findDerbyClient INFO: Cannot find javadb client jar file, jdbc driver not available Mar 13, 2009 11:14:59 AM APIClassLoaderService createAPIClassLoader INFO: APIClassLoader = java.net.URLClassLoader@59fb8de1 . . . Mar 13, 2009 11:15:10 AM com.sun.grizzly.pool.DynamicPool$1 run INFO: New instance created in 10,175 milliseconds Mar 13, 2009 11:15:10 AM com.sun.enterprise.v3.server.AppServerStartup run INFO: GlassFish v3 startup time : Static(356ms) startup services(11456ms) total(11812ms) |







Posted by Arun Gupta in web2.0 | Comments[0]
|
|
|
|
|
Wednesday March 11, 2009
TOTD
#70, #71,
#72
shows the first three integration tests that I typically run to ensure
that the
latest JRuby and GlassFish versions work nicely with each other.
#70
showed how to create a trivial Rails application and run it using GlassFish
Gem. #71
showed how the same application can be deployed on GlassFish
v3 Prelude. #72
showed how to deploy the same application on GlassFish v3.
The next test in the series is to ensure WAR-based deployment of a
Rails application continue to work on GlassFish v2. It also shows that
JNDI database connection pooling also work as expected. The latest
publicly
available build is GlassFish
v2.1.
Lets begin integration test #4.
| ~/tools/jruby-1.2.0RC2/samples/rails/runner
>../../../bin/jruby
-S gem install warbler JRuby limited openssl loaded. gem install jruby-openssl for full support. http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL Successfully installed warbler-0.9.12 1 gem installed Installing ri documentation for warbler-0.9.12... Installing RDoc documentation for warbler-0.9.12... |
| production: adapter: mysql encoding: utf8 database: runner_production pool: 5 username: root password: socket: /tmp/mysql.sock |
| production: adapter: jdbcmysql encoding: utf8 database: runner_production pool: 5 username: duke password: glassfish socket: /tmp/mysql.sock jndi: jdbc/runner_production driver: com.mysql.jdbc.Driver |
| ~/tools/jruby-1.2.0RC1/samples/rails/runner >../../../bin/jruby -S rake
db:create RAILS_ENV=production (in /Users/arungupta/tools/jruby-1.2.0RC1/samples/rails/runner) ~/tools/jruby-1.2.0RC1/samples/rails/runner >../../../bin/jruby -S rake db:migrate RAILS_ENV=production (in /Users/arungupta/tools/jruby-1.2.0RC1/samples/rails/runner) == CreateRunners: migrating ================================================== -- create_table(:runners) -> 0.1150s -> 0 rows == CreateRunners: migrated (0.1170s) ========================================= |
| ~/tools/glassfish/v2.1/glassfish/ >cp ~/tools/mysql-connector-java-5.1.6/mysql-connector-java-5.1.6-bin.jar ./lib |
| ~/tools/glassfish/v2.1/glassfish/bin
>./asadmin
start-domain Starting Domain domain1, please wait. Default Log location is /Users/arungupta/tools/glassfish/v2.1/glassfish/domains/domain1/logs/server.log. Redirecting output to /Users/arungupta/tools/glassfish/v2.1/glassfish/domains/domain1/logs/server.log Domain domain1 started. Domain [domain1] is running [Sun GlassFish Enterprise Server v2.1 (9.1.1) (build b60e-fcs)] with its configuration and logs at: [/Users/arungupta/tools/glassfish/v2.1/glassfish/domains]. Admin Console is available at [http://localhost:4848]. Use the same port [4848] for "asadmin" commands. User web applications are available at these URLs: [http://localhost:8080 https://localhost:8181 ]. Following web-contexts are available: [/web1 /__wstx-services runner ]. Standard JMX Clients (like JConsole) can connect to JMXServiceURL: [service:jmx:rmi:///jndi/rmi://Macintosh-187.local:8686/jmxrmi] for domain management purposes. Domain listens on at least following ports for connections: [8080 8181 4848 3700 3820 3920 8686 ]. Domain supports application server clusters and other standalone instances. |
| ~/tools/glassfish/v2.1/glassfish/bin >./asadmin
create-jdbc-connection-pool --datasourceclassname
com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource --restype
javax.sql.DataSource --property
"User=duke:Password=glassfish:URL=jdbc\:mysql\://localhost/runner_production"
jdbc/runner_pool Command create-jdbc-connection-pool executed successfully. |
| ~/tools/glassfish/v2.1/glassfish/bin >./asadmin create-jdbc-resource
--connectionpoolid jdbc/runner_pool jdbc/runner_production Command create-jdbc-resource executed successfully. |
| ~/tools/jruby-1.2.0RC2/samples/rails/runner >../../../bin/jruby -S warble
config cp /Users/arungupta/tools/jruby-1.2.0RC2/lib/ruby/gems/1.8/gems/warbler-0.9.12/generators/warble/templates/warble.rb config/warble.rb |
| # Include all gems which are used by the
web application require "#{RAILS_ROOT}/config/environment" BUILD_GEMS = %w(warbler rake rcov) for gem in Gem.loaded_specs.values next if BUILD_GEMS.include?(gem.name) config.gems[gem.name] = gem.version.version end |
| config.gems += ["activerecord-jdbc-adapter"] |
| ~/tools/jruby-1.2.0RC2/samples/rails/runner >../../../bin/jruby -S warble mkdir -p tmp/war/WEB-INF/gems/specifications cp /Users/arungupta/tools/jruby-1.2.0RC2/lib/ruby/gems/1.8/specifications/rails-2.2.2.gemspec tmp/war/WEB-INF/gems/specifications/rails-2.2.2.gemspec mkdir -p tmp/war/WEB-INF/gems/gems . . . cp public/javascripts/prototype.js tmp/war/javascripts/prototype.js cp public/stylesheets/scaffold.css tmp/war/stylesheets/scaffold.css mkdir -p tmp/war/WEB-INF |
| ~/tools/jruby-1.2.0RC2/samples/rails/runner >~/tools/glassfish/v2.1/glassfish/bin/asadmin
deploy runner.war Command deploy executed successfully. |

Posted by Arun Gupta in web2.0 | Comments[4]
|
|
|
|
|
Monday March 09, 2009
TOTD # 72: JRuby and GlassFish Integration Test #3: JRuby 1.2.0 RC2 + Rails 2.2.x + GlassFish v3
TOTD
#70 and #71
shows the first two integration tests that I typically run to ensure
that the
latest JRuby and GlassFish versions work nicely with each other.
#70
showed how to create a trivial Rails application and run it using GlassFish
Gem. #71
showed how the same application can be deployed on GlassFish
v3 Prelude.
The third test (explained in this blog) ensures that the
same
application can be easily deployed using GlassFish
v3. GlassFish v3 will be available later this year with full
support for Java EE 6.
JRuby 1.2.0 RC2 is now released. Test
#1 passed, Test
#2 gives the following error:
| Caused by: java.lang.NumberFormatException: For input
string: "0RC2" at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48) at java.lang.Integer.parseInt(Integer.java:456) at java.lang.Integer.parseInt(Integer.java:497) at com.sun.grizzly.jruby.RailsAdapter$JRubyVersion.<init>(RailsAdapter.java:137) at com.sun.grizzly.jruby.RailsAdapter$JRubyVersion.<init>(RailsAdapter.java:131) at com.sun.grizzly.jruby.RailsAdapter.<init>(RailsAdapter.java:110) at com.sun.grizzly.jruby.RubyRuntime.<init>(RubyRuntime.java:48) ... 22 more |

| ~/tools/glassfish/v3/b39/glassfishv3/glassfish
>./bin/asadmin
start-domain Name of the domain started: [domain1] and its location: [/Users/arungupta/tools/glassfish/v3/b39/glassfishv3/glassfish/domains/domain1]. Admin port for the domain: [4848]. |
| ~/tools/glassfish/v3/b39/glassfishv3/glassfish
>./bin/asadmin
create-jvm-options -DJRUBY_HOME="/Users/arungupta/tools/jruby-1.2.0RC2" created 1 option(s) Command create-jvm-options executed successfully. |
| ~/tools/jruby-1.2.0RC1/samples/rails >~/tools/glassfish/v3/b39/glassfishv3/bin/asadmin
deploy runner Command deploy executed successfully. |
| ActionController::RoutingError (No route matches
"s" with {:method=>:get}): /Users/arungupta/tools/jruby-1.2.0RC1/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/routing/recognition_optimisation.rb:66:in `recognize_path' /Users/arungupta/tools/jruby-1.2.0RC1/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/routing/route_set.rb:386:in `recognize' /Users/arungupta/tools/jruby-1.2.0RC1/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/dispatcher.rb:182:in `handle_request' /Users/arungupta/tools/jruby-1.2.0RC1/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/dispatcher.rb:110:in `dispatch_unlocked' /Users/arungupta/tools/jruby-1.2.0RC1/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/dispatcher.rb:123:in `dispatch' /Users/arungupta/tools/jruby-1.2.0RC1/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/dispatcher.rb:122:in `dispatch' /Users/arungupta/tools/jruby-1.2.0RC1/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/dispatcher.rb:132:in `dispatch_cgi' /Users/arungupta/tools/jruby-1.2.0RC1/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_controller/dispatcher.rb:39:in `dispatch' file:/Users/arungupta/tools/glassfish/v3/b39/glassfishv3/glassfish/modules/grizzly-jruby.jar!/rack/adapter/rails.rb:82:in `serve_rails' file:/Users/arungupta/tools/glassfish/v3/b39/glassfishv3/glassfish/modules/grizzly-jruby.jar!/rack/adapter/rails.rb:109:in `call' file:/Users/arungupta/tools/glassfish/v3/b39/glassfishv3/glassfish/modules/grizzly-jruby.jar!/jruby/rack/rails.rb:81:in `call' file:/Users/arungupta/tools/glassfish/v3/b39/glassfishv3/glassfish/modules/grizzly-jruby.jar!/rack/handler/grizzly.rb:55:in `call' :1 |
| ~/tools/jruby-1.2.0RC1/samples/rails >~/tools/glassfish/v3/b39/glassfishv3/bin/asadmin
deploy --contextroot runlog --force=true runner Command deploy executed successfully. |
| ~/tools/jruby-1.2.0RC2/samples/rails >~/tools/glassfish/v3/b39/glassfishv3/bin/asadmin
deploy runlog Command deploy executed successfully. |

Posted by Arun Gupta in web2.0 | Comments[5]
|
|
|
|
|
Thursday March 05, 2009
TOTD
#70 shows the first integration integration tests
that I typically run to ensure
that the
latest JRuby and GlassFish versions work nicely with each other.
The second test (explained in this blog) ensures that the
same
application can be deployed using GlassFish
v3 Prelude.
GlassFish v3 Prelude allows Rails applications to be
deployed natively, i.e. without any packaging.
Lets begin integration test #2.
| ~/tools/glassfish/v3/glassfishv3-prelude/glassfish
>./bin/asadmin
start-domain Name of the domain started: [domain1] and its location: [/Users/arungupta/tools/glassfish/v3/glassfishv3-prelude/glassfish/domains/domain1]. Admin port for the domain: [4848]. |
| ~/tools/glassfish/v3/glassfishv3-prelude/glassfish
>./bin/asadmin
create-jvm-options -DJRUBY_HOME="/Users/arungupta/tools/jruby-1.2.0RC1" created 1 option(s) Command create-jvm-options executed successfully. |
| ~/tools/jruby-1.2.0RC1/samples/rails >~/tools/glassfish/v3/glassfishv3-prelude/bin/asadmin
deploy runner Command deploy executed successfully. |
| Caused by: java.lang.NumberFormatException: For
input string: "0RC1" at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48) at java.lang.Integer.parseInt(Integer.java:456) at java.lang.Integer.parseInt(Integer.java:497) at com.sun.grizzly.jruby.RailsAdapter$JRubyVersion.<init>(RailsAdapter.java:137) at com.sun.grizzly.jruby.RailsAdapter$JRubyVersion.<init>(RailsAdapter.java:131) at com.sun.grizzly.jruby.RailsAdapter.<init>(RailsAdapter.java:110) at com.sun.grizzly.jruby.RubyRuntime.<init>(RubyRuntime.java:48) ... 30 more |
| ~/workspaces >svn co
http://svn.codehaus.org/jruby/trunk/jruby/ A jruby/bench A jruby/bench/bench_tak.rb A jruby/bench/bench_struct.rb . . . A jruby/.settings/org.eclipse.jdt.core.prefs A jruby/.settings/org.eclipse.jdt.ui.prefs U jruby Checked out revision 9347. ~/workspaces >cd jruby/ ~/workspaces/jruby >ant Buildfile: build.xml init: jar: . . . _update_scm_revision_: [jar] Building jar: /Users/arungupta/workspaces/jruby/lib/jruby.jar [jar] Warning: selected jar files include a META-INF/INDEX.LIST which will be replaced by a newly generated one. BUILD SUCCESSFUL Total time: 1 minute 21 seconds |
| ~/workspaces/jruby >./bin/jruby gem install rails JRuby limited openssl loaded. gem install jruby-openssl for full support. http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL Successfully installed rake-0.8.4 Successfully installed activesupport-2.2.2 Successfully installed activerecord-2.2.2 Successfully installed actionpack-2.2.2 Successfully installed actionmailer-2.2.2 Successfully installed activeresource-2.2.2 Successfully installed rails-2.2.2 7 gems installed Installing ri documentation for rake-0.8.4... Installing ri documentation for activesupport-2.2.2... Installing ri documentation for activerecord-2.2.2... Installing ri documentation for actionpack-2.2.2... Installing ri documentation for actionmailer-2.2.2... Installing ri documentation for activeresource-2.2.2... Installing RDoc documentation for rake-0.8.4... Installing RDoc documentation for activesupport-2.2.2... Installing RDoc documentation for activerecord-2.2.2... Installing RDoc documentation for actionpack-2.2.2... Installing RDoc documentation for actionmailer-2.2.2... Installing RDoc documentation for activeresource-2.2.2... |
| ~/tools/glassfish/v3/glassfishv3-prelude/glassfish
>./bin/asadmin
delete-jvm-options -DJRUBY_HOME="/Users/arungupta/tools/jruby-1.2.0RC1" deleted 1 option(s) Command delete-jvm-options executed successfully. |
| ~/tools/glassfish/v3/glassfishv3-prelude/glassfish
>./bin/asadmin
create-jvm-options -DJRUBY_HOME="/Users/arungupta/workspaces/jruby" created 1 option(s) Command create-jvm-options executed successfully. |
| ~/tools/jruby-1.2.0RC1/samples/rails >~/tools/glassfish/v3/glassfishv3-prelude/bin/asadmin
deploy --force=true runner Command deploy executed successfully. |
Posted by Arun Gupta in web2.0 | Comments[5]
|
|
|
|
|
Tuesday March 03, 2009
TOTD # 70: JRuby and GlassFish Integration Test# 1: JRuby 1.2.0 RC1 + Rails 2.2.x + GlassFish Gem
JRuby
1.2.0 RC1 is out for a while!
I typically run a series of tests to ensure that any publicly released
version of JRuby works nicely with GlassFish.
The main goal of running
these tests is to discover any blocking bugs before users do.
This particular set of tests are being run little late as RC1 was
released on Feb 24th. But I'll describe all the steps clearly in the
next few
blog entries so that you can try them out yourself.
JRuby team runs a whole slew of tests before releasing any bits.
Similarly we run a bunch of tests before releasing GlassFish Gem. These
tests, as mentioned earlier, are only to ensure that the latest release
of JRuby works nicely with the latest bits of GlassFish.
The first basic test is to check if a simple Rails application can be
run using the latest GlassFish
Gem. The steps are described next.
First, lets create a database user and grant privileges required by our
application:
| ~/tools >sudo
mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 30 Server version: 5.1.30 MySQL Community Server (GPL) Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql> create user duke@localhost identified by 'glassfish'; Query OK, 0 rows affected (0.00 sec) mysql> grant all on runner_development.* to duke@localhost identified by 'glassfish'; Query OK, 0 rows affected (0.03 sec) mysql> grant all on runner_production.* to duke@localhost identified by 'glassfish'; Query OK, 0 rows affected (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql> exit; Bye |
| ~/tools/jruby-1.2.0RC1 >./bin/jruby -S gem install rails
glassfish JRuby limited openssl loaded. gem install jruby-openssl for full support. http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL Successfully installed activesupport-2.2.2 Successfully installed activerecord-2.2.2 Successfully installed actionpack-2.2.2 Successfully installed actionmailer-2.2.2 Successfully installed activeresource-2.2.2 Successfully installed rails-2.2.2 Successfully installed rack-0.9.1 Successfully installed glassfish-0.9.2-universal-java 8 gems installed Installing ri documentation for activesupport-2.2.2... Installing ri documentation for activerecord-2.2.2... Installing ri documentation for actionpack-2.2.2... Installing ri documentation for actionmailer-2.2.2... Installing ri documentation for activeresource-2.2.2... Installing ri documentation for rack-0.9.1... Installing ri documentation for glassfish-0.9.2-universal-java... Installing RDoc documentation for activesupport-2.2.2... Installing RDoc documentation for activerecord-2.2.2... Installing RDoc documentation for actionpack-2.2.2... Installing RDoc documentation for actionmailer-2.2.2... Installing RDoc documentation for activeresource-2.2.2... Installing RDoc documentation for rack-0.9.1... Installing RDoc documentation for glassfish-0.9.2-universal-java... |
| ~/tools/jruby-1.2.0RC1/samples/rails
>../../bin/jruby
-S rails runner -d mysql JRuby limited openssl loaded. gem install jruby-openssl for full support. http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL create create app/controllers create app/helpers . . . create log/server.log create log/production.log create log/development.log create log/test.log |
| ~/tools/jruby-1.2.0RC1/samples/rails
>../../bin/jruby
-S gem install activerecord-jdbcmysql-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.9 Successfully installed jdbc-mysql-5.0.4 Successfully installed activerecord-jdbcmysql-adapter-0.9 3 gems installed Installing ri documentation for activerecord-jdbc-adapter-0.9... Installing ri documentation for jdbc-mysql-5.0.4... Installing ri documentation for activerecord-jdbcmysql-adapter-0.9... Installing RDoc documentation for activerecord-jdbc-adapter-0.9... Installing RDoc documentation for jdbc-mysql-5.0.4... Installing RDoc documentation for activerecord-jdbcmysql-adapter-0.9... |
| ~/tools/jruby-1.2.0RC1/samples/rails/runner
>../../../bin/jruby
script/generate scaffold runner
distance:float time: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/ . . . create test/fixtures/runners.yml create db/migrate create db/migrate/20090226171752_create_runners.rb |
| development: adapter: mysql encoding: utf8 database: runner_development pool: 5 username: root password: socket: /tmp/mysql.sock |
| development: adapter: jdbcmysql encoding: utf8 database: runner_development pool: 5 username: duke password: glassfish socket: /tmp/mysql.sock |
| ~/tools/jruby-1.2.0RC1/samples/rails/runner >../../../bin/jruby -S rake
db:create (in /Users/arungupta/tools/jruby-1.2.0RC1/samples/rails/runner) ~/tools/jruby-1.2.0RC1/samples/rails/runner >../../../bin/jruby -S rake db:migrate (in /Users/arungupta/tools/jruby-1.2.0RC1/samples/rails/runner) == CreateRunners: migrating ================================================== -- create_table(:runners) -> 0.1330s -> 0 rows == CreateRunners: migrated (0.1340s) ========================================= |
| ~/tools/jruby-1.2.0RC1/samples/rails/runner >../../../bin/jruby -S glassfish Feb 26, 2009 10:30:10 AM com.sun.enterprise.glassfish.bootstrap.ASMainStatic start INFO: Cache not present, will revert to less efficient algorithm Feb 26, 2009 10:30:10 AM com.sun.enterprise.glassfish.bootstrap.ASMainStatic findDerbyClient INFO: Cannot find javadb client jar file, jdbc driver not available Feb 26, 2009 10:30:10 AM APIClassLoaderService createAPIClassLoader INFO: APIClassLoader = java.net.URLClassLoader@14a66e3f no resource bundle found for version, using default GlassFish version Feb 26, 2009 10:30:11 AM AppServerStartup run INFO: [Thread[GlassFish Kernel Main Thread,5,main]] started Feb 26, 2009 10:30:11 AM com.sun.enterprise.v3.services.impl.GrizzlyProxy start INFO: Listening on port 3000 Feb 26, 2009 10:30:11 AM com.sun.enterprise.v3.admin.adapter.AdminEndpointDecider setGuiContextRoot INFO: Admin Console Adapter: context root: /_____admingui Feb 26, 2009 10:30:11 AM com.sun.enterprise.v3.admin.adapter.AdminConsoleAdapter setStateMsg INFO: The Admin Console Application is not yet installed. Feb 26, 2009 10:30:11 AM com.sun.enterprise.v3.admin.adapter.AdminEndpointDecider setGuiContextRoot INFO: Admin Console Adapter: context root: /_____admingui Feb 26, 2009 10:30:11 AM org.glassfish.scripting.rails.RailsDeployer load INFO: Loading application runner at / Feb 26, 2009 10:30:11 AM com.sun.grizzly.jruby.RailsAdapter <init> INFO: Jruby version is: 1.2.0RC1 Feb 26, 2009 10:30:11 AM com.sun.grizzly.jruby.rack.RackApplicationChooser detectRails INFO: Detected Rails application Feb 26, 2009 10:30:11 AM com.sun.grizzly.jruby.rack.RackApplicationChooser detectRails INFO: Rails not in thread-safe mode, starting in single-thread mode Feb 26, 2009 10:30:11 AM com.sun.grizzly.pool.DynamicPool logDynamicStatus INFO: Pool started without dynamic resizing enabled. Pool will not attempt to determine the upper and lower bounds that it should be using, and will stay at 1 Feb 26, 2009 10:30:16 AM SEVERE: JRuby limited openssl loaded. gem install jruby-openssl for full support. http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL Feb 26, 2009 10:30:18 AM INFO: RAILS_ROOT /Users/arungupta/tools/jruby-1.2.0RC1/samples/rails/runner Feb 26, 2009 10:30:18 AM INFO: PUBLIC_ROOT /Users/arungupta/tools/jruby-1.2.0RC1/samples/rails/runner/public Feb 26, 2009 10:30:19 AM com.sun.grizzly.pool.DynamicPool$1 run INFO: New instance created in 7,074 milliseconds Feb 26, 2009 10:30:19 AM com.sun.enterprise.v3.server.AppServerStartup run INFO: GlassFish v3 startup time : Static(525ms) startup services(7962ms) total(8487ms) Feb 26, 2009 10:30:19 AM com.sun.enterprise.glassfish.bootstrap.ASMainStatic start INFO: Started cache creation Feb 26, 2009 10:30:20 AM com.sun.enterprise.glassfish.bootstrap.ASMainStatic start INFO: Finished cache creation Feb 26, 2009 10:30:34 AM sun.reflect.NativeMethodAccessorImpl invoke0 INFO: |

Posted by Arun Gupta in web2.0 | Comments[10]
|
|
|
|
|
Wednesday January 14, 2009
TOTD #65: Windows 7 Beta 1 Build 7000 on Virtual Box: NetBeans + Rails + GlassFish + MySQL
Microsoft released Windows 7
Beta 1 - the next major version of Vista, download
here. There are tons
of improvments mostly centered around making the content
easily & intuitively accessible. But hey, Mac OSX already
serves
that purpose well for quite some time ;-)
But I still want to make sure that our Rails stack (NetBeans,
GlassFish,
and MySQL) work fine on it. And it very well do, without any issues, as
you'll realize at the end of this blog :)
Lets first get started with installing Windows 7 Beta as a Virtual Box
image. Few points to note here:











Posted by Arun Gupta in web2.0 | Comments[8]
|
|
|
|
|
Monday January 12, 2009
TOTD #64: OpenSolaris 2008/11 using Virtual Box
Here is a blog entry that was sitting in my Drafts folder for a long
time
(just because I didn't realize :). Anyway, it shows how to install Open Solaris 2008/11
on Virtual Box.
The original install was done using Virtual Box 2.0.6. I installed
Virtual Box 2.1 this morning and the image was easily recognized by the
updated Virtual Box.
Here are the basic steps.
Create a new VM ...

As part of the previous step, create a new Virtual Disk mapping to the
downloaded Open Solaris image ...

The generated VM settings are shown as below:

Click on "Start" and configure for the first run as:

Boot the Virtual Macine from the LiveCD shows the following GRUB:

Take the default for Language and Keyboard and then the following
screen is shown after the boot:

Click on "Install OpenSolaris" ...

Clicking on "Install" starts the installation ...

And finally the install is completed.

Click on "Reboot", select "Boot from Hard Disk" and press Enter ...

And then select if "full boot" or "text boot" is required as shown:

And the welcome screen is shown as:

Now you can develop your Rails
applications using the NetBeans
IDE and deploy them on GlassFish
and MySQL easily as
explained here.
There are multiple updates to the stack described earlier - JRuby 1.1.6,
Rails
2.2, MySQL
Alpha 6.0.x, GlassFish
v3 Prelude, and Virtual Box
2.1.
So go ahead and develop, deploy, and debug your Rails applications as
described in screencast
#26. You can even manage your Rails applications using JMX as
described in TOTD #61,
#62,
and #63.
Hwo do you follow the latest on each technology:
Posted by Arun Gupta in web2.0 | Comments[8]
|
|
|
|
|
Friday January 09, 2009
TOTD #63: jmx4r gem - How to manage/monitor your Rails/Merb applications on JRuby/GlassFish ?
TOTD
#61 and TOTD
#62 shows how to use JMX APIs to locally/remotely
manage/monitor your Rails/Merb applications. This Tip Of The Day
extends TOTD #62 and shows how remote management can be done using jmx4r gem.
This gem provides a clean mapping between JMX APIs and Ruby. It allows
to write pure Ruby code to manage/monitor any Rails application. As a
result it removes all dependency on the Java code used in TOTD
#62.
Lets first install the gem!
| ~ >gem
install jmx4r JRuby limited openssl loaded. gem install jruby-openssl for full support. http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL Successfully installed jmx4r-0.0.6 1 gem installed Installing ri documentation for jmx4r-0.0.6... Installing RDoc documentation for jmx4r-0.0.6... |
| require 'rubygems' require 'jmx4r' JMX::MBean.establish_connection :host => "129.145.133.163", :port => 8686 beans = JMX::MBean.find_all_by_name "org.jruby:*" beans.each { |bean| service = bean.object_name["service"] case service when "ClassCache" @cc_mbean = bean when "Config" @c_mbean = bean end } # clear the cache if it's full if @cc_mbean.full printf "JIT Max: %d, JIT Threshold: %d, Class load count: %d\n", @c_mbean.jit_max, @c_mbean.jit_threshold, @cc_mbean.class_load_count @cc_mbean.flush else puts "Class Cache is not full" printf "Loaded: %d, Reused: %d, Live: %d\n", @cc_mbean.class_load_count, @cc_mbean.class_reuse_count, @cc_mbean.live_class_count end |
| jruby main.rb |
| Class Cache is not full Loaded: 76, Reused: 0, Live: 76 |
Posted by Arun Gupta in web2.0 | Comments[4]
|
|
|
|
|
Thursday January 08, 2009
TOTD
#61 showed how to manage/monitor a Rails/Merb application
running using JRuby/GlassFish using standard Java tools. Both the
application and the management tools are running on the same machine.
But that's never the case in a production environment. Instead remote
management of an application is required when running in production
mode. Fortunately, similar set of tools can be used for remote
management as well.
However the underlying Java Virtual Machine needs to be configured to
enable remote monitoring. This is achieved by setting JAVA_OPTS
environment variables as shown below:
Set up the following envinronment variable before running the
Rails/Merb application:
| export JAVA_OPTS="-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=8686
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false" |
| service:jmx:rmi:///jndi/rmi://192.168.124.1:8686/jmxrmi |
| jconsole |



| include Java import java.io.IOException import java.util.HashSet import java.util.Set import javax.management.JMRuntimeException import javax.management.MBeanServerConnection import javax.management.MalformedObjectNameException import javax.management.ObjectName import javax.management.JMX import javax.management.remote.JMXConnector import javax.management.remote.JMXConnectorFactory import javax.management.remote.JMXServiceURL import org.jruby.management.ClassCacheMBean import org.jruby.management.ConfigMBean url = JMXServiceURL.new "service:jmx:rmi:///jndi/rmi://192.168.124.1:8686/jmxrmi" mbsc = JMXConnectorFactory.connect(url, nil).get_mbean_server_connection names = HashSet.new(mbsc.query_names(ObjectName.new("org.jruby:*"), nil)) names.each { |name| service = name.get_key_property "service" if service == "ClassCache" @cc_mbean = JMX.new_mbean_proxy(mbsc, name, Java::org.jruby.management.ClassCacheMBean.java_class) elsif service == "Config" @c_mbean = JMX.newMBeanProxy(mbsc, name, Java::org.jruby.management.ConfigMBean.java_class) end } # clear the cache if it's full if @cc_mbean.is_full puts @c_mbean.get_jit_max puts @c_mbean.get_jit_threshold puts @cc_mbean.get_class_load_count @cc_mbean.flush else puts "Class Cache is not full" printf "Loaded: %d, Reused: %d, Live: %d\n", @cc_mbean.get_class_load_count, @cc_mbean.get_class_reuse_count, @cc_mbean.get_live_class_count end |
Posted by Arun Gupta in web2.0 | Comments[3]
|
|
|
|
|
Wednesday January 07, 2009
TOTD #61: How to locally manage/monitor your Rails/Merb applications on JRuby/GlassFish using JMX ?
![]() |
GlassFish Gem can easily run both Rails and Merb application. Using JRuby, as opposed to MRI, allows you to use standard Java monitoring framework and tools. Java Management Extensions (JMX) is a standard management and monitoring solution for Java platform. This Tip Of The Day shows how to apply JMX techniques to monitor Rails/Merb applications. |
| jconsole |












Posted by Arun Gupta in web2.0 | Comments[5]
|
|
|
|
|
Friday November 21, 2008
TOTD #55: How to build GlassFish v3 Gem ?
GlassFish
Gem is a light-weight and robust deployment solution for
Ruby-on-Rails
and Merb
applications. The gem can be easily installed as:
| gem install glassfish |
| svn co
https://svn.dev.java.net/svn/glassfish-scripting/trunk/rails/v3/gem gem cd gem mvn -U clean install |
Posted by Arun Gupta in web2.0 | Comments[2]
|
|
|
|
|
Today's Page Hits: 8241
Total # blog entries: 1002