Tuesday, September 6, 2016

Dealing with Docker Memory Issues

In this article, I just want to discuss two of the major memory issues we have faced while working with dockers.


1. Default docker uses the base directory as /var/lib/docker and due to memory constraints many times we need to change this default to some other path. There are two ways to do this- One is to go with the "symlink" to refer some other directory and another way is to use docker provided "-g" option. The problem with the first approach is that after every docker service restart, the symlink directory is getting unmounted and to mount again we have to restart the host machine.


To resolve this, using second approach, we have to use '-g' option that docker provides. In Centos the guide says we should edit /etc/sysconfig/docker, and add the -g option in the other_args variable: ex. other_args="-g /var/lib/testdir" but this was not getting picked somehow in our AWS server. So after some research we have included this option in the UCD start docker component itself.

2. Second issue related to memory is that by default for any docker container the root is assigned 10gb of space and for WAS installation more than 10GB space is required. For this we need to append another attribute --storage-opt dm.basesize=25G. This will fix the problem.

To fix above, our final docker start command looks like
nohup sudo /usr/bin/docker daemon -g /opt/NewDirectory --storage-driver=devicemapper --storage-opt dm.basesize=25GB --storage-opt dm.loopmetadatasize=4GB --insecure-registry HN_OR_IP_ADDR_HERE:5000 --log-level="debug" >dockerlog.txt

Some good links on the above:

Saturday, September 3, 2016

Invoking PayPal Classic API's- Signature and Certificate based approahes

 Paypal provides two ways to invoke their API's- Through the signature base and another is through certificates.

1. Signature based: For signature based the mandatory parameters are:
    - API Username
    - API password
    - API signature

2. Certificate based: Mandatory parameters for this approach are:
    - API Username
    - API password
    - API certificate
    - API certificate key


Generate API Signature and Certificate

You need to generate the signature or certificate depending upon the approach you are going to use. The process for both is nearly same. Login to your Paypal sandbox account. If you don't have the valid account, register as new user. For more details for generating certificates and signatures can be obtained from here.

Code snippet to be integrated

1. Define property file

    - Property file for Signature based approach

        acct1.UserName = ****-facilitator_api1.gmail.com
        acct1.Password = 348889***
        acct1.Signature = W19Jweloyt7bsmlaqzxrL7vYoFV*****

    - Property file for Certificate based approach

        acct1.UserName = ****-facilitator_api1.gmail.com
        acct1.Password = 348889***
        acct1.CertPath=/opt/tmp/paypal_cert.p12
        acct1.CertKey=keyvalue

    - Common properties for both the approaches
        
        service.EndPoint.PayPalAPI=https://api.sandbox.paypal.com/2.0/
        service.EndPoint.PayPalAPIAA=https://api.sandbox.paypal.com/2.0/
        service.EndPoint.Permissions=https://svcs.sandbox.paypal.com/
        http.ConnectionTimeOut=5000

2. Initialize properties: here we are taking example of the certificate based approach

    loadProperties(){
    Properties PAYPAL_PROP = new Properties();
    PAYPAL_PROP.put("acct1.UserName",readProperty("acct1.UserName"));
    PAYPAL_PROP.put("acct1.Password",readProperty("acct1.Password"));
    PAYPAL_PROP.put("acct1.CertKey", readProperty("acct1.CertKey"));
    PAYPAL_PROP.put("acct1.CertPath", readProperty("acct1.CertPath"));
    PAYPAL_PROP.put("service.EndPoint.PayPalAPI", readProperty("service.EndPoint.PayPalAPI"));
    PAYPAL_PROP.put("service.EndPoint.PayPalAPIAA", readProperty("service.EndPoint.PayPalAPI"));
    PAYPAL_PROP.put("service.EndPoint.Permissions", readProperty("service.EndPoint.Permissions"));
    PAYPAL_PROP.put("http.ConnectionTimeOut", .readProperty("http.ConnectionTimeOut"));
    }


3. Invoke API's: Sample code snippet in Java for doVoid request

    DoVoid(String sAuthorizationId){
        DoVoidReq doVoidReq = new DoVoidReq();
        DoVoidRequestType doVoidRequest = new DoVoidRequestType(sAuthorizationId);
        doVoidReq.setDoVoidRequest(doVoidRequest);
        PayPalAPIInterfaceServiceService service = null;
        service = new PayPalAPIInterfaceServiceService(PAYPAL_PROP);
        DoVoidResponseType doVoidResponse = service.doVoid(doVoidReq);
}


Similarly you can invoke other Paypal API's using the above code.