Sunday, February 17, 2013

How to Run Jaggery.js App in Heroku Cloud

Jaggery.js is a server  side javascript framework for writing front-end ,communication ,server side logic and persistence in pure javascript.I felt that there
is no public cloud hosting service available for hosting jaggery apps for free(Other than stratoslive.wso2.com).So i have attempted to run a jaggery server on famous platform as a service Heroku.In this post i am going to describe how to run a jaggery app on Heroku.

Pre-request for running apps in Heroku cloud.

1.The app should be written in supported languages(Ruby, Node.js, Clojure, Java, Python, and Scala).
2.All the java apps should be pushed to git as Maven project  
3.Heroku only allow apps to open port that is given by a system variable PORT.
4.App should bind to the port within 60s.
5.App should not store anything to file for long term persistence.
6.Data base details will be given by a system variable DATABASE_URL.
etc...


So the challenge is to make the Jaggery server to obey above rules.

Jaggery server is actually a WSO2 carbon server.Which is actually a java app.so it should run in Heroku.To run a WSO2 Carbon app we have to set the JAVA_HOME.
But in Heroku during application launch java will be added to system path but JAVA_HOME will not be set .I have added following to WSO2 Carbon startup script to set the JAVA_HOME .

export JAVA_HOME=$(which java |xargs  readlink -f  | sed "s:bin/java::");
echo "Setting JAVA_HOME to $JAVA_HOME "

 Next thing is, i have to create a Maven project that should build a Jaggery server and copy Jaggery app into deployment folder.There are no Jaggery server dependency that i can get it as a zip file.But fortunately all the required dependencies for building a Jaggery server from a Carbon server are available.
I was able to create a Maven project that can build a jaggery server form carbon server.
The usual way of running java apps in Heroku, is specifying the launch command in Procfile.Procfile for the above Maven project looks like following

web: sh server/heroku-run/jaggery-1.0-SNAPSHOT/bin/server.sh

This means the Maven project has to unzip the built Jaggery server into heroku-run folder of server Maven module.

Now the a Maven project is ready that can build a Jaggery server and has a Procfile to launch the Jaggery server.But in order to start the server  I have to make sure that the Jaggery server opens only one port.
Jaggery server will open altogether 6 ports by default.Following are the ports and how i disable those ports.

1.http/https:These ports are opened by tomcat connectors.I need to make sure only one port to be opened.so i disabled the https connector in JAGGERY_HOME/carbon/repository/conf/tomcat/catalina-server.xml

2.jmx(2 ports):There is a configuration to not to start the jmx server.The file name is CARBON_HOME/repository/conf/etc/jmx.xml

3.Zookeeper server(opens one port):To disable Zookeeper  there should be a property(start_zk_server=false) in /carbon/repository/conf/etc/zoo.cfg

4.jmx remote (opened by tomcat):To disable this -Dcom.sun.management.jmxremote
should not be set.

Finally the port number in tomcat connector has to be set to the port number in PORT system variable provided by Heroku.All the configuration files in jaggery server can accept java system variable in the form of ${SYSTEM_VARIABLE}.To set that system variable we have to pass -DSYSTEM_VARIABLLE=value in start up script.In this way the value in PORT system variable can be passed to tomcat connector configuration.

The same way the information in DATABASE_URL(database url,username,password and database name) system variable should be passed to JAGGERY_HOME/carbon/repository/conf/datasources/master-datasources.xml.

The Maven project can be found in Github here
https://github.com/ajanthan/heroku-jaggeryjs-app-runner

Follows are steps to run your Jaggary app in Heroku.

0.Register in https://heroku.com and install Heroku tool
1.git clone http://github.com/ajanthan/heroku-jaggeryjs-app-runner.git
2.heroku create
3.heroku addons:add heroku-postgresql:dev
4.heroku config
5.heroku pg:promote HEROKU_POSTGRESQL_RED_URL
6.Insall postgresql (https://devcenter.heroku.com/articles/heroku-postgresql#local-setup)
apt-get install postgresql
7.heroku pg:psql
\i /home/heroku-jaggeryjs-app-runner/dbscript/postgresql.sql
8.add your Jaggery app to apps/ROOT directory
9.git add .
10.git commit -m "adding initial project"
11.git push  heroku master
12.heroku logs -t
Access my app here http://ajanthan.herokuapp.com/


Friday, February 15, 2013

WSO2 App Factory Preview

Yesterday WSO2 announced the public preview of WSO2 App Factory  beta on their annual conference WSO2Con 2013.You can access App Factory  here


In order to login to the App Factory you have to be a registered user in WSO2 Oxygen Tank.If you are still not a registered user,click get started button it will direct you to


After success full login you can create new application.

Each Application creation will create a git repository for you with skeleton Maven project.Edit the Maven project to include your changes and push to git repository.App Factory will build your project and deploy to development cloud using Jenkins.
Press goto buid server button in build tab to go to App FactoryJenkins CI.


Use same username and password to login into Jenkins CI.


To manually tricker a build use build button in builds page.


Observe notification panel to know the build status if you do not want to go to Jenkins.

Go to repository tab to create new versions of application.



Manage your application versions through various stage in governance tab.


Download logs of your applications in various stages(dev,test,staging and prod) in same tab.


Invite new users to other registered users through user administration tab


Manage your issues in Redmine.


Create new databases and associate those with data sources in configure resource tab.


Subscribe to APIs or create new APIs using WSO2 API Manager and use those in your application.


Create new properties as a resource in WSO2 Governance registry and use that in your application.

Note that in all case you will get complete isolation between resources across different stages.
Play with preview and report any issues or new features in https://wso2.org/jira/browse/APPFAC