Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Info

To view a screencast of the Quick Start Guide, click here.

...

  1. Log into the CEP Management Console and click on the Main tab. Under Manage, click Streams to open the Available Event Streams page. 
  2. Click Add Event Stream to open the Define New Event Stream page. 
  3. Enter information as follows to create a new event stream named org.wso2.event.sensor.stream.

    Event Stream Details

    Parameter NameValue
    Event Stream Nameorg.wso2.event.sensor.stream
    Event Stream Version1.0.0

    Stream Attributes

    Click Add to add the attribute after entering the attribute name and attribute type.

    Attribute CategoryAttributeAttribute Type
    Meta Datatimestamplong
     

    isPowerSaverEnabledbool
     

    sensorIdint
     

    sensorNamestring
    Correlation Datalongitudedouble
     

    latitudedouble
    Payload Datahumidityfloat
     

    sensorValuedouble
  4. Click Add Event Stream to save the information.

...

  1. Log into the CEP Management Console and click on the Main tab. Under Manage, click Receivers to open the Available Receivers page.
  2. Click Add Event Receiver to open the Create a New Event Receiver page.
  3. Enter information as follows to create the new event receiver named httpReceiver.

    Parameter NameValue
    Event Receiver NamehttpReceiver
    Input Event Adapter Typehttp
    Transportsall
    Event Streamorg.wso2.event.sensor.stream
    Message Formatjson
  4. Click Add Event Receiver to save the information.

...

  1. Log into the CEP Management Console and click on the Main tab. Under Manage, click Publishers to open the Available Publishers page.
  2. Click Add Event Publisher to open the Create a New Event Publisher page.
  3. Enter information as follows to create the new event publisher named  loggerPublisher.

    Parameter NameDescription
    Event Publisher NameloggerPublisher
    Event Sourceorg.wso2.event.sensor.stream
    Output Event Adapter Typelogger
    Message Formattext


  4. Click Add Event Publisher to save the information.

...

  1. Log into the CEP Management Console and click on the Main tab. Under Manage, click Streams to open the Available Event Streams page. 
  2. Click Add Event Stream to open the Define New Event Stream page. 
  3. Enter information as follows to create the event stream named org.wso2.event.sensor.filtered.stream.

    Event Stream Details

    Paramater NameValue
    Event Stream Nameorg.wso2.event.sensor.filtered.stream
    Event Stream Version1.0.0

    Stream Attributes

    Attribute CategoryAttributeAttribute Type
    Meta Datetimestamplong
     

    sensorNamestring
    Correlation Datalongitudedouble
     

    latitudedouble
    Payload DatasensorValuedouble
  4. Click Add Event Stream to save the information.

...

An Execution Plan can import one or more streams from the server for processing and push zero or more output streams back to the server. Refer Processing Events for further explanationsFor more information, see Analyzing Data.

  1. Log into the CEP Management Console and click on the Main tab. Under Manage, click Execution Plans to open the Available Execution Plans page. 
  2. Click Add Execution Plan to open the Create a New Execution Plan page.
  3. Enter information as follows to create the new execution plan

    Parameter NameValue
    Import Streamorg.wso2.event.sensor.stream:1.0.0
    AssensorStream
    Value OffilteredStream
    StreamIdorg.wso2.event.sensor.filtered.stream:1.0.0
  4. Click Import and then click Export. The section for query expressions will be updated as shown below.
  5. Add the following query expression.

    Anchor
    filter
    filter

    Code Block
    from sensorStream [sensorValue > 100]
                    select meta_timestamp, meta_sensorName, correlation_longitude, correlation_latitude, sensorValue
                    insert into filteredStream

    This query includes the value sensorValue > 100. Therefore, when the execution plan forwards events from org.wso2.event.sensor.stream:1.0.0  to org.wso2.event.sensor.filtered.stream:1.0.0, events in which the value for the sensorValue attribute is less than 100 will be dropped.

  6. Click Validate  Query Expressions. Once you get a message to confirm that the queries are valid, click Add Execution Plan.

...

  1. Log into the CEP Management Console and click on the Main tab. Under Manage, click Publishers to open the Available Publishers page.
  2. Click Add Event Publisher to open the Create a New Event Publisher page.
  3. Enter information as follows to create the new event publisher named UIPublisher.

    Parameter NameDescription
    Event Publisher NameuiPublisher
    Event Sourceorg.wso2.event.sensor.filtered.stream:1.0.0
    Output Event Adapter Typeui
    Message Formatwso2event
  4. Click Add Event Publisher to save the information.

Step 9: Create a dashboard and a gadget

WSO2 Analytics Dashboard will be used as the tool to analyse the output of the event flow you created in this guide. This step creates a dashboard and a gadget which analyses events from the  org.wso2.event.sensor.filtered.stream stream published by the uiPublisher publisher.

  1. Log into the CEP Management Console. In the Main tab, click Analytics Dashboard.
  2. Log into the Analytics Dashboard with your username and password.
  3. Click the menu icon and then click Gadgets to open the Gadgets page as demonstrated below.
    Image Modified
  4. Click GENERATE GADGET, and enter values in the Generate a Gadget wizard as follows.Image Modified
    1. In the Select Provider field, select Realtime Data Source. Then click Next.
    2. In the Event Stream field, select org.wso2.event.sensor.filtered.stream:1.0.0. Then click Next.
    3. Configure a chart as follows.

      Parameter NameValue
      Gadget NameSensor Value VS Timestamp
      Select Chart TypeLine Chart
      X-AxisTIMESTAMP
      X typetime
      Y-AxissensorValue
      Y typedefault
      Color domainsensorName
      Max length30
    4. Click Add to Store, and then click Go to Portal. the Dashboards page appears again.
  5. Click CREATE DASHBOARD to open the Create a Dashboard page. Configure a new dashboard as follows.Image Modified
    1. Enter a name and a description for the new dashboard as follows, and click Next.

      Parameter NameValue
      Name of your DashboardSensor Statistics
      DescriptionThis dashboard indicates the sensor value at different times in a particular location.
    2. Select the Single Column layout. A message appears to indicate that the dashboard is successfully created.
    3. Click the  icon for gadgets. Then select and drag Sensor Value VS Timestamp gadget to the first column as demonstrated above.

Step 10: Send Events to the HTTP Receiver via Curl Command

...

Code Block
languagexml
<?xml version="1.0"?>
<!--
  ~ Copyright (c) 2016, 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.
  -->

<domain name="SensorStatistics">
    <description>Domain for sensor data analysis</description>
    <scenarios>
        <scenario type="AnalyzeSensorStatistics">
            <description>Configure a sensor analytics scenario to display statistics for a given stream of your choice
            </description>
            <templates>
                <!--Note: These will be deployed in the order they appear here-->
                <!-- Input Event Stream-->
                <template type="eventstream">
                  {
                    "streamId": "org.wso2.event.sensor.stream:1.0.0",
                    "name": "org.wso2.event.sensor.stream",
                    "version": "1.0.0",
                    "nickName": "",
                    "description": "",
                    "metaData": [
                      {
                        "name": "timestamp",
                        "type": "LONG"
                      },
                      {
                        "name": "isPowerSaverEnabled",
                        "type": "BOOL"
                      },
                      {
                        "name": "sensorId",
                        "type": "INT"
                      },
                      {
                        "name": "sensorName",
                        "type": "STRING"
                      }
                    ],
                    "correlationData": [
                      {
                        "name": "longitude",
                        "type": "DOUBLE"
                      },
                      {
                        "name": "latitude",
                        "type": "DOUBLE"
                      }
                    ],
                    "payloadData": [
                      {
                        "name": "humidity",
                        "type": "FLOAT"
                      },
                      {
                        "name": "sensorValue",
                        "type": "DOUBLE"
                      }
                    ]
                  }
                </template>
                <!-- Output Event Stream-->
                <template type="eventstream">
                  {
                    "streamId": "org.wso2.event.sensor.filtered.stream:1.0.0",
                    "name": "org.wso2.event.sensor.filtered.stream",
                    "version": "1.0.0",
                    "nickName": "",
                    "description": "",
                    "metaData": [
                      {
                        "name": "timestamp",
                        "type": "LONG"
                      },
                      {
                        "name": "sensorName",
                        "type": "STRING"
                      }
                    ],
                    "correlationData": [
                      {
                        "name": "longitude",
                        "type": "DOUBLE"
                      },
                      {
                        "name": "latitude",
                        "type": "DOUBLE"
                      }
                    ],
                    "payloadData": [
                      {
                        "name": "sensorValue",
                        "type": "DOUBLE"
                      }
                    ]
                  }

                </template>
                <!-- Realtime Execution Plan-->
                <template type="realtime">
                    <![CDATA[
                    /* Enter a unique ExecutionPlan */
                    @Plan:name('ExecutionPlan')
                    /* Enter a unique description for ExecutionPlan */
                    -- @Plan:description('ExecutionPlan')
                    /* define streams/tables and write queries here ... */
                    @Import('org.wso2.event.sensor.stream:1.0.0')
                    define stream sensorStream (meta_timestamp long, meta_isPowerSaverEnabled bool, 
                        meta_sensorId int, meta_sensorName string, correlation_longitude double, correlation_latitude double, 
                        humidity float, sensorValue double);
                    @Export('org.wso2.event.sensor.filtered.stream:1.0.0')
                    define stream filteredStream (meta_timestamp long, meta_sensorName string, correlation_longitude double, 
                        correlation_latitude double, sensorValue double);
                    from sensorStream [sensorValue > $filteringVal$sensorValue]
                    select meta_timestamp, meta_sensorName, correlation_longitude, correlation_latitude, sensorValue
                    insert into filteredStream
                     ]]>
                </template>
                <template type="eventreceiver">
                  <![CDATA[
                  <?xml version="1.0" encoding="UTF-8"?>
                    <eventReceiver name="httpReceiver" statistics="disable" trace="disable" xmlns="http://wso2.org/carbon/eventreceiver">
                        <from eventAdapterType="http">
                            <property name="basicAuthEnabled">true</property>
                            <property name="transports">all</property>
                        </from>
                        <mapping customMapping="disable" type="json"/>
                        <to streamName="org.wso2.event.sensor.stream" version="1.0.0"/>
                    </eventReceiver>]]>
                  </template>
                <!-- Event Publisher-->
                <template type="eventpublisher">
                    <![CDATA[
                    <?xml version="1.0" encoding="UTF-8"?>
                    <eventPublisher name="loggerPublisher" statistics="disable"
                      trace="disable" xmlns="http://wso2.org/carbon/eventpublisher">
                      <from streamName="org.wso2.event.sensor.stream" version="1.0.0"/>
                      <mapping customMapping="disable" type="text"/>
                      <to eventAdapterType="logger"/>
                    </eventPublisher>
                        ]]>
                </template>
                <template type="eventpublisher">
                    <![CDATA[
                    <?xml version="1.0" encoding="UTF-8"?>
                    <eventPublisher name="uiPublisher" statistics="disable" trace="disable" xmlns="http://wso2.org/carbon/eventpublisher">
                      <from streamName="org.wso2.event.sensor.filtered.stream" version="1.0.0"/>
                      <mapping customMapping="disable" type="wso2event"/>
                      <to eventAdapterType="ui"/>
                    </eventPublisher>
                        ]]>
                </template>
                <!-- Gadget line chart -->
                <template type="gadget">
                    <config>
                        <properties>
                            <property name="directoryName">$sensorType-line-chart</property>
                            <property name="templateDirectory">lineChart</property>
                        </properties>
                        <artifacts>
                            <artifact file="gadget.json">
                                <![CDATA[
                                	{
                                    	"id": "$sensorType-line-chart",
                                    	"title": "$sensorType-line-chart",
                                    	"type": "gadget",
                                    	"thumbnail": "gadget/$sensorType-line-chart/thumbnail.png",
                                    	"data": {
                                        	"url": "gadget/$sensorType-line-chart/gadget.xml"
                                    	}
                                	}                        
								]]>
                            </artifact>
                            <artifact file="conf.json">
                                <![CDATA[
                                	{
										"provider-conf" : {
											"streamName" : "org.wso2.event.sensor.filtered.stream:1.0.0", 
											"provider-name" : "realtime"
										}, 
										"chart-conf" : {
											"x" : "TIMESTAMP", 
											"xType" : "time", 
											"y" : "sensorValue", 
											"yType" : "default", 
											"color" : "sensorName", 
											"maxLength" : "30", 
											"gadget-name" : "$sensorType-line-chart", 
											"chart-name" : "line-chart"
										}
									}
                                ]]>
                            </artifact>
                            <artifact file="js/core/gadget-util.js">
                                <![CDATA[
                                        var getGadgetLocation = function (callback) {
                                        var gadgetLocation = "/portal/store/carbon.super/fs/gadget/$sensorType-line-chart";
                                        var PATH_SEPERATOR = "/";
                                        if (gadgetLocation.search("store") != -1) {
                                            wso2.gadgets.identity.getTenantDomain(function (tenantDomain) {
                                                var gadgetPath = gadgetLocation.split(PATH_SEPERATOR);
                                                var modifiedPath = '';
                                                for (var i = 1; i < gadgetPath.length; i++) {
                                                    if (i === 3) {
                                                        modifiedPath = modifiedPath.concat(PATH_SEPERATOR, tenantDomain);
                                                    } else {
                                                        modifiedPath = modifiedPath.concat(PATH_SEPERATOR, gadgetPath[i])
                                                    }
                                                }
                                                callback(modifiedPath);
                                            });
                                        } else {
                                            callback(gadgetLocation);
                                        }
                                    }
                             
                                ]]>
                            </artifact>
                        </artifacts>
                    </config>
                </template>
                <!-- Gadget line chart -->
                <!-- Dashboard -->
                <template type="dashboard">
                    <config>
                        <properties>
                            <property name="dashboardId">analytics-$sensorType-dashboard</property>
                        </properties>
                        <content>
						<![CDATA[
                            {
  								"id": "analytics-$sensorType-dashboard",
  								"title": "Analytics $sensorType Dashboard",
  								"description": "This dashboard indicates the sensor value at different times in a particular location",
  								"permissions": {
    								"viewers": [
      									"Internal\/sensor-statistics-viewer"
    								],
    								"editors": [
      									"Internal\/sensor-statistics-editor"
    								],
    								"owners": [
      									"Internal\/sensor-statistics-owner"
    								]
  								},
  								"pages": [
    								{
      									"id": "landing",
      									"title": "Home",
      									"layout": {
        									"content": {
          										"loggedIn": {
            										"blocks": [
              											{
                											"id": "90dfe9100dc10dca1ae562e7f7451a4a",
                											"x": 0,
                											"y": 0,
                											"width": 12,
                											"height": 3,
                											"banner": false
              											}
            										]
          										}
        									},
        								"fluidLayout": false
      								},
      								"isanon": false,
      								"content": {
        								"default": {
          									"90dfe9100dc10dca1ae562e7f7451a4a": [
            									{
              										"id": "$sensorType-line-chart-0",
              										"content": {
                										"id": "$sensorType-line-chart",
                										"title": "$sensorType-line-chart",
                										"type": "gadget",
                										"thumbnail": "fs:\/\/gadget\/$sensorType-line-chart\/thumbnail.png",
                										"data": {
                  											"url": "fs:\/\/gadget\/$sensorType-line-chart\/gadget.xml"
                										},
                										"styles": {
                  											"title": "$sensorType-line-chart",
                  											"borders": true
                										},
                										"options": {
                  											"windowSize": {
                    											"type": "STRING",
                    											"title": "Window Size",
                    											"value": "10",
                    											"options": [
                      	
                    											],
                    											"required": false
                  											}
                										},
                										"locale_titles": {
                  
                										}
              										}
            									}
          									]
        								},
        								"anon": {
          
        								}
      								}
    							}
  							],
  							"menu": [
    							{
      								"id": "landing",
      								"isanon": false,
      								"ishidden": false,
      								"title": "Home",
      								"subordinates": [
        
      								]
    							}
  							],
  							"hideAllMenuItems": false,
  							"identityServerUrl": "",
  							"accessTokenUrl": "",
  							"apiKey": "",
  							"apiSecret": "",
  							"theme": "Default Theme",
  							"shareDashboard": false,
  							"isUserCustom": false,
  							"isEditorEnable": true,
  							"banner": {
    							"globalBannerExists": false,
    							"customBannerExists": false
  							},
  							"landing": "landing",
  							"isanon": false
						}
                         ]]>						
						</content>
                    </config>
                </template>
            </templates>
            <parameters>
                <parameter name="filteringVal" type="string">
                    <displayName>Filtering Value</displayName>
                    <description>Only the sensor values below filtering value will be dropped</description>
                    <defaultValue>100</defaultValue>
                </parameter>
				<parameter name="sensorType" type="string">
                    <displayName>Sensor Type Name</displayName>
                    <description>The name of the sensor type</description>
                    <defaultValue>temperature</defaultValue>
                </parameter>
            </parameters>
        </scenario>
    </scenarios>
</domain>

...

Note

Before you carry out this step

  1.  Copy Sensor Value VS Timestamp gadget which resides in  {PRODUCT_HOME}/repository/deployment/server/jaggeryapps/portal/store/carbon.super/fs/gadget/ and copy the folder to wso2cep-4.2.0/repository/conf/template-manager/gadget-templates and rename it as lineChart
  2. delete the following artifacts that you have already configured in steps 1 - 9.
    • org.wso2.event.sensor.stream event stream
    • org.wso2.event.sensor.filtered.stream event stream
    • httpReceiver event receiver
    • ExecutionPlan execution plan
    • loggerPublisher event publisher
    • uiPublisher event publisher
    • Sensor Value VS Timestamp gadget

    • Sensor Statistics dashboard
 


This step involves adding execution plan and stream configurations using the template you created and added in the previous step.

  1. If the CEP server was running when you created and deployed the template, restart the CEP server. 
  2. Log into the CEP Management Console. Click the Main tab and then click Template Manager. Create a new scenario as demonstrated below.
    1. Click on SensorStatistics to open the Deployed Scenarios page. Then click Create New Scenario to open the Edit Scenario page.
    2. Enter information as shown in the table below and click Add scenario.

      Parameter NameValue
      Scenario TypeAnalyzeSensorStatistics
      Scenario NameFilterSensorValues
      DescriptionFilter events with a sensor value greater than 120
      Sensor Value120

       A message appears to inform you that the scenario is successfully created. Close the message. The scenario you configured is displayed in the Deployed Scenarios page

...

The following is a summary of this guide which describes each element in the event flow.

ElementTypeRole
httpReceiverEvent ReceiverReceives CEP events in multiple formats and converts them all into the WSO2 Event format before forwarding them to the org.wso2.event.sensor.stream:1.0.0 event stream.
org.wso2.event.sensor.stream:1.0.0:Event StreamDefines the attributes on which selection of events to be processed by the event flow is based.
loggerPublisherEvent PublisherLogs events from the org.wso2.event.sensor.stream:1.0.0 event stream in the CEP CLI.
ExecutionPlanExecution PlanApplies a filter criteria to events in the org.wso2.event.sensor.stream:1.0.0 event stream and forwards the filtered events to org.wso2.event.sensor.filtered.stream:1.0.0 event stream.
SensorStatistics-FilterSensorValuesExecution PlanThis is an execution plan created from a template.
org.wso2.event.sensor.filtered.stream:1.0.0Event StreamImports attributes from the org.wso2.event.sensor.stream:1.0.0 event stream and receives events filtered from that event stream by the execution plan.
uiPublisherEvent PublisherPublishes events from the org.wso2.event.sensor.filtered.stream:1.0.0 event stream in the Analytics Dashboard.