IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 30, 2012, 1:46:12 PM (14 years ago)
Author:
eugene
Message:

merge changes from eam_branches/ipp-20120405

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/Ohana/src/opihi/dvo/dvo_host_utils.c

    r33662 r33963  
    44# define PARALLEL_MANUAL 0
    55# define PARALLEL_SERIAL 0
    6 # define MAX_PATH_LENGTH 1024
    7 
    8 int HostTableLaunchJobs (HostTable *table, char *basecmd, char *options) {
     6# define DVO_MAX_PATH 1024
     7
     8# define DIE(WHO,MSG) { perror(WHO); myAbort(MSG); }
     9
     10int HostTableLaunchJobs (HostTable *table, char *basecmd, char *options, int VERBOSE) {
    911
    1012  char uniquer[12];
     
    1315  snprintf (uniquer, 12, "%05d.%05d", PID, TIME % 100000);
    1416
     17  int top_status = TRUE;
    1518  int i;
    1619  for (i = 0; i < table->Nhosts; i++) {
    1720
    1821    // ensure that the paths are absolute path names
    19     char *tmppath = abspath (table->hosts[i].pathname, MAX_PATH_LENGTH);
     22    char *tmppath = abspath (table->hosts[i].pathname, DVO_MAX_PATH);
    2023    free (table->hosts[i].pathname);
    2124    table->hosts[i].pathname = tmppath;
     
    2326    // need to save the results filename with the uniquer
    2427    // XXX a bit of a waste (but only 1024 * 60 bytes or so
    25     ALLOCATE (table->hosts[i].results, char, MAX_PATH_LENGTH);
    26     snprintf (table->hosts[i].results, MAX_PATH_LENGTH, "%s/dvo.results.%s.fits", table->hosts[i].pathname, uniquer);
    27 
    28     char commandBase[MAX_PATH_LENGTH];
    29     snprintf (commandBase, MAX_PATH_LENGTH, "dvo.command.%s.txt", uniquer);
    30     char *commandFile = abspath(commandBase, MAX_PATH_LENGTH);
     28    ALLOCATE (table->hosts[i].results, char, DVO_MAX_PATH);
     29    snprintf (table->hosts[i].results, DVO_MAX_PATH, "%s/dvo.results.%s.fits", table->hosts[i].pathname, uniquer);
     30
     31    char commandBase[DVO_MAX_PATH];
     32    snprintf (commandBase, DVO_MAX_PATH, "dvo.command.%s.txt", uniquer);
     33    char *commandFile = abspath(commandBase, DVO_MAX_PATH);
    3134
    3235    FILE *f = fopen (commandFile, "w");
    3336    fprintf (f, "%s\n", basecmd);
    34     fclose (f);
     37    if (fflush (f)) DIE("flush", "failed to flush");
     38
     39    int fd = fileno (f);
     40    if (fsync (fd)) DIE("fsync", "failed to fsync");
     41
     42    if (fclose (f)) DIE("close", "failed to close");
     43
     44    // force NFS to write the file to disk
     45    int state;
     46    f = fsetlockfile (commandFile, 0.5, LCK_XCLD, &state);
     47    fclearlockfile (commandFile, f, LCK_XCLD, &state);
    3548
    3649    char command[1024];
     
    3851    free (commandFile);
    3952
    40     if (DEBUG || PARALLEL_MANUAL) fprintf (stderr, "command: %s\n", command);
     53    if (VERBOSE) gprint (GP_ERR, "command: %s\n", command);
    4154
    4255    if (PARALLEL_MANUAL) {
     
    4760      int status = system (command);
    4861      if (status) {
    49         fprintf (stderr, "ERROR running relphot_client\n");
    50         exit (2);
     62        gprint (GP_ERR, "ERROR running relphot_client\n");
     63        top_status = FALSE;
    5164      }
    5265    } else {
     
    5568      int pid = rconnect ("ssh", table->hosts[i].hostname, command, table->hosts[i].stdio, &errorInfo, FALSE);
    5669      if (!pid) {
    57         if (DEBUG) fprintf (stderr, "failure to start %s (error %d)\n", table->hosts[i].hostname, errorInfo);
    58         exit (1);
     70        gprint (GP_ERR, "failure to start %s (error %d)\n", table->hosts[i].hostname, errorInfo);
     71        top_status = FALSE;
     72        continue;
    5973      }
    6074      table->hosts[i].pid = pid; // save for future reference
    6175    }
    6276  }
    63   return TRUE;
     77  return top_status;
    6478}
    6579
     
    86100  }
    87101
    88   char *CATDIR = abspath (tmppath, MAX_PATH_LENGTH);
     102  char *CATDIR = abspath (tmppath, DVO_MAX_PATH);
    89103  if (!CATDIR) {
    90104    gprint (GP_ERR, "failed to make an absolute path from %s (too long)\n", tmppath);
     
    126140
    127141  // launch this command remotely
    128   HostTableLaunchJobs (table, basecmd, options);
     142  HostTableLaunchJobs (table, basecmd, options, VERBOSE);
    129143  free (options);
    130144  free (basecmd);
     
    184198  return TRUE;
    185199}
     200
     201// re-gather the remote results files: this can be used in case one of the clients failed,
     202// and has since been re-run
     203int HostTableReloadResults (char *uniquer, int VERBOSE) {
     204
     205  int i;
     206
     207  // load the list of hosts
     208  SkyTable *sky = GetSkyTable();
     209  if (!sky) {
     210    gprint (GP_ERR, "failed to load sky table for database\n");
     211    return FALSE;
     212  }
     213
     214  char *CATDIR = GetCATDIR ();
     215  if (!CATDIR) {
     216    gprint (GP_ERR, "failed to get CATDIR for database\n");
     217    return FALSE;
     218  }
     219
     220  HostTable *table = HostTableLoad (CATDIR, sky->hosts);
     221  if (!table) {
     222    gprint (GP_ERR, "ERROR: failure reading Host Table %s for database %s\n", sky->hosts, CATDIR);
     223    return FALSE;
     224  }   
     225
     226  // load fields from file
     227  int    Nvec = 0;
     228  Vector **vec = NULL;
     229  for (i = 0; i < table->Nhosts; i++) {
     230    // ensure that the paths are absolute path names
     231    char *tmppath = abspath (table->hosts[i].pathname, DVO_MAX_PATH);
     232    free (table->hosts[i].pathname);
     233    table->hosts[i].pathname = tmppath;
     234
     235    // need to save the results filename with the uniquer
     236    // XXX a bit of a waste (but only 1024 * 60 bytes or so
     237    ALLOCATE (table->hosts[i].results, char, DVO_MAX_PATH);
     238    snprintf (table->hosts[i].results, DVO_MAX_PATH, "%s/dvo.results.%s.fits", table->hosts[i].pathname, uniquer);
     239
     240    int    Ninvec = 0;
     241    Vector **invec = ReadVectorTableFITS (table->hosts[i].results, "RESULT", &Ninvec);
     242    if (!invec) {
     243      // failed to read the file, now what?
     244      gprint (GP_ERR, "failed to read remote result file : %s\n", table->hosts[i].results);
     245      free (table->hosts[i].results);
     246      table->hosts[i].results = NULL;
     247      continue;
     248    }
     249    free (table->hosts[i].results);
     250    table->hosts[i].results = NULL;
     251
     252    // fprintf (stderr, "%s : %d\n", table->hosts[i].pathname, invec[0]->Nelements);
     253
     254    vec = MergeVectors (vec, &Nvec, invec, Ninvec);
     255    if (vec != invec) {
     256      FreeVectorArray (invec, Ninvec);
     257    }
     258  }
     259
     260  for (i = 0; i < Nvec; i++) {
     261    AssignVector (vec[i], vec[i]->name, ANYVECTOR, TRUE);
     262  }
     263  free (vec);
     264
     265  free (table);
     266  return TRUE;
     267}
Note: See TracChangeset for help on using the changeset viewer.