Changeset - c44707a801aa
[Not reviewed]
default
0 1 0
ethanzonca - 16 years ago 2009-07-06 18:02:19

Commenting, removed some lux stuff so we can focus on blender. We really need to clean up.
1 file changed with 105 insertions and 133 deletions:
0 comments (0 inline, 0 general)
src/server/distrend.c
Show inline comments
 
@@ -26,48 +26,40 @@
 
 * Upload while rendering
 
 */
 

	
 

	
 
#include <stdio.h>
 
#include "execio.h"
 

	
 
// needs to be implemented
 
#include "options.h"
 

	
 
#include <confuse.h>
 

	
 
#define max 100
 
// maximum number of stored jobs in memory, per job type (lux/blend). Eventually we can dump this data to disk, or atleast the remainder not in memory...
 
#define max 100 // maximum number of stored jobs in memory, per job type (lux/blend). Eventually we can dump this data to disk, or atleast the remainder not in memory...
 

	
 
int jobnum = 0;
 

	
 
int hcfjob; //highest consecutively finished job
 
int hcfjob; // Highest consecutively finished job
 

	
 
int highest_jobnum; // The job number of the most recently created job, this is used when creating new jobs
 

	
 
// Structures for storing job information
 
// OOOOOOkay so we really need a struct for frameset rather than just an array, because we should track who each frame was sent out to. Please do this, someone! :D
 
struct {
 
  char *name;
 
  char *submitter;
 
  char *email;
 
  int priority;  // 1 is lowest, 10 is highest, 0 is done
 
  int percent_done;
 
  int completed_frames; // number of completed frames
 
  int assigned_frames; // number of assigned frames (that are not yet completed)
 
  int total_frames; // how many frames are in the animation
 
  struct frameset **frameset;
 

	
 
  struct frameset **frameset; // What exactly is this now? hehe
 

	
 
  // Ok... what's going on with using these??? --ethanzonca
 
  int frame_num[];
 
  char slave_name[][];
 
  short int frame_status[];
 
  // For secondary upload location...
 
  char url;
 
  char login_name;
 
  char login_pass;
 

	
 
} blendjob[max];
 

	
 
/*
 
// -- Matthew's handywork --
 
// struct for storing information on each frame for a particular blender job
 
struct {
 
@@ -76,23 +68,12 @@ struct {
 
	int frame_status; // status of frame, 0= unassigned, 1= taken, 2= done
 
} frameset[]; // Frameset array is generated by status_report_generator function
 
                         // Using this method to save memory, because if animation starts on a high frame number, it would waste a lot of RAM on empty structures
 
// -- end of Matthew's handywork --
 
*/
 

	
 
struct {
 
  char *name;
 
  char *submitter;
 
  char *email;
 
  int priority;
 
  int mode; // 0 = Static Render, stop at Spp, or infinity if spp is null. Framerange is ignored || 1 = animation, stop at Spp and stay in framerange.
 
  int spp;
 
  struct frameset ** frameset;
 
} luxjob[max];
 

	
 

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

	
 
// I'm assuming this is a non-working framework :)
 
	int distrend_do_config(int argc, char *argv[], struct distrend_config *config)
 
	{
 
@@ -153,118 +134,35 @@ struct distrend_config
 

	
 
  struct distrend_listen **listens; /*< Null terminated array of structs */
 

	
 
}
 

	
 

	
 
/* Notes on Registration:
 
We need to generate a key in registeruser() that is returned to the client.
 
How will we transfer the key?
 
*/
 

	
 
// Registration on server. Needs attention. Prevent account spamming.
 
// Set up something like: distrend -c username email@example.com
 
void registeruser(char *username, char *email){
 
  // Logs into sandboxed user on zserver2 and registers a user. Should eventually generate a key on the server and return it to the user.
 
  // All created user accounts should be sandboxed accordingly, requiring a different skel, and the default shell to be rbash. Also,
 
  // a custom path defined in the .bash_profile of the skel is needed.
 
  char buf[10];
 
  struct execio *testrem;
 
  char *execargv[] =
 
    {
 
  "ssh",
 
  "distren_setup@protofusion.org",
 
  "-i",
 
  "setup.rsa", // default distributed key, account can only create users.
 
  "-p",
 
  "23",
 
  "sudo /usr/sbin/useradd",
 
  "-M",
 
  "-c",
 
  email,
 
  "-d",
 
  "/home/distren",
 
  "--gid",
 
  "541", // Add in shellscript to generate ssh key and return it to the user somehow
 
  username,
 
  (char *)NULL
 
  };
 
  size_t readlen;
 
  fprintf(stderr, "Opening stream:\n", execio_open(&testrem, "ssh", execargv));
 
  buf[9] = '\0'; // null-terminating the array...
 
  while(!execio_read(testrem, buf, 9, &readlen)) // What's with the readlen stuff?
 
    {
 
      if(readlen > 9) {
 
	fprintf(stderr, "!!!! Something is terribly wrong!\n");
 
      }
 
      if(buf == 0) {
 
	fprintf(stderr, "Make this throw a successfull message if no output is returned... maybe");
 
      }
 
    buf[readlen] = '\0'; // Null-terminating the end of it again based on how large the data is?
 
    fprintf(stderr, "read \"%s\"\n", buf);
 
    }
 
  execio_close(testrem);
 
}
 

	
 

	
 

	
 

	
 

	
 
void loginuser(char *username, int secret){
 
  // Logs into sandboxed user on zserver2 as a client, currently does nothing
 
  char buf[10];
 
  struct execio *testrem;
 
  char *execargv[] =
 
    {
 
  "ssh",
 
  "username@protofusion.org", // username must be read from the conf
 
  "-i",
 
  "username.rsa", // Key created from registeruser()
 
  "-p",
 
  "23",
 
  "echo",
 
  "hello", // This should eventually open a non-terminating connection to the server for communication
 
  (char *)NULL
 
  };
 
  size_t readlen;
 
  fprintf(stderr, "Opening stream:\n", execio_open(&testrem, "ssh", execargv));
 
  buf[9] = '\0'; // null-terminating the array...
 
  while(!execio_read(testrem, buf, 9, &readlen)) // What's with the readlen stuff?
 
    {
 
      if(readlen > 9) {
 
	fprintf(stderr, "!!!! Something is terribly wrong!\n");
 
      }
 
      if(buf == 0) {
 
	fprintf(stderr, "Put stuff here-ish to check whether the operation(s) were successful.");
 
      }
 
    buf[readlen] = '\0'; // Null-terminating the end of it again based on how large the data is?
 
    fprintf(stderr, "read \"%s\"\n", buf);
 
    }
 
  execio_close(testrem);
 
}
 

	
 

	
 

	
 

	
 

	
 

	
 

	
 

	
 

	
 
/*
 
 frame[frame] Assignments:
 
  "NULL" - don't render me
 
  "0" - cancelled
 
  "1" - unassigned
 
  "2" - assigned to slave
 
  "3" - completed by slave and uploaded
 
 Have a script crawl through each job in the arrays, ordered by priority?, and assign a certain number of frames to each slave.
 
 Then we will need some sort of watchdog to monitor slaves on the main server to check for stales.
 

	
 
 Have a script crawl through each job in the arrays, priority-biased, and assign a frame to each slave.
 
 Then we will need some sort of watchdog to monitor slaves on the main server to check for stales. Maybe not worry about this for now.
 
*/
 

	
 

	
 
/* -- Coding using OLD FRAMESET STRUCTURE... temporarily saving it!! --
 
/* -- Coding using OLD FRAMESET STRUCTURE... temporarily saving it!! -- :: Normaldotcom glances at lordofwar with a concerned look...
 
// This function creates frame array based on the total number of frames to be rendered, which will then be parsed by function frame_farmer.
 
void frame_num_struct_builder(int sframe, int eframe) {
 
	int jobnum_new = highest_jobnum + 1;
 
	int total = (sframe - eframe) +1;  // total number of frames
 
	int fcount = sframe; // Used to create all the frames in the structure from sframe to eframe
 
	int x = 0;
 
@@ -433,12 +331,15 @@ your_frame = blendjob[jobnum].frame_num[
 
if(your_frame = null)  // If that job had no open frames for some reason, run the status report generator so that
 
	status_report_generator();  //the job priority can be changed to 0
 

	
 
return your_frame; // your_frame is returned as the frame to be rendered
 
}
 

	
 

	
 

	
 

	
 
// This figures out how much of the job is done, where jobnum corresponds to the job number
 
// This uses pointers, so when it is run it updates certain values in memory
 
void status_report_generator(){
 

	
 
	while(blendjob[(hcfjob+1)].priority = 0)  //If the job after the highest consecutively finished job is finished
 
		hcfjob+1;  // adds 1 to the highest consecutively finished job and checks the next one, till the job after the hcfjob is not done
 
@@ -515,42 +416,113 @@ jobnum++;
 

	
 

	
 

	
 

	
 

	
 
/*
 
Slave execution code lies below
 
 * --------------------------------------------------------------------
 
 * Slave code resides below.
 
 *
 
 * Slave listens on server for a command in the format of each function...
 
 * We need if's for returns... ==> watchdog
 
*/
 

	
 

	
 

	
 

	
 
Slave listens on server for a command in the format of each function...
 
We need if's for returns... ==> watchdog
 
*/
 
// Registration on server. Needs attention. Prevent account spamming.
 
// Key transfer?
 
// Set up something like: distrend -c username email@example.com
 
void registeruser(char *username, char *email){
 
  // Logs into sandboxed user on zserver2 and registers a user. Should eventually generate a key on the server and return it to the user.
 
  // All created user accounts should be sandboxed accordingly, requiring a different skel, and the default shell to be rbash. Also,
 
  // a custom path defined in the .bash_profile of the skel is needed.
 
  char buf[10];
 
  struct execio *testrem;
 
  char *execargv[] =
 
    {
 
  "ssh",
 
  "distren_setup@protofusion.org",
 
  "-i",
 
  "setup.rsa", // default distributed key, account can only create users.
 
  "-p",
 
  "23",
 
  "sudo /usr/sbin/useradd",
 
  "-M",
 
  "-c",
 
  email,
 
  "-d",
 
  "/home/distren",
 
  "--gid",
 
  "541", // Add in shellscript to generate ssh key and return it to the user somehow
 
  username,
 
  (char *)NULL
 
  };
 
  size_t readlen;
 
  fprintf(stderr, "Opening stream:\n", execio_open(&testrem, "ssh", execargv));
 
  buf[9] = '\0'; // null-terminating the array...
 
  while(!execio_read(testrem, buf, 9, &readlen)) // What's with the readlen stuff?
 
    {
 
      if(readlen > 9) {
 
	fprintf(stderr, "!!!! Something is terribly wrong!\n");
 
      }
 
      if(buf == 0) {
 
	fprintf(stderr, "Make this throw a successfull message if no output is returned... maybe");
 
      }
 
    buf[readlen] = '\0'; // Null-terminating the end of it again based on how large the data is?
 
    fprintf(stderr, "read \"%s\"\n", buf);
 
    }
 
  execio_close(testrem);
 
}
 

	
 

	
 

	
 

	
 

	
 
void loginuser(char *username, int secret){
 
  // Logs into sandboxed user on zserver2 as a client, currently does nothing
 
  char buf[10];
 
  struct execio *testrem;
 
  char *execargv[] =
 
    {
 
  "ssh",
 
  "username@protofusion.org", // username must be read from the conf
 
  "-i",
 
  "username.rsa", // Key created from registeruser()
 
  "-p",
 
  "23",
 
  "echo",
 
  "hello", // This should eventually open a non-terminating connection to the server for communication
 
  (char *)NULL
 
  };
 
  size_t readlen;
 
  fprintf(stderr, "Opening stream:\n", execio_open(&testrem, "ssh", execargv));
 
  buf[9] = '\0'; // null-terminating the array...
 
  while(!execio_read(testrem, buf, 9, &readlen)) // What's with the readlen stuff?
 
    {
 
      if(readlen > 9) {
 
	fprintf(stderr, "!!!! Something is terribly wrong!\n");
 
      }
 
      if(buf == 0) {
 
	fprintf(stderr, "Put stuff here-ish to check whether the operation(s) were successful.");
 
      }
 
    buf[readlen] = '\0'; // Null-terminating the end of it again based on how large the data is?
 
    fprintf(stderr, "read \"%s\"\n", buf);
 
    }
 
  execio_close(testrem);
 
}
 

	
 

	
 

	
 

	
 

	
 
// Executors
 

	
 
void exec_blender(char *input, char *output, int frame) {
 
  int ret;
 
  /* SEGFAULTAGE :-D */
 
  char *cmd[] = { "blender", "-b", "-o", output, input, "-f", frame, (char *)0 };
 
  ret = execv("/usr/bin/blender", cmd);
 

	
 
  // OHNOBINKI! ... check this... Its supposed to send a command back to the server and run the_finisher(); function which sets the frame status to complete.
 
  fprintf(stdin, the_finisher(frame));
 

	
 
void exec_luxrender_single(char *input, char *output) {
 
  int ret;
 
  char *cmd[] = { "luxrender", "-something", "something", "something", (char *)0 };
 
  ret = execv("/usr/bin/luxrender", cmd);
 
}
 

	
 
void exec_luxrender_anim(char *input, char *output, int sframe, int eframe, int spp) {
 
// spp is samples per pixel limitation on each frame
 
  int ret;
 
  char *cmd[] = { "luxrender", "-something", "something", "something", (char *)0 };
 
  ret = execv ("/usr/bin/luxrender", cmd);
 
}
 

	
 

	
 

	
 
  return 0;
 
}
0 comments (0 inline, 0 general)