Changeset - 14f43a497bd7
[Not reviewed]
default
0 2 0
ethanzonca - 16 years ago 2009-09-05 20:23:15

made start_data() actually do something
2 files changed with 8 insertions and 2 deletions:
0 comments (0 inline, 0 general)
src/server/distrend.c
Show inline comments
 
/*
 
  Copyright 2009 Nathan Phillip Brink, Ethan Zonca, Matthew Orlando
 

	
 
  This file is a part of DistRen.
 

	
 
  DistRen is free software: you can redistribute it and/or modify
 
  it under the terms of the GNU Affero General Public License as published by
 
  the Free Software Foundation, either version 3 of the License, or
 
  (at your option) any later version.
 

	
 
  DistRen is distributed in the hope that it will be useful,
 
  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
  GNU Affero General Public License for more details.
 

	
 
  You should have received a copy of the GNU Affero General Public License
 
  along with DistRen.  If not, see <http://www.gnu.org/licenses/>.
 

	
 
*/
 

	
 
/* This file contains the code which both processes (renders) jobs as a slave, and the code which distributes frames to slaves after receiving them from the client portion of the codebase. */
 

	
 
#include "execio.h"
 
#include "options.h"
 
#include "distrenjob.h"
 
#include "protocol.h"
 
#include "slavefuncs.h"
 

	
 
#include <confuse.h>
 
#include <stdio.h>
 
#include <stdlib.h>
 
#include <malloc.h>
 
#include <unistd.h> /* getopt */
 
#include <time.h>
 

	
 
#include <sys/stat.h>
 

	
 
/* ******************* Structs ************************ */
 

	
 
// Gets config info from confs
 
struct distrend_config
 
{
 
  cfg_t *mycfg;
 
  struct options_common *options;
 
  struct distrend_listen **listens; /*< Null terminated array of structs */
 
  char *datadir;
 
};
 

	
 

	
 

	
 
/*
 
 frame[frame] Status Assignments:
 
  "NULL" - don't render me
 
  "0" - canceled
 
  "1" - unassigned
 
  "2" - assigned to slave
 
  "3" - completed by slave and uploaded
 
*/
 

	
 
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; //
 
} general_info;
 

	
 

	
 

	
 
/*
 
  internally defined funcs's prototypes
 
*/
 
void status_report_generator(struct distrenjob **distrenjobs_head);
 
void distrenjob_remove(struct distrenjob **head, struct distrenjob *bj);
 

	
 
struct distrenjob *distrenjob_get(struct distrenjob *head, jobnum_t jobnum);
 

	
 
/* Global Vars, try to cut down on these */
 
jobnum_t jobnum = 0; // The next job number to create in the queue
 
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
 

	
 

	
 
/* ********************** Functions ************************* */
 

	
 
/**
 
   Performs command stored in a client's request.
 
*/
 
int distrend_do()
 
{
 
  return 0;
 
}
 
/**
 
   Accepts a client's connection
 
 */
 
void distrend_accept()
 
{
 

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

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

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

	
 
}
 
/**
 
   This is probably just a placeholder for remotio
 
*/
 
void remotio_send_to_client()
 
{
 
	// I am futile!
 
}
 

	
 
/** Fill variables after crash / shutdown from XML dumps */
 
int start_data(){
 
  if(1 == 0){
 
  struct stat buffer;
 
  if(stat(SYSCONFDIR "/data.xml", &buffer) == 0){
 
    // retrieve total_finished_jobs and total_finished_frames from xml file
 
    fprintf(stderr,"Parsing XML files and restoring previous state...\n");
 
    return 1;
 
  }
 
  else{
 
    general_info.total_finished_jobs = 0;
 
    general_info.total_frames_rendered = 0;
 
    fprintf(stderr,"Can't find XML dump, starting up fresh.\n");
 
    return 2;
 
  }
 
  free(&buffer); // @TODO: Is this pointless?
 
}
 

	
 
/** Finish-Setter: Sets a frame to the "completed" status.*/
 
void finish_frame(struct distrenjob *distrenjob, int frame){
 
  distrenjob->frameset[frame].status = 2;
 
  distrenjob->frameset[frame].time_to_render = (clock() - distrenjob[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 */
 
int queue(struct distrenjob *distrenjob, 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){
 
    distrenjob->name = name;
 
    distrenjob->submitter = submitter;
 
    distrenjob->email = email;
 
    distrenjob->priority = priority;
 
    distrenjob->frameset = frameset;
 
  }
 
  else{
 
    // Throw error.
 
    fprintf(stderr,"You tried to queue a job type that isn't supported by this version of DistRen.\nI have no idea how this would happen, but it just did.\n");
 
    return 0; // fail
 
  }
 
jobnum++; // Advance the jobnumber for the next queued job
 
return 0; // OK
 
}
 

	
 

	
 
/**
 
  Status Report Generator:
 
  -figures out how much of the job is done, where jobnum corresponds to the job number
 
  -removes finished jobs
 

	
 
  @param distrenjobs_head a pointer to a pointer because the head of the distrenjobs linked list may need to be changed by distrenjob_remove
 
*/
 
void status_report_generator(struct distrenjob **distrenjobs_head)
 
{
 
  struct distrenjob *distrenjob_ptr;
 
  unsigned short workers_working; /*< used to count the total number of workers working */
 
  unsigned int numjobs; /*< used to track number of jobs */
 

	
 
  distrenjob_ptr = *distrenjobs_head;
 
  workers_working = 0;
 
  numjobs = 0;
 

	
src/server/slave.c
Show inline comments
 
@@ -85,98 +85,101 @@ cfg_opt_t myopts[] = {
 
		CFG_SIMPLE_STR("username", &username),
 
		CFG_SIMPLE_STR("datadir", &datadir),
 
		CFG_END()
 
		};
 
struct options_common *commonopts;
 

	
 
username = NULL;
 
options_init(argc,argv,&my_cfg, myopts, "slave", &commonopts);
 
/* End option getter */
 

	
 

	
 
/* Notifies the user if there is no username in the conf file */
 
	if(username == NULL || strcmp(username, "!username") == 0 ){
 
	  fprintf(stderr, "\nYou didn't register!\nPlease register or edit your config. (see -h)\nIf this error persists, check distrenslave.conf to ensure all items are filled.\n");
 
	}
 
	else if( username != NULL || strcmp(username,"!username") != 0 ){
 
		// Logs ya in:
 
		if(login_user(username) == 1){
 
			fprintf(stderr,"You should now be logged into distren.\n");
 
		}
 
		else{
 
			fprintf(stderr,"Login failed. I have no clue why. Sorry.\n");
 
			return 0;
 
		}
 
	}
 
	else{
 
	  fprintf(stderr,"Something is terribly wrong!");
 
	}
 

	
 

	
 

	
 
/* Code-filled Variables  */
 
int jobnum;          // The job number that we're currently working
 
int framenum;        // @TODO: Remotio should fill this
 

	
 
int gotframe;        // set this to 1 after data for a job is received from the server
 
int busy = 0;        // Client business 1=busy 0=idle
 

	
 
char *urltoTar;      // Full URL to the server-side location of job#.tgz
 
char *pathtoTar;     // Full path to the location of the job#.tgz
 

	
 
char *urltoOutput;   // Full URL where output is posted
 
char *pathtoJobfile; // Full path to the job's main file
 
char *pathtoXml;     // Full path to the job's xml file
 
char *pathtoOutput;  // Full path to the output (rendered) file
 
char *outputExt;     // Output Extension (e.g., JPG)
 

	
 
int threads = sysconf(_SC_NPROCESSORS_ONLN); // Equals the number of currently online processors
 
// FOR Win32: int threads = sysinfo.dwNumberOfProcessors;
 

	
 
struct distrenjob *myjob; // Structure to hold data gathered from the XML file
 

	
 

	
 
// If the slave is getting job info...
 
if(gotframe ==1)
 
  {
 
    /* @TODO: fix these remoteio_read's */
 
    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
 

	
 
    char *tarcmd;
 
    char *outdir;
 
    char *jobdatapath;
 

	
 
    fprintf(stderr, "Received %d in job %d, preparing to render...\n",framenum,jobnum);
 

	
 
    /**
 
       Variable Preparation
 
       @todo find where to free() all of these
 
    */
 
    _distren_asprintf(&jobdatapath, "job%d", jobnum);
 
    _distren_asprintf(&urltoTar, "http://protofusion.org/distren/stor/job%d/job%d.tar.gz",jobnum); // Prepares URL to download from
 
    _distren_asprintf(&pathtoTar, "%s/stor/jobdata/job%d.tar.gz", datadir, jobnum); // Prepares destination to save to
 

	
 
    _distren_asprintf(&pathtoJobfile, "%s/%s/job.blend", datadir, jobdatapath ); // Prepares the path to the jobfile
 
    _distren_asprintf(&urltoOutput, "http://protofusion.org/distren/stor/job%d/output/", jobdatapath ); // Prepares the URL where output is posted
 
    _distren_asprintf(&pathtoXml, "%s/job%d/job%d.xml",datadir, jobnum ); // Prepares the path to the job's XML file
 

	
 
      // Downloads the job tar if it isn't  present. @TODO: Delete old job data
 
      struct stat buffer;
 
      int fstatus = stat(pathtoJobfile, &buffer);
 

	
 
      // If stat'ing the jobfile shows that the jobfile doesn't exist, we'll download it.
 
      if(fstatus == -1){
 
              // Downloads the Tar @TODO: add progress bar
 
              if( curlget(urltoTar, pathtoTar) == 0){
 
                fprintf(stderr, "File downloaded without errors\n");
 
              }
 
              else{
 
                fprintf(stderr, "Download tar from server failed. Either the server is down, or the job hosting system is screwed up.\nContact admin@protofusion.org and include this message.\nGoodbye. Better luck next time.\n");
 
              }
 
      }
 
      else{
 
        fprintf(stderr, "Using cached job file...\n");
 
      }
 

	
 
    _distren_asprintf(&outdir, "/tmp/distren/job%d", jobnum); /*< @todo free() */
 
    mkdir("/tmp/distren", 0750); /* @TODO: Make this less *nix-specific */
 
    mkdir(outdir, 0750);
 

	
 
    _distren_asprintf(&tarcmd, "tar -xvf \"%s\" -C \"%s\"", pathtoTar, outdir); /* @TODO: Make this portable. Libtar or something? */
0 comments (0 inline, 0 general)