|
|
|||||||||||||||||||||||||||||||||||||||||||||
Vivek Pandey's Blog
Run Django applications on GlassFish v3 PreviewPosted by vivekp on June 05, 2009 at 09:41 AM | Permalink | Comments (0)GlassFish v3 Preview is available and I am excited to announce support for Django applications. Django is a Python based framework, probably anyone hosting their applications on GAE might know Django is a Python based web framework. GlassFish-Scripting project provides implementation of Jython Container. Just like JRuby Container, Jython Container does the following:
Here is how you can run a Jython application on GlassFish v3 Preview. Install GlassFish v3 PreviewFollow the directions from here to install GlassFish v3 Preview.Install Jython Container on GlassFish v3 Preview
$ cd /tools/glassfishv3
Below is the GlassFish v3 Update Tool image. Select GlassFish v3 Jython Container and click Install. This would install Jython Container OSGi module and Grizzly adapter jars inside glassfish/modules directory.
Install JythonTo run your Django application, at the minimum you need Jython 2.5 release. Get Jython 2.5 RC3 from here. Once downloaded, run the installer by doing the following:
$ java -jar jython_installer-2.5rc3.jar
Follow the installer direction and after it is installed, add jython command to your path
$ export JYTHON_HOME=/path/to/jython-install
should display jython interpreter shell ![]() Install DjangoGet Django 1.0.2 from here.
$ tar xzvf Django-1.0.2-final.tar.gz
Follow the detailed instruction here. Create a sample Django application
$ django-admin.py startproject mysite
Start GlassFish v3 Preview
$ asadmin start-domain -v
Above /tools/jython is where I installed jython. jython.home system property tells Jython container in GlassFish v3, where to find jython container. Deploy the application
$ cd mysite
Now access http://localhost:8080/mysite and it should show the first Django page:
Enable Django adminDjango framework comes with a built in administration utility and we will enable it in this sample. The admin application needs a database. So first we would need to setup the database.Install PostgreSQLDownload and install PostgreSQL database server. Make sure it is running.Once installed, make sure it is running. You would also need to download and install PostgreSQL JDBC driver inside jython installation.
$ cd /tools/jython
Above /tools/jython is where I have installed jython. Install django-jythonYou would need JDBC drivers for the database backends. So you would need to install django-jython on your Jython installation. django-jython is a Google Code project that has JDBC database backend for PostgreSQL only. There is SQLite3 experimantal version and no MySQL as of now.Download the latest django-jython from here. Then install it on Jython.
$ tar zxvf django-jython-1.0b1.tar.gz
See further details on setting up backend here. Create database$ createdb mysiteRefer to details on how to go about creating database in PostgreSQL incase you encounter problem. We will use mysite database in our Django application. Configure DatabaseEdit settings.py and change the database configuration. For example these are my entries:
DATABASE_ENGINE = 'doj.backends.zxjdbc.postgresql'
Above, doj.backends.zxjdbc.postgresql is the name of the PostgreSQL JDBC driver, the database name is mysite and then the username and password. HOST and PORT values are empty meaning the default will be taken. It is time to sync the DB. So first make the PostgreSQL JDBC driver available to jython classpath so that the following syncdb command works:
$ export CLASSPATH=/tools/jython/postgresql-8.3-604.jdbc4.jar:$CLASSPATH
NOTE: postgresql-8.3-604.jdbc4.jar was downloaded and installed inside jython directory installation earlier. Enable admin appEdit settings.py and add 'django.contrib.admin' under INSTALLED_APPS.
INSTALLED_APPS = (Edit urls.py and uncomment all the lines that contains admin. Make sure you do not have space at the beginning on a line. ![]() Now you would need to redeploy the application so that you can access the admin application. But before we do that, we need to make the stylesheets available to the Jython container.
$ asadmin deploy --property
jython.mediaRoot=/tools/jython/Lib/site-packages/django/contrib/admin/
--force=true .
There is a bug in Jython container and this would not work so as a work around copy the admin media files to the GlassFish v3 domain1 docroot. $ cp -r
/tools/jython/Lib/site-packages/django/contrib/admin/media
/tools/glassfishv3/glassfish/domains/domain1/docroot/
Note: If you deploy your application at context root '/' then the above work around to make admin media files will not be needed. Now access : http://localhost:8080/mysite/admin, it should show: ![]() After you login, the admin console would let you manage users/groups. ![]() To summarise
A note about the Ruby application support, GlassFish v3 Preview release improves on the Ruby application support. Now the Ruby application deployment support is Rack based. Just like WSGI, Rack is a Ruby standard to wire a web server to a Ruby web framework. The Ruby web frameworks supported out of the box are: Rails, Merb and Sinatra. Try it out by running on GlassFish v3 Preview and send us feedback at GlassFish mailing list. Slides for Dynamic Language on GlassFish technical sessionPosted by vivekp on June 04, 2009 at 04:26 PM | Permalink | Comments (0)The slides for my JavaOne technical session: Dynamic Languages Powered by Glassfish are available here. GlassFish gem 0.9.5 available nowPosted by vivekp on June 04, 2009 at 04:16 PM | Permalink | Comments (0)I guess was too busy with JavaOne to announce the release of GlassFish gem 0.9.5. This release is based on GlassFish v3 Kernel from GlassFish v3 Preview. This release also has few critical fixes related to logging and an improvement in logging where you would be able to log the message on cosole using -l
option without a log file name.See the changes in this release and follow the documentation for installation and getting started. As always send your feedback to the forum and report any issues here. Plug-in any Ruby/Rack based framework to GlassFishPosted by vivekp on April 03, 2009 at 10:33 PM | Permalink | Comments (0)GlassFish gem as well as GlassFish v3 supports Rack. Rack provides an interface to plugin a Ruby web framework with a web sever. Similar to Python WSGI. This means that any ruby based framework that can talk Rack can be simply deployed on GlassFish. Here is how you can do it on GlassFish gem: Insall JRubyInstall JRuby from here. Setup JRUBY_HOME to the install location and add JRUBY_HOME/bin to your PATH.Install GlassFish gem$ gem install glassfish
Now, lets write a trivial app and save it in file: myapp.rb class MyAppWrite a rack-up script and save it in myframework.ru
That is pretty much your sample Ruby application and the Rack-up script to run on GlassFish. Above require 'rack/handler/grizzly' makes Grizzly handler available to Rack. To run it, simply run glassfish in side the directory where myapp.rb and myframework.ru are placed.
Now access, http://localhost:3000 in your browser to access your app.
If you are running GlassFish v3 server and want to deploy this app, you would simply use the same asadmin command from inside the application directory:
GlassFish gem as well as GlassFish v3 server can auto-detect Rails,
Merb and Sinatra applications. You can use the above mentioned
technique to plugin other frameworks. For reference also see Jacob's blog
where he explains how Sintra application is plugged in to GlassFish.New features in GlassFish 0.9.3 gemPosted by vivekp on March 16, 2009 at 11:09 AM | Permalink | Comments (0)I am happy to announce much awaited release of GlassFish gem ver 0.9.3. This release has many critical improvements and bug fixes. Here are the highlight of new features: ![]() Daemon modeGlassFish gem is started by JRuby, which starts a JVM in which GlassFish runs. In daemon mode, GlassFish forks itself with the optimal JVM settings as a daemon process and writes out the process id in to a file. The default filename is tmp/pids/glassfish-<PID>.pid. To stop GlassFish gem server, you would send it SIGINT. This process id file is automatically deleted when server is stopped using SIGINT. This will enable kill and bounce of GlassFish gem server.You can override the name and location of the PID file using -P or --pid option. At any time if you want to clean up zombie PID files, simply run the following rake task inside your app directory: [~/dev/depot]$ jruby rake tmp:pids:clear The daemon mode is made possible by using Akuma, which is another very useful library from Kohsuke. I am very interested in experimenting with the Network Server feature and see how it can help us create GlassFish gem cluster. ![]() During daemonization, during fork, daemon logs are written in log/glassfish-daemon.log file. Here, the time stamp, name of the PID file and other informations are recorded. This file is appended with the each new daemon instance. Rest of the server log goes in to usual logging file. Daemon mode will enable Capistrano style deployment for GlassFish gem. Jacob is going to start working on the Capistrano recipe for GlassFish gem as well. GlassFish rake taskA new rake task, gfrake is introduced in this release. It basically would let you create a template configuration file (see below about what it is) and clean up glassfish generated temporary files.
ConfigurationAt times, specially in production you would like to define the configuration information in a static file instead of wrapping CLI options in another script. Now you can do so by creating a glassfish.yml file in the config directory. To create it run gfrake config inside your application directory. By default, GlassFish gem looks for glassfish.yml inside the config directory. You can override it by passing your own using --config option.glassfish.yml contain not only CLI but other options as well. For example, you can define the JVM options with which GlassFish should start in daemon mode. This would be useful to tune the JVM to get optimal performance for your given hardware resources. ![]() Please note that this is the first version of configuration file and in latter releases will include more options. Although we will be very careful about not breaking backward compatibility but if it happens, such decisions will be taken judiciously and communicated. sudo not needed any moreThis is really not a feature rather a bug fix. GlassFish gem is based on the GlassFish v3 kernel. A fundamental aspect of GlassFish v3 server is that it runs an instance to serve a domain and the domain by default is located inside the GlassFish gem install location. This is a real problem for those who install GlassFish gem in a root privilege location. When trying to run glassfish with user privilege would fail as glassfish would detect that it can not write in the root privilege location. This has been reported by many users.The real fix is in GlassFish v3 where such error reporting are deffered and since there is no write in case of gem, such deffered checks will not cause failures for gem. In the mean time, GlassFish gem has a temporary solution, on startup it creates a temporary domain inside tmp/.glasfish of your application directory. Improved loggingUnlike previous versions of gem logging is not displayed on the console. On startup, GlassFish gem displays basic information and the logging goes to log/development.log or whatever your environment is. For example, if you are running the app in production, logs will go to log/production.log.You can override where logging should go using -l or --log option. [~/dev/depot]$ glassfish -l mylog.log You can easily control the log level using --log-level option. The various log levels are: ![]() Improved error reportingThere have been many improvements in the error detection, reporting. For example, instead of reporting port is busy after server starts, the check will happen early on, various validation improvements etc. This is a continuing work and with every release we will improve on anything that can make it easier to diagnose and help fix the problems.Support for Sinatra and framework auto-detectionBeside Rails and Merb Sinatra is supported as well. GlassFish supports any Rack based framework. To run your framework of choice simply place the rackup script (.ru) inside your application directory or set JVM property -Djruby.applicationType=/path/to/myframework.ru and GlassFish will plugin your script automatially. Save the code below in a .rb file and simply run glassfish in that directory and access your RESTful service at http://localhost:3000/.
Server busy handlingIn prior releases, when GlassFish gem is busy loading the application, a new request will give 404 HTTP error. This causes problems when you front-end Glassfish gem with some LoadBalancer, as it would treat 404 as client error and would not know what to do with it. This is fixed. Now, when GlassFish gem is busy loading application and a new request arrives, it will give a 503 (Server Unavailable) and a 'Loading application..." page and the load balancer will know not to route to that server while the 503 is in effect.Check out README and start using GlassFish gem and send your feedback to the forum and report any issues at the issue tracker. |
June 2009
Search this blog:CategoriesCommunity: GlassfishCommunity: Java Enterprise Community: Java Web Services and XML Extreme Programming J2EE JavaOne Web Applications Web Services and XML Archives
June 2009 Recent EntriesRun Django applications on GlassFish v3 Preview Slides for Dynamic Language on GlassFish technical session GlassFish gem 0.9.5 available now | ||||||||||||||||||||||||||||||||||||||||||||
|
|