Ejemplo n.º 1
0
/* Load current node table information into *node_buffer_pptr */
extern int
scontrol_load_nodes (node_info_msg_t ** node_buffer_pptr, uint16_t show_flags)
{
	int error_code;
	static int last_show_flags = 0xffff;
	node_info_msg_t *node_info_ptr = NULL;

	if (old_node_info_ptr) {
		if (last_show_flags != show_flags)
			old_node_info_ptr->last_update = (time_t) 0;
		error_code = slurm_load_node (old_node_info_ptr->last_update,
					      &node_info_ptr, show_flags);
		if (error_code == SLURM_SUCCESS)
			slurm_free_node_info_msg (old_node_info_ptr);
		else if (slurm_get_errno () == SLURM_NO_CHANGE_IN_DATA) {
			node_info_ptr = old_node_info_ptr;
			error_code = SLURM_SUCCESS;
			if (quiet_flag == -1)
				printf ("slurm_load_node no change in data\n");
		}
	}
	else
		error_code = slurm_load_node ((time_t) NULL, &node_info_ptr,
					      show_flags);

	if (error_code == SLURM_SUCCESS) {
		old_node_info_ptr = node_info_ptr;
		last_show_flags = show_flags;
		*node_buffer_pptr = node_info_ptr;
	}

	return error_code;
}
Ejemplo n.º 2
0
/* This set of functions loads/free node information so that we can map a job's
 * core bitmap to it's CPU IDs based upon the thread count on each node. */
static void _load_node_info(void)
{
	slurm_mutex_lock(&job_node_info_lock);
	if (!job_node_ptr)
		(void) slurm_load_node((time_t) NULL, &job_node_ptr, 0);
	slurm_mutex_unlock(&job_node_info_lock);
}
Ejemplo n.º 3
0
// Get bar summaries for cluster nodes
void ClusterMenu::get_lines() {
    // First we set the time of this update
    last_update = std::chrono::steady_clock::now();

    // Call SLURM API to write node information to pointer
    // Free pointer memory first if it has been previously set
    if (node_info_buffer_ptr != NULL) {
        slurm_free_node_info_msg(node_info_buffer_ptr);
    }
    slurm_load_node ((time_t) NULL, &node_info_buffer_ptr, SHOW_ALL);

    // Create a NodeContainer struct and populate with node information
    node_container.populate_nodes_from_slurm(node_info_buffer_ptr);

    // Call API function, pass job_info_ptr as reference (double pointer); flags must be SHOW_DETAIL to get job allocations
    // Free pointer memory first if it has been previously set
    if (job_info_buffer_ptr != NULL) {
        slurm_free_job_info_msg(job_info_buffer_ptr);
    }
    slurm_load_jobs((time_t) NULL, &job_info_buffer_ptr, SHOW_DETAIL);

    // Populate nodes with job allocations
    node_container.populate_job_allocations_from_slurm(job_info_buffer_ptr);

    // Get line content
    lines = node_container.get_node_bar_summary(32);

    // Record largest line for later use in horizontal scrolling
    get_longest_line();
}
Ejemplo n.º 4
0
bitstr_t *get_requested_node_bitmap(void)
{
	static bitstr_t *bitmap = NULL;
	static node_info_msg_t *old_node_ptr = NULL, *new_node_ptr;
	int error_code;
	int i = 0;
	node_info_t *node_ptr = NULL;

	if (!params.hl)
		return NULL;

	if (old_node_ptr) {
		error_code = slurm_load_node(old_node_ptr->last_update,
					     &new_node_ptr, SHOW_ALL);
		if (error_code == SLURM_SUCCESS)
			slurm_free_node_info_msg(old_node_ptr);
		else if (slurm_get_errno() == SLURM_NO_CHANGE_IN_DATA)
			return bitmap;
	} else {
		error_code = slurm_load_node((time_t) NULL, &new_node_ptr,
					     SHOW_ALL);
	}

	if (bitmap)
		FREE_NULL_BITMAP(bitmap);

	if (error_code) {
		slurm_perror("slurm_load_node");
		return NULL;
	}

	old_node_ptr = new_node_ptr;

	bitmap = bit_alloc(old_node_ptr->record_count);
	for (i = 0; i < old_node_ptr->record_count; i++) {
		node_ptr = &(old_node_ptr->node_array[i]);
		if (hostlist_find(params.hl, node_ptr->name) != -1)
			bit_set(bitmap, i);
	}
	return bitmap;
}
Ejemplo n.º 5
0
/* Return the maximum number of processors for any node in the cluster */
static int   _max_cpus_per_node(void)
{
	int error_code, max_cpus = 1;
	node_info_msg_t *node_info_ptr = NULL;

	error_code = slurm_load_node ((time_t) NULL, &node_info_ptr,
				      params.all_flag);
	if (error_code == SLURM_SUCCESS) {
		int i;
		node_info_t *node_ptr = node_info_ptr->node_array;
		for (i=0; i<node_info_ptr->record_count; i++) {
			max_cpus = MAX(max_cpus, node_ptr[i].cpus);
		}
		slurm_free_node_info_msg (node_info_ptr);
	}

	return max_cpus;
}
Ejemplo n.º 6
0
int main() {
    // Initialise container for all node information
    NodeContainer node_container;


    // Declare a pointer to which the SLURM API writes node information
    node_info_msg_t * node_info_buffer_ptr = NULL;
    // Call SLURM API to write node information to pointer
    slurm_load_node((time_t) NULL, &node_info_buffer_ptr, SHOW_ALL);

    // Create a NodeContainer struct and populate with node information
    node_container.populate_nodes_from_slurm(node_info_buffer_ptr);


    // Declare a pointer to which the SLURM API writes job information
    job_info_msg_t * job_info_buffer_ptr = NULL;
    // Call API function, pass job_info_ptr as reference (double pointer); flags must be SHOW_DETAIL to get job allocations
    slurm_load_jobs((time_t) NULL, &job_info_buffer_ptr, SHOW_DETAIL);

    // Populate nodes with job allocations
    node_container.populate_job_allocations_from_slurm(job_info_buffer_ptr);


    // Get lines for output
    std::vector<std::string> lines = node_container.get_node_bar_summary(32);

    // Print output
    for (std::vector<std::string>::iterator it = lines.begin(); it != lines.end(); ++it) {
        printf("%s\n", it->c_str());
    }


    // Clean up and nicely deallocated memory for SLURM pointers
    slurm_free_node_info_msg(node_info_buffer_ptr);
    slurm_free_job_info_msg(job_info_buffer_ptr);
}
int main()
{

//===========================================================================================
// Declarations
//===========================================================================================
	
	int i,j;
	int i2,j2;
	
	job_info_msg_t *job_ptr;	
	partition_info_msg_t *prt_ptr = NULL;
	node_info_msg_t *node_ptr = NULL;

	int err = SLURM_SUCCESS;
	err = slurm_load_partitions((time_t) NULL, &prt_ptr, 0);
	err = slurm_load_node((time_t) NULL, &node_ptr, 0);
	err = slurm_load_jobs((time_t) NULL, &job_ptr, 0);	

	Linked_List_Node* job_llist;
	struct json_object *partition = json_object_new_object();
	struct json_object *node = json_object_new_object();


//===========================================================================================
// Filling hash tables
//===========================================================================================

	j2 = 0;	
	i2 = 0;

	//fill node_job hash
	if (job_ptr->record_count > 0) {

		for (i = 0; i < job_ptr->record_count; i++) {
			
			
			j2=0;
			while( job_ptr->job_array[i].node_inx[j2] >= 0){
				
				i2 = 0;
								
				for(i2 = job_ptr->job_array[i].node_inx[j2];i2 <= job_ptr->job_array[i].node_inx[j2+1];i2++) {

					node_job_put(node_ptr->node_array[i2].name,job_ptr -> job_array[i]);
				}
				j2+=2;
			}
		
		}
	}
	

//============================================================================================
// Creating Output in Json
//============================================================================================

	// create json	

	int total_node_unknown = 0;
	int total_node_down = 0;
	int total_node_idle = 0;
	int total_node_allocated = 0;
	
	int current_node_unknown;
	int current_node_down;
	int current_node_idle;
	int current_node_allocated;

	int current_job_running;
	int current_job_waiting;
	int current_job_stopped;


	if(prt_ptr -> record_count > 0){	
	
		for (i = 0; i < prt_ptr->record_count; i++) {


			current_node_unknown = 0;
			current_node_down = 0;
			current_node_idle = 0;
			current_node_allocated = 0;

			current_job_running = 0;
			current_job_waiting = 0;			
			current_job_stopped = 0;
			
			
			int j2=0;
			while( prt_ptr->partition_array[i].node_inx[j2] >= 0){
				
				int i2 = 0;

				for(i2 = prt_ptr->partition_array[i].node_inx[j2];i2 <= prt_ptr->partition_array[i].node_inx[j2+1];i2++) {


					if(node_ptr->node_array[i2].node_state == 5 || node_ptr->node_array[i2].node_state == 3){   total_node_allocated++;   current_node_allocated++;}
					else if(node_ptr->node_array[i2].node_state == 1){ 	total_node_down++;      current_node_down++;}
					else if(node_ptr->node_array[i2].node_state == 2 || node_ptr->node_array[i2].node_state == 6){ 	total_node_idle++;      current_node_idle++;}
					else { 	total_node_unknown++; current_node_unknown++;}
	
					job_llist = node_job_get(node_ptr->node_array[i2].name); 			//get job name	
					while( job_llist != NULL){
						

						if(job_llist->value_job.job_state == 2 || job_llist->value_job.job_state == 8 || job_llist->value_job.job_state == 0) 	current_job_waiting++;
						else if(job_llist->value_job.job_state == 1) 	current_job_running++;
						else	current_job_stopped++;
					
						job_llist = job_llist->next;			
									
					}
				}	
				j2+=2;		
	
			}
			
			json_object_object_add(node, "Allocated", json_object_new_int(current_node_allocated));
			json_object_object_add(node, "Down", json_object_new_int(current_node_down));
			json_object_object_add(node, "Idle", json_object_new_int(current_node_idle));
			json_object_object_add(node, "Unknown", json_object_new_int(current_node_unknown));
			json_object_object_add(node, "Running", json_object_new_int(current_job_running));
			json_object_object_add(node, "Wating", json_object_new_int(current_job_waiting));
			json_object_object_add(node, "Stopped", json_object_new_int(current_job_stopped));

			json_object_object_add(partition, prt_ptr->partition_array[i].name , node);

		}
	
	}		
	
	node = json_object_new_object();
	json_object_object_add(node, "Unknown", json_object_new_int(total_node_unknown));
	json_object_object_add(node, "Down", json_object_new_int(total_node_down));
	json_object_object_add(node, "Idle", json_object_new_int(total_node_idle));
	json_object_object_add(node, "Allocated", json_object_new_int(total_node_allocated));
	
	json_object_object_add(partition, "General", node);
	printf("Content-type: text/html\n\n%s",json_object_to_json_string(partition));

	slurm_free_partition_info_msg(prt_ptr);
	slurm_free_node_info_msg(node_ptr);
	return 1;


}
Ejemplo n.º 8
0
int main(int argc, char **argv)
{
	log_options_t opts = LOG_OPTS_STDERR_ONLY;
	node_info_msg_t *node_info_ptr = NULL;
	node_info_msg_t *new_node_ptr = NULL;
	int error_code;
	int height = 40;
	int width = 100;
	int startx = 0;
	int starty = 0;
	int end = 0;
	int i;
	int rc;

	slurm_conf_init(NULL);
	log_init(xbasename(argv[0]), opts, SYSLOG_FACILITY_DAEMON, NULL);
	parse_command_line(argc, argv);
	if (params.verbose) {
		opts.stderr_level += params.verbose;
		log_alter(opts, SYSLOG_FACILITY_USER, NULL);
	}

	if (params.cluster_dims == 4) {
		min_screen_width = 92;
	} else if (params.cluster_dims == 3)
		min_screen_width = 92;

	/* no need for this if you are resolving */
	while (slurm_load_node((time_t) NULL,
			       &new_node_ptr, SHOW_ALL)) {
		if (params.resolve || (params.display == COMMANDS)) {
			new_node_ptr = NULL;
			break;		/* just continue */
		}
		error_code = slurm_get_errno();
		printf("slurm_load_node: %s\n",
		       slurm_strerror(error_code));
		if (params.iterate == 0)
			exit(1);
		sleep(10);	/* keep trying to reconnect */
	}

	select_g_ba_init(new_node_ptr, 0);

	if (dim_size == NULL) {
		dim_size = get_cluster_dims(new_node_ptr);
		if ((dim_size == NULL) || (dim_size[0] < 1))
			fatal("Invalid system dimensions");
	}
	_init_colors();

	if (params.resolve) {
		char *ret_str = resolve_mp(params.resolve, new_node_ptr);
		if (ret_str) {
			printf("%s", ret_str);
			xfree(ret_str);
		}
		_smap_exit(0);	/* Calls exit(), no return */
	}
	if (!params.commandline) {
		int check_width = min_screen_width;

		initscr();
		init_grid(new_node_ptr, COLS);
		signal(SIGWINCH, (void (*)(int))_resize_handler);

		if (params.cluster_dims == 4) {
			height = dim_size[2] * dim_size[3] + dim_size[2] + 3;
			width = (dim_size[1] + dim_size[3] + 1) * dim_size[0]
				 + 2;
			check_width += width;
		} else if (params.cluster_dims == 3) {
			height = dim_size[1] * dim_size[2] + dim_size[1] + 3;
			width = dim_size[0] + dim_size[2] + 3;
			check_width += width;
		} else {
			height = 10;
			width = COLS;
		}

	        if ((COLS < check_width) || (LINES < height)) {
			endwin();
			error("Screen is too small make sure the screen "
			      "is at least %dx%d\n"
			      "Right now it is %dx%d\n",
			      check_width,
			      height,
			      COLS,
			      LINES);
			_smap_exit(1);	/* Calls exit(), no return */
		}

		raw();
		keypad(stdscr, true);
		noecho();
		cbreak();
		curs_set(0);
		nodelay(stdscr, true);
		start_color();
		_set_pairs();

		grid_win = newwin(height, width, starty, startx);
		max_display = (getmaxy(grid_win) - 1) * (getmaxx(grid_win) - 1);

		if (params.cluster_dims == 4) {
			startx = width;
			width = COLS - width - 2;
			height = LINES;
		} else if (params.cluster_dims == 3) {
			startx = width;
			width = COLS - width - 2;
			height = LINES;
		} else {
			startx = 0;
			starty = height;
			height = LINES - height;
		}

		text_win = newwin(height, width, starty, startx);
        }
	while (!end) {
		if (!params.commandline) {
			_get_option();
redraw:
			clear_window(text_win);
			clear_window(grid_win);
			move(0, 0);

			update_grid(new_node_ptr);
			main_xcord = 1;
			main_ycord = 1;
		}

		if (!params.no_header)
			print_date();

		clear_grid();
		switch (params.display) {
		case JOBS:
			get_job();
			break;
		case RESERVATIONS:
			get_reservation();
			break;
		case SLURMPART:
			get_slurm_part();
			break;
		case COMMANDS:
#ifdef HAVE_BG
			wclear(text_win);
			get_command();
#else
			error("Must be on a real BG SYSTEM to "
			      "run this command");
			if (!params.commandline)
				endwin();
			_smap_exit(1);	/* Calls exit(), no return */
#endif
			break;
		case BGPART:
			if (params.cluster_flags & CLUSTER_FLAG_BG)
				get_bg_part();
			else {
				error("Must be on a BG SYSTEM to "
				      "run this command");
				if (!params.commandline)
					endwin();
				_smap_exit(1);	/* Calls exit(), no return */
			}
			break;
		}

		if (!params.commandline) {
			box(text_win, 0, 0);
			wnoutrefresh(text_win);

			print_grid();
			box(grid_win, 0, 0);
			wnoutrefresh(grid_win);

			doupdate();

			node_info_ptr = new_node_ptr;
			if (node_info_ptr) {
				error_code = slurm_load_node(
					node_info_ptr->last_update,
					&new_node_ptr, SHOW_ALL);
				if (error_code == SLURM_SUCCESS)
					slurm_free_node_info_msg(
						node_info_ptr);
				else if (slurm_get_errno()
					 == SLURM_NO_CHANGE_IN_DATA) {
					error_code = SLURM_SUCCESS;
					new_node_ptr = node_info_ptr;
				}
			} else {
				error_code = slurm_load_node(
					(time_t) NULL,
					&new_node_ptr, SHOW_ALL);
			}
			if (error_code && (quiet_flag != 1)) {
				if (!params.commandline) {
					mvwprintw(
						text_win,
						main_ycord,
						1,
						"slurm_load_node: %s",
						slurm_strerror(
							slurm_get_errno()));
					main_ycord++;
				} else {
					printf("slurm_load_node: %s",
					       slurm_strerror(
						       slurm_get_errno()));
				}
			}
		}

		if (params.iterate) {
			for (i = 0; i < params.iterate; i++) {
				sleep(1);
				if (!params.commandline) {
					if ((rc = _get_option()) == 1)
						goto redraw;
					else if (resize_screen) {
						resize_screen = 0;
						goto redraw;
					}
				}
			}
		} else
			break;

	}

	if (!params.commandline) {
		nodelay(stdscr, false);
		getch();
		endwin();
	}

	_smap_exit(0);	/* Calls exit(), no return */
	exit(0);	/* Redundant, but eliminates compiler warning */
}
Ejemplo n.º 9
0
/*
 * _query_server - download the current server state
 * part_pptr IN/OUT - partition information message
 * node_pptr IN/OUT - node information message
 * block_pptr IN/OUT - BlueGene block data
 * reserv_pptr IN/OUT - reservation information message
 * clear_old IN - If set, then always replace old data, needed when going
 *		  between clusters.
 * RET zero or error code
 */
static int
_query_server(partition_info_msg_t ** part_pptr,
	      node_info_msg_t ** node_pptr,
	      block_info_msg_t ** block_pptr,
	      reserve_info_msg_t ** reserv_pptr,
	      bool clear_old)
{
	static partition_info_msg_t *old_part_ptr = NULL, *new_part_ptr;
	static node_info_msg_t *old_node_ptr = NULL, *new_node_ptr;
	static block_info_msg_t *old_bg_ptr = NULL, *new_bg_ptr;
	static reserve_info_msg_t *old_resv_ptr = NULL, *new_resv_ptr;
	int error_code;
	uint16_t show_flags = 0;
	int cc;
	node_info_t *node_ptr;

	if (params.all_flag)
		show_flags |= SHOW_ALL;

	if (old_part_ptr) {
		if (clear_old)
			old_part_ptr->last_update = 0;
		error_code = slurm_load_partitions(old_part_ptr->last_update,
						   &new_part_ptr, show_flags);
		if (error_code == SLURM_SUCCESS)
			slurm_free_partition_info_msg(old_part_ptr);
		else if (slurm_get_errno() == SLURM_NO_CHANGE_IN_DATA) {
			error_code = SLURM_SUCCESS;
			new_part_ptr = old_part_ptr;
		}
	} else {
		error_code = slurm_load_partitions((time_t) NULL, &new_part_ptr,
						   show_flags);
	}
	if (error_code) {
		slurm_perror("slurm_load_partitions");
		return error_code;
	}

	old_part_ptr = new_part_ptr;
	*part_pptr = new_part_ptr;

	if (old_node_ptr) {
		if (clear_old)
			old_node_ptr->last_update = 0;
		if (params.node_name_single) {
			error_code = slurm_load_node_single(&new_node_ptr,
							    params.nodes,
							    show_flags);
		} else {
			error_code = slurm_load_node(old_node_ptr->last_update,
						     &new_node_ptr, show_flags);
		}
		if (error_code == SLURM_SUCCESS)
			slurm_free_node_info_msg(old_node_ptr);
		else if (slurm_get_errno() == SLURM_NO_CHANGE_IN_DATA) {
			error_code = SLURM_SUCCESS;
			new_node_ptr = old_node_ptr;
		}
	} else if (params.node_name_single) {
		error_code = slurm_load_node_single(&new_node_ptr, params.nodes,
						    show_flags);
	} else {
		error_code = slurm_load_node((time_t) NULL, &new_node_ptr,
					     show_flags);
	}

	if (error_code) {
		slurm_perror("slurm_load_node");
		return error_code;
	}
	old_node_ptr = new_node_ptr;
	*node_pptr = new_node_ptr;

	/* Set the node state as NODE_STATE_MIXED. */
	for (cc = 0; cc < new_node_ptr->record_count; cc++) {
		node_ptr = &(new_node_ptr->node_array[cc]);
		if (IS_NODE_DRAIN(node_ptr)) {
			/* don't worry about mixed since the
			 * whole node is being drained. */
		} else {
			uint16_t alloc_cpus = 0, err_cpus = 0, idle_cpus;
			int single_node_cpus =
				(node_ptr->cpus / g_node_scaling);

			select_g_select_nodeinfo_get(node_ptr->select_nodeinfo,
						     SELECT_NODEDATA_SUBCNT,
						     NODE_STATE_ALLOCATED,
						     &alloc_cpus);
			if (params.cluster_flags & CLUSTER_FLAG_BG) {
				if (!alloc_cpus &&
				    (IS_NODE_ALLOCATED(node_ptr) ||
				     IS_NODE_COMPLETING(node_ptr)))
					alloc_cpus = node_ptr->cpus;
				else
					alloc_cpus *= single_node_cpus;
			}
			idle_cpus = node_ptr->cpus - alloc_cpus;
			select_g_select_nodeinfo_get(node_ptr->select_nodeinfo,
						     SELECT_NODEDATA_SUBCNT,
						     NODE_STATE_ERROR,
						     &err_cpus);
			if (params.cluster_flags & CLUSTER_FLAG_BG)
				err_cpus *= single_node_cpus;
			idle_cpus -= err_cpus;

			if ((alloc_cpus && err_cpus) ||
			    (idle_cpus  && (idle_cpus != node_ptr->cpus))) {
				node_ptr->node_state &= NODE_STATE_FLAGS;
				node_ptr->node_state |= NODE_STATE_MIXED;
			}
		}
	}

	if (old_resv_ptr) {
		if (clear_old)
			old_resv_ptr->last_update = 0;
		error_code = slurm_load_reservations(old_resv_ptr->last_update,
						     &new_resv_ptr);
		if (error_code == SLURM_SUCCESS)
			slurm_free_reservation_info_msg(old_resv_ptr);
		else if (slurm_get_errno() == SLURM_NO_CHANGE_IN_DATA) {
			error_code = SLURM_SUCCESS;
			new_resv_ptr = old_resv_ptr;
		}
	} else {
		error_code = slurm_load_reservations((time_t) NULL,
						     &new_resv_ptr);
	}

	if (error_code) {
		slurm_perror("slurm_load_reservations");
		return error_code;
	}
	old_resv_ptr = new_resv_ptr;
	*reserv_pptr = new_resv_ptr;

	if (!params.bg_flag)
		return SLURM_SUCCESS;

	if (params.cluster_flags & CLUSTER_FLAG_BG) {
		if (old_bg_ptr) {
			if (clear_old)
				old_bg_ptr->last_update = 0;
			error_code = slurm_load_block_info(
				old_bg_ptr->last_update,
				&new_bg_ptr, show_flags);
			if (error_code == SLURM_SUCCESS)
				slurm_free_block_info_msg(old_bg_ptr);
			else if (slurm_get_errno() == SLURM_NO_CHANGE_IN_DATA) {
				error_code = SLURM_SUCCESS;
				new_bg_ptr = old_bg_ptr;
			}
		} else {
			error_code = slurm_load_block_info((time_t) NULL,
							   &new_bg_ptr,
							   show_flags);
		}
	}

	if (error_code) {
		slurm_perror("slurm_load_block");
		return error_code;
	}
	old_bg_ptr = new_bg_ptr;
	*block_pptr = new_bg_ptr;
	return SLURM_SUCCESS;
}
Ejemplo n.º 10
0
/* This set of functions loads/free node information so that we can map a job's
 * core bitmap to it's CPU IDs based upon the thread count on each node. */
static void _load_node_info(void)
{
	if (!job_node_ptr)
		(void) slurm_load_node((time_t) NULL, &job_node_ptr, 0);
}
Ejemplo n.º 11
0
Archivo: sinfo.c Proyecto: IFCA/slurm
/*
 * _query_server - download the current server state
 * part_pptr IN/OUT - partition information message
 * node_pptr IN/OUT - node information message
 * block_pptr IN/OUT - BlueGene block data
 * reserv_pptr IN/OUT - reservation information message
 * clear_old IN - If set, then always replace old data, needed when going
 *		  between clusters.
 * RET zero or error code
 */
static int
_query_server(partition_info_msg_t ** part_pptr,
	      node_info_msg_t ** node_pptr,
	      block_info_msg_t ** block_pptr,
	      reserve_info_msg_t ** reserv_pptr,
	      bool clear_old)
{
	static partition_info_msg_t *old_part_ptr = NULL, *new_part_ptr;
	static node_info_msg_t *old_node_ptr = NULL, *new_node_ptr;
	static block_info_msg_t *old_bg_ptr = NULL, *new_bg_ptr;
	static reserve_info_msg_t *old_resv_ptr = NULL, *new_resv_ptr;

	int error_code;
	uint16_t show_flags = 0;

	if (params.all_flag)
		show_flags |= SHOW_ALL;

	if (old_part_ptr) {
		if (clear_old)
			old_part_ptr->last_update = 0;
		error_code = slurm_load_partitions(old_part_ptr->last_update,
						   &new_part_ptr, show_flags);
		if (error_code == SLURM_SUCCESS)
			slurm_free_partition_info_msg(old_part_ptr);
		else if (slurm_get_errno() == SLURM_NO_CHANGE_IN_DATA) {
			error_code = SLURM_SUCCESS;
			new_part_ptr = old_part_ptr;
		}
	} else {
		error_code = slurm_load_partitions((time_t) NULL, &new_part_ptr,
						   show_flags);
	}
	if (error_code) {
		slurm_perror("slurm_load_partitions");
		return error_code;
	}

	old_part_ptr = new_part_ptr;
	*part_pptr = new_part_ptr;

	if (old_node_ptr) {
		if (clear_old)
			old_node_ptr->last_update = 0;
		if (params.node_name_single) {
			error_code = slurm_load_node_single(&new_node_ptr,
							    params.nodes,
							    show_flags);
		} else {
			error_code = slurm_load_node(old_node_ptr->last_update,
						     &new_node_ptr, show_flags);
		}
		if (error_code == SLURM_SUCCESS)
			slurm_free_node_info_msg(old_node_ptr);
		else if (slurm_get_errno() == SLURM_NO_CHANGE_IN_DATA) {
			error_code = SLURM_SUCCESS;
			new_node_ptr = old_node_ptr;
		}
	} else if (params.node_name_single) {
		error_code = slurm_load_node_single(&new_node_ptr, params.nodes,
						    show_flags);
	} else {
		error_code = slurm_load_node((time_t) NULL, &new_node_ptr,
					     show_flags);
	}

	if (error_code) {
		slurm_perror("slurm_load_node");
		return error_code;
	}
	old_node_ptr = new_node_ptr;
	*node_pptr = new_node_ptr;

	if (old_resv_ptr) {
		if (clear_old)
			old_resv_ptr->last_update = 0;
		error_code = slurm_load_reservations(old_resv_ptr->last_update,
						     &new_resv_ptr);
		if (error_code == SLURM_SUCCESS)
			slurm_free_reservation_info_msg(old_resv_ptr);
		else if (slurm_get_errno() == SLURM_NO_CHANGE_IN_DATA) {
			error_code = SLURM_SUCCESS;
			new_resv_ptr = old_resv_ptr;
		}
	} else {
		error_code = slurm_load_reservations((time_t) NULL,
						     &new_resv_ptr);
	}

	if (error_code) {
		slurm_perror("slurm_load_reservations");
		return error_code;
	}
	old_resv_ptr = new_resv_ptr;
	*reserv_pptr = new_resv_ptr;

	if (!params.bg_flag)
		return SLURM_SUCCESS;

	if (params.cluster_flags & CLUSTER_FLAG_BG) {
		if (old_bg_ptr) {
			if (clear_old)
				old_bg_ptr->last_update = 0;
			error_code = slurm_load_block_info(
				old_bg_ptr->last_update,
				&new_bg_ptr, show_flags);
			if (error_code == SLURM_SUCCESS)
				slurm_free_block_info_msg(old_bg_ptr);
			else if (slurm_get_errno() == SLURM_NO_CHANGE_IN_DATA) {
				error_code = SLURM_SUCCESS;
				new_bg_ptr = old_bg_ptr;
			}
		} else {
			error_code = slurm_load_block_info((time_t) NULL,
							   &new_bg_ptr,
							   show_flags);
		}
	}

	if (error_code) {
		slurm_perror("slurm_load_block");
		return error_code;
	}
	old_bg_ptr = new_bg_ptr;
	*block_pptr = new_bg_ptr;
	return SLURM_SUCCESS;
}
Ejemplo n.º 12
0
int
get_batch_queues(bridge_batch_manager_t* p_batch_manager,
                 bridge_batch_queue_t** p_p_batch_queues,
                 int* p_batch_queues_nb, char* batch_queue_name)
{
    int fstatus=-1;

    int i,j;

    int queue_nb=0;
    int stored_queue_nb=0;

    bridge_batch_queue_t* bn;

    partition_info_msg_t* ppim;
    partition_info_t* ppi;

    job_info_msg_t* pjim;
    job_info_t* pji;

    node_info_msg_t* pnim;
    node_info_t* pni;

    /* get slurm partition infos */
    if (slurm_load_partitions(0,&ppim,SHOW_ALL) != 0) {
        DEBUG3_LOGGER("unable to get slurm partitions infos");
        ppim=NULL;
        goto exit;
    }

    /* get nodes status */
    if(slurm_load_node(0,&pnim,SHOW_ALL)) {
        DEBUG3_LOGGER("unable to get nodes informations");
        slurm_free_partition_info_msg(ppim);
        pnim=NULL;
        goto exit;
    }

    /* get slurm job infos */
    if (slurm_load_jobs(0,&pjim,SHOW_ALL) != 0) {
        DEBUG3_LOGGER("unable to get allocations informations");
        slurm_free_partition_info_msg(ppim);
        slurm_free_node_info_msg(pnim);
        goto exit;
    }

    /* build/initialize storage structures */
    queue_nb = ppim->record_count;
    if (*p_p_batch_queues != NULL) {
        if (*p_batch_queues_nb < queue_nb)
            queue_nb=*p_batch_queues_nb;
    }
    else {
        *p_p_batch_queues = (bridge_batch_queue_t*)
                            malloc(queue_nb*(sizeof(bridge_batch_queue_t)+1));
        if (*p_p_batch_queues == NULL) {
            *p_batch_queues_nb = 0;
            queue_nb = *p_batch_queues_nb;
        }
        else {
            *p_batch_queues_nb = queue_nb;
        }
    }
    stored_queue_nb=0;

    /* fill queue structures */
    for (i=0; i<ppim->record_count && stored_queue_nb<queue_nb; i++) {

        /* get partition pointer */
        ppi=ppim->partition_array+i;

        if (ppi->name == NULL)
            continue;

        /* queue name filter */
        if (batch_queue_name != NULL &&
                strcmp(batch_queue_name,ppi->name) != 0)
            continue;

        bn = &(*p_p_batch_queues)[stored_queue_nb];

        /* put default values */
        init_batch_queue(p_batch_manager,bn);

        /* queue Name */
        bn->name=strdup(ppi->name);

        bn->default_queue = (uint32_t) ( ppi->flags | PART_FLAG_DEFAULT);
        bn->priority = (uint32_t) ppi->priority;

        /* queue activity */
        if(ppi->state_up == PARTITION_UP) {
            bn->activity = BRIDGE_BATCH_QUEUE_ACTIVITY_ACTIVE ;
            bn->state = BRIDGE_BATCH_QUEUE_STATE_OPENED ;
        } else if (ppi->state_up == PARTITION_DRAIN) {
            bn->activity = BRIDGE_BATCH_QUEUE_ACTIVITY_ACTIVE ;
            bn->state = BRIDGE_BATCH_QUEUE_STATE_CLOSED ;
        } else if (ppi->state_up == PARTITION_DOWN) {
            bn->activity = BRIDGE_BATCH_QUEUE_ACTIVITY_INACTIVE ;
            bn->state = BRIDGE_BATCH_QUEUE_STATE_OPENED ;
        } else if (ppi->state_up == PARTITION_INACTIVE) {
            bn->activity = BRIDGE_BATCH_QUEUE_ACTIVITY_INACTIVE ;
            bn->state = BRIDGE_BATCH_QUEUE_STATE_CLOSED ;
        } else {
            bn->activity = BRIDGE_BATCH_QUEUE_ACTIVITY_UNKNOWN ;
            bn->state = BRIDGE_BATCH_QUEUE_STATE_UNKNOWN ;
        }

        /* max times */
        if ( ppi->max_time != INFINITE )
            bn->seq_time_max = (uint32_t) ppi->max_time * 60 ;
        else
            bn->seq_time_max = NO_LIMIT;
        bn->par_time_max = bn->seq_time_max ;

        /* slurm */
        for ( j=0 ; j < pjim->record_count ; j++ ) {

            pji=pjim->job_array+j;

            if ( strcmp(pji->partition,ppi->name) != 0 )
                continue;

            switch ( pji->job_state & JOB_STATE_BASE ) {
            case JOB_PENDING :
                bn->jobs_nb++;
                bn->pending_jobs_nb++;
                break;
            case JOB_RUNNING :
                bn->jobs_nb++;
                bn->running_jobs_nb++;
                break;
            case JOB_SUSPENDED :
                bn->jobs_nb++;
                bn->syssuspended_jobs_nb++;
                break;
            }

        }

        /* Slurm does not provide information about Min and Max cpus per
         * partition. So we use the following method :
         *
         * if partition->name ~= /.*_seq/ min=max=1
         * otherwise, calculate it using MinNodes, MaxNodes and nodes
         * informations
         */

        int done = 0 ;
        char * p;
        p = rindex(ppi->name,'_');
        if ( p != NULL ) {
            if ( strcmp(p+1,"seq") == 0 ) {
                done = 1;
                bn->par_cores_nb_min = 1;
                bn->par_cores_nb_max = 1;
            }
        }

        if ( ! done ) {
            /* use partition nodes information to build the min and max */
            /* number of cores (only min and max nodes number are provided */
            /* by slurm so we have to build this information) */
            uint32_t max_cpus_per_node=0;
            uint32_t min_cpus_per_node=-1;
            bridge_nodelist_t list1,list2;
            bridge_nodelist_init(&list1,NULL,0);
            bridge_nodelist_add_nodes(&list1,ppi->nodes);
            for ( j=0 ; j < pnim->record_count ; j++ ) {
                pni=pnim->node_array+j;
                bridge_nodelist_init(&list2,NULL,0);
                bridge_nodelist_add_nodes(&list2,pni->name);
                if(bridge_nodelist_intersects(&list1,&list2)==0) {
                    bridge_nodelist_free_contents(&list2);
                    continue;
                }
                if ( pni->cpus > max_cpus_per_node )
                    max_cpus_per_node = pni->cpus ;
                if ( pni->cpus < min_cpus_per_node )
                    min_cpus_per_node = pni->cpus ;
                bridge_nodelist_free_contents(&list2);
            }
            bridge_nodelist_free_contents(&list1);

            if ( max_cpus_per_node > 0 && ppi->max_nodes != INFINITE )
                bn->par_cores_nb_max = max_cpus_per_node * ppi->max_nodes ;
            if ( min_cpus_per_node < (uint32_t) -1 && ppi->min_nodes > 1 )
                bn->par_cores_nb_min = min_cpus_per_node * ppi->min_nodes ;
        }

        stored_queue_nb++;
    }

    fstatus=0;

    /* free slurm informations */
    slurm_free_job_info_msg(pjim);
    slurm_free_node_info_msg(pnim);
    slurm_free_partition_info_msg(ppim);


    if(stored_queue_nb<queue_nb) {
        *p_p_batch_queues=(bridge_batch_queue_t*)
                          realloc(*p_p_batch_queues,
                                  stored_queue_nb*(sizeof(bridge_batch_queue_t)+1));
        if(*p_p_batch_queues==NULL)
            *p_batch_queues_nb=0;
        else
            *p_batch_queues_nb=stored_queue_nb;
    }

exit:

    return fstatus;
}
Ejemplo n.º 13
0
Archivo: smap.c Proyecto: VURM/slurm
int main(int argc, char *argv[])
{
	log_options_t opts = LOG_OPTS_STDERR_ONLY;
	node_info_msg_t *node_info_ptr = NULL;
	node_info_msg_t *new_node_ptr = NULL;
	int error_code;
	int height = 40;
	int width = 100;
	int startx = 0;
	int starty = 0;
	int end = 0;
	int i;
	int rc;
	int mapset = 0;

	log_init(xbasename(argv[0]), opts, SYSLOG_FACILITY_DAEMON, NULL);
	parse_command_line(argc, argv);
	if (params.verbose) {
		opts.stderr_level += params.verbose;
		log_alter(opts, SYSLOG_FACILITY_USER, NULL);
	}

	if (params.cluster_dims == 4) {
		min_screen_width = 92;
	} else if (params.cluster_dims == 3)
		min_screen_width = 92;

	while (slurm_load_node((time_t) NULL, &new_node_ptr, SHOW_ALL)) {
		error_code = slurm_get_errno();
		printf("slurm_load_node: %s\n", slurm_strerror(error_code));
		if (params.display == COMMANDS) {
			new_node_ptr = NULL;
			break;		/* just continue */
		}
		if (params.iterate == 0)
			_smap_exit(1);	/* Calls exit(), no return */
		sleep(10);	/* keep trying to reconnect */
	}

	_init_colors();
	select_g_ba_init(new_node_ptr, 0);
	init_grid(new_node_ptr);

	if (params.resolve) {
#if defined HAVE_BG_FILES && defined HAVE_BG_L_P
#if 1
		error("this doesn't work in the current 2.3 code. FIXME");
#else
		if (!have_db2) {
			printf("Required libraries can not be found "
			       "to access the Bluegene system.\nPlease "
			       "set your LD_LIBRARY_PATH correctly to "
			       "point to them.\n");
			goto part_fini;
		}

		if (!mapset)
			mapset = 1;
		if (params.resolve[0] != 'R') {
			i = strlen(params.resolve);
			i -= 3;
			if (i < 0) {
				printf("No real block was entered\n");
				goto part_fini;
			}
			char *rack_mid = find_bp_rack_mid(params.resolve+i);
			if (rack_mid) {
				printf("X=%c Y=%c Z=%c resolves to %s\n",
				       params.resolve[0+i],
				       params.resolve[1+i],
				       params.resolve[2+i],
				       rack_mid);
			} else {
				printf("X=%c Y=%c Z=%c has no resolve\n",
				       params.resolve[0+i],
				       params.resolve[1+i],
				       params.resolve[2+i]);
			}
		} else {
			uint16_t *coord = find_bp_loc(params.resolve);
			if (coord) {
				printf("%s resolves to X=%d Y=%d Z=%d\n",
				       params.resolve,
				       coord[0], coord[1], coord[2]);
			} else {
				printf("%s has no resolve.\n",
				       params.resolve);
			}
		}
part_fini:
#endif
#else
		printf("Must be physically on a BlueGene system for support "
		       "of resolve option.\n");
#endif
		_smap_exit(0);	/* Calls exit(), no return */
	}
	if (!params.commandline) {
		int check_width = min_screen_width;
		signal(SIGWINCH, (void (*)(int))_resize_handler);
		initscr();

		if (params.cluster_dims == 4) {
			height = dim_size[2] * dim_size[3] + dim_size[2] + 3;
			width = (dim_size[1] + dim_size[3] + 1) * dim_size[0]
				 + 2;
			check_width += width;
		} else if (params.cluster_dims == 3) {
			height = dim_size[1] * dim_size[2] + dim_size[1] + 3;
			width = dim_size[0] + dim_size[2] + 3;
			check_width += width;
		} else {
			height = 10;
			width = COLS;
		}

	        if ((COLS < check_width) || (LINES < height)) {
			endwin();
			error("Screen is too small make sure the screen "
			      "is at least %dx%d\n"
			      "Right now it is %dx%d\n",
			      check_width,
			      height,
			      COLS,
			      LINES);
			_smap_exit(1);	/* Calls exit(), no return */
		}

		raw();
		keypad(stdscr, TRUE);
		noecho();
		cbreak();
		curs_set(0);
		nodelay(stdscr, TRUE);
		start_color();
		_set_pairs();

		grid_win = newwin(height, width, starty, startx);
		max_display = grid_win->_maxy * grid_win->_maxx;

		if (params.cluster_dims == 4) {
			startx = width;
			COLS -= 2;
			width = COLS - width;
			height = LINES;
		} else if (params.cluster_dims == 3) {
			startx = width;
			COLS -= 2;
			width = COLS - width;
			height = LINES;
		} else {
			startx = 0;
			starty = height;
			height = LINES - height;
		}

		text_win = newwin(height, width, starty, startx);
        }
	while (!end) {
		if (!params.commandline) {
			_get_option();
redraw:
			clear_window(text_win);
			clear_window(grid_win);
			move(0, 0);

			main_xcord = 1;
			main_ycord = 1;
		}

		if (!params.no_header)
			print_date();

		clear_grid();
		switch (params.display) {
		case JOBS:
			get_job();
			break;
		case RESERVATIONS:
			get_reservation();
			break;
		case SLURMPART:
			get_slurm_part();
			break;
		case COMMANDS:
			if (params.cluster_flags & CLUSTER_FLAG_BG) {
				if (!mapset) {
					mapset = 1;
					wclear(text_win);
				}
				get_command();
			} else {
				error("Must be on a BG SYSTEM to "
				      "run this command");
				if (!params.commandline)
					endwin();
				_smap_exit(1);	/* Calls exit(), no return */
			}
			break;
		case BGPART:
			if (params.cluster_flags & CLUSTER_FLAG_BG)
				get_bg_part();
			else {
				error("Must be on a BG SYSTEM to "
				      "run this command");
				if (!params.commandline)
					endwin();
				_smap_exit(1);	/* Calls exit(), no return */
			}
			break;
		}

		if (!params.commandline) {
			box(text_win, 0, 0);
			wnoutrefresh(text_win);

			print_grid();
			box(grid_win, 0, 0);
			wnoutrefresh(grid_win);

			doupdate();

			node_info_ptr = new_node_ptr;
			if (node_info_ptr) {
				error_code = slurm_load_node(
					node_info_ptr->last_update,
					&new_node_ptr, SHOW_ALL);
				if (error_code == SLURM_SUCCESS)
					slurm_free_node_info_msg(
						node_info_ptr);
				else if (slurm_get_errno()
					 == SLURM_NO_CHANGE_IN_DATA) {
					error_code = SLURM_SUCCESS;
					new_node_ptr = node_info_ptr;
				}
			} else {
				error_code = slurm_load_node(
					(time_t) NULL,
					&new_node_ptr, SHOW_ALL);
			}
			if (error_code && (quiet_flag != 1)) {
				if (!params.commandline) {
					mvwprintw(
						text_win,
						main_ycord,
						1,
						"slurm_load_node: %s",
						slurm_strerror(
							slurm_get_errno()));
					main_ycord++;
				} else {
					printf("slurm_load_node: %s",
					       slurm_strerror(
						       slurm_get_errno()));
				}
			}
		}

		if (params.iterate) {
			for (i = 0; i < params.iterate; i++) {
				sleep(1);
				if (!params.commandline) {
					if ((rc = _get_option()) == 1)
						goto redraw;
					else if (resize_screen) {
						resize_screen = 0;
						goto redraw;
					}
				}
			}
		} else
			break;

	}

	if (!params.commandline) {
		nodelay(stdscr, FALSE);
		getch();
		endwin();
	}

	_smap_exit(0);	/* Calls exit(), no return */
	exit(0);	/* Redundant, but eliminates compiler warning */
}