IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 4, 2005, 5:35:47 PM (21 years ago)
Author:
eugene
Message:

substantial dev work on scheduler/pcontrol/pclient

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/opihi/pcontrol/JobOps.c

    r3212 r4450  
    3535}
    3636
     37Job *FindJobStack (IDtype JobID) {
     38
     39  Job *job;
     40
     41  job = FindJobPtr (JobID, PCONTROL_JOB_PENDING);
     42  if (job != NULL) return (job);
     43
     44  job = FindJobPtr (JobID, PCONTROL_JOB_BUSY);
     45  if (job != NULL) return (job);
     46
     47  job = FindJobPtr (JobID, PCONTROL_JOB_EXIT);
     48  if (job != NULL) return (job);
     49
     50  job = FindJobPtr (JobID, PCONTROL_JOB_CRASH);
     51  if (job != NULL) return (job);
     52
     53  job = FindJobPtr (JobID, PCONTROL_JOB_DONE);
     54  if (job != NULL) return (job);
     55
     56  return (NULL);
     57}
     58
     59/* add job to position in stack */
    3760int PutJob (Job *job, int StackID, int where) {
    3861
     
    5174}
    5275 
     76/* remove job from position in stack */
    5377Job *GetJob (int StackID, int where) {
    5478
     
    6387}
    6488 
     89/* return stack position of job */
    6590int FindJob (IDtype JobID, int StackID) {
    6691
     
    81106}
    82107
     108/* return pointer to job */
     109Job *FindJobPtr (IDtype JobID, int StackID) {
     110
     111  int i;
     112  Job *job;
     113  Stack *stack;
     114
     115  stack = GetJobStack (StackID);
     116  if (stack == NULL) return (NULL);
     117
     118  for (i = 0; i < stack[0].Nobject; i++) {
     119    job = (Job *) stack[0].object[i];
     120    if (job[0].JobID == JobID) {
     121      return (job);
     122    }
     123  }
     124  return (NULL);
     125}
     126
     127/* remove job from stack, return pointer */
     128Job *PullJob (IDtype JobID, int StackID) {
     129 
     130  int N;
     131  Job *job;
     132
     133  N = FindJob (JobID, StackID);
     134  if (N < 0) return (NULL);
     135
     136  job = GetJob (StackID, N);
     137  if (job == NULL) {
     138    fprintf (stderr, "programming error! job missing from stack\n");
     139    exit (1);
     140  }
     141  return (job);
     142}
     143
    83144IDtype AddJob (char *hostname, JobMode mode, int timeout, int argc, char **argv) {
    84145
     
    89150  job[0].argc     = argc;
    90151  job[0].argv     = argv;
    91   job[0].hostname = strcreate (hostname);
     152  job[0].hostname = hostname;
    92153  job[0].mode     = mode;
    93154  job[0].host     = NULL;
     
    119180}
    120181
    121 # if (0)
    122 void KillJob (Job *job) {
    123 
    124   int status;
    125   char line[64];
    126   Host *host;
    127 
    128   sprintf (line, "reset\n");
    129 
    130   /* send command to client */
    131   status = write (host[0].stdin, line, strlen(line));
    132   if ((status == -1) && (errno == EPIPE)) {
    133     fprintf (stderr, "host %s is down\n", host[0].hostname);
    134     PutHost (host, PCONTROL_HOST_DOWN, STACK_BOTTOM);
    135     PutJob (job, PCONTROL_JOB_PENDING, STACK_BOTTOM);
    136     return (FALSE);
    137   }
    138   /* check for a response */
    139 
    140   /** this needs to be cleaned up to handle the slow response case **/
    141 }
    142 # endif
    143 
     182/* unlink job and host, pull host from its stack */
    144183Host *UnlinkJobAndHost (Job *job) {
    145184
     
    147186  Host *host;
    148187
    149   host = job[0].host;
     188  host = (Host *) job[0].host;
     189  if (host == NULL) {
     190    fprintf (stderr, "programming error: job has no host\n");
     191    exit (2);
     192  }
    150193
    151194  /* unlink host & job */
     
    153196  host[0].job = NULL;
    154197 
    155   /*** need to pop host off of correct stack XXX ***/
    156   N = FindHost (host[0].HostID, host[0].stack);
    157   if (N < 0) {
     198  /* remove host from correct stack */
     199  if (PullHost (host[0].HostID, host[0].stack) == NULL) {
    158200    fprintf (stderr, "programming error: host is not found in current stack\n");
    159201    exit (2);
    160202  }
    161   host = GetHost (host[0].stack, N);
    162203  return (host);
    163204}
     
    166207  int N;
    167208
    168   job[0].host = host;
    169   host[0].job = job;
    170 
    171 # if (0)
    172   /*** need to pop host off of correct stack XXX ***/
    173   N = FindHost (host[0].HostID, host[0].stack);
    174   if (N < 0) {
    175     fprintf (stderr, "programming error: host is not found in current stack\n");
    176     exit (2);
    177   }
    178   host = GetHost (host[0].stack, N);
    179 # endif
    180 
    181   /*** need to pop job off of correct stack XXX ***/
    182   N = FindJob (job[0].JobID, job[0].stack);
    183   if (N < 0) {
     209  job[0].host = (struct Host *) host;
     210  host[0].job = (struct Job *) job;
     211
     212  /* remove job from correct stack */
     213  if (PullJob (job[0].JobID, job[0].stack) == NULL) {
    184214    fprintf (stderr, "programming error: job is not found in current stack\n");
    185215    exit (2);
    186216  }
    187   job = GetJob (job[0].stack, N);
    188 
    189   /*** this is fairly crazy : the only reason this works is cause I
    190        get the same host ptr here and in CheckIdleHost
    191   ***/
    192 }
     217}
Note: See TracChangeset for help on using the changeset viewer.