Monday, December 1, 2014

Running multiple ActiveMQ instances on one machine

1. Download and unzip the ActiveMQ
http://activemq.apache.org/

2. Go to the ActiveMQ home directory and create the instances as follows
cd <ACTIVEMQ_HOME>
./bin/activemq create instanceA
./bin/activemq create instanceB

3. Do ls -l you can see two sub directories created as instanceA and instance B

4. Let instanceA to use the default config, modify the config of instanceB
Go to the instanceB/conf folder and open the file jetty.xml to make the webconsole available at port '8162'

       <property name="connectors">
            <list>
                <bean id="Connector" class="org.eclipse.jetty.server.nio.SelectChannelConnector">
                    <property name="port" value="8162" />
                </bean>
            </list>
        </property>

5. Open the activemq.xml file and modify tcp port to '61617'

       <transportConnectors>
            <transportConnector name="openwire" uri="tcp://0.0.0.0:61617"/>
        </transportConnectors>

6. Save the both files and start the instances in two consoles
go to the instanceA/bin folder and ./activemq console
go to the instanceB/bin folder and ./activemq console

Monday, November 10, 2014

Mounting remote governance registry

Let's say we have AS instance and G-reg instance, both instance have pointed their governance registry to MySql database.

Now I want to mount the AS's governance registry to G-reg's /_system/as/governance path

1. Shutdown both instances

2. Configurations to be done in G-reg side (in registry.xml file)

mount G-reg governance registry as

<mount path="/_system/governance" overwrite="true">
        <instanceId>greggov</instanceId>
        <targetPath>/_system/governance</targetPath>
    </mount>

mount AS governance registry as

<mount path="/_system/as/governance" overwrite="true">
        <instanceId>asgov</instanceId>
        <targetPath>/_system/as/governance</targetPath>
    </mount>

3. Configuration to be done in AS side (in registry.xml file)

mount AS governance registry

<mount path="/_system/governance" overwrite="true">
        <instanceId>asgov</instanceId>
        <targetPath>/_system/as/governance</targetPath>
    </mount>

4. Now we need to do a data migration as follows
Use AS database and execute following sql commands

Update REG_PATH Set REG_PATH_VALUE = REPLACE(REG_PATH_VALUE, '/_system/governance', '/_system/as/governance') where REG_PATH_VALUE like '/_system/governance%';

Update REG_LOG Set REG_PATH = REPLACE(REG_PATH, '/_system/governance', '/_system/as/governance') where REG_PATH like '/_system/governance%';

Update REG_LOG Set REG_ACTION_DATA = REPLACE(REG_ACTION_DATA, '/_system/governance', '/_system/as/governance') where REG_ACTION_DATA like '%/_system/governance%';

Update REG_ASSOCIATION Set REG_SOURCEPATH = REPLACE(REG_SOURCEPATH, '/_system/governance', '/_system/as/governance'), REG_TARGETPATH = REPLACE(REG_TARGETPATH, '/_system/governance', '/_system/as/governance') where REG_SOURCEPATH like '/_system/governance%' or REG_TARGETPATH like '/_system/governance%';

5. Restart the both instances.

Monday, November 3, 2014

Pointing governance registry to a MySQL database

Take WSO2 instance (here, I'm taking WSO2 AS) and do the following configurations

1. Modify the master-datasource.xml file

<datasource>
            <name>asgove</name>
            <description>The datasource used for governance registry</description>
            <jndiConfig>
                <name>jdbc/asgove</name>
            </jndiConfig>
            <definition type="RDBMS">
                <configuration>
                    <url>jdbc:mysql://localhost:3306/asgove?autoReconnect=true</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>

2. Modify the registry.xml file

 <dbConfig name="asgove">
        <dataSource>jdbc/asgove</dataSource>
    </dbConfig>

<mount path="/_system/governance" overwrite="true">
        <instanceId>asgove</instanceId>
        <targetPath>/_system/as/governance</targetPath>
    </mount>

    <remoteInstance url="https://localhost:9443/registry">
        <id>asgove</id>
        <dbConfig>asgove</dbConfig>
        <readOnly>false</readOnly>
        <enableCache>true</enableCache>
        <registryRoot>/</registryRoot>
        <cacheId>root@jdbc:mysql://localhost:3306/asgove</cacheId>
    </remoteInstance>

Don't forget to add the MySQL jars to the component/lib folder

Restart the instance with -Dsetup

Wednesday, October 1, 2014

Why we need atleast 2 WKMs for WSO2 Product cluster

Assume we have an ELB cluster with 2 nodes connected to AS and ESB clusters. (Here the well known members are 2 ELBs) All nodes are connected and working fine (members joined the cluster).
Let’s say, if both ELBs were down and then restarted, the ASs and ESBs also have to be restarted to join the cluster again.


This is a known issue in Hazelcast. If all WK members fail, the entire cluster has to be restarted. Thats why they have recommend to have two WKs members at minimum.


To avoid this situation you can configure the AS and ESB management nodes also as well-known members. Clustering details can found on AS[2] and ESB[3] links.




To configure AS & ESB mgt nodes as WK members, follow the following steps
- Update the AS mgt node axis2.xml file with WK member details as follows (do the same for ESB as well)
<members>
   <member>
       <hostName>xxx.xxx.xxx.
206</hostName> <!-- this should be the ELB details -->
       <port>4500</port>
   </member>
   <member>
       <hostName>(its own ip)</hostName>
       <port>(AS mgt node localmember port)</port>
   </member>
</members>


- Next you have to add the WK member details to the loadbalancer.conf file in ELBS
esb {
      domains{
         wso2.esb.domain {
              tenant_range *;
              group_mgt_port 4500;
              members <ip-of-mgt-node>:<local-port-of-mgt-node>;
              members 192.168.8.126:4010;
              
         mgt {
              hosts mgt.esb480.wso2.com;
         }
         worker {
              hosts wkr.esb480.wso2.com;
         }
     }
  }

Thursday, September 11, 2014

Define HTTP endpoint in WSO2 ESB 4.6.0

WSO2 ESB 4.6.0 does not support the HTTP endpoint feature as 4.7.0. But we can send a HTTP GET request with query parameters using the property REST_URL_POSTFIX in ESB 4.6.0.

Below proxy configuration in 4.6.0 will send a GET request with the query parameters defined in REST_URL_POSTFIX.

<proxy xmlns="http://ws.apache.org/ns/synapse" name="myProxy" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
   <target>
      <inSequence>
         <property name="uri.var.site" value="33" scope="default" type="STRING"/>
         <property xmlns:ns="http://org.apache.synapse/xsd" name="REST_URL_POSTFIX"
         expression="fn:concat('?site=', get-property('uri.var.site'), '&cm_user_pw=' ,12345 , '&account=' , 'accout' , '&key=' , 'testKey' , '&q=' ,123)" scope="axis2" type="STRING"/>
         <log level="custom">
            <property name="url" expression="get-property('axis2','REST_URL_POSTFIX')"/>
         </log>
         <property name="HTTP_METHOD" value="GET" scope="axis2" type="STRING"/>
         <send>
            <endpoint>
               <address uri=""http://******.net/accounts/info.json" format="rest"/>
            </endpoint>
         </send>
      </inSequence>
   </target>
   <description></description>
</proxy>

How to define HTTP Endpoint in WSO2 ESB 4.8.1
https://docs.wso2.com/display/ESB481/HTTP+Endpoint

REST_URL_POSTFIX https://docs.wso2.com/display/ESB481/HTTP+Transport+Properties#HTTPTransportProperties-REST_URL_POSTFIXREST_URL_POSTFIX


Monday, September 1, 2014

Create a patch using github pull request

This blog explains how to create a patch using github pull request

add ".patch" at the end of the pull request and execute the following command
curl https://github.com/<user>/<project>/pull/5.patch > 5.patch

Friday, August 29, 2014

How to configure api-key for the back-end service/API during the publishing process

This blog explains how to configure api-key for the back-end service/API during publishing process.

The API key would be always constant. The scenario is: one user will register for the public API, obtain the non-expiring API-Key(let's call it as x-api-key) and publish that API on the WSO2 API Manager. Once the API is published the consumer of the API need not pass the x-api-key each time he/she is invoking the API, he/she only needs to pass the WSO2 Access Token and necessary parameters for the API.


You can set the api-key as follows

1. Create custom sequence as follows and save it in a xml file.

<sequence xmlns="http://ws.apache.org/ns/synapse" name="xxxxx">
<in>
<header name="api-key" scope="transport" value="123456789"/>
</in>
</sequence>

name the sequence as <API_NAME>:v<VERSION>--<DIRECTION>

2. login to the https://localhost:9443/carbon and add the xml file to the /_system/governance/apimgt/customsequences/in registry location

3. login to the https://localhost:9443/publisher and edit the published API

- go to the Manage page
- check “Sequences:” check box
- select the sequence you created under "In Flow"

For more information, you can refer https://docs.wso2.com/display/AM170/Adding+Mediation+Extensions#AddingMediationExtensions-APIExtension 

Monday, June 23, 2014

Fronting WSO2 AS worker/manager cluster with HAProxy

This blog describes how to configure HAProxy as a load balancer with WSO2 Application Server cluster

HAProxy 1.5
WSO2 Application Server 5.2.1

Setup WSO2 AS Cluster




This cluster consist of 3 WSO2 Application Server instances, as 3 worker nodes and 1 manager node, where 1 node work as both worker and manager. HAProxy performs load balancing with this cluster by distributing incoming requests to the worker nodes via HTTP/S on port 80/443.

All admin requests can be sent to the manager node directly via HTTPs on port 9444 or through the HAProxy via 443 port depending on how we configure the manager node.

Click here to see how to setup WSO2 Application Server cluster






Setup HAProxy load balancer


* Install HAProxy
$ sudo add-apt-repository ppa:vbernat/haproxy-1.5
$ sudo apt-get update
$ sudo apt-get install haproxy

Need version 1.5 since native SSL support was implemented in 1.5

* Set ENABLED to 1 if you want the init script to start haproxy

$sudo vi /etc/default/haproxy

* Edit the /etc/haproxy/haproxy.cfg file and add the following

# load balancing among the worker nodes - HTTP
frontend ft_wrk
      bind as.wso2.com:80
      default_backend bk_wrk

backend bk_wrk
      balance roundrobin
    server node1 as.wso2.com:9764
      server node2 as.wso2.com:9765
      server node3 as.wso2.com:9766

# load balancing among the worker nodes - HTTPS
# access the management console via HTTPS
frontend https-in
      bind *:443 ssl crt /etc/haproxy/ssl/haproxy.pem
      acl is_mgt hdr_beg(host) -m beg mgt.as.wso2.com
      acl is_wrk hdr_beg(host) -m beg as.wso2.com

      use_backend mgt_as_wso2_com if is_mgt
      use_backend as_wso2_com if is_wrk
      default_backend as_wso2_com

backend as_wso2_com
      balance roundrobin
      server node1 as.wso2.com:9444 check ssl
      server node2 as.wso2.com:9445 check ssl
      server node3 as.wso2.com:9446 check ssl

backend mgt_as_wso2_com
      server server1 mgt.as.wso2.com:9444 check ssl

NOTE: load balancer can receive HTTPS requests via 443 port either to management console https://mgt.as.wso2.com/carbon or worker nodes https://as.wso2.com/
frontend https-in block handles HTTPS requests come to the load balancer via 443 port,
bind *:443 ssl crt /etc/haproxy/ssl/haproxy.pem provide valid certificate to HAProxy.

acl is_mgt hdr_beg(host) -m beg mgt.as.wso2.com
acl is_wrk hdr_beg(host) -m beg as.wso2.com
acl properties filter manager and worker requests

Server verification is enabled by default in HAProxy, so need to specify the ca-file as follows
server node1 as.wso2.com:9444 check ssl ca-file /ca-file/path

To disable the server verifications need to specify ssl verify none as follows or specify ssl-server-verify none in global section
server node1 as.wso2.com:9444 check ssl verify none

* Mapping the host names to the IP
Update the “/etc/hosts” file

<IP-of-worker>    as.wso2.com
<IP-of-manager>    mgt.as.wso2.com


* Restart the HAProxy

$sudo  /etc/init.d/haproxy restart

Fronting WSO2 AS worker/manager cluster with Nginx

This Blog describes how to configure Nginx as a load balancer with WSO2 Application Server cluster

Nginx 1.4.1
WSO2 Application Server 5.2.1

Setup WSO2 AS Cluster




This cluster consist of 3 WSO2 Application Server instances, as 3 worker nodes and 1 manager node, where 1 node work as both worker and manager. Nginx performs load balancing with this cluster by distributing incoming requests to the worker nodes via HTTP/S on port 80/443.

All admin requests can be sent to the manager node directly via HTTPs on port 9444 or through the Nginx via 443 port depending on how we configure the manager node.
Click here to see how to setup WSO2 Application Server cluster


Setup Nginx load balancer



* Install Nginx


$sudo apt-get install nginx


* Locate the http{} block of the /etc/nginx/nginx.conf file and add the following


# load balancing among the worker nodes - HTTP
upstream wso2.as.com {
            server as.wso2.com:9764;
          server as.wso2.com:9765;
          server as.wso2.com:9766;
}

server {
          listen 80;
          server_name as.wso2.com;
          location / {
                      proxy_pass http://wso2.as.com;
          }
}

# load balancing among the worker nodes - HTTPS
# To configure load balancing for HTTPS instead of HTTP, just use “https” as the protocol.
upstream ssl.wso2.as.com {
          server as.wso2.com:9444;
          server as.wso2.com:9445;
          server as.wso2.com:9446;
}

server {
          listen 443;
          server_name as.wso2.com;
          ssl on;
          ssl_certificate /etc/nginx/ssl/server.crt;
          ssl_certificate_key /etc/nginx/ssl/server.key;
          location / {
                      proxy_pass https://ssl.wso2.as.com;
          }
}

# access the management console via HTTPS
server {
          listen 443;
          server_name mgt.as.wso2.com;
          ssl on;
          ssl_certificate /etc/nginx/ssl/server.crt;
          ssl_certificate_key /etc/nginx/ssl/server.key;
          location /carbon {
              proxy_pass https://mgt.as.wso2.com:9444;
          }
}


* Mapping the host names to the IP
Update the “/etc/hosts” file


<IP-of-worker>    as.wso2.com
<IP-of-manager>    mgt.as.wso2.com


* Restart the Nginx


$sudo /etc/init.d/nginx restart

Thursday, June 19, 2014

WSO2 AS worker/manager cluster without WSO2 ELB

This blog describes how to setup WSO2 Application Server worker/manager cluster without using WSO2 Elastic Load Balancer and later we can use this cluster for configure different 3rd party load balances

WSO2 Application Server - 5.2.1

1. Use Cases

Each use case consist of 3 WSO2 AS instances form worker/manager cluster fronting with load balancer.

Use Case 1:
Requests direct to worker node cluster through LB
No access to admin console through LB


 Use Case 2:
Requests direct to worker node cluster through LB.
Allows to access admin console through LB.




Use Case 3:
Requests direct to worker node cluster through LB.
Allows to access admin console through LB.
Additionally manager node also serve requests. (Here manger node work as both worker and manager)






Manager/Worker3
Worker1
Worker2
offset
1
2
3
localMemberPort
4100
4200
4300
http
9764
9765
9766
https
9444
9445
9446


2. Tips to configure 3rd party load balancer

In order to configure the load balancer, need to consider the following
  1. Load balancer ports are http 80 and https 443
  2. Direct the http requests to the worker nodes with load balancing as http://as.wso2.com/<service> via http 80 port
  3. Direct the https requests to the worker nodes with load balancing as https://as.wso2.com/<service> via https 443 port
  4. Access the management console as https://mgt.as.wso2.com/carbon via https 443 port

In WSO2 AS cluster worker nodes server requests on http 9763 and https 9443 ports and can access the management console https 9443 port.



3. Configure the Manager node

1. Unzip the WSO2 AS

2. Setting up the cluster configurations
Edit “<AS_HOME>/repository/conf/axis2/axis2.xml” file as follows

*** Enable clustering for this node:

<clustering class="org.wso2.carbon.core.clustering.hazelcast.HazelcastClusteringAgent" enable="true">
<parameter name="membershipScheme">wka</parameter>
<parameter name="domain">wso2.as.domain</parameter>
<parameter name="localMemberHost">mgt.as.wso2.com</parameter>
<parameter name="localMemberPort">4100</parameter>

*** Specify the well known member
Here, the well known member is a worker node

<members>
  <member>
        <hostName>as.wso2.com</hostName>
        <port>4200</port>        
  </member>
</members>

3. Configuring the port offset and host name
Edit “<AS_HOME>/repository/conf/carbon.xml” file as follows

<Offset>1</Offset>
<HostName>as.wso2.com</HostName>
<MgtHostName>mgt.as.wso2.com</MgtHostName>


4. Mapping the host names to the IP
Update the “/etc/hosts” file

127.0.0.1    as.wso2.com
127.0.0.1    mgt.as.wso2.com


5. Allow access the management console only through LB

Configure the HTTP/HTTPS proxy ports to communicate through the load balancer
Edit “<AS_HOME>/repository/conf/tomcat/catalina-server.xml” file as follows

<Connector  protocol="org.apache.coyote.http11.Http11NioProtocol"
              port="9763"
              proxyPort="80"

<Connector  protocol="org.apache.coyote.http11.Http11NioProtocol"
              port="9443"
              proxyPort="443"


4. Configure the worker node


1. Unzip the WSO2 AS

2. Setting up the cluster configurations
Edit “<AS_HOME>/repository/conf/axis2/axis2.xml” file as follows

*** Enable clustering for this node:

<clustering class="org.wso2.carbon.core.clustering.hazelcast.HazelcastClusteringAgent" enable="true">
<parameter name="membershipScheme">wka</parameter>
<parameter name="domain">wso2.as.domain</parameter>
<parameter name="localMemberHost">as.wso2.com</parameter>
<parameter name="localMemberPort">4200</parameter>



*** Specify the well known member
Here, the well known member is manager node

<members>
  <member>
        <hostName>mgt.as.wso2.com</hostName>
        <port>4100</port>        
  </member>
</members>



3. Configuring the port offset and host name
Edit “<AS_HOME>/repository/conf/carbon.xml” file as follows

<Offset>2</Offset>
<HostName>as.wso2.com</HostName>


4. Configure the HTTP/HTTPS proxy ports to communicate through the load balancer
Edit “<AS_HOME>/repository/conf/tomcat/catalina-server.xml” file as follows

<Connector  protocol="org.apache.coyote.http11.Http11NioProtocol"
              port="9763"
              proxyPort="80"

<Connector  protocol="org.apache.coyote.http11.Http11NioProtocol"
              port="9443"
              proxyPort="443"


5. Create the worker2 node
Get a copy of worker1 node and change the following in axis2.xml and carbon.xml

<parameter name="localMemberPort">4300</parameter>

<Offset>3</Offset>

5. Testing the cluster


1. Restart the configured load balancer

2. Start the manager node
sudo <AS_HOME>/bin/wso2server.sh

3. Start the worker1 and worker2 nodes
sudo <AS_HOME>/bin/wso2server.sh -DworkerNode=true

4. Check member joined messages in all consoles

5. Access management console https://mgt.as.wso2.com:9444/carbon

6. Access management console through LB https://mgt.as.wso2.com/carbon

7. Testing load distribution - http://as.wso2.com/sample or https://as.wso2.com/sample