Apache Stratos – Persistent mapping (adding a hard drive to your service instance)

Posted: April 21, 2014 in wso2
Tags: , , , , , ,
Use case 

Adding persistent volume is very much similar to adding a virtual hard drive to your instance. In Amazon EC2 it is adding a EBS storage device to the instance. Please refer to [1] for more details. Persistence volume capability comes handy when you want to store your content in a separate place and make the data available even after the instance is terminated or deleted. MySQL, MongoDB are examples where you may need this capability.

Below are the steps you need to perform to enable persistent volume mapping capability.

 Cartridge Definition

You need to add a similar configuration to the cartridge definition. Please note that the persistent is an optional configuration which user specify if he wants additional volumes to store his content.
 “persistence”: {
        “isRequired”: true,
        “volume” : [
            “device”: “/dev/sdc”,
            “mappingPath”: “/home/ubuntu/sdc”,
            “size”: “10”,
            “removeOnTermination”: “false”
Here I say I want an extra volumes to store my content. Linux device of the first volume should be /dev/sdc which will be mounted to the directory /home/ubuntu/sdc. The capacity of the volume should be 10GB. removeOnTermination parameter specify what should be done to the volume created after the termination of the instance. if removeOnTermination=false the volume and its data will exist even after the volume is terminated so data is not deleted.
Subscribe with persistent volumes
Just by adding to the cartridge definition does not provide volumes for the instances. We have to specify we require volumes at the time of subscribing.

Subscribing via CLI

You have to add below highlighted parameters when subscribing by Stratos CLI.
subscribe-cartridge <other-parameters> -pv <PERSISTENCE-VOLUME> -v <VOLUME-SIZE> -t <REMOVE-ON-TERMINATION>
PERSISTENCE-VOLUME>= true/false.  true if you need the feature
VOLUME-SIZE = size (in Giga Bytes) of the storage needed
REMOVE-ON-TERMINATION = true/false whether to delete the volume when the instance is terminated.
Subscribing via Stratos UI
               If you are subscribing with the Stratos Ui, there is tick as “Require Persistent Storage mappings” on the “subscribe to cartridge” page. Please tick it and provide required details.
Subscribe with Persistent mapping

Subscribe with Persistent mapping

Multiple persistent volumes

Stratos provides the capability to specify multiple persistent volumes in case you require more that one additional volume.
 “persistent”: {
        “isRequired”: true,
        “volume” : [
            “device”: “/dev/sdc”,
            “mappingPath”: “/home/ubuntu/sdc”,
            “size”: “10”,
            “removeOnTermination”: “false”
            “device”: “/dev/sdf”,
            “mappingPath”: “/home/ubuntu/sdf”,
            “size”: “20”,
            “removeOnTermination”: “false”
Note that don’t specify the same mappingPath to multiple volumes. Then it will be mapped to the last volume which can not be predicted, other volumes will not be mapped to a directory.

What happens behind the scene.

If you subscribe with persistent mappings, Stratos will,
1 Create the volumes.
2 Format and create a writable file system (ext3)
3 Mount volumes to the directory specified as mappingPath
Please note that the formatting and creating a file system happens at the first time only. Next time when the volume is attaching to another instance (after first instance is terminated), it is no longer needed to create a file system since file system is already there.

 How to verify if the volumes are created.

Log in to the instance created by ssh and execute the command “df -h”. You will see a output similar to below.
df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/xvdc        10G  7.1G   97G  3% /home/ubuntu/sdc
/dev/sda1       4000G  40G   320G  10% /home
In most IAASes such as EC2 one volume can be attached to only one instance. So if your deployment policy has maxInstance count more than 1, you might encounter problems when Stratos tries to attach the the volume to the second instance.
This has tested only in EC2, need to be tested in other IAASes as well.


Currently size parameter is mandatory at the time of subscription. But in ideal case the size specified in cartridge definition should be considered as the default if the size is not given at the time of subscription.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s