1.0 Introduction
In data services, environment change( dev-->qa-->prod) affects the datasources configuration. In the data source configuration, we need to provide database url, username, password.
Sample datasource configuration
<datasource>
<name>dss</name>
<definition type="RDBMS">
<configuration>
<driverClassName>com.mysql.jdbc.Driver</driverClassName>
<url>jdbc:mysql://localhost:3306/dss</url>
<username>root</username>
<password encrypted="true">E61Pys3tVBbLagNo+co9hChhwh6J8MZ/+CU4Z8vw6ABv9YR4SZAf9o3OZmUpLWVz8dKhPGrqPYnwIMw3InkJvpHea7xzEljrX9PF3PY/ax+Fe0upBhGIe+jvSDUai5RAb7cxSwhffnhx1JQZroieeIDxb6n1cpuRN8wd/z4zmtk=</password>
</configuration>
</definition>
</datasource>
For different environments , we might need to change
Eg:
3.0 Configurations
3.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 DSS mount registries</description>
<jndiConfig>
<name>jdbc/dssserver_config</name>
</jndiConfig>
<definition type="RDBMS">
<configuration>
<url>jdbc:mysql://localhost:3306/dss</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 datasource in the registry.xml
3.2 WSO2DSS-QA
In this sample, let’s take two DSS servers for QA and production environments.
master-datasource.xml
Create a new data source to point the mysql database which is already created.
registry.xml
We need to mount the config registry to different target path to make sure QA DSS 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.
Copy the mysql jdbc driver in repository/components/lib folder. Set different port offset in carbon.xml. For DSS_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.3 WSO2DSS-PROD
master-datasource.xml
Create a new data source to point the mysql database which is already created.
registry.xml
We need to mount the config registry to different target path to make sure PROD_DSS 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.
Copy the mysql jdbc driver in repository/components/lib folder. Set different port offset in carbon.xml. For DSS_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.
3.4 Datasource Configuration
When we create carbon datasource from UI, the password will be encrypted and saved to registry. Here since we need to directly upload the data source configuration to the registry, we can just upload the password in plain text. If user needs to encrypt the password, later he can access the datasource via datasource UI and save it. So, it will be encrypted and saved to registry.
Sample data source for QA-DSS server
<datasource>
<name>testdatasource</name>
<definition type="RDBMS">
<configuration>
<driverClassName>com.mysql.jdbc.Driver</driverClassName>
<url>jdbc:mysql://localhost:3306/service_qa</url>
<username>root</username>
<password encrypted="false">root</password>
</configuration>
</definition>
</datasource>
Save the configuration as testdatasource and upload in WSO2 G-Reg server under qa environment. Go to, https://localhost:9443/carbon and browse to /_system/config/env/qa/repository/components/org.wso2.carbon.ndatasource path and upload.
Sample data source for PROD-DSS server
Copy the same configuration and edit the parameters to reflect the production database configurations and save as testdatasource.
Go to, https://localhost:9443/carbon and browse to /_system/config/env/prod/repository/components/org.wso2.carbon.ndatasource path and upload.
Now same datasource configuration is available under two paths with the environment specific parameters. But the datasources’ name is same.(ie: testdatasource)
3.5 Dataservice
When we create dataservice, there is no any environment specific parameters. Only thing is, we need to point the datasource there, which contains environment specific parameters.
We already separated and stored the different datasource configurations with same name in different registry paths. So, if we upload same dataservice in both servers(ie: DSS_QA and DSS_PROD) both servers will talk to the relevant data source configurations, which are stored under relevant config registry without any issue.
Sample dataservice
<data name="dss_test">
<config id="testdatasource">
<property name="carbon_datasource_name">testdatasource</property>
</config>
<query id="select_person" useConfig="testdatasource">
<sql>call `person-info`(?, ?, ?);</sql>
<result element="people" rowName="person">
<element column="PERSON_NAME" name="name" xsdType="string"/>
<element column="PERSON_NICK" name="nick" xsdType="string"/>
<element column="PERSON_PHONE" name="phone" xsdType="string"/>
</result>
<param name="pName" sqlType="STRING"/>
<param name="pPhone" sqlType="STRING"/>
<param name="pNick" sqlType="STRING"/>
</query>
<operation name="select_person">
<call-query href="select_person">
<with-param name="pName" query-param="pName"/>
<with-param name="pPhone" query-param="pPhone"/>
<with-param name="pNick" query-param="pNick"/>
</call-query>
</operation>
</data>
Related post
Environment Management in WSO2 ESB using WSO2GREG
In data services, environment change( dev-->qa-->prod) affects the datasources configuration. In the data source configuration, we need to provide database url, username, password.
Sample datasource configuration
<datasource>
<name>dss</name>
<definition type="RDBMS">
<configuration>
<driverClassName>com.mysql.jdbc.Driver</driverClassName>
<url>jdbc:mysql://localhost:3306/dss</url>
<username>root</username>
<password encrypted="true">E61Pys3tVBbLagNo+co9hChhwh6J8MZ/+CU4Z8vw6ABv9YR4SZAf9o3OZmUpLWVz8dKhPGrqPYnwIMw3InkJvpHea7xzEljrX9PF3PY/ax+Fe0upBhGIe+jvSDUai5RAb7cxSwhffnhx1JQZroieeIDxb6n1cpuRN8wd/z4zmtk=</password>
</configuration>
</definition>
</datasource>
For different environments , we might need to change
- Database url
- Database username
- Database password
To manage different environments, we need a running WSO2 Governance Registry instance and we need to mount the config registries of WSO2 DSS to different target paths. The paths will indicate the different environments.
<mount path="/_system/config" overwrite="true">
<instanceId>config</instanceId>
<targetPath>/_system/config/env/prod</targetPath>
</mount>
All servers will talk to same database.( That is, wso2greg and wso2dss.)<instanceId>config</instanceId>
<targetPath>/_system/config/env/prod</targetPath>
</mount>
We need to upload the datasource configurations for different environments directly to the registry in the relevant environment paths. Note that, we can not use carbon datasource UI options available at dataservice server. Because WSO2 G-Reg will be the centralized server to manage different environments, so we need to avoid creating datasources from dataservice server.
3.0 Configurations
3.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 DSS mount registries</description>
<jndiConfig>
<name>jdbc/dssserver_config</name>
</jndiConfig>
<definition type="RDBMS">
<configuration>
<url>jdbc:mysql://localhost:3306/dss</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>
Use the created datasource in the registry.xml
<!-- This defines the default database and its configuration of the registry -->
<dbConfig name="wso2registry">
<dataSource>jdbc/dssserver_config</dataSource>
</dbConfig>
<dbConfig name="wso2registry">
<dataSource>jdbc/dssserver_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’)
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’)
3.2 WSO2DSS-QA
In this sample, let’s take two DSS servers for QA and production environments.
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 for DSS</description>
<jndiConfig>
<name>jdbc/dssserver_config</name>
</jndiConfig>
<definition type="RDBMS">
<configuration>
<url>jdbc:mysql://localhost:3306/dss</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>
<name>WSO2_REG_DB</name>
<description>The datasource for DSS</description>
<jndiConfig>
<name>jdbc/dssserver_config</name>
</jndiConfig>
<definition type="RDBMS">
<configuration>
<url>jdbc:mysql://localhost:3306/dss</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 DSS 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/dssserver_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/dssserver_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>
<dataSource>jdbc/dssserver_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/dssserver_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 DSS_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.3 WSO2DSS-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 for DSS</description>
<jndiConfig>
<name>jdbc/dssserver_config</name>
</jndiConfig>
<definition type="RDBMS">
<configuration>
<url>jdbc:mysql://localhost:3306/dss</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>
<name>WSO2_REG_DB</name>
<description>The datasource for DSS</description>
<jndiConfig>
<name>jdbc/dssserver_config</name>
</jndiConfig>
<definition type="RDBMS">
<configuration>
<url>jdbc:mysql://localhost:3306/dss</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_DSS 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/dssserver_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/dssserver_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>
<dataSource>jdbc/dssserver_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/dssserver_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 DSS_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.
3.4 Datasource Configuration
When we create carbon datasource from UI, the password will be encrypted and saved to registry. Here since we need to directly upload the data source configuration to the registry, we can just upload the password in plain text. If user needs to encrypt the password, later he can access the datasource via datasource UI and save it. So, it will be encrypted and saved to registry.
Sample data source for QA-DSS server
<datasource>
<name>testdatasource</name>
<definition type="RDBMS">
<configuration>
<driverClassName>com.mysql.jdbc.Driver</driverClassName>
<url>jdbc:mysql://localhost:3306/service_qa</url>
<username>root</username>
<password encrypted="false">root</password>
</configuration>
</definition>
</datasource>
Save the configuration as testdatasource and upload in WSO2 G-Reg server under qa environment. Go to, https://localhost:9443/carbon and browse to /_system/config/env/qa/repository/components/org.wso2.carbon.ndatasource path and upload.
Sample data source for PROD-DSS server
Copy the same configuration and edit the parameters to reflect the production database configurations and save as testdatasource.
Eg:
<datasource>
<name>testdatasource</name>
<definition type="RDBMS">
<configuration>
<driverClassName>com.mysql.jdbc.Driver</driverClassName>
<url>jdbc:mysql://localhost:3306/service_prod</url>
<username>root</username>
<password encrypted="false">root</password>
</configuration>
</definition>
</datasource>
<name>testdatasource</name>
<definition type="RDBMS">
<configuration>
<driverClassName>com.mysql.jdbc.Driver</driverClassName>
<url>jdbc:mysql://localhost:3306/service_prod</url>
<username>root</username>
<password encrypted="false">root</password>
</configuration>
</definition>
</datasource>
Go to, https://localhost:9443/carbon and browse to /_system/config/env/prod/repository/components/org.wso2.carbon.ndatasource path and upload.
Now same datasource configuration is available under two paths with the environment specific parameters. But the datasources’ name is same.(ie: testdatasource)
3.5 Dataservice
When we create dataservice, there is no any environment specific parameters. Only thing is, we need to point the datasource there, which contains environment specific parameters.
We already separated and stored the different datasource configurations with same name in different registry paths. So, if we upload same dataservice in both servers(ie: DSS_QA and DSS_PROD) both servers will talk to the relevant data source configurations, which are stored under relevant config registry without any issue.
Sample dataservice
<data name="dss_test">
<config id="testdatasource">
<property name="carbon_datasource_name">testdatasource</property>
</config>
<query id="select_person" useConfig="testdatasource">
<sql>call `person-info`(?, ?, ?);</sql>
<result element="people" rowName="person">
<element column="PERSON_NAME" name="name" xsdType="string"/>
<element column="PERSON_NICK" name="nick" xsdType="string"/>
<element column="PERSON_PHONE" name="phone" xsdType="string"/>
</result>
<param name="pName" sqlType="STRING"/>
<param name="pPhone" sqlType="STRING"/>
<param name="pNick" sqlType="STRING"/>
</query>
<operation name="select_person">
<call-query href="select_person">
<with-param name="pName" query-param="pName"/>
<with-param name="pPhone" query-param="pPhone"/>
<with-param name="pNick" query-param="pNick"/>
</call-query>
</operation>
</data>
Related post
Environment Management in WSO2 ESB using WSO2GREG