Sunday, April 7, 2013

Play Framework 2.x on Windows Azure

Today I am going about setting up a Play Framework 2.1 Scala based project on Windows Azure.

First, signup for a free 90 day windows azure account at https://account.windowsazure.com/signup?offer=ms-azr-0018p

Second setup eclipse with the windows azure deployment plugin.  Use eclipse's Install New Software and enter http://dl.msopentech.com/eclipse for the url.  If you don't have azure sdk 1.8 installed it will be automatically installed when you select new Windows Azure Deployment project in eclipse.  It may take a while as the .Net framework 4.0 will be installed also.  A guide is available at http://msdn.microsoft.com/en-us/library/windowsazure/hh694271.aspx.

Third, setup new azure deployment project in eclipse.  I downloaded publish settings from my azure account and saved locally, then pointed the eclipse plugin to it.  A project was setup with a sample war file, various deployment scripts.  Once deployed, the cloud service was setup on azure automatically and the application deployed.  The first deployment is taking a while so we'll see if it finished.  Presumably the app will be available at http://playtest.cloudapp.net/

Unfortunately the deployment never finished.  I was however able to goto the manage azure portal and upload the deployment.  It asks for 2 things the "package" and the "configuration".  Both of these are found in the deploy directory of the azure deployment project (WindowsAzurePackage.cspkg and ServiceConfiguration.cscfg respectively).  Select them and click the check mark to begin the upload.  After a while (~ 20 minites) the application finish uploading and begin deployment.  Once that's complete you can access the app.  My example is at http://tomcattest2.cloudapp.net/HelloWorld/

Now, looking that the WorkerRole1 directory, I noticed the artifacts are in there -- jdk, tomcat war file.  So what if instead of a war file I have a play dist zip?  And further, what if the start.cmd didn't run catcline_home/startup.cmd but ran a java command to run the play app.  So I created new play app (play new play2Test) and then created a dist (play dist).  Then in the WorkerRole1\approot\start.cmd I added

start java -cp ".\play2test-1.0-SNAPSHOT\lib\*" play.core.server.NettyServer .

where play2test-1.0-SNAPSHOT is the dist of my empty play app.

Lastly, I updated the worker role components - right click the worker role and select properties/components.  I removed HelloWorld.war file and added my dist.  Told the worker to unzip it in the approot directory so that my java command above would find all the jars and run the app.  I tested locally using the azure emulator and it worked.  I also changed the endpoints to map port 80 to port 9000 the default netty port for play apps.






Then I began the deploy to cloud step which rebuilds the deployment for cloud instead of local and stopped it after the build was complete and the deployment had begun.  Then went to azure management portal and manually uploaded.  With any luck the app will be available at http://play2test.cloudapp.net/.


Saturday, January 19, 2013

Play Framework 2.1 and Scala

After a bit of a wobbly start to the day, I finally got my brain activated and started plotting my next technical adventure.  I've been experimenting most recently with javascript frameworks like angularjs.  I found angular pretty good to work with, once I got over the initial learning curve.  MVC, Dependency injection, testable javascript, all good!  Unfortunately I didn't really realize the hoped for benefit of device specific rendering.  It seems to me that the nodejs server renders html to send to the browser, just like any other framework like grails, spring, jsf and play.  I enjoyed my experiences with Play 1.24 a year ago or so, and thought it would be nice to upgrade and work with scala instead of java.  Turns out, Play makes a good on ramp for scala experimentation.  Here's what I've done so far:

First things first, get play framework from http://playframework.org/.  I downloaded and unzipped the most current (2.1.RC2) and setup my machines path statement (Windows).  From there, I could follow the tutorial at http://playframework.org/documentation/2.1-RC2/ScalaTodoList.

I originally used my eclipse 3.7 JEE for editing after having run "play eclipse" on the todolist project.  Later I found the scala ide plugin for eclipse juno and downloaded and installed them from http://www.eclipse.org/downloads/ and http://scala-ide.org/download/milestone.html respectively.

I added twitter bootstrap to the tutorial app and pushed everything to my github account at https://github.com/sbasinge/todolist.

Now I am really ready to get rolling, but first I need to review the sample apps, in particular the comet and websocket based apps.  I think it would be interesting to create a online card game of some sort that uses comet or websocket for pushing cards, others actions, results, etc.

I'll let that stew for a while.  In the meantime, have a great time experimenting on your own -- and remember it's not as hard to do something, as it is to get started!