1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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
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
76
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
123 config = getConfig( "defaults_CondorRequirements" )
124 for property in [ "machine", "excluded_machine" ]:
125 config.options[property].type = [ types.StringType, types.ListType ]
126