Kraken Rules and Decision Tables
Kraken Rules and Decision Tables
© Copyright EIS Software Limited. Please do not use or duplicate without express authorization.
Training Overview
Agenda:
▸ Business Rules Approach in V20
▸ Kraken Rule Engine
▸ Decision Table Framework
▸ Kraken and DT Integration in V20 Stack
2 © Copyright EIS Software Limited. Please do not use or duplicate without express authorization.
Business Rules Approach in V20
3 © Copyright EIS Software Limited. Please do not use or duplicate without express authorization.
Business Rules in V20
Rule driven data validation on Lightweight Decision Table Engine, Full blown rule engine, used for
backend and client side used to organize and externalise complex business rules and
rule logic in tabular fashion invoked as stand alone service
4 © Copyright EIS Software Limited. Please do not use or duplicate without express authorization.
Business Rules for Validation: Why?
Why are we using business rule engine for data We need to externalize validation logic from
validation? code, and have defined in centralized manner, so
it is accessible for non-developers
There are already dozens of validation
frameworks, that can be applied on UI, REST We need ability rearrange and reuse the same
endpoint, service code or persistence layer validation logic in different places and different
use cases
Why increase complexity, when “it’s just simpler
to code”? We need support variability of validation logic
based on some parameters
5 © Copyright EIS Software Limited. Please do not use or duplicate without express authorization.
Building our own Rules Engine: Why?
Why we decided to build rules validation engine As a rule of thumb, typically 90% of complexity is
from scratch? not in engine itself, but in it’s integration
There are lots of different rule engine We needed ability to evaluate same validation
implementations of varying complexity rules on backend and UI
We already have BLS engine from V12 High variability of validation logic prevents using
static model based implementations
6 © Copyright EIS Software Limited. Please do not use or duplicate without express authorization.
Kraken Rule Engine
7 © Copyright EIS Software Limited. Please do not use or duplicate without express authorization.
What is Kraken?
8 © Copyright EIS Software Limited. Please do not use or duplicate without express authorization.
Kraken: Design Overview
9 © Copyright EIS Software Limited. Please do not use or duplicate without express authorization.
Kraken Design Time Model
10 © Copyright EIS Software Limited. Please do not use or duplicate without express authorization.
Kraken Designtime Model
– Entry Points, which specify which rules should be evaluated on rule engine
invocation
11 © Copyright EIS Software Limited. Please do not use or duplicate without express authorization.
Kraken Rule: Structure
Rule is a definition of logic to be executed Rule Header identifies rule. It consist of these parts:
against its target attribute under specific ▸ rule name
conditions. ▸ target context name
▸ target attribute
Rule name semantically identifies rule.
Rule Metadata contains customisable information about the
rule:
▸ dimension values
Condition is a boolean expression to determine if rule is
active for particular context instance. If condition is omitted,
rule will be always active.
Rule Payload defines action to be performed if rule is active.
12 © Copyright EIS Software Limited. Please do not use or duplicate without express authorization.
Kraken Rule: Payload Types
13 © Copyright EIS Software Limited. Please do not use or duplicate without express authorization.
Validation Payload Types
Payload Type Description Sample Can Be Defined On
Assertion Asserts custom validation logic in form of Rule "AssertRule" On Coverage.limitAmount Any primitive field
boolean expression. Field is valid only Assert limitAmount > 100
expression evaluates to true Error "code" : "Limit Amount must be more than 100"
RegExp Asserts that text matches regular expression Rule "RegExpRule" On Account.name String field
Assert Matches "^[a-zA-Z]*"
Error "code" : "Name must contain only letters"
Length Specifies maximum length of the string Rule "LengthRule" On Account.name String field
Assert Length 31
Error "code" : "Name must not be longer than 31"
Usage Asserts that field is mandatory (not empty) Rule "MandatoryRule" On Account.name Any non-collection
Set Mandatory field
Error "code" : "Name must be entered"
Size Range Asserts range of size for collection. One of Rule "SizeRange" On Policy.drivers { Collection field
boundaries (min or max) can be omitted to have Assert Size Min 2 Max 3
open range }
14 © Copyright EIS Software Limited. Please do not use or duplicate without express authorization.
Kraken Model: Entry Point
15 © Copyright EIS Software Limited. Please do not use or duplicate without express authorization.
Entry Point Samples
16 © Copyright EIS Software Limited. Please do not use or duplicate without express authorization.
Kraken Model: Context Definition
▸ Context Definitions define how data to be validated should be accessed by rule engine
▸ They are used to create abstract data model, against which rules are defined and executed - a vocabulary for rules
model
▸ Each Context Definition defines an entity to be validated by rules, is identified by context name, and can define
list of child context names, forming a tree structure
▸ Such structure allows to have decoupled and implementation agnostic representation of target domain model.
Rules can be executed on any data, corresponding to this representation model
▸ Context Model instructs Kraken rule engine, how to navigate the data image to access entities on which rules
need to be executed
17 © Copyright EIS Software Limited. Please do not use or duplicate without express authorization.
Context Definition Mapping
18 © Copyright EIS Software Limited. Please do not use or duplicate without express authorization.
Context Definition Mapping
19 © Copyright EIS Software Limited. Please do not use or duplicate without express authorization.
Context Definition Samples
20 © Copyright EIS Software Limited. Please do not use or duplicate without express authorization.
Kraken Expression Language (KEL)
21 © Copyright EIS Software Limited. Please do not use or duplicate without express authorization.
Kraken Expression Language
22 © Copyright EIS Software Limited. Please do not use or duplicate without express authorization.
Kraken Expression Language: Features
23 © Copyright EIS Software Limited. Please do not use or duplicate without express authorization.
Referencing Context Definition Fields
24 © Copyright EIS Software Limited. Please do not use or duplicate without express authorization.
Cross Context References
25 © Copyright EIS Software Limited. Please do not use or duplicate without express authorization.
Resolving Cross Context Reference Candidates
▸ This diagram depicts the order in
which Kraken engine will try to resolve
Cross Context Reference
▸ For sake of simplification, context
inheritance is not displayed
▸ The numbers depict priority by which
reference will be treated by
unambiguous
▸ If there will be two candidates with
same priority, error will be reported
(e.g. Address in this case)
▸ This graph is traversed starting from
each component on which rule with
CCRs is defined
26 © Copyright EIS Software Limited. Please do not use or duplicate without express authorization.
Referencing a Collection of Context Definitions
27 © Copyright EIS Software Limited. Please do not use or duplicate without express authorization.
Handling Rule Variability
28 © Copyright EIS Software Limited. Please do not use or duplicate without express authorization.
Rule Variability and Dimensions
▸ When rule logic needs to be varied based ▸ Rule Dimension - named external
on one or multiple external parameters parameter by which value rule’s contents
▸ Essentially can be represented by “if - need to be varied
else if - else if -...- else” conditions ▸ Referenced in “if-else if-.....-else”
▸ Moving this conditions out of rule conditions from the rule body
definition, and varying rule ▸ Multiple dimensions can be used
implementation itself is desirable ▸ Used to support variability for packages
approach from maintenance and and versioning
readability perspective ▸ Dynamic vs static approach
▸ Kraken Engine achieves this by using
dimensions and dimension aware rule
repositories
29 © Copyright EIS Software Limited. Please do not use or duplicate without express authorization.
Handling Multiple Dimensions
Examples of:
non dimensional (top left),
one dimensional (top right),
two dimensional (bottom left)
rule variability spaces
30 © Copyright EIS Software Limited. Please do not use or duplicate without express authorization.
Handling Multiple Dimensions
31 © Copyright EIS Software Limited. Please do not use or duplicate without express authorization.
Dynamic Rule Resolution and Variability
@Dimension("packageCd", "Barber")
Default To 200
Default To 250
32 © Copyright EIS Software Limited. Please do not use or duplicate without express authorization.
Rule Variability - Visualisation
33 © Copyright EIS Software Limited. Please do not use or duplicate without express authorization.
Kraken Runtime
34 © Copyright EIS Software Limited. Please do not use or duplicate without express authorization.
Kraken Evaluation Flow
▸ All Kraken model elements are loosely coupled, using semantic names
▸ This allows to resolve actual model configuration in runtime, just before rule execution
▸ Model elements are resolved by KrakenRuntimeRepository, which provided compiled rule
model data, loaded from DSL
▸ This approach can be extended by using Dynamic Rule Repository
35 © Copyright EIS Software Limited. Please do not use or duplicate without express authorization.
Kraken Evaluation Flow
36 © Copyright EIS Software Limited. Please do not use or duplicate without express authorization.
Interpreting Rule Evaluation Results
• Sample implementations:
– Validation status reducer
– Field metadata reducer (UI)
• Documentation in wiki
37 © Copyright EIS Software Limited. Please do not use or duplicate without express authorization.
Designtime to Runtime Translation
38 © Copyright EIS Software Limited. Please do not use or duplicate without express authorization.
Decision Table Framework
39 © Copyright EIS Software Limited. Please do not use or duplicate without express authorization.
What is a Decision Table?
40 © Copyright EIS Software Limited. Please do not use or duplicate without express authorization.
Decision Table Framework
41 © Copyright EIS Software Limited. Please do not use or duplicate without express authorization.
Decision Table Parts
42 © Copyright EIS Software Limited. Please do not use or duplicate without express authorization.
Anatomy of Decision Table
43 © Copyright EIS Software Limited. Please do not use or duplicate without express authorization.
Decision Table Structure
From the point of rule, input column is part of rule condition. All input columns together form a composite rule
condition.
Input columns are defined by:
▸ Name: Human readable, unique column name
▸ Input Expression: Will be evaluated and the result is a subject for that input column. Input Expressions are
written in Kraken Expression Language
44 © Copyright EIS Software Limited. Please do not use or duplicate without express authorization.
Aspect Columns
Aspect is Decision Table output that models some known property in the system that has explicit support for decision
tables. In other words, aspect is decision table output that the system knows how to interpret.
Aspect column works as output for the purpose of determining Decision Table evaluation result according to HitPolicy.
Example of Aspects:
▸ Kraken Rule Payload Aspects (e.g., default, min, reset, etc.)
▸ Policy specific aspects:
– applicability
– relationshipType
– entryPoints
Another special feature of aspect is that Decision Table Framework allows to call decision tables
by aspect, thus evaluating multiple decision tables at once.
This feature is key for Kraken Integration.
45 © Copyright EIS Software Limited. Please do not use or duplicate without express authorization.
Defining Kraken Rules in Decision Tables
46 © Copyright EIS Software Limited. Please do not use or duplicate without express authorization.
Kraken Aspects
47 © Copyright EIS Software Limited. Please do not use or duplicate without express authorization.
Kraken and DT Integration in V20 Stack
48 © Copyright EIS Software Limited. Please do not use or duplicate without express authorization.
Rules Component In V20
49 © Copyright EIS Software Limited. Please do not use or duplicate without express authorization.
Product Rules Configuration: Rules Model
Due dynamic behavior, Kraken rules are not assigned directly to the product. Instead Rules Model is defined for particular
product domain model, in *.grules DSL file. It specifies Kraken entry points and decision tables which are required for
particular product.
Model RulesAutoPolicy
Namespace AutoRules
EntryPoints [
"Validation",
"Presentational",
"Issue"
]
Decision Tables [
"ValueList",
"UserRole" from common,
"IceCreamPrice" from common
]
VersioningConfiguration [
"Package Code"
"Plan Code"
]
ExternalContext {
context : {
external : {
prev : PrevRevisionProjection
}
securityContext : SecurityContext
}
}
50 © Copyright EIS Software Limited. Please do not use or duplicate without express authorization.
Integration with Domain Model
▸ Dimensions are defined in domain model using
@Dimension annotation:
@Dimension("vehiclePlanCd")
Attr planCd: String
51 © Copyright EIS Software Limited. Please do not use or duplicate without express authorization.
Decision Table and Kraken Integration
▸ Implementation of
DynamicRulesRepository is provided,
which calls DecisionTable engine, and
generates Kraken rules from DT
response
52 © Copyright EIS Software Limited. Please do not use or duplicate without express authorization.
Integrating rules into new project
Following two guides describe procedure how to integrate Kraken and Decision Tables into new
V20 based project from scratch:
▸ Kraken integration guide
▸ Decision Table integration guide
53 © Copyright EIS Software Limited. Please do not use or duplicate without express authorization.
Invoking Rules From V20
54 © Copyright EIS Software Limited. Please do not use or duplicate without express authorization.
Dimension Value Resolver
▸ DimensionResolver
– Resolves dimension values for decision table inputs from domain entity by dimension annotations
55 © Copyright EIS Software Limited. Please do not use or duplicate without express authorization.
Release and Packaging
56 © Copyright EIS Software Limited. Please do not use or duplicate without express authorization.
Anatomy of Rules Component
▸ All rules related functionality,
is packaged in Rules
component
▸ Rules component is
configured to have matching
versions of Kraken backend
and UI
▸ Other subsystems must
integrate through Rules
component
▸ It must be ensured, that
same Rules component
version is used on backend
and UI
57 © Copyright EIS Software Limited. Please do not use or duplicate without express authorization.
Rules Component Dependencies in V20 Stack
58 © Copyright EIS Software Limited. Please do not use or duplicate without express authorization.