Skip to content

Commit

Permalink
Merge pull request #350 from PanDAWMS/tk
Browse files Browse the repository at this point in the history
eventservice | fix translation of numeric event states to string
  • Loading branch information
tkorchug authored Jun 14, 2024
2 parents 3511012 + eba67d7 commit 297fb35
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 25 deletions.
26 changes: 13 additions & 13 deletions core/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
17 changes: 10 additions & 7 deletions core/libs/eventservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down Expand Up @@ -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(
Expand All @@ -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
9 changes: 7 additions & 2 deletions core/libs/exlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand All @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion core/pandajob/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
2 changes: 1 addition & 1 deletion core/templates/jobList.html
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
{% elif fdict.field == 'harvesterinstance' %} {{ item.kname }} <a href="{{xurl}}{{fdict.field}}={{item.kname}}" >({{ item.kvalue }})</a>
{% elif fdict.field == 'durationmin' %} {% if item.kvalue > 0 %} {{ item.kname }} <a href="{{nodurminurl}}{{fdict.field}}={{item.kname}}" >({{ item.kvalue }})</a> {% endif %}
{% elif fdict.field == 'produsername' %} <a href="{% url 'userInfo' item.kname %}"> {{ item.kname }} </a><a href="{{xurl}}{{fdict.field}}={{item.kname}}" >({{ item.kvalue }})</a>
{% elif fdict.field == 'eventservicestatus' %} ({{ item.kvalue }})
{% elif fdict.field == 'eventservicestatus' %} <span class='{{item.kname}} item'>{{ item.kname }}</span> ({{ item.kvalue }})
{% elif fdict.field == 'container_name' and request.session.xurls and fdict.field in request.session.xurls %} {{ item.kname }} <a href="{{ request.session.xurls.container_name }}{{ fdict.field }}={{ item.kname }}">({{ item.kvalue }})</a>
{% elif fdict.field == 'jobstatus' %} <span class='{{item.kname}} item'>{{ item.kname }}</span>
{% if item.kname == 'closed:toreassign' %}
Expand Down
5 changes: 4 additions & 1 deletion core/templates/jobListES.html
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,11 @@ <h5>Warning! </h5>
<td><div class="comment more">
{% for item in fdict.list %}
{% if fdict.field == 'jeditaskid' and item.kname != 'Not specified' %} <a href="{% url 'taskInfo' item.kname %}"> {{ item.kname }} </a><a href="{{xurl}}{{fdict.field}}={{item.kname}}" >({{ item.kvalue }})</a>
{% elif fdict.field == 'jobsetid'%} <a href="{% url 'jobList' %}?jobsetid={{ item.kname }}">{{ item.kname }}</a> <a href="{{xurl}}{{fdict.field}}={{item.kname}}" > ({{ item.kvalue }}) </a>
{% elif fdict.field == 'jobsetid'%} <a href="{% url 'jobList' %}?jobsetid={{ item.kname }}"> {{ item.kname }}</a> <a href="{{xurl}}{{fdict.field}}={{item.kname}}" >({{ item.kvalue }})</a>
{% elif fdict.field == 'harvesterinstance' %} {{ item.kname }} <a href="{{xurl}}{{fdict.field}}={{item.kname}}" >({{ item.kvalue }})</a>
{% elif fdict.field == 'durationmin' %} {% if item.kvalue > 0 %} {{ item.kname }} <a href="{{nodurminurl}}{{fdict.field}}={{item.kname}}" >({{ item.kvalue }})</a> {% endif %}
{% elif fdict.field == 'produsername' %} <a href="{% url 'userInfo' item.kname %}"> {{ item.kname }} </a><a href="{{xurl}}{{fdict.field}}={{item.kname}}" >({{ item.kvalue }})</a>
{% elif fdict.field == 'eventservicestatus' %} <span class='{{item.kname}} item'>{{ item.kname }}</span> ({{ item.kvalue }})
{% elif fdict.field == 'container_name' and request.session.xurls and fdict.field in request.session.xurls %} {{ item.kname }} <a href="{{ request.session.xurls.container_name }}{{ fdict.field }}={{ item.kname }}">({{ item.kvalue }})</a>
{% elif fdict.field == 'jobstatus' %} <span class='{{item.kname}} item'>{{ item.kname }}</span>
{% if item.kname == 'closed:toreassign' %}
Expand Down

0 comments on commit 297fb35

Please sign in to comment.