API Script Execution and Policy Manager
In this blog, we’re going to look at the phase of development that happens after configuring your API. It is at this stage that you are likely at a point where you have already defined the application elements that will “feed” your API, and you are looking for a way to quickly and efficiently use your API as the hub for inter- and intra-application communication and execution. If you have properly configured your API script, then addressing the reference script is the next step towards executing the application. Let's look at this a bit more closely:
After you add your set of utility scripts, in your virtual service operation process definition, you add a Script Activity, import a pre-defined script, and add a script reference for the function you want to perform. For example, you may have a requirement to validate some data as part of your process and you created a reusable script (e.g., TestScript) that includes a function for validating data (validateData). In your process definition, import "TestScript" and reference the function in the script source as shown here:
Execute Your Script
Common functions that you may need to perform in your scripts can be saved in Script objects using the Add Script function in the Scripts section of each Organization in the Policy Manager Workbench. To make use of those common functions from the Script Activity the Script objects defining those functions must be imported. The Imports area is where those scripts are identified for import. The available scripts are listed in the Available Scripts tree. Any number of Scripts in that tree can be moved to the Imported Scripts list box. Only scripts that match the language type will be available for selection in the tree. The script does not return a value.
Pre-defined variables, which are offered as part of Akana's Policy Manager 7.0 are helpful if you are using scripts in a process. The following are provided:
- processContext: Provides functions for retrieving and changing information about the currently running process, such as the variables defined in the process and the authenticated subject(s) of the process.
- systemLog: Provides logging functions to the container’s log. The statements logged with this interface are mixed with the other system log statements.
- auditLog: Provides logging functions to the process audit log. If auditing is enabled for the virtual service operation that is invoking the process statements logged using this variable log information will be inserted into the audited message log for the operation’s execution. This can be found on the service’s Monitoring tab in the Logs sub-tab.
- alerter: Provides an interface for generating alerts that are displayed in on the Policy Manager alert pages.
- recorder: Provides an interface for recording content in the Policy Manager usage log pages.
- msgFactory: Providers functions for create message variables. A message variable cannot simply be assigned content like a simple string or int variable. It must be initialized using one of the functions in the msgFactory.
Interfaces and Classes
The Policy Manager Scripting API located in the \sm70\docs\scriptDocs folder of the Policy Manager 7.0 Release Folder provides a series of interfaces and classes you can use to build process related scripts. The API includes lots of use cases and sample code you can experiment with and use as a baseline when building your own scripts.