Monday, May 28, 2012

Lifecycles in WSO2 Governance Registry 4.1.1

Today I thought of taking you all through the lifecycle improvements that we did for WSO2 Governance Registry 4.1.1. We introduced a new lifecycle model with the WSO2 Governance Registry 4.0.0 release. This  model had many improvements when compared with the older versions(like G-Reg 3.6.0 and earlier versions) and had lot of flexibility. A detailed description about this model can be found here. This post focuses more towards the improvements that we did from G-Reg 4.0.0 to G-Reg 4.1.1.

The main improvement we did was to add couple of extension points to the lifecycle model in G-Reg 4.0.0. The lifecycle model in G-Reg 4.0.0 had extension points like "validations" and "permissions" which could be used to customize the behavior of the lifecycle runtime execution. Extension points like "validations" are a good method to run some custom code at a check item click or prior to a transition but our lifecycle model lacked the ability to attach an extension after a transition. So, for that we have introduced the following extension points in G-Reg 4.1.1 release.

  1. Executors
  2. Transition UI
With these new extension points, our lifecycle model has the ability to handle various kinds of validations and executions. In brief, our new lifecycle model allows users to plugin their custom code before and after a state transition. A detailed post about "Executors" can be found in here. I'll be covering the about the  "transition UI" improvements in another post. 

For more details about WSO2 Governance Registry 4.1.1, please go through our documentation which can be found here. Also you can find more details about the lifecycle model in WSO2 Governance Registry using this link.

Wednesday, May 16, 2012

Default Executors in G-Reg


This post applies to G-Reg 4.1.1 and upwards.

As you all know, WSO2 Governance Registry supports adding extensions to the execution logic of a lifecycle.This blog post covers about one particular extension point which is called an executor. This post discuss about the default executors that we have included in the Governance Registry distribution. To get more information about executors, please refer this.

We have 3 default executors in G-Reg. From this post, I'm planning to give an overview about these executors.

  1. Service version executor
  2. Demote action executor
  3. Copy executor

Service Version Executor


The main functionality of this executor is to version services and dependent resources of services(wsdl,schema and policy) when a lifecycle promote action happens. This executor was introduced  to G-Reg with the service version functionality implementation. To get an idea about this executor, we need to have some idea about the service version functionality of G-Reg.

Service Versioning

In G-Reg, we have introduced the ability version services and its dependent resources as an part of lifecycle management of the service. With this improvement, a service in G-Reg are kept in 3 environments when it is governed using the default service lifecycle.
  1. Trunk
  2. Branches/testing
  3. Branches/production
Each of these environments are correspond to a lifecycle state in the default service lifecycle. The default service lifecycle in G-Reg has 3 states.
  1. Development
  2. Testing
  3. Production
The service version functionality happens in the following way.
  1. At creation, the service resource(and its dependent resources) will be placed in "trunk" environment. The path structure of the service resource is like - "trunk/services/{namespace}/{name}". We limit the creation of 2 services with the same name and namespace in this environment. 
  2. All the services in "trunk" environment are on "development" state of the lifecycle.
  3. When a "promote" action happens, a UI is displayed to the user to enter the new versions of the service and its dependent resources(This is done using the "transition UI" functionality of G-Reg which I will be covering in another blog post).
  4. After completing the above action, the service and its dependent resources are moved to "branches/testing"environment. The path structure of a service resource in this environment is like - "branches/testing/{namespace}/{version}/{name}". In this environment, we create a collection with the version that the user has given and because of that, we allow users to keep multiple versions of the same service in this environment.
  5. With the above step, we do some additional processing and update the dependencies with the new paths and also update the version filed in the service to reflect the new version. 
  6. Promotion from "Testing" state to "Production" state is similar to step 3,4 and 5. All the services and the its dependencies are moved from "branches/testing" to "branches/production" environment. 
The service version executor is the one who does steps 4,5 and 6 when a promote transition happens. It is written in a way such that a user can change the environments from the lifecycle configuration. To get some idea about this, we need to look at the configuration of the service version executor.

Here you will notice several "parameter" elements. We focus our attention on 2 of these which are,

  1.  currentEnvironment
  2.  targetEnvironment 
The target environment parameter is the one who decides what is the next environment that the service is placed on. In other words, these 2 parameters say that, take the resource out from "/_system/governance/trunk/{@resourcePath}/{@resourceName}" and place it in "/_system/governance/branches/testing/{@resourcePath}/{@version}/{@resourceName}" path. By changing this configuration, an user has the ability to change the environments based on their requirement.

Also one important fact to note about this executor is that it is media type aware and it works only for services. 

Demote Action Executor


The demote action executor in G-Reg 4.1.1 does not do any copying of the resources to the previous environments. We have identified that the demote action requirement varies from one user to another. The ideal demote action would be to redirect the user to the resource in the previous environment but that is again challenging because there can be multiple versions of the same service in the previous environment. 

Therefore, we have introduced a demote action executor to avoid changing the lifecycle state when the demote action is performed for service in a particular state. In other words, this executor does not do anything apart from keeping the same lifecycle state when the demote action is preformed. 

Copy Executor


The idea behind the copy executor is to do a basic copy of resource from the given location to another. This executor has the ability to work with any media type and it is not media type aware. This executor does a basic copy operation(registry API copy operation) of that resource and it does modify the content or make associations like the service version executor. 

The configuration element of the copy executor is somewhat similar to the service version executor. 
Here you will find 2 parameters called the "currentEnvironment" and "targetEnvironment". These parameters work in the following way. The copy executor will copy any resource that is inside "currentEnvironment"  to the corresponding path in the "targetEnvironment". 

Eg: - Say that you have a resource in the following path.
    "/_system/governance/e1/foo/bar/xyz".
When the user applies a lifecycle (that is configured with the copy executor with the above configuration parameters) to resource "xyz" and do a promote operation, the copy executor will copy that resource to the following path.
"/_system/governance/e2/foo/bar/xyz"




Tuesday, May 15, 2012

Lifecycle extentions in WSO2 G-Reg - Part 1

This post applies to WSO2 Governance Registry 4.1.1 and upwards.

As you all know, WSO2 Governance Registry supports adding extensions to the execution logic of a lifecycle.This blog post covers about one particular extension point which is called an executor.

From this post, I'm planning to cover the following topics.
  1. What is an Executor
  2. How to write a Executor
  3. Add a custom Executor to a lifecycle

What is an Executor

In WSO2 Governance Registry lifecycle model, there are several extension points that one can use to plug there own execution logic. There are several types of pluggable extension points. One of them is called the "executor". An executor is an execution logic that is executed once a state transition happens in a lifecycle.


How to write an Executor

Writing an Executor in G-Reg is very easy. We have an interface called "Execution" in G-Reg which can be found in "org.wso2.carbon.governance.registry.extensions" bundle. This interface has 2 methods.

  • void init(Map parameterMap)
This method is called when the execution class is initialized. All the execution classes are initialized only once.
@param parameterMap Static parameter map given by the user. These are the parameters that have been given in the lifecycle configuration as the parameters of the executor.
Eg:- 
   
The parameters defined here are passed to the executor using this method.

  • boolean execute(RequestContext context,String currentState,String targetState)

This method will be called when the invoke() method of the default lifecycle implementation is called. Execution logic should reside in this method since the default lifecycle implementation will determine

the execution output by looking at the output of this method.


@param context The request context that was generated from the registry core for the invoke() call. The request context contains the resource, resource path and other variables generated during the initial call.
@param currentState The current lifecycle state.
@param targetState The target lifecycle state.
@return Returns whether the execution was successful or not.

To write a custom executor, an user has to implement this interface and add the custom logic inside the execute method. The runtime will execute all the executors that is registered against a particular event an a particular state.


Add a custom Executor to a lifecycle

Adding an Executor to a lifecycle has several steps to follow. 
  1. Compile the class and create a jar file out of it
  2. If the jar file is an OSGI bundle add it to "GREG_HOME/repository/components/dropins" folder and if the jar file is not an OSGI bundle then add it to "GREG_HOME/repository/components/lib" folder. Here what we did is that we added the executor implementation to the classpath of the G-Reg server. 
  3. Add the executor to the lifecycle configuration. Following is a segment of a lifecycle configuration that has an executor. 
There are 3 things that we need to focus our attention on. 
  1. The event that we register the executor - defined by the "forEvent" attribute of the execution element.
  2. The class of the executor - defined by the "class" attribute of the execution element.
  3. Static parameters that is passed to it(optional) - defined by the "parameter" elements of the execution element. 
Using these configurations, an user has the ability to attach their own execution logic to a lifecycle in G-Reg.