From 24ee1a5db2bcc6225969c98ce92d12fd796a8e95 Mon Sep 17 00:00:00 2001 From: ricardo Date: Wed, 25 Apr 2012 11:40:32 +0200 Subject: [PATCH 1/3] FIX: increase from 10 to 100, so a restart on the Agents does not block --- RequestManagementSystem/DB/RequestDBMySQL.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/RequestManagementSystem/DB/RequestDBMySQL.py b/RequestManagementSystem/DB/RequestDBMySQL.py index 761370bf03a..4182aa6b38c 100755 --- a/RequestManagementSystem/DB/RequestDBMySQL.py +++ b/RequestManagementSystem/DB/RequestDBMySQL.py @@ -295,8 +295,8 @@ def getRequest( self, requestType ): req = "SELECT * from SubRequests WHERE Status IN ( 'Waiting', 'Assigned' ) ORDER BY ExecutionOrder, LastUpdate" # now get sorted list of RequestID (according to the above) req = "SELECT * from ( %s ) as T1 GROUP BY RequestID" % req - # and get the 10 oldest ones of Type requestType - req = "SELECT RequestID, ExecutionOrder FROM ( %s ) as T2 WHERE RequestType = %s ORDER BY LastUpdate limit 10" % ( req, myRequestType ) + # and get the 100 oldest ones of Type requestType + req = "SELECT RequestID, ExecutionOrder FROM ( %s ) as T2 WHERE RequestType = %s ORDER BY LastUpdate limit 100" % ( req, myRequestType ) # and now get all waiting SubRequest for the selected RequestID and ExecutionOrder req = "SELECT A.%s FROM SubRequests AS A, ( %s ) AS B WHERE " % ( ', A.'.join( fields ), req ) req = "%s A.RequestID = B.RequestID AND A.ExecutionOrder = B.ExecutionOrder AND A.Status = 'Waiting' AND A.RequestType = %s;" % ( req, myRequestType ) From f4d952b281e32e115262a8f1e58eb097a18543d2 Mon Sep 17 00:00:00 2001 From: ricardo Date: Wed, 25 Apr 2012 11:49:14 +0200 Subject: [PATCH 2/3] FIX: protect in case of unexpected error return --- WorkloadManagementSystem/DB/JobDB.py | 46 ++++++++++++++++------------ 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/WorkloadManagementSystem/DB/JobDB.py b/WorkloadManagementSystem/DB/JobDB.py index d5afed307f6..f046c0feab3 100755 --- a/WorkloadManagementSystem/DB/JobDB.py +++ b/WorkloadManagementSystem/DB/JobDB.py @@ -1332,10 +1332,10 @@ def insertNewJobIntoDB( self, jdl, owner, ownerDN, ownerGroup, diracSetup ): classAdJob.insertAttributeInt( 'JobRequirements', reqJDL ) jobJDL = classAdJob.asJDL() - + # Replace the JobID placeholder if any - if jobJDL.find('%j') != -1: - jobJDL = jobJDL.replace('%j',str(jobID)) + if jobJDL.find( '%j' ) != -1: + jobJDL = jobJDL.replace( '%j', str( jobID ) ) result = self.setJobJDL( jobID, jobJDL ) if not result['OK']: @@ -1415,7 +1415,7 @@ def __checkAndPrepareJob( self, jobID, classAdJob, classAdReq, owner, ownerDN, classAdJob.insertAttributeString( 'OwnerGroup', ownerGroup ) if vo: classAdJob.insertAttributeString( 'VirtualOrganization', vo ) - submitPool = getVOOption(vo,'SubmitPools') + submitPool = getVOOption( vo, 'SubmitPools' ) if submitPool and not classAdJob.lookupAttribute( 'SubmitPools' ): classAdJob.insertAttributeString( 'SubmitPools', submitPool ) @@ -1666,8 +1666,8 @@ def rescheduleJob ( self, jobID ): site = classAdJob.getAttributeString( 'Site' ) if not site: site = 'ANY' - elif site.find(',') > 0: - site = "Multiple" + elif site.find( ',' ) > 0: + site = "Multiple" jobAttrNames.append( 'Site' ) jobAttrValues.append( site ) @@ -2008,20 +2008,26 @@ def getSiteSummaryWeb( self, selectDict, sortList, startItem, maxItems ): # Sort out different counters resultDict = {} - for attDict, count in result['Value']: - siteFullName = attDict['Site'] - status = attDict['Status'] - if not resultDict.has_key( siteFullName ): - resultDict[siteFullName] = {} - for state in JOB_STATES: - resultDict[siteFullName][state] = 0 - if status not in JOB_FINAL_STATES: - resultDict[siteFullName][status] = count - for attDict, count in resultDay['Value']: - siteFullName = attDict['Site'] - status = attDict['Status'] - if status in JOB_FINAL_STATES: - resultDict[siteFullName][status] = count + if result['OK']: + for attDict, count in result['Value']: + siteFullName = attDict['Site'] + status = attDict['Status'] + if not resultDict.has_key( siteFullName ): + resultDict[siteFullName] = {} + for state in JOB_STATES: + resultDict[siteFullName][state] = 0 + if status not in JOB_FINAL_STATES: + resultDict[siteFullName][status] = count + if resultDay['OK']: + for attDict, count in resultDay['Value']: + siteFullName = attDict['Site'] + if not resultDict.has_key( siteFullName ): + resultDict[siteFullName] = {} + for state in JOB_STATES: + resultDict[siteFullName][state] = 0 + status = attDict['Status'] + if status in JOB_FINAL_STATES: + resultDict[siteFullName][status] = count # Collect records now records = [] From ba867902c35997f935e61d0f252733af78b8e98f Mon Sep 17 00:00:00 2001 From: ricardo Date: Wed, 25 Apr 2012 11:52:36 +0200 Subject: [PATCH 3/3] FIX: escape all other types after converting them to strings, ie datetime,... --- Core/Utilities/MySQL.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Core/Utilities/MySQL.py b/Core/Utilities/MySQL.py index 4aaad4ad855..95638d3c6ee 100755 --- a/Core/Utilities/MySQL.py +++ b/Core/Utilities/MySQL.py @@ -156,6 +156,7 @@ from DIRAC import gLogger from DIRAC import S_OK, S_ERROR +from DIRAC import Time import MySQLdb # This is for proper initialization of embeded server, it should only be called once @@ -376,7 +377,11 @@ def _escapeValues( self, inValues = None ): return retDict inEscapeValues.append( retDict['Value'] ) else: - inEscapeValues.append( str( value ) ) + retDict = self.__escapeString( str( value ), connection ) + if not retDict['OK']: + self.__putConnection( connection ) + return retDict + inEscapeValues.append( retDict['Value'] ) self.__putConnection( connection ) return S_OK( inEscapeValues )