Вы находитесь на странице: 1из 71

Labkit

for
WSO2 Data Analytics Server 3.1.0
Developer Fundamentals

Email​: ​training@wso2.com

​CC BY 4.0                                      ​You are free to share and adapt for any purpose, even commercially.


Lab: Getting Started with WSO2 Data Analytics Server

Lab: Defining Event Streams

Lab: Creating Event Receivers

Lab: Creating Event Publishers

Lab: Creating Execution Plans

Lab: Viewing the Event Flow

Lab: Publishing a Single Event

Lab: Publishing Multiple Events

Lab: Persisting Event Streams

Lab: Creating Spark Scripts

Lab: Executing Spark Queries in the Spark Console

Lab: Searching for Data

Lab: Calling WSO2 DAS APIs

Lab: Creating Predictive Models

Lab: Creating Gadgets

Lab:Creating Dashboards

Lab: Creating a Template

Lab: Using a Template

Lab: Setting Up a Minimum HA Deployment Cluster

​CC BY 4.0                                      ​You are free to share and adapt for any purpose, even commercially.


Lab: Getting Started with WSO2 Data Analytics
Server
Training Objective
Download and run WSO2 Data Analytics Server (WSO2 DAS) to get started with the exercises
given below.

Note​: The participants are expected to be connected to the internet throughout in order to
successfully complete the lab exercises.

Business Scenario
Smarthome Info is a large scale supplier of electricity with customers spread in 10 states of
USA. Customers consist of houses and households.

This company needs to carry out detailed analysis for large volumes of data relating to the
electricity usage of all its customers in order to optimize its production and distribution of energy
based on the demand.

High Level Steps


1. Download and install WSO2 DAS
2. Run WSO2 DAS
3. Access the WSO2 DAS Management Console

Detailed Instructions
Download and Install WSO2 DAS
To download WSO2 DAS:
1. Visit the ​WSO2 DAS home page​ and click ​DOWNLOAD​. This downloads WSO2 DAS as
a zip file.
2. Unzip the zip file in a preferred location in your machine. As a result, a directory named
WSO2DAS-<VERION_NO>​ is created. This directory is referred to as the ​<DAS_HOME>
throughout this lab kit.

Run WSO2 DAS


To run WSO2 DAS, navigate to the ​<DAS_HOME>/bin ​directory from your CLI, and run the
following command.

For Windows: ​wso2server.bat --run

​CC BY 4.0                                      ​You are free to share and adapt for any purpose, even commercially.


For Linux: ​sh wso2server.sh

This starts the WSO2 DAS server.

Access WSO2 DAS Management Console


The DAS Management Console can be accesses with the following URL.

https://<DAS_HOST>:<DAS_PORT>

The DAS host is the local host. You can use ​localhost​ or the number of the local host in the URL.

The default DAS port is 9443. If required, it can be changed by using the following property with the
command to start the server.

-DportOffset n

When trying this lab kit, you can use ​admin​ as both the username and the password to log into the
DAS Management Console.

​CC BY 4.0                                      ​You are free to share and adapt for any purpose, even commercially.


Lab: ​Defining Event Streams
Training Objective
Learn how to create event streams to define a sequence of events.

Business Scenario
Info Smart Homes company is a power supplier. It needs to collect data relating to the power usage
over time of the houses that are its customers. A unit of data that is collected over time should have
the following information.

● ID
● Value
● Property
● Plug ID
● Household ID
● House ID

Here we assume a hierarchical structure with a house, identified by a unique house ID being the
topmost entity. Every house contains one or more household identified by a unique household
ID (within a house). Every household contains one or more smart plugs, each identified by a
unique plug ID (within a household). Every smart plug contains two sensors:

1. A load sensor that measures the current load with Watt as a unit.
2. A work sensor measuring the total accumulated work since the start (or reset) of the
sensor with kWh as a unit.

Detailed Instructions
In order to capture units of data with the information given above, we need to create an event
stream. The event stream should have a unique attribute for each item of information mentioned
above. All the units of data that have values to match all the attributes in the stream are selected into
the event flow of WSO2 DAS.

Follow the steps below to create an event stream to capture data as required.

1. Log into the DAS Management Console.


2. In the left navigator, click ​Streams​ to open the ​Available Event Streams​ page. Then click
Add Event Stream​ to open the ​Define New Event Stream​ page.
3. In the ​Event Stream Name​ field, enter ​SMARTHOME_DATA​. In the ​Event Stream Version
field, enter ​1.0.0​.
4. Add the following attributes. To add each attribute, enter the attribute name under ​Payload
Data Attributes​, select the attribute type and click ​Add​.

​CC BY 4.0                                      ​You are free to share and adapt for any purpose, even commercially.


Attribute Attribute Type

id string

value float

property bool

plug_id int

household_id int

house_id int

5. Click ​Add Event Stream​.

Follow steps 1-5 given above to define another stream to be used as the output stream.The
parameter and attribute values should be as follows.

Parameter Value

Event Stream Name usageStream

​CC BY 4.0                                      ​You are free to share and adapt for any purpose, even commercially.


Event Stream Version 1.0.0

Attribute Attribute Type

house_id int

maxVal float

minVal float

avgVal double

timestamp long

​CC BY 4.0                                      ​You are free to share and adapt for any purpose, even commercially.


Expected Outcome
The event streams added are displayed in the ​Available Event Streams​ page as shown below.

​CC BY 4.0                                      ​You are free to share and adapt for any purpose, even commercially.


​CC BY 4.0                                      ​You are free to share and adapt for any purpose, even commercially.
Lab: ​Creating Event Receivers
Training Objective
Define an event receiver to collect events of a particular data format via a specific transport.

Business Scenario
Info Smart Home receives data in the ​wso2event​ format.

Detailed Instructions
An event receiver is required to receive events in the ​wso2event​ format and then direct them to the
SMARTHOME_DATA​. event stream. Follow the steps below to create an event receiver of the
wso2event type.

1. Log in to the DAS Management Console, if you are not already logged in.
​ ain​, and then click ​Receivers​.
2. Click M
3. Click A​ dd Event Receiver​, and enter the details as shown below.

Parameter Value

Event Receiver DATA_RECEIVER

​CC BY 4.0                                      ​You are free to share and adapt for any purpose, even commercially.


Input Event Adapter Type wso2event

Event Stream SMARTHOME_DATA:1.0.0

Message Format wso2event

4. Click ​Add Event Receiver​.

Expected Outcome
The ​DATA_RECEIVER​ receiver is saved and is displayed in the ​Available Event Receivers​ as
follows.

​CC BY 4.0                                      ​You are free to share and adapt for any purpose, even commercially.


Lab: ​Creating Event Publishers
Training Objective
Create an event publisher to publish the output of the event flow on a selected interface.

Business Scenario
Info Smart Home needs to print the list of processed events in a CLI log.

Detailed Instructions
In order to print the processed events in a CLI log, an event publisher of the logger type should be
defined. The processed events should be published from the ​SMARTHOME_DATA​ event stream
because the processed events are directed to that stream.

Follow the steps below to create a logger publisher.

1. Log in to the DAS Management Console, if you are not already logged in.
​ ain​, and then click ​Publishers​ to open the ​Available Event Publishers​ page.
2. Click M
3. Click A​ dd Event Publisher​ to open the ​Create a New Event Publisher​ page and enter
information as follows.

​CC BY 4.0                                      ​You are free to share and adapt for any purpose, even commercially.


Parameter Value

Event Publisher Name DATA_PUBLISHER

Event Source SMARTHOME_DATA:1.0.0

Output Event Adapter Type logger

Message Format text

4. Click ​Add Event Publisher​ to save the information.

​CC BY 4.0                                      ​You are free to share and adapt for any purpose, even commercially.


Expected Outcome
The event publisher created is displayed in the list of available event publishers as shown below.

​CC BY 4.0                                      ​You are free to share and adapt for any purpose, even commercially.


Lab: ​Creating Execution Plans

Training Objective
Write Siddhi queries to analyze data real time.

Business Scenario
Average, minimum and maximum usage needs to be calculated for the events in the
SMARTHOME_DATA​ event stream, and the processed events with these values should be inserted
into the ​usageStream​.

Detailed Instructions
Follow the steps below to add an execution plan.

1. Log into the DAS Management Console if you are not already logged in.
2. In the ​Main​ tab, click ​Execution Plans​ to open the ​Available Execution Plans​ page.
​ dd Execution Plan​ to open the ​Create a New Execution Plan​ page.
3. Click A

​CC BY 4.0                                      ​You are free to share and adapt for any purpose, even commercially.


4. In the ​Import Stream​ field, select ​SMARTHOME_DATA:1.0.0​. Then enter ​inputStream​ in
the ​As​ field and click ​Import​. This adds the following query that specifies the
SMARTHOME_DATA​ stream as the source from which the events to be processed are
imported.

@Import('SMARTHOME_DATA:1.0.0')
define stream inputStream (id string, value float, property bool,
plug_id int, household_id int, house_id int);

5. In the ​Export Stream​ field, select ​usageStream:1.0.0​. Then enter ​outputStream​ in the
Value Of​ field and click ​Export​. This adds the following query that adds the ​usageStream
stream as the output stream to which values processed are exported.

@Export('usageStream:1.0.0')

define stream outputStream (house_id int, maxVal float, minVal


float, avgVal double, currentTime string);

6. Add the following query to the execution plan.

from inputStream[value>0]#window.time(1 min) select


house_id,max(value) as maxVal,min(value) as minVal, avg(value) as
avgVal,time:timestampInMilliseconds() as timestamp
group by house_id
insert current events into usageStream ;

​CC BY 4.0                                      ​You are free to share and adapt for any purpose, even commercially.


The query section should look as follows.

7. Click ​Validate Query Expressions​ to verify whether the queries entered are valid.
8. Click A​ dd Execution Plan​ to save the queries.

Expected Outcome
Once the execution plan is created and saved, it is displayed in the ​Available Execution Plans
page as follows.

​CC BY 4.0                                      ​You are free to share and adapt for any purpose, even commercially.


Lab: Viewing the Event Flow
Training Objective
The purpose of this exercise is to view how the event streams, receiver and publisher you
created in the previous labs are interconnected. This combination of interconnected DAS
artifacts forms the event flow that processes the events with the specified set of attributes.

Detailed Instructions
Follow the steps below to view the event flow.

1. Log into the DAS Management Console if you are not already logged in.
2. In the ​Main​ tab, click ​Flow ​to open the ​CEP Event Flow ​page.

Expected Outcome
The event flow is displayed as follows.

​CC BY 4.0                                      ​You are free to share and adapt for any purpose, even commercially.


Lab: ​Publishing a Single Event
Training Objective
Learn how to publish a single event to an event flow by assigning values to the attributes of the input
stream.

Business Scenario
Info Smart Home needs to publish a single event in the ​wso2event​ format.

Detailed Instructions
1. Log into the WSO2 DAS Management Console if you are not already logged in.
2. In the ​Tools​ tab, click ​Event Simulator​ to open the ​Event Stream Simulator​ page.
3. Select the ​SMART_HOME_DATA:1.0.0​ stream in the ​Event Stream Name​ field.
4. Enter values for the available attributes as follows.

Attribute Value

id 3655509222

​CC BY 4.0                                      ​You are free to share and adapt for any purpose, even commercially.


value 8.372

property FALSE

plug_id 5

household_id 2

house_id 10

5. Click ​Send​ to send the event.

Expected Outcome
A message appears to confirm that the event is successfully sent.

The event is logged in the CLI as follows

​CC BY 4.0                                      ​You are free to share and adapt for any purpose, even commercially.


Lab: ​Publishing Multiple Events
Training Objective
Learn how to publish multiple events to an event flow via a file that contains multiple combinations of
assigned values for the attributes of the input stream.

Business Scenario
Info Smart Home needs to publish the data to be analyzed in WSO2 DAS

Detailed Instructions
Follow the steps below to upload a file with events in the ​wso2event​ ​format to be analyzed using
WSO2 DAS.

1. Log into the WSO2 DAS Management Console if you are not already logged in.
2. In the ​Tools​ tab, click ​Event Simulator​ to open the ​Event Stream Simulator​ page.
3. Select the ​SMART_HOME_DATA:1.0.0​ stream in the ​Event Stream Name​ field.
4. Download the ​sample.csv​ file in a location in your machine.
5. Click ​Choose File​ in the ​Event Stream Simulator​ page and browse for the ​sample.csv
file. Then click ​Upload​. Click ​OK​ in the message that appears to confirm that the file was
successfully uploaded. Refresh the page. The uploaded file is displayed as follows.

​CC BY 4.0                                      ​You are free to share and adapt for any purpose, even commercially.


6. Click ​Configure​ to open the ​Event Mapping Configuration​ dialog box. Enter a comma (​,​ ​)
in the ​Field Delimiter​ field and click ​OK​. This adds the ​Play​ button to the uploaded file.

7. Click ​Play​. This publishes multiple events in the ​SMART_HOME_DATA:1.0.0​ stream.

Expected Outcome
A message appears to confirm that the event publishing has started.

The events sent are logged in the CLI as shown in the extract below, by the logger publisher
you previously created.

​CC BY 4.0                                      ​You are free to share and adapt for any purpose, even commercially.


​CC BY 4.0                                      ​You are free to share and adapt for any purpose, even commercially.
Lab: ​Persisting Event Streams
Training Objective
Persist event streams to save data in the databases in order to use them for Batch Analytics.

Business Scenario
The data captured by Info Smart Homes needs to be stored in the database in order to carry out
batch analytics as well as to carry out searches.

Detailed Instructions
In order to store the data captured by an event stream in databases, the event stream should be
persisted. Follow the steps below to persist the ​SMARTHOME_DATA​ and ​usageStream​ event
streams.

1. Log into the WSO2 Management Console if you are not already logged in.
2. In the ​Main​ tab, click ​Streams​ to open the ​Available Event Streams​ page.
​ dit​ for the ​SMART_HOME_DATA:1.0.0​ stream to open the ​Edit Event Stream​ page.
3. Click E
Then click ​Next [Persist Event]​.
4. Select the ​Persist Event Stream​ check box to store information in the
SMART_HOME_DATA:1.0.0​ stream to databases.
5. Select the ​Persist Attribute​ check box for each attribute in the stream. This ensures that all
the attribute values specified in events are stored in the database.
6. Select the ​Primary Key​ check box for the ​id​, ​household_id​ and the ​house_id​ attributes.
This allows you to search for single events by a specific combination of values for these
three attributes.

​CC BY 4.0                                      ​You are free to share and adapt for any purpose, even commercially.


7. Select the ​Index Column​ check box for all the attributes. This allows you to search for data
by any attribute.

8. Click ​Save Event Stream​ to save the information.

​CC BY 4.0                                      ​You are free to share and adapt for any purpose, even commercially.


Similarly, persist the ​usageStream​ event stream as shown below.

Expected Outcome
A message appears to confirm whether you want to update the event stream. Click ​Yes​ in the
message.

​CC BY 4.0                                      ​You are free to share and adapt for any purpose, even commercially.


Lab: ​Creating Spark Scripts
Training Objective
Learn how to create and execute Spark scripts in order to analyze events stored in the databases.

Business Scenario
The usage (i.e., the difference between the maximum usage and the minimum usage) should be
calculated for each event, and this information needs to be saved in a temporary table. Then the
events where the usage is greater than 30 should be filtered and saved in another table.

Prerequisite
Before you create the Spark Scripts given below and execute them, generate events to be
persisted in the system for Batch analytics by repeating ​Lab: Publishing Multiple Events​.

Detailed Instructions
Follow the steps below to add Apache Spark queries to process events as described in the above
business scenario.

1. Log into the Management Console if you are not already logged in.
2. In the ​Main ​tab, click ​Scripts​ to open the ​Available Analytics Scripts​ page.
3. Click ​Add New Analytics Script​ to open the ​Add New Analytics Script​ page.
4. Enter ​Batch_Analytics​ in the ​Script Name​ field.
5. Enter the following Spark queries in the ​Spark SQL Queries​ field, and click ​Add​.

CREATE TEMPORARY TABLE homeData USING CarbonAnalytics OPTIONS


(tableName "SMARTHOME_DATA", schema "id STRING, value FLOAT,
property BOOLEAN, plug_id INT, household_id INT, house_id INT");
create temporary table plugUsage using CarbonAnalytics options
(tableName "plug_usage", schema "house_id INT, household_id INT,
plug_id INT, usage FLOAT -sp");

insert overwrite table plugUsage select house_id, household_id,


plug_id, max(value) as usage from homeData where property = false
group by house_id, household_id, plug_id ;

Select * from plugUsage where usage>300;

​CC BY 4.0                                      ​You are free to share and adapt for any purpose, even commercially.


6. Once you click ​Add​, the Batch_Analytics script is displayed in the ​Available Analytics
Scripts​ ​ page as shown below.

The queries included in the above script does the following.


● CREATE TEMPORARY TABLE homeData USING CarbonAnalytics OPTIONS
(tableName "SMARTHOME_DATA", schema "id STRING, value FLOAT,
property BOOLEAN, plug_id INT, household_id INT, house_id
INT")​:​This creates the ​SMART_HOME_DATA ​temporary table with the specified
schema.
● create temporary table plugUsage using CarbonAnalytics options
(tableName "plug_usage", schema "house_id INT, household_id
INT, plug_id INT, usage FLOAT -sp")​: This creates the Plug_Usage
temporary table with the required fields.
● insert overwrite table plugUsage select house_id,
household_id, plug_id, max(value) as usage from homeData where
property = false group by house_id, household_id, plug_id​: This
query calculates the value of the usage field for each event applying the max - min
formula.
7. Click ​Execute ​to execute the the ​Batch_Analytics​ script.

Expected Outcome
Once the queries are successfully executed, the results are displayed as follows.

​CC BY 4.0                                      ​You are free to share and adapt for any purpose, even commercially.


​CC BY 4.0                                      ​You are free to share and adapt for any purpose, even commercially.
Lab: E​xecuting Spark Queries in the Spark Console

Training Objective
Learn how to use the Spark Console to execute Spark queries for faster results.

Business Scenario
Info Smarthomes need to execute a quick query to filter events where the plug usage is greater
than 100.

Detailed Instructions
1. Log into the DAS Management Console if you are not already logged in.
2. In the ​Main​ tab, click ​Console​ to open the ​Interactive Analytics Console​.
3. Enter the following command in the console and click ​Enter.

Select * from plugUsage where usage>100

Expected Outcome
The output is displayed as follows.

​CC BY 4.0                                      ​You are free to share and adapt for any purpose, even commercially.


​CC BY 4.0                                      ​You are free to share and adapt for any purpose, even commercially.
Lab: ​Searching for Data
Training Objective
Learn how to carry out Lucene queries to search for data persisted in the DAS.

Business Scenario
Info Smarthomes need to to search for the following events.
● The single event that with the following properties.
○ House ID - 39
○ Household ID - 11
○ ID - 3655508728
● All the records relating to house number 8.

Detailed Instructions
1. Log into the DAS Management Console if you are not already logged in.
2. In the ​Main​ tab, click ​Data Explorer​ to open the ​Data Explorer​ page.
3. In the ​Table Name​ field, select the ​SMARTHOME_DATA​ table and click ​Search​. This fetches
all the records that are currently stored in this table as shown below.
4. Select the ​By Primary Key​ ​ ​option. As a result, the house_id and the ​id​ fields are displayed
as shown below.
5. Enter values for each field as follows and click ​Search​.
Attribute Value

house_id 39

household_id 11

id
3655508728

This fetches a single record with the primary key combination given above as follows.

Each event should have a unique primary key combination. Therefore, a search by
primary key should always fetch just one event.

6. Select the ​By Query​ option. As a result, a field for search queries is displayed as follows.

​CC BY 4.0                                      ​You are free to share and adapt for any purpose, even commercially.


7. Enter the following in the query field to search for all the records relating to house ID 39 and
click ​Search.
house_id:8

For more detailed information of all the possible searches that can be carried out in WSO2 DAS,
see ​WSO2 Data Analytics Server Documentation - Searching for Data​.

Expected Outcome
The first query by the unique primary key combination fetches a single event as follows.

The ​house_id:8 ​query fetches 26 records as follows.

​CC BY 4.0                                      ​You are free to share and adapt for any purpose, even commercially.


Lab: Calling WSO2 DAS APIs
Training Objective
Call some of the APIs implemented in WSO2 DAS to perform searches.

Business Scenario
The Data Analyst at Smarthome Info needs the following information.
● A list of all the available analytics tables in the WSO2 DAS system containing
information relating to the business.
● The details saved in these tables.
● All the records relating to house number 8, sorted by the ID.
● The count of records relating to house number 8.
● The schema of the ​SMARTHOME_DATA​ table.

Detailed Instructions
Follow the steps below to obtain the information mentioned above.

Note​: Before you follow this exercise, follow the instructions on ​adding a basic auth header​.

1. Start the WSO2 DAS server if it is not already started.


2. Open a new terminal window and issue the following cURL commands.

Requirement cURL Command

List all the available tables curl -H "Content-Type:


application/json" -H
"Authorization: Basic
YWRtaW46YWRtaW4=" -v
https://localhost:9443/analytics/t
ables​ -k

Fetch information in all the tables curl -H "Content-Type:


application/json" -H
"Authorization: Basic
YWRtaW46YWRtaW4="
https://localhost:9443/analytics/t
ables/SMARTHOME_DATA​ -k

Fetch all records for house 8 curl -X POST -H "Content-Type:


application/json" -H
"Authorization: Basic

​CC BY 4.0                                      ​You are free to share and adapt for any purpose, even commercially.


YWRtaW46YWRtaW4="
https://localhost:9443/analytics/s
earch​ -d
'{"tableName":"SMARTHOME_DATA",
"query":"house_id:8", "start":0,
"count":3, "sortBy" : [{"field" :
"id", "sortType" : "ASC"}]}' -k

The count of records relating to house


curl -X POST -H "Content-Type:
number 8 application/json" -H
"Authorization: Basic
YWRtaW46YWRtaW4="
https://localhost:9443/analytics/s
earch_count​ -d
'{"tableName":"SMARTHOME_DATA",
"query":"house_id:8"}' -k

The schema of the ​SMARTHOME_DATA


curl -H "Content-Type:
table application/json" -H
"Authorization: Basic
YWRtaW46YWRtaW4="
https://localhost:9443/analytics/t
ables/SMARTHOME_DATA/schema​ -k

Expected Outcome
The table below shows the expected return for each cURL command.
Note: ​The return might vary depending on the amount of data you have simulated.

cURL Command Return

List all the available tables ["PLUG_USAGE","SMARTHOME_DATA


curl -H "Content-Type: ","USAGESTREAM"]
application/json" -H
"Authorization: Basic
YWRtaW46YWRtaW4=" -v
https://localhost:9443/analytics/t
ables​ -k

Fetch information in all the tables This fetches all the data is all the existing
tables. The following example is an
curl -H "Content-Type:
extract.
application/json" -H
[{"id":"45896194-1372-4b2c-13
"Authorization: Basic
YWRtaW46YWRtaW4=" 1d-740da92e9dc3","tableName":

​CC BY 4.0                                      ​You are free to share and adapt for any purpose, even commercially.


https://localhost:9443/analytics/t "SMARTHOME_DATA","timestamp":
ables/SMARTHOME_DATA​ -k 1484116419847,"values":{"hous
e_id":1,"household_id":1,"pro
perty":true,"plug_id":1,"id":
"test","_version":"1.0.0","va
lue":22.2}},{"id":"cba03c17-a
797-3e93-328a-29c86c9fedd9","
tableName":"SMARTHOME_DATA","
timestamp":1484116553666,"val
ues":{"house_id":39,"househol
d_id":11,"property":false,"pl
ug_id":1,"id":"3655508722","_
version":"1.0.0","value":49.3
58}}

[{"id":"f075cb02-8ef0-97bb-3b
Fetch all records for house 8
86-973bebd7a212","tableName":
curl -X POST -H "Content-Type: "SMARTHOME_DATA","timestamp":
application/json" -H 1484116852062,"values":{"hous
"Authorization: Basic e_id":8,"household_id":0,"pro
YWRtaW46YWRtaW4=" perty":false,"plug_id":5,"id"
https://localhost:9443/analytics/s
:"3655509020","_version":"1.0
earch​ -d
'{"tableName":"SMARTHOME_DATA",
.0","value":0.0}},{"id":"ecbd
"query":"house_id:8", "start":0, 55d9-a534-a4ac-38d6-39ee01134
"count":3, "sortBy" : [{"field" : 742","tableName":"SMARTHOME_D
"id", "sortType" : "ASC"}]}' -k ATA","timestamp":148411686107
2,"values":{"house_id":8,"hou
sehold_id":1,"property":false
,"plug_id":4,"id":"3655509029
","_version":"1.0.0","value":
0.517}},{"id":"7e30c466-2677-
4fbe-e2f8-78c23f9dbbb8","tabl
eName":"SMARTHOME_DATA","time
stamp":1484116864077,"values"
:{"house_id":8,"household_id"
:1,"property":false,"plug_id"
:5,"id":"3655509032","_versio
n":"1.0.0","value":41.675}}]

The count of records relating to house 8 This returns a number that equals the
number of records relating to house 8.
curl -X POST -H "Content-Type:
application/json" -H
"Authorization: Basic
YWRtaW46YWRtaW4="
https://localhost:9443/analytics/s

​CC BY 4.0                                      ​You are free to share and adapt for any purpose, even commercially.


earch_count​ -d
'{"tableName":"SMARTHOME_DATA",
"query":"house_id:8"}' -k

The schema of the ​SMARTHOME_DATA {"columns":{"id":{"type":"STR


table ING","isScoreParam":false,"is
Index":true,"isFacet":false},
curl -H "Content-Type: "value":{"type":"FLOAT","isSc
application/json" -H oreParam":false,"isIndex":tru
"Authorization: Basic
e,"isFacet":false},"property"
YWRtaW46YWRtaW4="
https://localhost:9443/analytics/t :{"type":"BOOLEAN","isScorePa
ables/SMARTHOME_DATA/schema​ -k ram":false,"isIndex":true,"is
Facet":false},"plug_id":{"typ
e":"INTEGER","isScoreParam":f
alse,"isIndex":true,"isFacet"
:false},"household_id":{"type
":"INTEGER","isScoreParam":fa
lse,"isIndex":true,"isFacet":
false},"house_id":{"type":"IN
TEGER","isScoreParam":false,"
isIndex":true,"isFacet":false
}},"primaryKeys":["house_id",
"household_id","id"]}

​CC BY 4.0                                      ​You are free to share and adapt for any purpose, even commercially.


Lab: Creating Predictive Models
Training Objective
Create models that make predictions based on analysis carried out using machine learner
algorithms.

Business Scenario
NOTE: ​A different dataset is used in this lab exercise. The Smart Home Info example will be
continued to be used after this lab exercise.

A Health Care service needs to develop an application to evaluate whether a person is


suffering with breast cancer or not. In order to make this prediction, a number of determining
factors specified by medical specialists are used in the algorithm based on which the prediction
is made.

High-level Steps
1. Create a dataset
2. Create a project
3. Create an analysis
4. Predict using the model

Detailed Instructions
Create a Dataset
Follow the steps below to upload the dataset based on which the training model is created.
1. Access the WSO2 Machine Learner wizard embedded within DAS via the
https://<DAS_HOME>:<DAS_PORT/ml/site/home/login.jag​ URL, and login with

​CC BY 4.0                                      ​You are free to share and adapt for any purpose, even commercially.


your credentials.

2. Click ​ADD DATASET​ to open the ​Create Dataset​ page.


​ ata Source​ field, click ​Choose File ​and browse for the
3. In the D
<DAS_HOME>/samples/ml/tuned/naive-bayes/breastCancerWisconsin.csv​ file.
Enter values for the rest of the parameters as shown below.

Parameter Name Value

Dataset Name Breast_Cancer_Dataset

Version 1.0.0

Description Breast cancer data in Wisconsin

Source Type File

Data Format CSV

Column Header Available Yes

​CC BY 4.0                                      ​You are free to share and adapt for any purpose, even commercially.


4. Click ​CREATE DATASET​ to save your changes. The ​Datasets​ page opens and the dataset
you entered is displayed as follows.

Create a Project
Follow the procedure below to create a project for the dataset uploaded.

1. Log into the Machine Learner wizard of WSO2 DAS if you are not already logged in. You can
access it with the ​https://<DAS_HOME>:<DAS_PORT/ml/site/home/login.jag​ URL,
and login with your credentials.
2. Click ​Add Project​.

​CC BY 4.0                                      ​You are free to share and adapt for any purpose, even commercially.


3. In the ​Create Project​ page, enter information as shown below.

Parameter Name Value

Project Name Breast_Cancer_data_analytics_pr


oject

Description This project performs


predictive analysis on the
breast cancer data in
Wisconsin.

Dataset Breast_Cancer_Dataset

​CC BY 4.0                                      ​You are free to share and adapt for any purpose, even commercially.


4. Click ​Create Project​ to to save the information. The project is displayed in the ​Projects
page as follows.

Create an Analysis
Follow the procedure below to analyse the ​Breast_Cancer_Dataset ​dataset, and then create a
training model based on that analysis.

1. Log into the Machine Learner wizard if you are not already logged in. You can access it with
the ​https://<DAS_HOME>:<DAS_PORT/ml/site/home/login.jag​ URL, and login
with your credentials.
2. Click the ​You have X projects​ link as shown below.

3. Click on the ​Breast_Cancer_data_analytics_project​ project to expand it.

​CC BY 4.0                                      ​You are free to share and adapt for any purpose, even commercially.


4. Enter ​breast_cancer_analysis_1 ​as the analysis name and click ​CREATE ANALYSIS​. The
following page appears displaying the summary statistics.

5. Click ​Next​ without making any changes to the summary statistics.

The ​Explore​ view opens. Note that ​Parallel Sets​ and ​Trellis Chart​ visualizations are
enabled, and ​Scatter Plot​ and ​Cluster Diagram​ visualizations are disabled. This is
determined by the feature types of the dataset.

​CC BY 4.0                                      ​You are free to share and adapt for any purpose, even commercially.


6. Click ​Next​. The ​Algorithms ​view is displayed. Enter values as shown below.

Parameter Name Value

Algorithm Name LOGISTIC REGRESSION L_BFGS

Response Name Class

Train Data Fraction 0.7

​CC BY 4.0                                      ​You are free to share and adapt for any purpose, even commercially.


7. Click ​Next​. The ​Parameters​ view appears. Enter ​L2​ as the reg type.

8. Click ​Next​. The ​Model​ view appears. Select ​Breast_Cancer_Dataset-1.0.0​ as the dataset
version.

9. Click ​RUN​ to train the model.

The training model is created as displayed as shown below.

Predict Using the Model


Follow the procedure below to make a prediction based on the training model you created.

​CC BY 4.0                                      ​You are free to share and adapt for any purpose, even commercially.


1. Log into the Machine Learner wizard if you are not already logged in. You can access it with
the https://<DAS_HOME>:<DAS_PORT/ml/site/home/login.jag URL, and login with your
credentials.
2. Click the ​You have X projects​ link as shown below to open the ​Projects​ window.

3. Click ​MODELS​ for the ​breast_cancer_analysis_1​ ​ ​analysis.

4. Click ​Predict​ on the model displayed.

​CC BY 4.0                                      ​You are free to share and adapt for any purpose, even commercially.


5. Enter values in the ​Predict​ page as shown below.

Parameter Name Value

Prediction Source Feature values

SampleCodeNumber 1018561

​CC BY 4.0                                      ​You are free to share and adapt for any purpose, even commercially.


ClumpThickness 2

UniformityOfCellSize 1

UniformityOfCell Shape 1

MarginalAdhesion 1

SingleEpithelialCellSize 2

BareNuclei 1

BlandChromati 1

NormalNucleoli 1

Mitoses 5

6. Click ​Predict​. The prediction is displayed as follows.

​CC BY 4.0                                      ​You are free to share and adapt for any purpose, even commercially.


Lab: ​Creating Gadgets
Training Objective
Learn how to create gadgets to present analyzed data.

Business Scenario
Smarthome Info needs a visual representation of the change in the maximum usage, minimum
usage and the average usage over time.

Detailed Instructions
1. Access the WSO2 DAS analytics Dashboard using the
https://<DAS_HOST>:<DAS_PORT>​/portal URL, and log in with your credentials.
2. Click the menu icon (shown below) and then click ​Gadgets​ to open the ​Gadgets​ page.

3. Click ​GENERATE GADGET​ to open the Gadget Generation wizard.


​ elect Provider​ page, make sure that ​Batch Data Source​ in the ​Select Provider
4. In the S
field.

5. In the ​Configure Provider​ page, enter information as follows.

Field Value

Event Table USAGESTREAM

Number of records to display 100

This is the event table from which data is fetched to update the gadget. Click the​ Test
Connection​ to test whether the gadget is successfully connected to that table. If the

​CC BY 4.0                                      ​You are free to share and adapt for any purpose, even commercially.


connection is valid, it is indicated as shown below.

5. Click ​Show Data​ to preview the data that is already available in the event table. A table with
a sample of the data already available in the ​USAGESTREAM​ event table is displayed as

​CC BY 4.0                                      ​You are free to share and adapt for any purpose, even commercially.


follows.

​CC BY 4.0                                      ​You are free to share and adapt for any purpose, even commercially.


6. Click ​Next​.​ In the ​Configure Chart​ page, enter information as follows.

Parameter Value

Gadget Name MaxPowerUsagePerHouse

Select Chart Type Line Chart

X Axis timestamp

X Type time

Y Axis maxVal

Y Type number

​CC BY 4.0                                      ​You are free to share and adapt for any purpose, even commercially.


Color domain house_id

Max Length 30

7. Click ​Add to Store​ to save the gadget configuration.

Two more gadgets are required for this scenario. In order to create them, repeat steps 1-5 above,
and enter information in the​ ​Configure Chart​ page as follows.

● Average Power Usage Per House

Parameter Value

​CC BY 4.0                                      ​You are free to share and adapt for any purpose, even commercially.


Gadget Name AvgPowerUsagePerHouse

Select Chart Type Line Chart

X Axis timestamp

X Type time

Y Axis avgVal

Y Type number

Color domain house_id

Max Length 30

● Minimum Power Usage Per House

Parameter Value

Gadget Name MinPowerUsagePerHouse

Select Chart Type Line Chart

X Axis timestamp

X Type time

Y Axis minVal

Y Type number

Color domain house_id

Max Length 30
Click ​Add to Store​ to save the gadget configurations.

​CC BY 4.0                                      ​You are free to share and adapt for any purpose, even commercially.


Expected Outcome
The gadgets you created are listed in the gadget store as shown below.

​CC BY 4.0                                      ​You are free to share and adapt for any purpose, even commercially.


Lab:​Creating Dashboards
Training Objective
Learn how to create a dashboard to contain one or more gadgets presenting analyzed information.

Business Scenario
A dashboard is required to place the three gadgets you created in the previous exercise.

Detailed Instructions
1. Access the WSO2 DAS analytics Dashboard using the
https://<DAS_HOST>:<DAS_PORT>/porta​l URL, and log in with your credentials.
2. Click ​CREATE DASHBOARD​ to open the ​Create a Dashboard Wizard.
3. Enter basic information for the dashboard as follows, and click ​Next​.

Field Value

Name of your Dashboard PowerDashboard

Description Presents the analysis of the power usage


of different households.

​CC BY 4.0                                      ​You are free to share and adapt for any purpose, even commercially.


4. Select the ​Single Column​ layout.

A message appears to indicate that the dashboard is successfully created.

5. Click the icon for gadgets. Then drag and drop the ​MaxPowerUsagePerHouse​,
AvgPowerUsagePerHouse​, and ​MinPowerUsagePerHouse​ gadgets to the columns in the
dashboard as demonstrated in the example below.

​CC BY 4.0                                      ​You are free to share and adapt for any purpose, even commercially.


Expected Outcome
When you access the home page (i.e., by accessing the Analytics Dashboard via the
https://<DAS_HOST>:<DAS_PORT>/porta​l URL, the ​PowerDashboard​ dashboard you

​CC BY 4.0                                      ​You are free to share and adapt for any purpose, even commercially.


created is displayed as follows.

When you click ​View​, the gadgets you added to it are displayed as follows.

​CC BY 4.0                                      ​You are free to share and adapt for any purpose, even commercially.


Lab: C​reating a Template
Training Objective
Create a template to containing common configurations in order to generate DAS artifacts
instead of manually defining them.

Business Scenario
Smarthome Info needs a template for an event stream, an event publisher and an execution
plan because it needs to create all three artifacts multiple times with similar configurations.

High Level Steps


1. Create a basic template file.
2. Add an event stream configuration.
3. Add an execution plan configuration.
4. Add an event publisher configuration.

Detailed Instructions
Create Basic Template
In this exercise, a basic template is created and saved as a file. The required event stream and
execution plan configurations are added in the later exercises.

Create an XML file with the following configuration and save it in the
<DAS_HOME>/repository/conf/template-manager/domain​ ​template​ directory as
PowerConsumptionAlerts.xml​.

<?xml version="1.0"?>
<!--
~ Copyright (c) 2017, 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,

​CC BY 4.0                                      ​You are free to share and adapt for any purpose, even commercially.


~ 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="PowerConsumptionAlerts">
<description>Domain for power consumption alerts</description>
<scenarios>
<scenario type="PowerConsumptionAlerts">
<description>Configure a scenario to notify power
consumption alerts.
</description>
​<templates>
​<!--Note: These will be deployed in the order they appear here-->
<template type="eventstream">
<!--A Stream Definition Template here-->
</template>
<template type="realtime">
<!--An Execution Plan Template here-->
</template>
<template type="eventreceiver">
<!--An Event Receiver Template here-->
</template>
<template type="eventpublisher">
<!--An Event Publisher Template here-->
</template>
<template type="gadget">
<!--A Gadget Template here-->
</template>
<template type="dashboard">
<!--A Dashboard Template here-->
</template>
</templates>
<streamMappings>
<!--Define stream mappings here-->
</streamMappings>
<parameters>
<!--Define parameters here-->
</parameters>
</scenario>
</scenarios>

​CC BY 4.0                                      ​You are free to share and adapt for any purpose, even commercially.


<commonArtifacts>
<!--Define common artifacts here-->
</commonArtifacts>
<scripts>
<!--Define JavaScript files and/or content here-->
<script src=””/>
</scripts>
</domain>

<domain name="PowerConsumptionAlerts">
<description>Domain for Power Consumption Alerts</description>
<scenarios>
<scenario type="PowerConsumptionAlerts">
<description>Configure a scenario to notify power consumption
alerts.
</description>
<templates>
<!--Note: These will be deployed in the order they appear
here-->
<template type="eventstream">
<!--A Stream Definition Template here-->
</template>
<template type="realtime">
<!--An Execution Plan Template here-->
</template>
<template type="eventreceiver">
<!--An Event Receiver Template here-->
</template>
<template type="eventpublisher">
<!--An Event Publisher Template here-->
</template>
<template type="gadget">
<!--A Gadget Template here-->
</template>
<template type="dashboard">
<!--A Dashboard Template here-->
</template>
</templates>
<streamMappings>

​CC BY 4.0                                      ​You are free to share and adapt for any purpose, even commercially.


<!--Define stream mappings here-->
</streamMappings>
<parameters>
<!--Define parameters here-->
</parameters>
</scenario>
</scenarios>
<commonArtifacts>
<!--Define common artifacts here-->
</commonArtifacts>
<scripts>
<!--Define JavaScript files and/or content here-->
<script src=””/>
</scripts>
</domain>

Add Event Stream Configuration


Add the following JSON configurations under the ​<template type="eventstream">​ element.

{
"streamId":"House$houseIdAlertStream:1.0.0",
"name":"House$houseIdAlertStream",
"version":"1.0.0",
"nickName":"",
"description":"",
"metaData":[

],
"correlationData":[

],
"payloadData":[
{
"name":"house_id",
"type":"INT"
},
{
"name":"type",
"type":"STRING"
},
{

​CC BY 4.0                                      ​You are free to share and adapt for any purpose, even commercially.


"name":"message",
"type":"STRING"
}
]
}

"streamId":"House$houseIdAlertStream:1.0.0",

"name":"House$houseIdAlertStream",

"version":"1.0.0",

"nickName":"",

"description":"",

"metaData":[

],

"correlationData":[

],

"payloadData":[

"name":"house_id",

"type":"INT"

},

​ "name":"type",

"type":"STRING"

},

​CC BY 4.0                                      ​You are free to share and adapt for any purpose, even commercially.


"name":"message",

"type":"STRING"

Add Execution Plan Configuration


Add the following configuration under the ​<template type="eventstream">​ element.

<template type="realtime">

<![CDATA[@Plan:name('House$houseIdPowerConsumptionAlerts')

@Import('SMARTHOME_DATA:1.0.0')
define stream dataIn (id string, value float, property bool,
plug_id int, household_id int, house_id int);

@Export('House$houseIdAlertStream:1.0.0')
define stream alertStream (house_id int, type string, message
string);

from dataIn[house_id==$houseId and value>$maxValue]


select house_id, "alert" as type, "usage it too high" as
message
insert into alertStream;

from dataIn[house_id==$houseId and value<$minValue]


select house_id, "warning" as type, "usage it too low" as
message
insert into alertStream;]]>

</template>

Add Publisher Configuration


Add the following configuration under the ​<template type="eventstream">​ element.

​CC BY 4.0                                      ​You are free to share and adapt for any purpose, even commercially.


<template type="event publisher">

<![CDATA[<?xml version="1.0" encoding="UTF-8"?>


<eventPublisher name="House$houseIdAlertPublisher"
statistics="disable" trace="disable"
xmlns="http://wso2.org/carbon/eventpublisher">
<from streamName="House$houseIdAlertStream"
version="1.0.0"/>
<mapping customMapping="disable" type="json"/>
<to eventAdapterType="logger">
<property
name="uniqueId">House$houseIdAlertPublisher</property>
</to>
</eventPublisher>]]>

</template>

Add Parameter Configurations

<parameters>
<parameter name="houseId" type="int">
<displayName>House ID</displayName>
<description>ID of the House</description>
<defaultValue>39</defaultValue>
</parameter>
<parameter name="maxValue" type="long">
<displayName>Maximum threshold</displayName>
<description>Maximum threshold value</description>
<defaultValue>100</defaultValue>
</parameter>
<parameter name="minValue" type="long">
<displayName>Minimum threshold</displayName>
<description>Minimum threshold value</description>
<defaultValue>10</defaultValue>
</parameter>
</parameters>

​CC BY 4.0                                      ​You are free to share and adapt for any purpose, even commercially.


Expected Outcome
Restart the DAS server and log into the DAS Management Console. In the ​Main​ tab, click
Template Manager​ to open the ​Domains​ page. The ​PowerConsumptionAlerts​ domain is
displayed as follows.

​CC BY 4.0                                      ​You are free to share and adapt for any purpose, even commercially.


Lab: ​Using a Template
Training Objective
Generating DAS artifacts from a template instead of manually defining them.

Business Scenario
Smarthome Info needs:
● A new execution plan that uses the existing ​Smarthome_Data​ stream as the input
stream.
● A new event stream that serves as the output stream to the new execution plan.

Detailed Instructions
Follo2
1. Log into the WSO2 DAS Management Console. (If the DAS server was already running
at the time you created the template, you need to restart it.
2. In the ​Main​ tab, click ​Template Manager​ to open the ​Domains​ page. The
PowerConsumptionAlerts​ template is displayed as shown below.

​CC BY 4.0                                      ​You are free to share and adapt for any purpose, even commercially.


3. Click on the ​PowerConsumptionAlerts​ template to open the ​Deployed Scenarios
page.

4. Click ​Create New Scenario ​to open the ​Edit Scenario​ page, and enter information as
follows.

Field Value

Scenario Type PowerConsumptionAlerts

Scenario Name UsageHouse39

Description Analyze usage of House 39

House ID 39

Maximum Threshold 100

Minimum Threshold 10

5. Click ​Add Scenario​.

Expected Outcome
The scenario is added to the list of deployed scenarios as shown below.

​CC BY 4.0                                      ​You are free to share and adapt for any purpose, even commercially.


If you go to the ​Main​ tab and click ​Flow​, you should see the event flow updated as follows.

● To view details of the execution plan, open the ​Main​ => ​Execution Plans​ => ​Available
Execution Plans​ page and click
PowerConsumptionAlerts-PowerConsumptionAlerts-UsageHouse39-realtime1​.
● ​ ain​ => ​Event Streams​ => ​Available Event
To view details of the event stream, open the M
Streams​ page and click ​House39AlertStream:1.0.0​.

​CC BY 4.0                                      ​You are free to share and adapt for any purpose, even commercially.


Lab: Setting Up a Minimum HA Deployment Cluster
Training Objective
Setting up a high availability WSO2 DAS cluster with two nodes. A minimum high availability
cluster consists of two nodes. One node serves as the active node and the other serves as the
passive node. If the active node fails, the passive node becomes the active node so that
processing of events is continued without interruption or loss of data.

For more information, see ​WSO2 Clustering Guide - Minimum High Availability Deployment -
DAS 3.1.0​.

Business Scenario
Smarthome Info needs to ensure high system availability to ensure that it suffers no loss as a
result of system failure.

Detailed Instructions
For detailed instructions, see ​WSO2 Clustering Guide - Minimum High Availability Deployment -
DAS 3.1.0​.

​CC BY 4.0                                      ​You are free to share and adapt for any purpose, even commercially.

Вам также может понравиться