Thursday, January 16, 2014

Clustering WSO2 Products with Registry Mounting

In this blog post I'm going to explain how to set up a cluster of WSO2 products using registry mounting. This setup method is applicable to products built using 4.2.0 kernel.

Here I will use WSO2 DSS as the product and WSO2 GREG for registry mounting.

This is what we are going to do!

GREG will be our central repository which uses MySQL as the database. The two DSS servers will use the same repository for their shared resources.

Now it is time to configure these products.

1. Download DSS 3.1.1 from here
2. Download GREG 4.6.0 from here
3. Create a database in MySQL and assign user priviledges with the following commands.

mysql>create database regdb;
mysql>use regdb;
mysql>grant all on regdb.* TO regadmin@localhost identified by "regadmin";

4. Extract the GREG 4.6.0 zip file and change the configured datasource in $GREG_HOME/repository/conf/datasources/master-datasources.xml file in order to tell GREG to run on top of the MySQL datasource instead of default H2 datasource

For that replace 

        <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:h2:repository/database/WSO2CARBON_DB;DB_CLOSE_ON_EXIT=FALSE;LOCK_TIMEOUT=60000</url>
                    <username>wso2carbon</username>
                    <password>wso2carbon</password>
                    <driverClassName>org.h2.Driver</driverClassName>
                    <maxActive>50</maxActive>
                    <maxWait>60000</maxWait>
                    <testOnBorrow>true</testOnBorrow>
                    <validationQuery>SELECT 1</validationQuery>
                    <validationInterval>30000</validationInterval>
                </configuration>
            </definition>
        </datasource>

with the following content

        <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/regdb</url>
                    <username>regadmin</username>
                    <password>regadmin</password>
                    <driverClassName>com.mysql.jdbc.Driver</driverClassName>
                    <maxActive>80</maxActive>
                    <maxWait>60000</maxWait>
                    <minIdle>5</minIdle>
                    <testOnBorrow>true</testOnBorrow>
                    <validationQuery>SELECT 1</validationQuery>
                    <validationInterval>30000</validationInterval>
                </configuration>
            </definition>
        </datasource>

5. Download the MySQL JDBC driver connector JAR from here and place it in the $GREG_HOME/repository/components/lib directory.

6. Start the GREG server with the following command

For Linux : wso2server.sh -Dsetup
For Windows : wso2server.bat -Dsetup

This will start GREG on MySQL  and setup the regdb database. The work by GREG is done now.

7. We have to configure DSS products as well. As we are having two DSS instance we have to make two copies.

8. As we are running two WSO2 product instances in the same machine, we have to change running ports for each products. We can change the port by changing the following value in $DSS_HOME/repository/conf/carbon.xml

<Offset>1</Offset>

Then it will run on HTTP port 9764 and HTTPS port 9444.


9. Put the following content to the $DSS_HOME/repository/conf/registry.xml for registry mounting in both DSS instances

<dbConfig name="mysql-reg">
     <url>jdbc:mysql://localhost:3306/regdb</url>
     <userName>regadmin</userName>
     <password>regadmin</password>
     <driverName>com.mysql.jdbc.Driver</driverName>
     <maxActive>5</maxActive>
     <maxWait>60000</maxWait>
     <minIdle>50</minIdle>
     <validationQuery>SELECT 1</validationQuery>
</dbConfig>

<remoteInstance url="https://localhost:9443/registry">
     <id>conf-gov-registry</id>
     <dbConfig>mysql-reg</dbConfig>
     <readOnly>false</readOnly>
     <enableCache>true</enableCache>
     <registryRoot>/</registryRoot>
</remoteInstance>

<!-- Governance data will be stored in /_system/governance collection of central registry instance -->
     <mount overwrite="true" path="/_system/governance">
     <instanceId>conf-gov-registry</instanceId>
     <targetPath>/_system/governance</targetPath>
</mount>

<!-- Configuration data will be stored in /_system/dssnodes collection of central registry instance --> 
     <mount overwrite="true" path="/_system/config">
     <instanceId>conf-gov-registry</instanceId>
     <targetPath>/_system/esbnodes</targetPath>
</mount>

10. Drop the MySQL driver into $DSS_HOME/repository/components/lib directory which is downloaded in the step5

11. By Default the All WSO2 products starts with STANDALONE mode. We have to tell the DSS product to start in CLUSTERED mode. We can enable it by the setting the following property in $DSS_HOME/repository/conf/axis2/axis2.xml to true

<clustering class="org.wso2.carbon.core.clustering.hazelcast.HazelcastClusteringAgent"
                enable="true">

12. We have to tell the cluster how many servers are running explicitly.This can be configured in the $DSS_HOME/repository/conf/etc/tasks-config.xml

<taskServerCount>2</taskServerCount>

With this configuration the server starts first will be waiting for others. (ie. It knows that there are two servers in the cluster and have to wait for the other one.)

12. Now, we are done with the configurations. You can test the clustering and registry mounting through task scheduling. More info available in docs. Once we schedule a task from one DSS instance, that particular task is shared with the other instance as well.








Wednesday, January 8, 2014

Maven 2 Building error : How to sort it out

Today I tried to build a source using Maven 2. In the pom.xml file it is building build.xml file using ant. Then I got the following error.

An Ant BuildException has occured

Perhaps JAVA_HOME does not point to the JDK. It is currently set to /media/chanika/apps/java/java_1.6/jdk1.6.0_45/jre

So the first thing came to my mind is that the path for java JDK is set to as a wrong one. But when I checked the path it has been set correctly.

So I googled a liitle bit and found out this is because of that Maven2 starts the antrun plugin with the JRE not the JDK.

This can be overcome by doing one of the followings.

1. By editing your pom.xml file in order to add tools.jar dependency.

      <profile>
          <id>tools.jar</id>
          <activation>
              <property>
                  <name>java.vendor</name>
                  <value>Sun Microsystems Inc.</value>
              </property>
          </activation>
          <build>
            <plugins>
            <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-antrun-plugin</artifactId>
              <dependencies>
                <dependency>
                  <groupId>com.sun</groupId>
                  <artifactId>tools</artifactId>
                  <version>1.5.0</version>
                  <scope>system</scope>
                  <systemPath>${java.home}/../lib/tools.jar</systemPath>
                </dependency>
              </dependencies>
            </plugin>
            </plugins>
          </build>
      </profile>

2. Or else you can add the following property to your build.xml file

<property name="build.compiler" value="extJavac"/>