From 56eb4257b2533bcf354380a359ddb876f5df9ffa Mon Sep 17 00:00:00 2001
From: Morris Jette <jette@schedmd.com>
Date: Thu, 24 Jan 2013 11:18:35 -0800
Subject: [PATCH] Add sview support for job arrays

---
 doc/html/job_array.shtml |  9 +++++++--
 src/sview/job_info.c     | 42 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 49 insertions(+), 2 deletions(-)

diff --git a/doc/html/job_array.shtml b/doc/html/job_array.shtml
index b82d7097cf3..be6df5b41e2 100644
--- a/doc/html/job_array.shtml
+++ b/doc/html/job_array.shtml
@@ -94,7 +94,7 @@ $ scancel 20_3 20_5
 $ scancel 20
 </pre>
 
-<h2>Squeue and Sview Command Use</h2>
+<h2>Squeue Command Use</h2>
 
 <p>TBD</p>
 
@@ -110,6 +110,7 @@ The <i>JobID</i> is a unique identifier for the job.
 The <i>ArrayJobID</i> is the <i>JobID</i> of the first element of the job
 array.
 The <i>ArrayTaskID</i> is the array index of this particular entry.
+Neiher field is displayed if the job is not part of a job array.
 In order to modify a job, always use the <i>JobID</i> specification.</p>
 
 <pre>
@@ -128,7 +129,11 @@ $ scontrol update JobId=15 TimeLimit=30
 
 <p>The following Slurm commands do not currently recognize job arrays and their
 use requires the use of SLurm job IDs, which are unique for each array element:
-sacct, sattach, sbcast, smap, sprio, sreport, sshare, sstat and strigger.</p>
+sacct, sattach, sbcast, smap, sprio, sreport, sshare, sstat, strigger, and
+sview.
+The sview command has been modified to permit display of a job's ArrayJobId
+and ArrayTaskId fields. Both fields are displayed with a value of "N/A" if
+the job is not part of a job array.</p>
 
 <p style="text-align:center;">Last modified 24 January 2013</p>
 
diff --git a/src/sview/job_info.c b/src/sview/job_info.c
index f45d513a2e6..6ed6ae5da1e 100644
--- a/src/sview/job_info.c
+++ b/src/sview/job_info.c
@@ -97,6 +97,8 @@ enum {
 	SORTID_ALLOC,
 	SORTID_ALLOC_NODE,
 	SORTID_ALPS_RESV_ID,
+	SORTID_ARRAY_JOB_ID,
+	SORTID_ARRAY_TASK_ID,
 	SORTID_BATCH,
 	SORTID_BATCH_HOST,
 	SORTID_BLOCK,
@@ -207,6 +209,10 @@ static display_data_t display_data_job[] = {
 	 EDIT_MODEL, refresh_job, create_model_job, admin_edit_job},
 	{G_TYPE_INT, SORTID_ALLOC, NULL, FALSE, EDIT_NONE, refresh_job,
 	 create_model_job, admin_edit_job},
+	{G_TYPE_STRING, SORTID_ARRAY_JOB_ID, "Array_Job_ID", FALSE, EDIT_NONE,
+	 refresh_job, create_model_job, admin_edit_job},
+	{G_TYPE_STRING, SORTID_ARRAY_TASK_ID, "Array_Task_ID", FALSE, EDIT_NONE,
+	 refresh_job, create_model_job, admin_edit_job},
 	{G_TYPE_STRING, SORTID_PARTITION, "Partition", FALSE,
 	 EDIT_TEXTBOX, refresh_job, create_model_job, admin_edit_job},
 #ifdef HAVE_BG
@@ -1317,6 +1323,29 @@ static void _layout_job_record(GtkTreeView *treeview,
 						   tmp_char,
 						   sizeof(tmp_char),
 						   SELECT_PRINT_DATA));
+
+	if (job_ptr->array_task_id != (uint16_t) NO_VAL) {
+		snprintf(tmp_char, sizeof(tmp_char), "%u",
+			 job_ptr->array_job_id);
+	} else {
+		snprintf(tmp_char, sizeof(tmp_char), "N/A");
+	}
+	add_display_treestore_line(update, treestore, &iter,
+				   find_col_name(display_data_job,
+						 SORTID_ARRAY_JOB_ID),
+				   tmp_char);
+
+	if (job_ptr->array_task_id != (uint16_t) NO_VAL) {
+		snprintf(tmp_char, sizeof(tmp_char), "%u",
+			 job_ptr->array_task_id);
+	} else {
+		snprintf(tmp_char, sizeof(tmp_char), "N/A");
+	}
+	add_display_treestore_line(update, treestore, &iter,
+				   find_col_name(display_data_job,
+						 SORTID_ARRAY_TASK_ID),
+				   tmp_char);
+
 	if (job_ptr->batch_flag)
 		sprintf(tmp_char, "yes");
 	else
@@ -1806,6 +1835,7 @@ static void _layout_job_record(GtkTreeView *treeview,
 static void _update_job_record(sview_job_info_t *sview_job_info_ptr,
 			       GtkTreeStore *treestore)
 {
+	char tmp_array_job_id[20], tmp_array_task_id[20];
 	char tmp_time_run[40],  tmp_time_resize[40], tmp_time_submit[40];
 	char tmp_time_elig[40], tmp_time_start[40],  tmp_time_end[40];
 	char tmp_time_sus[40],  tmp_time_limit[40],  tmp_alloc_node[40];
@@ -1829,6 +1859,16 @@ static void _update_job_record(sview_job_info_t *sview_job_info_ptr,
 	snprintf(tmp_alloc_node, sizeof(tmp_alloc_node), "%s:%u",
 		 job_ptr->alloc_node, job_ptr->alloc_sid);
 
+	if (job_ptr->array_task_id != (uint16_t) NO_VAL) {
+		snprintf(tmp_array_job_id,  sizeof(tmp_array_job_id),  "%u",
+			 job_ptr->array_job_id);
+		snprintf(tmp_array_task_id, sizeof(tmp_array_task_id), "%u",
+			 job_ptr->array_task_id);
+	} else {
+		snprintf(tmp_array_job_id,  sizeof(tmp_array_job_id),  "N/A");
+		snprintf(tmp_array_task_id, sizeof(tmp_array_task_id), "N/A");
+	}
+
 	if (job_ptr->batch_flag)
 		tmp_batch = "yes";
 	else
@@ -2020,6 +2060,8 @@ static void _update_job_record(sview_job_info_t *sview_job_info_ptr,
 			   SORTID_ACCOUNT,      job_ptr->account,
 			   SORTID_ALLOC,        1,
 			   SORTID_ALLOC_NODE,   tmp_alloc_node,
+			   SORTID_ARRAY_JOB_ID, tmp_array_job_id,
+			   SORTID_ARRAY_TASK_ID,tmp_array_task_id,
 			   SORTID_BATCH,        tmp_batch,
 			   SORTID_BATCH_HOST,   job_ptr->batch_host,
 			   SORTID_COLOR,
-- 
GitLab