Thursday, September 20, 2012

Create a JDBC mount to WSO2 Governance Registry

The objective of this post is to cover the steps to establish a JDBC mount using the latest WSO2 Governance Registry  and  WSO2 ESB. The registry database is consist with three logical partitions called local, config and governance. When more than one node present in the deployment setup (eg : esb cluster, AM distributed setup ..etc) we have to share the registry spaces (conf and governance) between the servers in deployment (cluster , distributed setup ..etc)to share configurations and artifacts.

 Configure Governance Registry.

1) Create a fresh database for Governance Registry (Here I'm using MySQL database installed in linux).

CREATE USER '<userName>'@'<IP_or_Host_of_MySQL_Server>' IDENTIFIED BY '<password>';

GRANT ALL PRIVILEGES ON *.* TO '<userName>'@'<IP_or_Host_of_MySQL_Server>' WITH GRANT OPTION;

CREATE DATABASE greg_db;
Open  /etc/mysql/my.cnf file and allow the host or IP to connect to MySQL server.
bind-address        = <Host_OR_IP>
2) Go to the GREG_HOME/repository/conf/datasources directory and open the master-datasources.xml file.

3) Update the url, username,password and driverClassName of the data source configuration.

<datasource>
            <name>WSO2_CARBON_DB</name>
            <description>The datasource used for registry and user manager</description>
            <jndiConfig>
                <name>jdbc/WSO2CarbonDB</name>
            </jndiConfig>
            <definition type="RDBMS">
                <configuration>
                    <url>jdbc:mysql://localhost:3306/greg_db</url>
                    <username>root</username>
                    <password>root123</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>
4) Open the axis2.xml and enable clustering. (GREG_HOME/repository/conf/axis2). This is used to send cache invalidation messages across the mounted servers.
<clustering class="org.wso2.carbon.core.clustering.hazelcast.HazelcastClusteringAgent" enable="true"/>
5) Copy the MySQL jdbc driver to GREG_HOME/repository/components/lib directory.
6) Start the Governance Registry server. (This is not necessary for JDBC mounts)
Configure ESB.

1) Open the master-datasources.xml file.
It is under ESB_HOME/repository/conf/datasources and add a new datasource configuration for remote Governance Registry server.
Eg:
<datasource>
            <name>WSO2_CARBON_DB_GREG</name>
            <description>The datasource used for registry and user manager</description>
            <jndiConfig>
                <name>jdbc/WSO2CarbonDB_GREG</name>
            </jndiConfig>
            <definition type="RDBMS">
                <configuration>
                    <url>jdbc:mysql://localhost:3306/greg_db</url>
                    <username>root</username>
                    <password>root123</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> 
2) Open the registry.xml file and add a new dbConfig for remote Governance Registry  server.
<dbConfig name="mounted_registry">
        <dataSource>jdbc/WSO2CarbonDB_GREG</dataSource>
</dbConfig>
3) Add remote Governance Registry instance to  registry.xml.
<remoteInstance url="https://localhost:9443/registry">
        <id>instanceid</id>
        <dbConfig>mounted_registry</dbConfig>
        <readOnly>false</readOnly>
        <enableCache>true</enableCache>
        <registryRoot>/</registryRoot>
        <cacheId>root@jdbc:mysql://localhost:3306/greg_db</cacheId>
</remoteInstance>
4) Add the mount configurations to registry.xml.(This defines the mount configuration to be used with the remote instance and the target    path for the mounts.)
<mount path="/_system/config" overwrite="true">
        <instanceId>instanceid</instanceId>
        <targetPath>/_system/nodes</targetPath>
</mount>
<mount path="/_system/governance" overwrite="true">
        <instanceId>instanceid</instanceId>
        <targetPath>/_system/governance</targetPath>
</mount>
5) Open the axis2.xml and enable clustering.
<clustering class="org.apache.axis2.clustering.tribes.TribesClusteringAgent" enable="true"/>
6) If both servers running on same machine change the port offset to different value of the carbon.xml
<Offset>0</Offset>
7) Copy the MySQL jdbc driver to ESB_HOME/repository/components/lib
8) Start the ESB server.
If the mount was successfully established to remote Governance Registry server,  you should be able to see the following INFO logs in ESB console.
[2012-09-20 19:28:11,159]  INFO - EmbeddedRegistryService Configured Registry in 112ms  
[2012-09-20 19:28:11,251]  INFO - EmbeddedRegistryService Connected to mount at mounted_registry in 4ms  
[2012-09-20 19:28:12,458]  INFO - EmbeddedRegistryService Connected to mount at mounted_registry in 1ms  
[2012-09-20 19:28:12,805]  INFO - RegistryCoreServiceComponent Registry Mode    : READ-WRITE
9) Sign in to the ESB server  using the default username and password (admin/admin) and browse the Registry. Now you should see the config and governance collections are updated with arrow icons.