def execute(sqlQuery): global sqlTableContent if ( sqlTableContent == None ): sqlTableContent = generateTableContent() global reExp sqlQuery = sqlQuery.replace('\n',' ') dateMatch = reExp.match(sqlQuery) if dateMatch == None: raise Exception("Misspecified query argument:"+sqlQuery) startDateS = dateMatch.group(1) endDateS = dateMatch.group(2) limitS = dateMatch.group(3) startDate = DateStrToSecs(startDateS) endDate = DateStrToSecs(endDateS) limit = int(limitS) results = [] for r in sqlTableContent: recordTime = r['tm'] if ( recordTime >= startDate and recordTime < endDate ): results.append(r.copy()) if ( len(results) == limit ): break if ( len(results) != 0 ): TestContainer.sendInterrupt(300) return results
def _processDBRow(self, row): """ Completely process a single DB row. Take the row, convert it to a UsageRecord, and send it up to Gratia. Process any recoverable errors which occurred during the process. Note we skip a row if it is an Intra-site transfer and we are instructed not to send them. Otherwise, we process the row in Gratia or exit the probe. @return: The number of jobs in this row, regardless of whether we sent them successfully or not. """ # Skip intra-site transfers if required if self._skipIntraSiteXfer(row): return row['njobs'] if ( TestContainer.isTest() ): if ( self._summarize ): TestContainer.sendInterrupt(15) return TestContainer.processRow(row,self._log) usageRecord = self._convertBillingInfoToGratiaUsageRecord(\ row) # Send to gratia, and see what it says. response = Gratia.Send(usageRecord) baseMsg = "Record: %s, %s, njobs %i" % (str(row['datestamp']), row['transaction'], row['njobs']) if response == "Fatal Error: too many pending files": # The server is currently not accepting record and # Gratia.py was not able to store the record, we will # need to resend it. # For now take a long nap and then by 'break' we # force a retry for this record. self._log.error("Error sending : too many pending files") longsleep = 15*60 self._log.warn("sleeping for = %i seconds." % longsleep) sleep_check(longsleep, self._stopFileName) elif response.startswith('Fatal Error') or \ response.startswith('Internal Error'): self._log.critical('error sending ' + baseMsg + \ '\ngot response ' + response) sys.exit(2) self._log.debug('sent ' + baseMsg) # If we got a non-fatal error, slow down since the server # might be overloaded. if response[:2] != 'OK': self._log.error('error sending ' + baseMsg + \ '\ngot response ' + response) return row['njobs']
def _processDBRow(self, row): """ Completely process a single DB row. Take the row, convert it to a UsageRecord, and send it up to Gratia. Process any recoverable errors which occurred during the process. Note we skip a row if it is an Intra-site transfer and we are instructed not to send them. Otherwise, we process the row in Gratia or exit the probe. @return: The number of jobs in this row, regardless of whether we sent them successfully or not. """ # Skip intra-site transfers if required if self._skipIntraSiteXfer(row): return row['njobs'] if (TestContainer.isTest()): if (self._summarize): TestContainer.sendInterrupt(15) return TestContainer.processRow(row, self._log) usageRecord = self._convertBillingInfoToGratiaUsageRecord(\ row) # Send to gratia, and see what it says. response = Gratia.Send(usageRecord) baseMsg = "Record: %s, %s, njobs %i" % (str( row['datestamp']), row['transaction'], row['njobs']) if response == "Fatal Error: too many pending files": # The server is currently not accepting record and # Gratia.py was not able to store the record, we will # need to resend it. # For now take a long nap and then by 'break' we # force a retry for this record. self._log.error("Error sending : too many pending files") longsleep = 15 * 60 self._log.warn("sleeping for = %i seconds." % longsleep) sleep_check(longsleep, self._stopFileName) elif response.startswith('Fatal Error') or \ response.startswith('Internal Error'): self._log.critical('error sending ' + baseMsg + \ '\ngot response ' + response) sys.exit(2) self._log.debug('sent ' + baseMsg) # If we got a non-fatal error, slow down since the server # might be overloaded. if response[:2] != 'OK': self._log.error('error sending ' + baseMsg + \ '\ngot response ' + response) return row['njobs']