This documentation is for WSO2 Stream Processor 4.4.0 (the latest version of WSO2 SP. View documentation for the Streaming Integrator, the successor of WSO2 SP.

All docs This doc
||
Skip to end of metadata
Go to start of metadata

Rule Templates are used as specifications to gain inputs from users through dynamically generated fields, for creating business rules. A template group is a business domain level grouping. The definition of a template looks as follows.

{
  "templateGroup" : {
    "name" : "<Name of the template group>",
    "uuid":"<UUID for the template group>",
    "description" : "<(Optional) description for the template group>",
    "ruleTemplates" : [
      {
        "name" : "<Name of the rule template>" ,
        "uuid" : "<UUID for the rule template>",
        "type" : "template",
        "instanceCount" : "one <or> many",
        "description" : "<(Optional) description for the rule template>",
        "script" : "<(Optional) Javascript with reference to the properties>",
        "templates" : [
          { "type" : "siddhiApp",
            "content" : "<SiddhiApp_1 with ${templatedProperty_x}>"
          },
          { "type" : "siddhiApp",
            "content" : "<SiddhiApp_n with ${templatedProperty_y}>"
          }
        ],
        "properties" : {
            "templatedProperty_x" : {"fieldName" : "<Field name for the property>", "description" : "<Description for the property>", "defaultValue" : "<Default value for the property>"},
            "templatedProperty_y" : {"fieldName" : "<Field name for the property>", "description" : "<Description for the property>", "defaultValue" : "<Default value for the property>", "options" : ["<option_1>", "<option_n>"]}
        }
      },
      {
        "name" : "<Name of the rule template>",
        "uuid" : "<UUID for the rule template>",
        "type" : "input",
        "instanceCount" : "one <or> many",
        "description" : "<(Optional) description for the rule template>",
        "script" : "<(Optional) Javascript with reference to the properties>",
        "templates" : [
          { "type" : "siddhiApp",
            "content" : "<SiddhiApp with ${templatedProperty_x}>",
            "exposedStreamDefinition" :"<Exposed stream definition>"
          }
        ],
        "properties" : {
          "templatedProperty_x" : {"fieldName" : "<Field name for the property>", "description" : "<Description for the property>", "defaultValue" : "<Default value for the property>", "options" : ["<option_1>", "<option_n>"]}
        }
      },
      {
        "name" : "<Name of the rule template>",
        "uuid" : "<UUID for the rule template>",
        "type" : "output",
        "instanceCount" : "one <or> many",
        "description" : "<(Optional) description for the rule template>",
        "script" : "<(Optional) Javascript with reference to the properties>",
        "templates" : [
          { "type" : "siddhiApp",
            "content" : "<SiddhiApp with ${templatedProperty_x}>",
            "exposedStreamDefinition" :"<Exposed stream definition>"
          }
        ],
        "properties" : {
          "templatedProperty_x" : {"fieldName" : "<Field name for the property>", "description" : "<Description for the property>", "defaultValue" : "<Default value for the property>", "options" : ["<option_1>", "<option_n>"]}
        }
      }
    ]
  }
}

The following parameters are configured:

Template Group basic data

The following parameters are configured under templateGroup.

ParameterDescriptionRequired/Optional
nameA name for the template group
Required
uuidA uniquely identifiable id for the template groupRequired
descriptionA description for the template.Optional

Rule Template details

Multiple rule templates can be defined under a templateGroup. For each ruleTemplate, the following set of parameters need to be configured:

ParameterDescriptionRequired/Optional
nameA name for the rule templateRequired
uuidA uniquely identifiable id for the rule templateRequired
typeThe type of the rule template. Possible values are as follows:
  • template: Used only to create an entire business rule from template
  • input : Used only in creating a business rule from scratch
  • output : Used only in creating a business rule from scratch
Required
instanceCount

This specifies whether the business rules derived from the template can be deployed only on one node, or whether they can be deployed on many nodes.

Possible values are as follows:

  • one
  • many
Required
script
The Java script to be executed on the templated fields.
Developers can use this script for:
  • validating purposes.
  • deriving values for a templated parameter by combining some other entered parameters

Each templated element that is going to be derived from entered parameters, has to be mentioned as a variable in the global scope of the javascript.

The entered parameters should be templated in the script itself, and will be later replaced with their respective entered values.

Consider the following script

/* 
* Validates a number and returns after adding 10 to it
* @throws Error when a non number is entered
*/
function deriveValue(value){
    if( !isNan(value) ) {
      return value + 10;
    }
    throw "A number is required";
}

var derivedValue = deriveValue(${enteredValue});


enteredValue should be defined as a property under properties in order to be filled by the user and replaced later.

The derived value stored in derivedValue will be then used to replace ${derivedValue} in the SiddhiApp template.

Optional
descriptionA brief description of the rule template.Optional
templates

These are the artifacts (i.e SiddhiApps) with templated parameters, that will be instantiated with replaced values when a business rule is created.

Required
properties

You can add a field name, description, default value and possible values (optional)
for the templated parameters.

Required


  1. Save the template group you created as a .json file in the <SP_HOME>/wso2/dashboard/resources/businessRules/templates directory.

  2. In the BusinessRules section of the <SP_HOME>/conf/dashboard/deployment.yaml file, add a configuration for the template you created as shown below.

    wso2.business.rules.manager:
    
      datasource: <datasourceName>
        - nodeURL1:
           - ruleTemplateUUID1
           - ruleTemplateUUID2
          nodeURL2:
           - ruleTemplateUUID1
           - ruleTemplateUUID2

    If you add this configuration, the business rules template is deployed only in the specified nodes when you run the worker and dashboard servers of your SP setup. If you do not add this configuration, the template is deployed in all the worker nodes of your SP set up.

  • No labels