Changeset - 8489c0f926e6
[Not reviewed]
Merge default
0 2 0
ethanzonca - 16 years ago 2009-08-08 15:17:00

2 files changed with 83 insertions and 91 deletions:
0 comments (0 inline, 0 general)
configure.ac
Show inline comments
 
@@ -42,13 +42,13 @@ AC_TYPE_PID_T
 
AC_TYPE_SIZE_T
 

	
 
#package dependencies:
 

	
 
PKG_PROG_PKG_CONFIG(0.17.2)
 

	
 
PKG_CHECK_MODULES(DISTLIBS, libconfuse >= 2.6 libcurl)
 
PKG_CHECK_MODULES(DISTLIBS, libconfuse >= 2.6 libcurl libxml-2.0)
 
PKG_CHECK_MODULES([CHECK], [check >= 0.9.4])
 

	
 
AC_DEFINE_DIR([SYSCONFDIR], [sysconfdir], [Directory to find configuration files in])
 

	
 
AC_CONFIG_FILES([Makefile
 
src/Makefile
src/server/distrend.c
Show inline comments
 
@@ -89,17 +89,17 @@ struct distrend_config
 

	
 
 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.
 
*/
 

	
 
struct general_info {
 
	short int jobs_in_queue; //
 
	unsigned short int free_clients;
 
	unsigned short int rendering_clients;//
 
	unsigned short int total_finished_jobs; //
 
	unsigned int total_frames_rendered; //
 
  short int jobs_in_queue; //
 
  unsigned short int free_clients;
 
  unsigned short int rendering_clients;//
 
  unsigned short int total_finished_jobs; //
 
  unsigned int total_frames_rendered; //
 
} general_info;
 

	
 

	
 

	
 
/*
 
  internally defined funcs's prototypes
 
@@ -128,30 +128,30 @@ int distrend_do()
 
}
 
/**
 
   Accepts a client's connection
 
 */
 
void distrend_accept()
 
{
 
  
 

	
 
}
 
/**
 
   Frees the action 
 
   Frees the action
 
*/
 
void distrend_action_free()
 
{
 
  
 

	
 
}
 
/**
 
   Start listening
 
*/
 
void distrend_listen()
 
{
 

	
 
}
 
/**
 
   Stop listening 
 
   Stop listening
 
*/
 
void distrend_unlisten()
 
{
 

	
 
}
 
/**
 
@@ -160,36 +160,35 @@ void distrend_unlisten()
 
void remotio_send_to_client()
 
{
 
	// I am futile!
 
}
 
/** Fill variables after crash / shutdown from XML dumps */
 
void start_data(){
 

	
 
	if(1 == 0){
 
		// retrieve total_finished_jobs and total_finished_frames from xml file
 
	}
 
	else{
 
		general_info.total_finished_jobs = 0;
 
		general_info.total_frames_rendered = 0;
 
	}
 
  if(1 == 0){
 
    // retrieve total_finished_jobs and total_finished_frames from xml file
 
  }
 
  else{
 
    general_info.total_finished_jobs = 0;
 
    general_info.total_frames_rendered = 0;
 
  }
 
}
 

	
 
// **** Finish-Setter: Sets a frame to the "completed" status.
 
/** Finish-Setter: Sets a frame to the "completed" status.*/
 
void finish_frame(struct blendjob *blendjob, int frame){
 
  blendjob->frameset[frame].status = 2;
 
  blendjob->frameset[frame].time_to_render = (clock() - blendjob[jobnum].frameset[frame].start_time); // Consider changing time-to-render to time-for-frame or something?
 

	
 
  general_info.total_frames_rendered++; // Increase total frames var for stats
 
}
 

	
 

	
 
// **** Queuer: Adds files to the queue
 
/** Queuer: Adds files to the queue */
 
void queue(struct blendjob *blendjob, int type, char *name, char *submitter, char *email, int priority, int mode, int spp, struct frameset *frameset) {
 
	// Type: 1 = blender, add more types later
 
	// jobnum is the next available job number
 
	if(type == 1){
 
  // Type: 1 = blender, add more types later
 
  // jobnum is the next available job number
 
  if(type == 1){
 
    blendjob->name = name;
 
    blendjob->submitter = submitter;
 
    blendjob->email = email;
 
    blendjob->priority = priority;
 
    blendjob->frameset = frameset;
 
  }
 
@@ -290,29 +289,29 @@ void status_report_generator(struct blen
 
    } /* while(blendjob_ptr) */
 

	
 
  general_info.jobs_in_queue = (highest_jobnum - general_info.total_finished_jobs); /*< extraneous parentheses! */
 
}
 

	
 

	
 
// **** Structure Builder: This function creates frame array based on the total number of frames to be rendered, which will then be parsed by function frame_farmer.
 
/** Structure Builder: 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(struct blendjob *job, unsigned int startframe, unsigned int numframes) {
 
  int jobnum_new = highest_jobnum + 1; /* global vars will someday leave us  */
 
  unsigned int counter;
 

	
 
	job->frameset = malloc(sizeof(struct frameset) * numframes);
 
	if(!job->frameset)
 
	  fprintf(stderr, "error allocating memory");
 
  job->frameset = malloc(sizeof(struct frameset) * numframes);
 
  if(!job->frameset)
 
    fprintf(stderr, "error allocating memory");
 

	
 
	job->total_frames = numframes; // sets the total number of frames in animation for status purposes
 
	job->jobnum = jobnum_new;
 
  job->total_frames = numframes; // sets the total number of frames in animation for status purposes
 
  job->jobnum = jobnum_new;
 

	
 
	for(counter = 0; counter < numframes; counter ++)
 
	  /* This builds the array, with the array starting at zero and the frameset.num starting at sframe */
 
	  job->frameset[counter].num = counter + startframe;
 
  for(counter = 0; counter < numframes; counter ++)
 
    /* This builds the array, with the array starting at zero and the frameset.num starting at sframe */
 
    job->frameset[counter].num = counter + startframe;
 

	
 
	highest_jobnum++; // After it has created the job, it adds one to the highest_jobnum interger
 
  highest_jobnum++; // After it has created the job, it adds one to the highest_jobnum interger
 
}
 

	
 

	
 

	
 
/**
 
  Frame Finder: matches your computer up with a lovely frame to render
 
@@ -335,47 +334,47 @@ int frame_finder(struct blendjob *head, 
 

	
 
  found = 0;
 
  while(!found)
 
    {
 
      /* enumerate through priority levels */
 
      for(priority = 10;
 
	  priority > 0
 
	    && !found;
 
	  priority --)
 
        priority > 0
 
            && !found;
 
           priority --)
 
	/* Find the job with the highest priority */
 
	for(blendjob_ptr = head;
 
	    blendjob_ptr != NULL
 
	      && !found;
 
	    blendjob_ptr = blendjob_ptr->next)
 
	  if(blendjob_ptr->priority == priority)
 
        for(blendjob_ptr = head;
 
            blendjob_ptr != NULL
 
            && !found;
 
            blendjob_ptr = blendjob_ptr->next)
 
          if(blendjob_ptr->priority == priority)
 
	    found = 1;
 

	
 
      if(!found)
 
	{
 
	  fprintf(stderr, "out of jobs to render\n");
 
	  return 1;
 
	}
 
        {
 
          fprintf(stderr, "out of jobs to render\n");
 
          return 1;
 
        }
 

	
 
      found = 0;
 
      for(your_frame = 0;
 
	  your_frame < blendjob_ptr->total_frames;
 
	  your_frame ++)
 
	if(blendjob_ptr->frameset[your_frame].status == 0)
 
	  found = 1;
 
        your_frame < blendjob_ptr->total_frames;
 
        your_frame ++)
 
        if(blendjob_ptr->frameset[your_frame].status == 0)
 
          found = 1;
 

	
 
      if(!found)
 
	{
 
	  /* there are no frames left in this job */
 
	  blendjob_ptr->priority --;
 
        {
 
          /* there are no frames left in this job */
 
          blendjob_ptr->priority --;
 

	
 
	  /* If that job had no open frames for some reason, run the status report generator so that */
 
	  status_report_generator(&head);
 
          status_report_generator(&head);
 

	
 
	  /* should the job be removed now? */
 
	  fprintf(stderr, "Job %d is finished, this is probably the place to call the job-removal function\n", blendjob_ptr->jobnum);
 
	}
 
          /* should the job be removed now? */
 
          fprintf(stderr, "Job %d is finished, this is probably the place to call the job-removal function\n", blendjob_ptr->jobnum);
 
        }
 
    } /* while(!found) */
 

	
 
  fprintf(stderr, "Missing apostrophe !!!!!!!!!!!!!!\n"); abort();
 
  /* sets the value of the frame to 1, which means its taken !!!!!! MISSSING APOSTROPHE!!!!!!! */
 
  blendjob_ptr->frameset[your_frame].status++;
 

	
 
@@ -384,12 +383,13 @@ int frame_finder(struct blendjob *head, 
 
  *job = blendjob_ptr;
 
  *frame =  &blendjob_ptr->frameset[your_frame];
 

	
 
  return 0;
 
}
 

	
 
/** Checks for dying slaves */
 
void blend_frame_watchdog(struct blendjob *blendjob_head)
 
{
 
  unsigned short int watchdog_forgiveness; /*< seconds to wait on a frame before re-assigning it */
 
  struct blendjob *blendjob_ptr;
 
  unsigned int counter;
 

	
 
@@ -399,18 +399,18 @@ void blend_frame_watchdog(struct blendjo
 
  for(blendjob_ptr = blendjob_head; blendjob_ptr; blendjob_ptr = blendjob_ptr->next)
 
    /* iterate through jobs */
 

	
 
    for(counter = 0; counter < blendjob_ptr->total_frames; counter ++)
 
      /* iterate through all frames for this job*/
 
      {
 
	if((blendjob_ptr->frameset[counter].start_time + (watchdog_forgiveness * 3600)) < clock())
 
	  /*
 
	    If frame is not completed within the number of hours specified by watchdog_forgiveness
 
	    Then change the frame status to unassigned
 
	  */
 
	  blendjob_ptr->frameset[counter].status = 0;
 
        if((blendjob_ptr->frameset[counter].start_time + (watchdog_forgiveness * 3600)) < clock())
 
          /*
 
            If frame is not completed within the number of hours specified by watchdog_forgiveness
 
            Then change the frame status to unassigned
 
           */
 
          blendjob_ptr->frameset[counter].status = 0;
 
      }
 

	
 
}
 

	
 
/**
 
   Finds a blendjob struct based on the jobnum
 
@@ -423,13 +423,13 @@ struct blendjob *blendjob_get(struct ble
 

	
 
  /*
 
    The conditions of the for loop will leave blendjob_ptr at NULL if the end of the list is reached. It will leave it pointing to the correct job if it is found.
 
   */
 
  for(blendjob_ptr = head;
 
      blendjob_ptr
 
	&& blendjob_ptr->jobnum != jobnum;
 
        && blendjob_ptr->jobnum != jobnum;
 
      blendjob_ptr = blendjob_ptr->next);
 

	
 
  return blendjob_ptr;
 
}
 

	
 

	
 
@@ -445,15 +445,15 @@ void blendjob_remove(struct blendjob **h
 
  if(bj == *head)
 
    *head = bj->next;
 
  else
 
    {
 

	
 
      for(previous_blendjob = *head;
 
	  previous_blendjob
 
	    && previous_blendjob->next != bj; /*< stop on the blendjob that comes before bj */
 
	  previous_blendjob = previous_blendjob->next)
 
        previous_blendjob
 
          && previous_blendjob->next != bj; /*< stop on the blendjob that comes before bj */
 
          previous_blendjob = previous_blendjob->next)
 
	/* all of the action is in the definition of the for loop itself */;
 

	
 
      /*
 
	This removes references to bj from the linked list. I.E., we now skip bj when iterating through the list
 
       */
 
      previous_blendjob->next = bj->next;
 
@@ -479,49 +479,51 @@ int distrend_do_config(int argc, char *a
 
      CFG_SIMPLE_INT("port", NULL),
 
      CFG_END()
 
    };
 
  cfg_opt_t myopts[] =
 
    {
 
      CFG_SEC("listen",  /* this must be imported into struct listens (which must still be declared) */
 
	      myopts_listen,
 
	      CFGF_MULTI),
 
          myopts_listen,
 
          CFGF_MULTI),
 
      CFG_SIMPLE_STR("datadir", NULL),
 
      CFG_END()
 
    };
 
  
 

	
 
  fprintf(stderr, "%s:%d running config\n", __FILE__, __LINE__);
 

	
 
  *config = malloc(sizeof(struct distrend_config));
 
  myopts[1].simple_value = &(*config)->datadir;
 
  
 

	
 
  options_init(argc, argv, &(*config)->mycfg, myopts, "server", &(*config)->options);
 

	
 
  fprintf(stderr, "using %s as datadir\n", (*config)->datadir); 
 
  
 
  fprintf(stderr, "using %s as datadir\n", (*config)->datadir);
 

	
 
  return 0;
 
}
 
int distrend_config_free(struct distrend_config *config)
 
{
 
  options_free(config->options);
 
  free(config);
 
  
 

	
 
  return 0;
 
}
 
// End non-working framework?
 

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

	
 
  /* TODO: Put some arg-grabbing code here */
 
  /* @TODO: Put some arg-grabbing code here */
 

	
 
  struct blendjob *head;
 

	
 
  int cont;
 
  struct distrend_listenset *listenset;
 
  struct distrend_config *config;
 

	
 
  start_data(); // Starts fresh or loads data from xml dump
 

	
 
  enum clientstatus
 
  {
 
    CLIENTSTATUS_UNINITIALIZED = 0,
 
    CLIENTSTATUS_BUSY = 1,
 
    CLIENTSTATUS_IDLE = 2
 
  } clientstatus;
 
@@ -538,50 +540,40 @@ int main(int argc, char *argv[])
 
      struct distren_action *action;
 
      int clientsays; /*< temporary example variable, will be replaced when we can handle messages */
 

	
 
      distrend_accept(&action);
 
      cont = distrend_do(action);
 

	
 

	
 
      /* Somewhat Pseudo-code for basic server operation, should be more event-driven */
 

	
 
      start_data();
 
      /* Make the following code more event-driven */
 
      status_report_generator(&head);
 
      blend_frame_watchdog(head);
 

	
 

	
 
      struct frameset *frame;
 
      struct blendjob *job;
 

	
 
      /* If the client is idle (meaning a client without the "busy" status connected via ssh), all clients should be idle by default. */
 
      /* If the client is idle, must be modified for climbing through linked list of clients (client->clientnum) */
 
      if(clientstatus == CLIENTSTATUS_IDLE)
 
	{
 
	  /**
 
	      normaldotcom: learn about ``return by pointer''
 
	  */
 
	  int returnnum = frame_finder(head, &job, &frame); // give framefinder args, framefinder should return job number and frame number somehow
 
	  int returnnum = frame_finder(head, &job, &frame); // Finds a frame to render
 
	  if(returnnum)
 
	    {
 
	      fprintf(stderr,"No frames are available to render at this time");
 
	      fprintf(stderr,"No frames are available to render at this time. Idling...\n");
 
	      sleep(10);
 
	    }
 
	  else
 
	    /* returnnum == 0 */
 
	    remotio_send_to_client(frame->num, job->jobnum); // Did you actually make this function, ohnobinki? --normaldotcom
 
	    remotio_send_to_client(frame->num, job->jobnum); // Pseudo-sends data to client
 
	}
 

	
 
      /* If the client states that they finished the frame */
 
      	if(clientsays == DISTREN_REQUEST_DONEFRAME){
 
      		clientstatus = CLIENTSTATUS_IDLE; // Sets the client back to idle
 
      		// finish_frame(jobnum, framenumprevious); // make it finish the previous frame or something, why framenumprevios? Is that the whole linked list thing coming in?
 
      		finish_frame(head, jobnum); // @TODO: update so it fits the purpose of the previous line
 
      	  clientstatus = CLIENTSTATUS_IDLE; // Sets the client back to idle
 
      	  finish_frame(head, frame->num); // @TODO: Check that finish_frame really gets the jobnum somehow
 
      	}
 

	
 
      /* End Somewhat Pseudo-code */
 

	
 

	
 
      distrend_action_free(action);
 
    }
 

	
 
  distrend_unlisten(listenset);
 
  distrend_config_free(config);
 

	
0 comments (0 inline, 0 general)