This documentation is for WSO2 CEP 2.1.0. View the home page of the latest release.

Build Analyzer

This sample demonstrates how complex event processor works for REST requests with Email Broker.

In this example CEP will receive a set of information regarding the build process and notify when build failure occurred in the the project "Complex Event Processor"

from buildfailStatisticsStream[status=='fail' and project=='Complex Event Processor']
			 insert into outbuildfailStream
			 userID ,timestamp, project,team , userName;
 

Prerequisites

  • Apache Ant to build & deploy the Sample & Service, and to run the client. Refer Installation Prerequisites for instructions to install Apache Ant. 
  • cURL to send REST request to CEP. cURL can be downloaded from http://curl.haxx.se/download.html.
  • (Optional) Edit the <CEP_HOME>/repository/conf/axis2/axis2_client.xml to use your Email account to send email notifications as mentioned in the "Configuring E-mail Broker" Section.

Here we will publish events using an REST API client and notifications are send using the email client.

Following is the configuration used in this sample.

BuildFailAnalysisBucket.xml
<?xml version="1.0" encoding="UTF-8"?>
<cep:bucket name="BuildFailAnalysisBucket" xmlns:cep="http://wso2.org/carbon/cep">
  <cep:description>Analyses build failures</cep:description>
  <cep:engineProviderConfiguration engineProvider="SiddhiCEPRuntime">
    <cep:property name="siddhi.persistence.snapshot.time.interval.minutes">0</cep:property>
    <cep:property name="siddhi.enable.distributed.processing">false</cep:property>
  </cep:engineProviderConfiguration>
  <cep:input brokerName="localAgentBroker" topic="buildfail_Statistics/1.3.2">
    <cep:tupleMapping queryEventType="Tuple" stream="buildfailStatisticsStream">
      <cep:property inputDataType="payloadData" inputName="timestamp"
        name="timestamp" type="java.lang.String"/> 
      <cep:property inputDataType="payloadData" inputName="status"
        name="status" type="java.lang.String"/>	
      <cep:property inputDataType="payloadData" inputName="userID"
        name="userID" type="java.lang.String"/>
      <cep:property inputDataType="payloadData" inputName="team"
        name="team" type="java.lang.String"/>
      <cep:property inputDataType="payloadData" inputName="project"
        name="project" type="java.lang.String"/>
      <cep:property inputDataType="payloadData" inputName="userName"
        name="userName" type="java.lang.String"/>
     </cep:tupleMapping>
  </cep:input>
  <cep:query name="BuildFailFilterQuery">
    <cep:expression><![CDATA[from buildfailStatisticsStream[status=='fail' and project=='Complex Event Processor']
			 insert into outbuildfailStream
			 userID ,timestamp, project,team , userName;]]></cep:expression>
    <cep:output brokerName="emailBroker" topic="wso2cep.demo@gmail.com/Build Failed">
      <cep:textMapping>There is a build failure in the Project - {project} of the Team - {team} at {timestamp}
Details of the build Failure : 
Person ID who responsible for build failure - {userID}
Name of the person who responsible for build failure - {userName}</cep:textMapping>
    </cep:output>
  </cep:query>
</cep:bucket>

Above file can be found, in Linux: cd <CEP_HOME>/samples/cep-samples/conf/buckets/BuildFailAnalysisBucket.xml

Configuring Topics for E-Mail Broker

The topic used when using e-mail broker will look like : <e-mail id>,<e-mail id>,...,<e-mail id>/<subject>

E.g.         admin@foo.com,user@bar.com/System Notification

In the above configuration we have set a default email address to send email notification. You have to change the email address to view the actual process of this example.

Change the "topic" attribute of the output tag  (<cep:output brokerName="emailBroker" topic="wso2cep.demo@gmail.com/Build Failed">)

  • Provide a valid email address(s) by changing the given default mail address. 

Deploying the Configurations

The steps are as follows :

  1. Install the WSO2 Complex Event Processor, but do not start the server,  Refer to the Installation and Deploymentfor instructions.
  2. In a command prompt, switch to the sample directory: <CEP_HOME>/samples/cep-samples 
    For example, in Linux: cd <CEP_HOME>/samples/cep-samples
  3. From there, type ant deploy-build,
    This will copy the broker-manager-config.xml to <CEP_HOME>/repository/conf directory and the bucket configuration to <CEP_HOME>/repository/deployment/server/cepbuckets directory.

Defining Stream in CEP engine

Here we are going to define events using the REST API with the help of curl commands.

Following file will post stream definitions  as the body of the POST request.

streamdefn1.json
{
	"name":"buildfail_Statistics",
	"version":"1.3.2",
	"nickName": "Analytics Statistics Information",
	"description": "Details of Analytics Statistics",
	"metaData":[
		{
			"name":"ipAdd","type":"STRING"
		}
	],
	"payloadData":[
		{
			"name":"userID","type":"STRING"
		},
		{
			"name":"timestamp","type":"STRING"
		},
		{
			"name":"userName","type":"STRING"
		},
		{
			"name":"project","type":"STRING"
		},
		{
			"name":"status","type":"STRING"
		},
		{
			"name":"team","type":"STRING"
		}
	]
}
  • Curl command for defining stream definition.
curl -k --user admin:admin https://localhost:9443/datareceiver/1.0.0/streams/ --data @streamdefn1.json -H "Accept: application/json" -H "Content-type: application/json" -X POST

You can see the server logs when defining the stream as shown in the below figure.

Defining events for stream

Now we need to pass events for above mentioned stream using the Rest API.

Following file will post events as the body of the POST request.

events1.json
[
    {
        "payloadData" : ["abc@org1.com", "120d", "abc", "Complex Event Processor", "fail", "Data Team"] ,
        "metaData" : ["192.168.1.1"]
    }
    ,
    {
        "payloadData" : ["anne@org2.com", "2342d", "anne", "Complex Event Processor", "fail", "Data Team"] ,
        "metaData" : ["192.168.1.1"]
    }
    ,
    {
        "payloadData" : ["sam@org1.com", "12414d", "sam", "Business Activity Monitor", "success", "Data Team"] ,
        "metaData" : ["192.168.1.3"]
    }
    ,
    {
        "payloadData" : ["anne@org1.com", "489d", "anne", "Business Activity Monitor", "success","Data Team"] ,
        "metaData" : ["192.168.1.2"]
    }
    ,
    {
        "payloadData" : ["ann@org3.com", "21324d", "anne", "Stratos", "fail","Platform Team"] ,
        "metaData" : ["192.168.1.3"]
    }
    ,
    {
        "payloadData" : ["paul@org3.com", "423d", "paul", "Application Server", "success","Development Team"] ,
        "metaData" : ["192.168.1.2"]
    }
    ,
    {
        "payloadData" : ["john@org1.com", "3324d", "john", "App Factory", "success","Solutions Team"] ,
        "metaData" : ["192.168.1.1"]
    }
    ,
    {
        "payloadData" : ["abraham@org1.com", "324d", "abraham", "Governance Registry", "success","Integration Team"] ,
        "metaData" : ["192.168.2.1"]
    }
    ,
    {
        "payloadData" : ["mathew@org1.com", "123d", "mathew", "Identity Server", "success","Integration Team"] ,
        "metaData" : ["192.168.3.1"]
    }
    ,
    {
        "payloadData" : ["suho@org1.com", "1432d", "suho", "Gadget Server", "success","Development Team"] ,
        "metaData" : ["192.168.1.1"]
    }
    ,
    {
        "payloadData" : ["tony@org1.com", "165d", "tony", "Enterprise Service Bus", "success","Integration Team"] ,
        "metaData" : ["192.168.2.1"]
    }
    ,
    {
        "payloadData" : ["helm@org1.com", "234d", "helm", "Enterprise Service Bus", "success","Integration Team"] ,
        "metaData" : ["192.168.1.3"]
    }
    ,
    {
        "payloadData" : ["greig@org1.com", "213d", "greig", "Complex Event Processor", "success","Data Team"] ,
        "metaData" : ["192.168.1.2"]
    }
]
  • Curl command to pass events for stream that mentioned in the streamdefn1.json

 

curl -k --user admin:admin https://localhost:9443/datareceiver/1.0.0/stream/buildfail_Statistics/1.3.2/ --data @events1.json -H "Accept: application/json" -H "Content-type: application/json" -X POST

Observation

Now you can see the email notifications in the mail box that you mentioned in above.

 

 

 

Copyright © WSO2 Inc. 2005-2014