Managing Business Rules via Templates
Introduction
In the previous tutorials, you covered various Siddhi concepts and created many Siddhi applications to try them out. In many scenarios, the basic outline of the Siddhi application has been the same. For example, the sources defined for SweetBots are same across multiple Siddhi applications. Furthermore, Siddhi application functionality can be templated so that conditions can be changed over time. Business Rules Management dashboard is a user friendly interface that can be used to build business rules (Siddhi applications customized as per business requirements).
Previously (in tutorial 7), you created a Siddhi application to observe KPIs. The Factory Foreman of the Sweet Factory needs to set different KPIs for the different categories of sweets. For this purpose, you need to template the Siddhi application for KPI analysis that you created in tutorial 7. Using this template, you can create different business rules based on sweet names, surplusMinThresholdInput
, and the start and end of work hours.
Before you begin:
Before creating business rules, the required templates must be defined. The following is a sample template you can use in this tutorial.
This template must be placed in the <SP_HOME>/wso2/dashboard/resources/businessRules/templates
directory as Sweet_Production_Factory.json
.
The group UUID (sweet-production-factory
) which is in the ruleTemplates
must be added in the <SP_HOME>/conf/dashboard/deployment.yaml
file under the wso2.business.rules.manager
namespace as shown below.
wso2.business.rules.manager: datasource: BUSINESS_RULES_DB # rule template wise configuration for deploying business rules deployment_configs: - #ip:port of the node localhost:9090: # uuids of rule templates which are needed to be deployed on the node given above - sweet-production-factory # credentials for worker nodes username: admin password: admin
For more information, see Business Rules Templates.
Tutorial steps
Let's get started!
In this tutorial, the dashboard environment is started in the same computer as the worker environment for simplicity.
- To start the dashboard profile of WSO2 SP, issue one of the following commands from the
<SP_HOME>/bin
directory.For Windows:
dashboard.bat
For Linux:
sh dashboard.sh
Now start the worker profile of WSO2 SP, issue one of the following commands from the
<SP_HOME>/bin
directory. This is needed when saving and deploying a business rule.For Windows:
worker.bat
For Linux:
sh worker.sh
- You can access the Business Rules dashboard via the following URL.
https://localhost:9643/business-rules
Then login by specifying
admin
as both the username and the password.This step uses the default URL and credentials. If the dashboard user store is changed, use a valid credential and ensure that the user has valid permisions for adding and deleting workers. For more information, see User Management.
To create a new rule that can be used for KPI analysis, let's click CREATE.
If previously defined business rules exist, they are displayed as shown in the example below. You can click + to add a new business rule.
- The following view opens when you click CREATE. You can observe that a business rule can be created from a business template or from scratch. You have already created and saved a business rules template. Therefore, let's click From Template to create a rule from it.
- When you click From Template the
Sweet Production Factory
template that you previously created and saved is displayed as follows.
To create a rule from this template, let's click on this template. It opens as follows.
- In the Rule Template field, you can select the KPI Analysis rule template.
- You can enter values in the rule template that opens as shown below.
Click Save and Deploy to proceed. As a result, the following log is displayed in the worker console.