Monday, June 16, 2014

Environment Management in WSO2 ESB using WSO2GREG


In ESB, when environment changes( dev-->qa-->prod) , that affects the proxy service configuration. Proxy service configuration includes sequences,endpoints,local entries etc. For different environments, endpoint configuration might change.(ie: the service url which is given as address uri)

Sample endpoint configuration 

<endpoint xmlns="http://ws.apache.org/ns/synapse" name="TestEndpoint">
   <address uri="http://abc.com">
      <suspendOnFailure>
         <progressionFactor>1.0</progressionFactor>
      </suspendOnFailure>
      <markForSuspension>
         <retriesBeforeSuspension>0</retriesBeforeSuspension>
         <retryDelay>0</retryDelay>
      </markForSuspension>
   </address>
</endpoint>

When we develop  ESB/Synapse artifacts, we might not prefer to modify the configuration for different environments. Users just want to deploy the same artifact in all different environments. To make the deployment easy in all environments, we need a running WSO2 Governance Registry instance and we need to mount the config/governance registries of WSO2ESB to different target paths of WSO2 G-Reg. The paths will indicate the different environments.

Eg:
<mount path="/_system/config" overwrite="true">
    <instanceId>config</instanceId>
    <targetPath>/_system/config/environment/production</targetPath>
</mount>

We need to upload the endpoint configuration for different environments( with the correct endpoint url) directly to the registry in the relevant environment paths.

The following sample configurations are related to  one production ESB, one qa ESB and a common G-Reg instance. All three instances will ponit same external DB. eg: mysql


Configurations 

1.  WSO2 G-Reg


master-datasource.xml

Create a new data source to point an external database. Eg: mysql.

 <datasource>
            <name>WSO2_REG_DB</name>
            <description>The datasource used for ESB mount registries</description>
            <jndiConfig>
                <name>jdbc/esbserver_config</name>
            </jndiConfig>
            <definition type="RDBMS">
                <configuration>
                    <url>jdbc:mysql://localhost:3306/esb</url>
                    <username>root</username>
                    <password>root</password>
                    <driverClassName>com.mysql.jdbc.Driver</driverClassName>
                    <maxActive>50</maxActive>
                    <maxWait>60000</maxWait>
                    <testOnBorrow>true</testOnBorrow>
                    <validationQuery>SELECT 1</validationQuery>
                    <validationInterval>30000</validationInterval>
                </configuration>
            </definition>
        </datasource>

registry.xml

Use the created above datasource in the registry.xml

<!-- This defines the default database and its configuration of the registry -->

    <dbConfig name="wso2registry">
        <dataSource>jdbc/esbserver_config</dataSource>
    </dbConfig>

Copy the mysql jdbc driver in repository/components/lib folder and start the server. Make sure to create tables in the mysql database. You can find the relevant sql scripts in the CARBON_HOME\dbscripts folder.

We need to set different port offsets to all carbon servers in carbon.xml. For G-Reg, let’s keep the default value (ie: ‘0’)

2 WSO2ESB-QA

master-datasource.xml
Create a new data source to point the mysql database which is already created.


 <datasource>
            <name>WSO2_REG_DB</name>
            <description>The datasource used for ESB mount registries</description>
            <jndiConfig>
                <name>jdbc/esbserver_config</name>
            </jndiConfig>
            <definition type="RDBMS">
                <configuration>
                    <url>jdbc:mysql://localhost:3306/esb</url>
                    <username>root</username>
                    <password>root</password>
                    <driverClassName>com.mysql.jdbc.Driver</driverClassName>
                    <maxActive>50</maxActive>
                    <maxWait>60000</maxWait>
                    <testOnBorrow>true</testOnBorrow>
                    <validationQuery>SELECT 1</validationQuery>
                    <validationInterval>30000</validationInterval>
                </configuration>
            </definition>
        </datasource>

registry.xml

We need to mount the config registry to different target path to make sure QA ESB server talks to different config registry. Governance registry space of all nodes will be mounted to same location, since governance space is common for all nodes.

  <dbConfig name="config">
       <dataSource>jdbc/esbserver_config</dataSource>
    </dbConfig>
      <remoteInstance url="https://localhost:9443/registry">
        <id>config</id>
        <dbConfig>config</dbConfig>
        <readOnly>false</readOnly>
        <registryRoot>/</registryRoot>
        <enableCache>true</enableCache>
    </remoteInstance>
     <mount path="/_system/config" overwrite="true">
        <instanceId>config</instanceId>
        <targetPath>/_system/config/env/qa</targetPath>
    </mount>

     <dbConfig name="governance">
       <dataSource>jdbc/esbserver_config</dataSource>
    </dbConfig>
      <remoteInstance url="https://localhost:9443/registry">
        <id>governance</id>
        <dbConfig>governance</dbConfig>
        <readOnly>false</readOnly>
        <registryRoot>/</registryRoot>
        <enableCache>true</enableCache>
    </remoteInstance>
     <mount path="/_system/governance" overwrite="true">
        <instanceId>governance</instanceId>
        <targetPath>/_system/governance</targetPath>
    </mount>


Copy the mysql jdbc driver in repository/components/lib folder. Set different port offset in carbon.xml. For ESB_QA server, let’s keep it as ‘1’. Start the server.
Go to https://localhost:9444/carbon/ URL and check the registry browser, you will see the registries are mounted.

3 WSO2ESB-PROD

master-datasource.xml
Create a new data source to point the mysql database which is already created.

 <datasource>
            <name>WSO2_REG_DB</name>
            <description>The datasource used for ESB mount registries</description>
            <jndiConfig>
                <name>jdbc/esbserver_config</name>
            </jndiConfig>
            <definition type="RDBMS">
                <configuration>
                    <url>jdbc:mysql://localhost:3306/esb</url>
                    <username>root</username>
                    <password>root</password>
                    <driverClassName>com.mysql.jdbc.Driver</driverClassName>
                    <maxActive>50</maxActive>
                    <maxWait>60000</maxWait>
                    <testOnBorrow>true</testOnBorrow>
                    <validationQuery>SELECT 1</validationQuery>
                    <validationInterval>30000</validationInterval>
                </configuration>
            </definition>
        </datasource>


registry.xml
We need to mount the config registry to different target path to make sure PROD_
ESB server talks to different config registry. Governance registry of all nodes will be mounted to same location, since governance space is common for all nodes.


<dbConfig name="config">
       <dataSource>jdbc/esbserver_config</dataSource>
    </dbConfig>
      <remoteInstance url="https://localhost:9443/registry">
        <id>config</id>
        <dbConfig>config</dbConfig>
        <readOnly>false</readOnly>
        <registryRoot>/</registryRoot>
        <enableCache>true</enableCache>
    </remoteInstance>
     <mount path="/_system/config" overwrite="true">
        <instanceId>config</instanceId>
        <targetPath>/_system/config/env/prod</targetPath>
    </mount>

     <dbConfig name="governance">
       <dataSource>jdbc/esbserver_config</dataSource>
    </dbConfig>
      <remoteInstance url="https://localhost:9443/registry">
        <id>governance</id>
        <dbConfig>governance</dbConfig>
        <readOnly>false</readOnly>
        <registryRoot>/</registryRoot>
        <enableCache>true</enableCache>
    </remoteInstance>
     <mount path="/_system/governance" overwrite="true">
        <instanceId>governance</instanceId>
        <targetPath>/_system/governance</targetPath>
    </mount>


Copy the mysql jdbc driver in repository/components/lib folder. Set different port offset in carbon.xml. For ESB_PROD server, let’s keep it as ‘2’. Start the server.
Go to https://localhost:9445/carbon/ URL and check the registry browser, you will see the registries are mounted. 

4. Endpoint configuration

We need to directly upload the endpoint configuration to the registry.Go to G-reg management console and upload the endpoint configurations(xml file) for the QA and Production environment under relevant target paths.
Eg: Upload the testEndpoint.xml of the qa environment to /_system/config/env/qa path. Upload the
testEndpoint.xml of the production environment to /_system/config/env/prod path.

Sample endpoint conf for QA-ESB server


<endpoint xmlns="http://ws.apache.org/ns/synapse" name="TestEndpoint">
   <address uri="http://<QA SERVICE ENDPOINT URL>">
      <suspendOnFailure>
         <progressionFactor>1.0</progressionFactor>
      </suspendOnFailure>
      <markForSuspension>
         <retriesBeforeSuspension>0</retriesBeforeSuspension>
         <retryDelay>0</retryDelay>
      </markForSuspension>
   </address>
</endpoint>


Sample endpoint conf for PROD-ESB server


<endpoint xmlns="http://ws.apache.org/ns/synapse" name="TestEndpoint">
   <address uri="http://<PROD SERVICE ENDPOINT URL>">
      <suspendOnFailure>
         <progressionFactor>1.0</progressionFactor>
      </suspendOnFailure>
      <markForSuspension>
         <retriesBeforeSuspension>0</retriesBeforeSuspension>
         <retryDelay>0</retryDelay>
      </markForSuspension>
   </address>
</endpoint>


5. Proxy Configuration

When we create proxy configuration we should not directly provide any of the address url. Rather we need to point the registry key. This registry key will be same for all environments. That means we do not need to modify the proxy configuration when we deploy that to qa or production environment.
Eg:  < endpoint="conf:/testEndpoint">

Sample proxy configuration

<proxy xmlns="http://ws.apache.org/ns/synapse"
       name="testEnvProxy"
       transports="https,http"
       statistics="disable"
       trace="disable"
       startOnLoad="true">
   <target endpoint="conf:/testEndpoint"/>
   <description/>
</proxy>

Related post
Environment Management in WSO2 DSS using WSO2GREG

2 comments:

  1. I would like to implement conditional router in wso2 but all im getting is "Target could not find sequence". Here is my proxy.xml file
























    . Kindly help me on this.

    ReplyDelete
  2. You can raise your question in stackoverflow.

    ReplyDelete