DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. Application Governance with WSO2 GReg and Jenkins

Application Governance with WSO2 GReg and Jenkins

Shelan Perera user avatar by
Shelan Perera
·
Feb. 05, 13 · Interview
Like (0)
Save
Tweet
Share
4.17K Views

Join the DZone community and get the full member experience.

Join For Free

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

Pre-Requisites 

  • WSO2 Governance Registry 4.5.1
  • Jenkins
  • A svn location to store build artifacts.

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

Configurations
n 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→ Application
Specify Name of the car/war file. (This should be the exact name in the svn location without extension)
eg: myCapp
3) 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.

application Jenkins (software) Build (game engine) Artifact (UML)

Published at DZone with permission of Shelan Perera, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • How Do the Docker Client and Docker Servers Work?
  • Top 10 Best Practices for Scaling Your Application: Expert Tips for Optimizing Performance and Ensuring Reliability
  • How to Create a Dockerfile?
  • GPT-3 Playground: The AI That Can Write for You

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: