IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 4573


Ignore:
Timestamp:
Jul 16, 2005, 6:01:28 AM (21 years ago)
Author:
eugene
Message:

added user scheduler/controller commands, fixed up I/F issues

Location:
trunk/Ohana/src/opihi
Files:
1 added
18 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/opihi/doc/scheduler.txt

    r4552 r4573  
     1
     22005.07.15
     3
     4The controller sends messages to both stdout and stderr.  I can easily
     5require the messages which are immediate responses to external
     6commands (status, check, etc) go back on stdout.  other messages
     7should go to stderr, or be suppressed.  I suppose i can regularly
     8harvest the stderr messages?
    19
    2102005.07.14
     
    5058- allow the 'periods' command to define defaults when outside of a
    5159  task
    52 
    53 -
    5460
    55612005.07.05
  • trunk/Ohana/src/opihi/include/pcontrol.h

    r4450 r4573  
    134134Host *PullHost (IDtype HostID, int StackID);
    135135int FindNamedHost (char *name, int StackID);
    136 void AddHost (char *hostname);
     136IDtype AddHost (char *hostname);
    137137void DownHost (Host *host);
    138138void OffHost (Host *host);
  • trunk/Ohana/src/opihi/include/scheduler.h

    r4552 r4573  
    8383} Job;
    8484
    85 # define CONTROLLER_PROMPT "pclient:"
     85# define CONTROLLER_PROMPT "pcontrol:"
    8686
    8787/* scheduler prototypes */
  • trunk/Ohana/src/opihi/pantasks/CheckSystem.c

    r4450 r4573  
    55  CheckTasks ();
    66  CheckJobs ();
     7  CheckControllerOutput ();
    78
    89}
  • trunk/Ohana/src/opihi/pantasks/ControllerOps.c

    r4552 r4573  
    55static int status = FALSE;
    66static int stdin_cntl, stdout_cntl, stderr_cntl;
     7static IOBuffer stdout_buffer;
     8static IOBuffer stderr_buffer;
    79
    810int CheckControllerStatus () {
     
    108110  line = NULL;
    109111  status = -1;
    110   for (i = 0; (i < CONTROLLER_TIMEOUT) && (status == -1) && (line == NULL); i++) {
     112  for (i = 0; (i < CONTROLLER_TIMEOUT) && (status != 0) && (line == NULL); i++) {
    111113    status = ReadtoIOBuffer (buffer, stdout_cntl);
    112114    if ((buffer[0].Nbuffer - Nstart) >= Nbytes) {
     
    261263  p = NULL;
    262264  status = -1;
    263   for (i = 0; (i < CONNECT_TIMEOUT) && (status == -1) && (p == NULL); i++) {
     265  for (i = 0; (i < CONNECT_TIMEOUT) && (status != 0) && (p == NULL); i++) {
    264266    status = ReadtoIOBuffer (&buffer, stdout_fd[0]);
    265267    p = memstr (buffer.buffer, "CONNECTED", buffer.Nbuffer);
     
    274276  stdout_cntl = stdout_fd[0];
    275277  stderr_cntl = stderr_fd[0];
     278
     279  InitIOBuffer (&stdout_buffer, 0x100);
     280  InitIOBuffer (&stderr_buffer, 0x100);
    276281
    277282  fprintf (stderr, "Connected\n");
     
    319324  line = NULL;
    320325  status = -1;
    321   for (i = 0; (i < CONTROLLER_TIMEOUT) && (status == -1) && (line == NULL); i++) {
     326  for (i = 0; (i < CONTROLLER_TIMEOUT) && (status != 0) && (line == NULL); i++) {
    322327    status = ReadtoIOBuffer (buffer, stdout_cntl);
    323328    line = memstr (buffer[0].buffer, response, buffer[0].Nbuffer);
     
    330335}
    331336
     337int CheckControllerOutput () {
     338
     339  int Nread;
     340
     341  /* read stdout buffer */
     342  Nread = ReadtoIOBuffer (&stdout_buffer, stdout_cntl);
     343  switch (Nread) {
     344    case -2:  /* error in read (programming error?  system level error?) */
     345      fprintf (stderr, "serious IO error\n");
     346      exit (2);
     347    case -1:  /* no data in pipe */
     348      break;
     349    case 0:   /* pipe is closed */
     350      /** change child state? **/
     351      break;
     352    default:  /* data in pipe */
     353      break;
     354  }
     355 
     356  /* read stderr buffer */
     357  Nread = ReadtoIOBuffer (&stderr_buffer, stderr_cntl);
     358  switch (Nread) {
     359    case -2:  /* error in read (programming error?  system level error?) */
     360      fprintf (stderr, "serious IO error\n");
     361      exit (2);
     362    case -1:  /* no data in pipe */
     363      break;
     364    case 0:   /* pipe is closed */
     365      /** change child state? **/
     366      break;
     367    default:  /* data in pipe */
     368      break;
     369  }
     370  return (TRUE);
     371}
     372
     373int PrintControllerOutput () {
     374
     375  fprintf (stderr, "--- stdout ---\n");
     376  fwrite (stdout_buffer.buffer, 1, stdout_buffer.Nbuffer, stderr);
     377  fprintf (stderr, "--- stdout ---\n");
     378  fwrite (stderr_buffer.buffer, 1, stderr_buffer.Nbuffer, stderr);
     379  fprintf (stderr, "---  done  ---\n");
     380  return (TRUE);
     381}
     382
     383
    332384/* memstr returns a view, not an allocated string : don't free */
  • trunk/Ohana/src/opihi/pantasks/Makefile

    r4552 r4573  
    4848$(SDIR)/controller_check.$(ARCH).o \
    4949$(SDIR)/controller_status.$(ARCH).o \
     50$(SDIR)/controller_output.$(ARCH).o \
    5051$(SDIR)/task.$(ARCH).o \
    5152$(SDIR)/task_command.$(ARCH).o \
  • trunk/Ohana/src/opihi/pantasks/controller.c

    r4552 r4573  
    44int controller_status  PROTO((int, char **));
    55int controller_check   PROTO((int, char **));
     6int controller_output  PROTO((int, char **));
    67
    78static Command controller_cmds[] = {
    89  {"host",   controller_host,   "define host for controller"},
     10  {"check",  controller_check,  "check controller host/job"},
    911  {"status", controller_status, "check controller status"},
    10   {"check",  controller_check,  "check controller host/job"},
     12  {"output", controller_output, "print controller output"},
    1113};
    1214
  • trunk/Ohana/src/opihi/pantasks/controller_check.c

    r4552 r4573  
    88
    99  if (argc != 3) goto usage;
    10   if (strcasecmp (argv[2], "JOB") &&
    11       strcasecmp (argv[2], "HOST")) goto usage;
     10  if (strcasecmp (argv[1], "JOB") &&
     11      strcasecmp (argv[1], "HOST")) goto usage;
    1212
    1313  /* check if controller is running */
     
    1818  }
    1919
    20   sprintf (command, "check %s %s", argv[2], argv[3]);
     20  sprintf (command, "check %s %s", argv[1], argv[2]);
    2121  InitIOBuffer (&buffer, 0x100);
    2222  status = ControllerCommand (command, CONTROLLER_PROMPT, &buffer);
  • trunk/Ohana/src/opihi/pantasks/controller_host.c

    r4539 r4573  
    77  IOBuffer buffer;
    88
    9   if (argc != 3) {
     9  if (argc != 2) {
    1010    fprintf (stderr, "USAGE: controller host (hostname)\n");
    1111    return (FALSE);
     
    1515  StartController ();
    1616
    17   sprintf (command, "host %s", argv[2]);
     17  sprintf (command, "host %s", argv[1]);
    1818  InitIOBuffer (&buffer, 0x100);
    1919  status = ControllerCommand (command, CONTROLLER_PROMPT, &buffer);
     
    3232    case CONTROLLER_GOOD:
    3333      fprintf (stderr, "controller command sent\n"); 
     34      fwrite (buffer.buffer, 1, buffer.Nbuffer, stderr);
     35      fprintf (stderr, "\n Nbytes received: %d\n", buffer.Nbuffer); 
    3436      return (TRUE);
    3537
  • trunk/Ohana/src/opihi/pantasks/controller_status.c

    r4552 r4573  
    77  IOBuffer buffer;
    88
    9   if (argc != 3) {
     9  if (argc != 1) {
    1010    fprintf (stderr, "USAGE: controller status\n");
    1111    return (FALSE);
     
    3737      fprintf (stderr, "controller command sent\n"); 
    3838      fwrite (buffer.buffer, 1, buffer.Nbuffer, stderr);
     39      fprintf (stderr, "\n Nbytes received: %d\n", buffer.Nbuffer); 
    3940      return (TRUE);
    4041
  • trunk/Ohana/src/opihi/pclient/job.c

    r4450 r4573  
    33int job (int argc, char **argv) {
    44
    5   int pid, status;
     5  int i, pid, status;
     6  char **targv;
    67
    78  if (argc < 2) {
     
    2021  if (pipe (child_stdout_fd) < 0) goto pipe_error;
    2122  if (pipe (child_stderr_fd) < 0) goto pipe_error;
     23
     24  /* need to define arg list with NULL termination */
     25  ALLOCATE (targv, char *, argc);
     26  for (i = 1; i < argc; i++) {
     27    targv[i-1] = strcreate (argv[i]);
     28  }
     29  targv[i] = 0;
    2230
    2331  pid = fork ();
     
    3947    setvbuf (stdout, (char *) NULL, _IONBF, BUFSIZ);
    4048    setvbuf (stderr, (char *) NULL, _IONBF, BUFSIZ);
    41     /* fprintf (stderr, "child is spawned, executing command\n"); */
    42     /* note that this message comes out on the other side of the stderr pipe */
    4349
    4450    /* exec job */
    45     status = execvp (argv[1], &argv[1]);
     51    status = execvp (targv[0], targv);
    4652    fprintf (stderr, "error starting child process: %d\n", status);
    4753    exit (1);
  • trunk/Ohana/src/opihi/pcontrol/GetJobOutput.c

    r4462 r4573  
    2525  line = NULL;
    2626  status = -1;
    27   for (i = 0; (i < PCLIENT_TIMEOUT) && (status == -1) && (line == NULL); i++) {
     27  for (i = 0; (i < PCLIENT_TIMEOUT) && (status != 0) && (line == NULL); i++) {
    2828    status = ReadtoIOBuffer (buffer, host[0].stdout);
    2929    if ((buffer[0].Nbuffer - Nstart) >= Nbytes) {
  • trunk/Ohana/src/opihi/pcontrol/HostOps.c

    r4450 r4573  
    153153}
    154154
    155 void AddHost (char *hostname) {
     155IDtype AddHost (char *hostname) {
    156156
    157157  Host *host;
     
    168168  host[0].job      = NULL;
    169169  PutHost (host, PCONTROL_HOST_DOWN, STACK_BOTTOM);
     170  return (host[0].HostID);
    170171}
    171172
  • trunk/Ohana/src/opihi/pcontrol/check.c

    r4552 r4573  
    1010
    1111  if (argc != 3) {
    12     fprintf (stderr, "USAGE: check job (JobID)\n");
    13     fprintf (stderr, "USAGE: check host (HostID)\n");
     12    fprintf (stdout, "USAGE: check job (JobID)\n");
     13    fprintf (stdout, "USAGE: check host (HostID)\n");
    1414    return (FALSE);
    1515  }
     
    4040  }
    4141
    42   fprintf (stderr, "unknown item to check\n");
     42  fprintf (stdout, "unknown item to check\n");
    4343  return (FALSE);
    4444}
  • trunk/Ohana/src/opihi/pcontrol/host.c

    r3212 r4573  
    33int host (int argc, char **argv) {
    44
     5  IDtype HostID;
    56  int N, Delete, Off, On, Start, Stop, Check;
    67  Host *host;
     
    1718  if ((N = get_argument (argc, argv, "-off"))) {
    1819    if (Delete) {
    19       fprintf (stderr, "-delete and -off incompatible\n");
     20      fprintf (stdout, "-delete and -off incompatible\n");
    2021      return (FALSE);
    2122    }
     
    2829  if ((N = get_argument (argc, argv, "-on"))) {
    2930    if (Delete || Off) {
    30       fprintf (stderr, "only one of -delete, -off, -on\n");
     31      fprintf (stdout, "only one of -delete, -off, -on\n");
    3132      return (FALSE);
    3233    }
     
    5758 
    5859  if (argc != 2) {
    59     fprintf (stderr, "USAGE: host (hostname) [-delete]\n");
     60    fprintf (stdout, "USAGE: host (hostname) [-delete]\n");
    6061    return (FALSE);
    6162  }
     
    6465    N = FindNamedHost (argv[1], PCONTROL_HOST_OFF);
    6566    if (N < 0) {
    66       fprintf (stderr, "host %s is not OFF\n", argv[1]);
     67      fprintf (stdout, "host %s is not OFF\n", argv[1]);
    6768      return (FALSE);
    6869    }
     
    7576    N = FindNamedHost (argv[1], PCONTROL_HOST_OFF);
    7677    if (N < 0) {
    77       fprintf (stderr, "host %s is not OFF\n", argv[1]);
     78      fprintf (stdout, "host %s is not OFF\n", argv[1]);
    7879      return (FALSE);
    7980    }
     
    9697      return (TRUE);
    9798    }
    98     fprintf (stderr, "host %s is not BUSY or IDLE\n", argv[1]);
     99    fprintf (stdout, "host %s is not BUSY or IDLE\n", argv[1]);
    99100    return (FALSE);
    100101  }
     
    103104    N = FindNamedHost (argv[1], PCONTROL_HOST_DOWN);
    104105    if (N < 0) {
    105       fprintf (stderr, "host %s is not DOWN\n", argv[1]);
     106      fprintf (stdout, "host %s is not DOWN\n", argv[1]);
    106107      return (FALSE);
    107108    }
     
    113114    N = FindNamedHost (argv[1], PCONTROL_HOST_IDLE);
    114115    if (N < 0) {
    115       fprintf (stderr, "host %s is not IDLE\n", argv[1]);
     116      fprintf (stdout, "host %s is not IDLE\n", argv[1]);
    116117      return (FALSE);
    117118    }
     
    143144      return (TRUE);
    144145    }
    145     fprintf (stderr, "host %s is not BUSY, IDLE, or DOWN\n", argv[1]);
     146    fprintf (stdout, "host %s is not BUSY, IDLE, or DOWN\n", argv[1]);
    146147    return (FALSE);
    147148  }
    148149
    149   AddHost (argv[1]);
     150  HostID = AddHost (argv[1]);
     151  fprintf (stdout, "HostID: %d\n", HostID);
    150152  return (TRUE);
    151153}
  • trunk/Ohana/src/opihi/pcontrol/pclient.c

    r4450 r4573  
    2424  line = NULL;
    2525  status = -1;
    26   for (i = 0; (i < PCLIENT_TIMEOUT) && (status == -1) && (line == NULL); i++) {
     26  for (i = 0; (i < PCLIENT_TIMEOUT) && (status != 0) && (line == NULL); i++) {
    2727    status = ReadtoIOBuffer (buffer, host[0].stdout);
    2828    line = memstr (buffer[0].buffer, response, buffer[0].Nbuffer);
  • trunk/Ohana/src/opihi/pcontrol/rconnect.c

    r4450 r4573  
    7676  p = NULL;
    7777  status = -1;
    78   for (i = 0; (i < CONNECT_TIMEOUT) && (status == -1) && (p == NULL); i++) {
     78  for (i = 0; (i < CONNECT_TIMEOUT) && (status != 0) && (p == NULL); i++) {
    7979    status = ReadtoIOBuffer (&buffer, stdout_fd[0]);
    8080    p = memstr (buffer.buffer, "CONNECTED", buffer.Nbuffer);
  • trunk/Ohana/src/opihi/pcontrol/status.c

    r3212 r4573  
    3030  stack = GetJobStack (Nstack);
    3131  Nobject = stack[0].Nobject;
    32   fprintf (stderr, "job stack %s:  %d objects\n", jobname[Nstack], Nobject);
     32  fprintf (stdout, "job stack %s:  %d objects\n", jobname[Nstack], Nobject);
    3333
    3434  for (i = 0; i < Nobject; i++) {
    3535    job = stack[0].object[i];
    36     fprintf (stderr, "%d  %s  %d  ", i, job[0].hostname, job[0].argc);
     36    fprintf (stdout, "%d  %s  %d  ", i, job[0].hostname, job[0].argc);
    3737    for (j = 0; j < job[0].argc; j++) {
    38       fprintf (stderr, "%s ", job[0].argv[j]);
     38      fprintf (stdout, "%s ", job[0].argv[j]);
    3939    }
    40     PrintID (stderr, job[0].JobID);
    41     fprintf (stderr, "\n");
     40    PrintID (stdout, job[0].JobID);
     41    fprintf (stdout, "\n");
    4242  }
    4343}
     
    5151  stack = GetHostStack (Nstack);
    5252  Nobject = stack[0].Nobject;
    53   fprintf (stderr, "host stack %s:  %d objects\n", hostname[Nstack], Nobject);
     53  fprintf (stdout, "host stack %s:  %d objects\n", hostname[Nstack], Nobject);
    5454
    5555  for (i = 0; i < Nobject; i++) {
    5656    host = stack[0].object[i];
    57     fprintf (stderr, "%d  %s  ", i, host[0].hostname);
    58     PrintID (stderr, host[0].HostID);
    59     fprintf (stderr, "\n");
     57    fprintf (stdout, "%d  %s  ", i, host[0].hostname);
     58    PrintID (stdout, host[0].HostID);
     59    fprintf (stdout, "\n");
    6060  }
    6161}
Note: See TracChangeset for help on using the changeset viewer.