From c2937517316b30e0a32e1dbcac315d4fbf3262c5 Mon Sep 17 00:00:00 2001 From: Joachim Gabler Date: Wed, 18 Sep 2024 11:43:10 +0200 Subject: [PATCH] BF: CS-348 incorrect timestamp from qstat -j jobid -xml EH: CS-592 Zombie jobs show a different time stamp as normal jobs --- source/clients/qstat/ocs_qstat.cc | 2 +- source/clients/qstat/ocs_qstat_xml.cc | 17 +++++++++----- source/libs/sgeobj/sge_cull_xml.cc | 32 +++++++++++++++++++++++---- 3 files changed, 40 insertions(+), 11 deletions(-) diff --git a/source/clients/qstat/ocs_qstat.cc b/source/clients/qstat/ocs_qstat.cc index 313da3ed0..e54a0567b 100644 --- a/source/clients/qstat/ocs_qstat.cc +++ b/source/clients/qstat/ocs_qstat.cc @@ -1874,7 +1874,7 @@ qstat_show_job(lList *jid_list, u_long32 isXML, qstat_env_t *qstat_env) { alp = sge_gdi(SGE_SME_LIST, SGE_GDI_GET, &ilp, nullptr, what); lFreeWhat(&what); - if (!isXML){ + if (!isXML) { for_each_ep(aep, alp) { if (lGetUlong(aep, AN_status) != STATUS_OK) { fprintf(stderr, "%s\n", lGetString(aep, AN_text)); diff --git a/source/clients/qstat/ocs_qstat_xml.cc b/source/clients/qstat/ocs_qstat_xml.cc index 6b4711b2b..47a119c3d 100644 --- a/source/clients/qstat/ocs_qstat_xml.cc +++ b/source/clients/qstat/ocs_qstat_xml.cc @@ -396,7 +396,8 @@ static int qstat_xml_job(job_handler_t* handler, u_long32 jid, job_summary_t *su int sge_ext, tsk_ext, sge_urg, sge_pri, sge_time; dstring ds = DSTRING_INIT; lList *attribute_list = nullptr; - + static bool compat = sge_getenv("SGE_QSTAT_SGE_COMPATIBILITY") != nullptr; + DENTER(TOP_LAYER); ctx->job_elem = lCreateElem(XMLE_Type); @@ -441,18 +442,22 @@ static int qstat_xml_job(job_handler_t* handler, u_long32 jid, job_summary_t *su xml_append_Attr_S(attribute_list, "state", summary->state); if (sge_time) { + u_long64 timestamp; + const char *attrib; if (summary->is_running) { - xml_append_Attr_S(attribute_list, "JAT_start_time", sge_ctime64_xml(summary->start_time, &ds)); - } - else { - xml_append_Attr_S(attribute_list, "JB_submission_time", sge_ctime64_xml(summary->submit_time, &ds)); + attrib = "JAT_start_time"; + timestamp = summary->start_time; + } else { + attrib = "JAT_submission_time"; + timestamp = summary->submit_time; } + xml_append_Attr_S(attribute_list, attrib, sge_ctime64(timestamp, &ds, true, compat ? false : true)); } /* deadline time */ if (sge_urg) { if (summary->deadline) { - xml_append_Attr_S(attribute_list, "JB_deadline", sge_ctime64_xml(summary->deadline, &ds)); + xml_append_Attr_S(attribute_list, "JB_deadline", sge_ctime64(summary->deadline, &ds, true, compat ? false : true)); } } diff --git a/source/libs/sgeobj/sge_cull_xml.cc b/source/libs/sgeobj/sge_cull_xml.cc index fc5b32952..2ee7a8c98 100644 --- a/source/libs/sgeobj/sge_cull_xml.cc +++ b/source/libs/sgeobj/sge_cull_xml.cc @@ -41,6 +41,7 @@ #include "uti/sge_dstring.h" #include "uti/sge_log.h" #include "uti/sge_rmon_macros.h" +#include "uti/sge_time.h" #include "cull/cull_lerrnoP.h" #include "cull/cull_list.h" @@ -48,7 +49,7 @@ #include "sgeobj/sge_cull_xml.h" -static void lWriteElemXML_(const lListElem *ep, int nesting_level, FILE *fp, int ignore_cull_name); +static void lWriteElemXML_(const lListElem *ep, int nesting_level, FILE *fp, int ignore_cull_name); static void lWriteListXML_(const lList *lp, int nesting_level, FILE *fp, int ignore_cull_name); static bool lAttributesToString_(const lList *attr_list, dstring *attr); static void lWriteXMLHead_(const lListElem *ep, int nesting_level, FILE *fp, int ignore_cull_name); @@ -383,11 +384,34 @@ static void lWriteElemXML_(const lListElem *ep, int nesting_level, FILE *fp, int } break; case lUlong64T: - if (!fp) { - DPRINTF( sge_u64, lGetPosUlong64(ep, i)); + { + u_long64 value = lGetPosUlong64(ep, i); + + // hack: assume it is a timestamp when the attribute name contains "time" + if (strstr(attr_name, "time") != nullptr) { + static bool compat = sge_getenv("SGE_QSTAT_SGE_COMPATIBILITY") != nullptr; + if (compat) { + if (!fp) { + DPRINTF(sge_u64, value / 1000000); + } else { + fprintf(fp, sge_u64, value / 1000000); + } + } else { + DSTRING_STATIC(dstr, 128); + if (!fp) { + DPRINTF("%s", sge_ctime64_xml(value, &dstr)); + } else { + fprintf(fp, "%s", sge_ctime64_xml(value, &dstr)); + } + } } else { - fprintf(fp, sge_u64, lGetPosUlong64(ep, i)); + if (!fp) { + DPRINTF(sge_u64, value); + } else { + fprintf(fp, sge_u64, value); + } } + } break; case lStringT: {