Package Ganga :: Package Lib :: Package Condor :: Module CondorRequirements'
[hide private]
[frames] | no frames]

Source Code for Module Ganga.Lib.Condor.CondorRequirements'

  1  ############################################################################### 
  2  # Ganga Project. http://cern.ch/ganga 
  3  # 
  4  # $Id: CondorRequirements.py,v 1.2 2008-07-29 10:30:39 karl Exp $ 
  5  ############################################################################### 
  6  # File: CondorRequirements.py 
  7  # Author: K. Harrison 
  8  # Created: 051229 
  9  #  
 10  # KH - 060728 : Correction to way multiple requirements are combined 
 11  #               in convert method 
 12  # 
 13  # KH - 060829 : Typo corrected 
 14  # 
 15  # KH - 061026 : Correction for missing import (types module) 
 16  #               Correction to allow configuration values for "machine" 
 17  #               and "excluded_machine" to be either string or list 
 18  #               Correction to handling of requirement for allowed machines 
 19  # 
 20  # KH - 080729 : Updates for typing system of Ganga 5 
 21  #               Improvements to documentation for CondorRequirements properties 
 22   
 23  """Module containing class for handling Condor requirements""" 
 24   
 25  __author__  = "K.Harrison <Harrison@hep.phy.cam.ac.uk>" 
 26  __date__    = "29 July 2008" 
 27  __version__ = "1.4" 
 28   
 29  from Ganga.GPIDev.Base.Objects import GangaObject 
 30  from Ganga.GPIDev.Schema import ComponentItem, Schema, SimpleItem, Version 
 31  from Ganga.Utility.Config import getConfig 
 32  from Ganga.Utility.logging import getLogger 
 33   
 34  import types 
 35   
 36  logger = getLogger() 
 37   
38 -class CondorRequirements( GangaObject ):
39 '''Helper class to group Condor requirements. 40 41 See also: http://www.cs.wisc.edu/condor/manual 42 ''' 43 44 _schema = Schema(Version(1,0), { 45 "machine" : SimpleItem( defvalue = "", typelist = [ "str", "list" ], 46 doc = """ 47 Requested execution hosts, given as a string of space-separated names: 48 'machine1 machine2 machine3'; or as a list of names: 49 [ 'machine1', 'machine2', 'machine3' ] 50 """ ), 51 "excluded_machine" : SimpleItem( defvalue = "", 52 typelist = [ "str", "list" ], 53 doc = """ 54 Excluded execution hosts, given as a string of space-separated names: 55 'machine1 machine2 machine3'; or as a list of names: 56 [ 'machine1', 'machine2', 'machine3' ] 57 """ ), 58 "opsys" : SimpleItem( defvalue = "LINUX", doc = "Operating system" ), 59 "arch" : SimpleItem( defvalue = "INTEL", doc = "System architecture" ), 60 "memory" : SimpleItem( defvalue = 400, doc = "Mininum physical memory" ), 61 "virtual_memory" : SimpleItem( defvalue = 400, 62 doc = "Minimum virtual memory" ), 63 "other" : SimpleItem( defvalue=[], typelist = [ "str" ], sequence=1, \ 64 doc= """ 65 Other requirements, given as a list of strings, for example: 66 [ 'OSTYPE == "SLC4"', '(POOL == "GENERAL" || POOL == "GEN_FARM")' ]; 67 the final requirement is the AND of all elements in the list 68 """ ) 69 } ) 70 71 _category = 'condor_requirements' 72 _name = 'CondorRequirements' 73
74 - def __init__( self ):
75 super( CondorRequirements, self ).__init__()
76
77 - def convert( self):
78 '''Convert the condition(s) to a JDL specification''' 79 80 requirementList = [] 81 82 if self.machine: 83 if type( self.machine ) == types.StringType: 84 machineList = self.machine.split() 85 else: 86 machineList = self.machine 87 machineConditionList = [] 88 for machine in machineList: 89 machineConditionList.append( "Machine == \"%s\"" % str( machine ) ) 90 machineConditionString = " || ".join( machineConditionList ) 91 requirement = ( " ".join( [ "(", machineConditionString, ")" ] ) ) 92 requirementList.append( requirement ) 93 94 if self.excluded_machine: 95 if type( self.excluded_machine ) == types.StringType: 96 machineList = self.excluded_machine.split() 97 else: 98 machineList = self.excluded_machine 99 for machine in machineList: 100 requirementList.append( "Machine != \"%s\"" % str( machine ) ) 101 102 if self.opsys: 103 requirementList.append( "OpSys == \"%s\"" % str( self.opsys ) ) 104 105 if self.arch: 106 requirementList.append( "Arch == \"%s\"" % str( self.arch ) ) 107 108 if self.memory: 109 requirementList.append( "Memory >= %s" % str( self.memory ) ) 110 111 if self.virtual_memory: 112 requirementList.append\ 113 ( "VirtualMemory >= %s" % str( self.virtual_memory ) ) 114 115 if self.other: 116 requirementList.extend( self.other ) 117 118 requirementString = "requirements = " + " && ".join( requirementList ) 119 120 return requirementString
121 122 # Allow property values to be either string or list 123 config = getConfig( "defaults_CondorRequirements" ) 124 for property in [ "machine", "excluded_machine" ]: 125 config.options[property].type = [ types.StringType, types.ListType ] 126