17
17
TQ_MIN_SHARE = 0.001
18
18
19
19
# For checks at insertion time, and not only
20
- singleValueDefFields = ("OwnerDN " , "OwnerGroup" , "CPUTime" )
20
+ singleValueDefFields = ("Owner " , "OwnerGroup" , "CPUTime" )
21
21
multiValueDefFields = ("Sites" , "GridCEs" , "BannedSites" , "Platforms" , "JobTypes" , "Tags" )
22
22
23
23
# Used for matching
@@ -94,14 +94,15 @@ def __initializeDB(self):
94
94
self .__tablesDesc ["tq_TaskQueues" ] = {
95
95
"Fields" : {
96
96
"TQId" : "INTEGER(11) UNSIGNED AUTO_INCREMENT NOT NULL" ,
97
- "OwnerDN" : "VARCHAR(255) NOT NULL" ,
97
+ "Owner" : "VARCHAR(255) NOT NULL" ,
98
+ "OwnerDN" : "VARCHAR(255)" ,
98
99
"OwnerGroup" : "VARCHAR(32) NOT NULL" ,
99
100
"CPUTime" : "BIGINT(20) UNSIGNED NOT NULL" ,
100
101
"Priority" : "FLOAT NOT NULL" ,
101
102
"Enabled" : "TINYINT(1) NOT NULL DEFAULT 0" ,
102
103
},
103
104
"PrimaryKey" : "TQId" ,
104
- "Indexes" : {"TQOwner" : ["OwnerDN " , "OwnerGroup" , "CPUTime" ]},
105
+ "Indexes" : {"TQOwner" : ["Owner " , "OwnerGroup" , "CPUTime" ]},
105
106
}
106
107
107
108
self .__tablesDesc ["tq_Jobs" ] = {
@@ -167,11 +168,9 @@ def _checkTaskQueueDefinition(self, tqDefDict):
167
168
"""
168
169
169
170
for field in singleValueDefFields :
170
- if field not in tqDefDict :
171
- return S_ERROR (f"Missing mandatory field '{ field } ' in task queue definition" )
172
- if field in ["CPUTime" ]:
171
+ if field == "CPUTime" :
173
172
if not isinstance (tqDefDict [field ], int ):
174
- return S_ERROR (f"Mandatory field { field } value type is not valid: { type (tqDefDict [field ])} " )
173
+ return S_ERROR (f"Mandatory field 'CPUTime' value type is not valid: { type (tqDefDict ['CPUTime' ])} " )
175
174
else :
176
175
if not isinstance (tqDefDict [field ], str ):
177
176
return S_ERROR (f"Mandatory field { field } value type is not valid: { type (tqDefDict [field ])} " )
@@ -261,7 +260,7 @@ def __createTaskQueue(self, tqDefDict, priority=1, connObj=False):
261
260
)
262
261
result = self ._update (cmd , conn = connObj )
263
262
if not result ["OK" ]:
264
- self .log .error ("Can't insert TQ in DB" , result ["Value " ])
263
+ self .log .error ("Can't insert TQ in DB" , result ["Message " ])
265
264
return result
266
265
if "lastRowId" in result :
267
266
tqId = result ["lastRowId" ]
@@ -383,7 +382,7 @@ def insertJob(self, jobId, tqDefDict, jobPriority, skipTQDefCheck=False):
383
382
self .log .error ("Error inserting job in TQ" , f"Job { jobId } TQ { tqId } : { result ['Message' ]} " )
384
383
return result
385
384
if newTQ :
386
- self .recalculateTQSharesForEntity (tqDefDict ["OwnerDN " ], tqDefDict ["OwnerGroup" ], connObj = connObj )
385
+ self .recalculateTQSharesForEntity (tqDefDict ["Owner " ], tqDefDict ["OwnerGroup" ], connObj = connObj )
387
386
finally :
388
387
self .__setTaskQueueEnabled (tqId , True )
389
388
return S_OK ()
@@ -549,7 +548,7 @@ def matchAndGetJob(self, tqMatchDict, numJobsPerTry=50, numQueuesPerTry=10, nega
549
548
if not tqList :
550
549
self .log .info ("No TQ matches requirements" )
551
550
return S_OK ({"matchFound" : False , "tqMatch" : tqMatchDict })
552
- for tqId , tqOwnerDN , tqOwnerGroup in tqList :
551
+ for tqId , tqOwner , tqOwnerGroup in tqList :
553
552
self .log .verbose ("Trying to extract jobs from TQ" , tqId )
554
553
retVal = self ._query (prioSQL % tqId , conn = connObj )
555
554
if not retVal ["OK" ]:
@@ -564,7 +563,7 @@ def matchAndGetJob(self, tqMatchDict, numJobsPerTry=50, numQueuesPerTry=10, nega
564
563
jobTQList = [(row [0 ], row [1 ]) for row in retVal ["Value" ]]
565
564
if not jobTQList :
566
565
self .log .info ("Task queue seems to be empty, triggering a cleaning of" , tqId )
567
- self .__deleteTQWithDelay .add (tqId , 300 , (tqId , tqOwnerDN , tqOwnerGroup ))
566
+ self .__deleteTQWithDelay .add (tqId , 300 , (tqId , tqOwner , tqOwnerGroup ))
568
567
while jobTQList :
569
568
jobId , tqId = jobTQList .pop (random .randint (0 , len (jobTQList ) - 1 ))
570
569
self .log .verbose ("Trying to extract job from TQ" , f"{ jobId } : { tqId } " )
@@ -681,25 +680,22 @@ def __generateTQMatchSQL(self, tqMatchDict, numQueuesToGet=1, negativeCond=None)
681
680
# Only enabled TQs
682
681
sqlCondList = []
683
682
sqlTables = {"tq_TaskQueues" : "tq" }
684
- # If OwnerDN and OwnerGroup are defined only use those combinations that make sense
685
- if "OwnerDN " in tqMatchDict and "OwnerGroup" in tqMatchDict :
683
+ # If Owner and OwnerGroup are defined only use those combinations that make sense
684
+ if "Owner " in tqMatchDict and "OwnerGroup" in tqMatchDict :
686
685
groups = tqMatchDict ["OwnerGroup" ]
687
686
if not isinstance (groups , (list , tuple )):
688
687
groups = [groups ]
689
- dns = tqMatchDict ["OwnerDN" ]
690
- if not isinstance (dns , (list , tuple )):
691
- dns = [dns ]
688
+ owner = tqMatchDict ["Owner" ]
692
689
ownerConds = []
693
690
for group in groups :
694
691
if Properties .JOB_SHARING in Registry .getPropertiesForGroup (group .replace ('"' , "" )):
695
692
ownerConds .append (f"tq.OwnerGroup = { group } " )
696
693
else :
697
- for dn in dns :
698
- ownerConds .append (f"( tq.OwnerDN = { dn } AND tq.OwnerGroup = { group } )" )
694
+ ownerConds .append (f"( tq.Owner = { owner } AND tq.OwnerGroup = { group } )" )
699
695
sqlCondList .append (" OR " .join (ownerConds ))
700
696
else :
701
697
# If not both are defined, just add the ones that are defined
702
- for field in ("OwnerGroup" , "OwnerDN " ):
698
+ for field in ("OwnerGroup" , "Owner " ):
703
699
if field in tqMatchDict :
704
700
sqlCondList .append (self .__generateSQLSubCond ("tq.%s = %%s" % field , tqMatchDict [field ]))
705
701
# Type of single value conditions
@@ -829,7 +825,7 @@ def __generateTQMatchSQL(self, tqMatchDict, numQueuesToGet=1, negativeCond=None)
829
825
sqlCondList .append (self .__generateNotSQL (negativeCond ))
830
826
831
827
# Generate the final query string
832
- tqSqlCmd = "SELECT tq.TQId, tq.OwnerDN , tq.OwnerGroup FROM `tq_TaskQueues` tq WHERE %s" % (
828
+ tqSqlCmd = "SELECT tq.TQId, tq.Owner , tq.OwnerGroup FROM `tq_TaskQueues` tq WHERE %s" % (
833
829
" AND " .join (sqlCondList )
834
830
)
835
831
@@ -883,7 +879,7 @@ def deleteJob(self, jobId, connObj=False):
883
879
return S_ERROR (f"Can't delete job: { retVal ['Message' ]} " )
884
880
connObj = retVal ["Value" ]
885
881
retVal = self ._query (
886
- "SELECT t.TQId, t.OwnerDN , t.OwnerGroup \
882
+ "SELECT t.TQId, t.Owner , t.OwnerGroup \
887
883
FROM `tq_TaskQueues` t, `tq_Jobs` j \
888
884
WHERE j.JobId = %s AND t.TQId = j.TQId"
889
885
% jobId ,
@@ -894,7 +890,7 @@ def deleteJob(self, jobId, connObj=False):
894
890
data = retVal ["Value" ]
895
891
if not data :
896
892
return S_OK (False )
897
- tqId , tqOwnerDN , tqOwnerGroup = data [0 ]
893
+ tqId , tqOwner , tqOwnerGroup = data [0 ]
898
894
self .log .verbose ("Deleting job" , jobId )
899
895
retVal = self ._update (f"DELETE FROM `tq_Jobs` WHERE JobId = { jobId } " , conn = connObj )
900
896
if not retVal ["OK" ]:
@@ -903,7 +899,7 @@ def deleteJob(self, jobId, connObj=False):
903
899
# No job deleted
904
900
return S_OK (False )
905
901
# Always return S_OK() because job has already been taken out from the TQ
906
- self .__deleteTQWithDelay .add (tqId , 300 , (tqId , tqOwnerDN , tqOwnerGroup ))
902
+ self .__deleteTQWithDelay .add (tqId , 300 , (tqId , tqOwner , tqOwnerGroup ))
907
903
return S_OK (True )
908
904
909
905
def getTaskQueueForJob (self , jobId , connObj = False ):
@@ -928,7 +924,7 @@ def getTaskQueueForJob(self, jobId, connObj=False):
928
924
return S_OK (retVal ["Value" ][0 ][0 ])
929
925
930
926
def __getOwnerForTaskQueue (self , tqId , connObj = False ):
931
- retVal = self ._query (f"SELECT OwnerDN , OwnerGroup from `tq_TaskQueues` WHERE TQId={ tqId } " , conn = connObj )
927
+ retVal = self ._query (f"SELECT Owner , OwnerGroup from `tq_TaskQueues` WHERE TQId={ tqId } " , conn = connObj )
932
928
if not retVal ["OK" ]:
933
929
return retVal
934
930
data = retVal ["Value" ]
@@ -937,16 +933,16 @@ def __getOwnerForTaskQueue(self, tqId, connObj=False):
937
933
return S_OK (retVal ["Value" ][0 ])
938
934
939
935
def __deleteTQIfEmpty (self , args ):
940
- (tqId , tqOwnerDN , tqOwnerGroup ) = args
936
+ (tqId , tqOwner , tqOwnerGroup ) = args
941
937
retries = 3
942
938
while retries :
943
939
retries -= 1
944
- result = self .deleteTaskQueueIfEmpty (tqId , tqOwnerDN , tqOwnerGroup )
940
+ result = self .deleteTaskQueueIfEmpty (tqId , tqOwner , tqOwnerGroup )
945
941
if result ["OK" ]:
946
942
return
947
943
self .log .error ("Could not delete TQ" , f"{ tqId } : { result ['Message' ]} " )
948
944
949
- def deleteTaskQueueIfEmpty (self , tqId , tqOwnerDN = False , tqOwnerGroup = False , connObj = False ):
945
+ def deleteTaskQueueIfEmpty (self , tqId , tqOwner = False , tqOwnerGroup = False , connObj = False ):
950
946
"""
951
947
Try to delete a task queue if its empty
952
948
"""
@@ -956,14 +952,14 @@ def deleteTaskQueueIfEmpty(self, tqId, tqOwnerDN=False, tqOwnerGroup=False, conn
956
952
self .log .error ("Can't insert job" , retVal ["Message" ])
957
953
return retVal
958
954
connObj = retVal ["Value" ]
959
- if not tqOwnerDN or not tqOwnerGroup :
955
+ if not tqOwner or not tqOwnerGroup :
960
956
retVal = self .__getOwnerForTaskQueue (tqId , connObj = connObj )
961
957
if not retVal ["OK" ]:
962
958
return retVal
963
959
data = retVal ["Value" ]
964
960
if not data :
965
961
return S_OK (False )
966
- tqOwnerDN , tqOwnerGroup = data
962
+ tqOwner , tqOwnerGroup = data
967
963
968
964
sqlCmd = f"SELECT TQId FROM `tq_TaskQueues` WHERE Enabled >= 1 AND `tq_TaskQueues`.TQId = { tqId } "
969
965
sqlCmd += "AND `tq_TaskQueues`.TQId not in ( SELECT DISTINCT TQId from `tq_Jobs` )"
@@ -981,7 +977,7 @@ def deleteTaskQueueIfEmpty(self, tqId, tqOwnerDN=False, tqOwnerGroup=False, conn
981
977
retVal = self ._update (f"DELETE FROM `tq_TaskQueues` WHERE TQId = { tqId } " , conn = connObj )
982
978
if not retVal ["OK" ]:
983
979
return retVal
984
- self .recalculateTQSharesForEntity (tqOwnerDN , tqOwnerGroup , connObj = connObj )
980
+ self .recalculateTQSharesForEntity (tqOwner , tqOwnerGroup , connObj = connObj )
985
981
self .log .info ("Deleted empty and enabled TQ" , tqId )
986
982
return S_OK ()
987
983
return S_OK (False )
@@ -1093,20 +1089,20 @@ def recalculateTQSharesForAll(self):
1093
1089
self .recalculateTQSharesForEntity ("all" , group )
1094
1090
return S_OK ()
1095
1091
1096
- def recalculateTQSharesForEntity (self , userDN , userGroup , connObj = False ):
1092
+ def recalculateTQSharesForEntity (self , user , userGroup , connObj = False ):
1097
1093
"""
1098
- Recalculate the shares for a userDN /userGroup combo
1094
+ Recalculate the shares for a user /userGroup combo
1099
1095
"""
1100
- self .log .info ("Recalculating shares" , f"for { userDN } @{ userGroup } TQs" )
1096
+ self .log .info ("Recalculating shares" , f"for { user } @{ userGroup } TQs" )
1101
1097
if userGroup in self .__groupShares :
1102
1098
share = self .__groupShares [userGroup ]
1103
1099
else :
1104
1100
share = float (DEFAULT_GROUP_SHARE )
1105
1101
if Properties .JOB_SHARING in Registry .getPropertiesForGroup (userGroup ):
1106
- # If group has JobSharing just set prio for that entry, userDN is irrelevant
1107
- return self .__setPrioritiesForEntity (userDN , userGroup , share , connObj = connObj )
1102
+ # If group has JobSharing just set prio for that entry, user is irrelevant
1103
+ return self .__setPrioritiesForEntity (user , userGroup , share , connObj = connObj )
1108
1104
1109
- selSQL = "SELECT Owner, COUNT(Owner) FROM `tq_TaskQueues` WHERE OwnerGroup='%s ' GROUP BY Owner" % ( userGroup )
1105
+ selSQL = f "SELECT Owner, COUNT(Owner) FROM `tq_TaskQueues` WHERE OwnerGroup='{ userGroup } ' GROUP BY Owner"
1110
1106
result = self ._query (selSQL , conn = connObj )
1111
1107
if not result ["OK" ]:
1112
1108
return result
@@ -1126,26 +1122,26 @@ def recalculateTQSharesForEntity(self, userDN, userGroup, connObj=False):
1126
1122
owners = dict (data )
1127
1123
# IF the user is already known and has more than 1 tq, the rest of the users don't need to be modified
1128
1124
# (The number of owners didn't change)
1129
- if userDN in owners and owners [userDN ] > 1 :
1130
- return self .__setPrioritiesForEntity (userDN , userGroup , entitiesShares [userDN ], connObj = connObj )
1125
+ if user in owners and owners [user ] > 1 :
1126
+ return self .__setPrioritiesForEntity (user , userGroup , entitiesShares [user ], connObj = connObj )
1131
1127
# Oops the number of owners may have changed so we recalculate the prio for all owners in the group
1132
- for userDN in owners :
1133
- self .__setPrioritiesForEntity (userDN , userGroup , entitiesShares [userDN ], connObj = connObj )
1128
+ for user in owners :
1129
+ self .__setPrioritiesForEntity (user , userGroup , entitiesShares [user ], connObj = connObj )
1134
1130
return S_OK ()
1135
1131
1136
- def __setPrioritiesForEntity (self , userDN , userGroup , share , connObj = False , consolidationFunc = "AVG" ):
1132
+ def __setPrioritiesForEntity (self , user , userGroup , share , connObj = False , consolidationFunc = "AVG" ):
1137
1133
"""
1138
- Set the priority for a userDN /userGroup combo given a splitted share
1134
+ Set the priority for a user /userGroup combo given a splitted share
1139
1135
"""
1140
- self .log .info ("Setting priorities" , f"to { userDN } @{ userGroup } TQs" )
1136
+ self .log .info ("Setting priorities" , f"to { user } @{ userGroup } TQs" )
1141
1137
tqCond = [f"t.OwnerGroup='{ userGroup } '" ]
1142
1138
allowBgTQs = gConfig .getValue (f"/Registry/Groups/{ userGroup } /AllowBackgroundTQs" , False )
1143
1139
if Properties .JOB_SHARING not in Registry .getPropertiesForGroup (userGroup ):
1144
- res = self ._escapeString (userDN )
1140
+ res = self ._escapeString (user )
1145
1141
if not res ["OK" ]:
1146
1142
return res
1147
1143
userDN = res ["Value" ]
1148
- tqCond .append (f"t.OwnerDN = { userDN } " )
1144
+ tqCond .append (f"t.Owner = { user } " )
1149
1145
tqCond .append ("t.TQId = j.TQId" )
1150
1146
if consolidationFunc == "AVG" :
1151
1147
selectSQL = "SELECT j.TQId, SUM( j.RealPriority )/COUNT(j.RealPriority) \
0 commit comments