IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 19125


Ignore:
Timestamp:
Aug 19, 2008, 12:29:10 PM (18 years ago)
Author:
eugene
Message:

adding host tracking and restart

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

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/opihi/include/pantasks.h

    r17419 r19125  
    5858  int Nrun;
    5959} TimeRange;
     60
     61/* data to define a host machine */
     62typedef struct {
     63  char       *hostname;
     64  int         max_threads;
     65} Host;
    6066
    6167/* a task is a description of the wrapping of a job */
     
    233239int QuitController ();
    234240int StopController ();
     241int RestartController ();
    235242int VerboseMode ();
    236243int KillLocalJob (Job *job);
  • trunk/Ohana/src/opihi/pantasks/ControllerOps.c

    r18085 r19125  
    1010static IOBuffer stderr_buffer;
    1111static int ControllerPID = 0;
     12
     13/* local static variables to track the controller host properties */
     14static Host *hosts = NULL;
     15static int Nhosts = 0;
     16static int NHOSTS = 0;
     17
     18int AddHost (char *hostname, int max_threads) {
     19
     20  int N;
     21
     22  N = Nhosts;
     23  Nhosts ++;
     24
     25  CHECK_REALLOCATE (hosts, Host, NHOSTS, Nhosts, 16);
     26
     27  hosts[N].hostname = strcreate (hostname);
     28  hosts[N].max_threads = max_threads;
     29 
     30  return (TRUE);
     31}
     32
     33int DeleteHost (char *hostname) {
     34
     35  int i, j;
     36
     37  for (i = 0; i < Nhosts; i++) {
     38    if (strcmp (hosts[i].hostname, hostname)) continue;
     39   
     40    // delete this one
     41    free (hosts[i].hostname);
     42    for (j = i; j < Nhosts - 1; j++) {
     43      hosts[j].hostname = hosts[j+1].hostname;
     44      hosts[j].max_threads = hosts[j+1].max_threads;
     45    }
     46    Nhosts --;
     47    return (TRUE);
     48  }
     49  return (FALSE);
     50}
    1251
    1352/* test if the controller is running */
     
    146185
    147186  /* is pipe still open? */
    148   if ((status == -1) && (errno == EPIPE)) return (CONTROLLER_DOWN);
     187  // XXX call StopController() here?
     188  if ((status == -1) && (errno == EPIPE)) {
     189    StopController ();
     190    return (CONTROLLER_DOWN);
     191  }
    149192
    150193  /* read at least Nbytes, then watch for CONTROLLER_PROMPT */
     
    158201    if (status == -1) nanosleep (&request, &remain);
    159202  }
    160   if (status ==  0) return (CONTROLLER_DOWN);
     203  if (status ==  0) {
     204    StopController ();
     205    return (CONTROLLER_DOWN);
     206  }
    161207  if (status == -1) return (CONTROLLER_HUNG);
    162208
     
    245291  if (VarConfig ("CONTROLLER", "%s", cmd) == NULL) strcpy (cmd, "pcontrol");
    246292
     293  if (hosts == NULL) {
     294    NHOSTS = 16;
     295    ALLOCATE (hosts, Host, NHOSTS);
     296  }
     297
    247298  bzero (stdin_fd,  2*sizeof(int));
    248299  bzero (stdout_fd, 2*sizeof(int));
     
    360411  if ((status == -1) && (errno == EPIPE)) {
    361412    StopController ();
    362     gprint (GP_ERR, "controller is down\n");
     413    gprint (GP_ERR, "controller is down, restarting\n");
     414    if (!RestartController ()) {
     415      return (FALSE);
     416    }
    363417    return (FALSE);
    364418  }
     
    509563  return (TRUE);
    510564}
     565
     566int RestartController () {
     567
     568  int i, status;
     569  char command[256];
     570  IOBuffer buffer;
     571
     572  gprint (GP_ERR, "controller is down, restarting\n");
     573  if (!StartController ()) {
     574    gprint (GP_ERR, "failure to re-start pcontrol\n");
     575    return (FALSE);
     576  }
     577
     578  InitIOBuffer (&buffer, 0x100);
     579
     580  // XXX lock the host table? SerialThreadLock ();
     581  fprintf (stderr, "controller is down, restarting\n");
     582  for (i = 0; i < Nhosts; i++) {
     583    fprintf (stderr, "controller host add %s -threads %d\n", hosts[i].hostname, hosts[i].max_threads);
     584    snprintf (command, 256, "host add %s -threads %d\n", hosts[i].hostname, hosts[i].max_threads);
     585    status = ControllerCommand (command, CONTROLLER_PROMPT, &buffer);
     586  }
     587  // SerialThreadUnlock ();
     588
     589  if (status) gwrite (buffer.buffer, 1, buffer.Nbuffer, GP_LOG);
     590
     591  FreeIOBuffer (&buffer);
     592
     593  return (TRUE);
     594}
  • trunk/Ohana/src/opihi/pantasks/controller_host.c

    r8548 r19125  
    33int controller_host (int argc, char **argv) {
    44
    5   int status;
     5  int N, status, max_threads;
    66  char command[1024];
    77  IOBuffer buffer;
    88
    9   if (argc != 3) {
    10     gprint (GP_ERR, "USAGE: controller host (command) (hostname)\n");
    11     return (FALSE);
     9  max_threads = 0;
     10  if ((N = get_argument (argc, argv, "-threads"))) {
     11    remove_argument (N, &argc, argv);
     12    max_threads = atoi(argv[N]);
     13    remove_argument (N, &argc, argv);
    1214  }
     15
     16  if (argc != 3) goto usage;
    1317
    1418  /* start controller connection (if needed) */
     
    1822  }
    1923
    20   sprintf (command, "host %s %s", argv[1], argv[2]);
     24  // the user may issue any of these commands:
     25  // ADD, ON, RETRY, CHECK, OFF, DELETE
     26  // we need to catch ADD and DELETE and modify our host table accordingly
     27  if (!strcasecmp (argv[1], "ADD")) {
     28    AddHost (argv[2], max_threads);
     29  } else {
     30    if (max_threads) goto usage;
     31  }
     32
     33  if (!strcasecmp (argv[1], "DELETE")) {
     34    DeleteHost (argv[2]);
     35  }
     36
     37  if (max_threads) {
     38    sprintf (command, "host %s %s -threads %d", argv[1], argv[2], max_threads);
     39  } else {
     40    sprintf (command, "host %s %s", argv[1], argv[2]);
     41  }
    2142  InitIOBuffer (&buffer, 0x100);
    2243
     
    2950  FreeIOBuffer (&buffer);
    3051  return (TRUE);
     52 
     53usage:
     54  gprint (GP_LOG, "USAGE: controller host (command) (hostname)\n");
     55  gprint (GP_ERR, "  valid commands: add, on, retry, check, off, delete\n");
     56  gprint (GP_ERR, "  -threads Nthreads is optional for 'add'\n");
     57  return (FALSE);
    3158}
    3259
Note: See TracChangeset for help on using the changeset viewer.