1# 2# Authors: Sergey Satskiy 3# 4# $Id: submitdroploader.py 309785 2011-06-28 13:46:22Z satskyse $ 5# 6 7""" 8NetScheduler Submit/drop loader 9""" 10 11import sys, time, threading 12from ns_traffic_settings import SubmitDropSettings 13 14 15class SubmitDropLoader( threading.Thread ): 16 " 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 "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 = SubmitDropSettings.packageSize 36 if pSize <= 0: 37 print >> sys.stderr, \ 38 "Invalid SubmitDropSettings.packageSize (" + \ 39 str( pSize ) + "). Must be > 0" 40 return 41 pause = SubmitDropSettings.pause 42 if pause < 0: 43 print >> sys.stderr, \ 44 "Invalid SubmitDropSettings.pause (" + \ 45 str( pause ) + "). Must be >= 0" 46 return 47 48 pCount = SubmitDropSettings.packagesCount 49 if not ( pCount == -1 or pCount > 0 ): 50 print >> sys.stderr, \ 51 "Invalid SubmitDropSettings.packagesCount (" + \ 52 str( pCount ) + "). Must be > 0 or -1" 53 return 54 55 # Settings are OK 56 while True: 57 pSize = SubmitDropSettings.packageSize 58 while pSize > 0: 59 jobKey = "" 60 try: 61 jobKey = self.__gridClient.submitJob( self.__qname, "bla" ) 62 try: 63 self.__gridClient.killJob( self.__qname, jobKey ) 64 except Exception, excp: 65 print >> sys.stderr, \ 66 "Submit/Drop: Cannot kill job: " + jobKey 67 print >> sys.stderr, str( excp ) 68 except Exception, excp: 69 print >> sys.stderr, "Submit/Drop: Cannot submit job" 70 print >> sys.stderr, str( excp ) 71 72 self.__count += 1 73 pSize -= 1 74 75 if pause > 0: 76 time.sleep( pause ) 77 78 if pCount == -1: # Infinite loop 79 continue 80 pCount -= 1 81 if pCount <= 0: 82 break 83 return 84 85