private void writeDriverHttpEndPoint ( final File driverFolder , final String applicationId , final Path dfsPath ) throws IOException { final FileSystem fs = FileSystem . get ( yarnConfiguration ) ; final Path httpEndpointPath = new Path ( dfsPath , fileNames . getDriverHttpEndpoint ( ) ) ; String trackingUri = null ; LOG . log ( Level . INFO , "Attempt to reading " + httpEndpointPath . toString ( ) ) ; for ( int i = 0 ; i < 60 ; i ++ ) { try { LOG . log ( Level . FINE , "Attempt " + i + " reading " + httpEndpointPath . toString ( ) ) ; if ( fs . exists ( httpEndpointPath ) ) { final FSDataInputStream input = fs . open ( httpEndpointPath ) ; final BufferedReader reader = new BufferedReader ( new InputStreamReader ( input , StandardCharsets . UTF_8 ) ) ; trackingUri = reader . readLine ( ) ; reader . close ( ) ; break ; } } catch ( Exception ignored ) { // readLine might throw IOException although httpEndpointPath file exists. // the for-loop waits until the actual content of file is written completely } try { Thread . sleep ( 1000 ) ; } catch ( InterruptedException ex2 ) { break ; } } if ( null == trackingUri ) { trackingUri = "" ; LOG . log ( Level . WARNING , "Failed reading " + httpEndpointPath . toString ( ) ) ; } else { LOG . log ( Level . INFO , "Completed reading trackingUri :" + trackingUri ) ; } final File driverHttpEndpointFile = new File ( driverFolder , fileNames . getDriverHttpEndpoint ( ) ) ; BufferedWriter out = new BufferedWriter ( new OutputStreamWriter ( new FileOutputStream ( driverHttpEndpointFile ) , StandardCharsets . UTF_8 ) ) ; out . write ( applicationId + "\n" ) ; out . write ( trackingUri + "\n" ) ; String addr = yarnConfiguration . get ( "yarn.resourcemanager.webapp.address" ) ; if ( null == addr || addr . startsWith ( "0.0.0.0" ) ) { String str2 = yarnConfiguration . get ( "yarn.resourcemanager.ha.rm-ids" ) ; if ( null != str2 ) { for ( String rm : str2 . split ( "," ) ) { out . write ( yarnConfiguration . get ( "yarn.resourcemanager.webapp.address." + rm ) + "\n" ) ; } } } else { out . write ( addr + "\n" ) ; } out . close ( ) ; }
We leave a file behind in job submission directory so that clr client can figure out the applicationId and yarn rest endpoint .