Introduction
This guide shows you how you can install Decision Manager in your Red Hat OpenShift environment to author, deploy, and execute decision services. This Hello World will show you the step-by-step journey (see Figure 1.0) from installing Decision Manager to deploying it in a Decision Manager environment to testing it inside a cloud environment.
We'll install Decision Manager on OpenShift, and it will run on top of Red Hat JBoss EAP (WildFly). Once we have Decision Manager up and running, we'll import an existing application to get a view of some of its capabilities. Finally, we'll wrap up our Hello World by deploying the project and testing it!
1. Setting up your environment
Pre-requisites
- In order to test this demo, you should have an up-and-running installation of Red Hat OpenShift 4.7. You can find detailed information on how to install your OCP environment at Red Hat OpenShift Getting Started.
- Alternatively, if you want, you can locally install Red Hat Code Ready Containers (CRC).
- You should also have a Cluster Admin role in your OpenShift installation.
Installing Business Automation Operator
The Business Automation Operator is the most effective way to deploy Decision Manager in an OpenShift environment. When using the Business Automation Operator, we can delegate all of the application management and all of its components.
First off, we'll need to subscribe to Business Automation Operator within the OperatorHub. Once we do this, we'll be able to create a new KieApp, which is a custom resource that represents the set of resources required to run our applications, e.g., volume claims, routes, services, and deployment configurations.
When we deploy a KieApp, we can choose between a set of recommended setups to deploy our Decision Manager environment. In this guide, we'll use the ephemeral template rhdm-trial, which deploys Decision Manager and a Kie Server.
Note: If you want more information on the available template options, we recommend you take a look at the official Red Hat Decision Manager documentation.
Now that we understand what we are going to deploy, let's get started.
Subscribing to the Operator
Let's install the Business Automation operator in three easy steps.
- Login to your OpenShift environment.
- Create a new OpenShift project (see Figure 1). On the left menu, select Projects. Next, click Create Project.
- Insert the Name, the Display Name, and the Description of the project, then click Create (see Figure 2).
Name |
hello-rhdm |
Display Name |
Getting Started with RHDM |
Description |
This is a getting started project with Red Hat Decision Manager |
This operator is installed by namespace and only affects the project to which it's installed. Let's install the Business Automation operator in our hello-rhdm project.
On the left margin, expand the Operators menu, and click OperatorHub. In OperatorHub (see Figure 3), search for Business Automation.
Select Business Automation. You should see, as in Figure 4, a description of the operator along with its version and current capabilities. Click Install.
You should be redirected to the Installed Operators list (see Figure 5). Click on the Business Automation Operator to see more details.
Congratulations, you've installed the Business Automation operator in your cluster. You're now ready to install Decision Manager in your cloud!
2. Deploy a new KieApp
Now it's time to install Decision Manager in this environment using the operator. TIP: Remember, we're using the rhdm-trial template, which is a template that allows us to quickly test Decision Manager. This template is ephemeral and its data will not stay persistent.
In the Operator Details screen (see Figure 6), locate KieApp and click Create Instance.
Switch to the YAML View, and fill in the template option. Change it from rhpam-trial to rhdm-trial. The result should look like Figure 7.
Click Create.
You should see a new KieApp, rhdm-trial, being provisioned. We now have in this RHDM environment a Decision Central where we can author, build, and deploy our decision apps, and a KIE Server that can execute our rules and decisions and that exposes APIs to integrate with client applications. TIP: Besides these two main components, you can also find secrets, deployment configurations, routes, services, service accounts, roles, and role bindings. All these resources are created by the operator for the base configuration which includes the exposure of services to the outside network and guarantees the security of the passwords.
See Figure 8. In the menu on the left, expand Networking and click Routes.
These routes are exposing our services to the outside world. Let's try accessing the Decision Central route.
Open the rhdm-trial-rhdmcentr-http route link in a new tab (see Figure 9).
If everything went well, a new tab should open in your browser with Decision Central available for you! These are the credentials for Decision Central:
- User: adminUser
- Password: RedHat
TIP: Can't access Decision Central? Take a look at the pod log to check if it's still bootstrapping. Once it's finished, give it another try. If you're running MacOS and face any certificate issues in Chrome, try accessing your MacOS in Firefox.
Congratulations, you've successfully installed Decision Manager in OpenShift. Now, let's import the loan project, build it, and run it!
3. Explore
You have two key components deployed in OpenShift: Decision Central and KIE Server. Decision Central is the component that allows you to develop business rules and decisions, to manage projects, and to build and package them. Finally, you can deploy it in KIE Server, the rules and decision engine. KIE Server is a lightweight component capable of executing the rules and decisions. It can be easily integrated with your services, for example via REST or JMS.
Authoring with Decision Manager
Let's start by accessing Decision Central (see Figure 10). Click on Design, create and modify projects and select MySpace.
Click Import Project (see Figure 11).
Insert the following repository URL https://github.com/jbossdemocentral/rhdm7-loan-demo-repo.git and click Import. Select loan-application (see Figure 12) and click Ok.
After the project has been imported, you should see four assets in the assets list.
- Three Data Models (Recommendation, Loan, and Applicant)
- A simple decision implemented using DMN (recommendation)
- And a traditional Guided Decision Table (loan-approval)
Open the loan-approval Decision Table (see Figure 13), and inspect the four rules defined in the table.
The rules control whether the “Loan” gets approved based on the amount of the loan and the credit score of the application. More specifically, when the application gets approved, the approved field of the “Loan” will be set to true.
Close this file, and select the Recommendation Decision Modeling Notation (DMN) file (see Figure 14). The DMN specification is a well-established pattern recognized by the Object Management Group (OMG) and it's platform-agnostic. The DMN file is specially created so that business teams can design decisions in a more intuitive way.
This DMN file has one input: Credit Score. Based on this Credit Score, the output will be a Recommendation about the loan amount. Click the Recommendation decision node as shown in Figure 15, and choose Edit.
You'll see the Decision Table (see Figure 16) responsible for determining the output based on the provided credit score.
Close your open files. Now that we explored our project rules and decisions, let's build and deploy the project.
Deploying the rules
We're now working with a traditional Maven project. We need to build and package it into a Knowledge Java Archive (Kjar), the Decision Deployment Unit which contains the model and rules. Once packaged, this application can be deployed in the engine. Luckily, Decision Central as shown in Figure 17, can help us with this task.
Click Deploy to build and deploy the project on the execution server that is running in another OpenShift pod:
Once the build and deployment have finished, you'll see, as shown in Figure 18, a successful deployment message. Click View deployment details.
The page will show a running “default-kie-server” with the “loan_application_1.2.0” container deployed (see Figure 19).
Our project is now available to be consumed by client applications! Let's have a look at how we can consume this decision service.
3. Explore
The KIE Server comes with a Swagger user interface (UI) that allows us to test the RESTful endpoints of the engine and consume rules deployed on it. Let's use this UI to test our rules.
Let's start by checking the deployed projects for this KIE Server: In your OpenShift console, open the Routes option under Networking. Locate the rhdm-trial-kieserver-http route, and open the URL in a new tab.
Access the KIE Server Swagger UI by adding "/docs" in your URL. Your credentials are:
- URL: http://youropenshift.url.com/docs
- User: adminUser
- Password: RedHat
Verify that the rules have been correctly deployed on the KIE Server by navigating to "KIE Server and KIE containers", and locate the "GET" "/server/containers" option (see Figure 21).
Click Try it out.
Leave the parameters empty and select Execute. If asked, use these credentials:
- User: adminUser
- Password: RedHat
The page that looks like Figure 22 will show a response with Success code "200" and a response body that lists the container id "loan-application_1.2.0" container.
Consuming business rules
Now, let's use the REST API to consume our rules implemented with Guided Decision Tables.
To send a request to the Decision Service, navigate to KIE session assets as seen in Figure 23, and search for POST "/server/containers/instances/{containerId}.
Click Try it out and fill the request parameters:
- "Parameter content-type" and "Response content type" to “application/json”;
- "containerId" to "loan-application_1.2.0" (the ID of the KIE container);
- In the "body", insert the following:
{ "lookup" : "default-stateless-ksession", "commands":[ { "insert":{ "object":{ "com.redhat.demos.dm.loan.model.Applicant":{ "creditScore":230, "name":"Jim Whitehurst" } }, "out-identifier":"applicant" } }, { "insert":{ "object":{ "com.redhat.demos.dm.loan.model.Loan":{ "amount":2500, "approved":false, "duration":24, "interestRate":1.5 } }, "out-identifier":"loan" } }, { "fire-all-rules":{ } } ] }
Click Execute (see Figure 24).
The page will show a response with code 200 and a response body that lists the result of the rule execution. Especially, the “Loan” object’s Approved field should now read as True, and the "reason" should bring the message in Figure 25: Congratulation your loan is approved, which is the outcome of the rule evaluation.
Consuming decisions
Now that we tested our business rule, let's try out our decision implemented with DMN. In order to do that, we'll use the decision engine REST API. In the KIE Server Swagger UI, navigate to DMN Assets as shown in Figure 26 and locate POST /server/containers/{containerId}/dmn.
Click Try it out, and fill in these parameters:
- ContainerID: loan-application_1.2.0
- Change the Parameter content type and the Response content type to application/json.
- Body:
{ "model-namespace" : "https://kiegroup.org/dmn/_C159F266-40FF-49CB-B4D9-447DFACDDC16", "model-name" : "recommendation", "decision-name" : [ ], "decision-id" : [ ], "dmn-context" : {"Credit Score": 100} }
Notice we are sending a "Credit Score" value of 100. Based on this input, the engine will make a Decision and give us the output. Click Execute and observe the output (see Figure 27).
In the body, change the Credit Score to 400, click Execute, and check the execution result.
Congratulations!
This concludes our Hello World. We installed Red Hat Decision Manager in OpenShift using the Business Automation Operator. We also imported a project directly from GitHub, we checked Guided Decision Tables and DMN, two of the many possible ways of implementing business logic, and we ended our Hello World by deploying and testing our services.
Last updated: June 17, 2021