forked from PanDAWMS/pilot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Node.py
262 lines (213 loc) · 9.99 KB
/
Node.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
import string
import os
import re
import commands
from pUtil import tolog, readpar
from FileHandling import getMaxWorkDirSize
class Node:
""" worker node information """
def __init__(self):
self.cpu = 0
self.nodename = None
self.mem = 0
self.disk = 0
self.numberOfCores = self.setNumberOfCores()
# set the batch job and machine features
self.collectMachineFeatures()
def setNodeName(self, nm):
self.nodename = nm
def displayNodeInfo(self):
tolog("CPU: %0.2f, memory: %0.2f, disk space: %0.2f" % (self.cpu, self.mem, self.disk))
def collectWNInfo(self, diskpath):
""" collect node information (cpu, memory and disk space) """
fd = open("/proc/meminfo", "r")
mems = fd.readline()
while mems:
if mems.upper().find("MEMTOTAL") != -1:
self.mem = float(mems.split()[1])/1024
break
mems = fd.readline()
fd.close()
fd = open("/proc/cpuinfo", "r")
lines = fd.readlines()
fd.close()
for line in lines:
if not string.find(line, "cpu MHz"):
self.cpu = float(line.split(":")[1])
break
diskpipe = os.popen("df -mP %s" % (diskpath)) # -m = MB
disks = diskpipe.read()
if not diskpipe.close():
self.disk = float(disks.splitlines()[1].split()[3])
return self.mem, self.cpu, self.disk
def setNumberOfCores(self) :
""" Report the number of cores in the WN """
# 1. Grab corecount from queuedata
# 2. If corecount is number and corecount > 1, set ATHENA_PROC_NUMBER env variable to this value
# 3. If corecount is 0, null, or doesn't exist, then don't set the env. variable
# 4. If corecount is '-1', then get number of cores from /proc/cpuinfo, and set the env. variable accordingly.
cores = []
nCores = None
# grab the schedconfig value
try:
nCores = int(readpar('corecount'))
except ValueError: # covers the case 'NULL'
tolog("corecount not an integer in queuedata")
except Exception, e:
tolog("corecount not set in queuedata: %s" % str(e))
else:
if nCores > 1:
tolog("Setting number of cores: ATHENA_PROC_NUMBER=%d (from schedconfig.corecount)" % (nCores))
os.environ['ATHENA_PROC_NUMBER'] = str(nCores)
return nCores
if not nCores or nCores == 0:
tolog("Will not set ATHENA_PROC_NUMBER")
return nCores
if nCores == -1:
# check locally
try:
cpuinfo = open("/proc/cpuinfo")
except Exception, e:
tolog("!!WARNING!!2998!! Failed to get the number of cores: %s" % str(e))
else:
for line in cpuinfo :
if re.match('core id', line):
a = re.search('core id\s*:\s*(\d+)', line)
cores.append(a.group(1))
cpuinfo.close()
nCores = len(cores)
if nCores == 0:
nCores = 1
tolog("Setting number of cores: ATHENA_PROC_NUMBER=%d (from cpuinfo)" % (nCores))
os.environ['ATHENA_PROC_NUMBER'] = str(nCores)
else:
tolog("Will not set ATHENA_PROC_NUMBER (nCores=%d)" % (nCores))
return nCores
def getNumberOfCores(self):
return self.numberOfCores
def readValue(self, path):
""" Read value from file """
value = ""
try:
f = open(path, "r")
except IOError, e:
tolog("!!WARNING!!2344!! Failed to open file: %s" % (e))
else:
value = f.read()
f.close()
# protect against trailing new line
if value.endswith("\n"):
value = value[:-1]
return value
def setDataMember(self, directory, name):
""" Set a batch job or machine features data member """
data_member_value = ""
path = os.path.join(directory, name)
if os.path.exists(path):
data_member_value = self.readValue(path)
return data_member_value
def dumpValue(self, name, value):
""" Print a value if not empty """
if value != "":
tolog("%s = %s" % (name, value))
else:
tolog("%s was not set by the batch system" % (name))
def collectMachineFeatures(self):
""" Collect the machine and job features from /etc/machinefeatures and $JOBFEATURES """
# treat float and int values as strings
self.hs06 = ""
self.shutdownTime = ""
self.jobSlots = ""
self.physCores = ""
self.logCores = ""
self.cpuFactorLrms = ""
self.cpuLimitSecsLrms = ""
self.cpuLimitSecs = ""
self.wallLimitSecsLrms = ""
self.wallLimitSecs = ""
self.diskLimitGB = ""
self.jobStartSecs = ""
self.memLimitMB = ""
self.allocatedCPU = ""
tolog("Collecting machine features")
if os.environ.has_key('MACHINEFEATURES'):
MACHINEFEATURES = os.environ['MACHINEFEATURES']
self.hs06 = self.setDataMember(MACHINEFEATURES, "hs06")
self.shutdownTime = self.setDataMember(MACHINEFEATURES, "shutdowntime")
self.jobSlots = self.setDataMember(MACHINEFEATURES, "jobslots")
self.physCores = self.setDataMember(MACHINEFEATURES, "phys_cores")
self.logCores = self.setDataMember(MACHINEFEATURES, "log_cores")
tolog("Machine features:")
self.dumpValue("hs06", self.hs06)
self.dumpValue("shutdowntime", self.shutdownTime)
self.dumpValue("jobslots", self.jobSlots)
self.dumpValue("phys_cores", self.physCores)
self.dumpValue("log_cores", self.logCores)
else:
tolog("$MACHINEFEATURES not defined locally")
if os.environ.has_key('JOBFEATURES'):
JOBFEATURES = os.environ['JOBFEATURES']
self.cpuFactorLrms = self.setDataMember(JOBFEATURES, "cpufactor_lrms")
self.cpuLimitSecsLrms = self.setDataMember(JOBFEATURES, "cpu_limit_secs_lrms")
self.cpuLimitSecs = self.setDataMember(JOBFEATURES, "cpu_limit_secs")
self.wallLimitSecsLrms = self.setDataMember(JOBFEATURES, "wall_limit_secs_lrms")
self.wallLimitSecs = self.setDataMember(JOBFEATURES, "wall_limit_secs")
self.diskLimitGB = self.setDataMember(JOBFEATURES, "disk_limit_GB")
self.jobStartSecs = self.setDataMember(JOBFEATURES, "jobstart_secs")
self.memLimitMB = self.setDataMember(JOBFEATURES, "mem_limit_MB")
self.allocatedCPU = self.setDataMember(JOBFEATURES, "allocated_CPU")
tolog("Batch system job features:")
self.dumpValue("cpufactor_lrms", self.cpuFactorLrms)
self.dumpValue("cpu_limit_secs_lrms", self.cpuLimitSecsLrms)
self.dumpValue("cpu_limit_secs", self.cpuLimitSecs)
self.dumpValue("wall_limit_secs_lrms", self.wallLimitSecsLrms)
self.dumpValue("wall_limit_secs", self.wallLimitSecs)
self.dumpValue("disk_limit_GB", self.diskLimitGB)
self.dumpValue("jobstart_secs", self.jobStartSecs)
self.dumpValue("mem_limit_MB", self.memLimitMB)
self.dumpValue("allocated_CPU", self.allocatedCPU)
else:
tolog("$JOBFEATURES not defined locally")
cmd = "hostname -i"
tolog("Executing command: %s" % (cmd))
out = commands.getoutput(cmd)
tolog("IP number of worker node: %s" % (out))
def addFieldToJobMetrics(self, name, value):
""" Add a substring field to the job metrics string """
jobMetrics = ""
if value != "":
jobMetrics += "%s=%s " % (name, value)
return jobMetrics
def addToJobMetrics(self, jobResult, path, jobId):
""" Add the batch job and machine features to the job metrics """
jobMetrics = ""
# jobMetrics += self.addFieldToJobMetrics("hs06", self.hs06)
# jobMetrics += self.addFieldToJobMetrics("shutdowntime", self.shutdownTime)
# jobMetrics += self.addFieldToJobMetrics("jobslots", self.jobSlots)
# jobMetrics += self.addFieldToJobMetrics("phys_cores", self.physCores)
# jobMetrics += self.addFieldToJobMetrics("log_cores", self.logCores)
# jobMetrics += self.addFieldToJobMetrics("cpufactor_lrms", self.cpuFactorLrms)
# jobMetrics += self.addFieldToJobMetrics("cpu_limit_secs_lrms", self.cpuLimitSecsLrms)
# jobMetrics += self.addFieldToJobMetrics("cpu_limit_secs", self.cpuLimitSecs)
# jobMetrics += self.addFieldToJobMetrics("wall_limit_secs_lrms", self.wallLimitSecsLrms)
# jobMetrics += self.addFieldToJobMetrics("wall_limit_secs", self.wallLimitSecs)
# jobMetrics += self.addFieldToJobMetrics("disk_limit_GB", self.diskLimitGB)
# jobMetrics += self.addFieldToJobMetrics("jobstart_secs", self.jobStartSecs)
# jobMetrics += self.addFieldToJobMetrics("mem_limit_MB", self.memLimitMB)
# jobMetrics += self.addFieldToJobMetrics("allocated_CPU", self.allocatedCPU)
# Get the max disk space used by the payload (at the end of a job)
if jobResult == "finished" or jobResult == "failed" or jobResult == "holding":
max_space = getMaxWorkDirSize(path, jobId)
if max_space > 0L:
jobMetrics += self.addFieldToJobMetrics("workDirSize", max_space)
else:
tolog("Will not add max space = %d to job metrics" % (max_space))
return jobMetrics
def getBenchmarkDictionary(self, si):
""" Execute the benchmack test if required by the site information object """
benchmark_dictionary = None
if si.shouldExecuteBenchmark():
benchmark_dictionary = si.executeBenchmark()
else:
tolog("Not required to run the benchmark test")
return benchmark_dictionary