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

Header file with agent related operations. More...

#include <host.h>
#include <job.h>
#include <scheduler.h>
#include <sys/types.h>
#include <gio/gio.h>
#include <glib.h>
Include dependency graph for agent.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  meta_agent_t
 
struct  agent_t
 

Macros

#define MAX_CMD   1023
 the size of the agent's command buffer (arbitrary)
 
#define MAX_NAME   255
 the size of the agent's name buffer (arbitrary)
 
#define MAX_ARGS   32
 the size of the argument buffer (arbitrary)
 
#define DEFAULT_RET   -1
 default return code (arbitrary)
 
#define LOCAL_HOST   "localhost"
 
#define SAG_NOKILL   (1 << 0)
 This agent should not be killed when updating the agent.
 
#define SAG_EXCLUSIVE   (1 << 1)
 This agent must not run at the same time as any other agent.
 
#define SAG_NOEMAIL   (1 << 2)
 This agent should not send notification emails.
 
#define SAG_LOCAL   (1 << 3)
 This agent should only run on localhost.
 
#define AGENT_STATUS_TYPES(apply)
 
#define SELECT_ENUM(passed)   AG_##passed,
 

Typedefs

typedef int agent_pk
 

Enumerations

enum  agent_status { AGENT_STATUS_TYPES =(SELECT_ENUM) }
 

Functions

meta_agent_tmeta_agent_init (char *name, char *cmd, int max, int spc)
 Creates a new meta agent. More...
 
void meta_agent_destroy (meta_agent_t *meta_agent)
 
agent_tagent_init (scheduler_t *scheduler, host_t *host, job_t *owner)
 Allocate and spawn a new agent. More...
 
void agent_destroy (agent_t *agent)
 Frees the memory associated with an agent. More...
 
void agent_death_event (scheduler_t *scheduler, pid_t *pids)
 
void agent_create_event (scheduler_t *scheduler, agent_t *agent)
 Event created when a new agent has been created. More...
 
void agent_ready_event (scheduler_t *scheduler, agent_t *agent)
 Event created when an agent is ready for more data. More...
 
void agent_update_event (scheduler_t *scheduler, void *unused)
 
void agent_fail_event (scheduler_t *scheduler, agent_t *agent)
 Fails an agent. More...
 
void list_agents_event (scheduler_t *scheduler, GOutputStream *ostr)
 Receive agent on interface. More...
 
void agent_transition (agent_t *agent, agent_status new_status)
 
void agent_pause (agent_t *agent)
 
void agent_unpause (agent_t *agent)
 
void agent_print_status (agent_t *agent, GOutputStream *ostr)
 Prints the status of the agent to the output stream provided. More...
 
void agent_kill (agent_t *agent)
 Unclean kill of an agent. More...
 
int aprintf (agent_t *agent, const char *fmt,...)
 
ssize_t agent_write (agent_t *agent, const void *buf, int count)
 
void test_agents (scheduler_t *scheduler)
 Calls the agent test function for every type of agent. More...
 
int add_meta_agent (GTree *meta_agents, char *name, char *cmd, int max, int spc)
 
void kill_agents (scheduler_t *scheduler)
 Call the agent_kill function for every agent within the system. More...
 
int is_meta_special (meta_agent_t *ma, int special_type)
 tests if a particular meta agent has a specific special flag set More...
 
int is_agent_special (agent_t *agent, int special_type)
 tests if a particular agent has a specific special flag set More...
 
void meta_agent_increase_count (meta_agent_t *)
 
void meta_agent_decrease_count (meta_agent_t *)
 

Variables

const char * agent_status_strings []
 

Detailed Description

Header file with agent related operations.

Definition in file agent.h.

Macro Definition Documentation

◆ AGENT_STATUS_TYPES

#define AGENT_STATUS_TYPES (   apply)
Value:
\
apply(FAILED) \ \
apply(CREATED) \ \
apply(SPAWNED) \ \
apply(RUNNING) \ \
apply(PAUSED) \ \
apply(CLOSED) \

Implementation of x macros used for the creation of the agent status enum. This is used so that if a new agent status is needed, it can be added here and all relevant declarations can be changed.

If you are unfamiliar with X macros, this is a very simply implementation of them and I suggest you look them up online.

Definition at line 50 of file agent.h.

◆ SELECT_ENUM

#define SELECT_ENUM (   passed)    AG_##passed,

Enum to keep track of the state of an agent

Definition at line 65 of file agent.h.

Typedef Documentation

◆ agent_pk

typedef int agent_pk
Todo:

Definition at line 74 of file agent.h.

Function Documentation

◆ add_meta_agent()

int add_meta_agent ( GTree *  meta_agents,
char *  name,
char *  cmd,
int  max,
int  spc 
)

Creates a new meta agent and adds it to the list of meta agents. This will parse the shell command that will start the agent process.

Parameters
meta_agentsGTree of meta agents available for the scheduler
namethe name of the meta agent (e.g. "nomos", "copyright", etc...)
cmdthe shell command used to the run the agent
maxthe max number of this type of agent that can run concurrently
spcanything special about the agent type

Definition at line 1316 of file agent.c.

◆ agent_create_event()

void agent_create_event ( scheduler_t scheduler,
agent_t agent 
)

Event created when a new agent has been created.

This means that the agent has been allocated internally and the fork() call has successfully executed. The agent has not yet communicated with the scheduler when this event is created.

Parameters
schedulerthe scheduler reference to which agent has to attach
agentthe agent that has been created.

Definition at line 1021 of file agent.c.

◆ agent_death_event()

void agent_death_event ( scheduler_t scheduler,
pid_t *  pid 
)

Event created when a SIGCHLD is received for an agent. If one SIGCHILD is received for several process deaths, there will be seperate events for each pid.

Parameters
schedulerthe scheduler reference to which process was attached to
pidthe pid of the process that died

Definition at line 952 of file agent.c.

◆ agent_destroy()

void agent_destroy ( agent_t agent)

Frees the memory associated with an agent.

This include:

  1. All of the files that are open in the agent
  2. All of the pipes still open for the agent
  3. Inform the os that the process can die using a waitpid()
  4. Free the internal data structure of the agent
Parameters
agentthe agent to destroy

Definition at line 924 of file agent.c.

◆ agent_fail_event()

void agent_fail_event ( scheduler_t scheduler,
agent_t agent 
)

Fails an agent.

This will move the agent status to AG_FAILED and send a SIGKILL to the relevant agent. It will also update the agents status within the job that owns it and close the associated communication thread.

Parameters
schedulerthe scheduler to which agent is attached
agentthe agent that is failing.

Definition at line 1102 of file agent.c.

◆ agent_init()

agent_t* agent_init ( scheduler_t scheduler,
host_t host,
job_t job 
)

Allocate and spawn a new agent.

The agent that is spawned will be of the same type as the meta_agent that is passed to this function and the agent will run on the host that is passed.

Parameters
schedulerthe scheduler this agent is being created under
hostthe machine to start the agent on
jobthe job that this agent belongs to

Definition at line 802 of file agent.c.

◆ agent_kill()

void agent_kill ( agent_t agent)

Unclean kill of an agent.

This simply sends a SIGKILL to the agent and lets everything else get cleaned up normally.

Parameters
agentthe agent to kill

Definition at line 1223 of file agent.c.

◆ agent_pause()

void agent_pause ( agent_t agent)

Pauses an agent, this will pause the agent by sending a SIGSTOP to the process and then decrease the load on the host machine.

Parameters
agentthe agent to pause

Definition at line 1164 of file agent.c.

◆ agent_print_status()

void agent_print_status ( agent_t agent,
GOutputStream *  ostr 
)

Prints the status of the agent to the output stream provided.

The formating for this is as such:

`agent:<pid> host:<host> type:<type> status:<status> time:<time>`
Parameters
agentAgent to get info from
ostrStream to write info to

Definition at line 1193 of file agent.c.

◆ agent_ready_event()

void agent_ready_event ( scheduler_t scheduler,
agent_t agent 
)

Event created when an agent is ready for more data.

This will event will be created when an agent first communicates with the scheduler, so this will handle changing its status to AG_RUNNING. This will also be created every time an agent finishes a block of data.

Parameters
schedulerthe scheduler reference to which agent is attached
agentthe agent that is ready

Definition at line 1042 of file agent.c.

◆ agent_transition()

void agent_transition ( agent_t agent,
agent_status  new_status 
)

Changes the status of the agent internal to the scheduler. This function is used to transition between agent states instead of a raw set of the status so that correct printing of the verbose message is guaranteed

Parameters
agentthe agent to change the status for
new_statusthe new status of the agentchar* sysconfdir = NULL; // system configuration directory (SYSCONFDIR)

Definition at line 1136 of file agent.c.

◆ agent_unpause()

void agent_unpause ( agent_t agent)

Unpause the agent, this will send a SIGCONT to the process regardless of if a SIGCONT was sent. If the process wasn't SIGSTOP'd this will do nothing. Also increases the load on the host.

Parameters
agentthe agent to unpause

Definition at line 1177 of file agent.c.

◆ agent_update_event()

void agent_update_event ( scheduler_t scheduler,
void *  unused 
)

Event created when the scheduler receives a SIGALRM. This will loop over every agent and call the update function on it. This will kill any agents that are hung without heart beat or any agents that have stopped updating the number of item processed.

Parameters
schedulerthe scheduler reference to inform
unusedneeded since this an event, but should be NULL

Definition at line 1087 of file agent.c.

◆ agent_write()

ssize_t agent_write ( agent_t agent,
const void *  buf,
int  count 
)

Write information to the communication thread for the agent. This is used when the scheduler needs to wake up or kill the thread used to talk to the agent. When using this function, one should always print "@@@..." where ... is the message that is actually getting sent.

Parameters
agentthe agent to send the information to
bufthe actual data
countthe number of bytes to write to the agent
Returns
returns if the write was successful

Definition at line 1274 of file agent.c.

◆ aprintf()

int aprintf ( agent_t agent,
const char *  fmt,
  ... 
)

Acts as a standard printf, but prints the agents instead of stdout. This is the main function used by the scheduler when communicating with the agents.

Parameters
agentthe agent to send the formated data to
fmtthe formating string for the data
Returns
if the print was successful

Definition at line 1238 of file agent.c.

◆ is_agent_special()

int is_agent_special ( agent_t agent,
int  special_type 
)

tests if a particular agent has a specific special flag set

Parameters
athe agent that should be tested
special_typein what way is the agent special
Returns
true or false

Definition at line 1353 of file agent.c.

◆ is_meta_special()

int is_meta_special ( meta_agent_t ma,
int  special_type 
)

tests if a particular meta agent has a specific special flag set

Parameters
mathe meta agent that should be checked
special_typein what way is the agent special
Returns
true or false

Definition at line 1341 of file agent.c.

◆ kill_agents()

void kill_agents ( scheduler_t scheduler)

Call the agent_kill function for every agent within the system.

This will send a SIGKILL to every child process of the scheduler. Used when shutting down the scheduler.

Definition at line 1301 of file agent.c.

◆ list_agents_event()

void list_agents_event ( scheduler_t scheduler,
GOutputStream *  ostr 
)

Receive agent on interface.

Calls agent_list() and print evert agent attached to the scheduler.

Parameters
schedulerthe scheduler to which agent is attached
ostrStream to write info to

Definition at line 1118 of file agent.c.

◆ meta_agent_decrease_count()

void meta_agent_decrease_count ( meta_agent_t ma)

Decrease the running agent count.

Parameters
maAgent's meta

Definition at line 1372 of file agent.c.

◆ meta_agent_destroy()

void meta_agent_destroy ( meta_agent_t ma)

Free the memory associated with a meta_agent. This is a destructor, and as a result the meta_agent should not be used again after a call to this method

Parameters
mathe meta_agent to clear

Definition at line 784 of file agent.c.

◆ meta_agent_increase_count()

void meta_agent_increase_count ( meta_agent_t ma)

Increase the running agent count.

Parameters
maAgent's meta

Definition at line 1362 of file agent.c.

◆ meta_agent_init()

meta_agent_t* meta_agent_init ( char *  name,
char *  cmd,
int  max,
int  spc 
)

Creates a new meta agent.

This will take and parse the information necessary for the creation of a new agent instance. The name of the agent, the cmd for starting the agent, the number of these agents that can run simutaniously, and any special conditions for this agent. This function is where the cmd will get parsed to be passed as command line args to the new agent.

Parameters
namethe name of the agent (i.e. nomos, buckets, etc...)
cmdthe command for starting the agent in a shell
maxthe number of these that can concurrently, -1 for no limit
spcany special conditions associated with the agent
Returns
meta_agent_t Meta agent

Definition at line 744 of file agent.c.

◆ test_agents()

void test_agents ( scheduler_t scheduler)

Calls the agent test function for every type of agent.

This is used when either the -t or -T option are used upon scheduler creation.

Parameters
schedulerscheduler reference to test attached agents

Definition at line 1290 of file agent.c.