Wednesday, August 31, 2011

How to build wso2 stratos 1.5.1 from the source

WSO2 Stratos is the most complete, enterprise-grade, open PaaS, with support for more core services than any other available PaaS today.
WSO2 Stratos provides the core cloud services and essential building blocks for example federated identity and single sign-on, data-as-a-service and messaging-as-a-service and more, required for developing SaaS and cloud applications.
Here below i will describe how to build stratos 1.5.1 from source.
You will find more information on wso2 stratos main page from this Link

Download stratos source from the hosted location
$ wget http://dist.wso2.org/products/stratos/1.5.1/wso2-stratos-1.5.1-src.zip

unzip content into some given location
unzip wso2-stratos-1.5.1-src.zip

go inside the extracted folder and start build it on line
stratos151src@sr2:~/stratos151src$mvn clean install

if it fails due to some reason(may be due to on line repo problems) follow the below guide lines.
In order to build carbon products we need to build axis2 first if that is not available at online repos

stratos151src@sr2:~/stratos151src/wso2-stratos-1.5.1-src/dependencies/axis2/1.6.1-wso2v1
Then build dependencies
And continue build in following order with given commands
stratos151src@sr2:~/stratos151src/wso2-stratos-1.5.1-src/dependencies$ mvn clean install

stratos151src@sr2:~/stratos151src/wso2-stratos-1.5.1-src/orbit$ mvn clean install -Dmaven.test.skip=true

stratos151src@sr2:~/stratos151src/wso2-stratos-1.5.1-src/service-stubs$ mvn clean install -Dmaven.test.skip=true
You must build carbon core with tests so use following command
stratos151src@sr2:~/stratos151src/wso2-stratos-1.5.1-src/core$ mvn clean install

Before build components we have to little change for stratos pom.xml file. Due to the error in pom file location of
org.wso2.carbon.tenant.dispatcher folder.

So lets see how we can do that modification
Go to stratos folder as follows
stratos151src@sr2:~/stratos151src/wso2-stratos-1.5.1-src/components/stratos$ vi pom.xml

Do the following change
replace line
org.wso2.carbon.tenant.dispatcher/3.2.0
with
org.wso2.carbon.tenant.dispatcher/1.5.1

Then build components
stratos151src@sr2:~/stratos151src/wso2-stratos-1.5.1-src/components$mvn clean install

Then we have to build features
stratos151src@sr2:~/stratos151src/wso2-stratos-1.5.1-src/features$mvn clean install

Then we have to build products and services
stratos151src@sr2:~/stratos151src/wso2-stratos-1.5.1-src/products$ ls
as  bam  bps  brs  carbon  cep  css  dss  esb  greg  gs  is  lb  manager  mb  ms  pom.xml  wsf

here you will see available products inside products folder
if you need to build appserver product and service use the following command. same way you can do this for other products as well

stratos151src@sr2:~/stratos151src/wso2-stratos-1.5.1-src/products/as/4.1.1$mvn clean install
Then built packs will be available on following location
stratos151src@sr2:~/stratos151src/wso2-stratos-1.5.1-src/products/as/4.1.1/modules/distribution/service/target






Usage metering and throttling in cloud computing - introduction for Users/Developers


Here in this post i will describe how to use usage metering and throttling in cloud environment. For this post i will use WSO2 stratos which is a complete Platform-as-a-Service for private and public clouds. Lets see how we do usage metering and throttling in stratos.
What is WSO2 Stratos ?
WSO2 Stratos is a complete SOA and developer platform offered as a self-service, multi-tenant, elastic runtime for private and public cloud infrastructures. What that means is that our complete SOA platform - now enhanced with Tomcat and Webapp support - is available as a  "cloud native" runtime that you can either use on the Web (yes - you can try it out right now), on Amazon VPC, or on your own internal private cloud based on Ubuntu Enterprise Cloud, Eucalyptus and (coming soon) vmWare vSphere. It is a complete Platform-as-a-Service for private and public clouds.
Download stratos source and more documents available at http://wso2.org/library/stratos
Post on how to build stratos 1.5.1 source available at
http://sanjeewamalalgoda.blogspot.com/2011/08/how-to-build-wso2-stratos-151-from.html
Sign up for a free account at  stratos private cloud https://stratoslive.wso2.com
What is Tenant ?
In stratos we used term tenant. What is tenant? it’s like an organization (sanjeewa.com) and it may few users (like departments within organization). There is administrator for each tenant and others are users. Administrator can allow users to use services and he is the person who governs the entire system for tenant. See following diagram for understanding tenant.
Tenant
Figure: Tenant and its users
Why we need Usage and Throttling ?
WSO2 stratos throttling component is the only one tomcat server based throttling module. And WSO2 Stratos 1.5.1 provides many new features like metering throttling and billing. So with WSO2 Stratos you will be able to measure, throttle and bill the server usage. Its really important to have reliable billing/ throttling model for cooperate service providers. Stratos 1.5.1 provides complete solution for web services with pricing model. So we will look at this usage and throttling model in detail. So this process has 2 main actions.
1. Before user perform some action we will check whether he is allow to do it or not(Ex adding new service/ service invocation).
2. After performing some action we keep it record (sanjeewa.com tenant used 100kb service Bandwidrh)
See following diagram for overview of usage and throttling.
sss
Figure : Usage And Throttling Overview


Usage Agent
Usage agent is responsible for measure parameters and publishes them into Business Activity monitor server(Where we store data and monitor). for each and every tenants agent measure some important parameters related to their usage of bandwidth and resources(Service/webApp bandwidth, Registry usage, User count). This usage metering process use some advanced listening technologies to avoid slows down or blocks entire process.
As an example let say some web service hosted by sanjeewa.com try to invoke by some client so this invocation takes 100kb service bandwidth. So we will store this entry this tenant(sanjeewa.com) got service bandwidth of 100kb at this time
Usage Summery generator
Summery generator component responsible for summarize captured data. And after collecting raw data we do sorting and summarization periodically and store those records in database. Those records are available per hourly, monthly, daily, quarterly and annually.
As example after hour we will put above 100kb entry to hourly table. Then at the end of the day it will go to daily table with corresponding day of month.
Throttling Manager
Throttling is used to avoid excess usage of resources and bandwidth. Throttling manager periodically check the usage records(The data captured by above mentioned usage agent) available and evaluate throttling rules and define set of actions for each and every tenant. These actions are contain what tenants can do what cannot do what are the error messages that we have to show them. Those rules are written in drools. Drools is a business rule management system (BRMS) with a forward chaining inference based rules engine, more correctly known as a production rule system, using an enhanced implementation of the Rete algorithm. Using a rules engine can lower an application's maintenance and extensibility costs by reducing the complexity of components that implement complex business logic. So inside WSO2 stratos throttling component is use drools for throttling configurations and provide user interface to change rules in easier way. After evaluating Throttling rules for each tenant we will store the validation information(What tenant allow to do and what should block) in registry with tenant ID
Example :Throttling manager check the monthly data available in monthly service bandwidth table and check the Drool correspond to that tenant(Drool specify the service bandwidth allow to this user and actions when limit exceeding). If that user didn’t exceed limit it will put entry to registry saying sanjeewa.com is allow to service invocation else it will put entry saying not allowed.
Throttling Agent
Throttling agent is acting as a supervising agent who check the actions taken by users. Basically this will check registry entry for given tenant (Put by throttling manager). To achieve higher performance throttling agent use in memory implementation. It will take copy of registry entries and keep it cached. So reading validation information from cache is much faster than reading registry.
As an example When some tenant/users try to invoke web service this agent check the corresponding registry entry for user weather he is allow to do this or not. If he can do agent will allow to do it otherwise it will prompt message to user saying the issue.


Throttling in a cloud computing environment


Introduction

Cloud computing is becoming more and more popular in the IT world these days. Cloud solutions providers come up with a lot of cloud implementations. People try out these cloud platforms and people who are convinced, start using the cloud in their enterprises too. Cloud vendors are concerned about their cloud’s smooth functionality and high up time. They have to keep an eye one how users are consuming the cloud resources. Throttling is the solution for controlling how users are allowed to consume the cloud resources. In the rest of this article, you will find out more on throttling and how to use the throttling functionality available in WSO2 StratosLive, 
the complete Open PaaS.

Content

What is throttling

When it comes to computing terminology, the word "throttling" simply means "controlling". Throttling can be seen in action in different situations. For example,

  • On a LAN, the network admin may throttle the bandwidth to control network congestion and server crashes.
  • An ISP may throttle the bandwidth for some users to control their usage above a certain limit.
  • CPU throttling is used to conserve power or reduce the heat generation.
Why throttling is important in cloud computing
When hosting a cloud, you have to be aware of the multi-tenant aspect, which can cause problems in consuming cloud resources. A large number of users may be using the cloud environment in different ways. If your cloud is a PaaS, they will be hosting services or web applications. If it is SaaS, they’ll be using your software. If it is an IaaS, they'll be running VM instances in your infrastructure.

In any of the above scenarios, if a user is consuming too much of your resources, it can cause problems to the entire cloud environment. Either you have to control the user's behaviour or you have to scale up your resources and charge the user for consuming resources. If you decide to scale up and charge, it is always good to have a control mechanism.

Another advantage of throttling is, you can use it to support your billing system. For example, if you charge based on subscriptions and you want to restrict the users consuming resources not allowed by their subscription, then, throttling is the answer for you.


What can be throttled

In a cloud environment, there are several parameters which can be throttled.
  • Network bandwidth
  • Storage
  • CPU usage
  • I/O operations
Lets see how throttling is used by a real cloud environment. I am considering WSO2 StratosLive, the complete, 100% Open Source PaaS from WSO2, to describe how throttling is used.

Throttling in WSO2 StratosLive 

WSO2 StratosLive presents the complete middleware platform from WSO2 known as “Carbon” in the cloud. Users can create tenants and use the StratosLive cloud environment. It uses throttling to ensure the users only consume resources which are allowed to them according to the usage plan they subscribe to. It throttles following parameters.


  • Webapp bandwidth - Tenants can host webapps in WSO2 Application Server. When requests are received and responses are sent, it is checked whether the tenant has permission to consume the bandwidth. If not, i.e. tenant has already consumed the allocated bandwidth, the request will be rejected.
  • Service bandwidth - Same as webapp bandwidth. This applies to the services hosted in StratosLive.
  • Registry bandwidth - This is considered when registry items are accessed by tenants. When a get/put operations is carried out in the registry, a certain bandwidth is consumed. It also undergoes throttling.
  • Registry storage - Tenants are allowed to store artifacts in the registry. But to control the storage consumed, it is throttled.
  • Number of users per tenant - When a tenant is created, tenant admin can add users to the tenant. This can be throttled if needed.
Above mentioned throttling is done based on monthly usage data of tenants. Not only that, there are throttling rules. These rules can be changed on the fly, making WSO2 StratosLive's throttling capabilities very powerful. 

How to configure throttling using WSO2 StratosLive
Next, let us take a look at how to set up WSO2 StratosLive with throttling. We mainly focus on setup and fine-tuning parameters for throttling and usage metering. First, you need to understand few terms.

Throttling Manager – Manage, evaluate what users can and cannot do based on their subscription plans and their current usage. 


Throttling Agent – This component detects user actions and allows or blocks it based on the validation information generated by throttling manager

Usage Plan- There are 4 types of usage plans available at WSO2 StratosLive. According to usage plan, users will allow different volume of resources and service usage. (Demo/SMB/Professional/Enterprise). You can find more information on usage plans of WSO2 StratosLive from here.  

We have to configure few things before it works properly.

1. How often throttling manager executes. Throttling manager periodically evaluates the tenants usage of resources (Service/webApp bandwidth, Registry usage, User count) and check it with their maximum allowed limit. After that process, it stores this validation data on registry. Here we can configure when to start this evaluation process and how often we do this by editing the configuration file, throttling-config.xml. It is assumed that you have setup Stratos correctly in your environment. Then go to  manager/repository/conf folder. There you will see throttling-config.xml file and that file has following entries.

interval parameter is there to specify the time frequency (in minutes) of executing throttling manager. According to this configuration, it executes rules every 60 minutes. That means, Configuration Manager detects any excess usage of resources within one hour. After each 60 minutes, it calls Data services, gets current usage of each tenant and updates their actions (What they are allowed to do or not)

delay parameter is there to define when to start first rule execution. According to this configuration, server runs the first throttling rule execution 15 minutes after the server started.

15 and 60 minutes are recommended values. But if you need much more accuracy you can reduce that interval value (But its advisable to use some value more than 3 minutes; else it causes performance drop). Also, remember that reducing this time always causes higher CPU Usage. If you don't need to run throttling manager you can disable it by setting a negative value for interval parameter. If you plan to run a manager instance without throttling you can use this configuration.
2. How other Services allow Throttling Manager usage. In order to  use throttling manager by services, we have to modify configuration in each and every service that we use (Appserver/ IS/ BAM/ DSS etc..). Those services need to access throttling manager at WSO2 Stratos Manager. In that case we have to modify throttling-agent-config.xml file, which has following content.

managerServiceUrl – is the URL that manager runs on - Manager services URL. You will see this URL when manager starts up at terminal. It is set to local host by default.

userName - Here we have to specify Stratos Manager server super admin user name (By default it is admin)

password – Specify Stratos Manager server super admin password (By default this will be admin)

This configuration is used by other services to invoke the throttling rules at manager. For example, when we add new user, the identity server will call throttling manager and invoke throttling rules for the respective tenant.  Otherwise within one hour of throttling, rule execution time tenant user may add any number of users. To avoid such misuses we use this technique.
3. How to write throttling rules. For each usage plan we have to specify the upper limit of resource and service usage. If any user tries to go beyond that limit, throttling agent will stop that action immediately. For example, if Demo account is allowed to add 1 users we have to specify it in throttling rules. You will see throttling-rules.drl file inside manager/repository/conf.
At first, manager takes rules from that file and stores it in registry. Only super admin user for Stratos manager is allowed to change throttling rules. If you logged in as super Admin you will see the throttling menu. By clicking it you can see the throttling rules editor window where you can write rules.

How to configure throttling in Cloud Environment using WSO2 Stratos – Users Guide


Here in this post i hope to discuss how to set up wso2 Stratos with throttling. In this post i will mainly focus on how to setup and fine tuning parameters for throttling and usage metering. If you need more information on usage metering and throttling see my previous post from here. First you need to understand few terms.If you need to understand more on throttling on Cloud environment please refer the this post on Amila Maharachchi’s Blog 
Throttling Manager – Manage, Evaluate what users can do and cannot do based on their subscription plans and their current usage.
Throttling Agent – This component detects user actions and allow them to do it or block it based on the Validation information generated by throttling manager
Usage Plan- There 4 types of usage plans available at WSO2 services. According to usage plan users will allow different volume of resources and service usage.(Demo/SMB/Professional/Enterprise). You will see more information on usage plans available at WSO2 StratosLive from here.
So we have to configure few things in order to work properly
01. How often throttling manager executes. Throttling manager periodically evaluates the tenants usage of resources(Service/webApp bandwidth, Registry usage, User count) and check it with their maximum allowed limit. After that process it store this validation data on registry. Here we can configure when start this evaluation process and how often we do this. To configure this we have to change configuration file( throttling-config.xml ). Before that you have to set up WSO2 Stratos properly(Manager/ IS/ any other services). Then go to inside of manager/repository/conf folder. There you will see throttling-config.xml file and that file has following entries.
<parameters>
<parameter name="interval">60</parameter>
<!--minutes = If This set to negative(-) value then throttling manager excecution will disable-->
<parameter name="delay">15</parameter>
</parameters>
interval parameter is there to specify the time frequency(in minutes) of executing throttling manager.According to this configuration it says execute rules after 60 minutes. With this configuration Manager will detect any excess usage of resources within one hour. after each 60 minutes It will call Data services and get current usage of each and every tenant and updating their actions(What they are allow to do or what they are not allowed)
delay parameter is there to define when to start first rule execution.According to this configuration server will run first throttling rule execution after 15 minutes time of server started.
15 minutes and 60 minutes are recommended values. But if you need much more accuracy you can reduce that interval value(But its advisable use some value more than 3 minutes otherwise it will causes to performance drop). And also remember reducing this time always causes to higher CPU Usage. If you don't need to run throttling manager you can disable it by setting negative value for  interval parameter. If you plan to run manager instance without throttling you can use this configuration.
02. How other Services allow to use Throttling manager. In order to  use throttling manager by services we have to modify configuration in each and every services that we use(Appserver/ IS/ BAM/ DSS etc..). Those services need to access throttling manager at WSO2 Stratos Manager. In that case we have to modify throttling-agent-config.xml file. That file has following content.
<throttlingAgentConfig xmlns="http://wso2.com/carbon/multitenancy/throttling/agent/config">
<parameters>
<parametername="managerServiceUrl">https://cloud-test.wso2.com/services/</parameter>
<parameter name="userName">admin</parameter>
<parameter name="password">admin</parameter>
</parameters>
</throttlingAgentConfig>
managerServiceUrl – is the URL of manager running on. Manager services URL. you will see this URL when manager starts up at terminal. by default this will set to local host.
userName – Here we have to specify Stratos Manager server super admin user name (By default it will be admin)
password – Here we have to specify Stratos Manager server super admin password (By default this will be admin)
This configuration is used by other services except manager to run the throttling rules at manager. As an example when we try to add new user identity server will call manager throttling manager to report new user adding. Otherwise within one hour of throttling rule execution time tenant user may add any number of users. To avoid such misuses we use this technique.
03. How to write throttling rules. For each usage plans we have to specify the upper limit of resource and service usage. And then if any user try to go beyond that limit throttling agent will stop that action immediately. As example if Demo account is allow to add 1 users we have to specify it in throttling rules. You will see throttling-rules.drl file inside manager/repository/conf. At first time manager takes rules from that file and store it in registry. Only super admin user for stratos manager allow to change throttling rules. If you logged in as super Admin you will see throttling menu. by clicking it you will see throttling rules editor window where you can write rules. There is other blog post on how to write throttling rules if you are interested please refer it .