Changeset - d231345767d5
[Not reviewed]
default
0 4 0
Ethan Zonca (ethanzonca) - 15 years ago 2010-09-13 17:04:23
e@ethanzonca.com
Added output extension and resolution support in render calls and _web calls, breaks slave.c
4 files changed with 52 insertions and 15 deletions:
0 comments (0 inline, 0 general)
distrensimpleslave-init
Show inline comments
 
@@ -7,17 +7,17 @@
 
# processname: distrensimpleslave
 

	
 
# Source function library
 
. /etc/rc.d/init.d/functions
 

	
 
prog="DistRen SimpleSlave"
 
process="distrensimpleslave"i
 
process="distrensimpleslave"
 
args=""
 

	
 
logfile="/var/log/distrensimpleslave"
 
binary="/usr/bin/distrensimpleslave $args 2>$logfile &"
 
binary="/usr/local/bin/distrensimpleslave $args 2>$logfile &"
 
lockfile="/var/lock/subsys/distrensimpleslave"
 

	
 
start() {
 
        echo -n $"Starting $prog: "
 
        daemon $binary
 
        touch $lockfile
src/server/simpleslave.c
Show inline comments
 
@@ -152,12 +152,14 @@ if(updateConf){
 
      return 1;
 
    }
 

	
 
  // Variables needed for main loop
 
  int jobnum = 0;
 
  int framenum = 0;
 
  int xres = 0;
 
  int yres = 0;
 
  int slavekey = atoi(username); // @TODO: Make this more friendly
 

	
 
  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;
 

	
 
@@ -207,13 +209,13 @@ if(updateConf){
 
  while(!quit)
 
    {
 

	
 
    // request work
 
    if(DEBUG)
 
      fprintf(stderr,"Requesting work from %s...\n", hostname);
 
    haveWork = _web_getwork(slavekey, password, &jobnum, &framenum);
 
    haveWork = _web_getwork(slavekey, password, &jobnum, &framenum, &xres, &yres, outputExt);
 

	
 
    /* If we got a frame */
 
    if(haveWork)
 
      {
 
        fprintf(stderr,"\nGot work from server...\n");
 
        if(DEBUG)
 
@@ -274,14 +276,13 @@ if(updateConf){
 

	
 
        /* Execute blender */
 
        if(DEBUG){
 
          fprintf(stderr,"Executing blender on file %s\n", pathtoJobfile);
 
          fprintf(stderr,"Directing output to file %s\n", pathtoOutput);
 
        }
 

	
 
        if(exec_blender(pathtoJobfile, pathtoRenderOutput, framenum))
 
        if(exec_blender(pathtoJobfile, pathtoRenderOutput, outputExt, xres, yres, 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);
src/server/slavefuncs.c
Show inline comments
 
@@ -31,12 +31,13 @@
 
#include <curl/easy.h>
 
#include <curl/types.h>
 

	
 
#include <archive.h>
 
#include <archive_entry.h>
 

	
 
#include <ctype.h>
 
#include <errno.h>
 
#include <stdio.h>
 
#include <string.h>
 
#include <unistd.h>
 
#include <stdlib.h>
 
#include <sys/stat.h>
 
@@ -45,12 +46,17 @@
 
#include <time.h>
 

	
 
// Function debug
 
#define DEBUG 0
 

	
 

	
 
void stringToUpper(char *string){
 
  while(*string != '\0') {
 
    *string = toupper((unsigned char)*string);
 
  }
 
}
 

	
 
/**
 
   Grabs the xml DOM node reached by an XPath.
 

	
 
   @param path an XPath that lead to DOM node
 
   @return the first node associated with the path or NULL if there is no match
 
@@ -255,20 +261,29 @@ return 1; // Success
 
}
 

	
 

	
 
/* Executors */
 

	
 
/** Executor function for Blender operations */
 
int exec_blender(char *input, char *output, int frame)
 
int exec_blender(char *input, char *output, char *outputExt, int xres, int yres, int frame)
 
{
 
  int ret;
 

	
 
  stringToUpper(outputExt);
 

	
 
  char *frame_str;
 
  _distren_asprintf(&frame_str, "%i", frame);
 

	
 
  char *xres_str;
 
  _distren_asprintf(&xres_str, "%i", xres);
 

	
 
  char *yres_str;
 
  _distren_asprintf(&yres_str, "%i", yres);
 

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

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

	
 
  char buf[20];
 
  struct execio *testrem;
 
@@ -646,49 +661,69 @@ void _web_startframe(int slavekey, char 
 
  if(DEBUG)
 
    fprintf(stderr,"%s\n", data.memory);
 
  if(data.memory)
 
    free(data.memory);
 
}
 

	
 
int _web_getwork(int slavekey, char *slavepass, int *jobnum, int *framenum){
 
/** @TODO: Needs to get xres, yres, outpuext */
 
int _web_getwork(int slavekey, char *slavepass, int *jobnum, int *framenum, int *xres, int *yres, char *outputext){
 
  char *url;
 
  _distren_asprintf(&url,"http://distren.org/slave/act.php?mode=getwork&slavekey=%d&slavepass=%s", slavekey, slavepass);
 
  struct _web_memorystruct data = _web_getrequest(url);
 
  free(url);
 

	
 
  if(!data.memory || !strcmp(data.memory,",")){
 
    fprintf(stderr,"*** No work available on server! In other news, really weird things are happening. Check it out. You shouldn't be seeing this.\n");
 
    return 0;
 
  }
 
  else if(!strcmp(data.memory, "ERROR_BADKEY")){
 
    fprintf(stderr,"*** Slave %d does not exist!\n",slavekey);
 
    fprintf(stderr,"*** Slave %d does not exist! Check your slave ID, or register your slave on distren.org\n",slavekey);
 
    free(data.memory);
 
    return 0;
 
  }
 
  else if(!strcmp(data.memory, "ERROR_NORENDERPOWER")){
 
    fprintf(stderr,"*** Render power not set! Please invoke distrensimpleslave -r to run the benchmark!\n",slavekey);
 
    fprintf(stderr,"*** Render power not set! Please invoke distrensimpleslave -r to run the benchmark!\n");
 
    free(data.memory);
 
    return 0;
 
  }
 
  // Compare to PACKAGE_VERSION
 
  else{
 
    char *tmp;
 
    char *serverversion;
 

	
 
    tmp = strtok (data.memory,",,");
 
    if(tmp != NULL){ // make sure work is available
 
      *jobnum = atoi(tmp);
 
    if(tmp != NULL) { // make sure work is available
 
      *jobnum = atoi(tmp); // Grab jobnum
 

	
 
      tmp = strtok (NULL, ",");
 
      if(tmp == NULL)
 
        return 0; // no work
 
      *framenum = atoi(tmp);
 
      *framenum = atoi(tmp); // Grab framenum
 

	
 
      tmp = strtok (NULL, ",");
 
      if(tmp == NULL)
 
        return 0; // no work
 
      serverversion = tmp;
 

	
 
      tmp = strtok (NULL, ",");
 
      if(tmp == NULL)
 
        return 0; // no work
 
      *xres = atoi(tmp);
 

	
 
      tmp = strtok (NULL, ",");
 
      if(tmp == NULL)
 
        return 0; // no work
 
      *yres = atoi(tmp);
 

	
 
      tmp = strtok (NULL, ",");
 
      if(tmp == NULL)
 
        return 0; // no work
 
      outputext = tmp;
 

	
 
      // @FIXME: Setting outputext and serverversion = temp; will this cause issues as these are pointers to parts of the original temp var?
 

	
 
      // @TODO: This should be called every time, not just on fail.
 
      if(strcmp(PACKAGE_VERSION,serverversion)){
 
        fprintf(stderr,"Your distren package is out of date! Please acquire a newer version. (%s local vs %s remote)\n", PACKAGE_VERSION, serverversion);
 
        return 0;
 
      }
 
      if(DEBUG)
src/server/slavefuncs.h
Show inline comments
 
@@ -27,25 +27,26 @@
 
#include <curl/curl.h>
 
#include <libxml/xpath.h>
 
#include <stdio.h>
 

	
 

	
 
struct msg;
 
void stringToUpper(char *string);
 
int sendSignal(struct remoteio *rem, char signal);
 
int sendExtSignal(struct remoteio *rem, char signal, char *data);
 
xmlNodePtr xml_quickxpath(xmlXPathContextPtr xpathctxt, xmlChar *path);
 
int software_updatecheck();
 
int delete_jobdata(int jobnum, char *datadir);
 
size_t curl_writetodisk(void *ptr, size_t size, size_t nmemb, FILE *stream);
 
CURLcode curlget(char *url, char *out);
 
CURLcode curlpost(char *filename, char *url, int jobnum, int framenum, int slavekey);
 
int ssh_keygen();
 
int register_user(char *username, char *email);
 
int login_user(char *username);
 
int conf_replace(char *conffile, char *wordtoreplace, char *replacewith);
 
int exec_blender(char *input, char *output, int frame);
 
int exec_blender(char *input, char *output, char *outputExt, int xres, int yres, int frame);
 
void xmlinit();
 
void xmlcleanup();
 
int distren_mkdir_recurse(const char *dirname);
 
int job_build_path(char *filename, unsigned int jobnum);
 
int downloadTar(char *url, char *destinationPath);
 
int uploadOutput(char *pathtoOutput, char *urltoOutput, int jobnum, int framenum, int slavekey);
 
@@ -69,13 +70,13 @@ struct _web_memorystruct;
 
void *_web_myrealloc(void *ptr, size_t size);
 
size_t _web_writememorycallback(void *ptr, size_t size, size_t nmemb, void *data);
 
struct _web_memorystruct _web_getrequest(char *url);
 
void _web_finishframe(int slavekey, char *slavepass, int jobnum, int framenum);
 
void _web_startframe(int slavekey, char *slavepass, int jobnum, int framenum);
 
void _web_resetframe(int slavekey, char *slavepass, int jobnum, int framenum);
 
int _web_getwork(int slavekey, char *slavepass, int *jobnum, int *framenum);
 
int _web_getwork(int slavekey, char *slavepass, int *jobnum, int *framenum, int *xres, int *yres, char *outputext);
 
void _web_setrenderpower(int slavekey, char *slavepass, int renderpower);
 
int slaveBenchmark(char *datadir, int *benchmarkTime, int *renderPower);
 

	
 

	
 

	
 
#endif
0 comments (0 inline, 0 general)