Changeset - 78516a1d1aee
[Not reviewed]
default
0 4 0
Ethan Zonca (ethanzonca) - 16 years ago 2010-03-14 16:39:49
e@ethanzonca.com
Distren is now functional
4 files changed with 68 insertions and 18 deletions:
0 comments (0 inline, 0 general)
src/server/simpleslave.c
Show inline comments
 
@@ -111,9 +111,13 @@ int main(int argc, char *argv[])
 
  char *pathtoTar;     /* Full path to the location of the job#.tgz */
 
  char *pathtoTardir;
 

	
 
  // Temporary for uncomressed testing
 
  char *urltoJobfile;
 

	
 
  char *urltoOutput;   /* Full URL where output is posted */
 
  char *pathtoOutput;  /* Full path to the output (rendered) file */
 
  char *pathtoOutdir;  /* Full path to output directory */
 
  char *pathtoRenderOutput; /* Contains blender framenum placeholder */
 

	
 
  char *pathtoJob; /* Path to job data folder */
 
  char *pathtoJobfile; /* Full path to the job's main file */
 
@@ -141,19 +145,23 @@ int main(int argc, char *argv[])
 

	
 
        fprintf(stderr, "Preparing to render frame %d in job %d\n", framenum, jobnum);
 

	
 
        prepareJobPaths(jobnum, framenum, outputExt, datadir, &urltoTar, &pathtoTar, &pathtoTardir, &pathtoJob, &pathtoJobfile, &urltoOutput, &pathtoOutput, &pathtoOutdir);
 
        prepareJobPaths(jobnum, framenum, outputExt, datadir, &urltoTar, &pathtoTar, &pathtoTardir, &pathtoJob, &pathtoJobfile, &urltoJobfile, &urltoOutput, &pathtoOutput, &pathtoRenderOutput, &pathtoOutdir);
 
        //free(outputExt);
 
        mkdir(pathtoTardir, 0700);
 
        int dlret = downloadTar(urltoTar, pathtoTar);
 
        // int dlret = downloadTar(urltoTar, pathtoTar);
 
        int dlret = downloadTar(urltoJobfile, pathtoJobfile);
 
        if(dlret == 0)
 
          fprintf(stderr,"Got data tarball\n");
 
          // fprintf(stderr,"Got data tarball\n");
 
          fprintf(stderr,"Got uncompressed data!\n");
 
        else if(dlret == 3){
 
          _web_resetframe(slavekey, password, jobnum, framenum);  // Unassign the frame on the server so other slaves can render it
 
          return 0; // ouput dir doesn't exist
 
        }
 
        else
 
          fprintf(stderr,"Using existing tarball %s...\n", pathtoTar);
 
          fprintf(stderr,"Using existing uncompressed data %s...\n", pathtoJobfile);
 
          //fprintf(stderr,"Using existing tarball %s...\n", pathtoTar);
 

	
 
        /* // Commented for decompression
 
        struct stat jbuffer;
 
        int jstatus = stat(pathtoJobfile, &jbuffer);
 
        if(jstatus == -1){
 
@@ -165,7 +173,7 @@ int main(int argc, char *argv[])
 
            return 1;
 
          }
 
        }
 

	
 
        */
 

	
 
        /* ignore return because directory may exist already */
 
        fprintf(stderr,"Creating output directory %s\n", pathtoOutdir);
 
@@ -177,7 +185,7 @@ int main(int argc, char *argv[])
 
        fprintf(stderr,"Executing blender on file %s\n", pathtoJobfile);
 
        fprintf(stderr,"Directing output to file %s\n", pathtoOutput);
 

	
 
        if(exec_blender(pathtoJobfile, pathtoOutput, framenum))
 
        if(exec_blender(pathtoJobfile, pathtoRenderOutput, framenum))
 
          {
 
            fprintf(stderr,"Error running Blender. Check your installation and/or your PATH.\n");
 
            _web_resetframe(slavekey, password, jobnum, framenum);  // Unassign the frame on the server so other slaves can render it
 
@@ -188,7 +196,7 @@ int main(int argc, char *argv[])
 
        struct stat buffer;
 
        int fstatus = stat(pathtoOutput, &buffer);
 
        if(fstatus == -1){
 
          fprintf(stderr,"*** Frame was not rendered correctly! Scene may not have camera, or your blender installation is not working.\n");
 
          fprintf(stderr,"*** %s doesn't exist! Scene may not have camera, or your blender installation is not working.\n", pathtoOutput);
 
          _web_resetframe(slavekey, password, jobnum, framenum);  // Unassign the frame on the server so other slaves can render it
 
          return 1;
 
        }
src/server/slave.c
Show inline comments
 
@@ -116,11 +116,15 @@ int main(int argc, char *argv[])
 
  char *urltoTar;      /* Full URL to the server-side location of job#.tgz */
 
  char *pathtoTar;     /* Full path to the location of the job#.tgz */
 
  char *pathtoTardir;
 
  char *pathtoRenderOutput;
 

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

	
 
  // Temporary for uncomressed testing
 
  char *urltoJobfile;
 

	
 
  char *pathtoJob;     /* Full path to job data folder */
 
  char *pathtoJobfile; /* Full path to the job's main file */
 
  char *outputExt;     /* Output Extension (e.g., JPG) */
 
@@ -147,7 +151,7 @@ int main(int argc, char *argv[])
 

	
 
        fprintf(stderr, "Preparing to render frame %d in job %d\n", framenum, jobnum);
 

	
 
        prepareJobPaths(jobnum, framenum, outputExt, datadir, &urltoTar, &pathtoTar,&pathtoTardir,&pathtoJob, &pathtoJobfile, &urltoOutput, &pathtoOutput, &pathtoOutdir);
 
        prepareJobPaths(jobnum, framenum, outputExt, datadir, &urltoTar, &pathtoTar,&pathtoTardir,&pathtoJob, &pathtoJobfile, &urltoJobfile, &urltoOutput, &pathtoOutput, &pathtoRenderOutput, &pathtoOutdir);
 
        free(outputExt);
 

	
 
        if(downloadTar(urltoTar, pathtoTar))
src/server/slavefuncs.c
Show inline comments
 
@@ -167,11 +167,13 @@ int curlget(char *url, char *out){
 
    curl_easy_cleanup(curl);
 
  }
 
  fprintf(stderr,"\n"); // Clears out he progressbar's carriage return
 
  fclose(outfile);
 
  return res; // 0 is OK, 1 is 404 or other error
 
}
 

	
 
/** Posts a file to a url with cUrl */
 
int curlpost(char *filename, char *url, int jobnum, int framenum, int slavekey){
 
  fprintf(stderr,"Uploading to %s\n", url);
 
  char *targetname = "uploadedfile"; // Name of the target in the php file on the server (Don't change me unless you have different PHP code)
 
  CURL *curl;
 
  CURLcode res;
 
@@ -180,23 +182,30 @@ int curlpost(char *filename, char *url, 
 
  struct curl_slist *headerlist=NULL;
 
  static const char buf[] = "Expect:";
 

	
 
  char *sjobnum;
 
  char *sframenum;
 
  char *sslavekey;
 
  _distren_asprintf(&sjobnum,"%d",jobnum);
 
  _distren_asprintf(&sframenum,"%d",framenum);
 
  _distren_asprintf(&sslavekey,"%d",slavekey);
 

	
 
  curl_global_init(CURL_GLOBAL_ALL);
 

	
 
  /* jobnum field... */
 
   curl_formadd(&formpost,
 
                &lastptr,
 
                CURLFORM_COPYNAME, "jobnum",
 
                CURLFORM_COPYCONTENTS, jobnum, CURLFORM_END);
 
                CURLFORM_COPYCONTENTS, sjobnum, CURLFORM_END);
 
  /* framenum field... */
 
  curl_formadd(&formpost,
 
               &lastptr,
 
               CURLFORM_COPYNAME, "framenum",
 
               CURLFORM_COPYCONTENTS, framenum, CURLFORM_END);
 
               CURLFORM_COPYCONTENTS, sframenum, CURLFORM_END);
 
  /* slavekey field... */
 
  curl_formadd(&formpost,
 
               &lastptr,
 
               CURLFORM_COPYNAME, "slavekey",
 
               CURLFORM_COPYCONTENTS, slavekey, CURLFORM_END);
 
               CURLFORM_COPYCONTENTS, sslavekey, CURLFORM_END);
 
  /* upload field... */
 
  curl_formadd(&formpost,
 
               &lastptr,
 
@@ -293,9 +302,9 @@ int exec_blender(char *input, char *outp
 
  _distren_asprintf(&frame_str, "%i", frame);
 

	
 
  char *command = "blender"; // @TODO: We currently expect this to be in PATH
 
  char *cmd[] = { command, "-b", "-o", output, input, "-f", frame_str, (char *)NULL }; // arguments for blender
 
  char *cmd[] = { command, "-b", input, "-o", output, "-f", frame_str, (char *)NULL }; // arguments for blender
 

	
 
  fprintf(stderr,"Preparing to execute command: %s -b -o %s %s -f %s\n", command, output, input, frame_str);
 
  fprintf(stderr,"Preparing to execute command: %s -b %s -o %s -f %s\n", command, input, output, frame_str);
 

	
 
  char buf[10];
 
  struct execio *testrem;
 
@@ -387,6 +396,7 @@ int downloadTar(char *url, char *destina
 

	
 

	
 
int uploadOutput(char *pathtoOutput, char *urltoOutput, int jobnum, int framenum, int slavekey){
 
  //fprintf(stderr,"Uploading output %s to url %s for job %d and frame %d for slavekey %d", pathtoOutput, urltoOutput, jobnum, framenum, slavekey);
 
  if( !curlpost(pathtoOutput, urltoOutput, jobnum, framenum, slavekey)) // Uploads output
 
    {
 
      fprintf(stderr,"Upload successful, removing old output...\n");
 
@@ -472,20 +482,26 @@ int unpackJob(char *outdir, char *pathto
 
}
 

	
 

	
 
void prepareJobPaths(int jobnum, int framenum, char *outputExt, char *datadir, char **urltoTar,char **pathtoTar,char **pathtoTardir,char **pathtoJob, char **pathtoJobfile,char **urltoOutput,char **pathtoOutput, char **pathtoOutdir)
 
void prepareJobPaths(int jobnum, int framenum, char *outputExt, char *datadir, char **urltoTar,char **pathtoTar,char **pathtoTardir,char **pathtoJob, char **pathtoJobfile, char **urltoJobfile, char **urltoOutput,char **pathtoOutput, char **pathtoRenderOutput, char **pathtoOutdir)
 
{
 
  // Variable Preparation
 
  char *jobdatapath;
 
   _distren_asprintf(&jobdatapath, "job%d", jobnum);
 
   _distren_asprintf(urltoTar, "http://data.distren.org/job%d/job%d.tar.gz", jobnum, jobnum); // Prepares URL to download from
 
   _distren_asprintf(urltoJobfile, "http://data.distren.org/job%d/job.blend", jobnum); // Prepares URL to download from
 

	
 
   _distren_asprintf(pathtoTar, "%s/%s/job%d.tar.gz", datadir, jobdatapath, jobnum); // Prepares destination to save to
 

	
 
   _distren_asprintf(pathtoTardir, "%s/%s/", datadir, jobdatapath); // Prepares destination to save to
 

	
 
   _distren_asprintf(pathtoJob, "%s/%s/", datadir, jobdatapath);
 

	
 
   _distren_asprintf(pathtoJobfile, "%s/%s/job.blend", datadir, jobdatapath ); // Prepares the path to the jobfile
 
   _distren_asprintf(urltoOutput, "http://distren.org/slaveUpload.php"); // Prepares the URL where output is posted
 
   _distren_asprintf(pathtoOutput, "%s/%s/output/job%d-frame%d.%s", datadir, jobdatapath, jobnum, framenum, outputExt );
 
   _distren_asprintf(urltoOutput, "http://dev.distren.org/slaveUpload.php?jobkey=%d&framekey=%d",jobnum,framenum); // Prepares the URL where output is posted
 

	
 
   _distren_asprintf(pathtoRenderOutput, "%s/%s/output/job%d-frame#.%s", datadir, jobdatapath, jobnum, outputExt ); // Note: the # is for blender to put in framenum in output file
 
   _distren_asprintf(pathtoOutput, "%s/%s/output/job%d-frame%d.%s", datadir, jobdatapath, jobnum, framenum, outputExt ); // Note: the # is for blender to put in framenum in output file
 

	
 
   _distren_asprintf(pathtoOutdir, "%s/%s/output", datadir, jobdatapath);
 
   free(jobdatapath);
 
}
 
@@ -584,6 +600,28 @@ void slaveTest(char *datadir)
 
   }
 
}
 

	
 
/*
 
int runBenchmark(int slavekey, char *datadir){
 
  // Execute blender
 

	
 
  if(exec_blender(pathtoJobfile, pathtoOutput, framenum))
 
    {
 
      fprintf(stderr,"Error running Blender. Check your installation and/or your PATH.\n");
 
      _web_resetframe(slavekey, password, jobnum, framenum);  // Unassign the frame on the server so other slaves can render it
 
      return 1;
 
    }
 
  free(pathtoJobfile);
 

	
 
  struct stat buffer;
 
  int fstatus = stat(pathtoOutput, &buffer);
 
  if(fstatus == -1){
 
    fprintf(stderr,"*** Frame was not rendered correctly! Scene may not have camera, or your blender installation is not working.\n");
 
    _web_resetframe(slavekey, password, jobnum, framenum);  // Unassign the frame on the server so other slaves can render it
 
    return 1;
 
  }
 

	
 
}
 
*/
 

	
 
/* simpleSlave functions */
 

	
 
@@ -659,7 +697,7 @@ void _web_finishframe(int slavekey, char
 
}
 

	
 
void _web_resetframe(int slavekey, char *slavepass, int jobnum, int framenum){
 
  fprintf(stderr,"Resetting frame %d in job %d on server...",framenum,jobnum);
 
  fprintf(stderr,"Resetting frame %d in job %d on server... ",framenum,jobnum);
 
  char *url;
 
  _distren_asprintf(&url,"http://dev.distren.org/slave/act.php?mode=resetframe&slavekey=%d&slavepass=%s&jobnum=%d&framenum=%d", slavekey, slavepass, jobnum, framenum);
 
  struct _web_memorystruct data = _web_getrequest(url);
src/server/slavefuncs.h
Show inline comments
 
@@ -49,7 +49,7 @@ int job_build_path(char *filename, unsig
 
int downloadTar(char *url, char *destinationPath);
 
int uploadOutput(char *pathtoOutput, char *urltoOutput, int jobnum, int framenum, int slavekey);
 
int unpackJob(char *outdir, char *pathtoTar);
 
void prepareJobPaths(int jobnum, int framenum, char *outputExt, char *datadir, char **urltoTar,char **pathtoTar,char **pathtoTardir,char **pathtoJob, char **pathtoJobfile,char **urltoOutput,char **pathtoOutput, char **pathtoOutdir);
 
void prepareJobPaths(int jobnum, int framenum, char *outputExt, char *datadir, char **urltoTar,char **pathtoTar,char **pathtoTardir,char **pathtoJob, char **pathtoJobfile,char **urltoJobfile,char **urltoOutput,char **pathtoOutput, char **pathtoRenderOutput, char **pathtoOutdir);
 
int checkUsername(char *username);
 
void slaveTest();
 

	
0 comments (0 inline, 0 general)