Index: /trunk/Ohana/src/opihi/doc/scheduler.txt
===================================================================
--- /trunk/Ohana/src/opihi/doc/scheduler.txt	(revision 4551)
+++ /trunk/Ohana/src/opihi/doc/scheduler.txt	(revision 4552)
@@ -1,2 +1,55 @@
+
+2005.07.14
+
+I am still exploring the scheduler / controller interactions.  the
+automatic interactions seem to work pretty well now.  The area of
+confusion is in the user interface, both in terms of checking on the
+status of things (both controller and scheduler) and in terms of
+having user control over aspects of the controller.
+
+I have defined user functions which execute the controller commands
+'status' and 'check'.  These are straightforeward since they simply
+send a command to the controller and echo the output (or give an error
+condition message).
+
+Should the user have the ability to define a job, independent of a
+task?  This could be implemented purely as a controller action: the
+controller commands 'job', 'kill', 'delete', 'stderr', 'stdout' would
+be available from the scheduler, and the commands simply passed
+along.  This adds a bit to the complexity: if the 'delete' command is
+passed along, nothing prevents the user from deleting a job scheduled
+by the scheduler from a task.  the scheduler may then get confused
+when it tries to interact with that job in the future from the
+automatic loop.
+
+Another option is to simply have these commands interact with the
+scheduler's job stack.  this has the advantage of limiting the
+scheduler / controller responsibility errors (scheduler, not user, is
+always responsible to sending/harvesting jobs to/from the
+controller, though we still need to handle the cases if a job is lost
+or dropped by the controller).  the diffficulty here is deciding how
+to handle the job completion.  we would need a way to define a set of
+exit macros, which could then do something useful with the output.  
+
+Another possibility is to define limits on how many times a task may
+spawn a job.  There would then be no 'job' function.  If we define
+this limitation, we will still need a way of killing and deleting a
+specific job.  Thus a 'kill' and 'delete' function would examine and
+modify the scheduler's job stack.  The stderr and stdout functions are
+then already part of the task commands.  
+
+Other task options might include: 
+
+- a list of allow / exclude time periods (which should be time-of-day
+  ranges and day-of-week ranges).
+
+- a function to delete an existing task (which would have to stop the
+  spawning of new jobs, at least until no more jobs for that task
+  remain).
+
+- allow the 'periods' command to define defaults when outside of a
+  task
+
+- 
 
 2005.07.05
Index: /trunk/Ohana/src/opihi/include/scheduler.h
===================================================================
--- /trunk/Ohana/src/opihi/include/scheduler.h	(revision 4551)
+++ /trunk/Ohana/src/opihi/include/scheduler.h	(revision 4552)
@@ -126,2 +126,3 @@
 int CheckLocalJobStatus (Job *job);
 void InitTaskTimers ();
+Function *FindControllerCommand (char *cmd);
Index: /trunk/Ohana/src/opihi/pantasks/ControllerOps.c
===================================================================
--- /trunk/Ohana/src/opihi/pantasks/ControllerOps.c	(revision 4551)
+++ /trunk/Ohana/src/opihi/pantasks/ControllerOps.c	(revision 4552)
@@ -3,6 +3,10 @@
 # define CONNECT_TIMEOUT 300
 
-int status = FALSE;
-int stdin_cntl, stdout_cntl, stderr_cntl;
+static int status = FALSE;
+static int stdin_cntl, stdout_cntl, stderr_cntl;
+
+int CheckControllerStatus () {
+  return (status);
+}
 
 int CheckControllerJob (Job *job) {
Index: /trunk/Ohana/src/opihi/pantasks/Makefile
===================================================================
--- /trunk/Ohana/src/opihi/pantasks/Makefile	(revision 4551)
+++ /trunk/Ohana/src/opihi/pantasks/Makefile	(revision 4552)
@@ -26,4 +26,6 @@
 
 funcs = \
+$(SDIR)/init.$(ARCH).o \
+$(SDIR)/scheduler.$(ARCH).o \
 $(SDIR)/CheckJobs.$(ARCH).o \
 $(SDIR)/CheckSystem.$(ARCH).o \
@@ -34,11 +36,16 @@
 $(SDIR)/TaskOps.$(ARCH).o \
 $(SDIR)/IOBufferOps.$(ARCH).o \
-$(SDIR)/memstr.$(ARCH).o \
-$(SDIR)/init.$(ARCH).o
+$(SDIR)/memstr.$(ARCH).o
 
 cmds = \
+$(SDIR)/run.$(ARCH).o \
+$(SDIR)/stop.$(ARCH).o \
+$(SDIR)/status.$(ARCH).o \
+$(SDIR)/kill.$(ARCH).o \
+$(SDIR)/delete.$(ARCH).o \
 $(SDIR)/controller.$(ARCH).o \
-$(SDIR)/run.$(ARCH).o \
-$(SDIR)/scheduler.$(ARCH).o \
+$(SDIR)/controller_host.$(ARCH).o \
+$(SDIR)/controller_check.$(ARCH).o \
+$(SDIR)/controller_status.$(ARCH).o \
 $(SDIR)/task.$(ARCH).o \
 $(SDIR)/task_command.$(ARCH).o \
Index: /trunk/Ohana/src/opihi/pantasks/controller.c
===================================================================
--- /trunk/Ohana/src/opihi/pantasks/controller.c	(revision 4551)
+++ /trunk/Ohana/src/opihi/pantasks/controller.c	(revision 4552)
@@ -1,3 +1,7 @@
 # include "scheduler.h"
+
+int controller_host    PROTO((int, char **));
+int controller_status  PROTO((int, char **));
+int controller_check   PROTO((int, char **));
 
 static Command controller_cmds[] = {
@@ -34,5 +38,5 @@
 
   for (i = 0; i < N; i++) {
-    if (!strcmp (controller_cmds[i].name, argv[1])) {
+    if (!strcmp (controller_cmds[i].name, cmd)) {
       return (controller_cmds[i].func);
     }
Index: /trunk/Ohana/src/opihi/pantasks/controller_check.c
===================================================================
--- /trunk/Ohana/src/opihi/pantasks/controller_check.c	(revision 4551)
+++ /trunk/Ohana/src/opihi/pantasks/controller_check.c	(revision 4552)
@@ -1,5 +1,5 @@
 # include "scheduler.h"
 
-int controller_host (int argc, char **argv) {
+int controller_check (int argc, char **argv) {
 
   int status;
@@ -7,13 +7,16 @@
   IOBuffer buffer;
 
-  if (argc != 3) {
-    fprintf (stderr, "USAGE: controller host (hostname)\n");
-    return (FALSE);
+  if (argc != 3) goto usage;
+  if (strcasecmp (argv[2], "JOB") && 
+      strcasecmp (argv[2], "HOST")) goto usage;
+
+  /* check if controller is running */
+  status = CheckControllerStatus ();
+  if (!status) {
+    fprintf (stderr, "controller is not running\n");
+    return (TRUE);
   }
 
-  /* start controller connection (if needed) */
-  StartController ();
-
-  sprintf (command, "host %s", argv[2]);
+  sprintf (command, "check %s %s", argv[2], argv[3]);
   InitIOBuffer (&buffer, 0x100);
   status = ControllerCommand (command, CONTROLLER_PROMPT, &buffer);
@@ -32,4 +35,5 @@
     case CONTROLLER_GOOD:
       fprintf (stderr, "controller command sent\n");  
+      fwrite (buffer.buffer, 1, buffer.Nbuffer, stderr);
       return (TRUE);
 
@@ -41,3 +45,8 @@
   fprintf (stderr, "programming error: should not reach here\n");  
   exit (1);
+
+usage:
+  fprintf (stderr, "USAGE: controller check job (jobID)\n");
+  fprintf (stderr, "USAGE: controller check host (hostID)\n");
+  return (FALSE);
 }
Index: /trunk/Ohana/src/opihi/pantasks/controller_status.c
===================================================================
--- /trunk/Ohana/src/opihi/pantasks/controller_status.c	(revision 4551)
+++ /trunk/Ohana/src/opihi/pantasks/controller_status.c	(revision 4552)
@@ -1,5 +1,5 @@
 # include "scheduler.h"
 
-int controller_host (int argc, char **argv) {
+int controller_status (int argc, char **argv) {
 
   int status;
@@ -8,12 +8,16 @@
 
   if (argc != 3) {
-    fprintf (stderr, "USAGE: controller host (hostname)\n");
+    fprintf (stderr, "USAGE: controller status\n");
     return (FALSE);
   }
 
-  /* start controller connection (if needed) */
-  StartController ();
+  /* check if controller is running */
+  status = CheckControllerStatus ();
+  if (!status) {
+    fprintf (stderr, "controller is not running\n");
+    return (TRUE);
+  }
 
-  sprintf (command, "host %s", argv[2]);
+  sprintf (command, "status");
   InitIOBuffer (&buffer, 0x100);
   status = ControllerCommand (command, CONTROLLER_PROMPT, &buffer);
@@ -32,4 +36,5 @@
     case CONTROLLER_GOOD:
       fprintf (stderr, "controller command sent\n");  
+      fwrite (buffer.buffer, 1, buffer.Nbuffer, stderr);
       return (TRUE);
 
Index: /trunk/Ohana/src/opihi/pantasks/delete.c
===================================================================
--- /trunk/Ohana/src/opihi/pantasks/delete.c	(revision 4551)
+++ /trunk/Ohana/src/opihi/pantasks/delete.c	(revision 4552)
@@ -1,5 +1,5 @@
-# include "pcontrol.h"
+# include "scheduler.h"
 
-int delete (int argc, char **argv) {
+int delete_job (int argc, char **argv) {
 
   Job *job;
@@ -13,28 +13,5 @@
   /* use a string interp to convert JobIDs to ints ? */
 
-  job = PullJob (JobID, PCONTROL_JOB_PENDING);
-  if (job != NULL) goto found;
-
-  job = PullJob (JobID, PCONTROL_JOB_CRASH);
-  if (job != NULL) goto found;
-
-  job = PullJob (JobID, PCONTROL_JOB_EXIT);
-  if (job != NULL) goto found;
-
-  fprintf (stderr, "job %s not PENDING, CRASH, EXIT\n", argv[1]);
-  return (FALSE);
-  
-found:
-  {
-    int j;
-    fprintf (stderr, "deleting job  %s  %d  ", job[0].hostname, job[0].argc);
-    for (j = 0; j < job[0].argc; j++) {
-      fprintf (stderr, "%s ", job[0].argv[j]);
-    }
-    PrintID (stderr, job[0].JobID);
-    fprintf (stderr, "\n");
-  }  
-  DelJob (job);
-
+  fprintf (stderr, "this function is not yet implemented\n");
   return (TRUE);
 }
Index: /trunk/Ohana/src/opihi/pantasks/init.c
===================================================================
--- /trunk/Ohana/src/opihi/pantasks/init.c	(revision 4551)
+++ /trunk/Ohana/src/opihi/pantasks/init.c	(revision 4552)
@@ -1,3 +1,2 @@
-# include "basic.h"
 # include "scheduler.h"
 
@@ -10,4 +9,7 @@
 int run             PROTO((int, char **));
 int stop            PROTO((int, char **));
+int status_sys      PROTO((int, char **));
+int kill_job        PROTO((int, char **));
+int delete_job      PROTO((int, char **));
 
 static Command cmds[] = {  
@@ -21,14 +23,21 @@
   {"run",        run,          "run the scheduler"},
   {"stop",       stop,         "stop the scheduler"},
+  {"status",     status_sys,   "get system status"},
+  {"kill",       kill_job,     "kill job"},
+  {"delete",     delete_job,   "delete job"},
+}; 
 
+/* these are functions which duplicate actions on the 
+   controller.  these could simply pass the command along 
+   to the controller (and should then be in 'controller'),
+   or they could add / modify the jobs in the scheduler
+   job stack 
+
+  {"job",        job,          "add job"},
   {"kill",       kill_sh,      "kill job"},
   {"delete",     delete,       "delete job"},
-  {"job",        job,          "add job"},
-  {"host",       host,         "add / delete / modify host"},
-  {"check",      check,        "get job or host status"},
-  {"status",     status,       "get system status"},
-  {"stdout",     stdout_pc,    "get stdout buffer for job"},
-  {"stderr",     stderr_pc,    "get stderr buffer for job"},
-}; 
+  {"stdout",     stdout_sh,    "get stdout buffer for job"},
+  {"stderr",     stderr_sh,    "get stderr buffer for job"},
+*/
 
 void InitSched () {
Index: /trunk/Ohana/src/opihi/pantasks/job.c
===================================================================
--- /trunk/Ohana/src/opihi/pantasks/job.c	(revision 4551)
+++ /trunk/Ohana/src/opihi/pantasks/job.c	(revision 4552)
@@ -1,3 +1,19 @@
-# include "pcontrol.h"
+# include "scheduler.h"
+
+/* this will require a bit of care: to define a job, we need
+   to specify:
+   - the command 
+     this is defined in the job command: job argv0 argv1 argv2...
+   - timeout (an option to the command)
+   - exit macros?
+     do nothing by default?
+   - stderr / stdout disposal?
+     save in a specific buffer by default?
+     send to a file?
+
+   the command can look just like the controller equivalent one:
+   job [-host host] [-timeout timeout] args...
+
+*/
 
 int job (int argc, char **argv) {
Index: /trunk/Ohana/src/opihi/pantasks/kill.c
===================================================================
--- /trunk/Ohana/src/opihi/pantasks/kill.c	(revision 4551)
+++ /trunk/Ohana/src/opihi/pantasks/kill.c	(revision 4552)
@@ -1,5 +1,5 @@
-# include "pcontrol.h"
+# include "scheduler.h"
 
-int kill_pc (int argc, char **argv) {
+int kill_job (int argc, char **argv) {
 
   Job *job;
@@ -12,12 +12,7 @@
   JobID = atoi (argv[1]);
 
-  job = PullJob (JobID, PCONTROL_JOB_BUSY);
-  if (job == NULL) {
-    fprintf (stderr, "job %s not BUSY\n", argv[1]);
-    return (FALSE);
-  }
-  KillJob (job);
+  /* not yet implemented */
+
+  fprintf (stderr, "this function is not yet implemented\n");
   return (TRUE);
 }
-
-/* find job from jobID, kill locally or on controller */
Index: /trunk/Ohana/src/opihi/pantasks/run.c
===================================================================
--- /trunk/Ohana/src/opihi/pantasks/run.c	(revision 4551)
+++ /trunk/Ohana/src/opihi/pantasks/run.c	(revision 4552)
@@ -14,15 +14,2 @@
   return (TRUE);
 }
-
-int stop (int argc, char **argv) {
-
-  if (argc != 1) {
-    fprintf (stderr, "USAGE: stop\n");
-    return (FALSE);
-  }
-
-  rl_event_hook = NULL;
-  rl_set_keyboard_input_timeout (1000000); 
-
-  return (TRUE);
-}
Index: /trunk/Ohana/src/opihi/pantasks/status.c
===================================================================
--- /trunk/Ohana/src/opihi/pantasks/status.c	(revision 4552)
+++ /trunk/Ohana/src/opihi/pantasks/status.c	(revision 4552)
@@ -0,0 +1,9 @@
+# include "scheduler.h"
+
+int status_sys (int argc, char **argv) {
+
+  ListTasks ();
+  ListJobs ();
+
+}
+
Index: /trunk/Ohana/src/opihi/pantasks/stop.c
===================================================================
--- /trunk/Ohana/src/opihi/pantasks/stop.c	(revision 4552)
+++ /trunk/Ohana/src/opihi/pantasks/stop.c	(revision 4552)
@@ -0,0 +1,14 @@
+# include "scheduler.h"
+
+int stop (int argc, char **argv) {
+
+  if (argc != 1) {
+    fprintf (stderr, "USAGE: stop\n");
+    return (FALSE);
+  }
+
+  rl_event_hook = NULL;
+  rl_set_keyboard_input_timeout (1000000); 
+
+  return (TRUE);
+}
Index: /trunk/Ohana/src/opihi/pcontrol/check.c
===================================================================
--- /trunk/Ohana/src/opihi/pcontrol/check.c	(revision 4551)
+++ /trunk/Ohana/src/opihi/pcontrol/check.c	(revision 4552)
@@ -10,6 +10,6 @@
 
   if (argc != 3) {
-    fprintf (stderr, "USAGE: check (job) (JobID)\n");
-    fprintf (stderr, "USAGE: check (host) (HostID)\n");
+    fprintf (stderr, "USAGE: check job (JobID)\n");
+    fprintf (stderr, "USAGE: check host (HostID)\n");
     return (FALSE);
   }
