Author: Eddy Caballero and Xiao Hua Liu
Summary
In Operational Decision Manager (ODM) on Cloud Pak for Business Automation (CP4BA) and containers, you may run into a situation where the parsing time for a large ruleset takes a long time and leads to high response times during the first ruleset execution.
In this scenario, you may want to “preload” the ruleset. Preloading the ruleset will load the ruleset into the cache before the first real execution so that you can avoid the parsing time.
There is no out of box solution to preload rulesets. This guide explains how to create a script that will preload a ruleset in an existing Decision Server Runtime pod by executing a curl command to get the WADL description file.
Steps
This solution involves creating a script that retrieves the names of all the Decision Server Runtime pods. Then, you can use the oc rsh command to enter each pod and execute a curl command to get the WADL description file. Retrieving the WADL file will load the ruleset into the cache.
Optional: Instead of retrieving the WADL file, you can also send a dummy request to the ruleset.
You may implement this in various ways, but your script should follow these general steps.
1) Get the names of all the Decision Server Runtime pods.
oc get pod -l run=<CP4BA deployment name>-odm-decisionserverruntime -o custom-columns=POD:.metadata.name --no-headers
Example:
oc get pod -l run=icp4adeploy-odm-decisionserverruntime -o custom-columns=POD:.metadata.name --no-headers
This command returns only the names of the Decision Server Runtime pods without any headers.
Output:
icp4adeploy-odm-decisionserverruntime-5b84fbbfcc-xxrdr
icp4adeploy-odm-decisionserverruntime-58f897cdf8-4968d
2) Use the oc rsh command to enter each pod.
oc rsh icp4adeploy-odm-decisionserverruntime-5b84fbbfcc-xxrdr
3) Now that you are inside the pod and can execute the curl command to get the WADL file (or send a dummy request).
curl -k --user <username>:<password> -X GET https://<hostname>:<DecisionServicePort>/odm/DecisionService/rest/v1/<RuleAppName>/<RuleAppVersion>/<RulesetName>/<RulesetVersion>/WADL
Example:
curl -k --user resExecutor:resExecutor -X GET https://localhost:9443/odm/DecisionService/rest/v1/MiniloanRuleApp/1.0/MiniloanRuleset/1.0/WADL
4) Repeat steps 2 and 3 for each Decision Server Runtime pod.
5) Now the ruleset is preloaded in each pod.
You can check the XU dump to confirm the ruleset has loaded in the cache.
6) In addition to this script, you can use the maxIdleTime ruleset property to ensure the ruleset stays in the cache as long as you need it.
Example Bash Script:
// Assisted by WCA@IBM
// Latest GenAI contribution: ibm/granite-20b-code-instruct-v2
# Set the CP4BA deployment name variable
export DEPLOYMENT_NAME=<your CP4BA deployment name>
# Get the list of pods in the current namespace
pods=$(oc get pods -l run=${DEPLOYMENT_NAME}-odm-decisionserverruntime -o jsonpath='{.items[*].metadata.name}')
# Iterate through each pod and execute the curl command within the pod
for pod in $pods; do
echo "Executing curl command within pod ${pod}"
oc rsh ${pod} curl -k --user resExecutor:resExecutor -X GET https://localhost:9443/odm/DecisionService/rest/v1/<RuleAppName>/<RuleAppVersion>/<RulesetName>/<RulesetVersion>/WADL
done
You can create a bash script, replacing the manual step done in step 1 to 4, by using preloading.sh with the code snippet above. Replace the variables indicated by the characters “<>” with the appropriate values. The result will look like the script below.
// Assisted by WCA@IBM
// Latest GenAI contribution: ibm/granite-20b-code-instruct-v2
# Set the CP4BA deployment name variable
export DEPLOYMENT_NAME=icp4adeploy
# Get the list of pods in the current namespace
pods=$(oc get pods -l run=${DEPLOYMENT_NAME}-odm-decisionserverruntime -o jsonpath='{.items[*].metadata.name}')
# Iterate through each pod and execute the curl command within the pod
for pod in $pods; do
echo "Executing curl command within pod ${pod}"
oc rsh ${pod} curl -k --user resExecutor:resExecutor -X GET https://localhost:9443/odm/DecisionService/rest/v1/MiniloanRuleApp/1.0/MiniloanRuleset/1.0/WADL
done
This script was generated using Watson Code Assistant. It retrieves the Decision Server runtimes pods from the CP4BA deployment named icp4adeploy and executes a curl command in each pod to retrieve the WADL description file for the Miniloan ruleset. This results in the ruleset being loaded in each pod.