Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Experimental #294

Merged
merged 4 commits into from
Jun 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 16 additions & 24 deletions qtop_py/plugins/pbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class PBSStatExtractor(StatExtractor):
def __init__(self, config, options):
StatExtractor.__init__(self, config, options)
self.user_q_search = r'^(?P<host_name>(?P<job_id>[0-9\[\]-]+)\.(?P<domain>[\w-]+))\s+' \
r'(?P<name>[\w@%.=+/{}-]+)\s+' \
r'(?P<name>[\w@%:.=+/{}-]+)\s+' \
r'(?P<user>[A-Za-z0-9.]+)\s+' \
r'(?P<time>\d+:\d+:?\d*|0)\s+' \
r'(?P<state>[BCEFHMQRSTUWX])\s+' \
Expand All @@ -37,29 +37,21 @@ def extract_qstat(self, orig_file):
except fileutils.FileEmptyError:
logging.error('File %s seems to be empty.' % orig_file)
all_qstat_values = []
else:
all_qstat_values = list()
with open(orig_file, 'r') as fin:
_ = fin.readline() # header
fin.readline()
line = fin.readline()
re_match_positions = ('job_id', 'user', 'state', 'queue_name') # was: (1, 5, 7, 8), (1, 4, 5, 8)
try: # first qstat line determines which format qstat follows.
re_search = self.user_q_search
qstat_values = self._process_qstat_line(re_search, line, re_match_positions)
# unused: _job_nr, _ce_name, _name, _time_use = m.group(2), m.group(3), m.group(4), m.group(6)
except AttributeError: # this means 'prior' exists in qstat, it's another format
re_search = self.user_q_search_prior
qstat_values = self._process_qstat_line(re_search, line, re_match_positions)
# unused: _prior, _name, _submit, _start_at, _queue_domain, _slots, _ja_taskID =
# m.group(2), m.group(3), m.group(6), m.group(7), m.group(9), m.group(10), m.group(11)
finally:
all_qstat_values.append(qstat_values)

# hence the rest of the lines should follow either try's or except's same format
for line in fin:
qstat_values = self._process_qstat_line(re_search, line, re_match_positions)
all_qstat_values.append(qstat_values)

all_qstat_values = list()
with open(orig_file, 'r') as fin:
_ = fin.readline() # header
fin.readline() # unimportant
line = fin.readline() # any qstat line determines which format qstat follows.
self.re_match_positions = ('job_id', 'user', 'state', 'queue_name') # was: (1, 5, 7, 8), (1, 4, 5, 8)
re_search = self.decide_format(line)

qstat_values = self._process_qstat_line(re_search, line)
all_qstat_values.append(qstat_values)

for line in fin:
qstat_values = self._process_qstat_line(re_search, line)
all_qstat_values.append(qstat_values)

return all_qstat_values

Expand Down
28 changes: 19 additions & 9 deletions qtop_py/serialiser.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,16 @@ def __init__(self, config, options):
self.options = options
self.anonymize = self.anonymize_func() if self.options.ANONYMIZE else self.eponymize_func()

def _process_qstat_line(self, re_search, line, re_match_positions):
def decide_format(self, line):
m1 = re.search(self.user_q_search, line.strip())
m2 = re.search(self.user_q_search_prior, line.strip())
if not any([m1, m2]):
logging.critical("Line: %s not matched to any known PBS format or unexpected character. Exiting...' % line.strip()")
sys.exit(1)

return self.user_q_search if m1 else self.user_q_search_prior # else being m2

def _process_qstat_line(self, re_search, line):
"""
extracts data from a tabular qstat-like file
returns a list
Expand All @@ -24,15 +33,16 @@ def _process_qstat_line(self, re_search, line, re_match_positions):
m = re.search(re_search, line.strip())

try:
job_id, user, job_state, queue = [m.group(x) for x in re_match_positions]
job_id, user, job_state, queue = [m.group(x) for x in self.re_match_positions]
except AttributeError:
logging.warn('Line: %s not properly parsed by regex expression. Assuming alternative qstat format.' % line.strip())
raise
job_id = job_id.split('.')[0]
user = self.anonymize(user, 'users')
for key, value in [('JobId', job_id), ('UnixAccount', user), ('S', job_state), ('Queue', queue)]:
qstat_values[key] = value
return qstat_values
logging.critical('Line:\n%s\n not properly parsed by regex expression. Unexpected character.' % line.strip())
sys.exit(1)
else:
job_id = job_id.split('.')[0]
user = self.anonymize(user, 'users')
for key, value in [('JobId', job_id), ('UnixAccount', user), ('S', job_state), ('Queue', queue)]:
qstat_values[key] = value
return qstat_values

def anonymize_func(self):
"""
Expand Down