Using the QoS Script Policy

Learn how to add custom utility scripts for performing different actions to the policy definition, using JavaScript, Jython, or BeanShell script languages.

About Policies Managing Policies QoS Policies

Getting Started with Scripts Policy Manager Scripting API

Supported Platforms: 7.2 and later

Table of Contents

  1. Introduction
  2. Script Policy Options
  3. Configuration
  4. QoS Script Policy: use cases for Policy Manager
  5. QoS Script Policy: use cases for the Akana API Platform (Community Manager)

Introduction

The Quality of Service (QoS) Script Policy allows you to add custom utility scripts for performing different actions to the policy definition, using JavaScript, Jython, or BeanShell script languages.

The Policy Manager Scripting API, located in the \docs\scriptDocs folder of the Policy Manager installation 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 custom quota management scripts.

You can also access the API on the Akana Documentation Repository: Policy Manager Scripting API.

Script Policy Options

The policy includes the configuration options shown below.

Script Policy Details
  • Name: A read-only field that displays the name of the Script Policy.
  • Description: A read-only field that displays the description of the Script Policy.
Script Policy
  • Imports: This section includes common functions that you might need to perform in your scripts that have been saved in Script objects, using the Policy Manager > Workbench > Organization > Scripts > Add Script function. The available scripts are listed in the Available Scripts tree. You can move any number of the scripts in that tree to the Imported Scripts list box. Only scripts that match the language type are available for selection in the tree.
  • Script Language: A drop-down list box that allows you to select the script language for the script to be added. Supported options: JavaScript, Jython, and BeanShell Engine script language types.
  • Expression: A text box that allows you to enter your script.
  • Test Script: A button that allows you to test the entered expression to determine if it is properly formed. This option is available in Policy Manager version 7.x only.

Configuration

Let's take a quick walkthrough of the Script Policy configuration process to get you started.

Step 1: Review Script Creation Process

The first step is to review the following documentation, to become familiar with the script creation process, available tools, and the Policy Manager scripting API:

Step 2: Add Policy

In Policy Manager, you can create a Script Policy instance using Add Policy in the Policies > QoS Policies section.

Step 3: Modify Policy

When you click Modify to make changes to the Script Policy on the Policy Details page, the initial policy looks like this:

Select the script language from the drop-down list box (JavaScript, Jython, or BeanShell Engine), and enter your script into the Expression text box.

Click Test Script (version 7.x only) to verify that your script is properly formed. Make adjustments as needed. Click Finish to add your script, and then click Close to exit the wizard.

Step 4: Activate Policy

If you are using Policy Manager 7.2 or above, activate the policy in the Policy Workflow Portlet. Otherwise, skip this step.

Step 5: Attach Policy

After you've saved your policy, attach it to a web service operation.

Step 6: Test Policy

To test the policy, send a request and view the Alerts portlet in the Registry of the Organization Tree. An alert is generated for each request sent.

back to top

QoS Script Policy: use cases for Policy Manager

For a walkthrough on how to use scripts and access to the Policy Manager Scripting API for each Policy Manager version, see Getting Started with Scripts (PM7x) or Getting Started with Scripts (PM8x).

back to top

QoS Script Policy: use cases for the Akana API Platform (Community Manager)

This section provides a list of Community Manager-specific usage scenarios for the Script Policy.

It includes:

  1. Add / Configure Script Policy
  2. How Do I Verify Script Policy at the Service Level?
  3. How Do I Verify Script Policy at the Contract Level?
  4. How Do I Verify Script Policy at the License > Term Level?

Add / Configure Script Policy

This example will configure s Script Policy using JavaScript.

Note: If you are using a Script Policy with Community Manager, you must first add the policy to the Community Manager Tenant Organization in Policy Manager. Once that's done, it will be available for selection in the developer portal.

  1. Go to the Policy Manager Management Console > Tenant Organization > Policies > QoS Policies and choose Add Policy.

  2. Specify Policy Name, Policy Type (Script Policy), click Finish, and then click Close.

  3. On the Script Policy Details screen, click Modify.

  4. Select the script language (for example, JavaScript) and specify the following script:
    alerter.alert("22222222","Custom alert code which is user defined.");

  5. Click Finish.
  6. Activate the policy.

How Do I Verify Script Policy at the Service Level?

  1. Launch Community Manager.
  2. Attach the Script Policy at the Service Level as shown below in the Edit API Wizard > Proxy section.

  3. Now send requests from the app in Test Client. An alert is generated for each request. You can see these alerts in Policy Manager > Registry level.

How do I Verify Script Policy at the Contract Level?

  1. Launch Community Manager.
  2. While requesting API Access, select the Script Policy checkbox and finish the process. Make sure the contract is activated.

  3. Send a request from the app in Test Client. The request should be successful and you will see the following alert type for each request.

How Do I Verify Script Policy at the License > Term Level?

  1. Launch Community Manager.
  2. Choose Edit License and attach the Script Policy.

  3. Select the scope that is used with your license.

  4. Request API access and select the same license.

  5. Activate the contract.
  6. Go to Test Client and send a request. You'll see an alert in Policy Manager for each request.

Back to top