||
Skip to end of metadata
Go to start of metadata

Clustering is an important feature in WSO2 products, which provides high-availability and high-scalability. By default, WSO2 products provide a clustering implementation that is based on the Hazelcast Community Edition. You can plug your own clustering implementation to the product by using the ClusteringAgent extension point in WSO2 Carbon.

Writing your own clustering implementation

WSO2 Carbon uses a modified version of the interface for Clustering Agent that is provided by Axis2. You can find the WSO2 version here. You can have your own clustering implementation by using this interface and overriding the relevant methods. 

 Following is the list of methods in this interface that you can override to have your own clustering implementation:

METHODDESCRIPTION

void init()

Should contain the implementation logic for Initializing the node and joining the cluster.

List<ClusteringCommand> sendMesssge(ClusteringMessage message, boolean isRpcMessage)

Should contain the implementation logic for sending a message to all members in this member's primary cluster.

void setMembers(List<Member> members)

Should set the static members of the cluster.

void addGroupManagementAgent(GroupManagementAgent agent, String applicationDomain)

Should contain the implementation logic for adding a GroupManagementAgent for an application domain.

void addGroupManagementAgent(GroupManagementAgent agent, String applicationDomain,String applicationSubDomain, int groupMgtPort)

Should contain the implementation logic for adding a GroupManagementAgent for an application domain and sub domain.

void resetGroupManagementAgent(String applicationDomain, String applicationSubDomain)

Should contain the implementation logic for resetting the GroupManagementAgent corresponding to an application domain and a sub domain and for clearing all the members of the corresponding GroupManagementAgent.

GroupManagementAgent getGroupManagementAgent(String applicationDomain)

Should contain the implementation logic for getting the GroupManagementAgent, which corresponds to the applicationDomain. This will be valid only when this node is running in groupManagement.

GroupManagementAgent getGroupManagementAgent(String applicationDomain, String applicationSubDomain)

Should contain the implementation logic for getting the GroupManagementAgent, which corresponds to the applicationDomain and sub domain.

void shutdown()

Should contain the implementation logic for disconnecting this node from the cluster. This node will no longer receive membership change notifications, state change messages or configuration change messages. The node will be standing alone once it shuts down. However, it has to continue to process Web service requests.

List<Member> getMembers()

Should contain the implementation logic for getting the list of members in a static group.

void stop()

Should contain the implementation logic for cleaning up and leaving the cluster.

void setStateManager(StateManager stateManager)

Should contain the implementation logic for setting the StateManager corresponding to this ClusteringAgent. This is an optional attribute.
We can have a cluster with no context replication, in which case the contextManager will be null. This value is set by the org.apache.axis2.deployment.ClusterBuilder, by reading the  "contextManager" element in the axis2.xml.

NodeManager getNodeManager()

Should return the NodeManager.

void setNodeManager(NodeManager nodeManager)

Should contain the implementation logic for setting the NodeManager corresponding to this ClusteringAgent. This is an optional attribute. We can have a cluster with no configuration management, in which case the configurationManager will be null. This value is set by the org.apache.axis2.deployment.ClusterBuilder, by reading the  "configurationManager" element in the axis2.xml

void setConfigurationContext(ConfigurationContext configurationContext)

Should set the system's configuration context. This will be used by the clustering implementation to get information about the Axis2 environment and to correspond with the Axis2 environment.

int getAliveMemberCount()

Should set the number of members alive.

Set<String> getDomains()

Should get all the domains to which the ClusteringAgent belongs.

boolean isCoordinator();

Should check whether this member is the coordinator for the cluster.

Your custom clustering agent should be packaged in an OSGI bundle and added to the <PRODUCT_HOME>/repository/components/dropins directory. In order for it to be used instead of the default clustering agent, you need to replace the default with your custom implementation in the <PRODUCT_HOME>/repository/conf/axis2/axis2.xml file. Following are the default configurations in the axis2.xml file. You need to replace the “class” attribute in the “clustering” element with your custom class and other elements and attribute values as required.

<!--To enable clustering for this node, set the value of "enable" attribute of the "clustering" element to "true". The initialization of a node in the cluster is handled by the class corresponding to the "class" attribute of the "clustering" element. It is also responsible for getting this node to join the cluster.-->
<clustering class="org.wso2.carbon.core.clustering.hazelcast.HazelcastClusteringAgent"
                enable="false">
 
        <!--This parameter indicates whether the cluster has to be automatically initalized when the AxisConfiguration is built. If set to "true" the initialization will not be done at that stage, and some other party will have to explictly initialize the cluster.-->
        <parameter name="AvoidInitiation">true</parameter>
        <!--The list of static or well-known members. These entries will only be valid if the "membershipScheme" above is set to "wka"-->
        <members>
            <member>
                <hostName>127.0.0.1</hostName>
                <port>4000</port>
            </member>
        </members>
         <!--Enable the groupManagement entry if you need to run this node as a cluster manager. Multiple application domains with different GroupManagementAgent implementations can be defined in this section.-->
        <groupManagement enable="false">
            <applicationDomain name="wso2.esb.domain"
                               description="ESB group"
       agent="org.wso2.carbon.core.clustering.hazelcast.HazelcastGroupManagementAgent"
                               subDomain="worker"
                               port="2222"/>
        </groupManagement>
</clustering>

When you restart the server after doing the required changes in the axis2.xml file, your custom Clustering Agent will be picked up and used.

  • No labels