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.

For information about using policies in the context of the Community Manager developer portal, see Business Policies.

Table of Contents

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, and then enter your script into the Expression text box.

Supported script languages:

Click Finish to add your script, and then click Close to exit the wizard.

Step 4: Activate Policy

When the policy configuration is complete, activate the policy so that you can use it.

Activate the policy in the Policy Workflow Portlet.

Step 5: Attach Policy

After you've saved and activated 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.

Activating a policy

When you create and configure a policy, the policy is in Draft state. When the policy configuration is complete, activate the policy: click Activate Policy and then confirm. See Activate a Policy.

A policy in Draft state is not available for general use. Once you activate the policy, it is in Active state and is available for use.

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.

Attaching a policy

To use the policy, go to the Policies folder in the respective organization and attach the policy to a web service, binding, or binding operation.

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 Community Manager 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.