Friday, June 26, 2009

Delivering – Probe SAP

I acted as a midwife assisting to bring ‘Innovation’ mother’s baby – ‘Probe SAP’ to the world. I was the delivery coach and saw every step of the gestation period and how much the mother takes care to bring the baby to the world. It was an uphill task but as with all of our mothers, ‘Innovation’ pulled it through. Kudos to mother Innovation.
Now the midwife’s view. I had the privilege to introduce the baby to the world… What a big expectation it was from different corners for this baby! Fortunately in this case, it was possible to tailor make the baby as per the world’s demand. Even with that flexibility, it was very difficult to meet the expectations. With the privilege also comes the responsibility to take the criticism… ‘I thought the baby would look like Shahrukh Khan, I thought the baby can fly like Superman, I thought the baby would run like Carl Lewis on the first day’ etc. these were the kind of expectations thrown at me during the baby introduction but I am happy the way, we as delivery team worked with expectations and explained to the public what the baby can do.
What the baby can do anyway …
It can analyze any SAP environment and list down all the customizations and come up with the impact of upgrade. The customizations could be anything, any type of objects – Probe recognizes 54 types of objects. The baby has two type of personalities. Inventizer – the uncommitted guy who does not look into the details but interested in getting an overall idea about the person he deals with. Inventizer will give a complete picture of an environment to give anyone an idea on what it takes to maintain or upgrade the environment. The other split personality is Analyzer – the finicky girl who wants to go into every detail and find fault in every little thing. Analyzer goes into the level of identifying the line number where the incompatible element exist to carry out the upgrade. With these, the baby has for sure taken the big leap into the world. Now it requires constant nurturing to turn it into a grown up person to tackle anything in the real world of SAP upgrade and maintenance.
Head mother of Hexaware’s Innovation team, Innovation lead Immanuel has done a great work in directing the team in this delivery. But for his passion and focus in the demanding environment with limited resources, it would be even more difficult child bearing. I do not want to mention any names fearing I will definitely miss out someone. Job well done to the whole innovation team of mothers involved in this.
The baby has taken the first step to run as Carl Lewis!

Thursday, June 18, 2009

Drools for Airlines

Enterprise Applications embraces a lot of business rules. These business rules are often critical areas in decision making processes that attribute to changes in the behavior of an enterprise transaction. While these business rules should be an integral part of the Enterprise Solution transactions, they should be easy to use, easily adaptable to modifications, should be segregated from the programming logics so as to be easily maintainable.

Most often, one of the architectural mistakes that we do is to embed these business rules as a part of the software application code. This methodology poses some severe disadvantages.
  • When new rules are enforced, it becomes all the more difficult to add them. The software program has to be modified to add this rule thereby causing a downtime of the application.
  • Embedding business rules with software program affords less maintainability.
  • Access to these critical business rules for business experts is minimal since they are bundled with the core application logic.
  • Efficient use of a business rules engine or a management system is inherently over looked.
  • Reliability of IT departments on the business rule modification.
  • Reduced or no usage of efficient algorithms for automated business decision process.
There are quite a number of business rule engines (management systems) available in the market. One of those that is prominent and noteworthy is the Drools (aka) JBoss Rules ™ that provides efficient way to handle business rules within an enterprise transaction. There are quite a number of advantages of Drools that makes it attractive to the others such as but not limited to:
  • Drools cater to many programming languages such as Java, Python, and Groovy etc.
  • Drools can run on .NET
  • Drools are Declarative in nature allowing programmers to use it at ease.
  • Drools are flexible enough to be used by means of Domain Specific Language (DSL) to address the semantics of problem domain.
  • Drools can be configured via decision tables (excel tables)
  • Drools is based on forward chaining inference mechanism, which means that changes to inference during rule executions dynamically change the output behavior. What this means is that the data is iterated through until the pre defined goal is reached unlike the backward chaining approach.
Drools employ the famous pattern matching RETE algorithm. When known facts are asserted into the knowledge base, the implementation fires the rules (defined by the rule set) in a sequenced manner until the end of the rule is reached and then looping back to the first if necessary.

Drools for Airline

Airlines reservation system is mission critical system and is characterized by deployment across the world requiring split second response for any input. I am considering a small business rule in the airlines passenger services space to explain the importance of the drools at runtime. A passenger list display for a flight might be queried with different parameters to search for. I am considering that a query has been supplied to match the requested origin and destination and a specific booking status of a passenger to match for display. The rule of thumb is to display only the confirmed passengers on board. Further the rule should check if the segment being queries is open for display.
Below is a snapshot of how the drools file would look like (denoted by *.drl extension)
Drools for Airlines

Well, one might argue that the above rule might be written through a java (or any program in that case) code. The code would not look complex but would not look simple either. The rule explained above is the simplest in its form. Resolving the above simpler logic into an application code itself would amount to redundant iterations, in efficient loops etc. Notice the line where the status of the FlightLeg is being checked for from the list of Flight Legs and the line where the passengers with confirmed status are collected. It is just a single line that does the work! Furthermore any one can infer the outcome of this decision, not mandating that java knowledge is absolutely essential.

There are flexible expression language extensions employed by drools which cannot be programmed efficiently when the business logic is embedded into the application code. Furthermore drools bring in an abstraction to employing the business rules thus keeping the application code more readable and more manageable. Above all the power of drools is realized when there are complex decision making processes during forward chaining inference, especially when a decision outcome should have inherent effect on the other.

The Rule Explained

As can be seen from the above screen shot, the rule file contains a package declaration at the top followed by a list of imports needed for the rule (similar to java environments). The next section is a set of rule definitions. A rule is recognized by a name followed by a set of conditions to check (denoted by the when keyword) and a set of actions to take as the conditions are satisfied (denoted by the then keyword). A rule file can define any number of rules to be fired and optionally a sequence in the firing manner (denoted by the salience keyword). You should probably use this salience attribute if the firing of one rule has a consequence on the other. The no-loop keyword in the second rule as can be seen from the screen shot is used to instruct the rules engine to skip looping.

Drools also provides a set of pre defined enriched functions to work with collections and the like (as can be seen from the above rule snapshot like the collect function), the retract function to evict objects from the working memory when they are no longer needed.

Invoking the rule

Invoking the drools rule file that we defined is simple. To start with,…… the rule we defined has to be built into a form of package. This is achieved by using the KnowledgeBuilder.

KnowledgeBuilder kBuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();

A Knowledge builder in drools is responsible for taking an input rule definition file (the individual rule files, decision tables or the DSL files) and turning them into what is called a KnowledgePackage which the KnowledgeBase can consume. Typically this is achieved in the following way.

kBuilder.add(ResourceFactory.newClassPathResource(“person.drl”), 
ResourceType.DRL);

KnowledgeBuilder can report errors if the input rules definitions or decision tables cannot be compiled to knowledge packages. As a better programming practice it is always good to check if the KnowledgeBuilder has errors before adding resources.

When the Knowledge Packages are built, it is then ready to be consumed by the KnowledgeBase. This is accomplished in the following way,

KnowledgeBase kBase = KnowledgeBaseFactory.newKnowledgeBase();

kBase.addKnowledgePackages(kBuilder.getKnowledgePackages());

StatefulKnowledgeSession session = kBase.newStatefulKnowledgeSession();

//insert the objects that you want the rules to be fired for!
session.insert($object1);

session.insert($object2);

session.insert($object3);

//fire all the rules……
session.fireAllRules();

//dispose of this session since it is stateful.
session.dispose();

Wasn’t it simple? As can be inferred, writing business rules using Drools simplifies the task of embedding the rules into the application code that could otherwise result in redundant iterations, complex logics during dynamic decision inference etc. All of those are done behind the scenes through Drools. All the more Drools employ efficient algorithms for best performance which would otherwise have to be designed (or compromised which is what happens most of the time). Above all the rules can be written as decision tables, XML files which makes it more attractive.
Let us consider a small (rather ‘naïve’ to be precise) example to see how to employ Drools at run time. I am assuming a face book class where a single face book has a collection of persons and each person has an address. I am considering making use of drools for these 2 business rules:
  • No 2 persons in the face book instance can share the same email address.
  • When the address type of the person is not specified it should be defaulted to ‘Residence’
A  downloadable source code (a small stand alone example to start with) is provided for reference (as an eclipse project). The source code uses the drools binary distribution  (v5.x, http://www.jboss.org/drools), XStream (another impressive library to convert your java objects to XML without the need for schema definition Xor ML annotations, can be found at http://xstream.codehaus.org) and Apache Log4J http://logging.apache.org)

Wednesday, June 3, 2009

Databases and Marketing


Really exciting times to be in Marketing. Well, personally for me they are (the geek in me just loves how databases and analytics have become so critical to marketing! :) )
It is incredible how central data is becoming to the art and science of marketing. Infact marketing nowadays is so data driven that it is more science than art.
And I am not referring to ROI and marketing measurement data. Usage of that data is to be able to speak the same language as the CFO and CEO; to get a seat at the table in the executive suite. Something that the marketing organization has had to learn to meet the CFO’s standards.
I am referring to a data driven approach that has been driven by the marketing department itself. And this has been driven by the marketing department’s desire to run programs that are not gambles. Campaigns that are designed with the customers and their behaviour in mind and therefore hit the target more often than not. And that has brought us today to a time where databases and analytics are critical for marketing to succeed.
Not being familar with database management and analytics is not an option anymore.