@@ -136,13 +136,46 @@ def __init__(self, name, description, can_be_submitted_to_ebi,
136
136
137
137
138
138
class BaseQiitaPlugin (object ):
139
- def __init__ (self , name , version , description , publications = None ):
139
+ _DEFAULT_PLUGIN_COUPLINGS = 'filesystem'
140
+ _ALLOWED_PLUGIN_COUPLINGS = [_DEFAULT_PLUGIN_COUPLINGS , 'https' ]
141
+
142
+ def __init__ (self , name , version , description , publications = None ,
143
+ plugincoupling = _DEFAULT_PLUGIN_COUPLINGS ):
140
144
logger .debug ('Entered BaseQiitaPlugin.__init__()' )
141
145
self .name = name
142
146
self .version = version
143
147
self .description = description
144
148
self .publications = dumps (publications ) if publications else ""
145
149
150
+ # Depending on your compute architecture, there are multiple options
151
+ # available how "thight" plugins are coupled to the central
152
+ # Qiita master/workers
153
+ # --- filesystem ---
154
+ # The default scenario is "filesystem", i.e. plugins as well as
155
+ # master/worker have unrestricted direct access to a shared filesystem,
156
+ # e.g. a larger volume / directory, defined in the server configuration
157
+ # as base_data_dir
158
+ # --- https ---
159
+ # A second scenario is that your plugins execute as independent jobs on
160
+ # another machine, e.g. as docker containers or other cloud techniques.
161
+ # Intentionally, you don't want to use a shared filesystem, but you
162
+ # have to make sure necessary input files are provided to the
163
+ # containerized plugin before execution and resulting files are
164
+ # transfered back to the central Qiita master/worker. In this case,
165
+ # files are pulled / pushed through functions
166
+ # qiita_client.fetch_file_from_central and
167
+ # qiita_client.push_file_to_central, respectivey.
168
+ # Actually, all files need to be decorated with this function.
169
+ # The decision how data are transferred is then made within these two
170
+ # functions according to the "plugincoupling" setting.
171
+ if plugincoupling not in self ._ALLOWED_PLUGIN_COUPLINGS :
172
+ raise ValueError (
173
+ ("valid plugincoupling values are ['%s'], but you "
174
+ "provided %s" ) % (
175
+ "', '" .join (self ._ALLOWED_PLUGIN_COUPLINGS ),
176
+ plugincoupling ))
177
+ self .plugincoupling = plugincoupling
178
+
146
179
# Will hold the different commands
147
180
self .task_dict = {}
148
181
@@ -151,7 +184,8 @@ def __init__(self, name, version, description, publications=None):
151
184
'QIITA_PLUGINS_DIR' , join (expanduser ('~' ), '.qiita_plugins' ))
152
185
self .conf_fp = join (conf_dir , "%s_%s.conf" % (self .name , self .version ))
153
186
154
- def generate_config (self , env_script , start_script , server_cert = None ):
187
+ def generate_config (self , env_script , start_script , server_cert = None ,
188
+ plugin_coupling = _DEFAULT_PLUGIN_COUPLINGS ):
155
189
"""Generates the plugin configuration file
156
190
157
191
Parameters
@@ -165,6 +199,9 @@ def generate_config(self, env_script, start_script, server_cert=None):
165
199
If the Qiita server used does not have a valid certificate, the
166
200
path to the Qiita certificate so the plugin can connect over
167
201
HTTPS to it
202
+ plugin_coupling : str
203
+ Type of coupling of plugin to central for file exchange.
204
+ Valid values: see _ALLOWED_PLUGIN_COUPLINGS.
168
205
"""
169
206
logger .debug ('Entered BaseQiitaPlugin.generate_config()' )
170
207
sr = SystemRandom ()
@@ -178,7 +215,8 @@ def generate_config(self, env_script, start_script, server_cert=None):
178
215
f .write (CONF_TEMPLATE % (self .name , self .version , self .description ,
179
216
env_script , start_script ,
180
217
self ._plugin_type , self .publications ,
181
- server_cert , client_id , client_secret ))
218
+ server_cert , client_id , client_secret ,
219
+ plugin_coupling ))
182
220
183
221
def _register_command (self , command ):
184
222
"""Registers a command in the plugin
@@ -188,8 +226,8 @@ def _register_command(self, command):
188
226
command: QiitaCommand
189
227
The command to be added to the plugin
190
228
"""
191
- logger .debug (
192
- f'Entered BaseQiitaPlugin._register_command( { command .name } )' )
229
+ logger .debug ('Entered BaseQiitaPlugin._register_command(%s)' %
230
+ command .name )
193
231
self .task_dict [command .name ] = command
194
232
195
233
def _register (self , qclient ):
@@ -244,14 +282,23 @@ def __call__(self, server_url, job_id, output_dir):
244
282
with open (self .conf_fp , 'U' ) as conf_file :
245
283
config .readfp (conf_file )
246
284
285
+ plugincoupling = self ._DEFAULT_PLUGIN_COUPLINGS
286
+ if config .has_section ('network' ) and \
287
+ config .has_option ('network' , 'PLUGINCOUPLING' ):
288
+ plugincoupling = config .get ('network' , 'PLUGINCOUPLING' )
289
+ if 'QIITA_PLUGINCOUPLING' in environ .keys () and \
290
+ environ ['QIITA_PLUGINCOUPLING' ] is not None :
291
+ plugincoupling = environ ['QIITA_PLUGINCOUPLING' ]
292
+
247
293
qclient = QiitaClient (server_url , config .get ('oauth2' , 'CLIENT_ID' ),
248
294
config .get ('oauth2' , 'CLIENT_SECRET' ),
249
295
# for this group of tests, confirm optional
250
296
# ca_cert parameter works as intended. Setting
251
297
# this value will prevent underlying libraries
252
298
# from validating the server's cert using
253
299
# certifi's pem cache.
254
- ca_cert = config .get ('oauth2' , 'SERVER_CERT' ))
300
+ ca_cert = config .get ('oauth2' , 'SERVER_CERT' ),
301
+ plugincoupling = plugincoupling )
255
302
256
303
if job_id == 'register' :
257
304
self ._register (qclient )
@@ -314,9 +361,11 @@ class QiitaTypePlugin(BaseQiitaPlugin):
314
361
_plugin_type = "artifact definition"
315
362
316
363
def __init__ (self , name , version , description , validate_func ,
317
- html_generator_func , artifact_types , publications = None ):
364
+ html_generator_func , artifact_types , publications = None ,
365
+ plugincoupling = BaseQiitaPlugin ._DEFAULT_PLUGIN_COUPLINGS ):
318
366
super (QiitaTypePlugin , self ).__init__ (name , version , description ,
319
- publications = publications )
367
+ publications = publications ,
368
+ plugincoupling = plugincoupling )
320
369
321
370
logger .debug ('Entered QiitaTypePlugin.__init__()' )
322
371
self .artifact_types = artifact_types
@@ -382,4 +431,8 @@ def register_command(self, command):
382
431
[oauth2]
383
432
SERVER_CERT = %s
384
433
CLIENT_ID = %s
385
- CLIENT_SECRET = %s"""
434
+ CLIENT_SECRET = %s
435
+
436
+ [network]
437
+ PLUGINCOUPLING = %s
438
+ """
0 commit comments