Skip to content
Snippets Groups Projects
Commit ceb8bad4 authored by Moe Jette's avatar Moe Jette
Browse files

Change format of test in api/build_info.c

Updated scontrol/scontrol.c for new APIs
parent 4d5c9379
No related branches found
No related tags found
No related merge requests found
...@@ -3,10 +3,14 @@ ...@@ -3,10 +3,14 @@
* provides interface to read, write, update, and configurations. * provides interface to read, write, update, and configurations.
*/ */
#include <ctype.h>
#include <errno.h> #include <errno.h>
#include <stdio.h> #include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h> #include <string.h>
#include <time.h> #include <time.h>
#include <unistd.h>
#include "slurmlib.h" #include "slurmlib.h"
#define BUF_SIZE 1024 #define BUF_SIZE 1024
...@@ -20,14 +24,16 @@ static int input_words; /* number of words of input permitted */ ...@@ -20,14 +24,16 @@ static int input_words; /* number of words of input permitted */
void dump_command (int argc, char *argv[]); void dump_command (int argc, char *argv[]);
int get_command (int *argc, char *argv[]); int get_command (int *argc, char *argv[]);
void print_build (char *build_param); void print_build (char *build_param);
void print_node (char *node_name); void print_node (char *node_name, struct node_buffer *node_buffer_ptr);
void print_node_list (char *node_list); void print_node_list (char *node_list);
void print_part (char *partition_name); void print_part (char *partition_name);
int process_command (int argc, char *argv[]); int process_command (int argc, char *argv[]);
int update_it (int argc, char *argv[]); int update_it (int argc, char *argv[]);
void usage (); void usage ();
main (int argc, char *argv[]) { int
main (int argc, char *argv[])
{
int error_code, i, input_field_count; int error_code, i, input_field_count;
char **input_fields; char **input_fields;
...@@ -55,7 +61,7 @@ main (int argc, char *argv[]) { ...@@ -55,7 +61,7 @@ main (int argc, char *argv[]) {
} }
else { else {
input_fields[input_field_count++] = argv[i]; input_fields[input_field_count++] = argv[i];
} /* else */ }
} }
if (input_field_count) if (input_field_count)
...@@ -88,7 +94,8 @@ main (int argc, char *argv[]) { ...@@ -88,7 +94,8 @@ main (int argc, char *argv[]) {
* argv - the arguments * argv - the arguments
*/ */
void void
dump_command (int argc, char *argv[]) { dump_command (int argc, char *argv[])
{
int i; int i;
for (i = 0; i < argc; i++) { for (i = 0; i < argc; i++) {
...@@ -103,7 +110,9 @@ dump_command (int argc, char *argv[]) { ...@@ -103,7 +110,9 @@ dump_command (int argc, char *argv[]) {
* argv - location to store the argument list * argv - location to store the argument list
* output: returns error code, 0 if no problems * output: returns error code, 0 if no problems
*/ */
int get_command (int *argc, char **argv) { int
get_command (int *argc, char **argv)
{
static char *in_line; static char *in_line;
static int in_line_size = 0; static int in_line_size = 0;
int in_line_pos = 0; int in_line_pos = 0;
...@@ -169,93 +178,131 @@ int get_command (int *argc, char **argv) { ...@@ -169,93 +178,131 @@ int get_command (int *argc, char **argv) {
* print_build - print the specified build parameter and value * print_build - print the specified build parameter and value
* input: build_param - NULL to print all parameters and values * input: build_param - NULL to print all parameters and values
*/ */
void print_build (char *build_param) { void
char req_name[BUILD_SIZE], next_name[BUILD_SIZE], value[BUILD_SIZE]; print_build (char *build_param)
{
int error_code; int error_code;
static struct build_buffer *old_build_buffer_ptr = NULL;
error_code = slurm_load_build (); struct build_buffer *build_buffer_ptr = NULL;
if (error_code) { struct build_table *build_table_ptr = NULL;
if (old_build_buffer_ptr) {
error_code = slurm_load_build (old_build_buffer_ptr->last_update,
&build_buffer_ptr);
if (error_code == 0)
slurm_free_build_info(old_build_buffer_ptr);
else if (error_code == -1)
build_buffer_ptr = old_build_buffer_ptr;
}
else
error_code = slurm_load_build ((time_t) NULL, &build_buffer_ptr);
if (error_code > 0) {
if (quiet_flag != 1) if (quiet_flag != 1)
printf ("slurm_load_build error %d\n", error_code); printf ("slurm_load_build error %d\n", error_code);
return; return;
} }
old_build_buffer_ptr = build_buffer_ptr;
if (build_param) build_table_ptr = build_buffer_ptr->build_table_ptr;
strncpy (req_name, build_param, BUILD_SIZE); if (build_param == NULL ||
else strcmp (build_param, "BACKUP_INTERVAL") == 0)
strcpy (req_name, ""); /* start at beginning of node list */ printf ("BACKUP_INTERVAL = %u\n",
build_table_ptr->backup_interval);
while (1) { if (build_param == NULL ||
error_code = slurm_load_build_name (req_name, next_name, value); strcmp (build_param, "BACKUP_LOCATION") == 0)
if (error_code != 0) { printf ("BACKUP_LOCATION = %s\n",
if (quiet_flag != 1) { build_table_ptr->backup_location);
if (error_code == ENOENT) if (build_param == NULL ||
printf ("no parameter %s found\n", strcmp (build_param, "BACKUP_MACHINE") == 0)
req_name); printf ("BACKUP_MACHINE = %s\n",
else build_table_ptr->backup_machine);
printf ("error %d finding value for parameter %s\n", if (build_param == NULL ||
error_code, req_name); strcmp (build_param, "CONTROL_DAEMON") == 0)
} printf ("CONTROL_DAEMON = %s\n",
break; build_table_ptr->control_daemon);
} if (build_param == NULL ||
printf ("%s=%s\n", req_name, value); strcmp (build_param, "CONTROL_MACHINE") == 0)
printf ("CONTROL_MACHINE = %s\n",
if (build_param || (strlen (next_name) == 0)) build_table_ptr->control_machine);
break; if (build_param == NULL ||
strcpy (req_name, next_name); strcmp (build_param, "EPILOG") == 0)
} printf ("EPILOG = %s\n", build_table_ptr->epilog);
/* slurm_free_build_info(); keep data for reuse, cleaned on exit */ if (build_param == NULL ||
strcmp (build_param, "FAST_SCHEDULE") == 0)
printf ("FAST_SCHEDULE = %u\n",
build_table_ptr->fast_schedule);
if (build_param == NULL ||
strcmp (build_param, "HASH_BASE") == 0)
printf ("HASH_BASE = %u\n",
build_table_ptr->hash_base);
if (build_param == NULL ||
strcmp (build_param, "HEARTBEAT_INTERVAL") == 0)
printf ("HEARTBEAT_INTERVAL = %u\n",
build_table_ptr->heartbeat_interval);
if (build_param == NULL ||
strcmp (build_param, "INIT_PROGRAM") == 0)
printf ("INIT_PROGRAM = %s\n", build_table_ptr->init_program);
if (build_param == NULL ||
strcmp (build_param, "KILL_WAIT") == 0)
printf ("KILL_WAIT = %u\n", build_table_ptr->kill_wait);
if (build_param == NULL ||
strcmp (build_param, "PRIORITIZE") == 0)
printf ("PRIORITIZE = %s\n", build_table_ptr->prioritize);
if (build_param == NULL ||
strcmp (build_param, "PROLOG") == 0)
printf ("PROLOG = %s\n", build_table_ptr->prolog);
if (build_param == NULL ||
strcmp (build_param, "SERVER_DAEMON") == 0)
printf ("SERVER_DAEMON = %s\n",
build_table_ptr->server_daemon);
if (build_param == NULL ||
strcmp (build_param, "SERVER_TIMEOUT") == 0)
printf ("SERVER_TIMEOUT = %u\n",
build_table_ptr->server_timeout);
if (build_param == NULL ||
strcmp (build_param, "SLURM_CONF") == 0)
printf ("SLURM_CONF = %s\n", build_table_ptr->slurm_conf);
if (build_param == NULL ||
strcmp (build_param, "TMP_FS") == 0)
printf ("TMP_FS = %s\n", build_table_ptr->tmp_fs);
} }
/* /*
* print_node - print the specified node's information * print_node - print the specified node's information
* input: node_name - NULL to print all node information * input: node_name - NULL to print all node information
* node_ptr - pointer to node table of information
* NOTE: call this only after executing load_node, called from print_node_list * NOTE: call this only after executing load_node, called from print_node_list
*/ */
void void
print_node (char *node_name) { print_node (char *node_name, struct node_buffer *node_buffer_ptr)
int error_code, size, i; {
char partition[MAX_NAME_LEN], node_state[MAX_NAME_LEN], int i, j;
features[FEATURE_SIZE]; static int last_inx = 0;
char req_name[MAX_NAME_LEN]; /* name of the partition */ struct node_table *node_ptr;
char next_name[MAX_NAME_LEN]; /* name of the next partition */
int cpus, real_memory, tmp_disk, weight; node_ptr = node_buffer_ptr->node_table_ptr;
char *dump; for (j = 0; j < node_buffer_ptr->node_count; j++) {
int dump_size; if (node_name) {
time_t update_time; i = (j + last_inx) % node_buffer_ptr->node_count;
unsigned *node_bitmap; /* bitmap of nodes in partition */ if (strcmp (node_name, node_ptr[i].name) != 0)
int bitmap_size; /* bytes in node_bitmap */ continue;
}
if (node_name) else
strncpy (req_name, node_name, MAX_NAME_LEN); i = j;
else printf ("NodeName=%s CPUs=%u ",
strcpy (req_name, ""); /* start at beginning of node list */ node_ptr[i].name, node_ptr[i].cpus);
printf ("RealMemory=%u TmpDisk=%u ",
while (1) { node_ptr[i].real_memory, node_ptr[i].tmp_disk);
error_code = printf ("State=%u Weight=%u ",
load_node_config (req_name, next_name, &cpus, node_ptr[i].node_state, node_ptr[i].weight);
&real_memory, &tmp_disk, &weight, printf ("Features=%s Partition=%s\n",
features, partition, node_state); node_ptr[i].features, node_ptr[i].partition);
if (error_code != 0) { if (node_name) {
if (quiet_flag != 1) { last_inx = i;
if (error_code == ENOENT)
printf ("no node %s found\n",
req_name);
else
printf ("error %d finding information for node %s\n", error_code, req_name);
}
break; break;
} }
printf ("NodeName=%s CPUs=%d RealMemory=%d TmpDisk=%d ", }
req_name, cpus, real_memory, tmp_disk);
printf ("State=%s Weight=%d Features=%s Partition=%s\n",
node_state, weight, features, partition);
if (node_name || (strlen (next_name) == 0))
break;
strcpy (req_name, next_name);
}
} }
...@@ -264,25 +311,42 @@ print_node (char *node_name) { ...@@ -264,25 +311,42 @@ print_node (char *node_name) {
* input: node_list - print information about the supplied node list (or regular expression) * input: node_list - print information about the supplied node list (or regular expression)
*/ */
void void
print_node_list (char *node_list) { print_node_list (char *node_list)
static time_t last_update_time = (time_t) NULL; {
static struct node_buffer *old_node_buffer_ptr = NULL;
struct node_buffer *node_buffer_ptr = NULL;
int start_inx, end_inx, count_inx, error_code, i; int start_inx, end_inx, count_inx, error_code, i;
char *str_ptr1, *str_ptr2, *format, *my_node_list, char *str_ptr1, *str_ptr2, *format, *my_node_list;
this_node_name[BUF_SIZE];; char this_node_name[BUF_SIZE];
error_code = load_node (&last_update_time); if (old_node_buffer_ptr) {
if (error_code) { error_code = slurm_load_node (old_node_buffer_ptr->last_update,
&node_buffer_ptr);
if (error_code == 0)
slurm_free_node_info (old_node_buffer_ptr);
else if (error_code == -1)
node_buffer_ptr = old_node_buffer_ptr;
}
else
error_code = slurm_load_node ((time_t) NULL, &node_buffer_ptr);
if (error_code > 0) {
if (quiet_flag != 1) if (quiet_flag != 1)
printf ("load_node error %d\n", error_code); printf ("load_node error %d\n", error_code);
return; return;
} }
else if (error_code == 0)
old_node_buffer_ptr = node_buffer_ptr;
if (quiet_flag == -1) if (quiet_flag == -1)
printf ("last_update_time=%ld\n", (long) last_update_time); printf ("last_update_time=%ld\n", (long) node_buffer_ptr->last_update);
if (node_list == NULL) { if (node_list == NULL) {
print_node (NULL); print_node (NULL, node_buffer_ptr);
} }
else { else {
format = NULL;
my_node_list = malloc (strlen (node_list) + 1); my_node_list = malloc (strlen (node_list) + 1);
if (my_node_list == NULL) { if (my_node_list == NULL) {
if (quiet_flag != 1) if (quiet_flag != 1)
...@@ -319,15 +383,14 @@ print_node_list (char *node_list) { ...@@ -319,15 +383,14 @@ print_node_list (char *node_list) {
sizeof (this_node_name)); sizeof (this_node_name));
else else
sprintf (this_node_name, format, i); sprintf (this_node_name, format, i);
print_node (this_node_name); print_node (this_node_name, node_buffer_ptr);
} }
free (format); if (format)
free (format);
str_ptr2 = (char *) strtok_r (NULL, ",", &str_ptr1); str_ptr2 = (char *) strtok_r (NULL, ",", &str_ptr1);
} }
free (my_node_list); free (my_node_list);
} /* else */ }
/* free_node_info(); keep data for reuse, cleaned on exit */
return; return;
} }
...@@ -336,66 +399,55 @@ print_node_list (char *node_list) { ...@@ -336,66 +399,55 @@ print_node_list (char *node_list) {
* print_part - print the specified partition's information * print_part - print the specified partition's information
* input: partition_name - NULL to print all partition information * input: partition_name - NULL to print all partition information
*/ */
void print_part (char *partition_name) { void
static time_t last_update_time = (time_t) NULL; /* time desired for data */ print_part (char *partition_name)
static char *yes_no[0] = { "NO", "YES" }; {
static char *up_down[0] = { "DOWN", "UP" }; int error_code, i;
char req_name[MAX_NAME_LEN]; /* name of the partition */ static struct part_buffer *old_part_buffer_ptr = NULL;
char next_name[MAX_NAME_LEN]; /* name of the next partition */ struct part_buffer *part_buffer_ptr = NULL;
int max_time; /* -1 if unlimited */ struct part_table *part_ptr = NULL;
int max_nodes; /* -1 if unlimited */
int total_nodes; /* total number of nodes in the partition */ if (old_part_buffer_ptr) {
int total_cpus; /* total number of cpus in the partition */ error_code = slurm_load_part (old_part_buffer_ptr->last_update,
char nodes[FEATURE_SIZE]; /* names of nodes in partition */ &part_buffer_ptr);
char allow_groups[FEATURE_SIZE];/* NULL indicates all */ if (error_code == 0)
int key; /* 1 if slurm distributed key is required */ slurm_free_part_info (old_part_buffer_ptr);
int state_up; /* 1 if state is up */ else if (error_code == -1)
int shared; /* 1 if partition can be shared */ part_buffer_ptr = old_part_buffer_ptr;
int default_flag; /* 1 if default partition */ }
int error_code; else
error_code = slurm_load_part ((time_t) NULL, &part_buffer_ptr);
error_code = load_part (&last_update_time); if (error_code > 0) {
if (error_code) {
if (quiet_flag != 1) if (quiet_flag != 1)
printf ("load_part error %d\n", error_code); printf ("load_part error %d\n", error_code);
return; return;
} }
if (quiet_flag == -1) else if (error_code == 0)
printf ("last_update_time=%ld\n", (long) last_update_time); old_part_buffer_ptr = part_buffer_ptr;
if (partition_name)
strncpy (req_name, partition_name, MAX_NAME_LEN);
else
strcpy (req_name, ""); /* start at beginning of partition list */
while (1) {
error_code =
load_part_name (req_name, next_name, &max_time,
&max_nodes, &total_nodes, &total_cpus,
&key, &state_up, &shared, &default_flag,
nodes, allow_groups);
if (error_code != 0) {
if (quiet_flag != 1) {
if (error_code == ENOENT)
printf ("no partition %s found\n",
req_name);
else
printf ("error %d finding information for partition %s\n", error_code, req_name);
}
break;
}
printf ("PartitionName=%s Nodes=%s MaxTime=%d MaxNodes=%d Default=%s ", if (quiet_flag == -1)
req_name, nodes, max_time, max_nodes, yes_no[default_flag]); printf ("last_update_time=%ld\n", (long) part_buffer_ptr->last_update);
printf ("Key=%s State=%s Shared=%s AllowGroups=%s ",
yes_no[key], up_down[state_up], yes_no[shared], allow_groups);
printf ("TotalNodes=%d total_cpus=%d \n", total_nodes, total_cpus);
if (partition_name || (strlen (next_name) == 0)) part_ptr = part_buffer_ptr->part_table_ptr;
for (i = 0; i < part_buffer_ptr->part_count; i++) {
if (partition_name &&
strcmp (partition_name, part_ptr[i].name) != 0)
continue;
printf ("PartitionName=%s MaxTime=%u ",
part_ptr[i].name, part_ptr[i].max_time);
printf ("MaxNodes=%u TotalNodes=%u ",
part_ptr[i].max_nodes, part_ptr[i].total_nodes);
printf ("TotalCPUs=%u Key=%u\n",
part_ptr[i].total_cpus, part_ptr[i].key);
printf (" Default=%u ",
part_ptr[i].default_part);
printf ("Shared=%u StateUp=%u ",
part_ptr[i].shared, part_ptr[i].state_up);
printf ("Nodes=%s AllowGroups=%s\n\n",
part_ptr[i].nodes, part_ptr[i].allow_groups);
if (partition_name)
break; break;
strcpy (req_name, next_name); }
}
/* free_part_info(); keep data for reuse, cleaned on exit */
} }
...@@ -406,7 +458,8 @@ void print_part (char *partition_name) { ...@@ -406,7 +458,8 @@ void print_part (char *partition_name) {
* ourput: return code is 0 or errno (only for errors fatal to scontrol) * ourput: return code is 0 or errno (only for errors fatal to scontrol)
*/ */
int int
process_command (int argc, char *argv[]) { process_command (int argc, char *argv[])
{
int error_code; int error_code;
if ((strcmp (argv[0], "exit") == 0) || if ((strcmp (argv[0], "exit") == 0) ||
...@@ -528,7 +581,8 @@ process_command (int argc, char *argv[]) { ...@@ -528,7 +581,8 @@ process_command (int argc, char *argv[]) {
* output: returns 0 if no error, errno otherwise * output: returns 0 if no error, errno otherwise
*/ */
int int
update_it (int argc, char *argv[]) { update_it (int argc, char *argv[])
{
char *in_line; char *in_line;
int error_code, i, in_line_size; int error_code, i, in_line_size;
...@@ -568,7 +622,8 @@ usage () { ...@@ -568,7 +622,8 @@ usage () {
printf ("%s [-q | -v] [<keyword>]\n", command_name); printf ("%s [-q | -v] [<keyword>]\n", command_name);
printf (" -q is equivalent to the keyword \"quiet\" described below.\n"); printf (" -q is equivalent to the keyword \"quiet\" described below.\n");
printf (" -v is equivalent to the keyword \"verbose\" described below.\n"); printf (" -v is equivalent to the keyword \"verbose\" described below.\n");
printf (" <keyword> may be omitted from the execute line and %s will execute in interactive\n"); printf (" <keyword> may be omitted from the execute line and %s will execute in interactive\n",
command_name);
printf (" mode to process multiple keywords (i.e. commands). valid <entity> values are:\n"); printf (" mode to process multiple keywords (i.e. commands). valid <entity> values are:\n");
printf (" build, job, node, and partition. node names may be sepcified using regular simple \n"); printf (" build, job, node, and partition. node names may be sepcified using regular simple \n");
printf (" expressions. valid <keyword> values are:\n"); printf (" expressions. valid <keyword> values are:\n");
...@@ -581,4 +636,4 @@ usage () { ...@@ -581,4 +636,4 @@ usage () {
printf (" update <options> update configuration per configuration file format.\n"); printf (" update <options> update configuration per configuration file format.\n");
printf (" verbose enable detailed logging.\n"); printf (" verbose enable detailed logging.\n");
printf (" version display tool version number.\n"); printf (" version display tool version number.\n");
} /* usage */ }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment