FOSSology  4.4.0
Open Source License Compliance by Open Source Software
job.c File Reference

Job handling operations. More...

#include <libfossrepo.h>
#include <agent.h>
#include <database.h>
#include <job.h>
#include <scheduler.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <glib.h>
#include <gio/gio.h>
Include dependency graph for job.c:

Go to the source code of this file.

Macros

#define TEST_NULV(j)   if(!j) { errno = EINVAL; ERROR("job passed is NULL, cannot proceed"); return; }
 
#define TEST_NULL(j, ret)   if(!j) { errno = EINVAL; ERROR("job passed is NULL, cannot proceed"); return ret; }
 
#define MAX_SQL   512;JOB_STATUS_TYPES
 
#define SELECT_STRING(passed)   MK_STRING_LIT(JOB_##passed),
 

Functions

static int is_active (int *job_id, job_t *job, int *counter)
 Tests if a job is active. More...
 
static int job_sstatus (int *job_id, job_t *job, GOutputStream *ostr)
 Prints the jobs status to the output stream. More...
 
static void job_transition (scheduler_t *scheduler, job_t *job, job_status new_status)
 
static gint job_compare (gconstpointer a, gconstpointer b, gpointer user_data)
 Used to compare two different jobs in the priority queue. More...
 
job_tjob_init (GTree *job_list, GSequence *job_queue, char *type, char *host, int id, int parent_id, int user_id, int group_id, int priority, char *jq_cmd_args)
 Create a new job. More...
 
void job_destroy (job_t *job)
 
void job_verbose_event (scheduler_t *scheduler, job_t *job)
 
void job_status_event (scheduler_t *scheduler, arg_int *params)
 Event to get the status of the scheduler or a specific job. More...
 
void job_pause_event (scheduler_t *scheduler, arg_int *params)
 Event to pause a job. More...
 
void job_restart_event (scheduler_t *scheduler, arg_int *params)
 
void job_priority_event (scheduler_t *scheduler, arg_int *params)
 
void job_fail_event (scheduler_t *scheduler, job_t *job)
 Events that causes a job to be marked a failed. More...
 
void job_add_agent (job_t *job, void *agent)
 Adds a new agent to the jobs list of agents. More...
 
void job_remove_agent (job_t *job, GTree *job_list, void *agent)
 
void job_finish_agent (job_t *job, void *agent)
 
void job_fail_agent (job_t *job, void *agent)
 
void job_set_data (scheduler_t *scheduler, job_t *job, char *data, int sql)
 
void job_update (scheduler_t *scheduler, job_t *job)
 
int job_is_open (scheduler_t *scheduler, job_t *job)
 Tests to see if there is still data available for this job. More...
 
char * job_next (job_t *job)
 
log_tjob_log (job_t *job)
 
job_tnext_job (GSequence *job_queue)
 Gets the next job from the job queue. More...
 
job_tpeek_job (GSequence *job_queue)
 Gets the job that is at the top of the queue if there is one. More...
 
uint32_t active_jobs (GTree *job_list)
 Gets the number of jobs that are not paused. More...
 

Variables

const char * job_status_strings [] = { JOB_STATUS_TYPES(SELECT_STRING) }
 

Detailed Description

Job handling operations.

Definition in file job.c.

Macro Definition Documentation

◆ SELECT_STRING

#define SELECT_STRING (   passed)    MK_STRING_LIT(JOB_##passed),

Array of C-Strings used to pretty-print the job status in the log file. Uses the X-Macro defined in job.h

Definition at line 44 of file job.c.

Function Documentation

◆ active_jobs()

uint32_t active_jobs ( GTree *  job_list)

Gets the number of jobs that are not paused.

Parameters
job_listThe list to check
Returns
number of non-paused jobs

Definition at line 720 of file job.c.

◆ is_active()

static int is_active ( int *  job_id,
job_t job,
int *  counter 
)
static

Tests if a job is active.

If the job is active, the integer pointed to by counter will be incremented by 1. This is used when determining if the scheduler can shutdown and will be called from within a g_tree_foreach().

Parameters
job_idThe id number used as the key in the Gtree
jobThe job that is being tested for activity
counterThe count of the number of active jobs
Returns
always returns 0

Definition at line 60 of file job.c.

◆ job_add_agent()

void job_add_agent ( job_t job,
void *  agent 
)

Adds a new agent to the jobs list of agents.

When a job is created it doesn't contain any agents that can process its data. When an agent is ready, it will add itself to the job using this function and begin processing the jobs data.

Parameters
jobthe job that the agent will be added to
agentthe agent to add to the job

Definition at line 434 of file job.c.

◆ job_compare()

static gint job_compare ( gconstpointer  a,
gconstpointer  b,
gpointer  user_data 
)
static

Used to compare two different jobs in the priority queue.

This simply compares their priorities so that jobs with a high priority are scheduler before low priority jobs.

Parameters
aThe first job
bThe second job
user_dataunused
Returns
The comparison of the two jobs

Definition at line 135 of file job.c.

◆ job_destroy()

void job_destroy ( job_t job)

Free the memory associated with a job. In addition to the job needing to be freed, the job owns the data associated with it so this must also free that information.

Parameters
jobthe job to free

Definition at line 201 of file job.c.

◆ job_fail_agent()

void job_fail_agent ( job_t job,
void *  agent 
)

Moves a job from the running agent list to the failed agent list.

Parameters
jobThe job that the agent belong to
agentThe agent to move the failed list

Definition at line 493 of file job.c.

◆ job_fail_event()

void job_fail_event ( scheduler_t scheduler,
job_t job 
)

Events that causes a job to be marked a failed.

This really only needs to call the job_transition function with JB_FAILED as that will change the job's status in the database.

Parameters
schedulerRelated scheduler structure
jobThe job that has failed

Definition at line 406 of file job.c.

◆ job_finish_agent()

void job_finish_agent ( job_t job,
void *  agent 
)

Moves an agent from the running agent list to the finished agent list.

Parameters
jobThe job to change
agentThe agent to move

Definition at line 478 of file job.c.

◆ job_init()

job_t* job_init ( GTree *  job_list,
GSequence *  job_queue,
char *  type,
char *  host,
int  id,
int  parent_id,
int  user_id,
int  group_id,
int  priority,
char *  jq_cmd_args 
)

Create a new job.

Every different task will create a new job and as a result the job will only deal with one type of agent. This is important because if an agent fails when processing data from a job, that job might need to create a new agent to deal with the data.

Parameters
job_listThe list of all jobs, the job will be added to this list
job_queueThe job queue, the job must be added to this for scheduling
typeThe type of agent that will be created for this job
hostThe name of the host that this job will execute on
idThe id number for the job in the database
parent_idThe parent id for the job in the database (queue)
user_idThe id of the user that created the job
group_idThe id of the group that created the job
priorityThe priority of the job, this is just a Linux process priority
jq_cmd_argsCommand line arguments
Returns
the new job

Definition at line 164 of file job.c.

◆ job_is_open()

int job_is_open ( scheduler_t scheduler,
job_t job 
)

Tests to see if there is still data available for this job.

Parameters
scheduler
jobthe job to test
Returns
if the job still has data available

Definition at line 570 of file job.c.

◆ job_log()

log_t* job_log ( job_t job)

Gets the log file for the particular job. If the job hasn't had anything to log yet, this will create the file from the repository and then return it.

Parameters
jobthe job to get the file for
Returns
the FILE* to print the job's log info

Definition at line 637 of file job.c.

◆ job_next()

char* job_next ( job_t job)

Gets the next piece of data that should be analyzed, if there is no more data to analyze, this will return NULL;

Parameters
jobthe job to get the data for
Returns
a pointer to the next block of data or NULL

Definition at line 610 of file job.c.

◆ job_pause_event()

void job_pause_event ( scheduler_t scheduler,
arg_int params 
)

Event to pause a job.

This event is created by the interface and like the job status event uses the pair to pass multiple things to a event function.

Parameters
schedulerthe scheduler this event was called on
paramsthe job_t* and a boolean CLI or UI

Definition at line 312 of file job.c.

◆ job_priority_event()

void job_priority_event ( scheduler_t scheduler,
arg_int params 
)

Event to change the priority of job. This is only called by the interface. This event uses the pair to pass multiple things to an event function.

Parameters
schedulerthe scheduler this event was called on
paramsthe job and its new priority

Definition at line 385 of file job.c.

◆ job_remove_agent()

void job_remove_agent ( job_t job,
GTree *  job_list,
void *  agent 
)

Removes an agent from a jobs list of agents, if a job no longer has any agents in any of it lists, this will then remove the job from the system.

Parameters
jobthe job to remove the agent from
job_listthe list of all available jobs
agentthe agent to remove from the job

Definition at line 449 of file job.c.

◆ job_restart_event()

void job_restart_event ( scheduler_t scheduler,
arg_int params 
)

Event to restart a paused job. This is called by the interface.

Parameters
schedulerThe scheduler this event was called on
paramsThe job that will be restarted

Definition at line 342 of file job.c.

◆ job_set_data()

void job_set_data ( scheduler_t scheduler,
job_t job,
char *  data,
int  sql 
)

Sets the data that a job should be working on. Currently runonpfile is not implemented, so sql will always be true.

Parameters
schedulerScheduler containing database connection, used for runonpfile
jobthe job to set the data for
datathe data that the job should be processing
sqlcurrently, always false
Todo:
runonpfile is not implemented

Definition at line 511 of file job.c.

◆ job_sstatus()

static int job_sstatus ( int *  job_id,
job_t job,
GOutputStream *  ostr 
)
static

Prints the jobs status to the output stream.

The output will be in this format: job:<id> status:<status> type:<agent type> priority:<priority> running:<# running> finished:<#finished> failed:<# failed>

Parameters
job_idthe id number that the job was created with
Note
if the int pointed to by the job_id is value 0, that means print all agent status as well
Parameters
jobthe job itself
ostrthe output stream to write everything to
Returns
always returns 0

Definition at line 80 of file job.c.

◆ job_status_event()

void job_status_event ( scheduler_t scheduler,
arg_int params 
)

Event to get the status of the scheduler or a specific job.

This is only generated by the interface receiving a status command. The parameter for this function is a little odd since the function needs 2 parameters, but is an event, so can only be passed 1. Because of this, the parameter is a pair, the first is always the g_output_stream to write the status to. The second is either 0 (scheduler status) or the jq_pk of the job that the status was requested for (job status).

Parameters
schedulerthe scheduler this event is called on
paramsthe g_output_stream and possibly the jq_pk of the job

Definition at line 266 of file job.c.

◆ job_transition()

static void job_transition ( scheduler_t scheduler,
job_t job,
job_status  new_status 
)
static

Changes the status of the job and updates the database with the new job status

Parameters
schedulerThe scheduler that this job belongs to
jobThe job to update the status on
new_statusthe new status for the job

Definition at line 109 of file job.c.

◆ job_update()

void job_update ( scheduler_t scheduler,
job_t job 
)

Updates the status of the job. This will check the status of all agents that belong to this job and if the job has finished or all of the agents have fail

Parameters
scheduler
job

Definition at line 531 of file job.c.

◆ job_verbose_event()

void job_verbose_event ( scheduler_t scheduler,
job_t job 
)

Causes the job to send its verbose level to all of the agents that belong to it.

Parameters
schedulerThe scheduler to job belongs to
jobUpdate all verbose levels on the agents of this job

Definition at line 244 of file job.c.

◆ next_job()

job_t* next_job ( GSequence *  job_queue)

Gets the next job from the job queue.

If there isn't a waiting in the job queue this will return NULL.

Parameters
job_queueThe queue to get job from
Returns
the job or NULL

Definition at line 681 of file job.c.

◆ peek_job()

job_t* peek_job ( GSequence *  job_queue)

Gets the job that is at the top of the queue if there is one.

Parameters
job_queueThe queue to get job from
Returns
the job at the top of the job queue, NULL if queue is empty

Definition at line 701 of file job.c.