Friday, December 9, 2016

Explaining the World Economy in Pictures

I found an interesting article on explaining how current economy works.
Please read below.
Explaining the World Economy in Pictures

Tuesday, October 18, 2016

Short notes on DevOps

DevOps: 

Integrates Developers and Operations teams in order to improve collaboration and productivity by Development of systems or application and automating infrastructure, deployment and monitoring performance.

Traditional approach and pitfalls:
Initially Developers(Application developers with programming skills and QA engineers) and Operations (Skills of configuring Networking/Firewall, Installing Windows/Unix/Linux/Database and other products, Deployment and monitoring of applications) are two different roles/groups.
The implementation of application would always start by Developers in their local boxes, where developer is responsible for Planning, Architecting, Designing, Implementing, Testing, Building, Packaging and Deploying in his local machine or in less capable environment or sandbox.

When it is decided by IT management or Business teams to take it to higher environments ( Functional Automation Testing, Performance Testing, User Acceptance Testing and finally into Production), an engagement of Infrastructure & Operations (I&O) team is required to create these environments on right infrastructure and with firewall configuration to isolate internal/external access.

By this time, I&O team has no clue about application release and has to find out the capacity to support this asset in all desired environments. The team may also needs to plan to upgrade H/W and change number of instances/clusters and increase disk space and RAM to make the asset more stable in production environment.

The turnaround time to promote a smallest change from conceptual to working solution is huge and the business may fall behind if the speed to market and attract/retain end customers is a very important part of Business Strategy.
This clearly shows the IT is falling behind the Business strategy.

New Approach:
If both Developers and Operations teams work together from the beginning of building the Application by following new standards,  the amount of time that will take to promote/release the asset into higher environments can be reduced.

How is this possible now?

The innovation and advancement of concepts in Hardware and software to manage the hardware has opened for following new practices to emerge.

a. Virtualization / Containerization (Docker)
 Allowing software to run multiple operating systems at the same time on same Hardware.
The software (Ex. Hypervisors) offers layer of abstraction, and allow to install many Guest OS and work with shared Hardware, Memory and other hardware resources.
b. Cloud (Utility) Computing.
c. Automating Infrastructure with scripts (Chef, Puppet, Saltstack and Ansible) and Vagrant for creating portable environments to run any other OS/Host.
d. The new concepts and practices are being evolved continuously and watch out or new disrupting concepts....

How do we engage this?
There are several vendors offering a complete suite of tool-chain to help IT organizations to realize the benefits of DevOps.  Mixing the other standards or methodologies (Agile/XP) of software development will take the complete Software Development and Delivery process to new level so that IT organization can immediately meet and align with Business priorities.

Other Benefits:
a. Innovate faster
b. Speed to market and get the feedback faster to improve the product.
c. Code little, build, test (Automated functional and performance, regression scripts) and release/deploy (using CI and CD practices) into all (including Prod) env in Iterative manner in collaboration with Operations team
d. Automate everything (Building, Automated Functional Testing, Automated Performance Testing, Regression Testing and  Release into Infrastructure),
e. Keep configuration of all (Dev, QA, PerfT, UAT and Prod) environments same to avoid surprises.
f. Monitor the application performance

Emphasizes a  Continuous Development (Developers) and Deployment (Operations/Administrators) using Agile practices. It is a cultural shift to IT teams (Software Engineering, Quality Assurance and Infrastructure Operations).

Automates the software delivery and infrastructure operations (i&o) in very collaborated manner very often and repeatedly.The following are key stages of DevOps.
Please refer to spreadsheet.DevOps Phases and Tools

DevOps Tools:  GitHub (source code management), Jeninks/Hudson (Continuous Integration & Deployment), Chef/Puppet (Infrastructure as code), Docker-Container, Hyper (vagrant), NewRelic (Application peformance monitoring of Logs) and SiteScope for alerts, Openshift

Wednesday, September 28, 2016

Enabling Apache Velocity UI Editor in Eclipse IDE




Adding Velocity UI Editor Plugin to Eclipse IDE


1. Download 'org.apache.velocity_1.7.0.2.jar'  and 'org.vaulttec.velocity.ui_1.0.5.jar'   or other latest versions from  https://sourceforge.net/projects/veloedit/files/org.vaulttec.velocity.ui/
Also refer to https://code.google.com/archive/p/velocity-edit/

2. Copy them into <Eclipse Installation Location>\plugins  directory.
3. Restart the Eclipse
4. Add new File associations (*.vtl and *.vm and *.vsl) in Eclipse settings at 'Windows>Preferences>General>Editors>File Associations'
5. Notice that a new entry (Velocity UI) can be seen under 'Windows>Preferences>' as the result of installing new JAR files.
6. Optional: Change the settings of 'Velocity UI' if needed.
7. Open a VTL file to see the settings are reflected in editor.

Thursday, September 15, 2016

 Pass by Value or Pass by Reference in Java?


Before coming to conclusion let's look at the example.

Code:
class Person {
private String name = null;

public Person() {
}

public String getName() {
return this.name;
}

public void setName(String newName) {
this.name = newName;
}
}

class Manager {
public Person changePersonName1(Person p) {
if (p != null) {
// just change only name
p.setName("I'm changed by Manager in changePersonName1()");
}
return p;
}

public Person changePersonName2(Person p) {
if (p != null) {
// just change only name
p.setName("I'm changed by Manager in changePersonName2()");
// create new Person instance, which means you no longer making any
// changes to the argument 'p' but on new Person instance
p = new Person();
p.setName("I'm recreated as new Person by Manager in changePersonName2()");
}
return p;
}
}

public class JavaPassByValueOrReference {
public static void main(String[] args) {
// Create a person
Person p1 = new Person();
p1.setName("I'm in p1 instance");

// Create a Manager
Manager mgr = new Manager();
System.out.println("0: Person p1 name = " + p1.getName());

//1-change name 
mgr.changePersonName1(p1);
System.out.println("1: Person p1 name = " + p1.getName());

//2-change name
mgr.changePersonName2(p1);
System.out.println("2: Person p1 name = " + p1.getName());
}
}
output:
0: Person p1 name = I'm in p1 instance
1: Person p1 name = I'm changed by Manager in changePersonName1()
2: Person p1 name = I'm changed by Manager in changePersonName2()

Explanation:
  1. In Main(..) method the 'Name' of Person is defaulted to "I'm in p1 instance".
  2. When Manager instance (mgr) changed the Person's name using  changePersonName1(..), the 'Name' of Person is changed from "I'm in p1 instance" to "I'm changed by Manager in changePersonName1()"
  3. When Manager instance (mgr) changed the Person's name using  changePersonName2(..), the 'Name' of Person is changed from "I'm changed by Manager in changePersonName1()" to "I'm changed by Manager in changePersonName2()"  instead of "I'm recreated as new Person by Manager in changePersonName2()"
The reason is in changePersonName2(Person p) of Manager class, the input argument (p) is reassigned to new Person instance (p = new Person()), changes to done on newly created instance are not returnable to or visible to Caller.

A copy of an object is made and passed to a function. On returning from the function, the copy is again copied back to the original passed object. So, the value set in the function is copied back.

In short 'Java is Pass the Reference By Value" or 'Pass the copy of Pointer(Reference) by Value'  or 'References are passed by Value' .

Wednesday, September 14, 2016

-startup

plugins/org.eclipse.equinox.launcher_1.3.200.v20160318-1642.jar

--launcher.library

plugins/org.eclipse.equinox.launcher.win32.win32.x86_64_1.1.400.v20160518-1444

--launcher.XXMaxPermSize

256M

-showlocation

--launcher.appendVmargs'

-vm

C:/Program Files/Java/jdk1.8.0_102/bin/javaw.exe

-Duser.name=RANGINY1

-product

org.eclipse.epp.package.jee.product

--launcher.defaultAction

openFile

-showsplash

org.eclipse.platform

--launcher.defaultAction

openFile

--launcher.appendVmargs

-vmargs

-Djava.net.preferIPv4Stack=true

-Declipse.p2.unsignedPolicy=allow

-Dcom.sun.management.jmxremote

-Dorg.eclipse.ecf.provider.filetransfer.excludeContributors=org.eclipse.ecf.provider.filetransfer.httpclient4

-Xverify:none

-Dosgi.requiredJavaVersion=1.8

-XX:+UseG1GC

-XX:+UseStringDeduplication

-Dosgi.requiredJavaVersion=1.8

-Xms256m

-Xmx1g


Wednesday, September 7, 2016

Java Enum example

import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;

public class EnumExample{
 public static void main(String args[]){
  // To Get the 'Day' by Abbreviation: 
  System.out.println("1 ="+Day.get("Su"));
  System.out.println("2 ="+Day.findByAbbr("Su"));
  // To get 'Day' name in String:
  System.out.println("3 ="+Day.valueOf("SUNDAY").toString());
  
  // To Get the Abbreviation by 'Day': 
  System.out.println("4 ="+Day.SUNDAY.getAbbreviation());
  System.out.println("5 ="+Day.valueOf("SUNDAY").getAbbreviation());  
 }
}

/**
 * Usage: 
 * 1. To Get the 'Day' by Abbreviation: Day.get("Su"))<br/>
 * 2. To Get the Abbreviation by 'Day': <br/>
 *    Day.SUNDAY.getAbbreviation();<br/>
 *        OR <br/>
 *    Day.valueOf("SUNDAY").getAbbreviation(); <br/>
 * 3. To get 'Day' name in String:<br/>
 *    Day.valueOf("SUNDAY").toString();
 */
 enum Day {
 //Enum types
 SUNDAY("Su"), MONDAY("Mo"), TUESDAY("Tu"), WEDNESDAY("We"), THURSDAY("Th"), FRIDAY("Fr"), SATURDAY("Sa");

 //internal state
 private final String abbreviation;

 // Reverse-lookup map for getting a day from an abbreviation
 private static final Map<String, Day> lookup_0 = new HashMap<String, Day>();
 
 
 
 // Populate the lookup table on loading time
 static {
  for (Day d : Day.values()) {
   lookup_0.put(d.getAbbreviation(), d);
  }
 }
 //Alternative way populating lookup table
 /*
 static {
  for (Day d : EnumSet.allOf(Day.class)) {
   lookup_0.put(d.getAbbreviation(), d);
  }
 }*/

 //Constructor
 private Day(final String abbreviation) {
  this.abbreviation = abbreviation;
 }

 public String getAbbreviation() {
  return abbreviation;
 }
 
 // This method can be used for reverse lookup purpose
 public static Day get(String abbreviation) {
  return (Day)lookup_0.get(abbreviation);
 }
 
 public static Day findByAbbr(String abbreviation){
     for(Day d : values()){
         if( d.abbreviation.equals(abbreviation)){
             return d;
         }
     }
     return null;
 }
}


Tuesday, May 31, 2016

Eclipse connectivity issue with Corporate Proxy

Overview 

Some applications we use need to access the web through the Corporate proxy and pull in content. In many cases what happens is the request fails as the application is unable to negotiate the connection using the NTLM protocol. Examples of this are the Marketplace in Eclipse Luna or installing packages with npm.
Cntlm is a tool that will work around this problem by proxying these requests locally and talking to the Corporate proxy to establish a connection. From the project website: "Cntlm is an NTLM / NTLMv2 authenticating HTTP/1.1 proxy. It caches auth'd connections for reuse, offers TCP/IP tunneling (port forwarding) thru parent proxy and much much more."

Setup Instructions

  1. Download and install cntlm from http://sourceforge.net/projects/cntlm/
  2. Edit C:\Program Files (x86)\Cntlm\cntlm.ini and make the following changes (make sure you are running your text editor as administrator​):​
    a. Add your Corporate username
    Username <corporate proxy server login>

    b. Comment out domain (we don’t need it)
    # Domain    corp-uk

    c. Change Proxy and Add additional NoProxy
    Proxy           <HTTPPROXYNAME>:<PORT>
    NoProxy         localhost, 127.0.0.*

    d. Get password hash from the command line
    > cd "C:\Program Files (x86)\Cntlm\"
    > cntlm -H -c cntlm.ini

    e. Paste the resulting 3 lines, which contain hashes of your password, back into your config.ini:
    PassLM          <HASH>
    PassNT          <HASH>
    PassNTLMv2      <HASH>    # Only for user <USERNAME>, domain '<HTTP PROXY NAME>'

    f. Comment out clear text password parameter
    # Password <fake password>

    g. Start CNTLM
    See instructions in README.txt (in the cntlm installation directory)

    h. Test CNTLM from the comand line
    > cntlm -M http://www.google.com

    After entering your Corporate password when prompted, you should see a response similar to the following (the HTTP 200 response indicating a success):

    Config profile  1/4... OK (HTTP code: 200)
    ----------------------------[ Profile  0 ]------
    Auth            NTLMv2
    PassNTLMv2      <your password hash>
    ------------------------------------------------
  3. Reboot your computer.  CNTLM will be installed and will run as a windows service and you won't have sto start it again manually unless of course you stop it manually.
After configuring and starting cntlm, applications should be able to access the web with no further action needed.

Changing CNTLM Password After CORPORATE Password Reset

  1. Get password hash from the command line
    > cd "C:\Program Files (x86)\Cntlm\"
    > cntlm -H -c cntlm.ini
  2. Copy the resulting 3 lines, which contain hashes of your passwordPassLM <HASH>
    PassNT <HASH>
    PassNTLMv2 <HASH> # Only for user <USERNAME>, domain '<HTTPPROXYHOST>'
  3. Open the cntlm.ini (configuration setting file) and replace (paste) the information from step two into your cntlm.ini file.
  4. Save, stop then start cntlm.  Information on how to do that can be found in the "Starting/Stopping CNTLM Manually" section below.

Starting/Stopping CNTLM Manually

  1. To start stop CNTLM manually open a command prompt as an Administrator
  2. To stop CNTLM type
    1. net stop cntlm
  3. To start CNTLM type:
    1. net start cntlm

Further info

Cntlm technical manual

How to Configure Eclipse Proxy Settings

Note: If installing from an external site hangs at “calculating requirements and dependencies” after following the instructions here, try unchecking the "Contact all update sites during install" box.
Beginning with Eclipse version 4.4 (Luna), special steps are needed in order for Eclipse to contact external sites (e.g. to install updates or plugins).
If when attempting to install plugins or open the Eclipse Marketplace, you receive an error stating "Proxy Authentication Required", this article is for you.

Background

The cause of the proxy error is a new set of HTTP client libraries that Eclipse uses beginning with v4.4. Removing those libraries, along with configuring Eclipse to talk to the proxy, will cause Eclipse to fall back on the JRE HTTP client libs. This should resolve the issue.

Part A: Configure Eclipse's Proxy Settings

First, you must configure Eclipse to play nice with the proxy by doing the following:
  1. In Eclipse go to Window>Preferences>General>Network Connections
  2. Choose Manual for the Active Provider
  3. For both HTTP and HTTPS, enter the following settings:
    • Host: <PROXY HOST>
    • Port: <PROXY PORT>
    • User: <PROXY USERID>
    • Password <PROXY USER PASSWORD>
    Note you will need to update this each time you change your password.
  4. Click OK to save your settings.

Part B: Remove Problematic Libraries

With Eclipse not running, go to Eclipse's plugins directory (e.g. C:\Program Files\Eclipse\plugins) and delete or rename the following three .jar files:

org.eclipse.ecf.provider.filetransfer.httpclient4.ssl_1.0.0.v20140528-1625.jar
org.eclipse.ecf.provider.filetransfer.httpclient4_1.0.500.v20140528-1625.jar
org.eclipse.ecf.provider.filetransfer.ssl_1.0.0.v20140528-1625.jar

After performing parts A and B above, Eclipse should be able to contact external update sites without any issues.    Notes
This information was compiled from this StackOverflow question and this bug report comment on the Eclipse bug tracker.

In addition to above 2 parts, see if https://wiki.eclipse.org/Disabling_Apache_Httpclient helps or
configure the following in eclipse.ini file.
-Djava.net.preferIPv4Stack=true
-Declipse.p2.unsignedPolicy=allow
-Dcom.sun.management.jmxremote
-Dorg.eclipse.ecf.provider.filetransfer.excludeContributors=org.eclipse.ecf.provider.filetransfer.httpclient4


Thursday, May 12, 2016



Best way to create a Singleton Pattern.


The Singleton Design Pattern is one of the Creational (creation of instance in best possible way) patterns.

The usage of enum, a new feature from Java5, allows safe way to implement Singleton design pattern as Java ensures that any enum value is instantiated only once in memory (JVM).

This singleton instance is accessible from anywhere since Java Enum values are globally accessible.

The drawback is that the enum type is somewhat inflexible as it does not allow lazy
initialization.

package org.comp.core;
public enum MyEnumSingleton {
INSTANCE;

       private MyEnumSingleton(){}


  public static void method1(){

//Do something 
}

  public static List buildStateCodeList(){
              final List<String>  stateCodeList = new ArrayList<String>();
             stateCodeList.add("AR");
             stateCodeList.add("AZ");
             ....
             ....
             return stateCodeList ;
}
}

From Caller:
List<String> stateCode_USA_List = MyEnumSingleton.INSTANCE.buildStateCodeList();


The following is more appropriate in  Distributed environment.   

package org.comp.core;
import java.io.*;
public class MySerializedSingleton implements Serializable{
private static final long serialVersionUID = -12345678923456789123L;
// Private/default constructor
private MySerializedSingleton(){}
//Inner static class to create instance (A safer way)
private static class MySingletonHelper{
private static final MySerializedSingleton instance = new MySerializedSingleton();
}

//Return singleton instance
public static MySerializedSingleton getInstance(){
return MySingletonHelper.instance;
}

/**
* Implement the readResolve() method to avoid creating a new instance in 'Deserialization'            scenario.  
*/
protected Object readResolve() {
return getInstance();
}

}