Pages

Monday, May 16, 2016

JSON variable ussage within BPMN processes in WSO2 BPS v3.5.0 and v3.5.1

ATM Activiti provides JSON as a data type.

Creating/Updating/Reading JSON variables

  1. Java Service Task


Within java service task we can create JsonNode (com.fasterxml.jackson.databind.JsonNode) and set the variable.


String jsonString =  "{"
                +"\"id\": 1,"
                +"\"name\" : {\"first\" : \"Yong\",\"last\" : \"Mook Kim\"},"
                +"\"priority\" : 5"
                +"}";
ObjectMapper mapper = new ObjectMapper();
JsonNode root = mapper.readTree(jsonString);
execution.createVariableLocal("testJsonVar", root);

  1. An Expression

Within expressions, We can query content using functionalities provided in Jackson library.

<sequenceFlow id="flow4" sourceRef="exclusivegateway1" targetRef="usertask3">
  <conditionExpression xsi:type="tFormalExpression">
     <![CDATA[${testJsonVar.get("priority").asInt() > 10}]]>
  </conditionExpression>
</sequenceFlow>
  1. BPMN REST API

From REST API side, we cannot set JSON variable over BPMN Rest API. But possible to add that functionality by creating variable converters for JSON in REST API in WSO2 BPS v3.5.0 and v3.5.1.
  1. Script Task

Can read JSON variables and manipulate, but cannot set JSON variables within a script in WSO2 BPS v3.5.0 and v3.5.1

Saturday, April 30, 2016

Setting up hot deployment for rules stored in registry in WSO2 BRS [Business Rule Server]

In most WSO2 products, we refer registry artifact instead packaging deployment artifacts in single CAPP when we need governance facilities over those artifacts. For example, more commonly we store WSO2 ESB Synapse Configuration of a sequence as a resource (or we can call registry artifact) and refer it in main Synapse configuration.

Likewise for WSO2 BRS rule services, we can store rules in the registry and refer them in rule service descriptor (.rsl file).

Simplest Method Of using registry artifacts

In such usage, in most cases in run-time, we read it, keep in cache, and reload when cache get invalidated. Therefore, when registry resource gets updated, it will affect to the run-time when cache gets invalidated.

Issue above method in case of rule service in WSO2 BRS

During rule service deployment, the rules in forms of .drl, .xls, .csv files, Inline or registry artifacts were read and inject those rules and build DroolsKnowledgeBase, since that is expensive process BRS cannot follow simple caching procedure.

There are two methods to update rules in run-time (without redeploying rule service)  rule service when registry resource get updated.

01. Manual method 

Publish message to relevant topic related to the registry resource.
Go to Main Tab click "Browse" under Topics. Then navigate to relavent topic (if your registry artifact path is gov:sharedRules/test then the topic resource path will be /registry/notifications/ResourceUpdated/_system/governance/sharedRules/test).

Click "details" to get details view.


02. Automatically updating rules

With this method when you update registry resources, relavent KnowledgeBases of each related rule services get reloasded. For achieve this, you have to little bit fiddle with WSO2 feature installation. But worth it, and this is kind of best useful way to update rules in run-time without un-deploying/redeploying rule service in production environment.

You just need to install following three features to WSO2 BRS:

  1. Apache Axis2 - Mail Transport -version1.1.0.wso2v17
  2. Registry Community Features - version 4.4.8
  3. Registry Handler Config - version 4.4.8
Note : Refer [1] to find how to install features for wso2 brs

This is tested in WSO2 BRS v2.2.0

[1] https://docs.wso2.com/display/BRS220/Installing+Features

Sunday, March 20, 2016

Monitor WSO2 cluster using Hazelcast mancenter

All wso2 servers use hazelcast for clustering at the moment.

Hazelcast provide ootb tool to monitor in memory data grid called "mancenter" or "Management Center"[1]. It's really cool tool to try out and have in your system. You can use it to monitor wso2 server clusters with simple configuration step. Unfortunately free version of it only can handle 2 nodes. But fortunately, they provide a free 1-month trial key for evaluation. You can apply for evaluation version from [2].

Follow simple steps to monitor wso2 cluster:
  1. Download hazelcast from [3].
  2. Extract and you can find mancenter.war at <extracted_dir>/hazelcast-3.5.2/mancenter.
  3. Deploy it in Tomcat by copying it to <TOMCAT_HOME>/webapps and start tomcat server if not already started.
  4. You can find mancenter by following URL http://localhost:<tomcat port>/mancenter.
  5. Update clustering configuration of WSO2 product.
    • Open <PRODUCT_HOME>/repository/conf/axis2/axis2.xml using your favourite text editor and update "mgtCenterURL" parameter under "clustering" element as follows:

  6. Start WSO2 servers. Refer WSO2 Clustering and Deployement Guide [4] if you need information about WSO2 product clustering.
  7. Then goto mancenter url (refresh if you already loaded), and login with username : admin and password : admin
  8. After you login you have to select the relevant cluster domain and click "connect"
  9. The Management Center Dashboard will be as follows. It lists all the nodes in the cluster and statistics.
  10. And also you can monitor all the runtime information suchas memory ussage, load average, etc. of each node.




[1] https://hazelcast.com/products/management-center/
[2] https://hazelcast.com/hazelcast-enterprise-download/trial/
[3] http://hazelcast.org/download/
[4] https://docs.wso2.com/display/CLUSTER44x/WSO2+Clustering+and+Deployment+Guide

Monday, February 29, 2016

Start BPMN Process by Listening to a Message Queue



There are several types of start events available in BPMN. First of all if you are not much familiar with BPMN processes here is some summary information about Start events, summarized from BPMN specification

Start Enevts

  • The Start Event simply indicates where the process start (entry points to process)
  • When trigger for start event occurs, a new process instance get created
  • There are 7 types of start events for top-level BPMN processes: None, Message, Timer, Conditional, Signal, Multiple, and Parallel





  • All the start events, except None Start Event, only applicable to processes used as top level process. None Start Event may used to invoke process from Call Activity
Now we will concentrate main topic of this post

Start BPMN Process by Listening to a Message Queue/Topic

WSO2 BPS 3.5.0/3.5.1 do not support starting bpmn process by listening to a message queue. But that feature will be available OOTB in a future release. At the moment we have to achieve that with the help of WSO2 ESB.

Things you need:
  1. WSO2 Enterprise Service Bus (WSO2 ESB 4.9.0 used for this post)
  2. WSO2 Business Process Server (WSO2 BPS 3.5.1 used for this post. You must have BPS 3.5.0 or higher version for BPMN support)
  3. ActiveMQ (5.12.0 used for this post or you can use WSO2 Message Broker too)

Architecture diagram




BPMNProcess_start_proxy is ESB proxy that consumes messages from the queue, create relevant message to start the bpmn process and make REST call to start the bpmn process. In this case ESB acts as message consumer of the queue.

Step 01 : Create BPMN process 

Follow [1] for basic guide to create BPMN process

Here is the BPMN process that I'm going to use


You can download it from [2]

This sample process shows approval process for placing a stock order. If the entire investment is greater that $100,000 and administrator should approve it.

Stem 02 : Configure WSO2 ESB

  • First you have to enable JMS transport of WSO2 ESB. You can find instruction in [3] to configure WSO2 ESB for ActiveMQ and [4] for WSO2 Message Broker. Refer [5] for other popular massage brokers.
  • Create BPMNProcess_start_proxy proxy service
    • This proxy service receive stock order message and start order approval BPMN process deployed in WSO2 BPS. The proxy extract relevent information and create JSON request including those data as variables and invoke BPMN REST API available in WSO2 BPS.

Step 03 : Start Servers

Start ActiveMQ
Start WSO2 ESB (default port, portOffset=0, 9443)
Start WSO2 BPS (portOffset=1, 9444): start $ sh bin/wso2server.sh -DportOffset=1

Step 04 : Make Stock order 

Make Stock order request to "StockOrderInQueue" message queue
Execute StockQuote Client : navigate to /samples/axis2Client and execute following command

ant stockquote -Dmode=placeorder -Dtrpurl="jms:/StockOrderInQueue?transport.jms.ConnectionFactoryJNDIName=QueueConnectionFactory&java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory&java.naming.provider.url=tcp://localhost:61616&transport.jms.ContentTypeProperty=Content-Type&transport.jms.DestinationType=queue"

User tasks can be completed using bpmn-explorer webapp (https://localhost:9444/bpmn-explorer) and login as ‘admin’

As shown above you can start BPMN process by listening to message queue. By integration with WSO2 ESB you can start BPMN process, using any type of transport that WSO2 ESB support for example: JMS, Kafka[6].

References:
[1] https://docs.wso2.com/display/BPS350/BPMN+Guide
[2] https://github.com/milindaperera/MilisLogBlog/tree/master/WSO2BPS/BPMN/BPMN_ESB_MQ_Integration
[3] https://docs.wso2.com/display/ESB490/Configure+with+ActiveMQ
[4] https://docs.wso2.com/display/ESB490/Configure+with+WSO2+Message+Broker
[5] https://docs.wso2.com/display/ESB490/Configuring+JMS+Transport
[6] https://docs.wso2.com/display/ESB490/Kafka+Inbound+Protocol

If this post is useful to you, any questions, corrections or for any suggestion, please leave a comment below :)

Thursday, January 28, 2016

Reset default superuser password of PostgreSQL database

If you forgot the password of the PostgreSQL database, you can reset it by following below steps:

Start PSQL terminal with following command
$sudo -u postgres psql postgres

Then run following command and will ask to enter new password:
# \password postgres

Enter new password:
 

This method is tested with PostgreSQL 9.1.12

Wednesday, January 13, 2016

Mount Windows shared file in Linux

This post mainly focus on how to mount windows shared file in Linux.

"mount" command [1] is used to attach file systems  (located on an attached device or in network) to the file system tree at specified node.

To mount network shared file, the format of the command with most basic options as follows:

mount -t <type> //<hostname>/<shared_name> <path_to_mount_point>

type: File-system type. In this case cifs (Common Internet File System is variation of SMB protocol developed by Microsoft and native file sharing protocol used in Windows for more information refer [2])
hostname: Host name of the server (or ip address)
shared_name : Name of the shared directory/file
path_to_mount_point : path to the directory that shared file system should be mounted to file system tree

eg:
sudo mount -t cifs //10.100.5.92/TempShareDoc ~/Documents/share/ -v

If you need to mount password protected shared file, you can add those information as options username and password as follows
mount -t <type> -o username=<user_name>,password=<password> //<hostname>/<shared_name> <path_to_mount_point>

Also we can set the permissions of the mounted file system using dir_mode (directory permissions) and file_mode (directory permissions) options, as follows
mount -t <type> -o dir_mode=<permissions>,file_mode=<permissions> //<hostname>/<shared_name> <path_to_mount_point>

eg: 
sudo mount -t cifs -o dir_mode=0755,file_mode=0755  //10.100.5.92/TempShareDoc ~/Documents/share/ -v


[1] http://linux.die.net/man/8/mount
[2] https://technet.microsoft.com/en-us/library/cc939973.aspx