@@ -66,7 +66,7 @@ class Connector(object):
6666 registered_clowder = list ()
6767
6868 def __init__ (self , extractor_name , extractor_info , check_message = None , process_message = None , ssl_verify = True ,
69- mounted_paths = None ):
69+ mounted_paths = None , clowder_url = None ):
7070 self .extractor_name = extractor_name
7171 self .extractor_info = extractor_info
7272 self .check_message = check_message
@@ -76,6 +76,7 @@ def __init__(self, extractor_name, extractor_info, check_message=None, process_m
7676 self .mounted_paths = {}
7777 else :
7878 self .mounted_paths = mounted_paths
79+ self .clowder_url = clowder_url
7980
8081 filename = 'notifications.json'
8182 self .smtp_server = None
@@ -373,19 +374,21 @@ def _process_message(self, body):
373374 if body .get ('notifies' ):
374375 emailaddrlist = body .get ('notifies' )
375376 logger .debug (emailaddrlist )
376- host = body .get ('host' , '' )
377- if host == '' :
377+ # source_host is original from the message, host is remapped to CLOWDER_URL if given
378+ source_host = body .get ('host' , '' )
379+ host = self .clowder_url if self .clowder_url is not None else source_host
380+ if host == '' or source_host == '' :
378381 return
379- elif not host .endswith ('/' ):
380- host += '/'
382+ if not source_host .endswith ('/' ): source_host += '/'
383+ if not host . endswith ( '/' ): host += '/'
381384 secret_key = body .get ('secretKey' , '' )
382385 retry_count = 0 if 'retry_count' not in body else body ['retry_count' ]
383386 resource = self ._build_resource (body , host , secret_key )
384387 if not resource :
385388 return
386389
387390 # register extractor
388- url = "%sapi/extractors" % host
391+ url = "%sapi/extractors" % source_host
389392 if url not in Connector .registered_clowder :
390393 Connector .registered_clowder .append (url )
391394 self .register_extractor ("%s?key=%s" % (url , secret_key ))
@@ -398,7 +401,7 @@ def _process_message(self, body):
398401 try :
399402 check_result = pyclowder .utils .CheckMessage .download
400403 if self .check_message :
401- check_result = self .check_message (self , host , secret_key , resource , body )
404+ check_result = self .check_message (self , source_host , secret_key , resource , body )
402405 if check_result != pyclowder .utils .CheckMessage .ignore :
403406 if self .process_message :
404407
@@ -418,10 +421,10 @@ def _process_message(self, body):
418421 found_local = True
419422 resource ['local_paths' ] = [file_path ]
420423
421- self .process_message (self , host , secret_key , resource , body )
424+ self .process_message (self , source_host , secret_key , resource , body )
422425
423- clowderurl = "%sfiles/%s" % (host , body .get ('id' , '' ))
424- # notificatino of extraction job is done by email.
426+ clowderurl = "%sfiles/%s" % (source_host , body .get ('id' , '' ))
427+ # notification of extraction job is done by email.
425428 self .email (emailaddrlist , clowderurl )
426429 finally :
427430 if file_path is not None and not found_local :
@@ -438,8 +441,8 @@ def _process_message(self, body):
438441 (file_paths , tmp_files , tmp_dirs ) = self ._prepare_dataset (host , secret_key , resource )
439442 resource ['local_paths' ] = file_paths
440443
441- self .process_message (self , host , secret_key , resource , body )
442- clowderurl = "%sdatasets/%s" % (host , body .get ('datasetId' , '' ))
444+ self .process_message (self , source_host , secret_key , resource , body )
445+ clowderurl = "%sdatasets/%s" % (source_host , body .get ('datasetId' , '' ))
443446 # notificatino of extraction job is done by email.
444447 self .email (emailaddrlist , clowderurl )
445448 finally :
@@ -624,9 +627,9 @@ class RabbitMQConnector(Connector):
624627 def __init__ (self , extractor_name , extractor_info ,
625628 rabbitmq_uri , rabbitmq_exchange = None , rabbitmq_key = None , rabbitmq_queue = None ,
626629 check_message = None , process_message = None , ssl_verify = True , mounted_paths = None ,
627- heartbeat = 5 * 60 ):
630+ heartbeat = 5 * 60 , clowder_url = None ):
628631 super (RabbitMQConnector , self ).__init__ (extractor_name , extractor_info , check_message , process_message ,
629- ssl_verify , mounted_paths )
632+ ssl_verify , mounted_paths , clowder_url )
630633 self .rabbitmq_uri = rabbitmq_uri
631634 self .rabbitmq_exchange = rabbitmq_exchange
632635 self .rabbitmq_key = rabbitmq_key
@@ -639,7 +642,7 @@ def __init__(self, extractor_name, extractor_info,
639642 self .consumer_tag = None
640643 self .worker = None
641644 self .announcer = None
642- self .heartbeat = 5 * 60
645+ self .heartbeat = heartbeat
643646
644647 def connect (self ):
645648 """connect to rabbitmq using URL parameters"""
@@ -770,7 +773,7 @@ def on_message(self, channel, method, header, body):
770773 job_id = json_body ['jobid' ]
771774
772775 self .worker = RabbitMQHandler (self .extractor_name , self .extractor_info , job_id , self .check_message ,
773- self .process_message , self .ssl_verify , self .mounted_paths ,
776+ self .process_message , self .ssl_verify , self .mounted_paths , self . clowder_url ,
774777 method , header , body )
775778 self .worker .start_thread (json_body )
776779
@@ -848,9 +851,10 @@ class RabbitMQHandler(Connector):
848851 """
849852
850853 def __init__ (self , extractor_name , extractor_info , job_id , check_message = None , process_message = None , ssl_verify = True ,
851- mounted_paths = None , method = None , header = None , body = None ):
854+ mounted_paths = None , clowder_url = None , method = None , header = None , body = None ):
855+
852856 super (RabbitMQHandler , self ).__init__ (extractor_name , extractor_info , check_message , process_message ,
853- ssl_verify , mounted_paths )
857+ ssl_verify , mounted_paths , clowder_url )
854858 self .method = method
855859 self .header = header
856860 self .body = body
0 commit comments