From ea034282175eb08057fd6bee8a2c93dbd32a5e0f Mon Sep 17 00:00:00 2001
From: Danny Auble <da@llnl.gov>
Date: Thu, 23 Apr 2009 20:12:13 +0000
Subject: [PATCH] added more functionality for reservations

---
 src/sview/block_info.c | 32 ++++++++------------
 src/sview/job_info.c   | 32 ++++++++------------
 src/sview/node_info.c  |  5 ++-
 src/sview/part_info.c  | 38 +++++++++--------------
 src/sview/popups.c     | 12 +++++++-
 src/sview/resv_info.c  | 69 ++++++++++++++++++++----------------------
 src/sview/sview.c      |  5 +++
 src/sview/sview.h      |  5 +--
 8 files changed, 94 insertions(+), 104 deletions(-)

diff --git a/src/sview/block_info.c b/src/sview/block_info.c
index 3c9e98a912e..cc6f32757aa 100644
--- a/src/sview/block_info.c
+++ b/src/sview/block_info.c
@@ -928,9 +928,7 @@ extern void specific_info_block(popup_info_t *popup_win)
 	int changed = 1;
 	sview_block_info_t *block_ptr = NULL;
 	int j=0, i=-1;
-	char *host = NULL, *host2 = NULL;
-	hostlist_t hostlist = NULL;
-	int found = 0;
+	hostset_t hostset = NULL;
 	ListIterator itr = NULL;
 	
 	if(!spec_info->display_widget) {
@@ -1041,29 +1039,18 @@ display_it:
 				  search_info->gchar_data)) 
 				continue;
 			break;
+		case RESV_PAGE:
 		case NODE_PAGE:
 			if(!block_ptr->nodes)
 				continue;
 			
-			hostlist = hostlist_create(search_info->gchar_data);
-			host = hostlist_shift(hostlist);
-			hostlist_destroy(hostlist);
-			if(!host) 
+			if(!(hostset = hostset_create(search_info->gchar_data)))
 				continue;
-
-			hostlist = hostlist_create(block_ptr->nodes);
-			found = 0;
-			while((host2 = hostlist_shift(hostlist))) { 
-				if(!strcmp(host, host2)) {
-					free(host2);
-					found = 1;
-					break; 
-				}
-				free(host2);
-			}
-			hostlist_destroy(hostlist);
-			if(!found)
+			if(!hostset_intersects(hostset, block_ptr->nodes)) {
+				hostset_destroy(hostset);
 				continue;
+			}
+			hostset_destroy(hostset);				
 			break;
 		case BLOCK_PAGE:
 			switch(search_info->search_type) {
@@ -1162,6 +1149,10 @@ extern void popup_all_block(GtkTreeModel *model, GtkTreeIter *iter, int id)
 	case PART_PAGE:
 		snprintf(title, 100, "Partition(s) containing block %s", name);
 		break;
+	case RESV_PAGE:
+		snprintf(title, 100, "Reservations(s) containing block %s",
+			 name);
+		break;
 	case NODE_PAGE:
 		snprintf(title, 100, "Base Partition(s) in block %s", name);
 		break;
@@ -1203,6 +1194,7 @@ extern void popup_all_block(GtkTreeModel *model, GtkTreeIter *iter, int id)
 		gtk_tree_model_get(model, iter, SORTID_PARTITION, &name, -1);
 		popup_win->spec_info->search_info->gchar_data = name;
 		break;
+	case RESV_PAGE: 
 	case NODE_PAGE: 
 		g_free(name);
 		gtk_tree_model_get(model, iter, SORTID_NODELIST, &name, -1);
diff --git a/src/sview/job_info.c b/src/sview/job_info.c
index fcf3dcd586d..ec4a2828f87 100644
--- a/src/sview/job_info.c
+++ b/src/sview/job_info.c
@@ -2792,9 +2792,8 @@ extern void specific_info_job(popup_info_t *popup_win)
 	job_info_t *job_ptr = NULL;	
 	ListIterator itr = NULL;
 	char name[30], *uname = NULL;
-	char *host = NULL, *host2 = NULL;
-	hostlist_t hostlist = NULL;
-	int found = 0, name_diff;
+	hostset_t hostset = NULL;
+	int name_diff;
 	
 	if(!spec_info->display_widget)
 		setup_popup_info(popup_win, display_data_job, SORTID_CNT);
@@ -2957,6 +2956,11 @@ display_it:
 				  job_ptr->partition))
 				continue;
 			break;
+		case RESV_PAGE:
+			if(strcmp(search_info->gchar_data,
+				  job_ptr->resv_name))
+				continue;
+			break;
 		case BLOCK_PAGE:
 			select_g_sprint_jobinfo(
 				job_ptr->select_jobinfo, 
@@ -2970,25 +2974,13 @@ display_it:
 			if(!job_ptr->nodes)
 				continue;
 			
-			hostlist = hostlist_create(search_info->gchar_data);
-			host = hostlist_shift(hostlist);
-			hostlist_destroy(hostlist);
-			if(!host)
+			if(!(hostset = hostset_create(search_info->gchar_data)))
 				continue;
-			
-			hostlist = hostlist_create(job_ptr->nodes);
-			found = 0;
-			while((host2 = hostlist_shift(hostlist))) { 
-				if(!strcmp(host, host2)) {
-					free(host2);
-					found = 1;
-					break; 
-				}
-				free(host2);
-			}
-			hostlist_destroy(hostlist);
-			if(!found)
+			if(!hostset_intersects(hostset, job_ptr->nodes)) {
+				hostset_destroy(hostset);
 				continue;
+			}
+			hostset_destroy(hostset);				
 			break;
 		default:
 			continue;
diff --git a/src/sview/node_info.c b/src/sview/node_info.c
index 1a90c21a5f8..c9eb292cec4 100644
--- a/src/sview/node_info.c
+++ b/src/sview/node_info.c
@@ -909,7 +909,7 @@ extern void specific_info_node(popup_info_t *popup_win)
 					  label,
 					  0, 1, 0, 1); 
 		gtk_widget_show(label);	
-		spec_info->display_widget = gtk_widget_ref(GTK_WIDGET(label));
+		spec_info->display_widget = gtk_widget_ref(label);
 		return;
 	}
 display_it:	
@@ -1096,6 +1096,9 @@ extern void popup_all_node(GtkTreeModel *model, GtkTreeIter *iter, int id)
 	case PART_PAGE:
 		snprintf(title, 100, "Partition(s) with %s %s", node, name);
 		break;
+	case RESV_PAGE:
+		snprintf(title, 100, "Reservation(s) with %s %s", node, name);
+		break;
 	case BLOCK_PAGE: 
 		snprintf(title, 100, "Blocks(s) with %s %s", node, name);
 		break;
diff --git a/src/sview/part_info.c b/src/sview/part_info.c
index 2aeef4b847b..5443599ac9f 100644
--- a/src/sview/part_info.c
+++ b/src/sview/part_info.c
@@ -191,7 +191,7 @@ static display_data_t options_data_part[] = {
 	{G_TYPE_STRING, NODE_PAGE, "Nodes", TRUE, PART_PAGE},
 #endif
 	{G_TYPE_STRING, SUBMIT_PAGE, "Job Submit", FALSE, PART_PAGE},
-	{G_TYPE_STRING, RESV_PAGE, "Reservation", TRUE, PART_PAGE},
+	{G_TYPE_STRING, RESV_PAGE, "Reservations", TRUE, PART_PAGE},
 	{G_TYPE_NONE, -1, NULL, FALSE, EDIT_NONE}
 };
 
@@ -238,12 +238,11 @@ static void _update_nodes_for_bg(int node_scaling,
        		   
 	hl = hostlist_create(bg_info_record->nodes);
 	while (1) {
-		if (node_name)
-			free(node_name);
 		node_name = hostlist_shift(hl);
 		if (!node_name)
 			break;
 		node_ptr = _find_node(node_name, node_msg);
+		free(node_name);
 		if (!node_ptr)
 			continue;
 		/* cores is overloaded to be the cnodes in an error
@@ -2098,9 +2097,7 @@ extern void specific_info_part(popup_info_t *popup_win)
 	sview_part_info_t *sview_part_info_ptr = NULL;
 	partition_info_t *part_ptr = NULL;
 	ListIterator itr = NULL;
-	char *host = NULL, *host2 = NULL;
-	hostlist_t hostlist = NULL;
-	int found = 0;
+	hostset_t hostset = NULL;
 	
 	if(!spec_info->display_widget)
 		setup_popup_info(popup_win, display_data_part, SORTID_CNT);
@@ -2230,30 +2227,19 @@ display_it:
 		i++;
 		part_ptr = sview_part_info_ptr->part_ptr;	
 		switch(spec_info->type) {
+		case RESV_PAGE:
 		case NODE_PAGE:
 			if(!part_ptr->nodes)
 				continue;
 
-			hostlist = hostlist_create(
-				spec_info->search_info->gchar_data);
-			host = hostlist_shift(hostlist);
-			hostlist_destroy(hostlist);
-			if(!host) 
+			if(!(hostset = hostset_create(
+				     spec_info->search_info->gchar_data)))
 				continue;
-			
-			hostlist = hostlist_create(part_ptr->nodes);
-			found = 0;
-			while((host2 = hostlist_shift(hostlist))) { 
-				if(!strcmp(host, host2)) {
-					free(host2);
-					found = 1;
-					break; 
-				}
-				free(host2);
-			}
-			hostlist_destroy(hostlist);
-			if(!found)
+			if(!hostset_intersects(hostset, part_ptr->nodes)) {
+				hostset_destroy(hostset);
 				continue;
+			}
+			hostset_destroy(hostset);				
 			break;
 		case PART_PAGE:
 		case BLOCK_PAGE:
@@ -2335,6 +2321,9 @@ extern void popup_all_part(GtkTreeModel *model, GtkTreeIter *iter, int id)
 	case JOB_PAGE:
 		snprintf(title, 100, "Job(s) in partition %s", name);
 		break;
+	case RESV_PAGE:
+		snprintf(title, 100, "Reservation(s) in partition %s", name);
+		break;
 	case NODE_PAGE:
 		gtk_tree_model_get(model, iter, SORTID_ONLY_LINE,
 				   &only_line, -1);
@@ -2403,6 +2392,7 @@ extern void popup_all_part(GtkTreeModel *model, GtkTreeIter *iter, int id)
 		popup_win->spec_info->search_info->gchar_data = name;
 		//specific_info_job(popup_win);
 		break;
+	case RESV_PAGE:
 	case NODE_PAGE:
 		g_free(name);
 		gtk_tree_model_get(model, iter, SORTID_NODELIST, &name, -1);
diff --git a/src/sview/popups.c b/src/sview/popups.c
index 3a7d457b340..4c83ca03b4f 100644
--- a/src/sview/popups.c
+++ b/src/sview/popups.c
@@ -152,6 +152,11 @@ void _search_entry(sview_search_info_t *sview_search_info)
 		xfree(lower);
 		
 		break;
+	case SEARCH_RESERVATION_NAME:
+		id = RESV_PAGE;
+		snprintf(title, 100, "Reservation %s info",
+			 sview_search_info->gchar_data);
+		break;
 	default:
 		g_print("unknown search type %d.\n",
 			sview_search_info->search_type);
@@ -799,7 +804,11 @@ extern void create_search_popup(GtkAction *action, gpointer user_data)
 		label = gtk_label_new("Which state?");
 	}
 #endif
-	else {
+	else if(!strcmp(name, "reservation_name")) {
+		sview_search_info.search_type = SEARCH_RESERVATION_NAME;
+		entry = create_entry();
+		label = gtk_label_new("Which reservation");
+	} else {
 		sview_search_info.search_type = 0;
 		goto end_it;
 	}
@@ -841,6 +850,7 @@ extern void create_search_popup(GtkAction *action, gpointer user_data)
 		case SEARCH_BLOCK_SIZE:
 		case SEARCH_PARTITION_NAME:
 		case SEARCH_NODE_NAME:
+		case SEARCH_RESERVATION_NAME:
 			sview_search_info.gchar_data =
 				g_strdup(gtk_entry_get_text(GTK_ENTRY(entry)));
 			break;
diff --git a/src/sview/resv_info.c b/src/sview/resv_info.c
index 42353e00ee6..bd06103c48e 100644
--- a/src/sview/resv_info.c
+++ b/src/sview/resv_info.c
@@ -105,9 +105,9 @@ static display_data_t options_data_resv[] = {
 	{G_TYPE_STRING, RESV_PAGE, "Remove", TRUE, ADMIN_PAGE},
 	{G_TYPE_STRING, RESV_PAGE, "Edit Reservation", TRUE, ADMIN_PAGE},
 	{G_TYPE_STRING, JOB_PAGE, "Jobs", TRUE, RESV_PAGE},
-	{G_TYPE_STRING, PART_PAGE, "Partition", TRUE, RESV_PAGE},
+	{G_TYPE_STRING, PART_PAGE, "Partitions", TRUE, RESV_PAGE},
 #ifdef HAVE_BG
-	{G_TYPE_STRING, BLOCK_PAGE, "Block", TRUE, RESV_PAGE},
+	{G_TYPE_STRING, BLOCK_PAGE, "Blocks", TRUE, RESV_PAGE},
 	{G_TYPE_STRING, NODE_PAGE, "Base Partitions", TRUE, RESV_PAGE},
 #else
 	{G_TYPE_STRING, NODE_PAGE, "Nodes", TRUE, RESV_PAGE},
@@ -520,7 +520,7 @@ static void _update_resv_record(sview_resv_info_t *sview_resv_info_ptr,
 	char *tmp_ptr = NULL;
 	char tmp_char[50];
 	reserve_info_t *resv_ptr = sview_resv_info_ptr->resv_ptr;
-		     
+
 	gtk_tree_store_set(treestore, iter, SORTID_UPDATED, 1, -1);
 
 	gtk_tree_store_set(treestore, iter,
@@ -1026,9 +1026,7 @@ extern void specific_info_resv(popup_info_t *popup_win)
 	int changed = 1;
 	sview_resv_info_t *sview_resv_info_ptr = NULL;
 	int j=0, i=-1;
-	char *host = NULL, *host2 = NULL;
-	hostlist_t hostlist = NULL;
-	int found = 0;
+	hostset_t hostset = NULL;
 	ListIterator itr = NULL;
 	
 	if(!spec_info->display_widget) {
@@ -1044,19 +1042,16 @@ extern void specific_info_resv(popup_info_t *popup_win)
 	if((resv_error_code = 
 	    get_new_info_resv(&resv_info_ptr, popup_win->force_refresh))
 	   == SLURM_NO_CHANGE_IN_DATA) { 
-		if(!spec_info->display_widget 
-		   || spec_info->view == ERROR_VIEW) {
+		if(!spec_info->display_widget || spec_info->view == ERROR_VIEW)
 			goto display_it;
-		}
-		changed = 0;
-		
+		changed = 0;		
 	} else if (resv_error_code != SLURM_SUCCESS) {
 		if(spec_info->view == ERROR_VIEW)
 			goto end_it;
 		spec_info->view = ERROR_VIEW;
 		if(spec_info->display_widget)
 			gtk_widget_destroy(spec_info->display_widget);
-		sprintf(error_char, "slurm_load_node_select: %s",
+		sprintf(error_char, "get_new_info_resv: %s",
 			slurm_strerror(slurm_get_errno()));
 		label = gtk_label_new(error_char);
 		gtk_table_attach_defaults(popup_win->table, 
@@ -1118,45 +1113,43 @@ display_it:
 		resv_ptr = sview_resv_info_ptr->resv_ptr;	
 		switch(spec_info->type) {
 		case PART_PAGE:
-			if(strcmp(resv_ptr->partition, 
-				  search_info->gchar_data)) 
-				continue;
-			break;
 		case BLOCK_PAGE:
 		case NODE_PAGE:
 			if(!resv_ptr->node_list)
 				continue;
 			
-			hostlist = hostlist_create(search_info->gchar_data);
-			host = hostlist_shift(hostlist);
-			hostlist_destroy(hostlist);
-			if(!host) 
+			if(!(hostset = hostset_create(search_info->gchar_data)))
 				continue;
-
-			hostlist = hostlist_create(resv_ptr->node_list);
-			found = 0;
-			while((host2 = hostlist_shift(hostlist))) { 
-				if(!strcmp(host, host2)) {
-					free(host2);
-					found = 1;
-					break; 
-				}
-				free(host2);
-			}
-			hostlist_destroy(hostlist);
-			if(!found)
+			if(!hostset_intersects(hostset, resv_ptr->node_list)) {
+				hostset_destroy(hostset);
 				continue;
+			}
+			hostset_destroy(hostset);				
 			break;
 		case JOB_PAGE:
 			if(strcmp(resv_ptr->name, 
 				  search_info->gchar_data)) 
 				continue;
 			break;
+		case RESV_PAGE:
+			switch(search_info->search_type) {
+			case SEARCH_RESERVATION_NAME:
+				if(!search_info->gchar_data)
+					continue;
+				
+				if(strcmp(resv_ptr->name, 
+					  search_info->gchar_data)) 
+					continue;
+				break;
+			default:
+				continue;
+			}
+			break;
 		default:
 			g_print("Unknown type %d\n", spec_info->type);
 			continue;
 		}
-		list_push(send_resv_list, resv_ptr);
+		list_push(send_resv_list, sview_resv_info_ptr);
 		j=0;
 		while(resv_ptr->node_inx[j] >= 0) {
 			change_grid_color(
@@ -1168,8 +1161,11 @@ display_it:
 	}
 	list_iterator_destroy(itr);
 	 
+	put_buttons_in_table(popup_win->grid_table,
+			     popup_win->grid_button_list);
+
 	_update_info_resv(send_resv_list, 
-			   GTK_TREE_VIEW(spec_info->display_widget));
+			  GTK_TREE_VIEW(spec_info->display_widget));
 	list_destroy(send_resv_list);
 end_it:
 	popup_win->toggled = 0;
@@ -1262,12 +1258,13 @@ extern void popup_all_resv(GtkTreeModel *model, GtkTreeIter *iter, int id)
 
 	switch(id) {
 	case JOB_PAGE:
-	case BLOCK_PAGE: 
 	case INFO_PAGE:
 		popup_win->spec_info->search_info->gchar_data = name;
 		//specific_info_job(popup_win);
 		break;
+	case BLOCK_PAGE: 
 	case NODE_PAGE:
+	case PART_PAGE:
 		g_free(name);
 		gtk_tree_model_get(model, iter, SORTID_NODE_LIST, &name, -1);
 		popup_win->spec_info->search_info->gchar_data = name;
diff --git a/src/sview/sview.c b/src/sview/sview.c
index 4b128406247..f4981a669a9 100644
--- a/src/sview/sview.c
+++ b/src/sview/sview.c
@@ -384,6 +384,8 @@ static GtkWidget *_get_menubar_menu(GtkWidget *window, GtkWidget *notebook)
 		"      <separator/>"
 		"        <menuitem action='node_name'/>"
 		"        <menuitem action='node_state'/>"
+		"      <separator/>"
+		"        <menuitem action='reservation_name'/>"
 		"      </menu>"
 		"      <menuitem action='refresh'/>"
 		"      <menuitem action='reconfig'/>"
@@ -464,6 +466,9 @@ static GtkWidget *_get_menubar_menu(GtkWidget *window, GtkWidget *notebook)
 		 "", "Search for a Node in a given state", 
 #endif
 		 G_CALLBACK(create_search_popup)},		
+		{"reservation_name", NULL, "Reservation Name", 
+		 "", "Search for reservation", 
+		 G_CALLBACK(create_search_popup)},
 		{"tab_pos", NULL, "_Tab Pos"},
 		{"interval", GTK_STOCK_REFRESH, "Set Refresh _Interval", 
 		 "<control>i", "Change Refresh Interval", 
diff --git a/src/sview/sview.h b/src/sview/sview.h
index e516a7ce5cd..1c3727215c9 100644
--- a/src/sview/sview.h
+++ b/src/sview/sview.h
@@ -86,9 +86,9 @@
 enum { JOB_PAGE, 
        STEP_PAGE, 
        PART_PAGE,
-       RESV_PAGE,
        NODE_PAGE, 
        BLOCK_PAGE, 
+       RESV_PAGE,
        SUBMIT_PAGE,
        ADMIN_PAGE,
        INFO_PAGE,
@@ -127,7 +127,8 @@ typedef enum { SEARCH_JOB_ID = 1,
 	       SEARCH_PARTITION_NAME,
 	       SEARCH_PARTITION_STATE,
 	       SEARCH_NODE_NAME,
-	       SEARCH_NODE_STATE
+	       SEARCH_NODE_STATE,
+	       SEARCH_RESERVATION_NAME,
 } sview_search_type_t;
 
 
-- 
GitLab