Changeset - 33de0c52b059
[Not reviewed]
default
0 3 0
Ethan Zonca (ethanzonca) - 16 years ago 2010-02-20 00:55:13
e@ethanzonca.com
Slave reorganization, cleanup
3 files changed with 40 insertions and 33 deletions:
0 comments (0 inline, 0 general)
src/server/slave.c
Show inline comments
 
@@ -51,28 +51,12 @@ int main(int argc, char *argv[])
 
    CFG_END()
 
  };
 
  cfg_t * my_cfg;
 

	
 
  struct options_common *commonopts;
 

	
 
  int jobnum = 0;
 
  int framenum = 0;
 

	
 
  char *urltoTar;      /* Full URL to the server-side location of job#.tgz */
 
  char *pathtoTar;     /* Full path to the location of the job#.tgz */
 

	
 
  char *urltoOutput;   /* Full URL where output is posted */
 
  char *pathtoJobfile; /* Full path to the job's main file */
 
  char *pathtoXml;     /* Full path to the job's xml file */
 
  char *pathtoOutput;  /* Full path to the output (rendered) file */
 
  char *outputExt;     /* Output Extension (e.g., JPG) */
 

	
 
  char *tarcmd;        /* Command to run for tar. Migrate to libtar sometime */
 
  char *outdir;        /* Output Directory for tar */
 
  char *jobdatapath;   /* Path to job data */
 

	
 
  struct distrenjob *myjob; /* Structure to hold data gathered from the XML file */
 

	
 
  struct remoteio *comm_slave;
 

	
 
  /**
 
     initializations
 
@@ -131,28 +115,42 @@ int main(int argc, char *argv[])
 
      }
 
    else
 
      {
 
	fprintf(stderr, "Please check your distrenslave.conf, it appears to be incorrectly formatted.\n");
 
      }
 

	
 

	
 

	
 
  fprintf(stderr, "Loading config...\n");
 

	
 

	
 
  fprintf(stderr, "Connecting to server...\n");
 
  tmp = remoteio_open(&comm_slave, commonopts->remoteio, server);
 
  if(tmp)
 
    {
 
      fprintf(stderr, "Error connecting to server; exiting\n");
 
      return 1;
 
    }
 

	
 
  int haveWork = 0;
 

	
 
  // Variables needed for main loop
 
  int jobnum = 0;
 
  int framenum = 0;
 

	
 
  char *urltoTar;      /* Full URL to the server-side location of job#.tgz */
 
  char *pathtoTar;     /* Full path to the location of the job#.tgz */
 

	
 
  char *urltoOutput;   /* Full URL where output is posted */
 
  char *pathtoOutput;  /* Full path to the output (rendered) file */
 

	
 
  while(1)
 
  char *pathtoJobfile; /* Full path to the job's main file */
 
  char *pathtoXml;     /* Full path to the job's xml file */
 
  char *outputExt;     /* Output Extension (e.g., JPG) */
 

	
 
  char *jobdatapath;   /* Path to job data */
 

	
 
  int haveWork = 0;
 
  int quit = 0;
 

	
 
  // Main loop
 
  while(!quit)
 
    {
 

	
 
    // request work
 
    fprintf(stderr,"Requesting work...\n");
 
    sendSignal(comm_slave, DISTREN_REQUEST_GETWORK);
 

	
 
@@ -176,21 +174,13 @@ int main(int argc, char *argv[])
 
        _distren_asprintf(&pathtoXml, "%s/job%d/job%d.xml", datadir, jobnum ); // Prepares the path to the job's XML file
 
        free(jobdatapath);
 

	
 
        if(downloadTar(urltoTar, pathtoTar))
 
          return 1;
 

	
 
        _distren_asprintf(&outdir, "/tmp/distren/job%d", jobnum);
 
        mkdir("/tmp/distren", 0750); /* @FIXME: Change to tmpdir once it exists */
 
        mkdir(outdir, 0750);
 

	
 
        _distren_asprintf(&tarcmd, "tar -xvf \"%s\" -C \"%s\"", pathtoTar, outdir); /* @FIXME:Use a lib here! */
 
        system(tarcmd);
 
        free(tarcmd);
 
        free(pathtoTar);
 
        free(outdir);
 
        unpackJob(pathtoTar, jobnum);
 

	
 
        /* Parses a job's XML file, puts data in the myjob struct */
 
        if(distrenjob_unserialize(&myjob, pathtoXml) == 0)
 
          {
 
            fprintf(stderr, "Well, the XML craziness may have worked. Maybe. \n");
 
            free(pathtoXml);
 
@@ -218,13 +208,12 @@ int main(int argc, char *argv[])
 
            return 1;
 
          }
 
        free(pathtoJobfile);
 

	
 
        /* Post-execution */
 
        fprintf(stderr, "Finished frame %d in job %d, uploading...\n", framenum, jobnum);
 

	
 
        uploadOutput(pathtoOutput, urltoOutput); // @TODO: Handle return value
 

	
 
        free(urltoOutput);
 
        free(pathtoOutput);
 

	
 
        // Tell the server that rendering and upload are complete of "jobjum.framenum"
src/server/slavefuncs.c
Show inline comments
 
@@ -383,6 +383,23 @@ int uploadOutput(char *pathtoOutput, cha
 
          sleep(10);
 
        }
 
      return 1; // Upload failed after multiple tries
 
      // @FUTURE: Keep track of files that we were unable to upload, and upload them later
 
    }
 
}
 

	
 

	
 
int unpackJob(char *pathtoTar, int jobnum){
 
  char *tarcmd;        /* Command to run for tar. Migrate to libtar sometime */
 
  char *outdir;        /* Output Directory for tar */
 

	
 
  _distren_asprintf(&outdir, "/tmp/distren/job%d", jobnum);
 
  mkdir("/tmp/distren", 0750); /* @FIXME: Change to tmpdir once it exists */
 
  mkdir(outdir, 0750);
 

	
 
  _distren_asprintf(&tarcmd, "tar -xvf \"%s\" -C \"%s\"", pathtoTar, outdir); /* @FIXME:Use a lib here! */
 
  system(tarcmd);
 
  free(tarcmd);
 
  free(pathtoTar);
 
  free(outdir);
 
  return 0;
 
}
src/server/slavefuncs.h
Show inline comments
 
@@ -45,8 +45,9 @@ int exec_blender(char *input, char *outp
 
void xmlinit();
 
void xmlcleanup();
 
int distren_mkdir_recurse(char *dirname);
 
int job_build_path(char *filename, unsigned int jobnum);
 
int downloadTar(char *url, char *destinationPath);
 
int uploadOutput(char *pathtoOutput, char *urltoOutput);
 
int unpackJob(char *pathtoTar, int jobnum);
 

	
 
#endif
0 comments (0 inline, 0 general)