private String getRunningDatanode ( Configuration conf ) throws IOException { FileSystem fs = FileSystem . newInstance ( conf ) ; fs . mkdirs ( new Path ( "/tmp" ) ) ; Path fileName = new Path ( "/tmp" , rtc . task_name + System . currentTimeMillis ( ) + rb . nextInt ( ) ) ; if ( fs . exists ( fileName ) ) { fs . delete ( fileName ) ; } FSDataOutputStream out = null ; byte [ ] buffer = new byte [ 1 ] ; buffer [ 0 ] = ' ' ; try { out = fs . create ( fileName , ( short ) 1 ) ; out . write ( buffer , 0 , 1 ) ; } finally { IOUtils . closeStream ( out ) ; } fs = getDFS ( fs ) ; assert fs instanceof DistributedFileSystem ; DistributedFileSystem dfs = ( DistributedFileSystem ) fs ; BlockLocation [ ] lbs = dfs . getClient ( ) . getBlockLocations ( fileName . toUri ( ) . getPath ( ) , 0 , 1 ) ; fs . delete ( fileName ) ; return lbs [ 0 ] . getHosts ( ) [ 0 ] ; }
Write a small file to figure out which datanode we are running