Thursday, February 19, 2015

Taking thread dump on CPU High usage in WSO2 products

Please follow the commands provided here to take the thread dump.

 

First you need to create test.sh script using following command.
     vi test.sh

Then paste following script content.

    #!/bin/bash
    # 1: ['command\ name' or PID number(,s)] 2: MAX_CPU_PERCENT
    [[ $# -ne 2 ]] && exit 1
    PID_NAMES=$1
    # get all PIDS as nn,nn,nn
    if [[ ! "$PID_NAMES" =~ ^[0-9,]+$ ]] ; then
        PIDS=$(pgrep -d ',' -x $PID_NAMES)
    else
        PIDS=$PID_NAMES
    fi
    # echo "$PIDS $MAX_CPU"
    MAX_CPU="$2"
    MAX_CPU="$(echo "($MAX_CPU+0.5)/1" | bc)"
    LOOP=1
    while [[ $LOOP -eq 1 ]] ; do
        sleep 0.3s
        # Depending on your 'top' version and OS you might have
        # to change head and tail line-numbers
        LINE="$(top -b -d 0 -n 1 -p $PIDS | head -n 8 \
            | tail -n 1 | sed -r 's/[ ]+/,/g' | \
            sed -r 's/^\,|\,$//')"
        # If multiple processes in $PIDS, $LINE will only match\
        # the most active process
        CURR_PID=$(echo "$LINE" | cut -d ',' -f 1)
        # calculate cpu limits
        CURR_CPU_FLOAT=$(echo "$LINE"| cut -d ',' -f 9)
        CURR_CPU=$(echo "($CURR_CPU_FLOAT+0.5)/1" | bc)
        echo "PID $CURR_PID: $CURR_CPU""%"
        if [[ $CURR_CPU -ge $MAX_CPU ]] ; then
            now="$(date)"
            echo "PID $CURR_PID ($PID_NAMES) went over $MAX_CPU""%" on $now
            jstack $CURR_PID > ./$now+jlog.txt
            echo "[[ $CURR_CPU""% -ge $MAX_CPU""% ]]"
            LOOP=0
            break
        fi
    done
    echo "Stopped"



Then we need to get process id of running WSO2 server by running following command.
    sanjeewa@sanjeewa-ThinkPad-T530:~/work$ jps
    30755 Bootstrap
    8543 Jps
    4892 Main


Now we know carbon server running with process ID 30755. Then we can start our script by providing init parameters(process ID and CPU limit). So it will keep printing CPU usage in terminal and once it reached limit it will take thread dump using jstack command. It will create new file with with embedding current date time and push Jstack output to it.

We can start scritp like this.
    sanjeewa@sanjeewa-ThinkPad-T530:~/work$ sh test.sh 30755 99

As you can see when CPU goes above 99% it will create log file and append thread dump.

 

Public sample wadl urls for testing

Public sample wadl urls for testing: https://developer.dnb.com/docs/v1/1.0/rest

 

Tuesday, February 17, 2015

Installing certificates into trust store

openssl s_client -showcerts -connect www.trimblemaps.com:443 </dev/null 2>/dev/null|openssl x509 -outform PEM > /tmp/trimblemaps.pem

 

keytool -importcert -alias trimblemaps -keystore client-truststore.jks --file /tmp/trimblemaps.pem

Installing Mongo in Linux using yum

Installing Mongo in linux using yum.

The Mongo DB downloads repository contains two packages:

  • mongo-10gen-server

This package contains the mongod and mongos daemons from the latest stable release and associated configuration and init scripts. Additionally, you can use this package to install daemons from a previous release of MongoDB.

  • mongo-10gen

This package contains all MongoDB tools from the latest stable release. Additionally, you can use this package to install tools from a previous release of MongoDB. Install this package on all production MongoDB hosts and optionally on other systems from which you may need to administer MongoDB systems.

Install MongoDB

Configure Package Management System (YUM)

Create a /etc/yum.repos.d/mongodb.repo file to hold the following configuration information for the MongoDB repository:

TIP

For production deployments, always run MongoDB on 64-bit systems.

If you are running a 64-bit system, use the following configuration:

[mongodb]

name=MongoDB Repository

baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/

gpgcheck=0

enabled=1

If you are running a 32-bit system, which is not recommended for production deployments, use the following configuration:

[mongodb]

name=MongoDB Repository

baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/i686/

gpgcheck=0

enabled=1

Install Packages

Issue the following command (as root or with sudo) to install the latest stable version of MongoDB and the associated tools:

yum install mongo-10gen mongo-10gen-server

When this command completes, you have successfully installed MongoDB!

Manage Installed Versions

You can use the mongo-10gen and mongo-10gen-server packages to install previous releases of MongoDB. To install a specific release, append the version number, as in the following example:

yum install mongo-10gen-2.2.3 mongo-10gen-server-2.2.3

This installs the mongo-10gen and mongo-10gen-server packages with the 2.2.3 release. You can specify any available version of MongoDB; however yum will upgrade the mongo-10gen and mongo-10gen-server packages when a newer version becomes available. Use the following pinningprocedure to prevent unintended upgrades.

To pin a package, add the following line to your /etc/yum.conf file:

exclude=mongo-10gen,mongo-10gen-server

 

Wednesday, February 11, 2015

How to get the url params in custom sequences in wso2 API Manager - 1.7.0

Here is the solution:

 

Example requesst :

GET http://localhost:8280/foo?a=1&b=2

 

and to log values of a and b

 

<sequence xmlns="http://ws.apache.org/ns/synapse" name="URL--PARAMS --In">

            <property name="VAL_a" expression="$url:a"/>

            <property name="VAL_b" expression="$url:b"/>

</sequence>

 

Thursday, February 5, 2015

How to swap the headers in a request in wso2 API Manager

File Name: /_system/governance/apimgt/customsequences/in/auth_token_swapper.xml

Content: 
<sequence xmlns="http://ws.apache.org/ns/synapse" name="AuthToken--Swapper--In">
         <property name="Backend-Authorization" expression="$trp:Backend-Authorization" scope="default" type="STRING"/>
         <property name="TPaaS-Authorization" expression="$trp:Authorization" scope="default" type="STRING"/>
    <filter xpath="fn:string-length(get-property('Backend-Authorization')) > 0">
          <then>
              <property name="TPaaS-Authorization" expression="get-property('TPaaS-Authorization')" scope="transport"/>
              <property name="Authorization" expression="get-property('Backend-Authorization')" scope="transport"/>
              <log level="custom">
                  <property name="TRACE" value="Global Mediation Extension by Guru Authorization is there."/>
              </log>
          </then>
          <else>
              <log level="custom">
                  <property name="TRACE" value="Global Mediation Extension by Guru Authorization is not there."/>
              </log>
          </else>
     </filter>
</sequence>

How to remove header from a request using wso2 API Manager

File Name: /_system/governance/apimgt/customsequences/in/auth_token_remover.xml

Content:
<sequence xmlns="http://ws.apache.org/ns/synapse" name="AuthToken--Remover--In">
    <header name="Authorization" scope="transport" action="remove"/>
    <log level="custom">
        <property name="TRACE" value="Global Mediation Extension by Krishna for Authorization remove."/>
    </log>
</sequence>

Tuesday, January 20, 2015

How to set/remove headers in api manager of wso2

File Name: /_system/governance/apimgt/customsequences/in/global_auth_header.xml

 

Content:

<sequence xmlns="http://ws.apache.org/ns/synapse" name="WSO2AM--ExtAuth--In">

    <property name="TPaaS-Authorization" expression="$trp:TPaaS-Authorization" scope="default" type="STRING"/>

    <filter xpath="fn:string-length(get-property('TPaaS-Authorization')) > 0">

          <then>

              <property name="Authorization" expression="get-property('TPaaS-Authorization')" scope="transport"/>

              <log level="custom">

                  <property name="TRACE" value="Global Mediation Extension by Guru Authorization is there."/>

              </log>

          </then>

          <else>

              <log level="custom">

                  <property name="TRACE" value="Global Mediation Extension by Guru Authorization is not there."/>

              </log>

          </else>

     </filter>

</sequence>

Sunday, January 18, 2015

How do I install cURL on a Windows machine for https?

Install cURL on Windows

There are 4 steps to follow to get cURL installed on Windows. There are two (2) libraries to install and they must be installed before cURL will work with SSL. Also, they must be installed in this order to work. Do not skip step 4.

·         Step 1 and Step 2 is to install SSL library

·         Step 3 is to install cURL

·         Step 4 is to install a recent certificate

Step One: Install Visual C++ 2008 Redistributables

From http://www.shininglightpro.com/products/Win32OpenSSL.html

For 64bit systems

·         Visual C++ 2008 Redistributables (x64)

For 32bit systems

·         Visual C++ 2008 Redistributables (x32)

Step Two: Install Win(32/64) OpenSSL v1.0.0k Light

Also from http://www.shininglightpro.com/products/Win32OpenSSL.html

For 64bit systems

·         Win64 OpenSSL v1.0.0k Light

For 32bit systems

·         Win32 OpenSSL v1.0.0k Light

Step Three: Install cURL

Visit http://curl.haxx.se/download.html.

Depending on if your system is 32 or 64 bit, download the corresponding curl.exe.

For example, go to the Win64 - Generic section and download the Win64 binary with SSL support (the one where SSL is not crossed out).

Unzip the file and copy curl.exe to C:\Windows\System32

Step Four: Install Recent CA Certificates

Do not skip this step.

Download a recent copy of valid CERT files from http://curl.haxx.se/docs/caextract.html.

Copy it to the same folder as you placed curl.exe (C:\Windows\System32) and rename it curl-ca-bundle.crt.

Test cURL

Be sure you are an Admin in Canvas.

Open a DOS command window, type in the following and press enter

curl https://yourcanvas.test.instructure.com (replace [yourcanvas] with your Canvas domain name)

You should get raw HTML output on the screen.

If you get an error such as ‘Command not found’ then cURL has not been installed

Notes on Running Commands

The DOS environment doesn't seem to like single quotes. Any example that uses single quotes to surround values is invalid on windows. The single quotes must be replaced with double quotes.

curl.exe -X POST -H "Content-Type: application/zip" --data-binary @BATCH_CANVAS_ACCOUNTS-TC.zip -H "Authorization: Bearer 7Ec3AJXBsRIgvFjkcF8P3rCtzDilNm8LuHcF5fki2" "https://<yourdomain>.instructure.com/api/v1/accounts/<your_account>/sis_imports.json?import_type=instructure_csv"

 

 

Tuesday, January 6, 2015

Error "File name/path too long" when you try to clone repo from git

When you clone Identity from git you will face an error which states “File name/path too long”.

 

Please execute the following command in your git console before you proceed.

 

 

git config core.longpaths true

 



Thanks & Regards,

Rajakrishna Reddy