Friday, July 25, 2014

How to debug HDFS source in Eclipse

1.To debug hdfs locally, open the hadoop-env.sh file located in /etc/hadoop, inside your hadoop distribution.
2. Add the following line.
     export HADOOP_OPTS="-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5000"

3. Set the debug point from Eclipse to remote java debugging under port 5000, and you are good to go.

Friday, July 18, 2014

Re-reading Input streams in Java

There are certain cases, when you would want to re-read an InputStream rather than creating and closing it over and over again.

In a similar case, what you could do is, you can use the mark() and reset() methods provided in the JAVA API (http://docs.oracle.com/javase/7/docs/api/java/io/InputStream.html). You can invalidate the mark point by setting the read limit to -1, and then when you call reset it will reset the position to 0.

The mark should be called before the  InputStream is read, and the reset should be called after the InputStream in read.

Please refer the example below.

   InputStream is = <some input stream>;
   is.mark(-1); // invalidate mark point.

    String jsonBody = "";
    BufferedReader r = new BufferedReader(new      

    InputStreamReader(is));
    String line;
    try {
     while ((line = r.readLine()) != null) {
     jsonBody += line; //read the stream and build the JSON body
     }
    } catch(Exception e) {
   
    }finally{
        try {
            is.reset(); //reset the input stream. This will bring the position of the input stream to 0.
            }catch (IOException e) {
              e.printStackTrace();
        } 

Installing ssh in ubuntu

I tried to install ssh in ubuntu 13.10 , and faced many number of issues due to mirror site not being able to be detected. After following many instructions and going through many sites, the only answer that worked for me was found at superuser.com. Here Aamir mentions the following steps.

1) Edit the  sources.list file using  root user privileges.
      sudo vi /etc/apt/sources.list

2) Replace the content of the file by the contents found at https://gist.github.com/syst3mw0rm/8163897


#############################################################
################### OFFICIAL UBUNTU REPOS ###################
#############################################################
###### Ubuntu Main Repos
deb http://in.archive.ubuntu.com/ubuntu/ saucy main restricted universe
###### Ubuntu Update Repos
deb http://in.archive.ubuntu.com/ubuntu/ saucy-security main restricted universe
deb http://in.archive.ubuntu.com/ubuntu/ saucy-updates main restricted universe

3) Save the file.

4) Open a terminal and type

     sudo apt-get update

5) Check if all goes well in the above step, and then proceed to install ssh.
    
    sudo apt-get install ssh