protected URI createUri ( String file , DatanodeID [ ] candidates , UnixUserGroupInformation ugi , HttpServletRequest request ) throws URISyntaxException { String scheme = request . getScheme ( ) ; final DatanodeID host = candidates [ 0 ] ; final String hostname ; if ( host instanceof DatanodeInfo ) { hostname = ( ( DatanodeInfo ) host ) . getHostName ( ) ; } else { hostname = host . getHost ( ) ; } // Construct query. StringBuilder builder = new StringBuilder ( ) ; builder . append ( "ugi=" + ugi ) ; // Populate the rest of parameters. Enumeration < ? > it = request . getParameterNames ( ) ; while ( it . hasMoreElements ( ) ) { String key = it . nextElement ( ) . toString ( ) ; String value = request . getParameter ( key ) ; builder . append ( "&" + key + "=" + value ) ; } // Construct the possible candidates for retry if ( candidates . length > 1 ) { builder . append ( "&candidates=" ) ; appendDatanodeID ( builder , candidates [ 1 ] ) ; for ( int j = 2 ; j < candidates . length ; j ++ ) { builder . append ( " " ) ; appendDatanodeID ( builder , candidates [ j ] ) ; } } // Add namenode address to the url params NameNode nn = ( NameNode ) getServletContext ( ) . getAttribute ( "name.node" ) ; String addr = NetUtils . toIpPort ( nn . getNameNodeAddress ( ) ) ; builder . append ( JspHelper . getUrlParam ( JspHelper . NAMENODE_ADDRESS , addr ) ) ; return new URI ( scheme , null , hostname , "https" . equals ( scheme ) ? ( Integer ) getServletContext ( ) . getAttribute ( "datanode.https.port" ) : host . getInfoPort ( ) , "/streamFile" + file , builder . toString ( ) , null ) ; }
Create a URI for streaming a file