[torquedev] new node attribute: "note"

Marcus R. Epperson mrepper at sandia.gov
Tue Jan 23 23:06:58 MST 2007


Patch for: torque-2.2.0-snap.200701181022

This patch adds a per-node "note" attribute.  The purpose is to allow system admins to add any annotation they want to a node.  The patch also adds a "-n" option to pbsnodes to set/clear it.

Example:

# pbsnodes -o -n "memory failure: DIMM3" tn5
# pbsnodes -a tn5
tn5
     state = offline
     np = 2
     ntype = cluster
     status = ...
     note = memory failure: DIMM3

To clear the note, either set it to an empty string "", or to "n" (similar convention to qsub's -m option).

I think something like this used to exist in Torque, but I couldn't tell for sure.  Any feedback welcome.

-Marcus
-------------- next part --------------
diff -Naurp torque-2.2.0-snap.200701181022/src/cmds/pbsnodes.c torque-2.2.0-snap.200701181022-note/src/cmds/pbsnodes.c
--- torque-2.2.0-snap.200701181022/src/cmds/pbsnodes.c	2006-11-28 13:41:49.000000000 -0700
+++ torque-2.2.0-snap.200701181022-note/src/cmds/pbsnodes.c	2007-01-23 17:48:46.000000000 -0700
@@ -122,6 +122,9 @@
 #define ALLI	5
 #define PURGE   6
 #define DIAG    7
+#define NOTE    8
+
+#define MAX_NOTE 1024
 
 int quiet = 0;
 
@@ -143,6 +146,48 @@ mbool_t DisplayXML = FALSE;
 
 
 /*
+ * set_note - set the note attribute for a node
+ *
+ */
+static int set_note(
+  int   con, 
+  char  *name,
+  char  *msg
+)
+{
+  char	         *errmsg;
+  struct attropl  new;
+  int             rc;
+
+  new.name     = ATTR_NODE_note;
+  new.resource = NULL;
+  new.value    = msg;
+  new.op       = SET;
+  new.next     = NULL;
+
+  rc = pbs_manager(
+    con, 
+    MGR_CMD_SET, 
+    MGR_OBJ_NODE, 
+    name, 
+    &new, 
+    NULL);
+
+  if (rc && !quiet) 
+    {
+    fprintf(stderr,"Error setting note attribute for node %s - ", name);
+
+    if ((errmsg = pbs_geterrmsg(con)) != NULL)
+      fprintf(stderr,"%s\n", errmsg);
+    else
+      fprintf(stderr,"error: %d\n", pbs_errno);
+    }
+
+  return rc;
+}
+
+
+/*
  * cmp_node_name - compare two node names, allow the second to match the
  *	first if the same up to a dot ('.') in the second; i.e.
  *	"foo" == "foo.bar"
@@ -366,6 +411,9 @@ int main(
   char	       **pa;
   struct batch_status *pbstat;
   int	flag = ALLI;
+  char	*note;
+  int	note_flag = 0;
+  int	len = 0;
 
   /* get default server, may be changed by -s option */
 
@@ -374,7 +422,7 @@ int main(
   if (def_server == NULL)
     def_server = "";
 
-  while ((i = getopt(argc,argv,"acdlopqrs:x-:")) != EOF)
+  while ((i = getopt(argc,argv,"acdlopqrs:x-:n:")) != EOF)
     {
     switch(i) 
       {
@@ -440,6 +488,39 @@ int main(
 
         break;
 
+      case 'n':
+
+        note_flag = 1;
+
+        /* preserve any previous option other than the default,
+         * to allow -n to be combined with -o, -c, etc
+         */
+        if ( flag == ALLI )
+          flag = NOTE;
+
+        note = strdup(optarg);
+
+        if ( note != NULL )
+          {
+          /* -n n is the same as -n ""  -- it clears the note */
+          if ( !strcmp(note,"n") )
+            {
+            *note = '\0';
+            }
+
+          len = strlen(note);
+          }
+
+        if ( len > MAX_NOTE )
+          {
+          fprintf(stderr,"\nWarning: note will be truncated at %d characters (was %d)\n\n",
+            MAX_NOTE,len);
+
+          note[MAX_NOTE] = '\0';
+          }
+
+        break;
+
       case '-':
 
         if ((optarg != NULL) && !strcmp(optarg,"version"))
@@ -467,7 +548,7 @@ int main(
     {
     if (!quiet)
       {
-      fprintf(stderr,"usage:\t%s [-{c|d|o|p|r}][-s server] [-q] node node ...\n",
+      fprintf(stderr,"usage:\t%s [-{c|d|o|p|r}][-s server] [-n \"note\"] [-q] node node ...\n",
         argv[0]);
 
       fprintf(stderr,"\t%s -l [-s server] [-q]\n",
@@ -546,6 +627,16 @@ int main(
       }
     }    /* END if ((flag == ALLI) || (flag == DOWN) || (flag == LIST) || (flag == DIAG)) */
 
+
+  if ( note_flag )
+    {
+    /* set the note attrib string on specified nodes */
+    for (pa = argv + optind;*pa;pa++) 
+      {
+      set_note(con,*pa,note);
+      }
+    }
+
   switch (flag) 
     {
     case DIAG:
diff -Naurp torque-2.2.0-snap.200701181022/src/include/attribute.h torque-2.2.0-snap.200701181022-note/src/include/attribute.h
--- torque-2.2.0-snap.200701181022/src/include/attribute.h	2006-10-19 17:10:09.000000000 -0600
+++ torque-2.2.0-snap.200701181022-note/src/include/attribute.h	2007-01-23 16:03:36.000000000 -0700
@@ -435,6 +435,7 @@ extern int      node_np_action  A_(( att
 extern int      node_ntype A_(( attribute*, void*, int));
 extern int      node_prop_list A_(( attribute*, void*, int));
 extern int      node_status_list A_(( attribute*, void*, int));
+extern int      node_note        A_(( attribute*, void*, int));
 
 /* Token manipulation functions */
 
diff -Naurp torque-2.2.0-snap.200701181022/src/include/pbs_ifl.h torque-2.2.0-snap.200701181022-note/src/include/pbs_ifl.h
--- torque-2.2.0-snap.200701181022/src/include/pbs_ifl.h	2007-01-09 19:49:00.000000000 -0700
+++ torque-2.2.0-snap.200701181022-note/src/include/pbs_ifl.h	2007-01-23 16:03:36.000000000 -0700
@@ -262,6 +262,7 @@
 #define ATTR_NODE_ntype         "ntype"
 #define ATTR_NODE_jobs          "jobs"
 #define ATTR_NODE_status        "status"
+#define ATTR_NODE_note          "note"
 
 
 
diff -Naurp torque-2.2.0-snap.200701181022/src/include/pbs_nodes.h torque-2.2.0-snap.200701181022-note/src/include/pbs_nodes.h
--- torque-2.2.0-snap.200701181022/src/include/pbs_nodes.h	2006-10-19 17:10:09.000000000 -0600
+++ torque-2.2.0-snap.200701181022-note/src/include/pbs_nodes.h	2007-01-23 16:03:36.000000000 -0700
@@ -123,6 +123,7 @@ struct pbsnode {
   u_long		*nd_addrs;	/* IP addresses of host */
   struct array_strings	*nd_prop;	/* array of properities */
   struct array_strings  *nd_status;
+  char           *nd_note;  /* note set by administrator */
   int		 	 nd_stream;	/* RPP stream to Mom on host */
   enum	psit		 nd_flag;
   short		 	 nd_nprops;	/* number of properties */
@@ -216,6 +217,7 @@ enum nodeattr {
   ND_ATR_ntype,
   ND_ATR_jobs,
   NODE_ATR_status,
+  NODE_ATR_note,
   ND_ATR_LAST }; /* WARNING: Must be the highest valued enum */
 
 
diff -Naurp torque-2.2.0-snap.200701181022/src/include/qmgr_node_public.h torque-2.2.0-snap.200701181022-note/src/include/qmgr_node_public.h
--- torque-2.2.0-snap.200701181022/src/include/qmgr_node_public.h	2006-06-19 18:23:29.000000000 -0600
+++ torque-2.2.0-snap.200701181022-note/src/include/qmgr_node_public.h	2007-01-23 16:03:36.000000000 -0700
@@ -95,3 +95,4 @@ ATTR_NODE_properties,
 ATTR_NODE_np,
 ATTR_NODE_ntype,
 ATTR_NODE_status,
+ATTR_NODE_note,
diff -Naurp torque-2.2.0-snap.200701181022/src/lib/Libattr/attr_node_func.c torque-2.2.0-snap.200701181022-note/src/lib/Libattr/attr_node_func.c
--- torque-2.2.0-snap.200701181022/src/lib/Libattr/attr_node_func.c	2006-10-19 17:10:15.000000000 -0600
+++ torque-2.2.0-snap.200701181022-note/src/lib/Libattr/attr_node_func.c	2007-01-23 17:55:22.000000000 -0700
@@ -1052,6 +1052,77 @@ int node_status_list(
   return(rc);
   }  /* END node_status_list() */
 
-/* END attr_node_func.c */
+/*
+ * node_note - Either derive a note attribute from the node
+ *             or update node's note from attribute's list.
+ */
+
+int node_note(
+
+  attribute *new,           /*derive status into this attribute*/
+  void      *pnode,         /*pointer to a pbsnode struct     */
+  int        actmode)       /*action mode; "NEW" or "ALTER"   */
+
+  {
+  int              rc = 0;
+  struct pbsnode  *np;
+  attribute        temp;
+
+  np = (struct pbsnode *)pnode;    /* because of at_action arg type */
+
+  switch(actmode) 
+    {
+    case ATR_ACTION_NEW:
+
+      /* if node has a note, then copy string into temp  */
+      /* to use to setup a copy, otherwise setup empty   */
+
+      if (np->nd_note != NULL) 
+        {
+        /* setup temporary attribute with the string from the node */
+
+        temp.at_val.at_str = np->nd_note;
+        temp.at_flags = ATR_VFLAG_SET;
+        temp.at_type  = ATR_TYPE_STR;
+
+        rc = set_str(new,&temp,SET);
+        } 
+      else 
+        {
+        /* node has no properties, setup empty attribute */
+
+        new->at_val.at_str  = NULL;
+        new->at_flags       = 0;
+        new->at_type        = ATR_TYPE_STR;
+        }
+
+      break;
 
+    case ATR_ACTION_ALTER:
 
+      if (np->nd_note != NULL)
+        {
+        free(np->nd_note);
+
+        np->nd_note = NULL;
+        }
+
+      /* update node with new string */
+
+      np->nd_note = new->at_val.at_str;
+
+      new->at_val.at_str = NULL;
+
+      break;
+
+    default:    
+       
+      rc = PBSE_INTERNAL;
+
+      break;
+    }  /* END switch(actmode) */
+
+  return(rc);
+  }  /* END node_note() */
+
+/* END attr_node_func.c */
diff -Naurp torque-2.2.0-snap.200701181022/src/server/node_attr_def.c torque-2.2.0-snap.200701181022-note/src/server/node_attr_def.c
--- torque-2.2.0-snap.200701181022/src/server/node_attr_def.c	2006-10-19 17:10:34.000000000 -0600
+++ torque-2.2.0-snap.200701181022-note/src/server/node_attr_def.c	2007-01-23 16:03:36.000000000 -0700
@@ -195,5 +195,19 @@ attribute_def node_attr_def[] = {
         MGR_ONLY_SET,
         ATR_TYPE_ARST,
         PARENT_TYPE_NODE,
-    }
+    },
+
+/* NODE_ATR_note */
+    {	ATTR_NODE_note,	/* "note" */
+	decode_str,
+	encode_str,
+	set_str,
+	comp_str,
+	free_str,
+	node_note,
+	NO_USER_SET,
+	ATR_TYPE_STR,
+	PARENT_TYPE_NODE,
+    },
+	
 };
diff -Naurp torque-2.2.0-snap.200701181022/src/server/node_func.c torque-2.2.0-snap.200701181022-note/src/server/node_func.c
--- torque-2.2.0-snap.200701181022/src/server/node_func.c	2006-10-19 17:10:29.000000000 -0600
+++ torque-2.2.0-snap.200701181022-note/src/server/node_func.c	2007-01-23 16:03:36.000000000 -0700
@@ -603,6 +603,8 @@ int status_nodeattrib(
       atemp[i].at_val.at_jinfo = pnode;
     else if (!strcmp ((padef + i)->at_name, ATTR_NODE_np))
       atemp[i].at_val.at_long = pnode->nd_nsn;
+    else if (!strcmp ((padef + i)->at_name, ATTR_NODE_note))
+      atemp[i].at_val.at_str  = pnode->nd_note;
     else 
       {
       /*we don't ever expect this*/
@@ -729,6 +731,7 @@ static void initialize_pbsnode(
   pnode->nd_order   = 0;
   pnode->nd_prop    = NULL;
   pnode->nd_status  = NULL;
+  pnode->nd_note    = NULL;
   pnode->nd_psn     = NULL;
   pnode->nd_state   = INUSE_NEEDS_HELLO_PING | INUSE_DOWN;
   pnode->nd_first   = init_prop(pnode->nd_name);


More information about the torquedev mailing list