#NEWLINE# def uploadChunk( self , upload , chunk ) : #NEWLINE# #INDENT# url = 'http://%s:%d/webhdfs/v1%s?op=APPEND&namenoderpcaddress=%s:%d&user.name=%s' #NEWLINE# url %= ( self . assetstore [ 'hdfs' ] [ 'host' ] , self . assetstore [ 'hdfs' ] [ 'webHdfsPort' ] , self . _absPath ( upload ) , self . assetstore [ 'hdfs' ] [ 'host' ] , self . assetstore [ 'hdfs' ] [ 'port' ] , self . _getHdfsUser ( self . assetstore ) ) #NEWLINE# resp = requests . post ( chunk , allow_redirects = False ) #NEWLINE# try : #NEWLINE# #INDENT# resp . raise_for_status ( ) #NEWLINE# #UNINDENT# except Exception : #NEWLINE# #INDENT# logger . exception ( ( 'HDFS response: ' + resp . text ) ) #NEWLINE# raise Exception ( 'Error appending to HDFS, see log for details.' ) #NEWLINE# #UNINDENT# if ( resp . status_code != 307 ) : #NEWLINE# #INDENT# raise Exception ( ( 'Expected 307 redirection to data node, instead got %d: %s' % ( resp . status_code , resp . text ) ) ) #NEWLINE# #UNINDENT# resp = requests . post ( resp . headers [ 'Location' ] , data = chunk ) #NEWLINE# chunk . close ( ) #NEWLINE# try : #NEWLINE# #INDENT# resp . raise_for_status ( ) #NEWLINE# #UNINDENT# except Exception : #NEWLINE# #INDENT# logger . exception ( ( 'HDFS response: ' + resp . text ) ) #NEWLINE# raise Exception ( 'Error appending to HDFS, see log for details.' ) #NEWLINE# #UNINDENT# upload [ 'received' ] = self . requestOffset ( upload ) #NEWLINE# try : #NEWLINE# #INDENT# resp . raise_for_status ( ) #NEWLINE# #UNINDENT# except Exception : #NEWLINE# #INDENT# logger . exception ( ( 'HDFS response: ' + resp . text ) ) #NEWLINE# raise Exception ( 'Error appending to HDFS, see log for details.' ) #NEWLINE# #UNINDENT# return upload