|
| 1 | +# Automating the deployment and execution of rulesets with the REST API |
| 2 | + |
| 3 | +## Introduction |
| 4 | + |
| 5 | +This sample demonstrates how to automate the deployment and execution of a ruleset using the REST API. |
| 6 | + |
| 7 | +In this sample, you will: |
| 8 | +- deploy ODM either on Kubernetes or in Docker, |
| 9 | +- deploy a ruleset from Decision Center to Decision Server, |
| 10 | +- execute this ruleset. |
| 11 | + |
| 12 | +## Prerequisites |
| 13 | + |
| 14 | +- Ensure you have at least Docker 24.0.x or Kubernetes 1.27+ |
| 15 | +- Install [jq](https://jqlang.github.io/jq/download/) |
| 16 | + |
| 17 | +## Installation of ODM |
| 18 | + |
| 19 | +Click one of the links below whether you wish to install ODM on: |
| 20 | + * [Kubernetes](README-KUBERNETES.md). |
| 21 | + * [Docker](README-DOCKER.md). |
| 22 | + |
| 23 | +## Configuration |
| 24 | + |
| 25 | +### 1. Set Environment Variables |
| 26 | + |
| 27 | +The following environment variables need to be set: |
| 28 | + |
| 29 | +<!-- markdown-link-check-disable --> |
| 30 | + |
| 31 | +| Name | Description | Value for Docker | |
| 32 | +| - | - | - | |
| 33 | +| DC_API_URL | Decision Center API URL | http://localhost:9060/decisioncenter-api | |
| 34 | +| DSR_URL | Decision Server Runtime URL | http://localhost:9060/decisioncenter/DecisionService) | |
| 35 | + |
| 36 | +<!-- markdown-link-check-enable--> |
| 37 | + |
| 38 | +### 2. Deploy the Decision Service |
| 39 | + |
| 40 | +If not already done, deploy the `Loan Validation Service` Decision Service into Decision Center by running: |
| 41 | +```bash |
| 42 | +# configure the Authentication (using Basic Auth) |
| 43 | +auth_credentials=(--user \"odmAdmin:odmAdmin\") |
| 44 | + |
| 45 | +decision_service_name="Loan Validation Service" |
| 46 | +filename="${decision_service_name// /_}.zip" # replace spaces by underscores |
| 47 | +filename_urlencoded="${decision_service_name// /%20}.zip" # replace spaces by %20 |
| 48 | + |
| 49 | +# download the Decision Service zip file |
| 50 | +curl -sL -o ${filename} "https://github.com/DecisionsDev/odm-for-dev-getting-started/blob/master/${filename_urlencoded}?raw=1" |
| 51 | + |
| 52 | +# upload the Decision Service in Decision Center |
| 53 | +curl -sk -X POST ${auth_credentials[@]} -H "accept: application/json" -H "Content-Type: multipart/form-data" \ |
| 54 | + --form "file=@${filename};type=application/zip" \ |
| 55 | + "${DC_API_URL}/v1/decisionservices/import" |
| 56 | +``` |
| 57 | + |
| 58 | +## Run the sample |
| 59 | + |
| 60 | +```bash |
| 61 | +# configure the Authentication (using Basic Auth) |
| 62 | +export auth_credentials=(--user 'odmAdmin:odmAdmin') |
| 63 | + |
| 64 | +# get the ID of the Decision Service in Decision Center |
| 65 | +export decision_service_name="Loan Validation Service" |
| 66 | +get_decisionService_result=$(curl -sk -X GET ${auth_credentials[@]} -H "accept: application/json" "${DC_API_URL}/v1/decisionservices?q=name%3A${decision_service_name// /%20}") |
| 67 | +decisionServiceId=$(echo ${get_decisionService_result} | jq -r '.elements[0].id') |
| 68 | + |
| 69 | +# get the ID of the deployment configuration in Decision Center |
| 70 | +export deployment_name="production deployment" |
| 71 | +get_deployment_result=$(curl -sk -X GET ${auth_credentials[@]} -H "accept: application/json" "${DC_API_URL}/v1/decisionservices/${decisionServiceId}/deployments?q=name%3A${deployment_name// /%20}") |
| 72 | +deploymentConfigurationId=$(echo ${get_deployment_result} | jq -r '.elements[0].id') |
| 73 | + |
| 74 | +# deploy the ruleapp from Decision Center |
| 75 | +curl -sk -X POST ${auth_credentials[@]} -H "accept: application/json" "${DC_API_URL}/v1/deployments/${deploymentConfigurationId}/deploy" | jq |
| 76 | + |
| 77 | +# execute the ruleset that was deployed |
| 78 | +export ruleset_path="/production_deployment/loan_validation_production" |
| 79 | +curl -sk -X POST ${auth_credentials[@]} -H "accept: application/json" -H "Content-Type: application/json" -d "@payload.json" ${DSR_URL}/rest${ruleset_path} | jq |
| 80 | +``` |
| 81 | + |
| 82 | +> [!NOTE] |
| 83 | +> The commands above rely on Basic Authentication (as ODM is deployed without an OpenID Connect Provider). |
| 84 | +> In a different environment with OpenID Connect, you can authenticate using the `client_credentials` grant type by: |
| 85 | +> - setting the environment variables |
| 86 | +> - CLIENT_ID |
| 87 | +> - CLIENT_SECRET |
| 88 | +> - OPENID_TOKEN_URL |
| 89 | +> - and replacing `auth_credentials=(--user "odmAdmin:odmAdmin")` by the commands below: |
| 90 | +> ```bash |
| 91 | +> access_token=$(curl -sk -X POST -H "Content-Type: application/x-www-form-urlencoded" -d "client_id=${CLIENT_ID}&scope=openid&client_secret=${CLIENT_SECRET}&grant_type=client_credentials" ${OPENID_TOKEN_URL}) | jq -r '.access_token') |
| 92 | +> auth_credentials=(-H "Authorization: Bearer ${access_token}") |
| 93 | +> ``` |
0 commit comments