Finally I thought of writing some technical stuff about WOS2 and its products. Currently I'm working in the WSO2 Governance Registry and this blog explains about the new lifeCycle configuration of WSO2 Governance Registry 4.0.0.
LifeCycles are a powerful concept when it comes to in the context of governance of different artifacts. The WOS2 Governance Registry (we'll call it G-Reg from this point onward) have the capability of associating lifeCycles for artifacts that are stored in the repository. The power of G-Reg's lifeCycles model is that the user has the ability to define his/her own lifeCycle. Users can do this using the configuration model we provide with G-Reg. The idea of this post is to describe about the new lifeCycle configuration model of G-Reg and what are the improvements that we have done to the configuration model itself.
Little detail about the configuration
First of all let me explain a bit about the current lifeCycle configuration. The new G-Reg lifeCycle configuration model is developed around the W3C specification of state chart XML or in other words SCXML[1]. The SCXML specification is a very powerful specification and we have used this mainly because of two reasons.
- SCXML is a stranded state machine language that has been adopted by the W3C
- The SCXML model is very extensible and therefore we can use our custom definitions without violating the specification
We have used this extensibility to our advantage and came up with a configuration model that has many capabilities. In the previous version of G-Reg(prior to G-Reg 4.0.0) we have used a simple lifeCycle configuration model. Even though the users had the ability to extend that lifeCycle configuration, it was somewhat a difficult talk. So what we did in this latest release was that, we took all of that hard work away from the user and made it part of the default implementation. First we'll look at the new configuration model and then let us see what a user can actually do with it.
Configuration Model
The new lifeCycle configuration model of G-Reg is given bellow. First let me explain a bit about the configuration model and later(most probably it will be another post) I will explain how a user can write their own configuration using this.
If you look at the new model carefully, you can see that it has some similarities to the previous configuration model as well. One such similarity is that we still use the same three elements to define this configuration as a lifeCycle. The elements "aspect","configuration" and "lifecycle" behave the same way as in previous lifeCycles configurations. The part that we need to concentrate is the element that has the name "scxml". This is the element that is defined according to to SCXML specification.
Let me explain the configuration element by element in detail.
This element defines the aspect and note that G-Reg have defined lifeCycles as aspects too. There are two attributes in this, "name" and "class". "name" attribute contains the name of the lifeCycle and the name has to be a unique one. Note that G-Reg does not allow creating two lifeCycles with the same name. The "class" attribute defines the class that is associated with the lifeCycle.
The "org.wso2.carbon.governance.registry.extensions.aspects.DefaultLifeCycle" is the default class that handles the new lifeCycle configuration and its specified operations. A user has the ability to define his/her own class(more information about this can be found using [2]) but the default class provided with the G-Reg distribution have the capability to handle any configuration that follows the above given template.
<configuration type="">
This element defines whether the type of this configuration is "literal" or "resource". This is same as in previous G-Reg versions where, if you give the configuration through the registry.xml, then the value should be "resource" and if it is given through the management console, the value should be "literal".
<scxml xmlns="http://www.w3.org/2005/07/scxml" version="1.0"
initialstate="">
This is the element that contains the SCXML based new configuration. The important fact about this element is that it defines the initial state of the lifeCycle. With SCXML the users have the ability to define an initial state and the initial state does not have to be the first state of the configuration. Also by changing the value of this attribute, a user can quickly modify the initial state and the flow of the lifeCycle. This is a huge leap forward from the previous configuration models.
Up to this point of the configuration, there can be only one element of each of the above described elements. The above mentioned elements are used to provide meta data about the lifeCycle(such as its name,class and other things) and the elements that are described below contains the actual configuration.
<state id="">
"State" elements defines the states of the lifeCycle. A lifeCycle can have multiple states and in the configuration, more than one state element can be given. The "id" attribute of the "state" element defines the name of that state. Note that G-Reg does not support multiple states with the same name and therefore all the state names of a lifeCycle should be unique.<datamodel>
This element contains all the custom elements that we have defined in G-Reg's new lifeCycles model. The SCXML specification allows users to define a data model to a state and we have used that extension to define our custom elements. We have defined few custom "data" elements(according to the SCXML specification) to define check items, transition permission, transition validations and transition scripts.<data name="checkItems/transitionValidations/transitoinPermission/transitionScripts">
This element defines about the data of its child elements. Note that a user can only define one such element of each kind since the underline implementation will ignore multiple elements and take only one into consideration. The attribute "name" defines about the data that this element contains. The "name" attribute should be set to "checkItems" if the user is defining check items as its child elements. Likewise the name should be set to "transitionValidations" if the data element defines transition validations and "transitionPermission" if the data element defines transition permissions and "transitionScripts" if the data element defines about the transition scripts. So I recommend not to modify this element.<item name="" forEvent="">
These elements contains the check items for each state. There can be more than one such element and the attribute "name" defines the name of the check item. G-Reg 4.0.0 allows you to define check items that are required for each transition. The "forEvent" attribute defines whether this check item is required for an specific transition. A check item can be required for more than one event and in such a scenario a user can give a comma(",") separated list for the "forEvent"attribute. Keeping the "forEvent" attribute empty means, that specific check item is not required for any transition event.<permissions>
The "permissions" element defines permissions for that specified action. A permission element can hold more than one child element which defines permissions. Under check items, the "permissions" element defines the users that have the capability of checking(check/uncheck) that check item. If a user does not have permissions to check an check item, then the management console will display that specific item in disabled mode. The idea behind that was to let the user know that there are some more check items in that state but he does not have permission to check them and to avoid user confusion.<permission roles=""/>
This element comes as a child element of the "permissions" element and will define the roles that have permission to do the specified action. Here the attribute "roles" accepts a comma(",") separated list and these roles should be present in G-Reg.<validations>
The "validations" element defines the validations that needs to be done for each action. This element can contain one or more "validation" elements(which is described next).<validation forEvent="" class="">
Validations are an important part of lifeCycles. The "validation" element defines the event and the validation class that has to be invoked at runtime. The attribute "forEvent" defines the event that this validation should be performed. This gives user the flexibility to define validations for each event. The user has the ability to define validations for check items, which makes it easy to validate different things at different levels.
The attribute "class" defines the class that needs to be executed at runtime to perform the validation. A user must give the full qualified name of a class that implements the "customValidations" interface, as the value of the attribute "class".<parameter name="" value=""/>
The parameter elements are used to give parameters to the validations classes. It is up to the user to define the name value pairs and the parameter element has attributes to define these values. A validations element can have more than one parameter element and it is up to the user code to handle them. The underline implementation of the "DefaultLifeCycle" class will pass all the parameters in a map object.<js forEvent="">
G-Reg lifeCycle configuration has the ability to give JavaScript functions to execute at both the server side and the client side. The "js" element defines the scripts that needs to be executed to different events. The "forEvent" attribute defines the transition action where this JavaScript function needs to be executed.<console function="">
The "console" element is there to define the JavaScript function that needs to be executed at the client side. The "function" attribute defines the name of the function and this function will be executed at a transition of one state to another.<script type="text/javascript">
This element contains the actual JavaScript code segment. A user has the ability to define any code segment here. The "type" attribute is set to "text/javascript" because at this moment G-Reg only support JavaScript as a scripting language.<server function="">
This is as same as the "console" function and the only difference is that this element defines the scripts that needs to be executed at the server side. This element also has a "function" attribute that defines the function name.Now I have explained all of the custom elements that we have defined in the new lifeCycle configuration of G-Reg. There is one element that I need to focus your attention on.
<transition event="" target=""/>
This element defines the transitions of a state. One improvement that we have done with this new lifeCycle configuration model is of allowing the user to define the transitions(the name and the target state) instead of using static transitions.
For all of you that have experience in lifeCycle configurations of previous G-Reg releases, you may recall that the configuration did not have a direct method of defining the transition event names and most importantly the target of the transition. Also you may recall that there were only two transitions that we supported by default. With the new SCXML based configuration model, we support any number of transitions from one state. Also this model has the capability of defining the target state of the transition and the name of the event as well. The attribute "event" is used to define the transition event name(eg: "Promote" or "Demote" or any name that the user specifies) and the attribute "target" is used to define the target state of the transition.That concludes the explanation of the new lifeCycle configuration model of G-Reg 4.0.0 and as you all can see, the new lifeCycle configuration model support many things by default. I hope that this guide was helpful to all of you to understand about the lifeCycle configuration and to write one of your own. If you have any inputs, questions, feel free to drop a comment because I will gladly accept them all.
Folks, Note that I'm planning to write another post explaining the default service lifeCycle of G-Reg 4.0.0 and how we are managing service resources using it.
References
Is it a good practice to put custom "data" elements in a different name space?
ReplyDelete