Wednesday, March 9, 2016

Deploy WSO2 products on OpenShift v3

What is OpenShift ?
Simply it's a open-source platform as a service product. It allows to manage, deploy, monitor the applications.

What's new ?
OpenShift v3 is the latest version it also called as OpenShift origin. Mainly new version allows to deploy containers and orchestrate using help of  kubernetes.
OpenShift supports
  • Source-To-Image (S2I)
  • Template (JSON)
  • Container (Docker)
deployments. For this I'm using container based deployment.

Installing OpenShift

There is a openshift all in one vm  or It's available as a docker all in one container. I'm using the docker container for this. I'm using ubuntu 15.04v because ubuntu 14.04 have some known issues and the docker client and server versions are 1.9.1v.
Note: If you decided to use vagrant openshift all in one vm you can directly jump to "Deploying WSO2 products" step

To pull the origin image and start the container use
sudo docker run -d --name "origin" \
       --privileged --pid=host --net=host \
       -v /:/rootfs:ro -v /var/run:/var/run:rw -v /sys:/sys -v /var/lib/docker:/var/lib/docker:rw \
       -v /var/lib/origin/openshift.local.volumes:/var/lib/origin/openshift.local.volumes \
       openshift/origin start

Start the container
sudo docker exec -it origin bash

Configuring OpenShift

Before proceeding to next step there are some configurations need to be done. Openshift latest version use oc CLI.

First need to login as administrator, can use any password
oc login -u system:admin

OpenShift ships with a built in docker registry image, to configure and start a registry container use
oadm registry --credentials=./openshift.local.config/master/openshift-registry.kubeconfig

Deploying WSO2 products
Again you should login as a different user, in this case i will use noelyahan, can use any password you want
oc login -u noelyahan

Now we may need to create a project before add new applications
oc new-project wso2-products

Now it's time to deploy docker containers from image, I have pushed some docker images to my docker hub profile so you can simply use
oc new-app noelyahan/wso2-esb-openshift
oc new-app noelyahan/wso2-jaggery-openshift

You can use the openshift management console to monitor or control from ui, but still openshift cli allows to control everything such as scale up, scale down, log view, deployment status etc ..

To pull a container and start, it took several minutes for me but for spin up new pod it took less than a minute.

WSO2 ESB and WSO2 Jaggery running with multiple nodes

Overview of the deployment

One running container instance

Running container terminal log

Apply routing for service
Now service is running it's own private IP address, to access the service from the outside world we need to create a route.The docker containers exposing some ports 9443, 9763 that means we can map these target ports and create a new domain name that route to running services.

  • Go to Browse > Routes there's a option to create a route
  • WSO2 products are running on https that means when we need to create a secured route

Routing figure 1

Routing figure 2 : Adding a passthrough routing type

Accessing the service url through the routed url


Thursday, November 5, 2015

Debugging Dart Web Application with WebStrom

Debugging a Dart application is pretty much easy with WebStrome IDE. But there are several steps to follow

  • Install  JetBrains Chrome Extension (Later need to setup by providing the correct port and ip)
  • Open the web application with webstrome by clicking on the html page's browser icon (top right corner)

  • Most probably it'll open with host=> & port => 63343
  • Right click top of the JetBrains Chrome Extension -> Options

  • Change the Host and Port values and apply the changes
  • Now It's time to setup the Javascript Debugger in webstrom go to Run -> Debug -> Edit Configuration
  • Add Javascript Debugger with + icon
  • Add the web page URL to debug configurations
  • Ok Done ! Lets test a sample app and see
  • Make a break point anywhere in dart source code
  • Simply go to Run -> Debug Dart_Debug (in this case I gave this name)
  • It'll open the web application with new tab, when it'll hit the brakpoint it should work
    • Whoo Hoo !!!

Friday, August 14, 2015

WSO2 Multi-tenant Cache [JSR107 (JCache) v1.0.0 update]

Current Carbon-Kernel v4.4.0 caching is based on JCache v0.5. This Blog is about new JSR107 (JCache) v1.0 update in Carbon-Kernel based on new Hazelcast caching provider. 

  • What is JCache
  • Whats in latest JSR107 (JCache) in high level view
  • WSO2 Caching
  • New caching API changes in WSO2 Caching
  • Examples of new caching API

What is JCache ?
   Caching is proven method to increase scalability and performance. JCache (JSR 107) is a standard caching API for Java. It can keeps some data in low-latency data structures for some period.It provides an API to create and work with in-memory cache of objects. It allows to create, access, update and remove entries from caches.JCache API only provides set of high level components (interfaces) to work with caching other than thinking about the implementation of the caching

Some common use cases
  • Client side caching of Web service calls
  • Caching of expensive computations such as rendered images
  • Caching of data
  • Servlet response caching
  • Caching of domain object graphs

Latest JSR107 (JCache) in high level view

Caching Provider – used to control Caching Managers and can deal with several of them,
Cache Manager – deals with create, read, destroy operations on a Cache
Cache – stores entries (the actual data) and exposes CRUD interfaces to deal with the entries
Entry – abstraction on top of a key-value pair akin to a java.util.Map


WSO2 Caching
Core Features
  1. Local and distributed mode
  2. L1 and L2 caching model for distributed mode
  3. Multi-tenancy
Local and distributed mode: carbon kernel has 2 different jcache implementations called local and distributed, default it use local cache when the Axis2 clustering is enabled it use distributed cache.In jcache v0.5 for distributed map carbon-kernel used Hazelcast distributed maps but in new jcache v1.0 for distributed cache it use Hazelcast caches.

L1 and L2 caching model for distributed mode: In order to improve performance there are 2 types of caching models called L1(Level 1) and L2(Level 2) caching, L1 cache is implemented by HashMaps, and new L2 cache is implemented by Hazelcast cache (wrapper of jcache v1.0 API).Every first time it checks in L1 cache but if the value is located in the L2 cache, then the value is also stored in the L1 cache

Multi-tenancy: It can cache and provide tenant specific data and make it available in every and each cluster members.

Sequence diagram of L1 and L2 caching model

In the distributed mode, if a cache entry is removed, invalidated or changed then the Hazelcast Cache Entry listeners that registered will trigger on each and every Hazelcast cluster member, In that same time L1 cache and the L2 cache being removed or updated

Sequence diagram of remove item


New caching API changes in WSO2 Caching
  • In previous jcache version, to create a CacheManager object had to call CacheManagerFactory and parse the name to CacheManager
    • Caching.getCacheManagerFactory().getCacheManager("sampleCacheManager");

  • New version of jcache use CachingProvider to create CacheManager by parsing a URI(String) object
    • Caching.getCachingProvider().getCacheManager(new URI("sampleCacheManager"));

  • To create a custom cache with custom configuration no need to call createCacheBuilder() to and parse the configuraion object, now CacheManager can directly call getCache() by parsing a cacheName and CacheConfiguration object

  • Other than that the org.wso2.carbon.caching.impl.CacheImpl class distributedCache is changed to Hazelcast cache (v4.3) insted of using Hazelcast Maps
    • hazelcastCacheManager = DataHolder.getInstance().getHazelcastCacheManager();

  • Because the Hazelcast cache is distrbuted one, There's no need of having registered OSGI service called DistributedMapProvider so the service intarface has removed from the org.wso2.carbon.caching and also from the org.wso2.carbon.core.clustering.HazelcastDistributedMapProvider

  • Other API changes are done to
    • org.wso2.carbon.user.core
    • org.wso2.carbon.registry.core

Examples of new caching API

Example: Simple cache creation

Example: Using cache configuration with a custom cache expiry

Please feel free to test out the new jcache v1.0 implementation

Friday, April 3, 2015

Configure Apache ActiveMQ 5.10 and WSO2 CEP 3.1.0

Copy appropriate activemq jars to $CEP_HOME/repository/components/lib 

If you are using activemq-5.9.1, above 5.8.x you cannot find activemq-core-x.x.jar now it has been split into two jars activemq-broker-5.x and activemq-client-5.x. In order to configure you only need these 3 jars to copied inside lib.

1. activemq-client-5.x.jar

2. activemq-broker-5.x.jar

3. geronimo-j2ee-management.x.x.jar

To test the communication run [WSO2 CEP Sample 0002]

Monday, March 30, 2015

Send email from linux terminal

This is very use full for raspberry pi projects.Email temperature information, notify things when you not there.And the best thing is its really easy to configure.I'll go through step by step.

  1. First thing is to install ssmtp.
    • sudo apt-get install ssmtp
  2. Edit and add new configurations to ssmtp.conf file. 
    • nano /etc/ssmtp/ssmtp.conf [add new line or change current lines ]
      • hostname=localhost
      • UseTLS=Yes
      • AuthPass=your.password
      • UseSTARTTLS=Yes
      • FromLineOverride=YES
    • ctrl+O [nano save]
    • ctrl+X [nano exit]
  3. Install mailutils to send emails from terminal.
    • sudo apt-get install mailutils
    • Sending a test mail
      • echo "Email Body [Happy Coding]" | mail -s "Email Subject [Finally Done]"
  4. Possible errors and how to fix them.
    • mail: cannot send message: Process exited with a non-zero status
      • check the error log >> cat /var/log/mail.err or cat /var/log/mail.log
      • If its Authorization failed (xxxxxxxxxxxxxxxxxxxxxxxxxx)
    • sSMTP[1564]: Cannot open
      • To fix this change port 587 to -> port 465 in mailhub attribute in ssmtp.conf 

Sunday, February 8, 2015

Setting up an OpenGL C++ with eclipse IDE on Ubuntu/Linux OS

I'm currently using Linux 3.13.0-24-generic x86_64 kernel version of linux mint with OpenGL version of 2.1 Mesa 10.1.0 follow this link to check OpenGL version [link]

You need to go through only three steps
  1. Download OpenGL C++ libraries.
  2. Setup and install eclipse CDT bundle.
  3. Configure the eclipse libraries [simple].
  4. Test OpenGL application.

Download OpenGL C++ dependencies
  • In terminal use sudo apt-get install libglu1-mesa-dev freeglut3-dev

Setup and install eclipse CDT bundle

  • In eclipse Help > Install New Software
  • Add new cdt installation path
  • Tick CDT Main Features hit next and finish the process and restart the eclipse

Configure the eclipse libraries [simple]

  • In eclipse choose New > C++ Project

  • Right click the project > Properties
  • Select C/C++ Build > Settings > GCC C++ Linker > Libraries > +
  • Add glut, GL, GLU libraries
  • Time to test a OpenGL app

Test OpenGL application

  • Download this sample source code [link] 
  • Right click on project New > File create new c or cpp file and paste the code
  • Its best practice to always clean and build the cpp project to do that right click Clean Project, right click Build Project / ctrl+B
  • Right click on project Run As > Local C/C++ program
  • It should show a red 3d cube like this
  • Fun [HACK] make the cube rotate 
    • Replace this code snippet inside void display(void) function
    •  while (true) {  
            glRotatef(1.0f, 1.0f, 1.0f, 1.0f);  

Friday, December 5, 2014

Unity3D C# and JavaScript Communication

        Hmm.. problem is you have a code written in javascript and most of your codes written in c# and you really want to use javascript with your c# script or other way around. Is there way to do that. Of course you can. Unity3d has this special topic in their documentation [Special Folders and Script Compilation Order].

Simplified note
  • If you want to use javascript on your c# script javascript need to compile before the c# script.
  • There are some special folders to do that (compilation folder order)
    1. Standard Assets
    2. Pro Standard Assets
    3. Plugins
    4. Editor
    5. Other folders will compile last
  • Lets see a simple cube moving example for this c# and javascript communication.
Setting up the environment
  1. Add a cube game object
  2. Add a empty game object called JavaScriptComponent (This is for attach js)
  3. Add a folder name called Script (to put our calling scripts)
  4. Add a folder name called Standard Assets or Plugins (Any one of the special folder)

How to call a javascript from c# script

  • The JavaScript
  1. Go to Input.GetAxis documentation sample and grab the JS version of the code.
  2. Make the rotation & translation variables global.
  3. Add 2 public functions call getRotation(), getTranslation() that returns rotation & translation
  4. Save the script inside Standard Assets
  5. Attach this script to JavaScriptComponent empty gameobject
  6. Find the code snippet of the MoveScript.js
      //[code snippet from]
 // A very simplistic car driving on the x-z plane.
 var speed : float = 10.0;
 var rotationSpeed : float = 100.0;
 private var translation : float;
 private var rotation : float;
 function Update () {
  // Get the horizontal and vertical axis.
  // By default they are mapped to the arrow keys.
  // The value is in the range -1 to 1
  translation = Input.GetAxis ("Vertical") * speed;
  rotation = Input.GetAxis ("Horizontal") * rotationSpeed;
  // Make it move 10 meters per second instead of 10 meters per frame...
  translation *= Time.deltaTime;
  rotation *= Time.deltaTime;
 //We are going to access these 2 methods from csharp script
 public function getRotation(){
  return rotation;
 public function getTranslation(){
  return translation;
  • The CSharp Script
  1. So now we know which game object holds our javascript.
  2. Use GameObject.Find ("JavaScriptComponent").GetComponent<MoveScriptJs>();  this code to get the js script reference.
  3. Attach the script to the Cube game object
  4. Find the Player.cs code snippet.
using UnityEngine;
using System.Collections;

public class Player : MonoBehaviour {

 private MoveScriptJs javaScript;

 // Use this for initialization
 void Start () {
  javaScript = GameObject.Find ("JavaScriptComponent").GetComponent<MoveScriptJs>();
 // Update is called once per frame
 void Update () {
  // Move translation along the object's z-axis
  transform.Translate (0, 0, javaScript.getTranslation());
  // Rotate around our y-axis
  transform.Rotate (0, javaScript.getRotation(), 0);

Now you can run the scene and see cube can be rotate and move, Most part of the code is done by javascript. Only rotation and transform floating point values are applying to this game object vectors by using c# script.How cool is that. Yes I know, this is a stupid way to move a game object but I wanted to show a kinda complex example and in next tutorial I want to show how to use the unity standard asset mobile joystick with c# script. The problem is unity ships this joystick assets with only javascript so how do we use this for mobile game that programmed using c# ? I know if you had follow this tutorial properly you can do it alone :) #happyCoding

Download the unity3d project [link]