Tuesday, June 19, 2018

[Ballerina Lesson - 1] Day one with Balerina!!!


Ballerina is a new programming language for integration in the concept of "Integration Simple". As the https://ballerina.io mentions "Ballerina is a compiled, transactional, statically and strongly typed programming language with textual and graphical syntaxes".

Before moving further, first we will explore bit on the keywords used in the above phrase.

Compiled -  This means that the source code will be converted to machine code before executing at the runtime, this will give an advantage over the interpreted code as it doesn't need to work it out on the fly as the application is running due to that it is more faster than the interpreted language. 

Statically and Strongly Typed - Here statically typed means variables need not be defined before they’re used, but explicit initialization is needed. The next part Strongly Typed means variables are necessarily bound to a particular data type. For eg: Java is also a Statically and Strongly Typed programming language.

As an initial step, we will setup the environment for the development.

Setting up Ballerina Development Environment with IntelliJ IDEA


As pre-requisites we need the following:

  • IntelliJ IDEA [1]
  • Ballerina IntelliJ IDEA Plugin [2]
  • Ballerina SDK [3]
[3] https://ballerina.io/downloads/ballerina-platform-0.970.1.zip

Follow the below screens to complete configuring the IntelliJ IDEA.

Go to File -> Settings and click on the plugins and you will get the below screen.



Then under search input "ballerina" and click on the "search in repositories" and then you will get the below results page.



Click on install and once complete you will get the below screen.





Now we can add the SDK for that follow the below screens. Go to File -> New -> Project... and select Ballerina.











Now we are done with configuring the IntelliJ IDEA. We will dive into the Ballerina development from my next blog.
“There is no real ending. It’s just the place where you stop the story.”
Frank Herbert -

Sunday, May 13, 2018

Integrating Jenkins + GitHub + WSO2 ESB 5.0.0

In the space of Continuous Integration with WSO2 ESB, the common scenario of integration we encounter is the integration of the combination Jenkins + GitHub + WSO2 ESB 5.0.0. In this article we are going to integrate these three from the scratch.

What we are going to do?
Prerequisites Version Used
1) Ubuntu 14.04.5 LTS
2) Java 1.8.0_171
3) Apache Maven 3.0.5
4) Gradle 2.6
5) WSO2 ESB 5.0.0
6) WSO2 ESB Tooling 5.0.0

Contents Included
1) Installation of Jenkins in Ubuntu 14.04
2) Creating an API project in WSO2 ESB Tooling and configuring Gradle build
3) Pushing the WSO2 Code to Git Repository
4) Configuring the Jenkins Job
5) Verification

1) Installation of Jenkins in Ubuntu 14.04


Execute the below commands to install Jenkins in local Ubuntu Distribution.
  wget -q -O - https://pkg.jenkins.io/debian/jenkins-ci.org.key | sudo apt-key add -   
  sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'   
  sudo apt-get update   
  sudo apt-get install jenkins  

Once execution done we can see a screen as below asking to input a password - which we need to get from /var/lib/jenkins/secrets/initialAdminPassword


Once we successfully entered the admin password we were able to see the page as below.


Here, I'm selecting "Select plugins to install" tab as it will give us some idea what we are installing. Check and enable if any specific plugins needs to be installed and then click on the install.




That's it - now we are ready to use our Jenkins.



2) Creating an API project in WSO2 ESB Tooling and configuring Gradle build


When we create a ESB project we need to create two projects ESB Config Project and Composite Application Project. The first one is to create our artifacts and the second one is to create the CAR file which is the one WSO2 uses to deploy in WSO2 ESB. Go through the below screen shots which will help to understand the project structure and the creation of artifacts.







Now we need to create the Composite Application Project. To create that follow the below screen shots.




Now we are done with the initial WSO2 configurations, now we need make our project to build using Gradle. Currently the project structure will be look as below:




First will add the build.gradle files to the sub projects and then will add the configurations to the root project. The below image will give details on how the sub projects were added with gradle configurations.



Once we are done with this one additional configuration we need to add is to configure the CAPP projects pom.xml to point to the correct wso2carbon.jks location, this is needed when deploying the CAR application to the WSO2 ESB Server.
  <plugin>  
     <groupId>org.wso2.maven</groupId>  
     <artifactId>maven-car-deploy-plugin</artifactId>  
     <version>1.1.1</version>  
     <extensions>true</extensions>  
     <configuration>  
      <carbonServers>  
       <CarbonServer>  
        <trustStorePath>${basedir}/../resources/wso2carbon.jks</trustStorePath>  
        <trustStorePassword>wso2carbon</trustStorePassword>  
        <trustStoreType>JKS</trustStoreType>  
        <serverUrl>https://localhost:9443</serverUrl>  
        <userName>admin</userName>  
        <password>admin</password>  
        <operation>deploy</operation>  
       </CarbonServer>  
      </carbonServers>  
     </configuration>  
    </plugin>  

Now we can move to the gradle configuration of our root project. Below is my configured folders and files screen shot.


resources - Have the wso2carbon.jks
gradle - Consists of the gradle wrapper jar
gradlew and gradle.bat - This is the executables for linux and windows
settings.gradle - To specify our root and sub projects
build.gradle - The main build file for the root project.

The contents of the settings.gradle and build.gradle are as below:


 rootProject.name ='test-esb-jenkins-integration'  
 include 'TestESBRespondBackAPI'  
 include 'TestESBRespondBackCAPP'  

 buildscript {  
       repositories {  
              jcenter()  
              mavenCentral()  
            maven { url 'http://maven.wso2.org/nexus/content/groups/wso2-public' }  
  }  
 }  
 group = 'test-esb-jenkins-integration'  
 version = '1.0.0'  
 apply plugin: 'java'  
 apply plugin: 'maven-publish'  
 task buildAndDeployCAR() {  
   println "Executing the build and CAR deployment task..."  
   dependsOn ':TestESBRespondBackAPI:buildWSO2'  
   dependsOn ':TestESBRespondBackCAPP:deployWSO2'  
   tasks.findByPath(':TestESBRespondBackCAPP:deployWSO2').mustRunAfter ':TestESBRespondBackAPI:buildWSO2'  
 }  

Now we are ready to build our project. Make sure the WSO2 ESB 5.0.0 is up and running in the default port. Then execute the below command.
 ./gradlew buildAndDeployCAR  

 /test-esb-jenkins-integration$ ./gradlew buildAndDeployCAR  
 Executing the build and CAR deployment task...  
 :TestESBRespondBackAPI:buildWSO2  
 [INFO] Scanning for projects...  
 [INFO]                                       
 [INFO] ------------------------------------------------------------------------  
 [INFO] Building TestESBRespondBackAPI 1.0.0  
 [INFO] ------------------------------------------------------------------------  
 [INFO]   
 [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ TestESBRespondBackAPI ---  
 [INFO] Deleting /home/engineer/wso2_certification/test-esb-jenkins-integration/TestESBRespondBackAPI/target/capp  
 [INFO]   
 [INFO] --- wso2-esb-api-plugin:2.1.0:pom-gen (api) @ TestESBRespondBackAPI ---  
 [INFO] Creating maven project for artifact TestESBRespondAPI:1.0.0...  
 [INFO] generating maven project...  
 [INFO] copying resources...  
 [INFO]   
 [INFO] --- exec-maven-plugin:1.4.0:exec (package) @ TestESBRespondBackAPI ---  
 [INFO] Scanning for projects...  
 [INFO] ------------------------------------------------------------------------  
 [INFO] Reactor Build Order:  
 [INFO]   
 [INFO] TestESBRespondAPI  
 [INFO] TestESBRespondBackAPI_module  
 [INFO]                                       
 [INFO] ------------------------------------------------------------------------  
 [INFO] Building TestESBRespondAPI 1.0.0  
 [INFO] ------------------------------------------------------------------------  
 [INFO]   
 [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ TestESBRespondAPI ---  
 [INFO]   
 [INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ TestESBRespondAPI ---  
 [WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!  
 [INFO] skip non existing resourceDirectory /home/engineer/wso2_certification/test-esb-jenkins-integration/TestESBRespondBackAPI/target/capp/artifacts/api/TestESBRespondAPI/src/main/resources  
 [INFO]   
 [INFO] --- maven-compiler-plugin:3.7.0-jboss-1:compile (default-compile) @ TestESBRespondAPI ---  
 [INFO] No sources to compile  
 [INFO]   
 [INFO] --- maven-resources-plugin:3.1.0:testResources (default-testResources) @ TestESBRespondAPI ---  
 [WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!  
 [INFO] skip non existing resourceDirectory /home/engineer/wso2_certification/test-esb-jenkins-integration/TestESBRespondBackAPI/target/capp/artifacts/api/TestESBRespondAPI/src/test/resources  
 [INFO]   
 [INFO] --- maven-compiler-plugin:3.7.0-jboss-1:testCompile (default-testCompile) @ TestESBRespondAPI ---  
 [INFO] No sources to compile  
 [INFO]   
 [INFO] --- maven-surefire-plugin:2.21.0:test (default-test) @ TestESBRespondAPI ---  
 [INFO] No tests to run.  
 [INFO]   
 [INFO] --- wso2-esb-api-plugin:2.1.0:package-api (default-package-api) @ TestESBRespondAPI ---  
 [INFO]                                       
 [INFO] ------------------------------------------------------------------------  
 [INFO] Building TestESBRespondBackAPI_module 1.0.0  
 [INFO] ------------------------------------------------------------------------  
 [INFO]   
 [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ TestESBRespondBackAPI_module ---  
 [INFO] ------------------------------------------------------------------------  
 [INFO] Reactor Summary:  
 [INFO]   
 [INFO] TestESBRespondAPI ................................. SUCCESS [1.115s]  
 [INFO] TestESBRespondBackAPI_module ...................... SUCCESS [0.024s]  
 [INFO] ------------------------------------------------------------------------  
 [INFO] BUILD SUCCESS  
 [INFO] ------------------------------------------------------------------------  
 [INFO] Total time: 1.614s  
 [INFO] Finished at: Sun May 13 10:16:23 BST 2018  
 [INFO] Final Memory: 11M/211M  
 [INFO] ------------------------------------------------------------------------  
 [INFO]   
 [INFO] --- maven-install-plugin:2.3:install (default-install) @ TestESBRespondBackAPI ---  
 [INFO] Installing /home/engineer/wso2_certification/test-esb-jenkins-integration/TestESBRespondBackAPI/pom.xml to /home/engineer/.m2/repository/com/example/TestESBRespondBackAPI/TestESBRespondBackAPI/1.0.0/TestESBRespondBackAPI-1.0.0.pom  
 [INFO]   
 [INFO] --- exec-maven-plugin:1.4.0:exec (install) @ TestESBRespondBackAPI ---  
 [INFO] Scanning for projects...  
 [INFO] ------------------------------------------------------------------------  
 [INFO] Reactor Build Order:  
 [INFO]   
 [INFO] TestESBRespondAPI  
 [INFO] TestESBRespondBackAPI_module  
 [INFO]                                       
 [INFO] ------------------------------------------------------------------------  
 [INFO] Building TestESBRespondAPI 1.0.0  
 [INFO] ------------------------------------------------------------------------  
 [INFO]   
 [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ TestESBRespondAPI ---  
 [INFO] Deleting /home/engineer/wso2_certification/test-esb-jenkins-integration/TestESBRespondBackAPI/target/capp/artifacts/api/TestESBRespondAPI/target  
 [INFO]   
 [INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ TestESBRespondAPI ---  
 [WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!  
 [INFO] skip non existing resourceDirectory /home/engineer/wso2_certification/test-esb-jenkins-integration/TestESBRespondBackAPI/target/capp/artifacts/api/TestESBRespondAPI/src/main/resources  
 [INFO]   
 [INFO] --- maven-compiler-plugin:3.7.0-jboss-1:compile (default-compile) @ TestESBRespondAPI ---  
 [INFO] No sources to compile  
 [INFO]   
 [INFO] --- maven-resources-plugin:3.1.0:testResources (default-testResources) @ TestESBRespondAPI ---  
 [WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!  
 [INFO] skip non existing resourceDirectory /home/engineer/wso2_certification/test-esb-jenkins-integration/TestESBRespondBackAPI/target/capp/artifacts/api/TestESBRespondAPI/src/test/resources  
 [INFO]   
 [INFO] --- maven-compiler-plugin:3.7.0-jboss-1:testCompile (default-testCompile) @ TestESBRespondAPI ---  
 [INFO] No sources to compile  
 [INFO]   
 [INFO] --- maven-surefire-plugin:2.21.0:test (default-test) @ TestESBRespondAPI ---  
 [INFO] No tests to run.  
 [INFO]   
 [INFO] --- wso2-esb-api-plugin:2.1.0:package-api (default-package-api) @ TestESBRespondAPI ---  
 [INFO]   
 [INFO] --- maven-install-plugin:2.5.2:install (default-install) @ TestESBRespondAPI ---  
 [INFO] Installing /home/engineer/wso2_certification/test-esb-jenkins-integration/TestESBRespondBackAPI/target/capp/artifacts/api/TestESBRespondAPI/target/TestESBRespondAPI-1.0.0.xml to /home/engineer/.m2/repository/com/example/TestESBRespondBackAPI/api/TestESBRespondAPI/1.0.0/TestESBRespondAPI-1.0.0.xml  
 [INFO] Installing /home/engineer/wso2_certification/test-esb-jenkins-integration/TestESBRespondBackAPI/target/capp/artifacts/api/TestESBRespondAPI/pom.xml to /home/engineer/.m2/repository/com/example/TestESBRespondBackAPI/api/TestESBRespondAPI/1.0.0/TestESBRespondAPI-1.0.0.pom  
 [INFO]                                       
 [INFO] ------------------------------------------------------------------------  
 [INFO] Building TestESBRespondBackAPI_module 1.0.0  
 [INFO] ------------------------------------------------------------------------  
 [INFO]   
 [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ TestESBRespondBackAPI_module ---  
 [INFO]   
 [INFO] --- maven-install-plugin:2.3:install (default-install) @ TestESBRespondBackAPI_module ---  
 [INFO] Installing /home/engineer/wso2_certification/test-esb-jenkins-integration/TestESBRespondBackAPI/target/capp/pom.xml to /home/engineer/.m2/repository/com/example/TestESBRespondBackAPI/TestESBRespondBackAPI_module/1.0.0/TestESBRespondBackAPI_module-1.0.0.pom  
 [INFO] ------------------------------------------------------------------------  
 [INFO] Reactor Summary:  
 [INFO]   
 [INFO] TestESBRespondAPI ................................. SUCCESS [1.225s]  
 [INFO] TestESBRespondBackAPI_module ...................... SUCCESS [0.140s]  
 [INFO] ------------------------------------------------------------------------  
 [INFO] BUILD SUCCESS  
 [INFO] ------------------------------------------------------------------------  
 [INFO] Total time: 1.794s  
 [INFO] Finished at: Sun May 13 10:16:26 BST 2018  
 [INFO] Final Memory: 12M/211M  
 [INFO] ------------------------------------------------------------------------  
 [INFO] ------------------------------------------------------------------------  
 [INFO] BUILD SUCCESS  
 [INFO] ------------------------------------------------------------------------  
 [INFO] Total time: 7.544s  
 [INFO] Finished at: Sun May 13 10:16:26 BST 2018  
 [INFO] Final Memory: 11M/211M  
 [INFO] ------------------------------------------------------------------------  
 :TestESBRespondBackCAPP:deployWSO2  
 [INFO] Scanning for projects...  
 [INFO]                                       
 [INFO] ------------------------------------------------------------------------  
 [INFO] Building TestESBRespondBackCAPP 1.0.0  
 [INFO] ------------------------------------------------------------------------  
 [INFO]   
 [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ TestESBRespondBackCAPP ---  
 [INFO] Deleting /home/engineer/wso2_certification/test-esb-jenkins-integration/TestESBRespondBackCAPP/target  
 [INFO]   
 [INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ TestESBRespondBackCAPP ---  
 [WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!  
 [INFO] skip non existing resourceDirectory /home/engineer/wso2_certification/test-esb-jenkins-integration/TestESBRespondBackCAPP/src/main/resources  
 [INFO]   
 [INFO] --- maven-compiler-plugin:3.7.0-jboss-1:compile (default-compile) @ TestESBRespondBackCAPP ---  
 [INFO] No sources to compile  
 [INFO]   
 [INFO] --- maven-resources-plugin:3.1.0:testResources (default-testResources) @ TestESBRespondBackCAPP ---  
 [WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!  
 [INFO] skip non existing resourceDirectory /home/engineer/wso2_certification/test-esb-jenkins-integration/TestESBRespondBackCAPP/src/test/resources  
 [INFO]   
 [INFO] --- maven-compiler-plugin:3.7.0-jboss-1:testCompile (default-testCompile) @ TestESBRespondBackCAPP ---  
 [INFO] No sources to compile  
 [INFO]   
 [INFO] --- maven-surefire-plugin:2.21.0:test (default-test) @ TestESBRespondBackCAPP ---  
 [INFO] No tests to run.  
 [INFO]   
 [INFO] --- maven-car-plugin:2.1.1:car (default-car) @ TestESBRespondBackCAPP ---  
 log4j:WARN No appenders could be found for logger (org.apache.axiom.om.util.StAXUtils).  
 log4j:WARN Please initialize the log4j system properly.  
 [INFO] Generating artifact descriptor for artifact: TestESBRespondAPI  
 [INFO] Copying artifact content to target location.  
 [INFO]   
 [INFO] --- maven-car-plugin:2.1.1:car (car) @ TestESBRespondBackCAPP ---  
 [INFO] Generating artifact descriptor for artifact: TestESBRespondAPI  
 [INFO] Copying artifact content to target location.  
 [INFO]   
 [INFO] --- maven-install-plugin:2.5.2:install (default-install) @ TestESBRespondBackCAPP ---  
 [INFO] Installing /home/engineer/wso2_certification/test-esb-jenkins-integration/TestESBRespondBackCAPP/target/TestESBRespondBackCAPP_1.0.0.car to /home/engineer/.m2/repository/com/example/TestESBRespondBackCAPP/TestESBRespondBackCAPP/1.0.0/TestESBRespondBackCAPP-1.0.0.car  
 [INFO] Installing /home/engineer/wso2_certification/test-esb-jenkins-integration/TestESBRespondBackCAPP/pom.xml to /home/engineer/.m2/repository/com/example/TestESBRespondBackCAPP/TestESBRespondBackCAPP/1.0.0/TestESBRespondBackCAPP-1.0.0.pom  
 [INFO]   
 [INFO] --- maven-car-deploy-plugin:1.1.1:deploy-car (default-deploy-car) @ TestESBRespondBackCAPP ---  
 [INFO] Deploying to Server...  
 [INFO] TSPath=../resources/wso2carbon.jks  
 [INFO] TSPWD=wso2carbon  
 [INFO] TSType=JKS  
 [INFO] Server URL=https://localhost:9443  
 [INFO] UserName=admin  
 [INFO] Password=admin  
 [INFO] Operation=deploy  
 log4j:WARN No appenders could be found for logger (org.apache.axis2.description.AxisOperation).  
 log4j:WARN Please initialize the log4j system properly.  
 [INFO] Authentication to https://localhost:9443 successful.  
 [INFO] Uploading TestESBRespondBackCAPP_1.0.0.car to https://localhost:9443...  
 [INFO] Uploading TestESBRespondBackCAPP_1.0.0.car to https://localhost:9443 completed successfully.  
 [INFO]   
 [INFO] --- maven-deploy-plugin:2.8.2:deploy (default-deploy) @ TestESBRespondBackCAPP ---  
 [INFO] Skipping artifact deployment  
 [INFO] ------------------------------------------------------------------------  
 [INFO] BUILD SUCCESS  
 [INFO] ------------------------------------------------------------------------  
 [INFO] Total time: 3.692s  
 [INFO] Finished at: Sun May 13 10:16:31 BST 2018  
 [INFO] Final Memory: 20M/351M  
 [INFO] ------------------------------------------------------------------------  
 :buildAndDeployCAR  
 BUILD SUCCESSFUL  
 Total time: 15.373 secs  
 engineer@engineer-VirtualBox:~/wso2_certification/test-esb-jenkins-integration$   

Based on the above logs we can confirm our setup working properly.

3) Pushing the WSO2 Code to Git Repository

To do this, create a new repository in your GitHub account.



Now execute the below commands to push our local code to Git Repository.

 git init  
 git add .  
 git commit -m "Skeleton Project Commit"  
 git remote add origin https://github.com/ajanthanerepo/test-esb-jenkins-integration.git  
 git push -u origin master  


4) Configuring the Jenkins Job

As of now we are done with the WSO2 ESB and GitHub Configurations, now we can move to configure our source code repository to build and deploy using Jenkins. To continue on that follow the screen shots.

Go to the Jenkins http://localhost:8080 and log into the console and follow the screens.







5) Verification

To verify our setup working properly - just execute the Build Now option and check the log console.
 Started by user Ajanthan  
 Building in workspace /var/lib/jenkins/workspace/TestESBJenkinsIntegrationProject  
 [WS-CLEANUP] Deleting project workspace...  
 [WS-CLEANUP] Done  
 Cloning the remote Git repository  
 Cloning repository https://github.com/ajanthanerepo/test-esb-jenkins-integration.git  
  > git init /var/lib/jenkins/workspace/TestESBJenkinsIntegrationProject # timeout=10  
 Fetching upstream changes from https://github.com/ajanthanerepo/test-esb-jenkins-integration.git  
  > git --version # timeout=10  
  > git fetch --tags --progress https://github.com/ajanthanerepo/test-esb-jenkins-integration.git +refs/heads/*:refs/remotes/origin/*  
  > git config remote.origin.url https://github.com/ajanthanerepo/test-esb-jenkins-integration.git # timeout=10  
  > git config --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/* # timeout=10  
  > git config remote.origin.url https://github.com/ajanthanerepo/test-esb-jenkins-integration.git # timeout=10  
 Fetching upstream changes from https://github.com/ajanthanerepo/test-esb-jenkins-integration.git  
  > git fetch --tags --progress https://github.com/ajanthanerepo/test-esb-jenkins-integration.git +refs/heads/*:refs/remotes/origin/*  
  > git rev-parse refs/remotes/origin/master^{commit} # timeout=10  
  > git rev-parse refs/remotes/origin/origin/master^{commit} # timeout=10  
 Checking out Revision e1d87e4f0a6a72511e9278033b558e095cefd801 (refs/remotes/origin/master)  
  > git config core.sparsecheckout # timeout=10  
  > git checkout -f e1d87e4f0a6a72511e9278033b558e095cefd801  
 Commit message: "upadted pom"  
  > git rev-list --no-walk 6c3359a631ddce5d7404bd4a278bd617dfcd884d # timeout=10  
 [Gradle] - Launching build.  
 [TestESBJenkinsIntegrationProject] $ /var/lib/jenkins/workspace/TestESBJenkinsIntegrationProject/gradlew buildAndDeployCAR  
 Executing the build and CAR deployment task...  
 :TestESBRespondBackAPI:buildWSO2  
 [INFO] Scanning for projects...  
 [INFO]                                       
 [INFO] ------------------------------------------------------------------------  
 [INFO] Building TestESBRespondBackAPI 1.0.0  
 [INFO] ------------------------------------------------------------------------  
 [INFO]   
 [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ TestESBRespondBackAPI ---  
 [INFO] Deleting /var/lib/jenkins/workspace/TestESBJenkinsIntegrationProject/TestESBRespondBackAPI/target/capp  
 [INFO]   
 [INFO] --- wso2-esb-api-plugin:2.1.0:pom-gen (api) @ TestESBRespondBackAPI ---  
 [INFO] Creating maven project for artifact TestESBRespondAPI:1.0.0...  
 [INFO]      generating maven project...  
 [INFO]      copying resources...  
 [INFO]   
 [INFO] --- exec-maven-plugin:1.4.0:exec (package) @ TestESBRespondBackAPI ---  
 [INFO] Scanning for projects...  
 [INFO] ------------------------------------------------------------------------  
 [INFO] Reactor Build Order:  
 [INFO]   
 [INFO] TestESBRespondAPI  
 [INFO] TestESBRespondBackAPI_module  
 [INFO]                                       
 [INFO] ------------------------------------------------------------------------  
 [INFO] Building TestESBRespondAPI 1.0.0  
 [INFO] ------------------------------------------------------------------------  
 [INFO]   
 [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ TestESBRespondAPI ---  
 [INFO]   
 [INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ TestESBRespondAPI ---  
 [WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!  
 [INFO] skip non existing resourceDirectory /var/lib/jenkins/workspace/TestESBJenkinsIntegrationProject/TestESBRespondBackAPI/target/capp/artifacts/api/TestESBRespondAPI/src/main/resources  
 [INFO]   
 [INFO] --- maven-compiler-plugin:3.7.0-jboss-1:compile (default-compile) @ TestESBRespondAPI ---  
 [INFO] No sources to compile  
 [INFO]   
 [INFO] --- maven-resources-plugin:3.1.0:testResources (default-testResources) @ TestESBRespondAPI ---  
 [WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!  
 [INFO] skip non existing resourceDirectory /var/lib/jenkins/workspace/TestESBJenkinsIntegrationProject/TestESBRespondBackAPI/target/capp/artifacts/api/TestESBRespondAPI/src/test/resources  
 [INFO]   
 [INFO] --- maven-compiler-plugin:3.7.0-jboss-1:testCompile (default-testCompile) @ TestESBRespondAPI ---  
 [INFO] No sources to compile  
 [INFO]   
 [INFO] --- maven-surefire-plugin:2.21.0:test (default-test) @ TestESBRespondAPI ---  
 [INFO] No tests to run.  
 [INFO]   
 [INFO] --- wso2-esb-api-plugin:2.1.0:package-api (default-package-api) @ TestESBRespondAPI ---  
 [INFO]                                       
 [INFO] ------------------------------------------------------------------------  
 [INFO] Building TestESBRespondBackAPI_module 1.0.0  
 [INFO] ------------------------------------------------------------------------  
 [INFO]   
 [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ TestESBRespondBackAPI_module ---  
 [INFO] ------------------------------------------------------------------------  
 [INFO] Reactor Summary:  
 [INFO]   
 [INFO] TestESBRespondAPI ................................. SUCCESS [1.296s]  
 [INFO] TestESBRespondBackAPI_module ...................... SUCCESS [0.033s]  
 [INFO] ------------------------------------------------------------------------  
 [INFO] BUILD SUCCESS  
 [INFO] ------------------------------------------------------------------------  
 [INFO] Total time: 2.020s  
 [INFO] Finished at: Sun May 13 11:10:00 BST 2018  
 [INFO] Final Memory: 11M/208M  
 [INFO] ------------------------------------------------------------------------  
 [INFO]   
 [INFO] --- maven-install-plugin:2.3:install (default-install) @ TestESBRespondBackAPI ---  
 [INFO] Installing /var/lib/jenkins/workspace/TestESBJenkinsIntegrationProject/TestESBRespondBackAPI/pom.xml to /var/lib/jenkins/.m2/repository/com/example/TestESBRespondBackAPI/TestESBRespondBackAPI/1.0.0/TestESBRespondBackAPI-1.0.0.pom  
 [INFO]   
 [INFO] --- exec-maven-plugin:1.4.0:exec (install) @ TestESBRespondBackAPI ---  
 [INFO] Scanning for projects...  
 [INFO] ------------------------------------------------------------------------  
 [INFO] Reactor Build Order:  
 [INFO]   
 [INFO] TestESBRespondAPI  
 [INFO] TestESBRespondBackAPI_module  
 [INFO]                                       
 [INFO] ------------------------------------------------------------------------  
 [INFO] Building TestESBRespondAPI 1.0.0  
 [INFO] ------------------------------------------------------------------------  
 [INFO]   
 [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ TestESBRespondAPI ---  
 [INFO] Deleting /var/lib/jenkins/workspace/TestESBJenkinsIntegrationProject/TestESBRespondBackAPI/target/capp/artifacts/api/TestESBRespondAPI/target  
 [INFO]   
 [INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ TestESBRespondAPI ---  
 [WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!  
 [INFO] skip non existing resourceDirectory /var/lib/jenkins/workspace/TestESBJenkinsIntegrationProject/TestESBRespondBackAPI/target/capp/artifacts/api/TestESBRespondAPI/src/main/resources  
 [INFO]   
 [INFO] --- maven-compiler-plugin:3.7.0-jboss-1:compile (default-compile) @ TestESBRespondAPI ---  
 [INFO] No sources to compile  
 [INFO]   
 [INFO] --- maven-resources-plugin:3.1.0:testResources (default-testResources) @ TestESBRespondAPI ---  
 [WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!  
 [INFO] skip non existing resourceDirectory /var/lib/jenkins/workspace/TestESBJenkinsIntegrationProject/TestESBRespondBackAPI/target/capp/artifacts/api/TestESBRespondAPI/src/test/resources  
 [INFO]   
 [INFO] --- maven-compiler-plugin:3.7.0-jboss-1:testCompile (default-testCompile) @ TestESBRespondAPI ---  
 [INFO] No sources to compile  
 [INFO]   
 [INFO] --- maven-surefire-plugin:2.21.0:test (default-test) @ TestESBRespondAPI ---  
 [INFO] No tests to run.  
 [INFO]   
 [INFO] --- wso2-esb-api-plugin:2.1.0:package-api (default-package-api) @ TestESBRespondAPI ---  
 [INFO]   
 [INFO] --- maven-install-plugin:2.5.2:install (default-install) @ TestESBRespondAPI ---  
 [INFO] Installing /var/lib/jenkins/workspace/TestESBJenkinsIntegrationProject/TestESBRespondBackAPI/target/capp/artifacts/api/TestESBRespondAPI/target/TestESBRespondAPI-1.0.0.xml to /var/lib/jenkins/.m2/repository/com/example/TestESBRespondBackAPI/api/TestESBRespondAPI/1.0.0/TestESBRespondAPI-1.0.0.xml  
 [INFO] Installing /var/lib/jenkins/workspace/TestESBJenkinsIntegrationProject/TestESBRespondBackAPI/target/capp/artifacts/api/TestESBRespondAPI/pom.xml to /var/lib/jenkins/.m2/repository/com/example/TestESBRespondBackAPI/api/TestESBRespondAPI/1.0.0/TestESBRespondAPI-1.0.0.pom  
 [INFO]                                       
 [INFO] ------------------------------------------------------------------------  
 [INFO] Building TestESBRespondBackAPI_module 1.0.0  
 [INFO] ------------------------------------------------------------------------  
 [INFO]   
 [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ TestESBRespondBackAPI_module ---  
 [INFO]   
 [INFO] --- maven-install-plugin:2.3:install (default-install) @ TestESBRespondBackAPI_module ---  
 [INFO] Installing /var/lib/jenkins/workspace/TestESBJenkinsIntegrationProject/TestESBRespondBackAPI/target/capp/pom.xml to /var/lib/jenkins/.m2/repository/com/example/TestESBRespondBackAPI/TestESBRespondBackAPI_module/1.0.0/TestESBRespondBackAPI_module-1.0.0.pom  
 [INFO] ------------------------------------------------------------------------  
 [INFO] Reactor Summary:  
 [INFO]   
 [INFO] TestESBRespondAPI ................................. SUCCESS [1.392s]  
 [INFO] TestESBRespondBackAPI_module ...................... SUCCESS [0.089s]  
 [INFO] ------------------------------------------------------------------------  
 [INFO] BUILD SUCCESS  
 [INFO] ------------------------------------------------------------------------  
 [INFO] Total time: 2.192s  
 [INFO] Finished at: Sun May 13 11:10:04 BST 2018  
 [INFO] Final Memory: 11M/208M  
 [INFO] ------------------------------------------------------------------------  
 [INFO] ------------------------------------------------------------------------  
 [INFO] BUILD SUCCESS  
 [INFO] ------------------------------------------------------------------------  
 [INFO] Total time: 9.326s  
 [INFO] Finished at: Sun May 13 11:10:04 BST 2018  
 [INFO] Final Memory: 9M/165M  
 [INFO] ------------------------------------------------------------------------  
 :TestESBRespondBackCAPP:deployWSO2  
 [INFO] Scanning for projects...  
 [INFO]                                       
 [INFO] ------------------------------------------------------------------------  
 [INFO] Building TestESBRespondBackCAPP 1.0.0  
 [INFO] ------------------------------------------------------------------------  
 [INFO]   
 [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ TestESBRespondBackCAPP ---  
 [INFO] Deleting /var/lib/jenkins/workspace/TestESBJenkinsIntegrationProject/TestESBRespondBackCAPP/target  
 [INFO]   
 [INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ TestESBRespondBackCAPP ---  
 [WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!  
 [INFO] skip non existing resourceDirectory /var/lib/jenkins/workspace/TestESBJenkinsIntegrationProject/TestESBRespondBackCAPP/src/main/resources  
 [INFO]   
 [INFO] --- maven-compiler-plugin:3.7.0-jboss-1:compile (default-compile) @ TestESBRespondBackCAPP ---  
 [INFO] No sources to compile  
 [INFO]   
 [INFO] --- maven-resources-plugin:3.1.0:testResources (default-testResources) @ TestESBRespondBackCAPP ---  
 [WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!  
 [INFO] skip non existing resourceDirectory /var/lib/jenkins/workspace/TestESBJenkinsIntegrationProject/TestESBRespondBackCAPP/src/test/resources  
 [INFO]   
 [INFO] --- maven-compiler-plugin:3.7.0-jboss-1:testCompile (default-testCompile) @ TestESBRespondBackCAPP ---  
 [INFO] No sources to compile  
 [INFO]   
 [INFO] --- maven-surefire-plugin:2.21.0:test (default-test) @ TestESBRespondBackCAPP ---  
 [INFO] No tests to run.  
 [INFO]   
 [INFO] --- maven-car-plugin:2.1.1:car (default-car) @ TestESBRespondBackCAPP ---  
 log4j:WARN No appenders could be found for logger (org.apache.axiom.om.util.StAXUtils).  
 log4j:WARN Please initialize the log4j system properly.  
 [INFO] Generating artifact descriptor for artifact: TestESBRespondAPI  
 [INFO] Copying artifact content to target location.  
 [INFO]   
 [INFO] --- maven-car-plugin:2.1.1:car (car) @ TestESBRespondBackCAPP ---  
 [INFO] Generating artifact descriptor for artifact: TestESBRespondAPI  
 [INFO] Copying artifact content to target location.  
 [INFO]   
 [INFO] --- maven-install-plugin:2.5.2:install (default-install) @ TestESBRespondBackCAPP ---  
 [INFO] Installing /var/lib/jenkins/workspace/TestESBJenkinsIntegrationProject/TestESBRespondBackCAPP/target/TestESBRespondBackCAPP_1.0.0.car to /var/lib/jenkins/.m2/repository/com/example/TestESBRespondBackCAPP/TestESBRespondBackCAPP/1.0.0/TestESBRespondBackCAPP-1.0.0.car  
 [INFO] Installing /var/lib/jenkins/workspace/TestESBJenkinsIntegrationProject/TestESBRespondBackCAPP/pom.xml to /var/lib/jenkins/.m2/repository/com/example/TestESBRespondBackCAPP/TestESBRespondBackCAPP/1.0.0/TestESBRespondBackCAPP-1.0.0.pom  
 [INFO]   
 [INFO] --- maven-car-deploy-plugin:1.1.1:deploy-car (default-deploy-car) @ TestESBRespondBackCAPP ---  
 [INFO] Deploying to Server...  
 [INFO] TSPath=/var/lib/jenkins/workspace/TestESBJenkinsIntegrationProject/TestESBRespondBackCAPP/../resources/wso2carbon.jks  
 [INFO] TSPWD=wso2carbon  
 [INFO] TSType=JKS  
 [INFO] Server URL=https://localhost:9443  
 [INFO] UserName=admin  
 [INFO] Password=admin  
 [INFO] Operation=deploy  
 log4j:WARN No appenders could be found for logger (org.apache.axis2.description.AxisOperation).  
 log4j:WARN Please initialize the log4j system properly.  
 [INFO] Authentication to https://localhost:9443 successful.  
 [INFO] Uploading TestESBRespondBackCAPP_1.0.0.car to https://localhost:9443...  
 [INFO] Uploading TestESBRespondBackCAPP_1.0.0.car to https://localhost:9443 completed successfully.  
 [INFO]   
 [INFO] --- maven-deploy-plugin:2.8.2:deploy (default-deploy) @ TestESBRespondBackCAPP ---  
 [INFO] Skipping artifact deployment  
 [INFO] ------------------------------------------------------------------------  
 [INFO] BUILD SUCCESS  
 [INFO] ------------------------------------------------------------------------  
 [INFO] Total time: 3.610s  
 [INFO] Finished at: Sun May 13 11:10:09 BST 2018  
 [INFO] Final Memory: 21M/294M  
 [INFO] ------------------------------------------------------------------------  
 :buildAndDeployCAR  
 BUILD SUCCESSFUL  
 Total time: 20.403 secs  
 This build could be faster, please consider using the Gradle Daemon: https://docs.gradle.org/2.14.1/userguide/gradle_daemon.html  
 Build step 'Invoke Gradle script' changed build result to SUCCESS  
 Finished: SUCCESS  



That's it and hope this helps someone who just starting into the Jenkins _ GitHub + WSO2 ESB Integration space.

All the source code can be found at https://github.com/ajanthanerepo/test-esb-jenkins-integration.git

References



Tuesday, March 27, 2018

Dynamically assign queue names to the JMS Endpoint in WSO2 ESB 4.9.0

This article explains a scenario where we need to send out messages to different queue's dynamically using Address Endpoint Templates.

Create a Address Endpoint Template as below, where we can pass the uri as a variable.
 <template xmlns="http://ws.apache.org/ns/synapse" name="DynamicQueueEndpoint">  
   <endpoint name="$name">  
    <address uri="$uri">  
      <suspendOnFailure>  
       <progressionFactor>1.0</progressionFactor>  
      </suspendOnFailure>  
      <markForSuspension>  
       <retriesBeforeSuspension>0</retriesBeforeSuspension>  
       <retryDelay>0</retryDelay>  
      </markForSuspension>  
    </address>  
   </endpoint>  
 </template>  

Then using the above template we can construct the JMS Endpoint as below in the sample proxy service.
 <?xml version="1.0" encoding="UTF-8"?>  
 <proxy xmlns="http://ws.apache.org/ns/synapse"  
     name="DynamicQueueProxy"  
     transports="http,https"  
     statistics="disable"  
     trace="disable"  
     startOnLoad="true">  
   <target>  
    <inSequence>  
      <log level="custom">  
       <property name="STATUS" value="[DynamicQueueProxy] Invoked..."/>  
      </log>  
      <property name="FORCE_SC_ACCEPTED" value="true" scope="axis2"/>  
      <property name="OUT_ONLY" value="true"/>  
      <property name="endpoint_1"  
           expression="fn:concat('jms:/',//DynamicQueueTest/QueueName,'?transport.jms.ConnectionFactoryJNDIName=QueueConnectionFactory&amp;java.naming.factory.initial=org.wso2.andes.jndi.PropertiesFileInitialContextFactory&amp;java.naming.provider.url=repository/conf/jndi.properties&amp;transport.jms.DestinationType=queue')"/>  
      <send>  
       <endpoint name="QueueEndpoint"  
            template="DynamicQueueEndpoint"  
            uri="${endpoint_1}"/>  
      </send>  
      <drop/>  
    </inSequence>  
   </target>  
   <description/>  
 </proxy>  

When send a message payload as below:
 <DynamicQueueTest>  
      <QueueName>DynamicQ3</QueueName>  
 </DynamicQueueTest>  

The message will be populated based on the QueueName specified in the above message.

That's it...



Thursday, February 15, 2018

Useful GIT Commands

This article explains about the GIT basics. The below commands were executed in Ubuntu 17.04. As the initial step use the below command to install the GIT client in Ubuntu 17.04.

 sudo add-apt-repository ppa:git-core/ppa  
 sudo apt-get update  
 sudo apt-get install git  

Then create account in GIT, to do that you can go to [1] https://github.com/

Once we are done with the GIT account creation, the next step is to create a repository. for example I have created a repository as below:



Now we are ready to go through the scenario's where we encounter in programming.


1) Moving the local files to a New GIT Repository.


- For this I have created a folder with two files as below:


- Then execute the below command inside the folder.

 ajanthan@ajanthan-Lenovo:~/testgitrepo$ git init  
 Initialized empty Git repository in /home/ajanthan/testgitrepo/.git/  
 ajanthan@ajanthan-Lenovo:~/testgitrepo$   

- Then execute the below:
 ajanthan@ajanthan-Lenovo:~/testgitrepo$ git add .  

- Before commit the files we need execute the below command, to tell our folder, under what account need to commit the files.
 ajanthan@ajanthan-Lenovo:~/testgitrepo$ git config --global user.email "ajanthaneng@gmail.com"  
 ajanthan@ajanthan-Lenovo:~/testgitrepo$ git config --global user.name "ajanthanerepo"  

- Now execute the below:
 ajanthan@ajanthan-Lenovo:~/testgitrepo$ git commit -m "Test commit"  
 [master (root-commit) 2d6bc85] Test commit  
  2 files changed, 4 insertions(+)  
  create mode 100644 README.md  
  create mode 100644 test.json  

- Now we need to specify the repository where the local files need to be moved, to that execute the below command, mentioning the repository url.
 ajanthan@ajanthan-Lenovo:~/testgitrepo$ git remote add origin https://github.com/ajanthanerepo/test-repo-ajan1  
 ajanthan@ajanthan-Lenovo:~/testgitrepo$ git remote -v  
 origin     https://github.com/ajanthanerepo/test-repo-ajan1 (fetch)  
 origin     https://github.com/ajanthanerepo/test-repo-ajan1 (push)  
 ajanthan@ajanthan-Lenovo:~/testgitrepo$   

- When we go to the repository still we couldn't see any files added, once we execute the below, then only the files will be moved from local.


 ajanthan@ajanthan-Lenovo:~/testgitrepo$ git push origin master  
 Username for 'https://github.com': ajanthaneng@gmail.com  
 Password for 'https://ajanthaneng@gmail.com@github.com':   
 Counting objects: 4, done.  
 Delta compression using up to 4 threads.  
 Compressing objects: 100% (2/2), done.  
 Writing objects: 100% (4/4), 290 bytes | 290.00 KiB/s, done.  
 Total 4 (delta 0), reused 0 (delta 0)  
 To https://github.com/ajanthanerepo/test-repo-ajan1  
  * [new branch]   master -> master  
 ajanthan@ajanthan-Lenovo:~/testgitrepo$   

- Now we can see our files moved successfully.


- Also we can create a branch using the below commands.
 ajanthan@ajanthan-Lenovo:~/testgitrepo$ git branch testbranch  
 ajanthan@ajanthan-Lenovo:~/testgitrepo$ git status  
 On branch master  
 nothing to commit, working tree clean  
 ajanthan@ajanthan-Lenovo:~/testgitrepo$ git checkout testbranch  
 Switched to branch 'testbranch'  
 ajanthan@ajanthan-Lenovo:~/testgitrepo$ git status  
 On branch testbranch  
 nothing to commit, working tree clean  
 ajanthan@ajanthan-Lenovo:~/testgitrepo$ git push -u origin testbranch  
 Username for 'https://github.com': ajanthaneng@gmail.com  
 Password for 'https://ajanthaneng@gmail.com@github.com':   
 Total 0 (delta 0), reused 0 (delta 0)  
 To https://github.com/ajanthanerepo/test-repo-ajan1  
  * [new branch]   testbranch -> testbranch  
 Branch 'testbranch' set up to track remote branch 'testbranch' from 'origin'.  
 ajanthan@ajanthan-Lenovo:~/testgitrepo$   


2) Cloning a remote repository and committing to that repository.

This is a most common scenario, where we clone a repository and do modifications and then commit those changes.

As the previous is a public repository, it is possible to directly clone the repo as below:
 ajanthan@ajanthan-Lenovo:~/testrepo4$ git clone https://github.com/ajanthanerepo/test-repo-ajan1.git  
 Cloning into 'test-repo-ajan1'...  
 remote: Counting objects: 4, done.  
 remote: Compressing objects: 100% (2/2), done.  
 remote: Total 4 (delta 0), reused 4 (delta 0), pack-reused 0  
 Unpacking objects: 100% (4/4), done.  
 ajanthan@ajanthan-Lenovo:~/testrepo4$ ls  
 test-repo-ajan1  
 ajanthan@ajanthan-Lenovo:~/testrepo4$   

Then I'm modifying the test.json file after that getting the diff.
 ajanthan@ajanthan-Lenovo:~/testrepo4/test-repo-ajan1$ vi test.json   
 ajanthan@ajanthan-Lenovo:~/testrepo4/test-repo-ajan1$   
 ajanthan@ajanthan-Lenovo:~/testrepo4/test-repo-ajan1$   
 ajanthan@ajanthan-Lenovo:~/testrepo4/test-repo-ajan1$   
 ajanthan@ajanthan-Lenovo:~/testrepo4/test-repo-ajan1$ git diff test.json  
 diff --git a/test.json b/test.json  
 index e20351f..4adce1d 100644  
 --- a/test.json  
 +++ b/test.json  
 @@ -1,3 +1,3 @@  
  {  
 -"ajanthan":"test"  
 +"ajanthanee":"test"  
  }  
 ajanthan@ajanthan-Lenovo:~/testrepo4/test-repo-ajan1$   

Now going to commit the changes, before that check the URLs.
 ajanthan@ajanthan-Lenovo:~/testrepo4/test-repo-ajan1$ git remote -v  
 origin     https://github.com/ajanthanerepo/test-repo-ajan1.git (fetch)  
 origin     https://github.com/ajanthanerepo/test-repo-ajan1.git (push)  

 ajanthan@ajanthan-Lenovo:~/testrepo4/test-repo-ajan1$ git add test.json   
 ajanthan@ajanthan-Lenovo:~/testrepo4/test-repo-ajan1$ git commit -m "added by ajanth"  
 [master ee7a1c2] added by ajanth  
  1 file changed, 1 insertion(+), 1 deletion(-)  
 ajanthan@ajanthan-Lenovo:~/testrepo4/test-repo-ajan1$   

Now do the push.
 ajanthan@ajanthan-Lenovo:~/testrepo4/test-repo-ajan1$ git push  
 Username for 'https://github.com': ajanthan005@yahoo.com  
 Password for 'https://ajanthan005@yahoo.com@github.com':   
 Counting objects: 3, done.  
 Delta compression using up to 4 threads.  
 Compressing objects: 100% (2/2), done.  
 Writing objects: 100% (3/3), 300 bytes | 300.00 KiB/s, done.  
 Total 3 (delta 0), reused 0 (delta 0)  
 To https://github.com/ajanthanerepo/test-repo-ajan1.git  
   2d6bc85..ee7a1c2 master -> master  
 ajanthan@ajanthan-Lenovo:~/testrepo4/test-repo-ajan1$   

Consider that the ajanthanerepo2 has updated the file test.json. Due to that we need to update the local repository of ajanthanerepo. To do that we need to pull as below:
 ajanthan@ajanthan-Lenovo:~/testgitrepo$ git pull origin master  
 remote: Counting objects: 6, done.  
 remote: Compressing objects: 100% (4/4), done.  
 remote: Total 6 (delta 0), reused 3 (delta 0), pack-reused 0  
 Unpacking objects: 100% (6/6), done.  
 From https://github.com/ajanthanerepo/test-repo-ajan1  
  * branch      master   -> FETCH_HEAD  
   2d6bc85..c8cc9ef master   -> origin/master  
 Updating 2d6bc85..c8cc9ef  
 Fast-forward  
  test.json | 2 +-  
  1 file changed, 1 insertion(+), 1 deletion(-)  

To confirm we can do a cat and see the file content.
 ajanthan@ajanthan-Lenovo:~/testgitrepo$ cat test.json   
 {  
 "ajanthanee":"test-edited by repo2"  
 }  
 ajanthan@ajanthan-Lenovo:~/testgitrepo$   

Hope this helps someone who starts with GIT...

Sunday, January 21, 2018

How to make a SOAP call through curl

This article explains the way to invoke a SOAP service through curl command and this may be useful when isolationg the issues in an integration environment.
 curl -ivs -H "Content-Type: text/xml; charset=utf-8" -d @test.xml -w "@performance-format.txt" -X POST 'http://192.168.1.5/test.asmx'   

Here, test.xml will be the message body of the request.
 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">  
   <soapenv:Header/>  
   <soapenv:Body>  
    <test/>  
   </soapenv:Body>  
 </soapenv:Envelope>  

performance-format.txt will be as below, this is to find out the request-response time.
 -----------------------------------------\n  
 url_effective: %{url_effective}\n   
 http_code: %{http_code}\n   
 content_type: %{content_type}\n   
 time_namelookup: %{time_namelookup}\n   
 time_connect: %{time_connect}\n   
 time_appconnect: %{time_appconnect}\n   
 time_pretransfer: %{time_pretransfer}\n   
 time_redirect: %{time_redirect}\n   
 time_starttransfer: %{time_starttransfer}\n   
 ----------------------------------------\n   
 time_total: %{time_total}\n   
 ----------------------------------------\n   


For more information on performance-format please refer [1].

[1] http://ajanthane.blogspot.com/2017/08/calculating-request-and-response-time.html

Friday, January 19, 2018

Usage of YYYY and yyyy when retrieving the year in a last week of a Calendar Year with SYSTEM_DATE property in WSO2 ESB 5.0.0

Usage of YYYY and yyyy when retrieving the year in a last week of a Calendar Year with SYSTEM_DATE property in WSO2 ESB 5.0.0

This article explains the difference between year retrieved using the below two properties in WSO2 ESB.

1) <property name="YEAR" expression="get-property('SYSTEM_DATE', 'YYYY')"/>
   
2) <property name="year" expression="get-property('SYSTEM_DATE', 'yyyy')"/>

The sample proxy service used is as below:
 <?xml version="1.0" encoding="UTF-8"?>  
 <proxy xmlns="http://ws.apache.org/ns/synapse"  
     name="WeekYearTestProxy"  
     transports="https http"  
     startOnLoad="true">  
   <description/>  
   <target>  
    <inSequence>  
      <log level="custom">  
       <property name="YEAR" expression="get-property('SYSTEM_DATE', 'YYYY')"/>  
       <property name="year" expression="get-property('SYSTEM_DATE', 'yyyy')"/>  
      </log>  
    </inSequence>  
   </target>  
 </proxy>  


The output log of the above proxy will be as below on 31/12/2017.
When you use YYYY as the format, then you may get into an issue during a last week of year as for example in my case it was 31/12/2017. When this property retrieve the year, it will print it as 2018. Why this happens is because YYYY will return the Weekly based calendar year and how that is calculated is as below and refer [1] for more information.

[1] https://docs.oracle.com/javase/8/docs/api/java/util/GregorianCalendar.html#week_year

Consider, I'm running the sample proxy on 31/12/2017 and it is a Sunday. Based on [1], we need to check the what value set to FirstDayOfWeek and the other parameter we need to check is the MinimalDaysInFirstWeek. We can check both of this using the below sample code:
 import java.util.Calendar;  
 import java.util.GregorianCalendar;  
 import java.util.Locale;  
 public class Test{  
      public static void main(String[] args) {  
           Calendar c = new GregorianCalendar();  
           System.out.println(Locale.getDefault() + ": " + c.getFirstDayOfWeek() + " - " + c.getMinimalDaysInFirstWeek());  
      }  
 }  

Output of the above Java code segment will be as below:

Above output tells us that the first day of week is Sunday and Minimal days in first week is 1.

Below are extracted from [2] [3] to get more understanding on the methods used above.
[2] https://docs.oracle.com/javase/8/docs/api/java/util/Calendar.html#getMinimalDaysInFirstWeek--

getMinimalDaysInFirstWeek

Gets what the minimal days required in the first week of the year are; e.g., if the first week is defined as one that contains the first day of the first month of a year, this method returns 1. If the minimal days required must be a full week, this method returns 7.

[3] https://docs.oracle.com/javase/8/docs/api/java/util/Calendar.html#getFirstDayOfWeek--

getFirstDayOfWeek

Gets what the first day of the week is; e.g., SUNDAY in the U.S., MONDAY in France.

Based on the above definitions and our output.
FirstDayofWeek is Sunday and as getMinimalDaysInFirstWeek returns as 1, the first week is the one that contains the first day of the first month of the year. Due to that the first week starts from Sunday 31/12/2017, due to that when we use YYYY, the year that will be returned is 2018.

That's how the YYYY, get's 2018...

For more info refer below section in [1].



Friday, January 5, 2018

Splitting WSO2 wire enabled logs based on size and backup them to another folder

This article explains how we can split the log files based on size and also how we can move the backup files to another folder using shell script. When we use log4j configuration to split the file based on size, we have a limitation that there is a possibility that we may lose a particular backup file, as it works as below. To avoid that we need to create a backup script and that also provided in this article.

Consider we are setting as below:
log4j.appender.CARBON_LOGFILE.MaxFileSize=1MB
log4j.appender.CARBON_LOGFILE.MaxBackupIndex=5

It will keep only 5 backup files, when the 6th ( means the wso2carbon.log reached 1MB ), it will delete the 1st backup file created that will be wso2carbon.log.5 and reassign the order, like wise old ones will be deleted keeping the latest.

Below are the steps to follow:

1) Take a backup of the ESB_HOME/repository/conf/log4j.properties.
2) Enable the wire logs in log4j.properties

Uncomment the below lines:
 #log4j.logger.org.apache.synapse.transport.http.headers=DEBUG  
 #log4j.logger.org.apache.synapse.transport.http.wire=DEBUG  

3) Follow the instructions [1].
[1] https://docs.wso2.com/display/ADMIN44x/Monitoring+Logs
Change the log4j.appender.CARBON_LOGFILE=org.wso2.carbon.utils.logging.appenders.CarbonDailyRollingFileAppenderappender
in the <PRODUCT_HOME>/repository/conf/ log4j.properties file as follows:
 log4j.appender.CARBON_LOGFILE=org.apache.log4j.RollingFileAppender  

Add the following two properties under RollingFileAppender

 log4j.appender.CARBON_LOGFILE.MaxFileSize=100MB   
 log4j.appender.CARBON_LOGFILE.MaxBackupIndex=200  

4) Restart the Server.

Once done you can see the output inside ESB_HOME/repository/logs folder as below:



5) Configure the cron job to run the backup script.

 cd /etc/cron.daily/  
 chmod 755 wso2backuplogscript-esb.sh  

 #!/bin/bash  
 ESB_HOME="/home/ajanthan/log_split/wso2esb-5.0.0"  
 DIRECTORY="$ESB_HOME/repository/logs"  
 BACKUP_SRC_FILES="wso2carbon.log.*"  
 DESTINATION="$DIRECTORY/archivefolder"  
 TIME=`date "+%Y%m%d-%H%M%S"`  
 FILENAME=backup-wso2carbon.$TIME.tar.gz  
 echo "[`date '+%Y-%m-%d %H:%M:%S'`] Starting the backup process...\r\n" ;  
 echo "Source Directory : $DIRECTORY\n";  
 echo "Destination Directory : $DESTINATION\n";  
 if ls $DIRECTORY/$BACKUP_SRC_FILES 1> /dev/null 2>&1;  
     then  
         echo "[`date '+%Y-%m-%d %H:%M:%S'`] Files available for backup. \n";  
         cd $DIRECTORY && tar -cvpzf $DESTINATION/$FILENAME $BACKUP_SRC_FILES #create,verbose,preserve permission,zip,filename  
     if [ -f "$DESTINATION/$FILENAME" ]  
         then  
         #echo -e "Inside then...\n";  
         echo "[`date '+%Y-%m-%d %H:%M:%S'`] $DESTINATION/$FILENAME found.\n";  
         echo "[`date '+%Y-%m-%d %H:%M:%S'`] Starting to remove the files from Source : $BACKUP_SRC_FILES\r\n";  
         rm -fv $BACKUP_SRC_FILES;  #Avoiding the prompt for each file and also printing what are the files got removed by using -fv.  
         echo "[`date '+%Y-%m-%d %H:%M:%S'`] File removal END.\r\n";  
     else  
         #echo -e "Inside elsee...\n";  
         echo "[`date '+%Y-%m-%d %H:%M:%S'`] $DESTINATION/$FILENAME not found.\r\n";  
     fi  
 else  
     echo "[`date '+%Y-%m-%d %H:%M:%S'`] Files do not available for backup.\n";  
 fi  
 echo "\r\n[`date '+%Y-%m-%d %H:%M:%S'`] Ending the backup process...\r\n";  


6) Create a folder for the backup files

ESB_HOME/repository/logs/archivefolder
ESB_HOME/repository/logs/backupprocesslogs

7) Add new cron job to crontab:

crontab -e

For Testing

*/5 * * * * sh /etc/cron.daily/wso2backuplogscript-esb.sh >> ESB_HOME/repository/logs/backupprocesslogs/backup-$(date +\%Y-\%m-\%d-\%H-\%M-\%S).log 2>&1


8) Check the log at $ESB_HOME/repository/logs/backupprocesslogs-esb/
Check the backup files at $ESB_HOME/repository/logs/archive-esblogs

Also can check the process related log at ESB_HOME/repository/logs/backupprocesslogs. The sample output will be as below: