18
18
from datetime import datetime
19
19
from functools import partial , wraps
20
20
from threading import RLock
21
+ import warnings
21
22
22
23
############################
23
24
# python 2 -> 3 "hacks"
@@ -214,53 +215,103 @@ def listdir(directory):
214
215
return contents
215
216
216
217
217
- def getFlavour (ceName ):
218
+ def getSubmitterInfo (ceName ):
219
+ """Get information about the submitter of the pilot.
220
+
221
+ Check the environment variables to determine the type of batch system and CE used
222
+ to submit the pilot being used and return this information in a tuple.
223
+ """
218
224
219
225
pilotReference = os .environ .get ("DIRAC_PILOT_STAMP" , "" )
226
+ # Batch system taking care of the pilot
227
+ # Might be useful to extract the info to interact with it later on
228
+ batchSystemType = "Unknown"
229
+ batchSystemJobID = "Unknown"
230
+ batchSystemParameters = {
231
+ "BinaryPath" : "Unknown" ,
232
+ "Host" : "Unknown" ,
233
+ "InfoPath" : "Unknown" ,
234
+ "Queue" : "Unknown" ,
235
+ }
236
+ # Flavour of the pilot
237
+ # Inform whether the pilot was sent through SSH+batch system or a CE
220
238
flavour = "DIRAC"
221
239
222
240
# # Batch systems
223
241
224
- # Take the reference from the Torque batch system
242
+ # Torque
225
243
if "PBS_JOBID" in os .environ :
226
- flavour = "SSHTorque"
227
- pilotReference = "sshtorque://" + ceName + "/" + os .environ ["PBS_JOBID" ].split ("." )[0 ]
244
+ batchSystemType = "PBS"
245
+ batchSystemJobID = os .environ ["PBS_JOBID" ]
246
+ batchSystemParameters ["BinaryPath" ] = os .environ .get ("PBS_O_PATH" , "Unknown" )
247
+ batchSystemParameters ["Queue" ] = os .environ .get ("PBS_O_QUEUE" , "Unknown" )
228
248
229
- # Take the reference from the OAR batch system
249
+ flavour = "SSH%s" % batchSystemType
250
+ pilotReference = "sshpbs://" + ceName + "/" + batchSystemJobID .split ("." )[0 ]
251
+
252
+ # OAR
230
253
if "OAR_JOBID" in os .environ :
231
- flavour = "SSHOAR"
232
- pilotReference = "sshoar://" + ceName + "/" + os .environ ["OAR_JOBID" ]
254
+ batchSystemType = "OAR"
255
+ batchSystemJobID = os .environ ["OAR_JOBID" ]
256
+
257
+ flavour = "SSH%s" % batchSystemType
258
+ pilotReference = "sshoar://" + ceName + "/" + batchSystemJobID
233
259
234
260
# Grid Engine
235
- if "JOB_ID" in os .environ and "SGE_TASK_ID" in os .environ :
236
- flavour = "SSHGE"
237
- pilotReference = "sshge://" + ceName + "/" + os .environ ["JOB_ID" ]
238
- # Generic JOB_ID
239
- elif "JOB_ID" in os .environ :
240
- flavour = "Generic"
241
- pilotReference = "generic://" + ceName + "/" + os .environ ["JOB_ID" ]
261
+ if "SGE_TASK_ID" in os .environ :
262
+ batchSystemType = "SGE"
263
+ batchSystemJobID = os .environ ["JOB_ID" ]
264
+ batchSystemParameters ["BinaryPath" ] = os .environ .get ("SGE_BINARY_PATH" , "Unknown" )
265
+ batchSystemParameters ["Queue" ] = os .environ .get ("QUEUE" , "Unknown" )
266
+
267
+ flavour = "SSH%s" % batchSystemType
268
+ pilotReference = "sshge://" + ceName + "/" + batchSystemJobID
242
269
243
270
# LSF
244
271
if "LSB_BATCH_JID" in os .environ :
245
- flavour = "SSHLSF"
246
- pilotReference = "sshlsf://" + ceName + "/" + os .environ ["LSB_BATCH_JID" ]
272
+ batchSystemType = "LSF"
273
+ batchSystemJobID = os .environ ["LSB_BATCH_JID" ]
274
+ batchSystemParameters ["BinaryPath" ] = os .environ .get ("LSF_BINDIR" , "Unknown" )
275
+ batchSystemParameters ["Host" ] = os .environ .get ("LSB_HOSTS" , "Unknown" )
276
+ batchSystemParameters ["InfoPath" ] = os .environ .get ("LSF_ENVDIR" , "Unknown" )
277
+ batchSystemParameters ["Queue" ] = os .environ .get ("LSB_QUEUE" , "Unknown" )
247
278
248
- # SLURM batch system
279
+ flavour = "SSH%s" % batchSystemType
280
+ pilotReference = "sshlsf://" + ceName + "/" + batchSystemJobID
281
+
282
+ # SLURM
249
283
if "SLURM_JOBID" in os .environ :
250
- flavour = "SSHSLURM"
251
- pilotReference = "sshslurm://" + ceName + "/" + os .environ ["SLURM_JOBID" ]
284
+ batchSystemType = "SLURM"
285
+ batchSystemJobID = os .environ ["SLURM_JOBID" ]
286
+
287
+ flavour = "SSH%s" % batchSystemType
288
+ pilotReference = "sshslurm://" + ceName + "/" + batchSystemJobID
252
289
253
290
# Condor
254
291
if "CONDOR_JOBID" in os .environ :
255
- flavour = "SSHCondor"
256
- pilotReference = "sshcondor://" + ceName + "/" + os .environ ["CONDOR_JOBID" ]
292
+ batchSystemType = "HTCondor"
293
+ batchSystemJobID = os .environ ["CONDOR_JOBID" ]
294
+ batchSystemParameters ["InfoPath" ] = os .environ .get ("_CONDOR_JOB_AD" , "Unknown" )
257
295
258
- # # CEs
296
+ flavour = "SSH%s" % batchSystemType
297
+ pilotReference = "sshcondor://" + ceName + "/" + batchSystemJobID
298
+
299
+ # # CEs/Batch Systems
259
300
260
301
# HTCondor
261
302
if "HTCONDOR_JOBID" in os .environ :
303
+ batchSystemType = "HTCondor"
304
+ batchSystemJobID = os .environ ["HTCONDOR_JOBID" ]
305
+
262
306
flavour = "HTCondorCE"
263
- pilotReference = "htcondorce://" + ceName + "/" + os .environ ["HTCONDOR_JOBID" ]
307
+ pilotReference = "htcondorce://" + ceName + "/" + batchSystemJobID
308
+
309
+ # # Local/SSH
310
+
311
+ # Local submission to the host
312
+ if "LOCAL_JOBID" in os .environ :
313
+ flavour = "Local"
314
+ pilotReference = "local://" + ceName + "/" + os .environ ["LOCAL_JOBID" ]
264
315
265
316
# Direct SSH tunnel submission
266
317
if "SSHCE_JOBID" in os .environ :
@@ -274,6 +325,8 @@ def getFlavour(ceName):
274
325
"sshbatchhost://" + ceName + "/" + os .environ ["SSH_NODE_HOST" ] + "/" + os .environ ["SSHBATCH_JOBID" ]
275
326
)
276
327
328
+ # # CEs
329
+
277
330
# ARC
278
331
if "GRID_GLOBAL_JOBURL" in os .environ :
279
332
flavour = "ARC"
@@ -284,9 +337,18 @@ def getFlavour(ceName):
284
337
flavour = "VMDIRAC"
285
338
pilotReference = "vm://" + ceName + "/" + os .environ ["JOB_ID" ]
286
339
287
- return flavour , pilotReference
340
+ return flavour , pilotReference , { "Type" : batchSystemType , "JobID" : batchSystemJobID , "Parameters" : batchSystemParameters }
288
341
289
342
343
+ def getFlavour (ceName ):
344
+ """Old method to get the flavour of the pilot. Deprecated.
345
+
346
+ Please use getSubmitterInfo instead.
347
+ """
348
+ warnings .warn ("getFlavour() is deprecated. Please use getSubmitterInfo() instead." , category = DeprecationWarning , stacklevel = 2 )
349
+ flavour , pilotReference , _ = getSubmitterInfo (ceName )
350
+ return flavour , pilotReference
351
+
290
352
class ObjectLoader (object ):
291
353
"""Simplified class for loading objects from a DIRAC installation.
292
354
@@ -834,6 +896,7 @@ def __init__(self):
834
896
self .stopOnApplicationFailure = True
835
897
self .stopAfterFailedMatches = 10
836
898
self .flavour = "DIRAC"
899
+ self .batchSystemInfo = {}
837
900
self .pilotReference = ""
838
901
self .releaseVersion = ""
839
902
self .releaseProject = ""
0 commit comments