1# 2# Authors: Sergey Satskiy 3# 4# $Id: batchsubmitdroploader.py 309785 2011-06-28 13:46:22Z satskyse $ 5# 6 7""" 8NetScheduler Batch submit/drop loader 9""" 10 11import sys, time, threading 12from ns_traffic_settings import BatchSubmitDropSettings 13 14 15class BatchSubmitDropLoader( threading.Thread ): 16 " Batch submit/drop loader " 17 18 def __init__( self, gridClient, qname ): 19 threading.Thread.__init__( self ) 20 self.__gridClient = gridClient 21 self.__qname = qname 22 self.__count = 0 23 return 24 25 def getName( self ): 26 " Loader identification " 27 return "Batch submit/drop" 28 29 def getCount( self ): 30 " Provides haw many loops completed " 31 return self.__count 32 33 def run( self ): 34 " threaded function " 35 pSize = BatchSubmitDropSettings.packageSize 36 if pSize <= 0: 37 print >> sys.stderr, \ 38 "Invalid BatchSubmitDropSettings.packageSize (" + \ 39 str( pSize ) + "). Must be > 0" 40 return 41 pause = BatchSubmitDropSettings.pause 42 if pause < 0: 43 print >> sys.stderr, \ 44 "Invalid BatchSubmitDropSettings.pause (" + \ 45 str( pause ) + "). Must be >= 0" 46 return 47 48 pCount = BatchSubmitDropSettings.packagesCount 49 if not ( pCount == -1 or pCount > 0 ): 50 print >> sys.stderr, \ 51 "Invalid BatchSubmitDropSettings.packagesCount (" + \ 52 str( pCount ) + "). Must be > 0 or -1" 53 return 54 55 batchSize = BatchSubmitDropSettings.jobsInBatch 56 if batchSize <= 1: 57 print >> sys.stderr, \ 58 "Invalid BatchSubmitDropSettings.jobsInBatch (" + \ 59 str( batchSize ) + "). Must be >= 2" 60 return 61 62 # Prepare jobs input 63 jobsInput = [] 64 for count in xrange( batchSize ): 65 jobsInput.append( '"bla"' ) 66 67 68 # Settings are OK 69 while True: 70 pSize = BatchSubmitDropSettings.packageSize 71 while pSize > 0: 72 jobKeys = [] 73 jobKey = "" 74 try: 75 jobKeys = self.__gridClient.submitBatch( self.__qname, 76 jobsInput ) 77 try: 78 for jobKey in jobKeys: 79 self.__gridClient.killJob( self.__qname, jobKey ) 80 except Exception, excp: 81 print >> sys.stderr, \ 82 "Batch submit/Drop: Cannot kill job: " + jobKey 83 print >> sys.stderr, str( excp ) 84 except Exception, excp: 85 print >> sys.stderr, "Batch submit/Drop: Cannot submit jobs" 86 print >> sys.stderr, str( excp ) 87 88 self.__count += 1 89 pSize -= 1 90 91 if pause > 0: 92 time.sleep( pause ) 93 94 if pCount == -1: # Infinite loop 95 continue 96 pCount -= 1 97 if pCount <= 0: 98 break 99 return 100 101