Thursday, December 24, 2015

Considering migration to cloud? Here are some tips and lesson learnt.

Recently, I was involved in migration to Openshift based cloud environment (enterprise version). We were migrating some of the apps based on the tech stack Java/JEE and back-end as oracle.

Though my organization has facilitated a dedicate infra support team, such migrations are still never easy to deal with.

Here are some of the lessons learned and point to consider if you are planning to place your apps into the cloud or, for that matter a new infra.

Do not show off and become the first one ever to do it in your company. You can be applauded, but might as well have to spend quite a few sleepless night depending upon number of switches you are turning on in the production environment.

Get a free ride or just walk in park. Get your feet wet by writing a simple app or a few servlets in a trial or evaluation server. Or, just watch someone help video/help manuals.

Talk to people who are doing the same thing in your company and as and when situation arise help them to get thru some technical issue or problem. The reward comes when you get stuck. :)

Housekeeping time. Remember, this is best time to get rid of your technical debts or any refactoring or code cleanup plans you had been keeping in the back burner  due to schedule crunch.


Analyze the impacts properly while committing yourself for the migration. You might not be knowing all the small little dependency. Following are some of the important stuff to lookout for:
  • DB Connection pooling code
  • Legacy code
  • Utilities like sending mails
  • Codes that reads a file like image or properties, from the codebase or the file system
  • Logging mechanism
  • LDAP Connections
  • Any 3rd party https calls that needs to be white-listed or needs to be added into 
  • Any other code that are based on the environment (for example, server provided API/tool etc.)
  • And last but not the least, static URLs which refers to your application 

Keep moving. When you are stuck on one particular issue, don't keep working on the same for long. Move ahead, solve the other small hanging ones. At the same time, keep following up with the support or any kind of help you can seek from a larger community. Usually, these are some small screws, which we some times just don't realize ourselves until may be, the very next morning. So, don't worry. Stay calm.

I think, these are some basic yet very relevant points I can tell from my experience. In case, you have some story or comment related with this, please do leave a comment.

Good luck in case you are into a migration phase and stumbled on this blog post. :)

Wednesday, September 2, 2015

Facade Design Pattern - A brief note

What is Facade Design Pattern?


Facade, pronounced as fuh-sahd, originated from french façade and italian facciata, meaning the face of a building, esp the main front or a front or outer appearance.

Lets see what it means in the world of design patterns.There are two important part of the problem it addresses:
a) The subsystems within a system 
b) Interaction between subsystems of two different systems. 

Sometimes the interaction becomes so complex, that we need to create a layer abstraction which can help in achieving simplicity by introducing simple interface to communicate.


Definition

Now lets see the official GoF definition, Facade Pattern: a single class that provides a unified interface to an entire subsystem.

Use case or example of Facade


There are many use case if we look through the interactions between various systems and their components. One such example is the interaction that happens between various components in Supply Chain Domain. The below image explain one such interaction. Although this is not exact interaction but this pretty much explains the crux of Facade.

Wednesday, June 18, 2014

Deprectaed and Abandonened...

Well, this is a slightly off technical discussion. However, it is nice and interesting to take a note of what software industry uses the word for something which is not going to be there anymore. These words differs in the context they are used.

Below are some common used words, in no particular order.

Deprecated: This is something which we often see while using  a programming language or a framework, where some methods/members are deprecated, meaning they are either no longer used, or they are replaced by some other methods/members.

Obsolete: Obsolete is word which people use to refer to something very old, such as a process or methodology which was relevant few years back, but not recommended any more or replaced by some better relevant process or methodologies or technique.

Withdrawn: For example, some product developers may withdraw BSD License, and provide their product with LGPL license, which is little more strict license in open source world.

Decommission: Lets say an enterprise has started to switch over to a new version control system or to a new version of RDBMS. Then, once the transition happens the old system are usually decommissioned.

And, there are some more:
  • uninstalled
  • discontinued
  • deactivated
  • unsupported
  • EOL (end of life)
  • Sunset
  • Dead (We witnessed an interesting discussion by some industry stalwarts likes of David, Kent and Martin on is TDD dead just a few weeks back )

Any other words comes in your mind? Please leave your comments :-).

Wednesday, June 4, 2014

Unix Tip: Working with CSV file in Unix


One of the unix problem I worked recently, thought its worth sharing.
The problem required to query over csv files in unix, like we query database using sql.
So, these commands work quite like SQL. :)

Requirement:

To get the first record for where 2nd column is null, that is, emp_name has been left blank for the below input file content.

Input File Name:

test_data.csv [1]

Input File Content:

employee_id,emp_name,emp_age
234,Ram,27
235,Shyam,21
236,Mohan,40
237,,25

Command:

sed 's/,,/,NULL,/g;' test_data.csv | awk -F, '$2 ~/NULL/'  | sed 's/,NULL,/,,/g;' | head -n 1

Description:


- sed 's/,,/,NULL,/g;' test_data.csv : replaces all empty values with the string "NULL"
- awk -F, '$2 ~/NULL/' : finds all the values where 2nd column is NULL, -F option is used for defining field separator
- sed 's/,NULL,/,,/g;' : reverts back all the NULL to empty values
- head -n 1 : prints only the first record, if you remove this you will get all the records. [2]



Other examples:

1) Get all employees age greater then 20

sed 's/,,/,NULL,/g;' test_data.csv | awk -F, '$3 > 20' | sed 's/,NULL,/,,/g;'

2) Get all employees whose employee_id is equal of 234

sed 's/,,/,NULL,/g;' test_data.csv | awk -F, '$1 == 234' | sed 's/,NULL,/,,/g;'

3) Get all employees whose employee_id is less than or equal to 235

sed 's/,,/,NULL,/g;' test_data.csv | awk -F, '$1 <= 235' | sed 's/,NULL,/,,/g;'


--------------------------------------------------------------------------------------------
[1] CSV: A CSV file contains comma separated values and can be easily created/edited with Microsoft Excel, almost like normal excel files.
[2] In case we don’t need entire row, we can also use cut command here to get only one field or a few fields

Tuesday, June 3, 2014

Unix Tip : Unix command to find the files modified 'n' number of days ago


Find is the command for searching files in a unix folder. Probably, this is one such command which you might need quite often.

And, while working on a project, with VCS ( version control ), you often need to find the files that have been modified today, in last couple days and so on. So, this is one the way find command comes handy. It finds the files recursively as well.

Examples:

# replaces n with number of days here
> find . -mtime –n 
# A minus (-) before n indicates number of days ago 
# i.e. include those file which falls between today and nth day
> find . -mtime n    
# display list of files modified exactly ON the nth day, from today
> find . -mtime +n 
# A plus (+) before n indicates file modified even prior to nth day

In case you need to find the files that have been modified few minutes ago, or some 'm' minutes ago, you can use the option mmin instead of mtime.

------
Reference: http://linux.about.com/od/commands/l/blcmdl1_find.htm

Friday, May 30, 2014

How to read JSON data (json request) from http request in a servlet or controller


If you use a javascript AJAX request which sends the http request in JSON data format and not in normal key value pair, you might need this.
One such example is the ExtJS store's, api config. For all the write operations the proxy for create/update/delete (use AJAX) sends the records in json form, in case the reader is defined as json.

Code:

protected void doPost(HttpServletRequest request, HttpServletResponse response) 
  throws ServletException, IOException {
  
 PrintWriter out = response.getWriter();
 StringBuilder jsonString = new StringBuilder();
 
 String jsonToken = null;
 
 BufferedReader reader = request.getReader();
 while ((jsonToken = reader.readLine()) != null){
  jsonString.append(line);
 } 
 // converting the JSON String into a JSONObject, which almost work like a Map  
 try {
  JSONObject requestJsonObject = new JSONObject(jsonString); 
  // JSONObject from JSON Java API from json.org
  System.out.println(requestJsonObject.toString());
 }catch(JSONException jsone){
  jsone.printStackTrace();
 } 
  
 // further processing goes here....
} 

Interesting reads:

Tuesday, May 27, 2014

ExtJS: Panel Vs ViewPort

Working with ExtJS apps, we often get advice from the senior programmers that we should use ViewPort instead of Panel.
So, the question that we arise is when to use a ViewPort and when to use a Panel. Or, why to use ViewPort if Panel suffice the need.

Well, ViewPort is particularly useful in case you are looking to create a single web page application.
I think designers of ExtJS have put together all the essential components very nicely which allows you to develop Single Page WebApp quite elegantly.

Using viewport you can utilize availbale height and width of browser. You can use screen.availWidth and screen.availHeight to give you component proper dimension.

When I tried to do a little bit of search on google and forms, couple of interesting points came out which can help understanding answer when and why:
  1. There may be only one ViewPort for a page for obvious reason that it is specialized container which give you the entire view area of browser. But of course you can use a layout like border layout and add Panels as child component.So, in case you have a
  2. And, in cases where you do not have the liberty of using the entire view of the document/web page, use Panel instead. For example, in case your entire web page is using JQuery, but you want to keep a ExtJS grid component, you can do so using a grid panel.
     
The below forum links might useful to further reading:
The only tricky thing that I found with ViewPort is when you want to have the scrolling option, meaning the scrollbars should appear when you reduce the browser window size.
There is  autoScorll config, which is by default false. Although there implies that if you make it true it should show you the scrollbars. But, that does not happen often. The reason is something interesting to know.

If you take a look at the docs for ExtJS (4.x), it clearly states, "The Viewport does not provide scrolling, so child Panels within the Viewport should provide for scrolling if needed using the autoScroll config."


All this is little contradictory. But the problem gets solved once you provide the width/height or both for the child Panels. The scrollbar does appear after that.

So, in case you want to keep the scrolling, you need to take care of child Panels.
-----------------------------------------------------------------------------
  1. Please note the properties in EtxJS are case-sensitive, so "autscroll" won't work, it must be "autoScroll".
  2. screen.availWidth and screen.availHeight are provided by java script. You can alternatively use Ext.container.Viewport.getWidth() and Ext.container.Viewport.getHeight() as well.

Prototype

Prototype is another creation pattern. Intent:  - Intent is to create objects by cloning existing instance  - Specify the kinds of obj...