FOSSology  4.4.0
Open Source License Compliance by Open Source Software
scheduler.h File Reference

Header file for the scheduler. More...

#include <logging.h>
#include <errno.h>
#include <limits.h>
#include <stdio.h>
#include <stdint.h>
#include <gio/gio.h>
#include <glib.h>
#include <libpq-fe.h>
#include <signal.h>
#include <fossconfig.h>
Include dependency graph for scheduler.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  scheduler_t
 

Macros

#define CHECKOUT_SIZE   100
 
#define AGENT_BINARY   "%s/%s/%s/agent/%s"
 Format to get agent binary.
 
#define AGENT_CONF   "mods-enabled"
 Agent conf location.
 
#define SafePQclear(pgres)   if (pgres) {PQclear(pgres); pgres = NULL;}
 
#define NOOP(val)   val
 
#define CONF_VARIABLES_TYPES(apply)
 
#define SELECT_DECLS(type, name, l_op, w_op, val)   extern type CONF_##name;
 
#define MK_STRING_LIT(passed)   #passed
 

Functions

scheduler_tscheduler_init (gchar *sysconfigdir, log_t *log)
 Create a new scheduler object. More...
 
void scheduler_destroy (scheduler_t *scheduler)
 Free any memory associated with a scheduler_t. More...
 
void scheduler_sig_handle (int signo)
 Handles any signals sent to the scheduler that are not SIGCHLD. More...
 
void scheduler_signal (scheduler_t *scheduler)
 Function that handles certain signals being delivered to the scheduler. More...
 
void scheduler_update (scheduler_t *scheduler)
 Update function called after every event. More...
 
void g_tree_clear (GTree *tree)
 Clears the contents of a GTree. More...
 
gint string_is_num (gchar *str)
 Checks if a string is entirely composed of numeric characters. More...
 
gint string_compare (gconstpointer a, gconstpointer b, gpointer user_data)
 
gint int_compare (gconstpointer a, gconstpointer b, gpointer user_data)
 
void scheduler_config_event (scheduler_t *scheduler, void *)
 Load both the fossology configuration and all the agent configurations. More...
 
void scheduler_close_event (scheduler_t *scheduler, void *)
 Sets the closing flag and possibly kills all currently running agents. More...
 
void scheduler_test_agents (scheduler_t *scheduler, void *)
 Event used when the scheduler tests the agents. More...
 
void scheduler_clear_config (scheduler_t *scheduler)
 Clears any information that is loaded when loading the configuration. More...
 
void scheduler_agent_config (scheduler_t *scheduler)
 Loads a particular agents configuration file. More...
 
void scheduler_foss_config (scheduler_t *scheduler)
 Loads the configuration data from fossology.conf. More...
 
int scheduler_daemonize (scheduler_t *scheduler)
 Daemonizes the scheduler. More...
 
void set_usr_grp (gchar *process_name, fo_conf *config)
 
int kill_scheduler (int force)
 Kills all other running scheduler. More...
 

Variables

int verbose
 The verbose flag for the cli. More...
 
int closing
 Set if scheduler is shutting down.
 
GThread * main_thread
 Pointer to the main thread.
 

Detailed Description

Header file for the scheduler.

Definition in file scheduler.h.

Macro Definition Documentation

◆ CONF_VARIABLES_TYPES

#define CONF_VARIABLES_TYPES (   apply)
Value:
apply(uint32_t, fork_backoff_time, atoi, %d, 5) \
apply(uint32_t, agent_death_timer, atoi, %d, 180) \
apply(uint32_t, agent_update_interval, atoi, %d, 120) \
apply(uint32_t, agent_update_number, atoi, %d, 5) \
apply(gint, interface_nthreads, atoi, %d, 10)

X-Macro used to define variables that can be loaded from the configuration file. To add a new configuration variable, simply add it to this macro and use it in the code.

Current variables: fork_backoff_time => The max time to back off when a call to fork() fails agent_death_timer => The amount of time to wait before killing an agent agent_update_interval => The time between each SIGALRM for the scheduler agent_update_number => The number of updates before killing an agent interface_nthreads => The number of threads available to the interface

For the operation that will be taken when a variable is loaded from the configuration file. You should provide a function or macro that takes a c-string and returns the correct type for assignment to the variable. For any integer types, just provide one of the atoi family of functions. for a string, use the CONF_NOOP macro.

Parameters
applyA macro that is passed to this function. Apply should take 3 arguments. The type of the variable, name of the variable, the operation to apply when loading from the file, the operation to perform when writing the variable to the log file, and the default value.

Definition at line 245 of file scheduler.h.

◆ MK_STRING_LIT

#define MK_STRING_LIT (   passed)    #passed

turns the input into a string literal

Definition at line 258 of file scheduler.h.

◆ NOOP

#define NOOP (   val)    val

If no operation needs to be applied to a configuration variable when it is loaded from the configuration file, use this macro as the operation.

example appearing in the CONF_VARIABLES_TYPES macro: apply(char*, some_variable, NOOP, "some value")

Definition at line 219 of file scheduler.h.

◆ SafePQclear

#define SafePQclear (   pgres)    if (pgres) {PQclear(pgres); pgres = NULL;}

Check if PGresult is not NULL. Then call PQclear and set result as NULL to prevent multiple calls.

Definition at line 129 of file scheduler.h.

◆ SELECT_DECLS

#define SELECT_DECLS (   type,
  name,
  l_op,
  w_op,
  val 
)    extern type CONF_##name;

The extern declaractions of configuration varaibles

Definition at line 253 of file scheduler.h.

Function Documentation

◆ g_tree_clear()

void g_tree_clear ( GTree *  tree)

Clears the contents of a GTree.

Parameters
treethe tree to remove all elements from

Definition at line 721 of file scheduler.c.

◆ int_compare()

gint int_compare ( gconstpointer  a,
gconstpointer  b,
gpointer  user_data 
)

Utility function that enable the agents to be stored in a GTree using the PID of the associated process.

Parameters
aThe pid of the first process
bThe pid of the second process
user_dataunused in this function
Returns
integral value idicating the relationship between the two pids

Definition at line 1074 of file scheduler.c.

◆ kill_scheduler()

int kill_scheduler ( int  force)

Kills all other running scheduler.

Parameters
forceif the scheduler should shutdown gracefully
Returns
0 for success (i.e. a scheduler was killed), -1 for failure.

This uses the /proc file system to find all processes that have fo_scheduler in the name and sends a kill signal to them.

Definition at line 620 of file scheduler.c.

◆ scheduler_agent_config()

void scheduler_agent_config ( scheduler_t scheduler)

Loads a particular agents configuration file.

This loads and saves the results as a new meta_agent. This assumes that the configuration file for the agent includes the following key/value pairs:

  1. command: The command that will be used to start the agent
  2. max: The maximum number of this agent that can run at once
  3. special: Anything that is special about the agent

Definition at line 743 of file scheduler.c.

◆ scheduler_clear_config()

void scheduler_clear_config ( scheduler_t scheduler)

Clears any information that is loaded when loading the configuration.

Parameters
schedulerthe scheduler to reset the information on

Definition at line 671 of file scheduler.c.

◆ scheduler_close_event()

void scheduler_close_event ( scheduler_t scheduler,
void *  killed 
)

Sets the closing flag and possibly kills all currently running agents.

This function will cause the scheduler to slowly shutdown. If killed is true this is a quick, ungraceful shutdown.

Parameters
schedulerthe scheduler
killedshould the scheduler kill all currently executing agents before exiting the event loop, or should it wait for them to finished first.

Definition at line 1014 of file scheduler.c.

◆ scheduler_config_event()

void scheduler_config_event ( scheduler_t scheduler,
void *  unused 
)

Load both the fossology configuration and all the agent configurations.

Parameters
schedulerthe scheduler to load the configuration for
unusedthis can be called as an event

Definition at line 991 of file scheduler.c.

◆ scheduler_daemonize()

int scheduler_daemonize ( scheduler_t scheduler)

Daemonizes the scheduler.

This will make sure that the pid that is maintained in the scheduler struct is correct during the daemonizing process.

Parameters
schedulerthe scheduler_t struct
Returns
if the daemonizing was successful.

Definition at line 973 of file scheduler.c.

◆ scheduler_destroy()

void scheduler_destroy ( scheduler_t scheduler)

Free any memory associated with a scheduler_t.

This will stop the interface if it is currently running, and free all the memory associated with the different regular expression and similar structures.

Parameters
scheduler
Todo:

Interface close

Repo close

Definition at line 362 of file scheduler.c.

◆ scheduler_foss_config()

void scheduler_foss_config ( scheduler_t scheduler)

Loads the configuration data from fossology.conf.

This assumes that fossology.conf contains the following key/value pairs:

  1. port: the port that the scheduler will listen on
  2. LOG_DIR: the directory that the log should be in

There should be a group named HOSTS with all of the hosts listed as key/value pairs under this category. For each of these hosts, the scheduler will create a new host as an internal representation.

Definition at line 853 of file scheduler.c.

◆ scheduler_init()

scheduler_t* scheduler_init ( gchar *  sysconfigdir,
log_t log 
)

Create a new scheduler object.

This will initialize everything to a point where it can be used. All regular expressions, GTree's and the job_queue will be correctly created.

Parameters
sysconfigdirDirectory containing the fossology.conf
logLog file to log messages to
Returns
A new scheduler_t* that can be further populated

Definition at line 249 of file scheduler.c.

◆ scheduler_sig_handle()

void scheduler_sig_handle ( int  signo)

Handles any signals sent to the scheduler that are not SIGCHLD.

Currently Handles:

Signal Effect
SIGCHLD Scheduler will handle to death of the child process or agent
SIGALRM Scheduler will run agent updates and database updates
SIGTERM Scheduler will gracefully shut down
SIGQUIT Scheduler will forcefully shut down
SIGHIP Scheduler will reload configuration data
Parameters
signothe number of the signal that was sent

Definition at line 93 of file scheduler.c.

◆ scheduler_signal()

void scheduler_signal ( scheduler_t scheduler)

Function that handles certain signals being delivered to the scheduler.

This function is called every time the event loop attempts to take something from the event queue. It will also get called once a second regardless of if a new event has been queued.

This function checks the sigmask variable to check what signals have been received since the last time it was called. The sigmask variable should always be accessed atomically since it is accessed by the event loop thread as well as the signal handlers.

Parameters
schedulerScheduler to sent signal to

Definition at line 142 of file scheduler.c.

◆ scheduler_test_agents()

void scheduler_test_agents ( scheduler_t scheduler,
void *  unused 
)

Event used when the scheduler tests the agents.

Parameters
schedulerthe scheduler struct
unused

Definition at line 1029 of file scheduler.c.

◆ scheduler_update()

void scheduler_update ( scheduler_t scheduler)

Update function called after every event.

The heart of the scheduler, the actual scheduling algorithm. This will be passed to the event loop as a call back and will be called every time an event is executed. Therefore the code should be light weight since it will be run very frequently.

Todo:
Currently this will only grab a job and create a single agent to execute the job.
Todo:

Allow for runonpfile jobs to have multiple agents based on size

Allow for job preemption. The scheduler can pause jobs, allow it

Allow for specific hosts to be chosen.

Definition at line 433 of file scheduler.c.

◆ set_usr_grp()

void set_usr_grp ( gchar *  process_name,
fo_conf config 
)

Correctly set the project user and group. The fossology scheduler must run as the user specified by PROJECT_USER and PROJECT_GROUP since the agents must be able to connect to the database. This ensures that that happens correctly.

Parameters
process_name
config

Definition at line 557 of file scheduler.c.

◆ string_compare()

gint string_compare ( gconstpointer  a,
gconstpointer  b,
gpointer  user_data 
)

Utility function that enables the use of the strcmp function with a GTree.

Parameters
aThe first string
bThe second string
user_dataunused in this function
Returns
Integral value indicating the relationship between the two strings

Definition at line 1060 of file scheduler.c.

◆ string_is_num()

gint string_is_num ( gchar *  str)

Checks if a string is entirely composed of numeric characters.

Parameters
strthe string to test
Returns
TRUE if the string is entirely numeric, FALSE otherwise

Definition at line 1041 of file scheduler.c.

Variable Documentation

◆ verbose

int verbose
extern

The verbose flag for the cli.

The verbose flag for the cli.

Definition at line 38 of file fo_cli.c.