Install WSO2 API Manager Analytics features into DAS 3.1.0 Minimum HA Cluster
Hi readers,
Today I’m going to write this story on how to use WSO2 Data Analytics Server to have a High Availability Environment (Cluster) and set it up as API Manager Analytics by installing features on it. So this article will contains few sections for you to follow.
When surfing through internet, you could find most of the articles on Analytics using Mysql, so I’m going to use Oracle as the DBMS to write this story.
1. Let’s create a DAS cluster,
So the first section is all about how to create a Data Analytics HA Cluster. Following are the steps,
1. First download Data Analytics Server 3.1.0 from here and extracted in both instances.
2. Then logged into oracle server and create users for following datasources. If you can browse through the downloaded DAS distribution, these datasources can be found in [DAS_HOME]/repository/conf/datasources directory.
- WSO2CarbonDB (create user as ‘carbondb’)
- WSO2REG_DB (create user as ‘regdb’)
- WSO2UM_DB (create user as ‘userdb’)
- WSO2_ANALYTICS_EVENT_STORE_DB (create user as ‘eventstoredb’)
- WSO2_ANALYTICS_PROCESSED_DATA_STORE_DB (create user as ‘prosdatadb’)
- WSO2_METRICS_DB (create user as ‘metricsdb’)
3. You need to add following User management datasource in <DAS_HOME>/repository/conf/datasources/master-datasources.xml. By default ‘WSO2CarbonDB’ will act as both User and Registry database but when doing the clustering we’re having separate datasource for each.
<datasource>
<name>WSO2UM_DB</name>
<description>The datasource used for user manager</description>
<jndiConfig>
<name>jdbc/WSO2UM_DB</name>
</jndiConfig>
<definition type="RDBMS">
<configuration>
<url>jdbc:oracle:thin:@localhost:1521/oracledb</url>
<username>userdb</username>
<password>userdb</password> <driverClassName>oracle.jdbc.driver.OracleDriver</driverClassName>
<maxActive>50</maxActive>
<maxWait>60000</maxWait>
<testOnBorrow>true</testOnBorrow>
<validationQuery>SELECT 1 FROM DUAL</validationQuery>
<defaultAutoCommit>false</defaultAutoCommit>
<validationInterval>30000</validationInterval>
</configuration>
</definition>
</datasource>
Note- oracledb is the database SID where the users were created.
4. Also add registry datasource in <DAS_HOME>/repository/conf/datasources/master-datasources.xml
<datasource>
<name>WSO2REG_DB</name>
<description>The datasource used by the registry</description>
<jndiConfig>
<name>jdbc/WSO2REG_DB</name>
</jndiConfig>
<definition type="RDBMS">
<configuration>
<url>jdbc:oracle:thin:@localhost:1521/oracledb</url>
<username>regdb</username>
<password>regdb</password>
<driverClassName>oracle.jdbc.driver.OracleDriver</driverClassName>
<maxActive>50</maxActive>
<maxWait>60000</maxWait>
<testOnBorrow>true</testOnBorrow>
<validationQuery>SELECT 1 FROM DUAL</validationQuery>
<defaultAutoCommit>false</defaultAutoCommit>
<validationInterval>30000</validationInterval>
</configuration>
</definition>
</datasource>
Change other datasources according to the created database users by changing url, username, password, driverClassName as above.
5. Open the <DAS_HOME>/repository/conf/user-mgt.xml file and modify the dataSource property of the <configuration> element as follows. This will make the created datasource in 3rd step to use as User Database.
<configuration>
…
<Property name="dataSource">jdbc/WSO2UM_DB</Property>
</configuration>
6. Add the dataSource attribute of the <dbConfig name=”govregistry”> in <DAS_HOME>/repository/conf/registry.xml file in order to do registry mounting. Make sure to keep the ‘wso2registry’ db config as it is.
<dbConfig name="govregistry">
<dataSource>jdbc/WSO2REG_DB</dataSource>
</dbConfig>
<remoteInstance url="https://localhost:9443/registry">
<id>gov</id>
<cacheId>regdb@jdbc:oracle:thin:@localhost:1521/oracledb</cacheId>
<dbConfig>govregistry</dbConfig>
<readOnly>false</readOnly>
<enableCache>true</enableCache>
<registryRoot>/</registryRoot>
</remoteInstance>
<mount path="/_system/governance" overwrite="true">
<instanceId>gov</instanceId>
<targetPath>/_system/governance</targetPath>
</mount>
<mount path="/_system/config" overwrite="true">
<instanceId>gov</instanceId>
<targetPath>/_system/config</targetPath>
</mount>
In <cacheId>, ‘regdb’ is the username of the WSO2REG_DB.
7. Now we’re going to enable Hazelcast clustering for DAS nodes. Set following properties in <DAS_HOME>/repository/conf/axis2/axis2.xml file.
a) Enable clustering by setting value as ‘true’ for clustering class=”org.wso2.carbon.core.clustering.hazelcast.HazelcastClusteringAgent” as below,
<clustering class="org.wso2.carbon.core.clustering.hazelcast.HazelcastClusteringAgent" enable="true">
b) Enable well known address by changing the membershipScheme to ‘wka’
<parameter name="membershipScheme">wka</parameter>
c) Add respective server IP address as the value for the localMemberHost property for each node. If the analytics nodes are in the same node, you can keep the same ip here.
<parameter name="localMemberHost">10.100.1.89</parameter>
d) Change the localMemberPort accordingly. Both nodes should have different unique ports unless they are in different instances.
<parameter name="localMemberPort">4000</parameter>
e) Add both the DAS nodes as well known addresses in the cluster by specifying under the <members> tag in each node as shown below.
<members>
<member>
<hostName>10.100.1.89</hostName>
<port>4000</port>
</member>
<member>
<hostName>10.100.1.90</hostName>
<port>4000</port>
</member>
</members>
Note — Make sure to have different ports for both nodes as per ‘localMemberPort’ and include under <members> tag in each node if you have both nodes in same machine.
8. Enable HA mode in <DAS_HOME>/repository/conf/event-processor.xml in order to Cluster CEP in both nodes.
<mode name="HA" enable="true">
9. Enter the respective server IP address under the HA mode Config for <hostname> in <eventSync> and <management> sections as below,
<eventSync>
<hostName>10.100.1.89</hostName>
..
</eventSync> <management>
<hostName>10.100.1.89</hostName>
..
</management>
10. Modify <DAS_HOME>/repository/conf/analytics/spark/spark-defaults.conf as follows,
a) Keep carbon.spark.master as ’local’. This creates a spark cluster with Hazelcast cluster.
b) Set ‘carbon.spark.master.count’ as 2 since both node works as master (active and passive)
carbon.spark.master local
carbon.spark.master.count 2
11. If the path to <DAS_HOME> is different in the two nodes, please do the following (ex- if 1st node’s DAS directory is /ubuntu/user1/wso2das-3.1.0 and 2nd node’s directory is /ubuntu/user2/wso2das-3.1.0). If it is same you can skip this step.
Create identical symbolic links to <DAS_HOME> in both nodes and ensure that we can use a common path. Uncomment and change carbon.das.symbolic.link accordingly by setting the symlink path.
carbon.das.symbolic.link /home/ubuntu/das/das_symlink/
12. As the last step download the Oracle database JDBC driver and copy it to <DAS_HOME>/repository/components/lib in both nodes
Make sure to apply changes accordingly in both nodes and change ip address and ports (ex- localmemberport, port offset in carbon.xml if both are in same machine, etc).
13. Start at least one server with -Dsetup since we need to populate tables for the created databases and other node with/without -Dsetup . Go to <DAS_HOME>/bin and run
sh wso2server.sh -Dsetup
Now we have a functional DAS minimum HA cluster. So we need to turn this into an API manger Analytics Cluster (Not using Magic, I promise).
Steps to install APIM Analytics features
WSO2 products are compatible to install features from other products from same carbon version. For this there’s a repository called ‘P2’ which contains all the features which you can use. Let’s install features,
- Let’s got to Features section in DAS management console after starting the server.
Management console -> Main -> Configure -> Features
2. Click Repository Management and go to Add Repository.
3. Give a name and browse or add url to add the repository.
Note — You can get the p2 repo from here
Name — Any preferred name (ex — p2 repo)
Location (from URL) — http://product-dist.wso2.com/p2/carbon/releases/wilkes
4. Go to ‘Available Features’ tab, untick ‘Group features by category’ and click ‘Find Features’
5. Following features needed to be installed from listed set of features.
Tick the above features and click install and features will be installed.
Note — Make sure to do the same for both nodes.
Steps to Configure Statistic Datasource
Now we have an APIM Analytics Cluster. Congratulations 🔥🔥.
So how we’re going to use this to process API Manager events ?
After installing features into DAS cluster, there will be a datasource file created inside <DAS_HOME>/repository/conf/datasources as stats-datasources.xml. What we need to do is create a statistics database in oracle and point that in this datasource file since we have followed other required steps when doing the clustering. So these are the steps.
1. Shut down both Analytics servers.
2. Create a database user for statistics database in oracle (ex- user — statdb)
3. Go to <DAS_HOME>/repository/conf/datasources and open stats-datasources.xml and change the properties as below,
<datasource>
<name>WSO2AM_STATS_DB</name>
<description>The datasource used for setting statistics to API Manager</description>
<jndiConfig>
<name>jdbc/WSO2AM_STATS_DB</name>
</jndiConfig>
<definition type="RDBMS">
<configuration>
<url>jdbc:oracle:thin:@localhost:1521/oracledb</url>
<username>statdb</username>
<password>statdb</password> <driverClassName>oracle.jdbc.driver.OracleDriver</driverClassName>
<maxActive>50</maxActive>
<maxWait>60000</maxWait>
<testOnBorrow>true</testOnBorrow>
<validationQuery>SELECT 1 FROM DUAL</validationQuery>
<validationInterval>30000</validationInterval>
<defaultAutoCommit>false</defaultAutoCommit>
</configuration>
</definition>
</datasource>
Now we have a complete API Manager Analytics 2 node Minimum HA cluster. You can follow,
API Manager 2.5.0 Documentation to configure API Manager 2.5.0 with Analytics.
API Manager 2.2.0 Documentation to configure API Manager 2.2.0 with Analytics.
API Manager 2.1.0 Documentation to configure API Manager 2.1.0 with Analytics.
API Manager 2.0.0 Documentation to configure API Manager 2.0.0 with Analytics.
Have Questions ? Add in the comment section.
Also don’t forget to Clap hard for this story. Bravo…!!!!