Tuesday Sep 22, 2009

TOTD #105: GlassFish v3 Monitoring – How to monitor a Rails app using asadmin, JavaScript, jConsole, REST ?

Monitoring infrastructure in GlassFish v3 is getting an extreme makeover. Prashanth defines it very nicely in his detailed introduction:

We provide a way to dynamically and non-intrusively generate monitoring events from any of the GlassFish runtime classes, the ability to listen to these events, collect the statistics and expose these statistics through various standard clients.

The "dynamic" nature indicates that monitoring can be turned ON or OFF in a GlassFish instance running in production environment. It also means the granularity to which the monitoring information can be generated. This information can be generated for not only a traditional Java EE applications, but Rails, Django and other type of applications that can be easily deployed on GlassFish v3. And that is extensible for other pluggable containers too. The data can be accessed using multiple mechanisms providing the administrator a wide variety of choice for tools, e.g. DTrace, JMX, REST, asadmin CLI, and Admin Console and thus another point in favor of "dynamic".

The "non-intrusive" behavior means that monitoring can be used in production environment with minimal overhead. It also means that there is no overhead when monitoring is not enabled. Anyway, monitoring needs to be explicitly enabled as explained below.

As mentioned above, there are multiple ways to access the monitoring data. The different ways to access the monitoring data are:

  1. DTrace scripts (only on Solaris)
  2. asadmin CLI
  3. Admin Console
  4. JMX/jConsole
  5. REST
  6. Custom client using a 3rd party scripting language (available as value-add feature to paid customers only)

This Tip Of The Day will describe how to access the monitoring data using asadmin CLI and a JavaScript client. Note that the JavaScript client feature is available as a value-add to the community version of GlassFish and available only to the paid customers.

This tip will use a pre-deployed Rails application as (Redmine as described in TOTD #104) on a nightly GlassFish v3 build (CI, nightly, or promoted) and explains how to monitor this application.

Using the terminology defined in Monitoring in GlassFish v3 blog, the JRuby subsystem in GlassFish has multiple probe providers and each provider has multiple probes. The JRuby subsystem also provides multiple stats providers with probe listeners. All of these elements are linked using the monitoring infrastructure in GlassFish.

Lets monitor our Rails application

Monitoring using asadmin CLI

By default the monitoring is turned OFF for all the components. Lets enable monitoring for the JRuby container as:

asadmin enable-monitoring --level jruby-container=HIGH

The other possible values are "LOW" and "OFF". All the probes publishing monitoring data can be listed as:

~/tools/glassfish/v3/9-18/glassfishv3 >./bin/asadmin list --monitor=true "\*"
server
server.containers
server.containers.jruby
server.containers.jruby.applications
server.containers.jruby.http
server.containers.jruby.http.redmine-0.8.5
server.containers.jruby.runtime-pool
server.containers.jruby.runtime-pool.redmine-0.8.5

Command list executed successfully.

A snapshot of the monitoring data can be obtained as:

~/tools/glassfish/v3/9-18/glassfishv3 >./bin/asadmin get --monitor=true "\*jruby\*"
server.containers.jruby.applications.activerubyapplications.redmine-0.8.5-appName = redmine-0.8.5
server.containers.jruby.applications.activerubyapplications.redmine-0.8.5-description =
 server.containers.jruby.applications.activerubyapplications.redmine-0.8.5-environment = development
server.containers.jruby.applications.activerubyapplications.redmine-0.8.5-jrubyVersion = 1.3.0
server.containers.jruby.applications.activerubyapplications.redmine-0.8.5-lastsampletime = 1253322280437
server.containers.jruby.applications.activerubyapplications.redmine-0.8.5-name = redmine-0.8.5
server.containers.jruby.applications.activerubyapplications.redmine-0.8.5-rubyFramework = rails
server.containers.jruby.applications.activerubyapplications.redmine-0.8.5-starttime = 1253322280437
server.containers.jruby.applications.activerubyapplications.redmine-0.8.5-unit =
server.containers.jruby.applications.activerubyappscount-count = 1
server.containers.jruby.applications.activerubyappscount-description = Number of currently loaded Ruby applications
server.containers.jruby.applications.activerubyappscount-lastsampletime = 1253322279921
server.containers.jruby.applications.activerubyappscount-name = ActiveRubyApplications
server.containers.jruby.applications.activerubyappscount-starttime = 1253322279922
server.containers.jruby.applications.activerubyappscount-unit = count
server.containers.jruby.http.redmine-0.8.5.address = null
server.containers.jruby.http.redmine-0.8.5.averageprocessingtime = 0
server.containers.jruby.http.redmine-0.8.5.count200-count = 0
server.containers.jruby.http.redmine-0.8.5.count200-description = Number of responses with a status code equal to 200
server.containers.jruby.http.redmine-0.8.5.count200-lastsampletime = 1253322280245
server.containers.jruby.http.redmine-0.8.5.count200-name = Count200
server.containers.jruby.http.redmine-0.8.5.count200-starttime = 1253322280245
server.containers.jruby.http.redmine-0.8.5.count200-unit = count
server.containers.jruby.http.redmine-0.8.5.count2xx-count = 0
server.containers.jruby.http.redmine-0.8.5.count2xx-description = Number of responses with a status code in the 2xx range
server.containers.jruby.http.redmine-0.8.5.count2xx-lastsampletime = 1253322280245
server.containers.jruby.http.redmine-0.8.5.count2xx-name = Count2xx
server.containers.jruby.http.redmine-0.8.5.count2xx-starttime = 1253322280245
server.containers.jruby.http.redmine-0.8.5.count2xx-unit = count
server.containers.jruby.http.redmine-0.8.5.count302-count = 0
server.containers.jruby.http.redmine-0.8.5.count302-description = Number of responses with a status code equal to 302
server.containers.jruby.http.redmine-0.8.5.count302-lastsampletime = 1253322280245
server.containers.jruby.http.redmine-0.8.5.count302-name = Count302
server.containers.jruby.http.redmine-0.8.5.count302-starttime = 1253322280245
server.containers.jruby.http.redmine-0.8.5.count302-unit = count
server.containers.jruby.http.redmine-0.8.5.count304-count = 0
server.containers.jruby.http.redmine-0.8.5.count304-description = Number of responses with a status code equal to 304
server.containers.jruby.http.redmine-0.8.5.count304-lastsampletime = 1253322280245
server.containers.jruby.http.redmine-0.8.5.count304-name = Count304
server.containers.jruby.http.redmine-0.8.5.count304-starttime = 1253322280245
server.containers.jruby.http.redmine-0.8.5.count304-unit = count
server.containers.jruby.http.redmine-0.8.5.count3xx-count = 0
server.containers.jruby.http.redmine-0.8.5.count3xx-description = Number of responses with a status code in the 3xx range
server.containers.jruby.http.redmine-0.8.5.count3xx-lastsampletime = 1253322280245
server.containers.jruby.http.redmine-0.8.5.count3xx-name = Count3xx
server.containers.jruby.http.redmine-0.8.5.count3xx-starttime = 1253322280245
server.containers.jruby.http.redmine-0.8.5.count3xx-unit = count
server.containers.jruby.http.redmine-0.8.5.count400-count = 0
server.containers.jruby.http.redmine-0.8.5.count400-description = Number of responses with a status code equal to 400
server.containers.jruby.http.redmine-0.8.5.count400-lastsampletime = 1253322280245
server.containers.jruby.http.redmine-0.8.5.count400-name = Count400
server.containers.jruby.http.redmine-0.8.5.count400-starttime = 1253322280245
server.containers.jruby.http.redmine-0.8.5.count400-unit = count
server.containers.jruby.http.redmine-0.8.5.count401-count = 0
server.containers.jruby.http.redmine-0.8.5.count401-description = Number of responses with a status code equal to 401
server.containers.jruby.http.redmine-0.8.5.count401-lastsampletime = 1253322280245
server.containers.jruby.http.redmine-0.8.5.count401-name = Count401
server.containers.jruby.http.redmine-0.8.5.count401-starttime = 1253322280245
server.containers.jruby.http.redmine-0.8.5.count401-unit = count
server.containers.jruby.http.redmine-0.8.5.count403-count = 0
server.containers.jruby.http.redmine-0.8.5.count403-description = Number of responses with a status code equal to 403
server.containers.jruby.http.redmine-0.8.5.count403-lastsampletime = 1253322280245
server.containers.jruby.http.redmine-0.8.5.count403-name = Count403
server.containers.jruby.http.redmine-0.8.5.count403-starttime = 1253322280245
server.containers.jruby.http.redmine-0.8.5.count403-unit = count
server.containers.jruby.http.redmine-0.8.5.count404-count = 0
server.containers.jruby.http.redmine-0.8.5.count404-description = Number of responses with a status code equal to 404
server.containers.jruby.http.redmine-0.8.5.count404-lastsampletime = 1253322280245
server.containers.jruby.http.redmine-0.8.5.count404-name = Count404
server.containers.jruby.http.redmine-0.8.5.count404-starttime = 1253322280245
server.containers.jruby.http.redmine-0.8.5.count404-unit = count
server.containers.jruby.http.redmine-0.8.5.count4xx-count = 0
server.containers.jruby.http.redmine-0.8.5.count4xx-description = Number of responses with a status code in the 4xx range
server.containers.jruby.http.redmine-0.8.5.count4xx-lastsampletime = 1253322280245
server.containers.jruby.http.redmine-0.8.5.count4xx-name = Count4xx
server.containers.jruby.http.redmine-0.8.5.count4xx-starttime = 1253322280245
server.containers.jruby.http.redmine-0.8.5.count4xx-unit = count
server.containers.jruby.http.redmine-0.8.5.count503-count = 0
server.containers.jruby.http.redmine-0.8.5.count503-description = Number of responses with a status code equal to 503
server.containers.jruby.http.redmine-0.8.5.count503-lastsampletime = 1253322280245
server.containers.jruby.http.redmine-0.8.5.count503-name = Count503
server.containers.jruby.http.redmine-0.8.5.count503-starttime = 1253322280245
server.containers.jruby.http.redmine-0.8.5.count503-unit = count
server.containers.jruby.http.redmine-0.8.5.count5xx-count = 0
server.containers.jruby.http.redmine-0.8.5.count5xx-description = Number of responses with a status code in the 5xx range
server.containers.jruby.http.redmine-0.8.5.count5xx-lastsampletime = 1253322280245
server.containers.jruby.http.redmine-0.8.5.count5xx-name = Count5xx
server.containers.jruby.http.redmine-0.8.5.count5xx-starttime = 1253322280245
server.containers.jruby.http.redmine-0.8.5.count5xx-unit = count
server.containers.jruby.http.redmine-0.8.5.countother-count = 0
server.containers.jruby.http.redmine-0.8.5.countother-description = Number of responses with other status codes
server.containers.jruby.http.redmine-0.8.5.countother-lastsampletime = 1253322280245
server.containers.jruby.http.redmine-0.8.5.countother-name = CountOther
server.containers.jruby.http.redmine-0.8.5.countother-starttime = 1253322280245
server.containers.jruby.http.redmine-0.8.5.countother-unit = count
server.containers.jruby.http.redmine-0.8.5.errorcount-count = 0
server.containers.jruby.http.redmine-0.8.5.errorcount-description = Number of responses with a status code greater than 400
server.containers.jruby.http.redmine-0.8.5.errorcount-lastsampletime = 1253322280245
server.containers.jruby.http.redmine-0.8.5.errorcount-name = ErrorCount
server.containers.jruby.http.redmine-0.8.5.errorcount-starttime = 1253322280245
server.containers.jruby.http.redmine-0.8.5.errorcount-unit = count
server.containers.jruby.http.redmine-0.8.5.requestcount-count = 0
server.containers.jruby.http.redmine-0.8.5.requestcount-description = Number of HTTP requests received
server.containers.jruby.http.redmine-0.8.5.requestcount-lastsampletime = 1253322280243
server.containers.jruby.http.redmine-0.8.5.requestcount-name = RequestCounter
server.containers.jruby.http.redmine-0.8.5.requestcount-starttime = 1253322280243
server.containers.jruby.http.redmine-0.8.5.requestcount-unit = count
server.containers.jruby.http.redmine-0.8.5.requestpersecond = null
server.containers.jruby.runtime-pool.redmine-0.8.5.activeruntimes-count = 1
server.containers.jruby.runtime-pool.redmine-0.8.5.activeruntimes-description = Currently active runtimes
server.containers.jruby.runtime-pool.redmine-0.8.5.activeruntimes-lastsampletime = 1253322280241
server.containers.jruby.runtime-pool.redmine-0.8.5.activeruntimes-name = activeRuntimes
server.containers.jruby.runtime-pool.redmine-0.8.5.activeruntimes-starttime = 1253322280241
server.containers.jruby.runtime-pool.redmine-0.8.5.activeruntimes-unit = count
server.containers.jruby.runtime-pool.redmine-0.8.5.applicationname = redmine-0.8.5
server.containers.jruby.runtime-pool.redmine-0.8.5.contextpath = /redmine-0.8.5
server.containers.jruby.runtime-pool.redmine-0.8.5.hardmaximum-count = 1
server.containers.jruby.runtime-pool.redmine-0.8.5.hardmaximum-description = Maximum active runtimes
server.containers.jruby.runtime-pool.redmine-0.8.5.hardmaximum-lastsampletime = 1253322280241
server.containers.jruby.runtime-pool.redmine-0.8.5.hardmaximum-name = hardMaximum
server.containers.jruby.runtime-pool.redmine-0.8.5.hardmaximum-starttime = 1253322280241
server.containers.jruby.runtime-pool.redmine-0.8.5.hardmaximum-unit = count
server.containers.jruby.runtime-pool.redmine-0.8.5.hardmminimum-count = 1
server.containers.jruby.runtime-pool.redmine-0.8.5.hardmminimum-description = Minimum active runtimes
server.containers.jruby.runtime-pool.redmine-0.8.5.hardmminimum-lastsampletime = 1253322280241
server.containers.jruby.runtime-pool.redmine-0.8.5.hardmminimum-name = hardMinimum
server.containers.jruby.runtime-pool.redmine-0.8.5.hardmminimum-starttime = 1253322280241
server.containers.jruby.runtime-pool.redmine-0.8.5.hardmminimum-unit = count

Command get executed successfully.

The command asadmin get --monitor=true "\*jruby\*" dumps a snapshot of the monitoring data such as the number of Ruby currently applications loaded, application name, JRuby version, environment (development / test / production), currently active runtimes, min/max runtimes, number of HTTP requests / responses with a certain HTTP code and much more information. It basically dumps all the JRuby monitoring information captured so far.

An alternate regular expression may be specified such as:

asadmin get --monitor=true "\*jruby\*runtime-pool\*"

to gather only the runtime pool specific values.

Monitoring using JavaScript client

Third-party scripting client are a value-add to the community versions. Just like Enterprise Manager, the value-add will be available as a patch to the users who purchase commercial support. Lets see what can be done with it though.

First of all you can type the command "list-probes" to see a list of all the probes that are available. A typical output will look like:

~/tools/glassfish/v3/9-18/glassfishv3 >./bin/asadmin list-probes
glassfish:kernel:connections-keep-alive:decrementCountConnectionsEvent decrementCountConnectionsEvent(java.lang.String)
glassfish:web:web-module:webModuleStoppedEvent webModuleStoppedEvent(java.lang.String, java.lang.String)
glassfish:jca:connection-pool:connectionValidationFailedEvent connectionValidationFailedEvent(java.lang.String, int)
glassfish:jca:work-management:workWaitedFor workWaitedFor(java.lang.String, long)
glassfish:jdbc:connection-pool:connectionTimedOutEvent connectionTimedOutEvent(java.lang.String)
glassfish:security:ejbpolicy:ejbPCCreationEvent ejbPCCreationEvent(java.lang.String)
glassfish:kernel:thread-pool:threadReturnedToPoolEvent threadReturnedToPoolEvent(java.lang.String, java.lang.String)
glassfish:web:session:sessionPersistedEndEvent sessionPersistedEndEvent(java.lang.String, java.lang.String, java.lang.String)
glassfish:web:http-service:requestStartEvent requestStartEvent(java.lang.String, java.lang.String, java.lang.String, int, java.lang.String, java.lang.String)
glassfish:jdbc:connection-pool:connectionsFreedEvent connectionsFreedEvent(java.lang.String, int)
glassfish:jdbc:connection-pool:toString toString(java.lang.String, java.lang.StringBuffer)
glassfish:jca:connection-pool:decrementFreeConnectionsSizeEvent decrementFreeConnectionsSizeEvent(java.lang.String, int)
glassfish:kernel:connections-keep-alive:incrementCountFlushesEvent incrementCountFlushesEvent(java.lang.String)
glassfish:webservices:109:deploy deploy(com.sun.enterprise.deployment.Application, com.sun.enterprise.deployment.WebServiceEndpoint)
glassfish:jca:connection-pool:connectionAcquiredEvent connectionAcquiredEvent(java.lang.String)
glassfish:web:http-service:requestEndEvent requestEndEvent(java.lang.String, java.lang.String, java.lang.String, int, java.lang.String, java.lang.String, int)
glassfish:kernel:connections-keep-alive:incrementCountRefusalsEvent incrementCountRefusalsEvent(java.lang.String)
glassfish:kernel:connections:connectionConnectedEvent connectionConnectedEvent(java.lang.String, int)
glassfish:kernel:file-cache:addHeapSizeEvent addHeapSizeEvent(java.lang.String, long)
glassfish:jruby:runtime-pool:runtimePoolUpdateEvent runtimePoolUpdateEvent(java.lang.String, int, int, int, int, int)
glassfish:security:web:securityManagerCreationEvent securityManagerCreationEvent(java.lang.String)
glassfish:security:web:securityManagerDestructionEvent securityManagerDestructionEvent(java.lang.String)
glassfish:webservices:ri:undeploy undeploy(com.sun.xml.ws.transport.http.servlet.ServletAdapter)
glassfish:web:session:sessionPersistedStartEvent sessionPersistedStartEvent(java.lang.String, java.lang.String, java.lang.String)
glassfish:ejb:pool:objectAddedEvent ejbObjectAddedEvent()
glassfish:ejb:bean:methodStartEvent ejbMethodStartEvent(java.lang.String, java.lang.String, java.lang.String, java.lang.reflect.Method)
glassfish:jdbc:connection-pool:connectionRequestServedEvent connectionRequestServedEvent(java.lang.String, long)

All the JRuby probes can be easily listed as:

~/tools/glassfish/v3/9-18/glassfishv3 >./bin/asadmin list-probes | grep jruby
glassfish:jruby:runtime-pool:runtimePoolUpdateEvent runtimePoolUpdateEvent(java.lang.String, int, int, int, int, int)
glassfish:jruby:http:requestStartEvent requestStartEvent(java.lang.String, java.lang.String, int)
glassfish:jruby:jruby-container:jrubyModuleStartedEvent jrubyModuleStartedEvent(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
glassfish:jruby:jruby-container:jrubyModuleStoppedEvent jrubyModuleStoppedEvent(java.lang.String, java.lang.String, java.lang.String)
glassfish:jruby:http:requestEndEvent requestEndEvent(java.lang.String, int)
glassfish:jruby:runtime-pool:runtimePoolStartEvent runtimePoolStartEvent(java.lang.String, int, int, int, int, int, int, int)

More detailed information about each probe can be easily found by giving the command:

~/tools/glassfish/v3/9-18/glassfishv3 >./bin/asadmin list-probes --manpage=true glassfish:jruby:runtime-pool:runtimePoolUpdateEvent

This will show the detailed information ("man" pages) about the specific probe. A JavaScript client to monitor the deployed Rails application and gather the relevant statistics can be written using these pages as shown below:

moduleStarted = function(appName, appType, env, jruby) {
    client.print( '\\n log> Deployed a \\'' + appType + '\\' app named \\'' + appName + '\\' in \\'' + env + '\\' environment with JRuby \\'' + jruby + '\\'.');
}

moduleStopped = function(appName, appType, env) {
    client.print( '\\n log> Undeployed a \\'' + appType + '\\' app named \\'' + appName + '\\' in \\'' + env + '\\' environment.');
}

requestStarted = function(contextPath, serverName, port) {
    client.print( '\\n log> Request started at \\'' + contextPath + '\\' hosted on \\'' + serverName + ':' + port + '\\'');
}

requestEnded = function(contextPath, statusCode) {
    client.print( '\\n log> Request stopped at \\'' + contextPath + '\\' with status code \\'' + statusCode + '\\'');
}

runtimePoolStart = function(appName, activeRuntimes, queueSize) {
   client.print( '\\n log> JRuby runtime pool started for the app \\'' + appName + '\\': active runtime - ' + activeRuntimes + ', queue size - ' + queueSize);
}

runtimePoolUpdate = function(appName, activeRuntimes, queueSize) {
   client.print( '\\n log> JRuby runtime pool updated for the app \\'' + appName + '\\': active runtime - ' + activeRuntimes + ', queue size - ' + queueSize);
}

moduleStartedParams = java.lang.reflect.Array.newInstance(java.lang.String, 4);
moduleStartedParams[0]="appName";
moduleStartedParams[1]="applicationType";
moduleStartedParams[2]="environment";
moduleStartedParams[3]="jrubyVersion";
scriptContainer.registerListener('glassfish:jruby:jruby-container:jrubyModuleStartedEvent', moduleStartedParams, 'moduleStarted');

moduleStoppedParams = java.lang.reflect.Array.newInstance(java.lang.String, 3);
moduleStoppedParams[0]="appName";
moduleStoppedParams[1]="applicationType";
moduleStoppedParams[2]="environment";
scriptContainer.registerListener('glassfish:jruby:jruby-container:jrubyModuleStoppedEvent', moduleStoppedParams, 'moduleStopped');

requestStartParams = java.lang.reflect.Array.newInstance(java.lang.String, 3);
requestStartParams[0]="contextPath";
requestStartParams[1]="serverName";
requestStartParams[2]="port";
scriptContainer.registerListener('glassfish:jruby:http:requestStartEvent', requestStartParams, 'requestStarted');

requestEndParams = java.lang.reflect.Array.newInstance(java.lang.String, 2);
requestEndParams[0]="contextPath";
requestEndParams[1]="statusCode";
scriptContainer.registerListener('glassfish:jruby:http:requestEndEvent', requestEndParams, 'requestEnded');

runtimePoolParams = java.lang.reflect.Array.newInstance(java.lang.String, 3);
runtimePoolParams[0]="appName";
runtimePoolParams[1]="activeRuntimes";
runtimePoolParams[2]="queueSize";
scriptContainer.registerListener('glassfish:jruby:runtime-pool:runtimePoolStartEvent', runtimePoolParams, 'runtimePoolStart');
scriptContainer.registerListener('glassfish:jruby:runtime-pool:runtimePoolUpdateEvent', runtimePoolParams, 'runtimePoolUpdate');

This script register listeners for different probe events, pass a set of parameters that need to be captured, and print the information in a callback method specified during registration. The number of listeners and parameters / listener may be altered to meet your data capturing needs.

This script is stored in a file "monitor-rails.js" and used as described below. As a Rails application is deployed, requests invoked, and undeployed, the following messages are printed on the console:

~/tools/glassfish/v3/9-18/glassfishv3 >./bin/asadmin run-script monitor-rails.js


 log> Deployed a 'rails' app named 'redmine-0.8.5' in 'development' environment with JRuby '1.3.0'.
 log> JRuby runtime pool started for the app 'redmine-0.8.5': active runtime - 1, queue size - 0
 log> Request started at '/redmine-0.8.5' hosted on 'localhost:8080'
 log> Request stopped at '/redmine-0.8.5' with status code '200'
 log> Request started at '/redmine-0.8.5' hosted on 'localhost:8080'
 log> Request stopped at '/redmine-0.8.5' with status code '200'
 log> Undeployed a 'rails' app named 'redmine-0.8.5' in 'development' environment.

Note "run-script" is the command that comes as part of the value-add. As described earlier, a snapshot of the monitoring information can be easily captured using asadmin as:

~/tools/glassfish/v3/9-18/glassfishv3 >./bin/asadmin get --monitor=true "\*jruby\*request\*"
server.containers.jruby.http.redmine-0.8.5.requestcount-count = 2
server.containers.jruby.http.redmine-0.8.5.requestcount-description = Number of HTTP requests received
server.containers.jruby.http.redmine-0.8.5.requestcount-lastsampletime = 1253638362651
server.containers.jruby.http.redmine-0.8.5.requestcount-name = RequestCounter
server.containers.jruby.http.redmine-0.8.5.requestcount-starttime = 1253638362651
server.containers.jruby.http.redmine-0.8.5.requestcount-unit = count
server.containers.jruby.http.redmine-0.8.5.requestpersecond = 1

Command get executed successfully.

As you can see, the total number of requests is shown as "2".

Just for fun, I ran Apache ab with 20 requests and 4 concurrency ("-n 20 -c 4") on "http://localhost:8080/redmine-0.8.5" and saw the following results:

Monitoring OFF
(default)
Monitoring=HIGH
(no data printed)
Monitoring=HIGH
(data printed)
Time taken for requests (secs) 26.231 26.997 26.665
Requests per second 0.76 0.74 0.75
Time per request (ms) 1311.574 1349.859 1333.239


The server was restarted between each run. These numbers were generated on my development machine so they are most likely skewed. But as a development benchmark the numbers do indicate that GlassFish v3 monitoring is truly non-intrusive. The total time taken for requests, requests/second, and time/request is pretty much identical.

Future blogs will cover how to access this data using web-based DTrace scripts, web-based Admin Console, jConsole, and REST interface.

A complete archive of all the tips is available here.

Technorati: totd glassfish v3 monitoring asadmin javascript jruby rails redmine

Thursday Sep 17, 2009

TOTD #104: Popular Ruby-on-Rails applications on GlassFish v3 – Redmine, Typo, Substruct

GlassFish v3 is opening up new frontiers by allowing to easily deploy Rails, Grails and Django applications, in addition to Java EE, without any additional packaging. You can even write a custom container to support new types of applications. Numerous entries on this blog have talked about how to deploy Rails applications on GlassFish v3. This Tip Of The Day (TOTD) will recap them and, once again, demonstrate how to easily get started with deploying some popular open source Rails applications on GlassFish v3.

Lets prepare a GlassFish v3 build for deploying Rails applications. This blog is going to use 9/16 nightly but you should pick the latest nightly or promoted.

  1. Unzip the downloaded bundle as:
    ~/tools/glassfish/v3/9-16 >unzip ~/Downloads/glassfish-v3-b64-09_16_2009.zip
  2. Configure JRuby/Rails in GlassFish v3 - JRuby/rails can be configured three different ways - use a previously installed JRuby/Rails directory, install JRuby/Rails module using the graphical Update Center or the "pkg" binary. This Update Center module comes packaged with JRuby 1.3.1, Rails 2.3.2 and some other useful gems. Pick the option you are most comfortable with and use it for your GlassFish installation.
    1. Configure previously installed JRuby/Rails directory as:
      ~/tools/glassfish/v3/9-16/glassfishv3/bin/asadmin create-jvm-options -Djruby.home=/Users/arungupta/tools/jruby
      Authentication failed with password from login store: /Users/arungupta/.asadminpass
      
      Enter admin password >
      created 1 option(s)
      Command create-jvm-options executed successfully.

      That's it!
    2. Install JRuby/Rails module using graphical Update Tool
      1. The graphical Update Tool tool can be invoked as:
        ~/tools/glassfish/v3/9-16/glassfishv3 >./bin/updatetool
        
        The software needed for this command (updatetool) is not installed.
        
        If you choose to install Update Tool, your system will be automatically
        configured to periodically check for software updates. If you would like
        to configure the tool to not check for updates, you can override the
        default behavior via the tool's Preferences facility.
        
        When this tool interacts with package repositories, some system information
        such as your system's IP address and operating system type and version
        is sent to the repository server. For more information please see:
        
        http://wiki.updatecenter.java.net/Wiki.jsp?page=UsageMetricsUC2
        
        Once installation is complete you may re-run this command.
        
        Would you like to install Update Tool now (y/n): y
        
        Proxy: Using system proxy settings.
        Install image: /Users/arungupta/tools/glassfish/v3/9-16/glassfishv3
        Installing pkg packages.
        Installing updatetool packages.
        Registering notifier: Already registered.
        Initialization complete.
        
        Software successfully installed. You may now re-run this command (updatetool).
      2. The first invocation of the command installs the Update Tool and the second invocation shows the following screen after "JRuby on GlassFish" module is selected:


        Click on green button in the top left to install the module and it picks up the dependencies as well as shown below:


        Click on "Install" to start the installation and click on "Accept" to accept the license.
      3. Close the Update Tool window once the installation is completed. The module creates "glassfish/jruby" directory.
    3. Install JRuby/Rails module using "pkg" binary
      1. Install the JRuby/Rails bits using the "pkg" binary. Invoke the command as:
        ~/tools/glassfish/v3/9-16/glassfishv3 >./bin/pkg

        The software needed for this command (pkg) is not installed. When this tool interacts with package repositories, some system information such as your system's IP address and operating system type and version is sent to the repository server. For more information please see: http://wiki.updatecenter.java.net/Wiki.jsp?page=UsageMetricsUC2 Once installation is complete you may re-run this command. Would you like to install this software now (y/n): y Proxy: Using system proxy settings. Install image: /Users/arungupta/tools/glassfish/v3/9-16/glassfishv3 Installing pkg packages. Initialization complete. Software successfully installed. You may now re-run this command (pkg).
      2. The command "pkg list -a" shows all the modules available for installation and the output looks like:

        ~/tools/glassfish/v3/9-16/glassfishv3 >./bin/pkg list -a
        NAME (PUBLISHER)                              VERSION         STATE      UFIX
        ant (contrib.glassfish.org)                   1.7.1-0.6       known      ----
        felix                                         2.0.0-0         installed  ----
        glassfish-appclient                           3.0-65          installed  ----
        glassfish-cmp                                 3.0-65          installed  ----
        
        . . .
        
        jersey-docs-and-examples                      1.1.2-1.0       known      ----
        jmaki (contrib.glassfish.org)                 1.8.1-2.0       known      ----
        jruby                                         1.3.1-1.1       known      ----
        jruby (contrib.glassfish.org)                 1.2.0-1.1       known      u---
        jruby-gems (contrib.glassfish.org)            2.3.2-1.1       known      ----
        jython-container (contrib.glassfish.org)      0.5.3-1.0       known      ----
        jython-runtime (contrib.glassfish.org)        2.5.0-1.0       known      ----
        metro                                         2.0-19          installed  ----
        
        . . .
        
        updatetool                                    2.3.0-36.2403   known      ----
        updatetool (contrib.glassfish.org)            2.2.2-30.2311   known      u---
        wxpython2.8-minimal                           2.8.10.1-36.2403 known      ----
        wxpython2.8-minimal (contrib.glassfish.org)   2.8.8-30.2311   known      u---
      3. Start the installation of "jruby" module as:

        ~/tools/glassfish/v3/9-17/glassfishv3 >./bin/pkg install jruby
        DOWNLOAD                                  PKGS       FILES    XFER (MB)
        Completed                                  2/2 14810/14810    37.0/37.0
        
        PHASE                                        ACTIONS
        Install Phase                            17273/17273
  3. Redmine on GlassFish - Redmine is an open source project management web application. The simplified steps to deploy Redmine on GlassFish v3 are given below (also on GlassFish Gem and on GlassFish v3 TP2):
    1. Download and unzip Redmine 0.8.5 (latest stable release).
    2. Change the database adapter from "mysql" to "jdbcmysql" as:

      sed s/'adapter: mysql'/'adapter: jdbcmysql'/ <config/database.yml.new >config/database.yml
    3. Create the database manually as "sudo mysqladmin create redmine_development". "db:create" fails because of JRUBY-3502.
    4. Migrate the database as "db:migrate".
    5. Deploy the application as:
      ~/samples/jruby/redmine >~/tools/glassfish/v3/9-16/glassfishv3/bin/asadmin deploy redmine-0.8.5
       Authentication failed with password from login store: /Users/arungupta/.asadminpass
      
      Enter admin password>
      Command deploy executed successfully.
    6. Here are some snapshots from the deployed application:





  4. Typo on GlassFish - Typo is the oldest Ruby on Rails blogware. The simplified steps to deploy Typo on GlassFish v3 are given below (also on GlassFish Prelude):
    1. Download and unzip Typo 5.3 (latest stable release).
    2. Change the database adapter from "mysql" to "jdbcmysql" as:

      sed s/'adapter: mysql'/'adapter: jdbcmysql'/ <config/database.yml.example >config/database.yml
    3. Create the database manually as "sudo mysqladmin create typo_dev". "db:create" fails because of JRUBY-3502.
    4. Typo runs using Rails 2.2.2 so lets install Rails 2.2.2 so lets install Rails 2.2.2 as:
      ~/samples/jruby/typo/typo-5.3 >~/tools/glassfish/v3/9-16/glassfishv3/glassfish/jruby/bin/jruby -S gem install rails -v 2.2.2
      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
      6 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 rails-2.2.2...
      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 rails-2.2.2...
    5. Migrate the database as "db:migrate".
    6. Deploy the application as:
      ~/samples/jruby/typo >~/tools/glassfish/v3/9-16/glassfishv3/bin/asadmin deploy typo-5.3
      Authentication failed with password from login store: /Users/arungupta/.asadminpass
      
      Enter admin password>
      Command deploy executed successfully.
    7. Here are are some snapshots from the deployed application:





  5. Substruct on GlassFish - Substruct is an open source E-Commerce project in Ruby-on-Rails. The simplified steps to deploy Substruct on GlassFish v3 are given below (also on GlassFish v3 Gem):
    1. Download and unzip substruct 1.0 a6 (latest stable release).
    2. Install the required gems as:
      ~/samples/jruby/substruct >~/tools/glassfish/v3/9-16/glassfishv3/glassfish/jruby/bin/jruby -S gem install RedCloth fastercsv mime-types mini_magick ezcrypto jruby-openssl --no-ri --no-rdoc
    3. Change the database adapter from "mysql" to "jdbcmysql" as:

      ~/samples/jruby/substruct/substruct_rel_1-0-a6>sed s/'adapter: mysql'/'adapter: jdbcmysql'/ <config/database.yml
      >config/database.yml.new
      ~/samples/jruby/substruct/substruct_rel_1-0-a6>mv config/database.yml.new config/database.yml
    4. Create the database manually as "sudo mysqladmin create substruct_development". "db:create" fails because of JRUBY-3502.
    5. Initialize the database as:
      ~/samples/jruby/substruct/substruct_rel_1-0-a6 >~/tools/glassfish/v3/9-16/glassfishv3/glassfish/jruby/bin/jruby -S rake substruct:db:bootstrap
    6. Deploy the application as:
      ~/samples/jruby/substruct >~/tools/glassfish/v3/9-16/glassfishv3/bin/asadmin deploy substruct_rel_1-0-a6
      Authentication failed with password from login store: /Users/arungupta/.asadminpass
      Enter admin password>
      
      Command deploy executed successfully.
    7. Here is a snapshot of the deployed application:

So we deployed Redmine, Typo, and Substruct using JRuby/Rails on GlassFish without any additional packaging. There are several Rails applications deployed in production on GlassFish.

What Rails applications are you deploying on GlassFish ?

Technorati: glassfish v3 rubyonrails jruby redmine typo mephisto substruct

Friday Mar 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 ?


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

JRuby 1.2, Rails 2.3GlassFish 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-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...

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

Sunday Mar 15, 2009

TOTD # 74: JRuby and GlassFish Integration Test #5: JRuby 1.2.0 RC2 + Rails 2.x.x + GlassFish + Redmine


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.
  1. Download Redmine 0.8 ...

    /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.
  2. Copy "config/database.yml.example" to "config/database.yml" and then generate/migrate the database:

    ~/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) ===========================

  3. Redmine is a Rails 2.1.x application so install Rails 2.1.x using JRuby 1.2 and run the application as:

    ~/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)

    Very simple and seamless!
The application is now accessible at "http://locahost:3000". The following screen dumps are captured by traversing through different parts of the application:















The next blog will show the last test in this series. The current set of tests are available using the tags rubyonrails+glassfish+integrationtest.

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 redmine integrationtest

Wednesday May 28, 2008

JRuby 1.1.2 released - Getting Started with v3 Gem


JRuby 1.1.2 was released yesterday - download here!

The highlights are:
  • Startup time drastically reduced
  • YAML symbol parsing >100x faster
  • Performance, threading, and stack depth improvements for method calls
  • Fixed several nested backref problems
  • Fixed bad data race (JRUBY-2483)
  • Gazillions of bigdecimal issues fixed
  • 95 issues resolved since JRuby 1.1.1
Getting started is really simple, just follow the steps listed below.

Unzip JRuby 1.1.2 zip bundle ...

~/testbed/ >unzip ~/Downloads/jruby-bin-1.1.2.zip
Archive:  /Users/arungupta/Downloads/jruby-bin-1.1.2.zip
   creating: jruby-1.1.2/
   creating: jruby-1.1.2/bin/
  inflating: jruby-1.1.2/bin/_jrubycleanup.bat 
  inflating: jruby-1.1.2/bin/_jrubyvars.bat 
  . . .
  inflating: jruby-1.1.2/share/ri/1.8/system/Zlib/crc_table-c.yaml 
  inflating: jruby-1.1.2/share/ri/1.8/system/Zlib/zlib_version-c.yaml 
  inflating: jruby-1.1.2/share/ri/1.8/system/created.rid 
  inflating: jruby-1.1.2/share/ri/1.8/system/fatal/cdesc-fatal.yaml 
~/testbed >

... and then install Rails and GlassFish v3 gem ...

~/testbed/jruby-1.1.2 >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
Bulk updating Gem source index for: http://gems.rubyforge.org/
Bulk updating Gem source index for: http://gems.rubyforge.org/
Successfully installed activesupport-2.0.2
Successfully installed activerecord-2.0.2
Successfully installed actionpack-2.0.2
Successfully installed actionmailer-2.0.2
Successfully installed activeresource-2.0.2
Successfully installed rails-2.0.2
Successfully installed glassfish-0.2.0-universal-java
6 gems installed

... and verify ...

~/testbed/jruby-1.1.2 >bin/jruby -S gem list g

\*\*\* LOCAL GEMS \*\*\*

glassfish (0.2.0)

... and now host any of your Rails application on v3 Gem (such as Redmine) ...

~/testbed/redmine >../jruby-1.1.2/bin/jruby -S glassfish_rails redmine-0.7
May 28, 2008 12:07:19 PM com.sun.enterprise.glassfish.bootstrap.ASMain main
INFO: Launching GlassFish on HK2 platform
May 28, 2008 12:07:19 PM com.sun.enterprise.glassfish.bootstrap.ASMainHK2 findDerbyClient
INFO: Cannot find javadb client jar file, jdbc driver not available
May 28, 2008 12:07:20 PM com.sun.enterprise.v3.services.impl.GrizzlyProxy start
INFO: Listening on port 3000
May 28, 2008 12:07:20 PM com.sun.enterprise.v3.services.impl.GrizzlyEmbeddedHttpConfigurator configureSSL
WARNING: pewebcontainer.all_ssl_protocols_disabled
May 28, 2008 12:07:20 PM com.sun.enterprise.v3.services.impl.GrizzlyEmbeddedHttpConfigurator configureSSL
WARNING: pewebcontainer.all_ssl_ciphers_disabled
May 28, 2008 12:07:20 PM com.sun.enterprise.v3.services.impl.GrizzlyProxy start
INFO: Listening on port 3131
May 28, 2008 12:07:20 PM com.sun.enterprise.v3.services.impl.GrizzlyProxy start
INFO: Listening on port 3838
May 28, 2008 12:07:21 PM com.sun.enterprise.v3.admin.adapter.AdminConsoleAdapter setContextRoot
INFO: Admin Console Adapter: context root: /admin
May 28, 2008 12:07:21 PM com.sun.enterprise.rails.RailsDeployer registerAdapter
INFO: Loading application redmine-0.7 at /
May 28, 2008 12:07:21 PM 
INFO: Starting Rails instances
May 28, 2008 12:07:26 PM 
SEVERE: JRuby limited openssl loaded. gem install jruby-openssl for full support.
http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
May 28, 2008 12:07:32 PM com.sun.grizzly.jruby.RubyObjectPool$1 run
INFO: Rails instance instantiation took : 11481ms
May 28, 2008 12:07:32 PM com.sun.enterprise.v3.server.AppServerStartup run
INFO: Glassfish v3 started in 12787 ms

Below is the screenshot from a previously deployed Redmine application, now on the GlassFish gem:



Simple isn't it ?

If your Rails application does not work on the gem, file bugs here with "jruby" as "subcomponent" (default version is "v3").

Alternatively, you can download GlassFish v3 TP2 and deploy your applications to leverage complete Java EE functionality.

You can also configure JRuby 1.1.2 as a Ruby platform in NetBeans 6.1 as described in TOTD #27.

Technorati: jruby ruby rubyonrails glassfish v3 gem redmine netbeans webtier

Thursday May 22, 2008

Redmine on GlassFish - Ruby-on-Rails Project Management Application



Redmine
is a flexible project management web application written using Ruby on Rails framework. The feature list is pretty comprehensive from the usual suspects like multiple projects, role-based control, forums/wikis/SCM for each project to enterprise level features such as LDAP-authentication and multiple languages. It is cross-platform and cross-database and deploys very nicely on GlassFish v3.

GlassFish v3 modularity and extensibility allows Rails applications to be deployed without any modification (no WARing). This blog explains the steps on how to deploy Redmine on GlassFish and shows some screenshots later. More documentation is available in Redmine Guide.
  1. Check out the most stable release of Redmine by giving the command:

    ~/testbed/redmine >svn co http://redmine.rubyforge.org/svn/branches/0.7-stable redmine-0.7
  2. Configure the database
    1. Start your MySQL server 

      ~/testbed/redmine >sudo mysqld_safe --user root
      Starting mysqld daemon with databases from /usr/local/mysql/data
    2. Create the database as:

      ~/testbed/redmine/redmine-0.7 >../jruby-1.1.1/bin/jruby -S rake db:create
      (in /Users/arungupta/testbed/redmine/redmine-0.7)
    3. Migrate the database as:

      ~/testbed/redmine/redmine-0.7 >../jruby-1.1.1/bin/jruby -S rake db:migrate
      (in /Users/arungupta/testbed/redmine/redmine-0.7)
      == 1 Setup: migrating =========================================================
      -- create_table("attachments", {:force=>true})
         -> 0.2840s
      -- create_table("auth_sources", {:force=>true})
         -> 0.0540s
      -- create_table("custom_fields", {:force=>true})
         -> 0.0430s
      -- create_table("custom_fields_projects", {:id=>false, :force=>true})
         -> 0.0080s
      -- create_table("custom_fields_trackers", {:id=>false, :force=>true})
         -> 0.0500s

      . . .

      == 90 ChangeVersionsNameLimit: migrating ======================================
      -- change_column(:versions, :name, :string, {:limit=>nil})
         -> 0.0220s
      == 90 ChangeVersionsNameLimit: migrated (0.0220s) =============================

      == 91 ChangeChangesetsRevisionToString: migrating =============================
      -- change_column(:changesets, :revision, :string, {:null=>false})
         -> 0.0210s
      == 91 ChangeChangesetsRevisionToString: migrated (0.0230s) ====================

      == 92 ChangeChangesFromRevisionToString: migrating ============================
      -- change_column(:changes, :from_revision, :string)
         -> 0.0130s
      == 92 ChangeChangesFromRevisionToString: migrated (0.0150s) ===================
  3. Download, Install and Configure GlassFish v3
    1. Download GlassFish v3 from here.
    2. Unzip the downloaded bundle.
    3. Add the following fragment as the last line in "glassfishv3-tp2/glassfish/config/asenv.conf" file:

      JRUBY_HOME="/Users/arungupta/testbed/redmine/jruby-1.1.1"
  4. Deploy Redmine as:

    ~/testbed/redmine >./glassfishv3-tp2/glassfish/bin/asadmin deploy redmine-0.7
    Command deploy executed successfully.

    ... and the GlassFish console shows:

    May 21, 2008 4:58:30 PM com.sun.enterprise.rails.RailsDeployer registerAdapter
    INFO: Loading application redmine-0.7 at /redmine-0.7
    May 21, 2008 4:58:30 PM 
    INFO: Starting Rails instances
    May 21, 2008 4:58:37 PM 
    SEVERE: JRuby limited openssl loaded. gem install jruby-openssl for full support.
    http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL
    May 21, 2008 4:58:42 PM com.sun.grizzly.jruby.RubyObjectPool$1 run
    INFO: Rails instance instantiation took : 11979ms
    May 21, 2008 4:58:42 PM com.sun.enterprise.v3.deployment.DeployCommand execute
    INFO: Deployment of redmine-0.7 done is 12091 ms
That's it, your application is ready to be used! Here are some screen snapshots from my trial run:


















Rails powered by the GlassFish Application Server provides all the good reasons on why you should consider using GlassFish instead of the traditional deployment models for Ruby-on-Rails applications.

This application is also covered in LAB 5539 as part of FREE 20-week Ruby-on-Rails course by Sang "with Passion" Shin.

Technorati: web2.0 rubyonrails jruby ruby glassfish redmine
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