Changeset - 99a5a69d493c
[Not reviewed]
default
0 6 0
ethanzonca - 16 years ago 2009-12-11 11:25:00
ez@ethanzonca.com
Initial remotio calls and helper functions
6 files changed with 46 insertions and 21 deletions:
0 comments (0 inline, 0 general)
etc/distrendaemon.conf
Show inline comments
 
/*
 
 configuration for _this_ server
 
*/
 
daemon
 
{
 
  datadir = "/home/ohnobinki/var/distren"
 
  datadir = "/home/ethanzonca/var/distren"
 
  render_types = {"povray", "blender", "inkscape", "imagemagick", "dcraw"}
 
}
 

	
 
include("distrencommon.conf")
 

	
 

	
 
listen {
 
       type = "unix"
 
       path = "/home/ohnobinki/var/run/distrend.sock"
 
       path = "/home/ethanzonca/var/run/distrend.sock"
 
       port = "0770"
 
}
etc/distrenslave.conf
Show inline comments
 
slave
 
{
 
  username = "!username"
 
  datadir = "/home/ohnobinki/var/distren"
 
  datadir = "/home/ethanzonca/var/distren"
 
}
 

	
 
include("distrencommon.conf")
src/common/protocol.h
Show inline comments
 
@@ -57,8 +57,9 @@ enum distren_request_type
 
    /**
 
       server->server
 
    */
 
    DISTREN_REQUEST_RENDERFRAME = 8,
 
    DISTREN_REQUEST_DONEFRAME = 9,
 
    DISTREN_REQUEST_PROGRESS = 10, /*< tells another server of the progress of the first server's work at rendering */
 
    DISTREN_REQUEST_GETWORK = 11,
 

	
 
  };
src/server/slave.c
Show inline comments
 
@@ -27,15 +27,16 @@
 
#include <stdio.h>
 
#include <stdlib.h>
 
#include <string.h>
 
#include <sys/stat.h>
 
#include <unistd.h>
 

	
 

	
 

	
 
int main(int argc, char *argv[])
 
{
 

	
 
  char curopt;
 
  char *username;
 

	
 
  while(-1 != (curopt = getopt(argc, argv, "u:h")))
 
     {
 
       if(curopt == ':')
 
@@ -111,22 +112,32 @@ int main(int argc, char *argv[])
 
  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; /* Structures for remotio */
 
  struct remoteio_opts *comm_slaveoptions;
 

	
 
  fprintf(stderr,"Connecting to server...\n");
 
  remoteio_open(&comm_slave, comm_slaveoptions, "protofusion" );
 

	
 
  int haveWork = 0;
 

	
 
  while(1)
 
    {
 

	
 
    tell_the_server(0); // Give me some work!
 
    // request work
 
    fprintf(stderr,"Requesting work...\n");
 
    sendSignal(comm_slave, DISTREN_REQUEST_GETWORK);
 

	
 
    /* If we got a frame */
 
    if(haveWork)
 
      {
 

	
 
        fprintf(stderr,"Got work from server...\n");
 
        /* @TODO: Add remotio hooks */
 
        // jobnum = remoteio_read(jobnum); /* Set jobnum from remoteio (we could use info from struct, but we need this info to download the xmlfile */
 
        //framenum = remoteio_read(jobnum); /* Set framenum from remoteio */
 

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

	
 
@@ -147,21 +158,21 @@ int main(int argc, char *argv[])
 
            // Download the Tar
 
            if( curlget(urltoTar, pathtoTar) == 0){
 
              fprintf(stderr, "Job data retrieved successfully\n");
 
              free(urltoTar);
 
            }
 
            else {
 
              fprintf(stderr, "Downloading job data from server failed. Check your network connection.\n");
 
              fprintf(stderr, "Downloading job data from %s failed. Check your network connection.\n",urltoTar);
 
              return 1; // Eventually make a retry loop
 
            }
 
          }
 
        else
 
          fprintf(stderr, "Using cached job file...\n");
 

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

	
 
        _distren_asprintf(&tarcmd, "tar -xvf \"%s\" -C \"%s\"", pathtoTar, outdir); /* @TODO:Use a lib here! */
 
        system(tarcmd);
 
        free(tarcmd);
 
        free(pathtoTar);
 
@@ -175,53 +186,56 @@ int main(int argc, char *argv[])
 

	
 
            /* Frees things up if it was successful. xml2distrenjob() really (usually) only fails if malloc'ing inside it fails */
 
            distrenjob_free(&myjob);
 
          }
 
        else
 
          {
 
            fprintf(stderr, "I think the XML craziness may have failed, so I'll terminate just for fun.\n");
 
            fprintf(stderr, "XML job data parsing has failed. Please contact a developer, or try again.\n");
 
            return 1;
 
          }
 

	
 
        /* Variable-fillers which require XML */
 
        outputExt = myjob->output_format;
 
        /* Prepares the path to the jobfile */
 
        _distren_asprintf(&pathtoOutput, "%s/job%d/output/job%d-frame%d.%s", datadir, jobnum, jobnum, framenum, outputExt );
 
        free(outputExt);
 

	
 
        /* Execute blender */
 
        if(exec_blender(pathtoJobfile, pathtoOutput, framenum))
 
          {
 
            fprintf(stderr,"Error running Blender. Check your installation and/or your PATH.");
 
            fprintf(stderr,"Error running Blender. Check your installation and/or your PATH.\n");
 
            return 1;
 
          }
 
        free(pathtoJobfile);
 

	
 
        /* Post-execution */
 
        fprintf(stderr, "Finished frame %d in job %d, uploading...", framenum, jobnum);
 
        fprintf(stderr, "Finished frame %d in job %d, uploading...\n", framenum, jobnum);
 
        if( !curlpost(pathtoOutput, urltoOutput)) // Uploads output
 
          {
 
            fprintf(stderr,"Upload successful, removing old output...\n");
 
            remove(pathtoOutput); // Delete the file after its uploaded
 
          }
 
        else
 
          {
 
            fprintf(stderr,"Upload failed. Check your network connection. Trying again...");
 
            int tries=0;
 
            while(tries<10 && curlpost(pathtoOutput, urltoOutput))
 
            fprintf(stderr,"Upload failed. Check your network connection. Retrying upload...\n");
 
            int tries=1;
 
            while(tries<=10 && curlpost(pathtoOutput, urltoOutput))
 
              {
 
                fprintf(stderr, "Upload failed. Trying again in 10 seconds... (attempt %d of 10)", tries);
 
                fprintf(stderr, "Upload failed. Trying again in 10 seconds... (attempt %d of 10)\n", tries);
 
                tries++;
 
                sleep(10);
 
              }
 
            // @TODO: Keep track of files that we were unable to upload, and upload them later
 
          }
 
        free(urltoOutput);
 
        free(pathtoOutput);
 

	
 
        tell_the_server(DISTREN_REQUEST_DONEFRAME); /* Tells the server that it's done rendering, and upload is done */
 
        // Tell the server that rendering and upload are complete
 
        // sendServer(DISTREN_REQUEST_DONEFRAME);
 
        sendSignal(comm_slave, DISTREN_REQUEST_DONEFRAME);
 

	
 
      }
 
    else
 
      fprintf(stderr,"Nothing to do. Idling...\n");
 

	
 
    // If the server says that every frame for the last jobnum is finished, OR if the data is getting old
 
    if(1 == 0)
 
@@ -230,8 +244,12 @@ int main(int argc, char *argv[])
 
        // except for ones that couldn't be uploaded
 
        delete_jobdata(jobnum, datadir);
 
      }
 

	
 
    sleep(5); // Poll 5 seconds. @TODO: Remove all polling
 
  }
 

	
 
  fprintf(stderr,"Closing connection to server...\n");
 
  remoteio_close(comm_slave);
 

	
 
  return 0;
 
}
src/server/slavefuncs.c
Show inline comments
 
@@ -18,12 +18,13 @@
 
*/
 

	
 
#include "asprintf.h"
 
#include "distrenjob.h"
 
#include "execio.h"
 
#include "protocol.h"
 
#include "remoteio.h"
 
#include "slavefuncs.h"
 

	
 
#include <curl/curl.h>
 
#include <curl/easy.h>
 
#include <curl/types.h>
 

	
 
@@ -32,13 +33,20 @@
 
#include <unistd.h>
 
#include <stdlib.h>
 
#include <sys/stat.h>
 
#include <fcntl.h>
 

	
 

	
 

	
 
// Sends the server a single request (see protocol.h)
 
int sendSignal(struct remoteio *rem, int signal){
 
  size_t written;
 
  char *ssignal;
 
  _distren_asprintf(&ssignal,"%d",signal);
 
  remoteio_write(rem, ssignal, strlen(ssignal), &written);
 
  return 0;
 
}
 
/**
 
 utility function for XPath-ish stuff:
 
 */
 
xmlNodePtr xml_quickxpath(xmlXPathContextPtr xpathctxt, xmlChar *path)
 
{
 
  xmlNodePtr toreturn;
 
@@ -67,16 +75,12 @@ int delete_jobdata(int jobnum, char *dat
 
  _distren_asprintf(&jobpath, "%s/%d", datadir, jobnum);
 
  // rmdir(jobpath);
 
  fprintf(stderr, "Please manually remove %s. Automatic removal is currently not implemented.\n", jobpath);
 
  return 0;
 
}
 

	
 
/** Stub @TODO: Replace with remotio */
 
void tell_the_server(int stuff){
 
}
 

	
 
/** Function referenced by curlget() to write data to disk. */
 
size_t curl_writetodisk(void *ptr, size_t size, size_t nmemb, FILE *stream)
 
 {
 
    return fwrite(ptr, size, nmemb, stream);
 
  }
 

	
src/server/slavefuncs.h
Show inline comments
 
@@ -22,15 +22,17 @@
 

	
 
#include "distrenjob.h"
 

	
 
#include <libxml/xpath.h>
 
#include <stdio.h>
 

	
 

	
 
struct msg;
 
int sendSignal(struct remoteio *rem, int signal);
 
xmlNodePtr xml_quickxpath(xmlXPathContextPtr xpathctxt, xmlChar *path);
 
int software_updatecheck();
 
void tell_the_server(int stuff);
 
int delete_jobdata(int jobnum, char *datadir);
 
size_t curl_writetodisk(void *ptr, size_t size, size_t nmemb, FILE *stream);
 
int curlget(char *url, char *out);
 
int curlpost(char *filename, char *url);
 
int ssh_keygen();
 
int register_user(char *username, char *email);
0 comments (0 inline, 0 general)