DAS Capp is used to defining the artifacts, and ship to DAS as an archive. There are about 7 types of artifacts. Here I will show how to create a capp for analyzing stream data. For that, we need around 4 artifacts type. Those are,
Event Streams, Event receivers, Event stores, and Analytics Scripts.
A simple example for this scenario is said wso2 APIM need to get statistic data for their API manager usage. In that case, APIM published the event stream to the DAS and DAS do the analytics and provide the summarized data. To support this scenario the simplest thing would be defined the required artifacts as a capp and providing to the DAS. The Capp contain the definition for stream and the data formats to process.
let's define the stream format as below and Stream definition is saved in JSON format. For that, you need to provide the unique name for the stream name. There is two section named metadata and payload data. metadata section leaves it as default and you modify the payload section as you wish. It contains the actual data format you are publishing.
create org.wso2.sample.stream_1.0.0.json file and put the following content.
{ "streamId": "org.wso2.capp.sample:1.0.0", "name": "org.wso2.capp.sample", "version": "1.0.0", "nickName": "", "description": "sample data stream", "metaData": [], "correlationData": [], "payloadData": [ { "name": "api", "type": "STRING" }, { "name": "user", "type": "STRING" }, { "name": "application", "type": "STRING" }, { "name": "request", "type": "STRING" } ] }
Next, this would be defining this as an artifact. To form stream artifacts moved the above JSON file to the directory called EventStream_Sample_1.0.0. Then you need to add artifact.xml to define the artifact information inside the directory you created.
add the following to the artifact.xml
<?xml version="1.0" encoding="UTF-8"?> <artifact name="Eventstream_sample" version="1.0.0" type="event/stream" serverRole="DataAnalyticsServer"> <file>org.wso2.sample.stream_1.0.0.json</file> </artifact>
make sure the correct artifact name and filename are defined.
Then define how to persist data to internal DAS Tables. Next, we create artifacts for the store. create another directory called Eventstore_sample_1.0.0. inside that, we create ORG_WSO2_CAPP_SAMPLE.xml and artifact.xml as below.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <EventStoreConfiguration> <Source> <StreamId>org.wso2.capp.sample:1.0.0</StreamId> </Source> <TableSchema> <ColumnDefinition> <Name>api</Name> <EnableIndexing>true</EnableIndexing> <IsPrimaryKey>false</IsPrimaryKey> <EnableScoreParam>false</EnableScoreParam> <Type>STRING</Type> </ColumnDefinition> <ColumnDefinition> <Name>user</Name> <EnableIndexing>true</EnableIndexing> <IsPrimaryKey>false</IsPrimaryKey> <EnableScoreParam>false</EnableScoreParam> <Type>STRING</Type> </ColumnDefinition> <ColumnDefinition> <Name>application</Name> <EnableIndexing>true</EnableIndexing> <IsPrimaryKey>false</IsPrimaryKey> <EnableScoreParam>false</EnableScoreParam> <Type>STRING</Type> </ColumnDefinition> <ColumnDefinition> <Name>request</Name> <EnableIndexing>true</EnableIndexing> <IsPrimaryKey>false</IsPrimaryKey> <EnableScoreParam>false</EnableScoreParam> <Type>INTEGER</Type> </ColumnDefinition> </TableSchema> </EventStoreConfiguration>
ORG_WSO2_CAPP_SAMPLE.xml has column definition tags. which used to define the Table definition of the Table create for the Stream. There you can find 5 child elements as below. use them as appropriate
‹Name›consumerKey‹/Name› column name ‹EnableIndexing›true‹/EnableIndexing› need indexing, if you hope to use REST api this should be true ‹IsPrimaryKey›false‹/IsPrimaryKey› is it primary key ‹EnableScoreParam›false‹/EnableScoreParam› ‹Type›STRING‹/Type›
The data type of the column, it supports primitive type and a special type called facet. Use facet if u are hoping to use drill-down operations.
Then define the artifact.xml as similar to this
<?xml version="1.0" encoding="UTF-8"?> <artifact name="Eventstore_sample" version="1.0.0" type="analytics/eventstore" serverRole="DataAnalyticsServer"> <file>ORG_WSO2_CAPP_SAMPLE.xml</file> </artifact>
Next, need to bind the stream to the table using receivers. Create another directory Eventreceiver_sample_1.0.0 for the receiver. Then create EventReceiver_sample.xml and artifact.xml, and put the following content and as below
EventReceiver_sample.xml
<?xml version="1.0" encoding="UTF-8"?> <eventReceiver name="EventReceiver_sample" statistics="disable" trace="disable" xmlns="http://wso2.org/carbon/eventreceiver"> <from eventAdapterType="wso2event"> <property name="events.duplicated.in.cluster">false</property> </from> <mapping customMapping="disable" type="wso2event"/> <to streamName="org.wso2.capp.sample" version="1.0.0"/> </eventReceiver>
<?xml version="1.0" encoding="UTF-8"?> <artifact name="Eventreceiver_sample" version="1.0.0" type="event/receiver" serverRole="DataAnalyticsServer"> <file>EventReceiver_sample.xml</file> </artifact>
At last, you need to define the spark scripts which do the correct summarization. Now we have to define the artifact for the script. Create Sparkscripts_1.0.0 directory and create sample_script.xml and artifact.xml as below
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <Analytics> <Name>sample_script</Name> <Script> create temporary table sampleData USING CarbonAnalytics OPTIONS(tableName "ORG_WSO2_CAPP_SAMPLE"); select * from sampleData; </Script> <CronExpression>0 0/5 * 1/1 * ? *</CronExpression> </Analytics>
<?xml version="1.0" encoding="UTF-8"?> <artifact name="Sparkscripts" version="1.0.0" type="analytics/spark" serverRole="DataAnalyticsServer"> <file>sample_script.xml</file> </artifact>
Creating achieve from the artifacts we have defined all the artifacts for the capp. Now we create the deployable artifact for the all the artifacts. Create the artifacts.xml same directory that all other artifacts directory contains. Then define the artifacts.xml as below.
<?xml version="1.0" encoding="UTF-8"?> <artifacts> <artifact name="SAMPLE_CAPP" version="v1.0.0" type="carbon/application"> <dependency artifact="Eventstream_sample" version="1.0.0" include="true" serverRole="DataAnalyticsServer"/> <dependency artifact="Eventstore_sample" version="1.0.0" include="true" serverRole="DataAnalyticsServer"/> <dependency artifact="Eventreceiver_sample" version="1.0.0" include="true" serverRole="DataAnalyticsServer"/> <dependency artifact="Sparkscripts" version="1.0.0" include="true" serverRole="DataAnalyticsServer"/> </artifact> </artifacts>
capp is the normal .zip file with .car extension. To create archive select all the artifacts and zip it. In the zip, it should contain all the artifacts directory and artifacts.xml at the root level of the zip. Rename archive extension from .zip to .car after zipped.
Download the sample from here
Add Comment
Comments (0)