From d700faec7b3a95b4803c43386f584e590bf6030e Mon Sep 17 00:00:00 2001 From: Tatiana Korchuganova Date: Fri, 14 Jun 2024 12:44:43 +0200 Subject: [PATCH 1/2] eventservice | add translation of numeric event states to string for jobList --- core/constants.py | 26 +++++++++++++------------- core/libs/eventservice.py | 17 ++++++++++------- core/libs/exlib.py | 9 +++++++-- core/pandajob/utils.py | 2 +- 4 files changed, 31 insertions(+), 23 deletions(-) diff --git a/core/constants.py b/core/constants.py index 94c79b51..75e4346a 100644 --- a/core/constants.py +++ b/core/constants.py @@ -61,19 +61,19 @@ 'merging' ) -EVENT_STATES = ( - 'ready', - 'sent', - 'running', - 'finished', - 'cancelled', - 'discarded', - 'done', - 'failed', - 'fatal', - 'merged', - 'corrupted', -) +EVENT_STATES = MappingProxyType({ + 0: 'ready', + 1: 'sent', + 2: 'running', + 3: 'finished', + 4: 'cancelled', + 5: 'discarded', + 6: 'done', + 7: 'failed', + 8: 'fatal', + 9: 'merged', + 10: 'corrupted', +}) TASK_STATES = ( 'registered', diff --git a/core/libs/eventservice.py b/core/libs/eventservice.py index df42c35e..fd192882 100644 --- a/core/libs/eventservice.py +++ b/core/libs/eventservice.py @@ -7,8 +7,8 @@ from django.conf import settings from core.libs.exlib import dictfetchall, get_tmp_table_name, insert_to_temp_table from core.libs.dropalgorithm import insert_dropped_jobs_to_tmp_table, get_tmp_table_name_debug - from core.common.models import JediEvents, GetEventsForTask +from core import constants as const _logger = logging.getLogger('bigpandamon') @@ -155,16 +155,14 @@ def add_event_summary_to_tasklist(tasks, transaction_key=None): return tasks -def get_event_status_summary(pandaids, eventservicestatelist): +def get_event_status_summary(pandaids): """ Getting event statuses summary for list of pandaids of ES jobs :param pandaids: list :return: dict of status: nevents """ summary = {} - tmpTableName = get_tmp_table_name() - transactionKey = insert_to_temp_table(pandaids) new_cur = connection.cursor() new_cur.execute( @@ -177,9 +175,14 @@ def get_event_status_summary(pandaids, eventservicestatelist): ) t1 group by status""".format(tmpTableName, transactionKey, settings.DB_SCHEMA_PANDA)) - evtable = dictfetchall(new_cur) - + evtable = dictfetchall(new_cur, style='lowercase') + # translate numerical status to string, if not in const.EVENT_STATES, then it is 'unknown' for ev in evtable: - summary[ev['status']] = ev['countstat'] + if ev['status'] in const.EVENT_STATES: + summary[const.EVENT_STATES[ev['status']]] = ev['countstat'] + else: + if 'unknown' not in summary: + summary['unknown'] = 0 + summary['unknown'] += ev['countstat'] return summary \ No newline at end of file diff --git a/core/libs/exlib.py b/core/libs/exlib.py index ceff4a74..b0de2fd6 100644 --- a/core/libs/exlib.py +++ b/core/libs/exlib.py @@ -77,7 +77,7 @@ def insert_to_temp_table(list_of_items, transactionKey = -1): def dictfetchall(cursor, **kwargs): - "Returns all rows from a cursor as a dict" + """Returns all rows from a cursor as a dict""" style = 'default' if 'style' in kwargs: style = kwargs['style'] @@ -87,11 +87,16 @@ def dictfetchall(cursor, **kwargs): dict(zip([str(col[0]).upper() for col in desc], row)) for row in cursor.fetchall() ] + elif style == 'lowercase': + return [ + dict(zip([str(col[0]).lower() for col in desc], row)) + for row in cursor.fetchall() + ] else: return [ dict(zip([col[0] for col in desc], row)) for row in cursor.fetchall() - ] + ] def is_timestamp(key): diff --git a/core/pandajob/utils.py b/core/pandajob/utils.py index 09903e8c..6777dbc8 100644 --- a/core/pandajob/utils.py +++ b/core/pandajob/utils.py @@ -198,7 +198,7 @@ def job_summary_dict(request, jobs, fieldlist=None): if is_event_service(job): esjobs.append(job['pandaid']) if len(esjobs) > 0: - sumd['eventservicestatus'] = get_event_status_summary(esjobs, const.EVENT_STATES) + sumd['eventservicestatus'] = get_event_status_summary(esjobs) # convert to ordered lists suml = [] From eba67d717867f0e1c1d9d4c30e345dbf0dedd45b Mon Sep 17 00:00:00 2001 From: Tatiana Korchuganova Date: Fri, 14 Jun 2024 12:46:14 +0200 Subject: [PATCH 2/2] jobList | add color-coded state of events to eventservicestatus attribute summary --- core/templates/jobList.html | 2 +- core/templates/jobListES.html | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/core/templates/jobList.html b/core/templates/jobList.html index c25f2999..5524fe31 100644 --- a/core/templates/jobList.html +++ b/core/templates/jobList.html @@ -157,7 +157,7 @@ {% elif fdict.field == 'harvesterinstance' %} {{ item.kname }} ({{ item.kvalue }}) {% elif fdict.field == 'durationmin' %} {% if item.kvalue > 0 %} {{ item.kname }} ({{ item.kvalue }}) {% endif %} {% elif fdict.field == 'produsername' %} {{ item.kname }} ({{ item.kvalue }}) - {% elif fdict.field == 'eventservicestatus' %} ({{ item.kvalue }}) + {% elif fdict.field == 'eventservicestatus' %} {{ item.kname }} ({{ item.kvalue }}) {% elif fdict.field == 'container_name' and request.session.xurls and fdict.field in request.session.xurls %} {{ item.kname }} ({{ item.kvalue }}) {% elif fdict.field == 'jobstatus' %} {{ item.kname }} {% if item.kname == 'closed:toreassign' %} diff --git a/core/templates/jobListES.html b/core/templates/jobListES.html index 5210aaed..d2cc2026 100644 --- a/core/templates/jobListES.html +++ b/core/templates/jobListES.html @@ -144,8 +144,11 @@
Warning!
{% for item in fdict.list %} {% if fdict.field == 'jeditaskid' and item.kname != 'Not specified' %} {{ item.kname }} ({{ item.kvalue }}) - {% elif fdict.field == 'jobsetid'%} {{ item.kname }} ({{ item.kvalue }}) + {% elif fdict.field == 'jobsetid'%} {{ item.kname }} ({{ item.kvalue }}) + {% elif fdict.field == 'harvesterinstance' %} {{ item.kname }} ({{ item.kvalue }}) + {% elif fdict.field == 'durationmin' %} {% if item.kvalue > 0 %} {{ item.kname }} ({{ item.kvalue }}) {% endif %} {% elif fdict.field == 'produsername' %} {{ item.kname }} ({{ item.kvalue }}) + {% elif fdict.field == 'eventservicestatus' %} {{ item.kname }} ({{ item.kvalue }}) {% elif fdict.field == 'container_name' and request.session.xurls and fdict.field in request.session.xurls %} {{ item.kname }} ({{ item.kvalue }}) {% elif fdict.field == 'jobstatus' %} {{ item.kname }} {% if item.kname == 'closed:toreassign' %}