Create Rule¶
Action Service supports two different action types:
Predefined Action Type
Custom Action Type
Predefined Action Type¶
Action service has some predefined action types as the following:
RDBMS dumping
Callback URL
Push notification to android phone
Posting SOS data to Elastic Search DB
Event push to “syslog” Linux utility
Insert content to TCUP Sensor Observation Service
Messaging through JMS/MQTT/AMQP
Send SMS
Send Email
User plugin invoke (task)
Store parquet format data into HDFS
Calculate summary or aggregate functions on incoming data stream
Poll a data source in a given schedule
Insert in Redis stream
Detect absence of sensors data
Transformation of nested or flat structure JSON to a flat structure JSON.
Publish data to topic on MQTT broker.
Sample JSON for create rule
is listed in the section below:
{
"RuleName": " ",
"RuleDescription": " ",
"noOfInstance": " ",
"RoutingLogic": " ",
"Key": " ",
"input": {
"type": "Direct\MQ\topic",
"exchange": " ",
"topic": " ",
"MQName": " "
},
"actions": [{
"type": "action_name",
"parameter": [
{
"name": "name of the parameter",
"value": "value of parameter / path of the json to find the value ",
"type": " type of parameter",
"dataType": "data type of parameter"
}
]
}]
}
Description for create rule
JSON parameters are listed in the section below:
Parameter |
Required |
Values |
Description |
---|---|---|---|
RuleName |
true |
string |
Rule Name should be unique for every rule |
RuleDescription |
true |
string |
It should be a short description about the rule functionality |
no of Instance |
false |
integer |
It should be in the range of 1-10 which defines the parallelism factor |
RoutingLogic |
false |
string |
It should have value ConsistentHashing which defines routing logic for rule |
Key |
false |
string |
It should be the path value mentioned as (:)colon separated format.It defines consistent hashing key. |
input type |
true |
MQ/Direct/topic |
It represent type of the input from which Action Service will receive data |
exchange |
false |
string |
If the type is topic or Direct then exchange name need to be mentioned here |
topic |
false |
string |
If input type is topic then topic name need to be mentioned here |
MQName |
false |
string |
If input type is MQ then MQ name need to be mentioned here |
action type |
true |
string |
Action type name need to be mentioned here |
parameter |
true |
array element |
It contains four field 1. name 2. value 3. type 4. dataType which is used to set variable information from rule |
name |
true |
string |
It represents name of the variable |
value |
true |
string |
It represents constant value or path of the observation JSON from which value can be fetched |
type |
false |
string |
It represents type of the variable such as path,query ,JSONVar etc. |
dataType |
false |
string |
It represents data type of variable |
Note
By default RoutingLogic is in round robin fashion.
While running the rule there can be a requirement to group incoming messages based on a field so that the messages under the same group can be processed by the same worker and messages of a different group can be processed by a different worker. This type of routing logic is called ConsistentHashing. RoutingLogic need to be provided ConsistentHashing in the rule to implement this along with the Key on which the grouping will happen . For eg, if grouping to be done on sensor id, then Key should be observations:sensor
, similarly for grouping with feature, the Key in the rule should be observations:feature
.
In the Key, field value should be mentioned. It could be any field present in the incoming messages.
Every parameter needed to perform action will be mentioned as element in the parameter array in the following format:
{
"name": "name of the parameter",
"value": "value of parameter / path of the json to find the value ",
"type": " type of parameter",
"dataType": "data type of parameter"
}
Note
Value field has maximum size of 2000 bytes. Please contact the administrator if you need more space.
Different input JSON needed for different action types are listed below:
Action Rule can be created either from swagger API Sandbox or from portal. To create the rule from swagger, click on POST actionRules API in swagger, give the input JSON and hit Try it out!
button, it will create an action rule. JSON for each action type is given in the respective section. User can use those json as template to create the rule using swagger.
The swagger image for create rule
is as follows:
Note
Before operating on any of the above API, user needs to have authentication to access API along with
x-api-key
which enables them to use Action Service.
Action Rule Using Portal¶
Create Action Rule
Action Rule can be created using the portal as shown below.
Select Action Service from the portal page (left hand side after expanding services) and then click on create.
Fill in the details as mentioned in the image below and then select Action Type from the dropdown.
Fill in the details after selecting the Action Type and then click on ‘Create Rule’. The input JSONs of different action types can be referred to fill in the details.
Search Action Rule by Rule Name
An action rule can be searched by typing the rule name as mentioned in the image below.
Search Action Rule by Status
Similarly an action rule can be searched by status as mentioned in the image below.
Search Action Rule by Action Type
Action Rule can also be searched by selecting the Action Type as mentioned in the image below.
Custom Action Type¶
Users can create own custom action type and add it in the action service. Users can follow Appendix 1 for implementing a new custom type. Users have to create a runnable jar and give it to TCUP admin along with the class name for addition in Action Service. The process to add a new custom type is as follows:
Create Action Type¶
Action type can be created in 3 ways:
1.Using Postman
Download REST client API like Postman from the following link https://www.getpostman.com/downloads/
POST http://<domainname>/admingw/ActionModule/v1.0/actionTypes/{type}/{className}
Enter the headers. On clicking on
SEND
button of Postman client with jar file and mentioning action type name, class name in the path, the admin can create new action type as in the image below:
2.Using CURL command
We need to copy the JarfileName.jar to one of the docker container inside the cluster nodes. And execute the below CURL command to upload the custom action jar file to the Action service.
Curl Command to upload a Custom Action Type
curl -X POST –header ‘Content-Type: multipart/form-data’ –header ‘Accept: application/json’ –header ‘x-api-key: admin’ ‘http://<domainname>/ActionModule/v1.0/actionTypes/{type}/{className}’ -F ‘JarFile=@{/path/to/Jarfile/JarFileName.jar}’
3.Using Admin API sandbox (Applicable from R11 onwards)
Click on API Sandbox -> Action Service and then create the action type.
Warning
Above API service can only be accessed by TCUP admin.
Bigger size custom jar file upload support
Default size of custom action type is set to 100MB in the application.conf of the service. In case need to update further, the below parameters can be updated in application.conf:
play.http.parser.maxMemoryBuffer = 100000K
play.http.parser.maxDiskBuffer = 100000K
Warning
Above API service can only be accessed by TCUP admin.
Update Action Type¶
It updates an action type. An action type can be updated in 3 ways:
1.Using Postman
PUT http://<domainname>/admingw/ActionModule/v1.0/actionTypes/{type}/{className}
Enter the headers.On clicking on
SEND
button of Postman client with jar file and mentioning action type name, class name in the path, the admin can update action type as in the image below:
2.Using Curl Command
We need to copy the JarfileName.jar to one of the docker container inside the cluster nodes. And execute the below CURL command to upload the custom action jar file to the Action service.
Curl Command to update a Custom Action Type
curl -X PUT –header ‘Content-Type: multipart/form-data’ –header ‘Accept: application/json’ –header ‘x-api-key: admin’ ‘http://<domainname>/ActionModule/v1.0/actionTypes/{type}/{className}’ -F ‘JarFile=@{/path/to/Jarfile/JarFileName.jar}’
3.Using Admin API sandbox (Applicable from R11 onwards)
Click on Admin API Sandbox -> Action Service and then update the action type.
Warning
Above API service can only be accessed by TCUP admin.
Create Validation JSON¶
It adds validation JSON to an action type.It can be done in 2 ways:
1.Using Postman
PUT http://<domainname>/admingw/ActionModule/v1.0/actionTypes/{type}
On clicking on
SEND
button of Postman client with jar file and mentioning action type name, the admin can add validation JSON to an action type as in the image below:
2.Using Admin API sandbox (Applicable from R11 onwards)
Click on Admin API Sandbox -> Action Service and then add the validation json for custom action type.
Warning
Above API service can only be accessed by TCUP admin.
Get All Action Type¶
It lists all the available action types.
GET http://<domain name>/ActionModule/v1.0/actionTypes
Click on GET actionType API in swagger and hit
Try it out!
button, it will display all the action type as below:
[
{
"actionId": 1,
"actionType": "SOS",
"jarName": "SOSAction.jar",
"className": "SOSAction"
},
{
"actionId": 2,
"actionType": "ESREGISTRATION",
"jarName": "ESREGISTRATION.jar",
"className": "ESREGISTRATION"
},
{
"actionId": 3,
"actionType": "RDBMS",
"jarName": "RDBMSAction.jar",
"className": "RDBMSAction"
}
]
The swagger image for GET actionType API is as below:
Get a Specific Action Type¶
It gives a specific action type based on action type name.
GET http://<domainname>/ActionModule/v1.0/actionTypes/{type}
Click on GET actionType/{actionType} API in swagger, give action type and hit
Try it out!
button, it will display the action rule of the mentioned action type as below:
{
"actionId": 2,
"actionType": "ESREGISTRATION",
"jarName": "ESREGISTRATION.jar",
"className": "ESREGISTRATION",
"validationJson": {
"mandatory": [{
"name": "connectorURL",
"dataType": "string"
}, {
"name": "connectionTimeout",
"dataType": "integer"
}, {
"name": "mappingName",
"dataType": "string"
}, {
"name": "indexName",
"dataType": "string"
}],
"optional": [{
"name": "",
"value": "",
"type": [
"header",
"path",
"query"
],
"dataType": ""
}]
}
}
The swagger image for GET a specific actionType API is as below:
Delete an Action Type¶
This will delete an action type. An admin can only delete an action type. An action type can be deleted in 3 ways:
1.Using Postman
DELETE http://<domainname>/admingw/ActionModule/v1.0/actionTypes/{type}
On clicking on
SEND
button of Postman or rest client with mentioning action type name in the path, the admin can delete an action type as in the image below:
The image for DELETE a specific actionType API is as below:
2.Using Curl Command
Execute the below CURL command to delete the custom action jar file from the Action service.
curl -X DELETE –header ‘Accept: application/json’ –header ‘x-api-key: admin’ ‘http://<domainname>/ActionModule/v1.0/actionTypes/{type}’
3.Using Admin API sandbox (Applicable from R11 onwards)
Click on Admin API Sandbox -> Action Service and then delete the action type.
Note
Above API service can only be accessed by TCUP admin.