Eric D. Schabell: CodeReady Containers - Exploring a Node.js Front End with Decision Management Back End

Thursday, October 29, 2020

CodeReady Containers - Exploring a Node.js Front End with Decision Management Back End

decision management
As a cloud-native developer you've installed an OpenShift Container Platform development environment on your local machine, but what's next?

What can you do with the fully stocked container registry provided to you?

There is no better way to learn about container technologies, cloud native methods, and container-based application development than getting hands-on with great open technologies.

This article targets getting you started on your new OpenShift Container Platform 4.5 by putting the latest process automation developer tooling at your disposal together with a real project for you to deploy and explore.  Even better, if you need more help getting started, we'll provide a free online workshop where you can build this project yourself.

Let's get started right now exploring the development, deployment, and running of a Node front end working together with a decision management back end. This scenario is wrapped up in a Quick Loan Bank story where you're providing a loan application platform for the bank.


Decision management developer tooling

This demo project showcases the tooling available in Red Hat Decision Manager implementing complex decision logic which can be exposed as a decision service. 

quick loan bank demo
The Quick Loan Bank in this demo uses technical rules, decision tables, guided rules with a Domain Specific Language, and Excel decision tables to define its loan calculation and approval system. You will be given examples of calling the rules as if using them from an application through the RestAPI that is exposed by the server. 

Furthermore, this demo provides a Node.js client application written in AngularJS and PatternFly that showcases how web applications can consume decision services deployed on the decision server.

This demo installs the Red Hat Decision Manager and a Node.js front end application on OpenShift Container Platform on your local machine. It's leveraging CodeReady Containers and delivers a fully functioning container-native development experience.


Install on CodeReady Containers

There are two options to install and run this project on the OpenShift Container Platform (OCP); use your own existing installation or to install on CodeReady Containers which provides you with a local OCP cluster.

decision management

  1. Ensure you have a CodeReady Containers installation:
  • your own CodeReady Containers installation, if using this you just need to set the variables to point to it in init.{sh|bat} script.

  • CodeReady Containers Easy Install

  1. Download and unzip this demo.

  2. Run 'init.sh' or 'init.bat' file. 'init.bat' must be run with Administrative privileges:

   # If using the CodeReady Containers installation, just ensure a correctly set cluster 
   # address for the HOST_IP variable at the top of the init.{sh|bat} files, for example:
   #
   # HOST_IP=api.crc.testing  
   # 
   # Now just run the script without arguments and it picks up that hostname as follows:
   #
   $ ./init.sh

Now log in to Red Hat Decision Manager to start developing containerized process automation projects (the address will be generated by OCP):

  • CodeReady Container example: https://crc-quick-loan-bank-demo-appdev-in-cloud.apps-crc.testing ( u:erics / p:redhatdm1! )

Testing API access

Prior to running the Node.js front-end application, let's explore the API and confirm that it's working:

  1. Log in to the decision manager business central dashboard at: http://insecure-quick-loan-bank-rhdmcentr-appdev-in-cloud.apps-crc.testing with u:erics and p:redhatdm1!

  2. Click on the "loan-application" project to open the Loan Application Demo project.

  3. decision management
    The project has simple data model (Loan & Applicant) and single decision table (loan-application) which contains the loan approval rule set.

  4. Build and deploy version 1.0 of the project. Click on the "Build and Deploy" in the upper right corner.

  5. Go to "Menu -> Deploy -> Execution Servers" repository to see the 'loan-application_1.0' KIE Container deployed on the Decision Server.

  6. The decision server provides a Swagger UI that documents the full RESTful interface exposed by the server at: http://insecure-quick-loan-bank-kieserver-appdev-in-cloud.apps-crc.testing/docs

  7. In the Swagger UI:

    • navigate to "KIE Server and KIE containers"
    • expand the "GET" operation for resource "/server/containers"
    • click on "Try it out"
    • leave the parameters blank and click on "Execute"
    • when asked for credentials use: Username: erics, Password: redhatdm!
    • observe the response, which lists the KIE Containers deployed on the server and their status (STARTED, STOPPED).
  8. We can use the Swagger UI to test our Loan Approval Decision Service. In the Swagger UI:

    • navigate to "KIE session assets"
    • expand the "POST" operation for resource "/server/containers/instances/{id}"
    • click on "Try it out"
    • set the "id" parameter to the name of the KIE Container that hosts our rules, in this case loan-application_1.0.
    • set "Parameter content type" to application/json.
    • set "Response content type" to application/json
    • use the following request as the "body" parameter. Note that the Loan object has its approved attribute set to false:
    {
       "lookup": "default-stateless-ksession",
       "commands": [
          {
             "insert": {
                "object": {
                   "com.redhat.demo.qlb.loan_application.model.Applicant": {
                      "creditScore":410,
                      "name":"Billy Bob",
                      "age":40,
                      "yearlyIncome":90000
                   }
                },
                "out-identifier":"applicant"
             }
          },
          {
             "insert": {
                "object": {
                   "com.redhat.demo.qlb.loan_application.model.Loan": {
                      "amount":250000,
                      "duration":10
                   }
                },
                "out-identifier":"loan"
             }
          },
          {
             "start-process" : {
                "processId" : "loan-application.loan-application-decision-flow",
                "parameter" : [ ],
                "out-identifier" : null
             }
          }
       ]
    }
    • observe the result. The Quick Loan Bank rules have fired and determined that, based on the credit score of the application, and the amount of the loan, the loan can be approved. The approved attribute of the Loan has been set to true.

Exploring the front end UI

During the automated installation we've deployed this front end project into a container and configured it to access the KIE server back end, so let's give it a go:
  1. Log in to the decision manager business central dashboard at: http://insecure-quick-loan-bank-rhdmcentr-appdev-in-cloud.apps-crc.testing with u:erics and p:redhatdm1!

  2. node front end
    Click on the "loan-application" project to open the Loan Application Demo project.

  3. The project has simple data model (Loan & Applicant) and single decision table (loan-application) which contains the loan approval rule set.

  4. Build and deploy version 1.0 of the project. Click on the "Build and Deploy" in the upper right corner.

  5. Go to "Menu -> Deploy -> Execution Servers" repository to see the 'loan-application_1.0' KIE Container deployed on the Decision Server.

  6. Open the deployed Quick Loan Bank application form: http://qlb-client-application-appdev-in-cloud.apps-crc.testing

  7. Fill in the form as follows and submit for evaluation:

    node front end
    Name: Eric D. Schabell Age: 40 Credit Score: 410 Yearly Income: 90000 Amount: 250000 Duration: 10

Try to enter different values to see a loan get disapproved, for example, change above applicant age from 40 to 80 for rejection based on age. 

This concludes the tour of our Quick Loan Bank example with a Node.js front end and decision management back end. Looking for more content to get started with Red Hat Decision Manager? Try one of these online workshops to build more projects from scratch.