Twin Cities BizTalk User Group Rule Engines: BRE vs WF Rules November 2006 Stephen Kaufman.

Slides:



Advertisements
Similar presentations
Overview and Demonstration of declarative workflows in SharePoint using Microsoft SharePoint Designer 2007 Kevin Hughes MCT, MCITP, MCSA, MCTS, MCP, Network+,
Advertisements

Chapter 10: Designing Databases
Module 11: Integrating Business Rules. Overview Lesson 1: Introduction to Business Rules Lesson 2: Integrating Business Rules.
Designing, Deploying and Managing Workflow in SharePoint Sites Steve Heaney Product Development Manager OBS
ASP.NET Best Practices Dawit Wubshet Park University.
Edoclite and Managing Client Engagements What is Edoclite? How is it used at IU? Development Process?
Feature requests for Case Manager By Spar Nord Bank A/S IBM Insight 2014 Spar Nord Bank A/S1.
Lesson 17: Configuring Security Policies
Rule Based Systems Michael J. Watts
Introduction to Windows Workflow Foundation (WF) Keith Elder Microsoft MVP Blog: Quicken Loans –
Building Enterprise Applications Using Visual Studio ®.NET Enterprise Architect.
Software Engineering and Design Principles Chapter 1.
Concepts of Version Control A Technology-Independent View.
© 2004, The Trustees of Indiana University 1 OneStart Workflow Basics Brian McGough, Manager, Systems Integration, UITS Ryan Kirkendall, Lead Developer.
Chapter 11 ASP.NET JavaScript, Third Edition. 2 Objectives Learn about client/server architecture Study server-side scripting Create ASP.NET applications.
Configuration Management
Using Microsoft SharePoint to Develop Workflow and Business Process Automation Ted Perrotte National Practice Manager, Quilogy, Microsoft Office SharePoint.
Copyrighted material John Tullis 8/13/2015 page 1 Blaze Software John Tullis DePaul Instructor
USING THE MICROSOFT BUSINESS RULES ENGINE Ed Jones MCT, MCPD, MCTS.
Matt Winkler – Technical Evangelist WF Microsoft Corporation CON312.
IBM Proof of Technology Discovering the Value of SOA with WebSphere Process Integration © 2005 IBM Corporation SOA on your terms and our expertise WebSphere.
1 Developing Rules Driven Workflows in Windows Workflow Foundation Jurgen Willis COM318 Program Manager Microsoft Corporation.
Architecture Of ASP.NET. What is ASP?  Server-side scripting technology.  Files containing HTML and scripting code.  Access via HTTP requests.  Scripting.
C++ Object Oriented 1. Class and Object The main purpose of C++ programming is to add object orientation to the C programming language and classes are.
Katanosh Morovat.   This concept is a formal approach for identifying the rules that encapsulate the structure, constraint, and control of the operation.
5/5/2005Toni Räikkönen Internet based data collection from enterprises using XML questionnaires and XCola engine CoRD Meeting May 11th 2005.
MT311 Java Application Development and Programming Languages Li Tak Sing( 李德成 )
Lecture 8 Inheritance Richard Gesick. 2 OBJECTIVES How inheritance promotes software reusability. The concepts of base classes and derived classes. To.
11 SECURITY TEMPLATES AND PLANNING Chapter 7. Chapter 7: SECURITY TEMPLATES AND PLANNING2 OVERVIEW  Understand the uses of security templates  Explain.
GrIDS -- A Graph Based Intrusion Detection System For Large Networks Paper by S. Staniford-Chen et. al.
Workflow and SharePoint Presented by Ben Geers. Overview What is workflow? Windows Workflow Foundation How does workflow apply to SharePoint? WSS v3 vs.
Developing Workflows with SharePoint Designer David Coe Application Development Consultant Microsoft Corporation.
11 MANAGING AND DISTRIBUTING SOFTWARE BY USING GROUP POLICY Chapter 5.
20411B 8: Installing, Configuring, and Troubleshooting the Network Policy Server Role Presentation: 60 minutes Lab: 60 minutes After completing this module,
김영태 선임 연구원 웹서비스를 위한 Personalization Server JPS 1.0 웹서비스를 위한 Personalization Server JPS 1.0.
Auckland Connected Systems User Group November 19th 2009 Jeffrey Chilberto BizTalk Consultant
Puppet with vSphere Workshop Install, configure and use Puppet on your laptop for vSphere DevOps Billy Lieberman August 1, 2015.
Module 10 Administering and Configuring SharePoint Search.
Jess: A Rule-Based Programming Environment Reporter: Yu Lun Kuo Date: April 10, 2006 Expert System.
Daniel van Wyk – 3fifteen – SA Developer.Net – Information Worker Group.
CONTENTS Processing structures and commands Control structures – Sequence Sequence – Selection Selection – Iteration Iteration Naming conventions – File.
Welcome to the Twin Cities BizTalk User Group July 2006.
Distributed Information Systems. Motivation ● To understand the problems that Web services try to solve it is helpful to understand how distributed information.
37 Copyright © 2007, Oracle. All rights reserved. Module 37: Executing Workflow Processes Siebel 8.0 Essentials.
Object Oriented Software Development
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns VIII Chain of Responsibility, Strategy, State.
A university for the world real R © 2009, Chapter 9 The Runtime Environment Michael Adams.
WRITING CONTROL STRUCTURES (CONDITIONAL CONTROL).
What is a Package? A package is an Oracle object, which holds other objects within it. Objects commonly held within a package are procedures, functions,
Permissions Lesson 13. Skills Matrix Security Modes Maintaining data integrity involves creating users, controlling their access and limiting their ability.
Master Data Management & Microsoft Master Data Services Presented By: Jeff Prom Data Architect MCTS - Business Intelligence (2008), Admin (2008), Developer.
Sections © Copyright by Pearson Education, Inc. All Rights Reserved.
Chapter 5 : Integrity And Security  Domain Constraints  Referential Integrity  Security  Triggers  Authorization  Authorization in SQL  Views 
M1G Introduction to Programming 2 3. Creating Classes: Room and Item.
Review of Parnas’ Criteria for Decomposing Systems into Modules Zheng Wang, Yuan Zhang Michigan State University 04/19/2002.
Chapter 3 JSP Overview. The Problem with Servlets processing the request and generating the response are both handled by a single servlet class Java programming.
Introduction to Active Directory
IMS 4212: Constraints & Triggers 1 Dr. Lawrence West, Management Dept., University of Central Florida Stored Procedures in SQL Server.
Text TCS INTERNAL Oracle PL/SQL – Introduction. TCS INTERNAL PL SQL Introduction PLSQL means Procedural Language extension of SQL. PLSQL is a database.
Workflow in Microsoft Office SharePoint Server Jessica Gruber Consultant Microsoft Corporation.
Windows Workflow Foundation Guy Burstein Senior Consultant Advantech – Microsoft Division
1. Advanced SQL Functions Procedural Constructs Triggers.
11 Making Decisions in a Program Session 2.3. Session Overview  Introduce the idea of an algorithm  Show how a program can make logical decisions based.
Introduction ITEC 420.
SharePoint 101 – An Overview of SharePoint 2010, 2013 and Office 365
Working in the Forms Developer Environment
A Software Architecture Model……
Distribution and components
ARCH-1: Application Architecture made Simple
Objectives In this lesson you will learn about: Need for servlets
Presentation transcript:

Twin Cities BizTalk User Group Rule Engines: BRE vs WF Rules November 2006 Stephen Kaufman

Agenda RETE Algorithm WF Rules Processing BRE Rules Processing Compare/Contrast Forward Chaining Iterating Overview

To RETE or Not to RETE Is that a question we should care about? Which rules engine implements RETE? What is RETE –It is an optimization algorithm –It reduces the number of predicate evaluations by remembering the most recent value and re-using it on subsequent re- evaluations You do not need a RETE engine to implement forward chaining

RETE There are times that rule sets are structured so that the optimization would make no difference or even hurt performance –If each rule evaluates independent expressions against different facts, the RETE algorithm will provide no improvement. –The RETE algorithms intrinsic overhead may result in a net loss of performance

Agenda RETE Algorithm WF Rules Processing BRE Rules Processing Compare/Contrast Forward Chaining Iterating Overview

WF Rules Processing WF provides a policy class –This policy class uses an internal executor class to execute the rule set The policy activity sends the rule set to the executor which creates a sorted list of RuleState objects –Each RuleState presents an individual rule and its associated state –The RuleState objects are sorted by priority

WF Rules Processing –Each rule is executed in sequence If two or more rules have the same priority the execution ends up based on an implementation dependent choice – currently on rule name (however, that is not something to count on) Each rule can have two sets of actions –One of these sets is executed depending on the overall evaluation of the rule condition – thus allowing if/then/else functionality The executor detects when actions perform changes to properties

WF Rules Processing The executor detects when actions perform changes to properties which can lead to forward chaining

Agenda RETE Algorithm WF Rules Processing BRE Rules Processing Compare/Contrast Forward Chaining Iterating Overview

BRE Rule Processing The BRE uses a RETE engine to process the rule execution –The RETE engine is a compiled representation of a rule set The BRE executes it RETE algorithm by asserting a number of facts to the engine These facts are turned into rule objects which may end up on the agenda

BRE Rule Processing All rule objects are evaluated based on their priority –Once rules are placed on the agenda they are then processed in order The BRE follows the Match-Resolve-Act phases. –This is discussed on pages in the book “Artificial Intelligence – a modern approach”, v1 by Russell and Norvig

BRE Rule Processing The agenda is created with the rule objects in the order they will run As rules are pulled off the agenda and executed they may; –cause conditions to be re-evaluated and the agenda being modified before the next rule is pulled off the agenda –update existing facts, –assert new facts, –re-assert existing facts –Remove facts from the agenda

Agenda RETE Algorithm WF Rules Processing BRE Rules Processing Compare/Contrast Forward Chaining Iterating Overview

Compare/Contrast - Agenda WF does not use an agenda nor does it have the concept of a vocabulary BRE uses an agenda and the developer has the ability to modify how the engine operates at run time

Compare/Contrast - Assert WF acts against one object –At run-time there is no mechanism for adding or removing individual items –It is only possible to update the values – which may lead to a re-evaluation of the rules (forward chaining) With the BRE you can assert as many facts as necessary (short term and long term) as well as retract facts –You need to manually remove certain types

Compare/Contrast - Assert Retracting Facts Manually –This is necessary if you manually add facts during rule processing and don’t want to reuse that fact in future processing –These facts can be preserved if you are using the same instance of the engine and want to maintain the state across execution calls –Typically manually added facts are used for specific instances of rule processing and therefore need to be retracted

Compare/Contrast - Verbs WF’s Update verb is used in rule actions to invoke forward chaining where the value of a property has not been changed. BRE’s Update verb works differently in that you are telling the engine to re- evaluate what should be added to the agenda WF provides both explicit and implicit updates whereas the BRE only provides explicit updates.

Compare/Contrast - Verbs Implicit Update –Each rule is analyzed and relationships between rules are identified automatically. –The engine ensures that the rule will be re- evaluated whenever a dependant rule is executed Explicit Update –The developer tell the engine to re-evaluate rules with a specified condition

Compare/Contrast - Instances BRE requires you think and design in a non procedural fashion One rule may result in multiple facts of the same type being added to the agenda –The BRE allows you to associate an instance number with the terms that reference a given fact type factType(1).item == factType(2).item This will cause every possible combination of one instance being evaluated against every possible combination of the other instance

Multi Instance Support What is it? –BRE rules are expressed against types, not instances or variables. At execution time, the engine matches instances that are asserted against the rules written against their type. –This makes it possible to assert as many instances of a given type as needed and have them be processed independently. Be Careful.

Multi Instance Support Why should I be careful? Example IF Customer.AccountType == “Residential” AND Order.Value > 500 THEN Order.Discount = 5 If two instances of Customer type and Order were asserted, then the outcome would be : –Instance 1 of Customer and Instance 1 of Order –Instance 1 of Customer and Instance 2 of Order –Instance 2 of Customer and Instance 1 of Order –Instance 2 of Customer and Instance 2 of Order

Multi Instance Support Why should I be careful? Example IF Customer.AccountType == “Residential” AND Order.Value > 500 THEN Order.Discount = 5 If two instances of Customer type and Order were asserted, then the outcome would be : –Instance 1 of Customer and Instance 1 of Order –Instance 1 of Customer and Instance 2 of Order –Instance 2 of Customer and Instance 1 of Order –Instance 2 of Customer and Instance 2 of Order You need to add an additional condition to the rules IF Customer.AccountType == “Residential” AND Order.Value > 500 AND Order.CustomerID = Customer.ID THEN Order.Discount = 5

Types vs Instances There are times when writing rules against instances have advantages over types –Scenario An employee is requesting a higher security clearance. If the employees manager has authorization to grant the requested level or a higher level and the employee is within one level of the requested security clearance then grant the request

Types vs Instances WF IF this.manager.AuthorizationLevel >= this.accessRequest.RequestedLevel AND this.employee.SecurityLevel == this.accessRequest.RequestedLevel – 1 AND this.accessRequest.IsManagerApproved == true THEN this.employee.SecurityLevel = this.accessRequest.RequestedLevel IF this.employee.SecurityLevel > this.accessRequest.RequestedLevel – 1 AND this.accessRequest.IsManagerApproved == true THEN this.director.RequestSecurityClearance(this.employee, this.accessRequest) this.employee, this.manager and this.director are all objects of type Employee

Types vs Instances BRE IF Employee.AuthorizationLevel >= AccessRequest.RequestedLevel AND Employee.SecurityLevel == AccessRequest.RequestedLevel – 1 AND AccessRequest.IsManagerApproved == true THEN Employee.SecurityLevel = AccessRequest.RequestedLevel IF Employee.SecurityLevel > AccessRequest.RequestedLevel – 1 AND AccessRequest.IsManagerApproved == true THEN Employee.RequestSecurityClearance(Employee, AccessRequest)

Types vs Instances BRE IF Employee.AuthorizationLevel >= AccessRequest.RequestedLevel AND Employee.SecurityLevel == AccessRequest.RequestedLevel – 1 AND AccessRequest.IsManagerApproved == true THEN Employee.SecurityLevel = AccessRequest.RequestedLevel IF Employee.SecurityLevel > AccessRequest.RequestedLevel – 1 AND AccessRequest.IsManagerApproved == true THEN Employee.RequestSecurityClearance(Employee, AccessRequest) Will this work? Is there something missing?

Types vs Instances BRE IF Employee.AuthorizationLevel >= AccessRequest.RequestedLevel AND Employee.SecurityLevel == AccessRequest.RequestedLevel – 1 AND AccessRequest.IsManagerApproved == true THEN Employee.SecurityLevel = AccessRequest.RequestedLevel IF Employee.SecurityLevel > AccessRequest.RequestedLevel – 1 AND AccessRequest.IsManagerApproved == true THEN Employee.RequestSecurityClearance(Employee, AccessRequest) Will this work? Is there something missing? You need to distinguish between the various instances of Employee

Types vs Instances BRE IF Employee(0).AuthorizationLevel >= AccessRequest.RequestedLevel AND AccessRequest.EmployeeID == Employee(0).ID AND AccessRequest.IsManagerApproved == true AND Employee(1).SecurityLevel == AccessRequest.RequestedLevel – 1 AND Employee(0).ManagerID == Employee(1).ID THEN Employee(1).SecurityLevel = AccessRequest.RequestedLevel IF Employee(0).SecurityLevel > AccessRequest.RequestedLevel – 1 AND AccessRequest.EmployeeID == Employee(0).ID AND AccessRequest.IsManagerApproved == true AND Employee(1).Title == “Director” THEN Employee(1).RequestSecurityClearance(Employee(0), AccessRequest)

Types vs Instances There are also times when writing rules against types have advantages over instances –The BRE algorithm lets you decide the manager relationship in rules rather in the calling code –If you wanted to change the rule so that the manager’s manager can be used when the manager is out of the office you could do this entirely in the rules with BRE

Types vs Instances –With WF you would need to change the calling code You would need to add an extra property You would also need to get the additional employee object All in all they really are doing different things. –BRE is executing over a collection of employee objects, –WF is executing over a single object with 2 properties.

Agenda RETE Algorithm WF Rules Processing BRE Rules Processing Compare/Contrast Forward Chaining Iterating Overview

Forward Chaining Explained In forward chaining, rule actions operate against the object state where rule actions change the value of items in the object state This causes the engine to automatically re-evaluate the relevant rules against the new values which in turn continues until no additional re-evaluation is needed.

Forward Chaining - WF Rules run directly on the sorted list of the RuleState objects and execute the then or else action The RuleState object has a pending flag which starts off as true –As each rule is processed the pending flag is set to false –The flag is set no matter which action may, or may not, have fired

Forward Chaining - WF When the then or else is processed, the engine analyzes the action and determines if they invoke code which will have side effects. –A side effect is code that may alter the state of the object in a way that could affect the evaluation of conditions in other rules

Forward Chaining - WF If side effects are encountered, the engine searches the collection of RuleState objects looking for rules whose conditions are affected AND whose pending flag is set to false If the engine finds an affected rule with a higher priority than the rule which caused the side effect, the higher priority rule is evaluated and its actions are processed

Forward Chaining - WF Execution continues from the higher priority rule that just ran If there are no higher priority rules affected then the engine continue to process the rules in order from the rule that caused the side effect So, forward chaining is tied to prioritization and can cause a loop back to higher priority rules

Forward Chaining - WF For simpler rule sets, forward chaining can sometimes be eliminated by re- prioritizing the rules so that they are evaluated in a different order. –Or for rule sets with no prioritization, creating the rules in a different order MAY also be a possibility to eliminate forward chaining –Remember that rules are evaluated arbitrarily

Forward Chaining Example What does this rule do? IF Truck.ShippingCharge < 2.5 THEN Truck.ShippingCharge = 1;

Forward Chaining - Looping WF provides the RuleReevaluationBehavior at the rule level as well as the RuleChainingBehavior public enum RuleChainingBehavior { Full,// default; implicit, explicit and attribute-based chaining None,// do not chain; purely sequential execution UpdateOnly,// chain only on explicit Update statements } BRE provides the Maximum Execution Loop Depth at the ruleset level (default of 65536)

Agenda RETE Algorithm WF Rules Processing BRE Rules Processing Compare/Contrast Forward Chaining Iterating Overview

Iterating in the BRE Given the following XML, how will the BRE loop through the item nodes? Manifest Pro BizTalk 2006 by Apress Essential Windows Workflow by Addison-Wesley Default Composer Settings –XPath Field: *[local-name()='Item' and namespace-uri()=''] –XPath Selector: /*[local-name()='Package' and namespace-uri()='']/*[local- name()='Items' and namespace-uri()='']

Iterating in the BRE Manifest Pro BizTalk 2006 by Apress Essential Windows Workflow by Addison-Wesley The developer must manually modify the properties in the Composer –XPath Field: '.' (without the single quotes) –XPath Selector: /*[local-name()='Items' and namespace-uri()='']/*[local- name()='Item' and namespace-uri()='']'

Iterating in WF Rules WF requires additional methods/properties be placed on the object that is submitted. It is possible to iterate using the WF rules when your source is an xml document i.e., this.document.SelectNodes()

Iterating in WF Rules Create ruleset with at least 4 rules as well as decorate your class with extra properties Create an enumerator property of type System.Collections.Generic.IEnumerator or System.Collections.IEnumerator Create an items collection to contain your collection of items which can be of type List or anything that supports IEnumerator Create a property to hold the current item

Iterating in WF Rules Rules Iteration Pattern - Four Rules –Rule 1 (Priority = 2) //Always execute this rule once to create the enumerator. IF 1==1 THEN this.enumerator = this.myCollection.GetEnumerator() –Rule2 (Priority = 1) IF this.enumerator.MoveNext() THEN this.currentInstance = this.enumerator.Current –Rules 3-N (Priority = 0).... //Additional rules written against this.currentInstance

Iterating in WF Rules Rules Iteration Pattern - Four Rules –Rule N+1 (Priority = -1) // can be any condition as long as it is evaluated every time; // this.currentInstance will be evaluated each time this.currentInstance changes, whereas // "1==1" would only be evaluated once. IF this.currentInstance == this.currentInstance THEN... Update("this/enumerator") //this will cause Rule 2 to be reevaluated ELSE... Update("this/enumerator") This pattern works for a single collection –Repeat this as needed or in a hierarchy for multiple collections

Agenda RETE Algorithm WF Rules Processing BRE Rules Processing Compare/Contrast Forward Chaining Iterating Overview

Tools BRE Provides –An in-process execution engine that runs on the server –The ability to collect references into a concise library to provide domain specific terms – a vocabulary. This is a feature that will be added in future version of WF rules –A centralized database for the storage and management of rulesets. This includes audit information on ruleset changes –A windows service to monitor changes and provide ruleset deployment –A tracking infrastructure when called from BizTalk. This tracking data is available through the BTS tracking DB as well as the Health and Activity Tracking tool (HAT) and also file based. There is also a public interface to write your own tracking interceptor

Tools WF Provides –A rules UI that can be re-hosted in your own application –An in-process execution engine that runs on the client –The ability to track the rules –Rules located and executed on the client

BRE vs. Workflow Rules BizTalk Rules –Rete Based Analysis –XML/DB support in addition to the CLR Type support –If/Then –Vocabulary –File and DB storage of policies –Dynamic Policy-level updates –Caching Architecture –Implicit multi-instance support –Working Memory (stateful) –Rules Tracking –Server Based –Security Workflow Rules –Forward Execution Algorithm –Rules written against workflow variables – CLR Types –If/Then/Else –Short circuiting evaluation –Implicit chaining –More chaining control –Client based

Questions?