Está en la página 1de 70

JBoss Rails & JBoss in the Cloud

Bob McWhirter
JBoss Middleware, a division of Red Hat, Inc.

1
JBoss-Rails

2
Agenda for JBoss-Rails
‣ Background on Ruby on Rails
‣ Rationale for JBoss-Rails
‣ HOWTO JBoss-Rails
‣ JBoss-Rails Microcontainer Deployer
‣ Web deployment
‣ Meta-data
‣ Parsing
‣ Structure

3
Ruby on Rails
Background

‣ Built upon the Ruby language.


‣ Full Model-View-Controller support:
‣ Easy embedded-Ruby templates (erb).
‣ ActiveRecord for ORM.

‣ REST support baked right in.


‣ Fast code/test cycle.

4
Ruby on Rails
Downsides

‣ Traditional C-Ruby (aka “MRI”) not the most


performant.
‣ Until recently, not thread-safe.
‣ Each request-handling processor was a new
interpreter. Run packs of mongrels.

‣ Supports purely a web-view of the world.


‣ Primarily a UNIX environment.

5
JBoss-Rails
Why?

‣ Rails is ultimately just yet-another


application model & framework, if you
ignore the bit about Ruby.
‣ Still maps to functionality we’re used to in
the Java EE world.
‣ JRuby provides a conformant & performant
Java-hosted Ruby interpreter.

6
JBoss-Rails
Really, why?

‣ I love writing applications using Ruby and


Rails.
‣ But it’s sometimes a true pain:
‣ Lots of moving parts (httpd, mongrel, cron, etc).
‣ No baked-in support for non-web processing, such
as batch jobs, asynchronous message-handling, or
timers.

7
JBoss-Rails
Why JBoss is The Answer

‣ JBoss technologies provide enterprise-


grade infrastructure:
‣ Web Container
‣ Messaging
‣ Caching
‣ Clustering

8
JBoss-Rails
Why JBoss is The Answer

‣ JBoss technologies provides an end-to-end


deployment stack:
‣ AS5 For the processing and handling.
‣ mod_cluster for front-end proxying and clustering.

‣ JBoss is happy to support Windows


developers.

9
JBoss-Rails
It’s just a deployer

‣ To enable AS5 to deploy Ruby-on-Rails


applications, you simply copy a new
deployer into your server’s deployers/
directory. It’s about 12 MB.

cp -R jboss-rails.deployer/ $JBOSS_HOME/server/all/deployers/

10
JBoss-Rails Deployer
Microcontainer

‣ A little bit later we’ll dive into how the


deployer is put together

11
JBoss-Rails
Preparing your RoR app
‣ Your Rails application needs to have Rails
“vendorized”.
‣ Rails itself should be in your source-tree under
vendor/rails/**

‣ Your Rails application needs to have Gems


it uses “vendorized”
‣ Ensure each gem is also installed underneath
vendor/plugins/**

12
JBoss-Rails
Preparing your RoR app

Really, that’s just a “best practice”


regardless of your Ruby environment.

13
JBoss-Rails
Preparing your RoR app

‣ Optionally, for ease, install the jboss-rails-


plugin into your app using git.
cd vendor/plugins
git clone git@github.com:bobmcwhirter/jboss-rails-plugin.git

‣ The plugin provides Rake and Capistrano


tasks to ease usage of JBoss-Rails.

14
JBoss-Rails Plugin
Setup JDBC

‣ JBoss-Rails uses JDBC instead of Ruby DB


drivers.
‣ The plugin can easily check your
database.yml configuration and set up
your project for JDBC:

rake jboss:rails:jdbc:install

15
JBoss-Rails
Preparing your RoR app

‣ Once you’ve vendorized Rails, your Gems,


and installed the JDBC drivers using the
plugin...

16
JBoss-Rails
Deploying your app

‣ The simplest way to deploy is using the


rake tasks provided by the jboss-rails-plugin

rake jboss:rails:deploy

17
JBoss-Rails
Deploying your app
‣ It’ll seek out $JBOSS_HOME/server/default,
and drop a JBoss-Rails deployment
descriptor into the deploy/ directory.
‣ AS5 doesn’t even have to be running.
‣ The RAILS_ROOT of your application is the
live deployment:
‣ Editing of views & controllers will be reflected
immediately.

18
JBoss-Rails
Deployment descriptor
‣ The deployment descriptor is just a YAML
file acting as a symlink with meta-data to
replace web.xml:
deploy/myapp-rails.yml

---
application:
RAILS_ENV: development
RAILS_ROOT: /Users/bob/oddthesis
web:
context: /

19
JBoss-Rails
Deployment descriptor
‣ The context allows you to host multiple
apps, even alongside traditional WARs.
‣ An optional host is allowed for virtual-host
binding within AS5.
deploy/myapp-rails.yml

web:
host: api.mycorp.com
context: /api-v2

20
Your Rails App on JBoss
‣ Surf to your server’s normal web-listening
port, at the host and context specified...

21
Your other apps on JBoss
‣ And your other contexts work, too:

22
JBoss-Rails Internals
Microcontainer Pieces

‣ We’ll walk backwards through the deployer:


‣ It ends with a running an accessible application.
‣ In the middle, we tickle Tomcat.
‣ It starts with noticing there’s a Rails app needing
deployment.

23
Deploying a Web App
AS5 knows how to do that

‣ The deployer knows it’s running within AS5,


which means there’s a Servlet container
(Tomcat) available to it.
‣ No reason to start another webserver

‣ Luckily, using a ServletFilter from


JRuby-Rack, we can hook a Rails app in
as a Java web application.

24
Deploying a Web App
AS5 knows how to do that

‣ Configure a regular web-app for Tomcat, but


instead of reading a web.xml, just set up the
configuration programatically. A web.xml for
a Rails app is just boiler-plate anyhow.
‣ Mix in RAILS_ROOT for the ServletFilter.

‣ Mix in the context and host configuration.

25
How do we know RAILS_ROOT?
RailsApplicationMetaData & RackWebMetaData

‣ The RAILS_ROOT for the deploying


application is handed to us through a
RailsMetaData object during deployment.
‣ The RailsApplicationMetaData is
associated with a RackWebMetaData.
‣ It is the RWMD’s mere existence is what
drives this portion of the deployment.

26
MetaData comes from where?
Anywhere, really

‣ These MetaData objects can be deployed


from anywhere. You can create and deploy
them programmatically, even. They aren’t
very magic.
‣ They’re just a Java object model embodying
configuration information.

27
One source of metadata
Parsing deployers!

‣ While MetaData can be created a multitude


of ways, ParsingDeployers can create
them from files.
‣ Files such as...
‣ web.xml

‣ persistence.xml
‣ myapp-rails.yml

28
Rails parsing deployers
Files into MetaData

‣ The myapp-rails.yml is read.


‣ A RailsApplicationMetaData object is
created and associated with the deployment.
‣ Includes RAILS_ROOT
‣ Includes RAILS_ENV

‣ A RackWebMetaData object is created and also


associated with the deployment.
‣ Includes host
‣ Includes context

29
Symlink or Archive deployment
If you don’t use myapp-rails.yml

‣ You can also drop a symlink or archive of


your app into deploy/ and provide
configuration in your app’s config/
directory.
‣ config/jboss-rails-env.yml

‣ config/jboss-web.yml

30
Meta-data files
Knowing where to look

Rails apps have


a familiar and
recognizable
structure.

31
Structure Deployers
Telling Microcontainer where to look

‣ Humans can recognize the structure of a


Rails application.
‣ Structure deployers recognize the “shape”
as a Rails app, too.
‣ And knows config/ holds a lot of important
configuration type of files.
‣ Tells Microcontainer to “look in there”.

32
Deployer Review
Start-to-End

‣ Rails structure deployer recognizes RoR


app.
‣ Parsing deployers poke around config/
and create *MetaData objects.
‣ Other deployers consume *MetaData
objects and set up Tomcat, Quartz, etc.

33
Other Ruby/Rails Deployers
Quartz Scheduler

‣ Cron-like recurring scheduled tasks are


useful.
‣ Another deployer looks for
jboss-scheduler.yml.
‣ Creates ScheduleMetaData.
‣ Which is consumed and deployed as Ruby-
backed tasks into AS5’s Quartz scheduler.

34
Other Ruby/Rails Deployers
Future

‣ Deployment of Ruby-backed Message-


Driven Beans (MDBs).
‣ Deployment of Ruby-defined Drools rules.

35
JBoss-Rails Questions
Please hold your questions until the end

‣ Questions about JBoss-Rails will be


answered at the end of this presentation...

36
JBoss-Cloud

37
Agenda for JBoss-Cloud
‣ What’s “the cloud?”
‣ JBoss-Cloud project
‣ Thincrust Appliances
‣ Challenges working in the cloud
‣ Multicast
‣ DHCP
‣ Other configuration
‣ Launch JBoss in the cloud
‣ Future Work

38
What does “The Cloud” mean?
Virtualization

‣ “The Cloud” means OS-level hardware


virtualization.
‣ Amazon EC2
‣ VMWare
‣ KVM
‣ Xen

39
What does “The Cloud” mean?
Not grids

‣ Google’s AppEngine
‣ Sun’s GridEngine

40
Why the cloud?
Red Hat synergy

‣ Virtualization makes clustering convenient.


‣ Virtualization makes scaling easier.
‣ Red Hat has excellent tooling for creating
cloud server images.
‣ Will lead to push-button deployment from
development to production clusters.

41
JBoss-Cloud
Project

‣ The JBoss-Cloud project is tooling to


produce cloud-ready server images.
‣ Based on the Red Hat Thincrust project which...
‣ Uses Kickstart files to stitch together...
‣ Bundles of RPMs
‣ Can target many virtualization hosts:
‣ VMWare
‣ EC2
‣ KVM

42
JBoss-Cloud
Thincrust Appliances

‣ JBoss-Cloud, using Thincrust tooling,


creates consistent specialized server
images, known as “appliances”.
‣ JGroups Appliance (for GossipRouter)
‣ JBoss-AS5 Appliance (including JBoss-Rails)
‣ Apache/mod_cluster Appliance (web front-end)
‣ PostGIS Appliance (enterprise-grade database)

43
JBoss-Cloud
Fedora Remix

‣ Based upon Fedora 10 Yum repositories.


‣ Includes “just enough” packages.
‣ Plus appliance-specific packages

44
Cloud Considerations
Some things work differently

‣ Few cloud environments have multicast


enabled, affecting cluster formation.
‣ Most cloud environments boot images using
DHCP, affecting node locating.
‣ Cluster servers are homogenous, and
ideally require no manual configuration.

45
Cloud Workarounds
Not problems, just challenges
‣ Instead of relying upon multicast for cluster
discovery and formation, fire up a
GossipRouter.
‣ Use Puppet to handle reconfiguration, such
as adjusting the bind IP based upon the
DHCP-assigned address.
‣ Inject any custom configuration using cloud
out-of-band boot-data facilities.

46
Gossip in the Cloud
Overcoming lack of multicast

‣ When multicast can’t be used, JGroups


provides a GossipRouter as a rendezvous.
‣ Each cluster node is told about the
GossipRouter at boot.
‣ Nodes discover each other through the
central router.
‣ A JGroups appliance can cohabitate with
other appliances.

47
Dynamic Reconfiguration
Using Puppet

‣ The core Thincrust tooling provides


facilities to run Puppet scripts at boot.
‣ These scripts can introspect the state of the
server, and adjust configurations AS5
launches.
‣ They can also use cloud boot-data facilities
for additional configuration:
‣ Web-proxy and GossipRouter addresses

48
Dynamic Reconfiguration
Puppet in action

‣ For instance, script determines the


machine’s current IP address and sets the
following in /etc/jboss-as5.conf:
JBOSS_IP=192.168.237.174
‣ It also queries the boot meta-data and sets
in the same file:
JBOSS_GOSSIP_HOST=192.168.237.173
JBOSS_PROXY_LIST=192.168.237.173:80

49
/etc/init.d/jboss-as5
Configuration and booting

‣ The /etc/init.d/jboss-as5 script


reads /etc/jboss-as5.conf, and sets the
appropriate Java properties.
‣ JBoss AS5 fires up fully-configured, ready
to form a cluster with other nodes.

50
Clustering becomes easy
Boot and go

‣ To build a cluster then...


‣ boot one JGroups+WebProxy appliance.
‣ boot one-or-more JBoss AS5 appliances with the
address of the first appliance as boot meta-data.

51
Web Proxies
JBoss mod_cluster

‣ Apache httpd and mod_proxy_ajp are good


stuff.
‣ But keeping worker lists correctly configured in
an every-changing, DHCP-booted environment
is not fun.
‣ JBoss mod_cluster uses the JGroups cluster
view to maintain the worker list.
‣ mod_cluster works with stock Fedora apache-
httpd

52
JBoss mod_cluster
Reversing the relationship

‣ Instead of having to explicitly tell the httpd


process about each worker, simply tell the
worker nodes about the httpd server.

‣ That’s JBOSS_PROXY_LIST in the


configuration.

‣ Nodes ping httpd, on the regularly-listening


port, and tell it about themselves.

53
JBoss mod_cluster
If you have multicast

‣ If you have multicast, you can avoid even


dealing with JBOSS_PROXY_LIST.

‣ mod_cluster can advertise itself over


multicast to the nodes for completely
automatic discovery and configuration.

‣ JBoss-Cloud assumes no multicast, though.

54
JBoss VM2
Slight Tangent
‣ Before we actually walk through using
JBoss-Cloud images, we need to pick a
virtualization environment.
‣ I’m using VMWare Fusion on an Apple
MacBook Pro.
‣ Instead of using the GUI, I use JBoss VM2,
a layer to allow VMWare to work somewhat
like Amazon EC2.

55
JBoss VM2
Images and Instances

‣ Like EC2, you register image bundles with


VM2.
$ vm2 register front-end-appliance.tgz
registering front-end-appliance as vmi-ac731d2449

‣ You can then spin up multiple instances


from the same image.
$ vm2 run-instances vmi-ac731d2449

56
Front-End Appliance
Launch your first machine

‣ The front-end-appliance contains

‣ JGroups GossipRouter

‣ Apache httpd with JBoss mod_cluster

‣ Launch 1 instance:
$ vm2 run-instances vmi-ac731d2449

57
Write a cluster.conf

‣ Discover the front-end-appliance instance


IP address:
$ vm2 describe-instances
Instance ID VMI State IP Address
------------------------------------------------------
i-672cc0e853 vmi-ac731d2449 RUNNING 192.168.237.173

‣ Create a cluster.conf boot data file


JBOSS_PROXY_LIST=192.168.237.173:80
JBOSS_GOSSIP_HOST=192.168.237.173

58
Boot up AS5 nodes
Build your cluster
‣ Launch an AS5 appliance with the
cluster.conf as boot meta-data:
$ vm2 run-instances vmi-42c8ee3ea4 -f cluster.conf

‣ Confirm everything is running:


$ vm2 describe-instances

Instance ID VMI Name State IP Address


------------------------------------------------------------------------------
i-672cc0e853 vmi-ac731d2449 front-end-appliance RUNNING 192.168.237.173
i-90030665a9 vmi-42c8ee3ea4 jboss-as5-appliance RUNNING 192.168.237.174
------------------------------------------------------------------------------

59
Confirm!
Fire up that browser
‣ Surf to the front-end box. Notice the IP
address reported by the JMX console
compared to the location bar:

60
Do it again
Launch more AS5 nodes

‣ Keep launching AS5 appliances with the


same cluster.conf.

‣ They’ll join the cluster and link up with the


web proxy front-ends.

61
Deploy your App
Get code on the servers

‣ Currently, it’s up to you to rsync/scp/uucp


your application into the cluster nodes
deploy/ directories, where it should hot-
deploy.

‣ Soon JON/JOPR will support AS5, and help


with multi-node cluster deployment of apps.

62
Future Work
Actual EC2 Support

‣ Adjustment of the Puppet recipes to handle


the way EC2 provides boot meta-data.

‣ Convert all current appliance images to


EC2’s bundle format.

63
Future Work
JBoss Cloud-Control project

‣ Cloud-Control will ease management of


cluster.conf files and control the booting
and management of server instances.
‣ Abstract cluster topology definitions will mix
with applications and cloud credentials:
$ cloud-control new-cluster \
--topology small-cluster.yml \
--target ec2 \
--deploy myapp.war

64
Resources
JBoss-Rails & JBoss-Cloud

65
OddThesis.org
Where it all goes down

OddThesis.org is the
primary project site
for both JBoss-Rails
and JBoss-Cloud.

66
GitHub.com
Where the source lives

We use git for


revision control.

The repositories
are hosted at
GitHub.com

‣ http://github.com/bobmcwhirter/jboss-rails
‣ http://github.com/bobmcwhirter/jboss-rails-plugin
‣ http://github.com/bobmcwhirter/jboss-cloud
‣ http://github.com/bobmcwhirter/vm2

67
irc.freenode.net
Where the developers chat

Chat with the


developers on
IRC.

‣ irc://irc.freenode.net/jboss-rails
‣ irc://irc.freenode.net/jboss-cloud

68
Projects Mentioned
Project I use, but didn’t write

‣ JRuby-Rack (Rails-Servlet integration)


‣ http://github.com/nicksieger/jruby-rack/tree/master
‣ Red Hat Thincrust (appliance creation)
‣ http://thincrust.net/
‣ Puppet (dynamic reconfiguration)
‣ http://reductivelabs.com/projects/puppet/
‣ JBoss Microcontainer (JBoss AS5 kernel)
‣ http://jboss.org/jbossmc
‣ JBoss mod_cluster (Web proxying)
‣ http://jboss.org/mod_cluster

69
Thanks
Pause, thank crowd, exit.

Thanks for paying attention.

http://creativecommons.org/licenses/by-sa/3.0/us/

70

También podría gustarte