2010/04/20
20 Apr, 2010

Client-side Scripting for Lifecycles in Governance Registry

  • Senaka Fernando
  • Director Solutions Architecture - WSO2

The WSO2 Governance Registry supports Resource (and Collection) Lifecycles along with Lifecycle Management via the Management Console. With the help of this feature client-side scripting support for lifecycles can be done easily via WSO2 Governance Registry.

The WSO2 Governance Registry supports Resource (and Collection) Lifecycles along with Lifecycle Management via the Management Console. In the navigator under Govern click on Lifecycles to see a list of available lifecycles. Through this interface, new lifecycle configurations can be added while existing configurations can be edited or deleted if they are currently not in use. If a lifecycle is in use, you can find a list of resources and collections to which the lifecycle has been attached by clicking on Find Usages.

Each lifecycle configuration contains one or more state elements. More information on lifecycle configuration and the various elements in it, can be found in here.

The client-side scripting support is available for lifecycle state transition event. This can be done by adding something similar to the following under the state element.

    <js>
        <console promoteFunction="myFunction">
            <script type="text/javascript">
                myFunction = function() {
                    // executable script
                }
            </script>
        </console>
    </js>

As an example, let's add an alert for for the state transition from Initialize to Designed in the default ServiceLifeCycle . This can be done by editing the existing lifecycle and adding the configuration below.

    <aspect name="ServiceLifeCycle" class="org.wso2.carbon.governance.registry.extensions.aspects.ChecklistLifeCycle">
        <configuration type="literal">
            <lifecycle>
                <state name="Initialize" location="/environment/init">
                    <checkitem>Requirements Gathered</checkitem>
                    <checkitem>Architecture Finalized</checkitem>
                    <checkitem>High Level Design Completed</checkitem>
                    <js>
                        <console promoteFunction="myFunction">
                            <script type="text/javascript">
                                myFunction = function() {
                                    alert("Promoted Resource to Designed State");
                                }
                            </script>
                        </console>
                    </js>
                </state>
                <state name="Designed" location="/environment/design">
                    <checkitem>Code Completed</checkitem>
                    <checkitem>WSDL, Schema Created</checkitem>
                    <checkitem>QoS Created</checkitem>
                </state>
                <state name="Created" location="/environment/development">
                    <checkitem>Effective Inspection Completed</checkitem>
                    <checkitem>Test Cases Passed</checkitem>
                    <checkitem>Smoke Test Passed</checkitem>
                </state>
                <state name="Tested" location="/environment/qa">
                    <checkitem>Service Configuration</checkitem>
                </state>
                <state name="Deployed" location="/environment/prod">
                    <checkitem>Service Configuration</checkitem>
                </state>
                <state name="Deprecated" location="/environment/support" />
            </lifecycle>
        </configuration>
    </aspect>

After saving this configuration, add the ServiceLifeCycle to a Service (or any other resource/collection), tick all the check-boxes, and click on the Promote button. You will get an information dialog followed by the alert we added. Likewise, you can add any valid executable JavaScript that is capable of performing some task that you require.

Applies To:- WSO2 Governance Registry-3.5.0 or later.

Author

Senaka Fernando, Software Engineer, WSO2, [email protected]

 

About Author

  • Senaka Fernando
  • Director Solutions Architecture
  • WSO2