#ifndef ZENTIFIC_TYPES_H #define ZENTIFIC_TYPES_H /* default priorities for each job type */ #define JOBPRIORITY_IMMEDIATE 10 #define JOBPRIORITY_HIGH 5 #define JOBPRIORITY_DEFAULT 3 #define JOBPRIORITY_LOW 1 /* relative execution speed estimations */ #define JOBSPEED_SLOW 10 #define JOBSPEED_DEFAULT 5 #define JOBSPEED_FAST 1 /* status of the execution of a job */ #define JOBSTATUS_INSERTED 0 #define JOBSTATUS_FETCHED 1 #define JOBSTATUS_ENQUEUED 2 #define JOBSTATUS_EXECUTING 3 #define JOBSTATUS_COMPLETED 4 #define JOBSTATUS_CANCELLED 5 #include "zentific/adts.h" /** * Describes a job action to perform. * * The priority can be provided in the database or left NULL. If it is NULL, then it is assumed to * be JOBPRIORITY_DEFAULT. The only exceptions to this are the "cancel" job, which is always a * priority JOBPRIORITY_IMMEDIATE, and a "domain_update" job, which is also a JOBPRIORITY_IMMEDIATE. * These two are executed right away because they affect other jobs that may have been ahead of them * in the execution queue. */ typedef struct t_zJob { /* describes the job as it is listed in the database */ int id; /* a unique identifier for this job (only needs to be unique to the source) */ struct t_zJobSource *source; /* identifies which source the job came from. Used for write-backs */ int runtype; /* 0 = normal job, 1 = scheduled one-time job, 2 = scheduled, repeating job */ int priority; /* one of the JOBPRIORITY defines from above */ char domU[38]; /* UUID of target DomU with dashes */ char dom0[38]; /* UUID of target Dom0 with dashes */ char host[16]; /* IP address with periods */ char extra[256]; /* other job-related data */ /* describes which job type will handle the execution */ char jobtype_class[32]; char jobtype_name[256]; /* describes the job as it is executing */ unsigned int pid; /* PID of the job while it is executing */ unsigned int time_started; /* UNIX timestamp */ unsigned int status; /* Job Status */ int return_value; /* value returned from the execution */ void* jobtype; /* job type structure to use in executing the job */ /** WARNING: These two are deprecated and will be removed in future versions. Write new * jobtypes off of the "addon" jobtype pattern (see jobtypes/addon/README.txt) */ char *jobtype_string; /* string for the action to execute in shell (if needed). Unparsed. */ int jobtype_speed; /* options are JOBSPEED_SLOW, JOBSPEED_DEFAULT, or JOBSPEED_FAST */ /* used to lock the job when we need to modify properties */ sem_t mutex; } zJob; /** * Defines all of the necessary information for a job source */ typedef struct t_zJobSource { /* reference to the library descriptor to unload in the end */ void *library; /* configuration data provided by init call */ void *config; /* initialize function that is called during preparation */ void *(*init)(void); /* fetch function to call each time there is a new job */ int (*fetch)(void *, struct t_zList*, int, struct t_zJobSource*); /* update function to call when a job has changed */ int (*update)(void *, struct t_zJob*); /* uninit function call when exiting */ int (*uninit)(void *); } zJobSource; /** * Represents a physical machine */ typedef struct t_zDom0 { int id; char *uuid; char *hostname; //char uuid[37]; //char hostname[256]; // flags to keep track of jobs int busy; struct z_job *current_job; // list of VMs running on this domain struct zList *vms; } zDom0; /** * Represents a virtual machine */ typedef struct t_zDomU { int id; // char uuid[37]; // char name[256]; char *uuid; char *name; zDom0 *dom0; } zDomU; /** * Defines the wrapper API for Internal job types. */ typedef struct t_zInternalJobType { /* name of the module. Based on file name */ char name[256]; /* reference to the descriptor that the module loaded from */ void *library; /* configuration data provided by init call */ void *config; /* initialization function. Called once */ void *(*init)(void); /* execute a job. Actual signature is: * * int zJob_Execute(void *config, zList *run_list, zList *thread_list, zJob *job) */ int (*execute)(void *, zList *, zList *, zJob *); /* describes how long the execution is expected to take. Used for scheduling purposes */ int (*speed)(void *, zJob*); /* cleanup function. Called once when exiting */ int (*uninit)(void *); } zInternalJobType; /** * Defines the wrapper API for Addon job types. */ typedef struct t_zAddonJobType { /* Name of the module. Based on file name. */ char name[256]; /* reference to the descriptor that the module loaded from */ void *library; /* configuration data provided by init call */ void *config; /* initialization function. Called once */ void *(*init)(void); /* execute a job. Actual signature is: * * int zJob_Execute(void *config, zJob *job) */ int (*execute)(void *, zJob *); /* describes how long the execution is expected to take. Used for scheduling purposes */ int (*speed)(void *, zJob*); /* cleanup function. Called once when exiting */ int (*uninit)(void *); } zAddonJobType; /** * Represents a worker thread in the list of workers */ typedef struct t_zWorker { /* ID of the thread that this represents */ pthread_t thread_id; /* Job currently being executed by this thread */ zJob *current_job; } zWorker; /** * Loads all internal job types and calls their initialization scripts. Returns a list of * zInternalJobType variables. * * Returns NULL if there was an error. */ zList *z_InitInternalJobTypes(); /** * Loads all addon job types and calls their initialization scripts. Returns a list of * zInternalJobType variables. * * Returns NULL if there was an error. */ zList *z_InitAddonJobTypes(); /** * Unloads all sources via their uninit functions. Works on both internal and */ int z_UninitJobTypes(zList *jobtypes); /** * Executes a job */ int z_ExecuteJob(zJob *job, zList *internalList, zList *addonList, zList* runList, zList* threadList); /** * Calculate the estimated execution speed of a job */ int z_JobSpeed(zJob *job, zList *addonList, zList *internalList); #endif // ZENTIFIC_TYPES_H