Version 9.6
 —  Developing Custom Actions  —

Sample Custom Actions

Your CentraSite installation contains two sample custom action rules. One rule is a Java rule, and the other is a Groovy script rule.

The content is organized under the following sections:


Sample Java Action: Enforce Unique Asset Names

Your CentraSite installation contains a sample Java action rule (which is contained in uniquenamechecker.zip) that you can use to create a custom action that ensures that the name and version combination of a newly-created asset is unique within the CentraSite catalog. If it is not unique, the action returns Failure, and the asset is not allowed to be created.

To create the custom action, you will use the CentraSite user interface to:

  1. Create a custom action category

  2. Create a custom action template, to which you upload the sample Java rule

  3. Create a Design/Change-Time policy and add the custom action template to it

Create and test the custom action as follows.

Start of instruction setTo create and test the custom action Enforce Unique Asset Names

  1. In CentraSite Control, go to Policies > Action Templates.

  2. Click the Add Action Category button.

  3. In the Add Action Category dialog box, do the following:

    1. Specify a name for the new custom category, for example My Custom Actions. An action category name can contain any character (including spaces).

    2. Choose Design/Change-Time as the action category type.

    3. Click OK.

    The action category that you created appears as a custom category next to an icon in the Policy Information panel.

  4. Click Add Action Template.

  5. On the Add Action Template page, specify the following fields:

    In this field... Do the following...
    Category

    Select the custom action category you just created.

    Name

    Enter the name Enforce Unique Asset Names for the new action template.

    Description

    Optional. Type a description for the new action template. For example: Ensures that asset names are unique.

    Implementation

    Select Java.

    Uploaded File

    Click the Browse button and upload the following rule file:

    <CentraSite_Install_Dir>\demos\Custom actions\Java\uniquenamechecker.zip

    This .zip file that contains the following:

    • A folder named lib, which contains a jar file with the action’s executor class and the external libraries.

    • A folder named META-INF, which contains a property file named assertion.properties, which is the build file for the action.

    For more information about creating and uploading actions rules, see Creating Action Rules.

  6. In the Scope panel, specify the following fields:

    In this field... Do the following...
    Object Types

    Select Service as the type of object to which this action template applies.

    Event Types

    Select PreCreate as the type of event to which this action template applies.

  7. Click Save.

    The Edit Action Template Detail page is displayed.

  8. Create a policy and add the sample action to the policy as follows:

    1. In CentraSite Control, go to Policies > Design/Change Time.

    2. Click Add Policy.

    3. In the Policy Information panel, enter a name for the new policy, for example, Ensure Unique Asset Names Policy. A policy name can contain any character (including spaces).

    4. In the Scope panel, specify the object and event types to which the policy applies as follows:

      • In the Object Types field, select Service as the type of object to which this policy applies.

      • In the Event Types field, select PreCreate as the type of event to which this policy applies.

      • In the Organization field, select your organization name as the organization to which this policy belongs (and to whose objects the policy will be applied).

    5. Click Next.

    6. From the Available Actions list, choose the custom action Enforce Unique Asset Names action that you created.

    7. Click Finish to save the new policy. The Design/Change-Time Policy Details page is displayed.

    8. Activate the policy by choosing the Change State button and choosing the Productive state.

Top of page

Sample Groovy Script Action: Service Attribute Checker

Your CentraSite installation contains a sample Groovy action rule (ServiceAttributeChecker.groovy) that you can use to create a custom action that checks for a particular value of a service attribute.

To create and test the custom action, you will use the CentraSite user interface to:

  1. Create a custom action category

  2. Create a custom action template, to which you upload the sample Groovy script rule

  3. Create a Design/Change-Time policy and add the custom action template to it

  4. Test the custom action "on demand" (manually) on the policy's detail page

Create and test the custom action as follows.

Start of instruction setTo create and test the custom action Service Attribute Checker

  1. In CentraSite Control, go to Policies > Action Templates.

  2. Click the Add Action Category button.

  3. In the Add Action Category dialog box, do the following:

    1. Specify a name for the new custom category, for example My Custom Actions. An action category name can contain any character (including spaces).

    2. Choose Design/Change-Time as the action category type.

    3. Click OK.

    The action category that you created appears as a custom category next to an icon in the Policy Information panel.

  4. Click Add Action Template.

  5. On the Add Action Template page, specify the following fields:

    In this field... Do the following...
    Category

    Select the custom action category you just created.

    Name

    Enter the name Service Attribute Checker for the new action template.

    Description

    Optional. Type a description for the new action template. For example: Validates asset attribute values.

    Implementation

    Select Groovy.

    Uploaded File

    Click the Browse button and upload the following rule file:

    <CentraSite_Install_Dir>\demos\Custom actions\Groovy\ServiceAttributeChecker.groovy

    In the Scope panel, specify the following fields and click Save:

    In this field... Do the following...
    Object Types

    Select Service as the type of object to which this action template applies.

    Event Types

    Select OnTrigger as the type of event to which this action template applies. This will enable you to test the action "on demand" (manually) in the Actions profile of the Design/Change Time Policy Detail page.

  6. In the Edit Action Template Detail page, select the Parameter Templates profile in order to add the action's parameter templates and click the Add Parameter Template button.

  7. Set the first parameter template for the action as follows:

    In this field... Do the following...
    Name

    Enter Attribute Name. This parameter will hold the attribute that you want to check (e.g., any CentraSite attribute, which you will assign after you add the action to a policy).

    Type

    Choose the data type Attribute for this parameter template.

    Default Value

    Leave blank.

    Array

    Leave blank.

    Required

    Select this check box.

  8. Click the Add Parameter Template button again to set the second parameter template as follows:

    In this field... Do the following...
    Name

    Enter Possible Attribute Value. This parameter will hold the value of the attribute that you want to check.

    Type

    Select the data type String for this parameter template.

    Default Value

    Enter an attribute value that you want to check.

    Array

    Leave blank.

    Required

    Select this check box.

  9. Click Save and then Close.

    The parameter template that you added appears in the Parameter Templates profile.

  10. Create a policy and add the sample action to the policy as follows:

    1. In CentraSite Control, go to Policies > Design/Change Time.

    2. Click Add Policy.

    3. In the Policy Information panel, enter a name for the new policy, for example, Service Attribute Checker Policy. A policy name can contain any character (including spaces).

    4. In the Scope panel, specify the object and event types to which the policy applies as follows:

      • In the Object Types field, select Service as the type of object to which this policy applies.

      • In the Event Types field, select OnTrigger as the type of event to which this policy applies.

      • In the Organization field, select your organization name as the organization to which this policy belongs (and to whose objects the policy will be applied).

    5. Click Next.

    6. From the Available Actions list, choose the custom action Service Attribute Checker action that you created.

    7. Click Finish to save the new (as yet incomplete) policy. The Design/Change-Time Policy Details page is displayed.

    8. To configure the two parameters for the action, choose the action name on the Actions profile. For the Attribute Name parameter, choose an attribute. For the Possible Attribute Value parameter, select the default value that you defined for the Possible Attribute Value parameter in the action template.

    9. Click Save and then Close. The policy detail page is displayed.

    10. Activate the policy by choosing the Change State button and choosing the Productive state.

    11. Select the Actions profile.

    12. To test the action, click the Run button. The action checks all services in your organization and displays a pop-up. The pop-up should indicate Success in the Result column for the service that matches the value you specified in Possible Attribute Value. All other services will also be displayed, with Failure in the Result column.

  11. After you have completed testing, you can use this custom action in other Design/Change-Time policies. To do this, go to its Scope panel, change the event type from OnTrigger to PreCreate or PreUpdate, and include the action in other Design/Change-Time policies whose event type scope is either PreCreate or PreUpdate.

Top of page