Skip to content

Commit

Permalink
reformat PreJob. Fix #8938 (#8949)
Browse files Browse the repository at this point in the history
  • Loading branch information
belforte authored Feb 27, 2025
1 parent 4f7e4c9 commit c51853e
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 121 deletions.
19 changes: 19 additions & 0 deletions src/python/ServerUtilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -1168,3 +1168,22 @@ def getRucioAccountFromLFN(lfn):
return "{0}_group".format(account)
return account
raise Exception("Expected /store/(user,group)/rucio/<account>, got {0}".format(lfn))


def pythonListToClassAdExprTree(aList):
# arg: aList : list of strings
# return: value : a string representing the classAd value
# transforms a python list of strings into a string containing the
# internal (ExprTree) representation of a ClassAd such that the ad
# will be converted to a python list when used like : myList = ad['myAd']
# https://htcondor.readthedocs.io/en/latest/apis/python-bindings/api/version2/classad2/classad.html#classad2.ClassAd
# inside python we can simply do ad['myAd'] = myList but if we want
# to create the ad in a submitted job via the JDL MY.<attribute> command
# https://htcondor.readthedocs.io/en/latest/man-pages/condor_submit.html#submit-description-file-commands
# the python list [a, b, c] needs to become '{"a","b","c"}'
# i.e. a string with the ExprTree representatio of a ClassAd list
import json
quotedItems = json.dumps(aList) # from [s1, s2] to the string '["s1","s2"]'
quotedItems = quotedItems.lstrip('[').rstrip(']') # remove square brackets [ ]
value = "{" + quotedItems + "}" # make final string adding the curly brackets { }
return value
24 changes: 11 additions & 13 deletions src/python/TaskWorker/Actions/DagmanCreator.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from ast import literal_eval

from ServerUtilities import MAX_DISK_SPACE, MAX_IDLE_JOBS, MAX_POST_JOBS, TASKLIFETIME
from ServerUtilities import getLock, checkS3Object
from ServerUtilities import getLock, checkS3Object, pythonListToClassAdExprTree

import TaskWorker.DataObjects.Result
from TaskWorker.Actions.TaskAction import TaskAction
Expand Down Expand Up @@ -340,17 +340,16 @@ def makeJobSubmit(self, task):
jobSubmit['My.CRAB_PublishDBSURL'] = classad.quote(task['tm_publish_dbs_url'])
jobSubmit['My.CRAB_ISB'] = classad.quote(task['tm_cache_url'])

def pythonListToClassAdValue(aList):
# python lists need special handling to become the string '{"a","b",...,"c"}'
quotedItems = json.dumps(aList) # from [s1, s2] to the string '["s1","s2"]'
quotedItems = quotedItems.lstrip('[').rstrip(']') # remove square brackets [ ]
value = "{" + quotedItems + "}" # make final string adding the curly brackets { }
return value
jobSubmit['My.CRAB_SiteBlacklist'] = pythonListToClassAdValue(task['tm_site_blacklist'])
jobSubmit['My.CRAB_SiteWhitelist'] = pythonListToClassAdValue(task['tm_site_whitelist'])
jobSubmit['My.CRAB_AdditionalOutputFiles'] = pythonListToClassAdValue(task['tm_outfiles'])
jobSubmit['My.CRAB_EDMOutputFiles'] = pythonListToClassAdValue(task['tm_edm_outfiles'])
jobSubmit['My.CRAB_TFileOutputFiles'] = pythonListToClassAdValue(task['tm_outfiles'])

# note about Lists
# in the JDL everything is a string, we can't use the simple classAd[name]=somelist
# but need the ExprTree format (what classAd.lookup() would return)
jobSubmit['My.CRAB_SiteBlacklist'] = pythonListToClassAdExprTree(task['tm_site_blacklist'])
jobSubmit['My.CRAB_SiteWhitelist'] = pythonListToClassAdExprTree(task['tm_site_whitelist'])
jobSubmit['My.CRAB_AdditionalOutputFiles'] = pythonListToClassAdExprTree(task['tm_outfiles'])
jobSubmit['My.CRAB_EDMOutputFiles'] = pythonListToClassAdExprTree(task['tm_edm_outfiles'])
jobSubmit['My.CRAB_TFileOutputFiles'] = pythonListToClassAdExprTree(task['tm_outfiles'])

jobSubmit['My.CRAB_UserDN'] = classad.quote(task['tm_user_dn'])
jobSubmit['My.CRAB_UserHN'] = classad.quote(task['tm_username'])
jobSubmit['My.CRAB_AsyncDest'] = classad.quote(task['tm_asyncdest'])
Expand Down Expand Up @@ -709,7 +708,6 @@ def prepareJobArguments(self, dagSpecs, task):
argDict['eventsPerLumi'] = task['tm_events_per_lumi'] #
argDict['maxRuntime'] = dagspec['maxRuntime'] # -1
argDict['scriptArgs'] = task['tm_scriptargs']
argDict['CRAB_AdditionalOutputFiles'] = "{}"
# following one are for bkw compat. with CRABClient v3.241218 or earlier, to be removed
argDict['CRAB_Archive'] = argDict['userSandbox']
argDict['CRAB_ISB'] = 'dummy'
Expand Down
27 changes: 13 additions & 14 deletions src/python/TaskWorker/Actions/DagmanResubmitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import HTCondorLocator

from ServerUtilities import FEEDBACKMAIL
from ServerUtilities import FEEDBACKMAIL, pythonListToClassAdExprTree
from TaskWorker.Actions.TaskAction import TaskAction
from TaskWorker.Actions.DagmanSubmitter import checkMemoryWalltime
from TaskWorker.WorkerExceptions import TaskWorkerException
Expand Down Expand Up @@ -70,7 +70,6 @@ def executeInternal(self, *args, **kwargs): #pylint: disable=unused-argument

## Calculate new parameters for resubmitted jobs. These parameters will
## be (re)written in the _CONDOR_JOB_AD when we do schedd.edit() below.
ad = classad.ClassAd()
params = {'CRAB_ResubmitList' : 'jobids',
'CRAB_SiteBlacklist' : 'site_blacklist',
'CRAB_SiteWhitelist' : 'site_whitelist',
Expand All @@ -79,13 +78,7 @@ def executeInternal(self, *args, **kwargs): #pylint: disable=unused-argument
'CRAB_RequestedCpus' : 'numcores',
'JobPrio' : 'priority'
}
for taskparam in params.values():
if ('resubmit_'+taskparam in task) and task['resubmit_'+taskparam] is not None:
# the following seems to Stefano a very complicated way to handle
# in different (proper) way the cases where resubmit_xxxx is list and
# where it is a number. Should be verified and simplified
if isinstance(task['resubmit_'+taskparam], list):
ad[taskparam] = task['resubmit_'+taskparam]

if ('resubmit_jobids' in task) and task['resubmit_jobids']:
self.logger.debug("Resubmitting when JOBIDs were specified")
try:
Expand All @@ -94,12 +87,18 @@ def executeInternal(self, *args, **kwargs): #pylint: disable=unused-argument
# all the jobs, not only the ones we want to resubmit. That's why the pre-job
# is saving the values of the parameters for each job retry in text files (the
# files are in the directory resubmit_info in the schedd).
# We use classAds here as way to pass informations to PreJobs.
# Value in schedd.exit(const, ad, value) can be string or ExprTree
# https://htcondor.readthedocs.io/en/latest/apis/python-bindings/api/version2/htcondor2/schedd.html#htcondor2.Schedd.edit
# We need ExprTree when the ad correspond to a python list
for adparam, taskparam in params.items():
if taskparam in ad:
schedd.edit(rootConst, adparam, ad.lookup(taskparam))
elif task['resubmit_' + taskparam] is not None:
# param values set in this case are numbers, need to convert to strings
schedd.edit(rootConst, adparam, str(task['resubmit_' + taskparam]))
if task['resubmit_' + taskparam] is not None:
if isinstance(task['resubmit_'+taskparam], list):
newAdValue = pythonListToClassAdExprTree(task['resubmit_'+taskparam])
else:
newAdValue = str(task['resubmit_'+taskparam])
schedd.edit(rootConst, adparam, newAdValue)
# finally restart the dagman with the 3 lines below
schedd.act(htcondor.JobAction.Hold, rootConst)
schedd.edit(rootConst, "HoldKillSig", 'SIGUSR1')
schedd.act(htcondor.JobAction.Release, rootConst)
Expand Down
Loading

0 comments on commit c51853e

Please sign in to comment.