Skip to content

Commit 0d1f540

Browse files
committed
Fixes for transferring files from external services using the http protocol. Automatic file transfers from Pac Bio SMRT Portal are functional for version 1.1.0.
1 parent f514b94 commit 0d1f540

File tree

8 files changed

+49
-18
lines changed

8 files changed

+49
-18
lines changed

external_service_types/pacific_biosciences_smrt_portal.xml

-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
<description></description>
33
<version>1</version>
44
<data_transfer_settings>
5-
<!--
6-
<data_transfer protocol='scp' automatic_transfer='True' host='host' user_name='user_name' password='password' data_location='data_location' />
7-
-->
85
<data_transfer protocol='http' automatic_transfer='True' />
96
</data_transfer_settings>
107
<run_details>

lib/galaxy/jobs/deferred/data_transfer.py

+9-6
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
import logging, urllib2, re, shutil
55

66
from galaxy import eggs
7-
from galaxy.util import json
8-
from string import Template
97
from sqlalchemy import and_
108

119
from galaxy.util.odict import odict
@@ -19,6 +17,8 @@
1917

2018
log = logging.getLogger( __name__ )
2119

20+
__all__ = [ 'DataTransfer' ]
21+
2222
class DataTransfer( object ):
2323
check_interval = 15
2424
dataset_name_re = re.compile( '(dataset\d+)_(name)' )
@@ -36,7 +36,10 @@ def run_job( self, job ):
3636
if job.params[ 'protocol' ] in [ 'http', 'https' ]:
3737
results = []
3838
for result in job.params[ 'results' ].values():
39-
result[ 'transfer_job' ] = self.app.transfer_manager.new( protocol=job.params[ 'protocol' ], url=result[ 'url' ] )
39+
result[ 'transfer_job' ] = self.app.transfer_manager.new( protocol=job.params[ 'protocol' ],
40+
name=result[ 'name' ],
41+
datatype=result[ 'datatype' ],
42+
url=result[ 'url' ] )
4043
results.append( result )
4144
elif job.params[ 'protocol' ] == 'scp':
4245
results = []
@@ -83,9 +86,9 @@ def run_job( self, job ):
8386
# Update the state of the relevant SampleDataset
8487
new_status = self.app.model.SampleDataset.transfer_status.ADD_TO_LIBRARY
8588
if protocol in [ 'http', 'https' ]:
86-
result_dict = job.params[ 'results' ]
87-
library_dataset_name = job.params[ 'result' ][ 'name' ]
88-
extension = job.params[ 'result' ][ 'datatype' ]
89+
result_dict = job.params[ 'result' ]
90+
library_dataset_name = result_dict[ 'name' ]
91+
extension = result_dict[ 'datatype' ]
8992
elif protocol in [ 'scp' ]:
9093
# In this case, job.params will be a dictionary that contains a key named 'result'. The value
9194
# of the result key is a dictionary that looks something like:

lib/galaxy/jobs/deferred/pacific_biosciences_smrt_portal.py

+14-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
produced by SMRT Portal.
44
"""
55
import logging, urllib2, re, shutil
6+
from string import Template
7+
from galaxy.util import json
8+
69
from data_transfer import *
710

811
log = logging.getLogger( __name__ )
@@ -18,9 +21,16 @@ def create_job( self, trans, **kwd ):
1821
sample = kwd[ 'sample' ]
1922
smrt_job_id = kwd[ 'secondary_analysis_job_id' ]
2023
external_service = sample.request.type.get_external_service( 'pacific_biosciences_smrt_portal' )
24+
external_service.load_data_transfer_settings( trans )
25+
http_configs = external_service.data_transfer[ trans.model.ExternalService.data_transfer_protocol.HTTP ]
26+
if not http_configs[ 'automatic_transfer' ]:
27+
raise Exception( "Manual data transfer using http is not yet supported." )
2128
smrt_host = external_service.form_values.content[ 'host' ]
22-
external_service_type_id = external_service.external_service_type_id
23-
external_service_type = self.app.external_service_types.all_external_service_types[ external_service_type_id ]
29+
external_service_type = external_service.get_external_service_type( trans )
30+
# TODO: is there a better way to store the protocol?
31+
# external_service_type.data_transfer looks somethng like
32+
# {'http': <galaxy.sample_tracking.data_transfer.HttpDataTransferFactory object at 0x1064239d0>}
33+
protocol = external_service_type.data_transfer.keys()[0]
2434
results = {}
2535
for k, v in external_service.form_values.content.items():
2636
match = self.dataset_name_re.match( k ) or self.dataset_datatype_re.match( k )
@@ -42,6 +52,7 @@ def create_job( self, trans, **kwd ):
4252
self.sa_session.add(sample)
4353
self.sa_session.flush()
4454
params = { 'type' : 'init_transfer',
55+
'protocol' : protocol,
4556
'sample_id' : sample.id,
4657
'results' : results,
4758
'smrt_host' : smrt_host,
@@ -50,6 +61,7 @@ def create_job( self, trans, **kwd ):
5061
self._associate_untransferred_datasets_with_sample( sample, external_service, results )
5162
elif 'transfer_job_id' in kwd:
5263
params = { 'type' : 'finish_transfer',
64+
'protocol' : kwd[ 'result' ][ 'protocol' ],
5365
'sample_id' : kwd[ 'sample_id' ],
5466
'result' : kwd[ 'result' ],
5567
'transfer_job_id' : kwd[ 'transfer_job_id' ] }

lib/galaxy/jobs/transfer_manager.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,13 @@ def new( self, path=None, **kwd ):
3030
if protocol in [ 'http', 'https' ]:
3131
if 'url' not in kwd:
3232
raise Exception( 'Missing required parameter "url".' )
33-
transfer_job = self.app.model.TransferJob( state=self.app.model.TransferJob.states.NEW, params=kwd )
3433
elif protocol == 'scp':
3534
# TODO: add more checks here?
3635
if 'sample_dataset_id' not in kwd:
3736
raise Exception( 'Missing required parameter "sample_dataset_id".' )
3837
if 'file_path' not in kwd:
3938
raise Exception( 'Missing required parameter "file_path".' )
40-
transfer_job = self.app.model.TransferJob( state=self.app.model.TransferJob.states.NEW, params=kwd )
39+
transfer_job = self.app.model.TransferJob( state=self.app.model.TransferJob.states.NEW, params=kwd )
4140
self.sa_session.add( transfer_job )
4241
self.sa_session.flush()
4342
return transfer_job

lib/galaxy/model/__init__.py

+5
Original file line numberDiff line numberDiff line change
@@ -1825,6 +1825,11 @@ def load_data_transfer_settings( self, trans ):
18251825
scp_configs[ 'data_location' ] = self.form_values.content.get( data_transfer_obj.config.get( 'data_location', '' ), '' )
18261826
scp_configs[ 'rename_dataset' ] = self.form_values.content.get( data_transfer_obj.config.get( 'rename_dataset', '' ), '' )
18271827
self.data_transfer[ self.data_transfer_protocol.SCP ] = scp_configs
1828+
if data_transfer_protocol == self.data_transfer_protocol.HTTP:
1829+
http_configs = {}
1830+
automatic_transfer = data_transfer_obj.config.get( 'automatic_transfer', 'false' )
1831+
http_configs[ 'automatic_transfer' ] = util.string_as_bool( automatic_transfer )
1832+
self.data_transfer[ self.data_transfer_protocol.HTTP ] = http_configs
18281833
def populate_actions( self, trans, item, param_dict=None ):
18291834
return self.get_external_service_type( trans ).actions.populate( self, item, param_dict=param_dict )
18301835

lib/galaxy/sample_tracking/data_transfer.py

+14-3
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,23 @@ def parse( self, config_file, elem ):
2727
# Validate
2828
for name, value in self.config.items():
2929
assert value, "'%s' attribute missing in 'data_transfer' element of type 'scp' in external_service_type xml config file: '%s'." % ( name, config_file )
30-
30+
31+
class HttpDataTransferFactory( DataTransferFactory ):
32+
type = 'http'
33+
def __init__( self ):
34+
pass
35+
def parse( self, config_file, elem ):
36+
self.config = {}
37+
self.config[ 'automatic_transfer' ] = elem.get( 'automatic_transfer' )
38+
# Validate
39+
for name, value in self.config.items():
40+
assert value, "'%s' attribute missing in 'data_transfer' element of type 'http' in external_service_type xml config file: '%s'." % ( name, config_file )
41+
3142
class FtpDataTransferFactory( DataTransferFactory ):
3243
type = 'ftp'
3344
def __init__( self ):
3445
pass
3546
def parse( self, elem ):
3647
pass
37-
38-
data_transfer_factories = dict( [ ( data_transfer.type, data_transfer() ) for data_transfer in [ ScpDataTransferFactory, FtpDataTransferFactory ] ] )
48+
49+
data_transfer_factories = dict( [ ( data_transfer.type, data_transfer() ) for data_transfer in [ ScpDataTransferFactory, HttpDataTransferFactory, FtpDataTransferFactory ] ] )

lib/galaxy/sample_tracking/external_service_types.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,16 @@ def parse( self, root ):
8484
def parse_data_transfer_settings( self, root ):
8585
self.data_transfer = {}
8686
data_transfer_settings_elem = root.find( 'data_transfer_settings' )
87-
# Currently only data transfer using scp is supported.
87+
# Currently only data transfer using scp or http is supported.
8888
for data_transfer_elem in data_transfer_settings_elem.findall( "data_transfer" ):
8989
if data_transfer_elem.get( 'protocol' ) == model.ExternalService.data_transfer_protocol.SCP:
9090
scp_data_transfer = data_transfer_factories[ model.ExternalService.data_transfer_protocol.SCP ]
9191
scp_data_transfer.parse( self.config_file, data_transfer_elem )
9292
self.data_transfer[ model.ExternalService.data_transfer_protocol.SCP ] = scp_data_transfer
93+
if data_transfer_elem.get( 'protocol' ) == model.ExternalService.data_transfer_protocol.HTTP:
94+
http_data_transfer = data_transfer_factories[ model.ExternalService.data_transfer_protocol.HTTP ]
95+
http_data_transfer.parse( self.config_file, data_transfer_elem )
96+
self.data_transfer[ model.ExternalService.data_transfer_protocol.HTTP ] = http_data_transfer
9397
def parse_run_details( self, root ):
9498
self.run_details = {}
9599
run_details_elem = root.find( 'run_details' )

lib/galaxy/web/controllers/requests_admin.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ def initiate_data_transfer( self, trans, sample_id, sample_datasets=[], sample_d
671671
if not scp_configs[ 'automatic_transfer' ]:
672672
deferred_plugin = 'ManualDataTransferPlugin'
673673
else:
674-
raise Exception( "Automatic data transfer using scp is not yet suppored." )
674+
raise Exception( "Automatic data transfer using scp is not yet supported." )
675675
trans.app.job_manager.deferred_job_queue.plugins[ deferred_plugin ].create_job( trans,
676676
sample=sample,
677677
sample_datasets=sample_datasets,

0 commit comments

Comments
 (0)