Updating Rule Applications in Code using irSDK
Warning: As with the previous posts about Continuous Integration/Continuous Deployment, this post is intended for a technical/developer audience.
A while back, I started a series about CI/CD with a pair of blog posts that walk through examples of ways to include InRule in your CI/CD pipeline. Among other things, I covered how to retrieve a Rule Application from either an irCatalog instance or from a .ruleappx file, as well as how to promote a rule application to a downstream catalog or file destination.
For some of our customers that use environment-specific data or integrations with external resources like REST services or databases, different executions or environments may need to point to different reference data or external resource locations. To enable that, InRule has a variety of options:
- 1. Provide overrides as part of the request during execution (either using our standard REST execution service or a during custom execution using irSDK). This is considered a request-level override.
- 2. Add settings to the configuration of an execution service with overrides to use for all requests flowing through that execution service. This was added in InRule version 5.6, and is considered a service-level override.
- 3. Modify the Rule Application in code using irSDK during the promotion process, so that the updated reference data or external resource locators are modified in the actual Rule Application definition. This requires custom development to implement, and is considered a code-based Rule Application modification.
Our general recommendation is to use either option 1 or 2. Particularly now that option 2 has been released, fewer customers will have a need to implement option 3 – but we do occasionally find customers that have a business need to implement option 3 due to some internal requirements. This Rule Application modification will need to be done between the two previously mentioned steps in the pipeline – after the retrieval of the Rule Application definition, and before it gets Promoted to a downstream target.
A word of caution
By modifying the Rule Application during the promotion process, there will by definition be a disparity between what is checked into the source Catalog and what gets saved to the target Catalog. This means that there needs to be strict governance in place to control/prohibit use of other tools (Catalog Manager, irAuthor) to perform promotions, since they do not take into account the changes made in the pipeline. You will also want to ensure that promotion is never done in a backwards direction, as that would overwrite the settings with the values from the downstream environment.
Updating Rule Application in Code
That was a lot of background and context – let’s take a look at how you can actually make it happen!
This post is not going to have an associated console application like the previous posts did, since the items that need to be updated in a given Rule Application will differ substantially from customer to customer. However, we will walk through a variety of different items that you may have a need to update, which should provide the context around where to look to find and update anything in the Rule Application. Each example is structured as a static helper method that will extend the behaviors available on the RuleApplicationDef object when referenced in a static class.
Database Connection Strings
This is an extremely common item to differ between environments – and it can also easily be overridden at a request- or service- level. If you need to modify the Rule Application Definition level, it’s a straightforward process:
REST Service Root URLs
This is another extremely common one (with the same standard override options), and is also a straightforward item to override in code if needed:
REST Operation Header Values
Now we’re getting more complicated! This substitution cannot be performed via configuration, and could be used for things like setting the API Key value in a REST request header. Note that we generally recommend passing in or retrieving the authentication header value during execution, and then populating the header value dynamically. However, if you need to hard-code the updated value in your Rule App definition, the process is again fairly straightforward:
Inline Value Lists
This item, as well as the next one, can be overridden at either the request- or service- level in addition to being set in code. However, given the complexity and amount of data that may be involved, there may be a need to replace it directly in the definition:
As with the previous item, this can also be overridden at other levels or set in the definition directly, albeit with a bit more complexity:
Entity Field Default Values
Let’s end on a simpler one. We’ve looked at updating all sorts of supporting data, but what about setting schema properties directly? This could be used for something like a flag indicating environment or log level, access token, or any number of other pieces of information:
As I mentioned before, the examples I have listed are intended to give you some context into where you might look to find various components of a Rule Application to update them using irSDK.
Before going down the route of implementing custom code in your CI/CD pipeline to modify the Rule Application definition, I would very strongly encourage you to look into the functionality introduced in 5.6 that allows for overriding execution settings at a service-level; that should handle the vast majority of situations, and you can find all the details in the InRule Developer Help by navigating to “Application Integration with InRule > Configuration Files > InRule Runtime Service Config File Settings”. If you find that does not cover your needs, using irSDK to modify the definition may prove to be a great solution. Remember: anything that you’re able to set in irAuthor, you’re able to modify using irSDK.