Wednesday Jan 22, 2014

Batch Processor in Oracle Policy Automation (OPA)

Adeolu Owokade | Monad Solutions

In this article, we will be exploring the Batch Processor in Oracle Policy Modeling. The Batch Processor allows a large number of cases to be processed in batch. It can take input from comma separated files or from a database and can output to the same.

Let me give an example of where the batch processor may come in handy. Imagine a Telecommunications organization that recently implemented OPA for its customers to check what mobile phone packages they can apply for. However, that organization already has data about its existing customers in a database and will also want to know which packages are applicable to its existing client base. The best way to do this will be by running this data in a batch rather than conducting an interview for each existing customer.

The Batch Processor sees its usefulness in other areas like conducting what-if analysis and generating test scripts from existing Excel data. We will explore input from and output to CSV files. This article assumes you have working knowledge of OPA; I will make it as practical as possible so let us begin by modeling a simple rulebase.

Sample Policy

  • The customer is eligible to apply for the Gold Plan if the customer has been a registered customer for at least 3 years and the total amount spent by the customer is above £3,000.
  • The customer is eligible to apply for the Silver Plan if the customer has been a registered customer for at least 2 years and the total amount spent by the customer is above £2,000.
  • Any registered customer is eligible to apply for the Basic Plan.

The OPA rules for this policy are as shown below:

The data model is as shown below:

Batch Processor Zero-configuration

If you are using CSV files as the input to the Batch Processor, much of the mapping from CSV data to OPA data can be done automatically through the Zero-configuration, by following a few simple guidelines which we will discuss in this section.

Entities

The CSV file name should be the public name of the entity. In our example, we will use two CSV files: "global" and "customer". "customer" is the public name of 'the customer' entity as shown below:

The CSV files are as shown below:

Input Attributes

The columns on the first row in the CSV files should be named with the attribute public names.

Identifier

By default, a column with the heading "#" is assumed to be a unique identifier for that entity.

Output attributes

To represent output attributes, enclose such public names in brackets.

One-to-Many Relationships

One-to-many relationships can also be represented in CSV files by using the public name of the relationship as the column title. For example, the relationship between global and 'the customer' entity is a one-to-many relationship which I can represent  in the customer.csv as shown below:

In the diagram above, customer instances #1 to #4 are instances under global instance #1 while customer instances #5 to #7 are instances under global instance #2.

The full content of the CSV files are shown below. The global.csv file has two instances of 'global'. You can think of this like two separate interviews (or 2 test cases). The customer.csv file has 7 instances representing 7 customers.

Running the Batch Processor

The batch processor is a standalone application that is run from the command line using the parameters listed below:

  • java -jar determinations-batch.jar <command line parameters> (JAVA)
  • Determinations.Batch.exe <command line parameters> (.NET)
To make running the Batch Processor easier especially when using Zero-configuration, I recommend placing all your files and rulebase in one folder. For example, take the rulebase ZIP file (found in the output folder in the Development folder of your OPA project) and place it in a separate folder. In that same folder, create another sub-folder to hold your CSV input files (name it "csv" so you don't have to specify the name of the folder in the CLI parameters).

Then, you can open a command prompt, navigate to this folder and run the batch processor from this location.

Note: If you are not running the Batch Processor from its default location, you must specify the full path e.g. "C:\Program Files (x86)\Oracle\Policy Modeling\bin\determinations-batch.jar"

Batch Processor Output

When the Batch process is complete, a folder (called "csv.out") is automatically created. This folder used to be named "output" in earlier versions of OPA (I'm using version 10.4.4). This folder contains the same CSV files in the input folder but with the generated output values.

Let's view the content of these CSV files. First, the customer.csv:

Notice that the output field – out_cust_years-reg – has been filled out. This is just the number of years between the current date (January 08, 2014) and the dates the customer registered.

Let's also view the global.csv file, where the output should count the number of customers that are eligible for each plan.

Summary

In this article, we have seen how to use CSV as input to the Batch Processor. We have also seen how to ensure that our csv files are properly formatted so that zero-configuration can take place. There are move advanced topics like writing a configuration file to be used for running the batch process and also database connections but this gives a good overview of the Batch processor.

I hope you have found this article insightful.


This article originally appeared on Monad's Commentary on Oracle Policy Automation (OPA) blog on 10 January 2014. Republished with permission.  

Sunday Jan 19, 2014

Ten Minute Tutorial: XDS Logger Plugin for Determinations Server (JDeveloper)

Andrew Higginbottom | Policy Automation Technical Zealot

Welcome to another TMT. This time we will create a plugin for Oracle Determinations Server to log incoming SOAP requests in the Oracle Policy Automation XDS (eXplicit Data Set) format - not to be confused with XSD. You can take this and load it into the Oracle Policy Modeling debugger to track down issues with specific SOAP requests. DISCLAIMER: This might take you longer than 10 minutes, depending on how fast you can click and how fast your PC is!

Last time we used Eclipse but this time we will be using JDeveloper to build and test the plugin. Again there are some prerequisites:
  1. Oracle JDeveloper (I used 11.1.2.4.0)
  2. Oracle Policy Automation Runtime Components for Java (I used v10.4.4.21.0)
  3. SoapUI (I used 4.6.4)

Once downloaded, install JDeveloper, extract the OPA Runtime Components to a convenient location and install SoapUI.

Now we begin. Start JDeveloper and accept the "Studio Developer (All Features)" role.

Select Application > New... from the main menu to create a new application workspace.
Give the application a name "ODSXDSPlugin"

Accept the default Project1 and Finish.

Having set up the Application, we now import the Determinations Server WAR file. File > Import... from the main menu, then select > WAR File. Call the project "determinations server".

At the next step Browse... to the location where you extracted the OPA Runtime and select /determinations-server/determinations-server.war.

Right-click determinations-server project, New..., General > Java Class.
Enter Name "XDSLogger", Package "com.opablog.aeh".

Add the "OnBeforeThinkEventHandler" interface. This event is fired for every request, after the request has been parsed into the session but before the rules are executed.


This time I've provided the code to copy and paste in, replacing the entire contents of the new XDSLogger.java file:

package com.opablog.aeh;

import com.oracle.determinations.engine.SessionUtils;
import com.oracle.determinations.server.assess.extensions.AssessPlugin;
import com.oracle.determinations.server.assess.extensions.AssessPluginRegisterArgs;
import com.oracle.determinations.server.assess.extensions.events.OnBeforeThinkEvent;
import com.oracle.determinations.server.assess.extensions.events.OnBeforeThinkEventHandler;
import java.io.IOException;
import java.io.StringWriter;
import org.apache.log4j.Logger;

public class XDSLogger implements OnBeforeThinkEventHandler {
 
    private Logger log = Logger.getLogger(this.getClass());
 
    public XDSLogger() {
        super();
    }

    @Override
    public void handleEvent(Object object, OnBeforeThinkEvent onBeforeThinkEvent) {
        try {
            StringWriter w = new StringWriter();
            SessionUtils.exportSession(onBeforeThinkEvent.getSession(), w);
            log.debug(w.toString());
        } catch (IOException e) {
            log.error(e);
        }
    }

    @Override
    public AssessPlugin getInstance(AssessPluginRegisterArgs assessPluginRegisterArgs) {
        return this;
    }
}


Edit Application Sources/config/application.properties to configure ODS to load the plugin by updating the plugin.libraries parameter to "plugin.libraries=com.opablog.aeh.XDSLogger"

Edit Application Sources/log4j.xml to increase the logging level by setting <level value="DEBUG"/> under the <root> element. Don't do this in production!

Copy in the PocketMoneyComputation.zip rulebase from the \examples\rulebases\compiled folder in your expanded OPA runtime location. Use Windows Explorer to copy the file into your JDeveloper project. For me the destination folder is located at C:\JDeveloper\mywork\ODSXDSPlugin\determinations-server\src\rulebases.


Now we can deploy the plugin to our local server.
Select Run > Start Server Instance (IntegratedWebLogicServer) from the main menu and enter credentials of your choice to use for server setup.

Wait for domain to build and server to start up. Once completed you should see "IntegratedWebLogicServer started." in the Log window.

Now we can deploy our Determinations Server with XDS logger plugin.

Right-click the determinations-server project and Deploy > "determinations-server...". Select "Deploy to Application Server", click Next, then IntegratedWebLogicServer, then Finish. Ignore any warnings logged during startup - they are only there because we turned the logging up to DEBUG.
In the deployment tab you should see that deployment has finished and you are given the URL in the Deployment - Log window.


Finally we can test our plugin by sending a request using SoapUI.
Open the URL in your favourite browser and you will see the familiar page listing the OPA services available. Grab the full URL to the specific Assess service WSDL.

Start SoapUI and select File > New SOAP Project from the main menu. Give the project a name and paste the WSDL URL for Initial WSDL. Make sure Create Requests is checked.

Open Request1 under the Assess node and paste the following minimal SOAP message to replace the default content:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:typ="http://oracle.com/determinations/server/10.4/PocketMoneyComputation/assess/types">
   <soapenv:Header/>
   <soapenv:Body>
      <typ:assess-request>

         <typ:global-instance>
            <!--You may enter the following 6 items in any order-->
            <!--Optional:-->
            <typ:base_rate>
               <typ:number-val>2.50</typ:number-val>
            </typ:base_rate>
            <typ:person_name>
               <!--You have a CHOICE of the next 3 items at this level-->
               <typ:text-val>Parent</typ:text-val>
            </typ:person_name>
 
            <typ:total_money outcome-style="decision-report"/>
 
            <typ:list-child>
               <typ:child id="1">
                  <typ:child_name>
                     <typ:text-val>Bobby</typ:text-val>
                  </typ:child_name>
                  <typ:child_age>
                     <typ:number-val>7</typ:number-val>
                  </typ:child_age>
                  <typ:child_money outcome-style="value-only"/>
               </typ:child>
               <typ:child id="2">
                  <typ:child_name>
                     <typ:text-val>Betty</typ:text-val>
                  </typ:child_name>
                  <typ:child_age>
                     <typ:number-val>9</typ:number-val>
                  </typ:child_age>
                  <typ:child_money outcome-style="value-only"/>
               </typ:child>
 
            </typ:list-child>
         </typ:global-instance>
      </typ:assess-request>
   </soapenv:Body>
</soapenv:Envelope>

Press "play" (the green arrow pointing to the right) to submit Request1. You should see a response that looks similar to the request, but with calculated values returned along with the inputs used.

In addition to processing the Assess request as normal, our new Determinations Server plugin has logged the inputs to the application log in the OPA XDS format.

You can now copy this XML into a text file and load it up in OPM to debug!

There are obvious improvements that could be made to this, such as logging each request to its own file, but I will leave those as an exercise for the reader. This is supposed to be a TMT after all!



Wednesday Jan 08, 2014

Building an Oracle Policy Automation Center of Excellence

Matthew Bickham | OPA Implementation Manager (Europe) & Center of Excellence Facilitator

Introduction

We all know Oracle Policy Automation (OPA) enables business experts to be able to create sophisticated rulebase applications directly without the need to have a background or qualification in software development. The diagram below provides an overview of the steps that are normally conducted to build an OPA rulebase:  

Business rule authors are critical to every project and to wrap them into a structure, I always encourage customers to establish a Center of Excellence (CoE) where talent, skills, processes and disciplines are centrally governed within a business. Whilst business experts may not initially have the skills to build software, the CoE approach provides everything needed to grow capability and confidence in authoring rules and systems that significantly outweighs any nervousness that may have existed at the outset. This is very important because initially not all organizations are ready to take the leap of faith needed for business experts to play a more development role. For those that do, there are significant rewards. Just some quotes from our CoEs:

“OPA is the most innovative technology on our estate”

“OPA has paid for itself 7 times over and that is just with our first project!”

“OPA is a game changer. We would never have been able to achieve what we have done using any other method or technology”

OPA Projects

Any project is often born through a business need to build a system to meet a brand-new requirement. In terms of OPA this will mean that a project will include a requirement for a system to automatically make a complex decision on behalf of the organization using rules and building a customer experience friendly interview that will include assessment screens, smooth screen-flow, data validation, look-ups (of known data) and documented outputs of the rulebase determinations that are made.

Projects are normally resourced to meet the needs of the project and formed based on the availability of key people, timelines to deliver and scope of the project work. Given these variables, a lot is left to chance and luck. Rulebase resources may require initial training but there is a tension to deliver in an agile way and this needs the team to be properly trained, experienced and ready to start creating rulebase components from day one. Forming a brand new project team for every project is very difficult given issues with availability of key experts. A much better approach is to build a Center of Excellence that maintains skills and grows capability so that with every new project the team grows in strength.

The Benefits

An OPA CoE addresses start-up issues because every project is safely delivered within a structure that already has the capability and skills to deliver a project from the beginning. It will contain a pool of resources at various skills levels. Senior members of the team will evolve through experience and lead areas of work including rules architecture, test management, project management and technical architecture. The CoE is special in that it is business centric but includes IT team members who must connect and manage the integration between OPA and other systems. This enables the business authors to remain focused on delivering projects using their skills to the full.

So why is an OPA Center of Excellence any different to any other CoE? The key difference is that the CoE is business focused with more Subject Matter Experts involved more directly with building and testing rulebase components than ever before. This is not only limited to rule authoring. Those involved in testing utilize tools within OPA itself (regression tester, what-if analysis, test coverage reporting etc) to verify rules directly, safely navigating rules and components at a read-only level. Powerful test suites are developed by business experts directly into a rulebase and each key outcome is tested against manually created expected outcomes. The business expert has responsibility for this work and has proven to significantly reduce the time to develop and test solutions, not leaving all the testing effort until the end. In addition, our customers report that defect-free systems are commonplace with OPA after initial implementation because the experts in that area of the business were more intimately involved in the authoring and testing process throughout. Due to OPA’s unique natural language capability, rules are easily read and understood by testers and other members of the team and this is one of the key factors in its success.

Becoming an OPA CoE

There is a process to becoming an OPA CoE. Oracle has assisted many organizations build their structure and capability which establishes a robust model for the successful delivery of projects that utilizes OPA in the future. To start, a Center of Excellence requires management and governance to control, direct and prioritize the work that is conducted. For most, this is led by a business manager with skills to manage resources across projects and business areas. Next, there is organization and structure to the Center of Excellence. For the resource teams, training and a qualification in OPA is achieved to an advanced level to ensure that the team members are fully skilled to successfully deliver projects with the product. A skills matrix is formed and a detailed record is kept of the skills attained as the experience of each member of the team grows. A CoE will also want to be known within the business and a communication plan is created to inform internal and external stakeholders about its purpose and vision. Other criteria exist to achieve recognition and includes adherence to best practices design standards, rule authoring guidelines and the control of rules within a configuration management system.

For all OPA CoEs there is now access to an exclusive online Oracle work-group that allows for greater sharing of knowledge, promotes decision of OPA related topics and provides valuable information about forthcoming events.

Summary

The OPA CoE approach has provided many OPA customers with a valuable structure and focus that has truly maximized the use of the technology and has built a strong team around it. ‘Growing your own’ OPA capability is part of the whole ethos behind the application and true value has been achieved when our customers have taken this best practice approach.  

Please get in touch if you would like to find out more.

About

Welcome to the OPA blog where Oracle's Policy Automation experts share their views on everything OPA.

Search

Archives
« January 2014
SunMonTueWedThuFriSat
   
1
2
3
4
5
6
7
9
10
11
12
13
14
15
16
17
18
20
21
23
24
25
26
27
28
29
30
31
 
       
Today