DevOps Zone is brought to you in partnership with:

At present I am a Software Engineer at WSO2.I was an undergraduate in University of Moratuwa Sri Lanka and a Young Innovator alumnus at International Communication Union (UN specialized agency).I was a Google Summer of code student for 2010 and 2011 and elected as an Apache Committer for Apache Roller.My key interests are Distributed Systems and SOA related technologies. Shelan is a DZone MVB and is not an employee of DZone and has posted 10 posts at DZone. You can read more from them at their website. View Full User Profile

Application Governance with WSO2 GReg and Jenkins

02.05.2013
| 1590 views |
  • submit to reddit

This tutorial will show how you can automate the application Governance using WSO2 Governance Registry and Jenkins (for Build Automation).

Pre-Requisites 


Things to note

  • Jenkins or similar build automation tool should be used to build the artifact and deploy it to the specific Dev SVN location. 
  • There are three SVN locations required for Dev , QA and Production artifact deployment. 
  • User needs to specify the exact name of the artifact (without the extension) as Application Name when adding the application to WSO2 Governance Registry. 
  • This particular sample is tested with WSO2 Governance Registry 4.5.1. Therefore it is recommended to use the same version of the product.

Resource Location

Please download resources from following location.
https://svn.wso2.org/repos/wso2/scratch/application-governance/

Workflow

Configurationsn this workflow build automation is excluded and user needs to add the built artifact and first deploy to Dev SVN location. (Developer may use Jenkins to build and its plugin to add it to a SVN location)

1) Create the Registry Extension file for Applications as specified below. Deploy the Application RXT file to Governance Registry as described in http://docs.wso2.org/wiki/display/Governance450/Deploying+an+Extension+File
<artifactType type="application/vnd.wso2-application+xml"
 
shortName="applications" singularLabel="Application" pluralLabel="Applications" hasNamespace="false" iconSet="9">
    <storagePath>/applications/@{overview_name}</storagePath>
 <nameAttribute>overview_name</nameAttribute>
    <ui>
        <list>
            <column name="Name">
                <data type="path" value="overview_name" href="/applications/@{name}"/>
            </column>
            <column name="type">
                <data type="type" value="overview_type"/>
            </column>
        </list>
    </ui>
    <content>
        <table name="Overview">
            <field type="text" required="true">
                <name>Name</name>
            </field>
            <field type="options">
     <name>Type</name>
     <values>
      <value>car</value>
      <value>war</value>
     </values>
    </field>
            <field type="text-area">
                <name>Description</name>
            </field>
        </table>
    </content>
</artifactType>
2) Create an Application in Governance Registry.

Add→ ApplicationSpecify Name of the car/war file. (This should be the exact name in the svn location without extension)
eg: myCapp3) Add Svn Executor to Governance Registry Server.

  • Edit the svn-executor-1.0.jar’s svn.properties file and add your svn credentials and Jenkins URL.

  • Copy the svn-executor-1.0.jar and svnkit-bundle-1.0.0.jar (provided separately) to G-REG_HOME/repository/components/lib folder.

  • Copysvn-client-adapter-1.6.18.wso2v2.jartoG-REG_HOME/repository/components/dropins folder.


4) Add a new lifecycle in Governance Registry names AppLifeCycle by following the instructions provided in
http://docs.wso2.org/wiki/display/Governance450/Adding+Lifecycles. Use the lifecycle configuration specified below.
<!--
 ~ Copyright (c) 2005-2010, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
 ~
 ~ WSO2 Inc. licenses this file to you under the Apache License,
 ~ Version 2.0 (the "License"); you may not use this file except
 ~ in compliance with the License.
 ~ You may obtain a copy of the License at
 ~
 ~    http://www.apache.org/licenses/LICENSE-2.0
 ~
 ~ Unless required by applicable law or agreed to in writing,
 ~ software distributed under the License is distributed on an
 ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 ~ KIND, either express or implied.  See the License for the
 ~ specific language governing permissions and limitations
 ~ under the License.
 -->
<aspect name="AppLifeCycle" class="org.wso2.carbon.governance.registry.extensions.aspects.DefaultLifeCycle">
    <configuration type="literal">
        <lifecycle>
            <scxml xmlns="http://www.w3.org/2005/07/scxml"
                   version="1.0"
                   initialstate="Development">
                <state id="Development">
                    <datamodel>
                        <data name="checkItems">
                            <item name="Code Completed" forEvent="">                            
                            </item>
                           
                            <item name="Added to SVN" forEvent="">
                            </item>
                        </data>
 
   <data name="transitionExecution">
                            <execution forEvent="Promote" class="org.wso2.carbon.executor.SvnDeploymentExecutor">
     <parameter name="currentEnvironment" value="https://svn.wso2.org/repos/wso2/scratch/greg-scm-test/dev"/>
                                <parameter name="targetEnvironment" value="https://svn.wso2.org/repos/wso2/scratch/greg-scm-test/qa"/>
                            </execution>   
                        </data>  
                    </datamodel>
                    <transition event="Promote" target="Testing"/>                  
                </state>
                <state id="Testing">
                    <datamodel>
                        <data name="checkItems">
                            <item name="Effective Inspection Completed" forEvent="">
                            </item>
                            <item name="Test Cases Passed" forEvent="">
                            </item>
                            <item name="Smoke Test Passed" forEvent="">
                            </item>
                        </data>
                         <data name="transitionExecution">
                            <execution forEvent="Promote" class="org.wso2.carbon.executor.SvnDeploymentExecutor">
                                <parameter name="currentEnvironment" value="https://svn.wso2.org/repos/wso2/scratch/greg-scm-test/qa"/>
                                <parameter name="targetEnvironment" value="https://svn.wso2.org/repos/wso2/scratch/greg-scm-test/prod"/>
                            </execution>
 
                            <execution forEvent="Demote" class="org.wso2.carbon.executor.SvnDeploymentExecutor">
                             <parameter name="currentEnvironment" value="https://svn.wso2.org/repos/wso2/scratch/greg-scm-test/qa"/>
                            </execution>
                        </data>
                            
    
                    </datamodel>
                    <transition event="Promote" target="Production"/>
                    <transition event="Demote" target="Development"/>
                </state>
                <state id="Production">  
                    <datamodel>
                        <data name="checkItems">
                            <item name="Verify No one using the application" forEvent="">
                            </item>
                        </data>
   <data name="transitionExecution">
                            <execution forEvent="Retire" class="org.wso2.carbon.executor.SvnDeploymentExecutor">
    <parameter name="currentEnvironment" value="https://svn.wso2.org/repos/wso2/scratch/greg-scm-test/qa"/>
                                <parameter name="targetEnvironment" value="https://svn.wso2.org/repos/wso2/scratch/greg-scm-test/prod"/>
                            </execution>   
                        </data>  
                    </datamodel>
                    <transition event="Retire" target="Retired"/>
                </state>  
                 
                <state id="Retired">  
                    <datamodel>     
                    </datamodel>
                </state>
                               
            </scxml>
        </lifecycle>
    </configuration>
</aspect> 
In the above lifecycle configuration you need to change your svn locations that are used in promotions.

Eg:

From Dev to QA
<parameter name="currentEnvironment" value="https://svn.wso2.org/repos/wso2/scratch/greg-scm-test/dev"/>
5) Attach the AppLifeCycle to your application.6) Promote Application from Development to Testing.
This will copy external CApp from Dev environment to QA environment (in the relevant SVN locations)
7) Demote Application from Testing to Development back
This will remove the artifact from QA environment (QA SVN location)
Deployment Automation with Jenkins
1) Start Jenkins and add the URL to svn-executor-1.0.jar’s properties file.
2) Create two Build jobs with name “promote” and “demote”.
3) Apply “This build is parameterized” check box and add following parameters to each of the job separately .
  • name
  • svnUrl
  • state

4) Create a local repository (A folder in you local file system) to check out the artifacts.
eg: /home/user1/repository

5) for promote Build job add the following script ( Build → Add build step → execute shell). Please change the values appropriately to suit your environment 
#!/bin/bash
 
if  [[ "${state}" == "Testing" ]] ;
then
##  repository location
cd /media/data/wso2/support/repository/
 
svn checkout $svnUrl
 
 
## svn checkout location (This will be repository url + ‘qa’ as
## QA artifact was store in our repository
## https://svn.wso2.org/repos/wso2/scratch/greg-scm-test/qa/
 
 
cd /media/data/wso2/support/repository/qa
cp -r ./$name
 
## Location of the Testing server
/media/data/wso2/support/wso2qaesb-4.5.0/repository/carbonapps/0/
fi
 
if [[ "${state}" == "Production" ]] ;
then
cd /media/data/wso2/support/repository/
svn checkout $svnUrl
 
## svn checkout location (This will be repository url + ‘prod’ as
## Production artifact was store in our repository
## https://svn.wso2.org/repos/wso2/scratch/greg-scm-test/prod/
 
cd /media/data/wso2/support/repository/prod
cp -r ./$name
 
## url of the Production server
/media/data/wso2/support/wso2prodesb-4.5.0/repository/carbonapps/0/
fi 
6) For demote Build job use the following action ( Build → Add build step → execute shell)
#!/bin/bash
 
if  [[ "${state}" == "Testing" ]] ;
then
 
## location of the local ‘QA’ artifacts are stored.
cd /media/data/wso2/support/repository/qa
 
svn update 
 
cd /media/data/wso2/support/wso2qaesb-4.5.0/repository/carbonapps/0
 
rm -rf ./$name
fi
7) When you promote as in the script it will deploy the artifact to Development server and when demote it will remove the Application from Carbon server which will respectively deploy/ undeploy

8) You need to have similar script for artifact deployment from initial project to developer location which is not covered in the sample.

Published at DZone with permission of Shelan Perera, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)