In this article I explain how to set up Apache Stratos using Openstack/Docker as the underlying IaaS. This is the third article on a series of step by step series of articles(see  and ). In the previous articles I discussed how to set up the IaaS environment, that is Openstack Havana with Docker Driver. In this article I discuss how to build Tomcat cartridge for Stratos in Openstack/Docker, and then how to install Apache Stratos to use this Openstack/Docker set up as the IaaS.
This series is kind of a bottom-up approach rather than a top-down approach of the Apache Stratos Architecture. In the block diagram describing the architecture you can see that Apache Stratos can run it’s cartridges on many IaaS(concurrently or separately). The communication between Stratos and IaaS happen through jclouds API’s. jcloud support more than fifty IaaSs. So theoretically Apache Stratos can be made to support all the IaaSes supported by jclouds. We started from Openstack/Docker IaaS and first learnt how to make that IaaS ready for Stratos to work with it. Before going further here is a brief description of Stratos architecture focussed mainly on how cartridges connect with the main picture.
Apache Stratos is a fast growing open source PaaS where users can deploy their applications in various run time environments. A user in Stratos is a tenant or a tenant admin or a Stratos admin. First lets understand with following scenario. X company has selected Apache Startos as it’s private PaaS environment. The Stratos admin’s role is to set up Stratos and any IaaS environment used by Stratos. Setting up Stratos means installing it’s various middle-ware servers like Stratos Mananger, Stratos Controller and Stratos Auto Scaler. Then he need to setup IaaS, for example Openstack/Docker. Then he need to set up run time eivnronments in Stratos called Cartridges. Suppose X company has set of customers who need to use a web application deployed on Tomcat and there is a administrator managing this application. Then the customers are the tenants and the administrator is the tenant admin. The tenant admin subscribe to the Tomcat cartridge which is already created by Stratos admin. When he subscribes he provides a git repository url where he has his tomcat Web application uploaded. This user interface and tenant managing functionality is provided by Apache Stratos Manager server. When the tenants use this application, the scaling decisions are taken by Auto Scaler server. Communication between the underlying IaaS and Stratos PaaS is managed by Stratos Controller server.
What does it mean by Tomcat cartridge mentioned above? It is simply a cluster of Apache Stratos aware virtual machines running Tomcat web services engine usually fronted by a load balancer. This cluster runs in the underlying IaaS, in our case this is a cluster of Docker containers running in Openstack.
So how does the Stratos admin create Tomcat cartridge? It is just creating OS images installed with necessary software for Tomcat web server, for the underlying IaaSes on which the cartridge is supposed to run plus some configuration settings on the Stratos Controller. In our case this is equivalent to creating an Openstack/Docker image, uploading it to Openstack glance repository and setting tomcat cartridge configuration in Stratos Controller with image id information. This would be the scope of this article.
So what we do here is first create an Ubuntu OS Docker image with necessary software and configuration to run Tomcat web server, based on the Stratos base image we introduced in the previous article. Then we upload this image to Openstack glance repository and test it in Openstack environment. That will complete the IaaS part of our Tomcat cartridge. After this, I will explain how to complete the next step of introducing our Tomcat cartridge to Apache Stratos.
First we need to build Apache Stratos from source. For that I suggest you to have a separate Virtualbox VM node. The reason is that if you are a developer your development/testing environment(creating of which is the aim of this article series) has to be regularly updated with the latest code. So having a separate build machine is always good. Of course you can later integrate an automated build environment like Jenkins to your set up as well. But for now let’s do this way. Create such VM node and log into it.
Now we will build Stratos using Maven version 3. Before building set the followng Maven options. Otherwise out of memory errors could occur.
export MAVEN_OPTS="-Xmx1024m -XX:MaxPermSize=256m"
mvn clean install
This will build Stratos Server, Load balancer, cartridge agent and other artifacts which will be needed as we proceed. Note that the Stratos server here has the Stratos Controller, Stratos Manager and Stratos Autoscaler embedded into a single product. When run the server you decide to run manager, auto-scaler and controller together as a single server or run them as individual servers. You can find Startos server binary in incubator-stratos/products/stratos/modules/distribution/target/ folder.
Second we should install Puppet master into our Virtualbox VM node where Openstack/Docker run. I’ will explain why we need Puppet later. I suggest you to follow the Configure Puppet Master of the Apache Stratos documentation. In that documentation the
PUPPETMASTER-DOMAIN is given as test.org. In my set up I gave it as stratos.org. You have the choice of your own. Also see my changes to
$package_repo = 'http://192.168.57.30:8080'
#following directory is used to store binary packages
# Stratos message broker IP and port
# Stratos CEP IP and port
# Stratos Cartridge Agent’s trust store password
Since in our single node set up all servers run in the same node, we have both mb ip and cep ip the same value as our Virtualbox ip. If you use different version of Java update java_distribution and java_name accordingly.
For Stratos installation we also need a database. We already have a Mysql database in our Virtualbox VM created while installing Openstack.
Create Mysql database user. We will later need that user as the Mysql database user when configuring Stratos.
grant all privileges on *.* TO 'wso2'@'localhost' identified by 'g' with grant option;
grant all privileges on *.* TO 'wso2'@'%' identified by 'g' with grant option;
In the last article we created the Stratos base cartridge image using a base Dockerfile. Now we will create Tomcat cartridge Dockerfile using our previuos image as the base. Create a folder name tomcat and create this Dockerfile in it.
# VERSION 0.0.1
MAINTAINER Damitha Kumarage "email@example.com"
MAINTAINER Lakmal Warusawithana "firstname.lastname@example.org"
RUN apt-get install -q -y puppet
RUN apt-get install -q -y ruby
RUN mkdir /root/bin
ADD init.sh /root/bin/
ADD puppet.conf /etc/puppet/
RUN chmod +x /root/bin/init.sh
ADD stratos_sendinfo.rb /root/bin/
ENTRYPOINT /usr/local/bin/run_scripts.sh | /usr/sbin/sshd -D
See what are the additions we make here to the Dockerfile. Here From stratosbase means we make our previous image as base here. First we install Puppet. The reason for installing Puppet is that Puppet handle all stuff related to installing Java, Tomcat and Apache Stratos agent. In each cartridge there should be a Stratos agent to coordinate the cartridge instances with the Stratos Server. When the cartridge instance load, Puppet client will communicate with the Puppet Master to install software. Of course we can get rid of Puppet by doing all stuff related to installing Java, Tomcat and Stratos agent ourselves within the Dockerfile. If we do that we can reduce the load time of cartridges. However the real strength of Puppet is unavoidable in a production ready cartridge where we need to periodically update the cartridges with patches and maintenance code. Download init.sh, puppet.conf and stratos_sendinfo.rb from  and copy into the tomcat folder. Copy run_scripts.sh file from your previous stratosbase folder into tomcat folder as well. You need to add the following line as the last line to this run_scripts.sh file.
/root/bin/init.sh > /var/log/stratos_init.log
When above line is get executed when loading the cartridge, it will install and configure Stratos agent and necessary software into the cartridge.
Now you can build, tag and push the above image into glance repository by.
docker build -t tomcat .
docker tag tomcat 192.168.57.30:5042/tomcat
docker push 192.168.57.30:5042/tomcat
You will need the glance server image id of this image to register the cartridge in Stratos below. You can view it from Openstack dashboard ui or
Next step is to install Stratos server binary we built above. For that I recommend to follow the guide provided in link , which is easy enough to follow. Howerver pay special attention to following lines in stratos-installer/conf/setup.conf file to make sure they are in accordance to our setup. I have included a brief explanation of each change inline in different color
export host_user="wso2" This is our virtualbox vm os user we created in previous articles
export stratos_domain="stratos.org" This is the domain we choose for our Stratos setup.
export host_ip="192.168.57.30" Ip of the Virtualbox instance
export offset=2 When we have this offset https port of the Stratos server will be 9445
export ec2_provider_enabled=false Keep all other IaaS except Openstack disabled
export openstack_provider_enabled=true Enable Openstack IaaS
export openstack_identity="demo:demo" This is the default Openstack demo account
export openstack_credential="g" Password we provided for Openstack demo account(See devstack/localrc file)
export vcloud_provider_enabled=false Keep all other IaaS except Openstack disabled
In the setup.conf file we configure our Openstack IaaS access details as shown above. This is where we provide Stratos the knowledge about our IaaS.
Next we install load balancer. There are several ways you can configure a load balancer for Stratos. You can have a specific load balancer for a cartridge cluster or you can have a generic load balancer that will handle several cartridge clusters. In the former case we can configure load balancer as a cartridge in Stratos. But in our setup we will configure load balancer as a generic load balancer server.
Copy the load balancer zip file from incubator-stratos/products/load-balancer/modules/distribution/target/ to virtualbox vm’s /opt folder. Unarchive it and edit the following lines in repository/conf/load-balancer.conf
Also change repository/conf/templates/jndi.properties.template to following
That’s all for load balancer configuration. Open a new terminal to Virtualbox VM and start the load balancer by
We have installed Apache Stratos in the same Virtualbox VM, where we created our Tomcat cartridge image. Now we need to make our Stratos aware about our Tomcat cartridge image. Download autoscale-policy.jason, deployment-policy.jason, partition.jason and tomcat.json from .
Access the Stratos UI interface as Stratos admin user named admin by
The default password for Stratos admin user is admin.
Follow the wizard to deploy partion, autoscale policy, deployment policy and the tomcat cartridge. Just copy and paste the relevant content from the json files you downloaded. Remember to skip the load balancer configuration step as we are not installing the load balancer as a cartridge, but as a standalone server as explained above.
Also make sure you change the line
in tomcat.json file before copying the content. Here you give the id of the Stratos image you created above. You can see the Stratos server logs while doing the deployment by,
tail -f /opt/stratos/apache-stratos-default/repository/logs/wso2carbon.log
Now Startos administrator can create a tenant admin for Tomcat cartridge following the instructions in the Stratos admin ui. Then log in as that tenant administrator. Now you can see the Tomcat cartridge created above. Subscribe to it providing a valid git repository url. Make sure to copy a Tomcat sample.war file in that repository so that you can test your tomcat cartridge once it is active. Wait for some time and click your subscribed cartridge link to see whether there are active instances created for your cartridge. If so access your Tomcat sample application through provided urls there. You can also access the tomcat webpage directlry from the instance ip which you can view from the Openstack dashboard.
For more details on deploying and subscribing to cartridges using admin console see .
That’s all for your Startos setup using Openstack/Docker IaaS on a single Virtualbox VM. You will be able to use this set up as a development and Testing environment for Apache Stratos. Chris Snow has wonderfully automated the whole process I described in the three blogs(installing and configuring virtualbox, installing Openstack/Docker, installing Stratos and creating and testing cartridges) using vagrant boxes for both linux and windows and he has excellent blog post on it. So now it is just one command and you are off testing Stratos with Openstack/Docker IaaS.