-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGet_Data.py
More file actions
61 lines (49 loc) · 1.97 KB
/
Get_Data.py
File metadata and controls
61 lines (49 loc) · 1.97 KB
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
#Test Cases
#Get data from txt file assuming slurm sacct was run and piped into txt file
from Utility import *
import subprocess
def get_data(jobid, debug):
used_slurm_call = False
try:
with open('sacct_output/{j}.txt'.format(j=jobid), 'r') as f:
data = f.read()
f.close()
except:
cmd = 'sacct -P -j {j} -o Start,End,Nodelist,Partition,JobId > sacct_output/{j}.txt'.format(j=jobid)
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
out, err = p.communicate()
used_slurm_call = True
# Handle: Broken sacct
if 'sacct: error: Problem talking to the database: Connection timed out' in err:
return 'sacct not enabled', None, None, None, used_slurm_call
# Handle: No data from sacct command
file_length = sum(1 for line in open('sacct_output/{j}.txt'.format(j=jobid)))
if file_length <= 1:
return 'no data', None, None, None, used_slurm_call
with open('sacct_output/{j}.txt'.format(j=jobid), 'r') as f:
data = f.read()
f.close()
t1, t2, node_names, cluster_names = parse_job_file(data)
#convert cluster names to match directory names in rrd
cluster_names = convert_cluster_names(cluster_names)
# Expand nodes if necessary and flatten nested lists
node_names = expand_node_list(node_names)
## Use long time window for debugging
# t1 = '2015-05-25T10:00:00'
# t2 = 'now'
if t1 == 'Unknown':
start = t1
stop = t1
else:
start = convert_enddate_to_seconds(t1)
start += 3600*6
# Handle: Job not yet finished
try:
stop = convert_enddate_to_seconds(t2)
stop += 3600*6
# stop = 'now'
except ValueError:
return start, False, None, None, used_slurm_call
# stop = 'now'
# print start, stop
return start, stop, cluster_names, node_names, used_slurm_call