Saturday, August 16, 2014

Implement Registry Extension (RXT) 2.0 + Associated UI support - Project Documentation




Project Idea


The initial project idea was to Implement RXT 2.0, a JSON based model to replace the existing XML based RXT configuration. But due to the complexity and the time limitation of the project, the scope was narrowed down to create a Jaggery Application to Add a new RXT to WSO2 Governance Registry.

Overview


WSO2 Governance Registry is a SOA based registry/repository to manage, govern and store resources. These resources can be any artifact varying from a plain text file to a WSDL, service, URI, API, Schema, policy etc. The artifacts can be associated with lifecycle management, configuration governance, development process governance, design and run-time governance, team collaboration and provided with access control mechanisms.

Configurable Governance Artifacts are one of the many ways of extending the functionality of WSO2 Governance Registry to support modeling any type of asset to suit the user requirements. The RXT model provides an extensible configuration language to create new types of artifacts.

The main objective of this project is to provide enhanced usability when configuring new types of artifacts and introduce a new intermediate JSON based RXT format which can be used when WSO2 Governance Registry is migrating to a JSON based RXT format.

Design


The basic design includes generating a JSON based RXT using the user input and send it to the Registry backend and convert it to the existing XML based RXT format and use it without breaking the current XML based RXT implementation. To achieve the task I came up with the following design. In the Jaggery Application ‘ArtifactBuilder’ user input is read and basic input validation is done. A JSON based RXT is generated from the user input. ManageGenericArtifact Admin Service is called via Jaggery and JSON is sent to the Registry backend. The JSON -> XML conversion is handled by a Util method and finally via the generated XML, RXT, the existing code is executed to add the new Artifact Type. Since the Newly generated JSON based RXT is sent to the Registry, it can be persisted in the registry at a later point of time as well. The diagram below shows a design of the proposed Application.



Implementation


The main Technologies used to create the Jaggery Application are, Bootstrap, Basic HTML/CSS, Javascript, Jquery, JSON and for the communication, Jaggery-JQuery. Bootstrap 2 is the main UI framework used in the Jaggey Application Implementation. To add the drag and drop functionality Bootsnipp Form builder was used [1] and to add/delete dynamic table rows the ‘Dynamic table row creation/deletion’ snippet was used [2]. Both of the snippets comes under the MIT license.

When user logs in to WSO2 Governance Registry and navigate to the List Applications, they can click on the ArtifactBuilder Jaggery Application which will navigate to the below UI, which makes it easier to model their Artifact with only a few clicks without the hazel of editing a XML. The below image show part of the Jaggery application.






User can enter the basic artifact details, drag and drop the content ui elements to build the UI, then add the UI and Relationship information and click ‘Save Artifact’ which will do the input validation and generate a JSON based RXT model to be sent to the backend.

All the input is read from Javascript via the Document Object Model (DOM) and transformed into the JSON format.

I have created a new method addJSONRXTResource in ManageGenericArtifactService and exposed it as a admin service method so that it can be called directly by passing the payload of a RXT JSON. A new Util class was added in order to generate the conventional RXT XML using the JSON string. Inside addJSONRXTResource after generating the xml, addRXTResource admin service method is called and the newly generated XML based artifact is added without breaking the existing XML model.

In the Jaggery application, once the JSON is generated, the addJSONRXTResource is called via a Jaggery WS-Request [3] by passing the JSON string as the payload.

Sample JSON RXT


{  
   "artifactType":{  
      "hasNamespace":"false",
      "iconset":"18",
      "lifecycle":"",
      "nameAttribute":"overview_id",
      "nameSpaceAttribute":"",
      "pluralLabel":"people",
      "shortName":"person",
      "singularLabel":"person",
      "storagePath":"/people/@{name}",
      "type":"application/vnd.wso2-person+xml"
   },
   "content":{  
      "Overview":[  
         {  
            "helptext":"help",
            "id":"id",
            "label":"ID",
            "placeholder":"id",
            "required":"checked",
            "type":"text"
         },
         {  
            "helptext":"help",
            "id":"name",
            "label":"Name",
            "placeholder":"name",
            "required":null,
            "type":"text"
         },
         {  
            "id":"gender",
            "label":"Gender",
            "options":"Male\nFemale",
            "type":"option"
         },
         {  
            "id":"address",
            "label":"Adress",
            "type":"textArea"
         }
      ]
   },
   "relationships":[  
      {  
         "relationship":"Association",
         "source/target":"",
         "type":""
      }
   ],
   "ui":[  
      {  
         "href":"@{stroragePath}",
         "type":"path",
         "value":"overviewa_id"
      },
      {  
         "href":"@{stroragePath}",
         "type":"path",
         "value":"overview_name"
      }
   ]
}



Jaggery App : https://github.com/ireshapm0/ArtifactBuilder/commits/master
Carbon-governance : https://github.com/ireshapm0/carbon-governance/commits/dev-rxt-json

The below screencast shows the basic end to end functionality of the Application when adding a new Artifact Type.



Future Work

  • Multiple Table support for dynamic <content> section. 
  • Minimize user input effort by adding auto-complete data 
  • Generate UI from RXT - Edit RXT UI 
  • Finalize content type fields and their usage


References


[1] http://bootsnipp.com/forms
[2] http://bootsnipp.com/snippets/featured/dynamic-table-row-creation-and-deletion
[3] http://jaggeryjs.org/documentation.jag?api=ws



Use Jaggery WS-Request to call Admin Services of WSO2 Products



During the project I had to call certain admin services's methods of WSO2 G-Reg 5.0.0. using jaggery application. Following are the steps I went through to discover available admin services exposed to outside in Greg. Since this procedure would be the same for any of WSO2 servers ( e.g. WSO2 ESB, GReg, IS, CEP, BPS, ES, AS, BAM, etc.) I will try to make this post as general as possible.


To find out the available Admin services:


1. Open “wso2greg-5.0.0-SNAPSHOT/repository/conf/carbon.xml” file
           For the general case it would be : <server_home>/repository/conf' directory
           and then open carbon.xml

2. Setting HideAdminServises property to 'false', will allow us to view the admin service's wsdl.
       (Not mandatory - If you are not willing to view the wsdl of the service in browser, you        can left out this step)
<HideAdminServiceWSDLs>false</HideAdminServiceWSDLs>
3. Start the server with the OSGIConsole.
./wso2server.sh -DosgiConsole
4.Once the server is started we can view Adin servoces :
                  Press enter & type 'listAdminServices'


osgi > listAdminServices

Part of the list of admin services of GReg 
5. To check the wsdl of the admin service in the browser:
                Add ?wsdl to the url at its end.

HTTP 403 error is thrown if we have not set the hideAdminServiceWSDLs to false.

wsdl of a sample admin service


To use Soap UI to test the services:


Soap creates a Soap Envelope and call the given endpoint. Basically it does the job of a Soap client.


1. Download and install SoapUI at http://www.soapui.org/
                       I.  Go to File > New SOAP Project.
                       II.Paste the wsdl url in the 'initial wsdl' box and click OK.


SoapUI 5.0.0- Add new SOAP Project

2. Click on the Admin Service method from which you want to call from SoapUI and try sending a request.
We have to set Authentication and security related settings to access the admin service.

                      I.   Click on 'Auth' below and click 'Add New Authorization'.
                      II.  Select type Basic and set the username and password. ( Default username                                                            and password for every WSO2 Product would be 'admin').
                      III.Insert the values of the parameters and click the submit request button.



SoapUI 5.0.0 Successful request to an endpoint
If everything went well, we will end up with successful response.
In the response envelope check the return tag to see if the response we are getting is correct.

To call an Admin Service using Jaggery WS-Request:

We don't have to find out available admin services and to use SoapUI to test services if Admin Service endpoint URL and the action that should be called. Basically we can call the same admin service method uisng Jaggery WSRequest.

Jaggery documentation can be found at http://jaggeryjs.org/documentation.jag?api=ws

Jaggery code to call the above Admin service.

<%
var rxt = "JSON RXT Config Should go here";
var log = new Log();
var ws = require('ws');

var addRxt = new ws.WSRequest();
var options = new Array();
options.useSOAP = 1.1;
options.action = "urn:addJSONRXTResource";
var payload = '<ser:addJSONRXTResource xmlns:ser="http://services.generic.governance.carbon.wso2.org"> <ser:jsonRxtConfig>'+rxt+'</ser:jsonRxtConfig> </ser:addJSONRXTResource>';
var result;

try {
    addRxt.open(options, "https://localhost:9443/services/ManageGenericArtifactService", false, "admin", "admin");
    addRxt.send(payload);
    result = addRxt.responseE4X;
} catch (e) {
    log.error(e.toString());
}
   print(result);
%>
Action:Method to be called from the Admin Service
Payload:Actual request payload to be sent to the endpoint.

Specify the name servers correctly when sending the payload. WSRequest's open() will open the connection with the endpoint with necessary authentication and then sends the payload. Result will get the response Soap Message in which it will print in the page itself.