Automatic scaling of virtual system pattern instances in IBM PureApplication System

A technique to create a Virtual System Pattern Scaling Manager pattern type

A virtual system pattern is an IBM® PureApplication™ System deployment model that defines the cloud workload as a topology of middleware images. The virtual system pattern model supports only static scaling of virtual system pattern instance nodes. This article explains how to build a virtual application pattern that can implement automatic scaling of the virtual system pattern instance nodes. This technique leverages the virtual application pattern policy, the monitoring framework, and the Virtual System Pattern Clone API.

Bhadri Madapusi, Advisory Software Developer, IBM

Photo of Bhadri Madapusi Bhadri Madapusi is a Software Developer and currently focused on IBM PureApplication System pattern type development. Bhadri has over 10 years of software development experience. Previously, he worked on cloud computing, Business Process Management, and WebSphere Commerce.



Valentina Birsan, Senior Software Developer, IBM

Photo of Valentina BirsanValentina Birsan is a Senior Developer in WebSphere and currently focused on IBM PureApplication System pattern type development. Previously, Valentina was a technical lead for Rational Application Developer. She was one of the initial members of the Eclipse TPTP open source project, and served as the chair of the Test and Performance Tools Project Architecture Group. Valentina was also the lead architect for the Cosmos Service Modeling Eclipse open source project and a member of the Service Management Language open standard.



09 October 2013

Also available in Chinese Japanese Spanish

Introduction

A virtual system pattern (VSP) model defines a cloud workload as a topology of middleware images. The VSP middleware workload topology can have one or more virtual images, which are known as parts. Each part in the workload model can be configured for static scaling. At deployment time, IBM Pure Application System (hereafter called PureApplication System) creates a VSP instance composed of a number of virtual machines (VSP instance VM nodes) based on the scaling settings on the part. The VSP model does not support automatic scaling based on the scaling policy.

Abbreviations

  • VSP: virtual system pattern
  • VAP: virtual application pattern
  • VM: virtual machine

This article explains how you can build a virtual application pattern (VAP) pattern type that acts as a scaling manager to dynamically add and remove VSP instance VM nodes based on the user defined policy. This article assumes that you know how to use the VAP Plug-in Development Toolkit (VAP PDK) to build a VAP pattern type and plug-ins, and that you are familiar with the VAP scaling framework. For more information about the VAP scaling framework, see Scalability and elasticity for virtual application patterns in IBM PureApplication System.


Create a VAP pattern type to auto-scale VSP instances

The following sections explain how to create the "VSP Scaling Manager" VAP pattern type. This VAP pattern type acts as a manager and drives the auto scaling of VSP instance VM nodes. This technique leverages the VAP monitoring and policy framework and the VSP Clone API. Building this pattern type involves the following steps:

  1. Create VAP application model metadata to capture VSP instance details.
  2. Create a policy object to define a scaling policy.
  3. Create a topology template to convert the application model to the topology document.
  4. Create monitoring metamodel and monitoring scripts to monitor the VSP instance.
  5. Create a VSP instance of the VM nodes scaling scripts.

Use case

In this article, we will use the WebSphere cluster VSP as the target VSP for auto scaling. As shown in Figure 1, the WebSphere cluster VSP consists of a deployment manager part, a custom node part, and an IBM HTTP server part. In the following section, you will see how to auto-scale the custom node part based on the CPU usage of the system. You can use this technique to scale any VSP part based on any user-defined scaling metric.

Figure 1. WebSphere cluster VSP
WebSphere cluster VSP

Step 1: Create a VAP application model metadata

To scale the VM nodes of a VSP instance, you will need the following user input:

  • VSP instance name
  • VSP node part name
  • User credentials required to access the running instance
  • User credentials required to execute the VSP command line APIs (deployer command line API)

The VSP instance name and VSP node part name are required to uniquely identify the asset to be scaled. In our WebSphere cluster VSP use case, the value for the VSP node part name is custom nodes and the value for the VSP instance name is the instance name of the deployed WebSphere cluster VSP instance. The instance user credentials are required to execute the monitoring scripts (using ssh) on the VM that is to be scaled. The deployer user credentials are required to run the APIs to add or remove the VM based on the monitored value.

You can obtain the required input from the user by using the VAP component object attributes. The component object attributes are modeled using the VAP application model metadata. Listing 1 shows the application model metadata. Figure 2 shows these attributes as displayed in the virtual application builder.

Listing 1. VSP Scaling Manager attributes metamodel (metadata.json)
{
      "id": "vsyscloning",
      "type": "component",
      "label": "VSys Scaling Manager",
      "description": "Example for cloning a virtual system",
      "image": "appmodel\/images\/demoapp.png",
      "thumbnail": "appmodel\/images\/thumbnail\/demoappl.png",
      "attributes": [
         {
            "id": "CLONENODE",
            "type": "string",
            "required": true,
            "label": "Virtual System Node",
         },
         {
            "id": "CLONEVSYS",
            "type": "string",
            "required": true,
            "label": "Virtual System Instance Name",
         },
         {
            "id": "VSYSPASS",
            "type": "string",
            "required": true,
            "label": "Virtual System password",
            "displayType": "password"
         },         
         {
            "id": "DEPHOST",
            "type": "string",
            "required": true,
            "label": "Deployer Host Name",
          },
         {
            "id": "DEPUSER",
            "type": "string",
            "required": true,
            "label": "Deployer User Id",
          },
         {
            "id": "DEPPASS",
            "type": "string",
            "required": true,
            "label": "Deployer password",
            "displayType": "password"
         }
      ]
   }
Figure 2. VSP Scaling Manager attributes
VSP Scaling Manager attributes

Step 2: Create a policy object to define a scaling policy

You will use the VAP policy framework to create a VSP auto scaling policy. The VAP policy framework lets you define a policy object using the VAP application model metadata. Refer to Scalability and elasticity for virtual application patterns in IBM PureApplication System for more details on how to define the policy using the VAP application model metadata.

Listing 2 shows the policy object definition for the CPU-based scaling. Figure 3 shows the policy as displayed in the virtual application builder. Using the policy interface shown in Figure 3, the user can create a scaling policy to scale the VSP instance VM nodes based on the VM CPU usage. The default policy definition, shown in Figure 3, instructs the system to scale up if the CPU usage is greater than 80% and to scale down if the CPU usage is less than 10%.

In our WebSphere cluster VSP use case, this scaling policy scales up the custom nodes VM if the CPU usage of all the custom nodes VM is greater than 80%. It scales down if the CPU usage of all the custom nodes VM is less than 10%.

Listing 2. VSP Scaling Manager CPU scaling policy object metamodel (metadata.json)
{	
        "id": "ScalingPolicyofVSys",
        "label": "VSys Scaling Policy",
        "type": "policy",
        "applicableTo": [
            "vsyscloning"
        ],
        "thumbnail": "appmodel/images/thumbnail/ClusterPolicy.png",
        "image": "appmodel/images/ClusterPolicy.png",        
        "description": "VSys scaling policy",
        "groups": [
			{
			   "category":"Scaling Type",
			   "id":"CPUVsys",
			   "label":"CPU Based",
			   "defaultValue":true,
			   "attributes":[
			      "cpuVsys",
			      "scaleInstanceRange1",
			      "triggerTime1",
                             ...
			   ],
			}                                    
        ],
        "attributes": [
            {
                "id": "triggerTime1",
                "label": "Minimum time (sec) to trigger add/remove",
                "type": "number",
                "max": 1800,
                "min": 30,
                "required": true,
                "sampleValue": 120,
                ...
            },
            {
                "id": "scaleInstanceRange1",
                "label": "Instance number range of scaling in/out",
                "type": "range",
                "min": 1,
                "max": 10,
                "required": true,
                "sampleValue": [
                    1,
                    10
                ],
                ...
            },
	    {
		 "id":"cpuVsys",
		 "label":"Scaling in/out when average CPU usage of clustered members is out 
           of threshold range(#)",
		 "type":"range",
                "displayType": "percentage",			   
		 "required":true,
		 "max":100,
		 "min":1,
		 "sampleValue":[
		      10,
		      80
		 ],
                ...
	     }     
        ]
}
Figure 3. VSP Scaling Manager CPU scaling policy
VSP Scaling Manager CPU scaling policy

Step 3: Create a topology template to convert the application model to a topology document

The PureApplication System IaaS layer uses the topology document to create VAP instances. A topology document is built from the application model. This model is created behind the scenes by PureApplication System while creating a VAP using the virtual application builder. You will use the velocity template shown in Listing 3 to convert the "VSP Scaling Manager" VAP application model to a topology document. The template shown in Listing 3 creates a role named "clone" with the following parameter values: VSP instance details (captured through Step 1) and the policy definition (captured through Step 2). The parameter values will be used in the "VSP Scaling Manager" VAP life-cycle scripts to drive the VSP instance scaling.

Listing 3. VSP Scaling Manager topology template (vsyscloning.vm)

Click to see code listing

Listing 3. VSP Scaling Manager topology template (vsyscloning.vm)

{
  #set($spattrs = $provider.getPolicyAttributes($component, 
   "ScalingPolicyofVSys"))		
  "vm-templates": [
   {
   "persistent":false,                 
    "name": "${prefix}-clone",
    "roles": [
    {
      "parms": {
	"DEPHOST":"$attributes.DEPHOST",
	"DEPUSER":"$attributes.DEPUSER",
	"DEPPASS":"$attributes.DEPPASS",						
	"CLONENODE":"$attributes.CLONENODE",	
	"CLONEVSYS":"$attributes.CLONEVSYS",
	"VSYSPASS":"$attributes.VSYSPASS",
	#if_value( $spattrs, "scaleInstanceRange1", '"MININST": 
    	$spattrs.scaleInstanceRange1.get(0),')
	#if_value( $spattrs, "scaleInstanceRange1", '"MAXINST": 							
        $spattrs.scaleInstanceRange1.get(1),')
	#if_value( $spattrs, "cpuVsys", '"MINCPU": $spattrs.cpuVsys.get(0),')
	#if_value( $spattrs, "cpuVsys", '"MAXCPU": $spattrs.cpuVsys.get(1),')		
    #if_value( $spattrs, "triggerTime1", '"triggerTime": 							
        $spattrs.triggerTime1,')
	"isCloned": "FALSE"
     },		            		                
     "type": "SClone",
     "name": "clone"                 
   }
  ],
  "packages": ["SClone"]
  }        		        
 ]
}

Step 4: Create monitoring metamodel and scripts

In this step, you will create the necessary assets to monitor the VSP instance VM nodes. Based on the monitored values, you will trigger the VSP instance VM node scaling as defined in the scaling policy. You will use the VAP monitoring framework to monitor VSP instance VM nodes. The VAP monitoring framework triggers the collection of monitored metrics and displays the monitored metrics in VAP console. To accomplish this, the VAP monitor framework expects the VAP plug-in to provide the following:

  • Metric metadata to define the metric data (Listing 4 shows the metric metadata for the CPU usage metric).
  • A script (see cpuutil.sh in the provided code sample) to collect the metric from VSP instance VM nodes.
  • Metric metadata and collection script registration code. Listing 5 shows the maestro API call to register the assets to the framework.
  • Metric display metadata to graphically present the collected metrics. Listing 6 shows the display metadata used to display the VSP instance VM node CPU metric.
Listing 4. Metric metadata for the VSP CPU metric (cpuvsyscollector.json)
{
   "version":1,
   "update_interval": 60,   
   "category":[
      "cpuvsys"
   ],
   "metadata":[
      {
         "cpuvsys":{
   			"update_interval":60,         
            "metrics":[
               {
                  "attribute_name":"cpuVsys",
                  "metric_name":"cpuVsys",
                  "metric_type":"COUNTER"
               }
            ]
         }
      }
   ]
}
Listing 5. Register metric collector (configure.py)
#Register cpu vsys collector
maestro.monitorAgent.register('{\
"node":"%s",\
"role":"%s",\
"collector":"com.ibm.maestro.monitor.collector.script",\
"config":{\
"metafile":"/home/virtuser/collectors/cpuvsyscollector.json",\
"executable":"/home/virtuser/collectors/cpuutil.sh",\
"arguments":"%s",\
"validRC":"0",\
"workdir":"/tmp",\
"timeout":"120"}}' % (nodeName,roleName,arguments));
Listing 6. Monitor metric display metadata (monitoring_ui.json)
[
   {
      "version":2,
      "category":"cpuvsys",
      "label":"CPU Usage",
      "displayRoles": ["SClone"],
      "displays":[
         {
            "label":"CPU Usage of Virtual System Instance Node",
            "monitorType":"HistoricalNumber",
            "chartType":"Lines",
            "metrics":[
               {
                  "attributeName":"cpuVsys",
                  "label":"Used Percentage"
               }
            ]
         }
      ]
   }
]

Scaling and monitoring scripts

In this section, we will dive into the monitoring and scaling script (see cpuutil.sh in the provided code sample). The script performs the following tasks:

  • The script retrieves the CPU utilization of the VSP instance VM nodes. In our use case, the script gets the CPU utilization of the WebSphere VSP custom nodes instances.
  • If the retrieved value is greater than the value specified in the policy, then a new VSP instance VM node is created until the maximum defined in the policy is reached. In our use case, if the custom nodes instances CPU usage is greater than 80, new WebSphere VSP custom nodes will be created until 10 such nodes exist.
  • If the retrieved value is less than the value specified in the policy, then all the nodes, except the minimum number specified in the policy, are deleted. In our use case, if the custom nodes instances CPU usage is less than 10, all except two WebSphere VSP custom nodes, will be removed.
  • Finally, the script returns the metric data to the VAP monitoring framework to be displayed in the deployment console.

This script is triggered by the monitoring framework at regular intervals. The trigger interval is based on the update_interval parameter value defined in the monitor metadata (see Listing 4). In this script, we essentially short wire the VAP monitoring framework to trigger the scaling on the VSP instance VM nodes. In the next section, you will see how to use the VSP Clone and Delete APIs to add or delete a VSP instance VM node.


Step 5: Create VSP instance VM node scaling scripts

You will use Python scripts to add or delete a VSP instance VM node. The Python script is triggered by the monitoring script, cpuutil.sh, using the PureApplication System deployer command line utility. Listing 7 and Listing 8 show the Python script to add a VSP instance VM node and to delete a VSP instance VM node. These scripts use the VSP virtual system objects, the virtual machine objects, and their clones. They also delete the methods to scale up and down the VSP instance VM node.

Listing 7. Script to add a new VSP part VM
#This python script is used to clone one new node (of type cloneNode)
#belonging to Vsys instance cloneVSys.
#No new node will be created if max is reached.
import os
import sys
cloneNode=sys.argv[1]
cloneVSys=sys.argv[2]
max=sys.argv[3]

#function to check if the maximum clone limit is reached
def isMax(max, system, cloneNode):
    current=0
    vms=system.virtualmachines
    for vm in vms:
        vmpartname= vm.patternpart.partCaption
        vmstatus = vm.currentstatus
        if(vmpartname == cloneNode and vmstatus == "RM01006"):            
             current+=1
    if(current < max):
        return "False"
    else:
        return "True"

#Get the input virtual system instance.  
allsystems=deployer.virtualsystems.list({'name':cloneVSys})
found='False'
for system in allsystems:
    vsysname=system.name
    vsysstatus = system.currentstatus
    print "SysName:" + vsysname + " SysStatus:" + vsysstatus
    if(vsysstatus == "RM01006" or vsysstatus == "RM01070"):
        #Get all the running virtual machines
        vms=system.virtualmachines
        for vm in vms:
            vmpartname= vm.patternpart.partCaption
            vmstatus = vm.currentstatus
            print "VMName:" + vmpartname + " VMStatus:" + vmstatus
            if(vmpartname == cloneNode and vmstatus == "RM01006"):
                found='True'
                #If max limit not reached then clone.
                isMaximum = isMax(int(max), system, cloneNode)
                if(isMaximum == 'False'):
                    print "Clone started"
                    vm.clone()
                break
        if(found=='True'):
            break
Listing 8. Script to delete VSP part VM
#This python script is used to release all the nodes (of type cloneNode)
#belonging to Vsys instance cloneVSys.
#No nodes are released if min specified is reached.

import os
import sys
cloneNode=sys.argv[1]
cloneVSys=sys.argv[2]
min=int(sys.argv[3])

#Check if minimum number of nodes reached.
def isMin(min, system, cloneNode):
    current=0
    vms=system.virtualmachines
    for vm in vms:
        vmpartname= vm.patternpart.partCaption
        vmstatus = vm.currentstatus
        if(vmpartname == cloneNode and vmstatus == "RM01006"):
             current+=1
    if(current > min):
        return "False"
    else:
        return "True"

#Get the input virtual system instance.
allsystems=deployer.virtualsystems.list({'name':cloneVSys})
found='False'
for system in allsystems:
    vsysname=system.name
    vsysstatus = system.currentstatus
    print "SysName:" + vsysname + " SysStatus:" + vsysstatus
    if(vsysstatus == "RM01006" or vsysstatus == "RM01070"):
        #Get all the running virtual machines
        vms=system.virtualmachines
        for vm in vms:
            vmpartname= vm.patternpart.partCaption
            vmstatus = vm.currentstatus
            print "VMName:" + vmpartname + " VMStatus:" + vmstatus
            if(vmpartname == cloneNode and vmstatus == "RM01006"):
                found='True'          
                #Delete till minimum specified is reached.      
                isMinimum = isMin(int(min), system, cloneNode)
                if(isMinimum == 'True'):
                    break
                else:
                    print "delete started"
                    vm.delete()
        if(found=='True'):
            break

In the above five steps, you essentially did the following:

  • Used the VAP Policy Object to define the user defined scaling policy.
  • Used the VAP monitoring framework to trigger the VSP instance VM monitoring and based on the monitored metric triggered dynamic auto scaling of the VSP instance VM.
  • Used the clone and remove methods provided by the VSP command API to create a new VSP instance VM node or to delete an existing VSP instance VM node.

Testing the use case

In this section, you will see how to test the WebSphere Cluster custom nodes scaling use case. To test the use case, first you need to create an instance of the WebSphere Cluster VSP. Figure 4 shows a WebSphere Cluster VSP instance. You must also create a VAP pattern type to drive the VSP scaling. The sample code provided with this article has a VAP pattern type (vsysscalingmgr) that you can import into your PureApplication System environment to drive the VSP scaling. Once imported, you can create a new VAP using the virtual application builder and deploy the newly created VAP.

Figure 4. WebSphere Cluster VSP instance
WebSphere Cluster VSP instance

Figure 5 shows the WebSphere Cluster Scaling Manager VAP in the virtual application builder.

Figure 5. WebSphere Cluster Scaling Manager pattern
WebSphere Cluster Scaling Manager pattern

After the pattern is deployed, you can simulate the scaling using the following steps:

  1. Log into the Deployment Manager console. Create new servers on the existing nodes and perform a full resynchronization or perform some other operation on the node that increases the CPU utilization on the custom nodes.
  2. Alternately, you can unit test the VSP instance custom nodes scaling by un-commenting the lines shown in Listing 9 in the monitoring script, cpuutil.sh. This feeds a dummy value of 85 as the CPU usage for subsequent tasks in the script. To scale down, you can comment out the lines you un-commented.
    Listing 9. Lines to un-comment to test the VSP Scaling Manager pattern
    cpuval=$(ssh -i $DIR_NAME/key -o StrictHostKeyChecking=no $ADMIN_NAME@$i "top -b -d1 -n2
    | grep -i \"Cpu(s)\" | cut -d ',' -f1  | awk '{print \$2}' | cut -d '%' -f1 | sed -n 2p")
    #To unit test clone un-comment the following line. After cloning to unit-test delete
    #comment this line.
    #cpuval=85
    #end unit test un-comment	   
    echo "cpu value is "$cpuval  >> /home/virtuser/collectors/scaling.log

Figure 6 shows the monitoring user interface in the VAP console. This displays the CPU usage of the VSP instance node custom nodes. Note that when you unit test the pattern type using the method described in Listing 9, the graph spikes to 85% and then falls back to 2%.

Figure 6. CPU usage of virtual system instance node
CPU usage of virtual system instance node

Figure 7 shows the addition of the custom nodes instance. When the CPU usage exceeds 80% for all the custom nodes instances, new WebSphere VSP custom nodes will be created until a maximum of 10 nodes is reached. When the CPU usage falls below 10% for all the custom nodes instances, all except two custom nodes instance will be removed.

Figure 7. WebSphere VSP custom nodes scaling
WebSphere VSP custom nodes scaling

Conclusion

In this article, you learned how to create a VAP pattern type to drive the user-defined automatic scaling of a VAP instance VM node. Using this technique, you can auto-scale a VSP instance VM node using a user-defined scaling policy with minimal or no change to your VSP. Further, you can monitor the VSP instance metrics using the VAP dashboard. The disadvantages of this technique are that the user is required to input user credentials for the VSP instance VM, and only PureApplication System users who have access to work with the VSP instance can deploy the VAP Scaling Manager instance. Otherwise, the deployer CLI will not have access to add or remove the nodes.


Download

DescriptionNameSize
Code samplecode_sample.zip52KB

Resources

Comments

developerWorks: Sign in

Required fields are indicated with an asterisk (*).


Need an IBM ID?
Forgot your IBM ID?


Forgot your password?
Change your password

By clicking Submit, you agree to the developerWorks terms of use.

 


The first time you sign into developerWorks, a profile is created for you. Information in your profile (your name, country/region, and company name) is displayed to the public and will accompany any content you post, unless you opt to hide your company name. You may update your IBM account at any time.

All information submitted is secure.

Choose your display name



The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerWorks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

Required fields are indicated with an asterisk (*).

(Must be between 3 – 31 characters.)

By clicking Submit, you agree to the developerWorks terms of use.

 


All information submitted is secure.

Dig deeper into Cloud computing on developerWorks


  • Bluemix Developers Community

    Get samples, articles, product docs, and community resources to help build, deploy, and manage your cloud apps.

  • Cloud digest

    Complete cloud software, infrastructure, and platform knowledge.

  • DevOps Services

    Software development in the cloud. Register today to create a project.

  • Try SoftLayer Cloud

    Deploy public cloud instances in as few as 5 minutes. Try the SoftLayer public cloud instance for one month.

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Cloud computing
ArticleID=947509
ArticleTitle=Automatic scaling of virtual system pattern instances in IBM PureApplication System
publish-date=10092013