FOSSology
4.4.0
Open Source License Compliance by Open Source Software
|
Contains agent related information. More...
#include <agent.h>
#include <database.h>
#include <event.h>
#include <host.h>
#include <job.h>
#include <logging.h>
#include <scheduler.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <glib.h>
Go to the source code of this file.
Classes | |
struct | agent_spawn_args |
Macros | |
#define | TEST_NULV(a) |
Test if paramater is NULL. More... | |
#define | TEST_NULL(a, ret) |
Test if paramater is NULL. More... | |
#define | AGENT_CREDENTIAL |
#define | AGENT_LOG_CREDENTIAL |
#define | AGENT_ERROR(...) |
#define | AGENT_NOTIFY(...) |
#define | AGENT_WARNING(...) |
#define | AGENT_SEQUENTIAL_PRINT(...) |
#define | AGENT_CONCURRENT_PRINT(...) |
#define | SELECT_STRING(passed) MK_STRING_LIT(AGENT_##passed), |
#define | MAX_CMD_ARGS 30 |
Functions | |
static int | agent_close_fd (int *pid_ptr, agent_t *agent, agent_t *excepted) |
This will close all of the agent's pipes. More... | |
static int | update (int *pid_ptr, agent_t *agent, gpointer unused) |
static int | agent_kill_traverse (int *pid, agent_t *agent, gpointer unused) |
GTraversalFunction that kills all of the agents. More... | |
static int | agent_list (char *name, meta_agent_t *ma, GOutputStream *ostr) |
GTraverseFunction that will print the name of every agent in alphabetical order separated by spaces. More... | |
static int | agent_test (const gchar *name, meta_agent_t *ma, scheduler_t *scheduler) |
GTraversalFunction that tests the current agent on every host. More... | |
static void | agent_listen (scheduler_t *scheduler, agent_t *agent) |
static void | shell_parse (char *confdir, int user_id, int group_id, char *input, char *jq_cmd_args, int jobId, int *argc, char ***argv) |
Parses the shell command that is found in the configuration file. More... | |
static void * | agent_spawn (agent_spawn_args *pass) |
Spawns a new agent using the command passed in using the meta agent. More... | |
meta_agent_t * | meta_agent_init (char *name, char *cmd, int max, int spc) |
Creates a new meta agent. More... | |
void | meta_agent_destroy (meta_agent_t *ma) |
agent_t * | agent_init (scheduler_t *scheduler, host_t *host, job_t *job) |
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 *pid) |
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... | |
void | kill_agents (scheduler_t *scheduler) |
Call the agent_kill function for every agent within the system. More... | |
int | add_meta_agent (GTree *meta_agents, char *name, char *cmd, int max, int spc) |
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 *ma) |
void | meta_agent_decrease_count (meta_agent_t *ma) |
Variables | |
const char * | agent_status_strings [] |
Contains agent related information.
Definition in file agent.c.
#define AGENT_CONCURRENT_PRINT | ( | ... | ) |
#define AGENT_CREDENTIAL |
#define AGENT_ERROR | ( | ... | ) |
#define AGENT_LOG_CREDENTIAL |
#define AGENT_NOTIFY | ( | ... | ) |
NOTIFY macro specifically for agents
#define AGENT_SEQUENTIAL_PRINT | ( | ... | ) |
#define AGENT_WARNING | ( | ... | ) |
WARNING macro specifically for agents
#define SELECT_STRING | ( | passed | ) | MK_STRING_LIT(AGENT_##passed), |
#define TEST_NULL | ( | a, | |
ret | |||
) |
Test if paramater is NULL.
Like TEST_NULV(), returns ret instead of void.
a | Object to check |
ret | Value to return if a is NULL |
#define TEST_NULV | ( | a | ) |
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.
meta_agents | GTree of meta agents available for the scheduler |
name | the name of the meta agent (e.g. "nomos", "copyright", etc...) |
cmd | the shell command used to the run the agent |
max | the max number of this type of agent that can run concurrently |
spc | anything special about the agent type |
This will close all of the agent's pipes.
This function will be called by g_tree_foreach() which is the reason for its formatting.
pid_ptr | the key that was used to store this agent |
agent | the agent that is being closed |
excepted | this is an agent we don't want to close, this is it |
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.
scheduler | the scheduler reference to which agent has to attach |
agent | the agent that has been created. |
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.
scheduler | the scheduler reference to which process was attached to |
pid | the pid of the process that died |
void agent_destroy | ( | agent_t * | agent | ) |
Frees the memory associated with an agent.
This include:
agent | the agent to destroy |
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.
scheduler | the scheduler to which agent is attached |
agent | the agent that is failing. |
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.
scheduler | the scheduler this agent is being created under |
host | the machine to start the agent on |
job | the job that this agent belongs to |
void agent_kill | ( | agent_t * | agent | ) |
|
static |
GTraversalFunction that kills all of the agents.
This is used for an unclean death since all of the child processes will be sent a kill signal instead of existing cleanly.
pid | the process id associated with the agent |
agent | a pointer to the information associated with an agent |
unused |
|
static |
GTraverseFunction that will print the name of every agent in alphabetical order separated by spaces.
name | the name of the agent |
ma | the meta_agents structure associated with the specific name |
ostr | the output stream to write the data to, socket in this case |
|
static |
Main function used for agent communication. This is where the communication thread will spend the majority of its time.
scheduler | Pointer to scheduler interface |
agent | a the agent that will be listened on |
Start by getting the version information from the agent. The agent should send "VERSION: <string>" where the string is the version information. there are five things that can happen here.
If we reach here the agent has correctly sent VERION information to the scheduler. The agent now enters a listening loop. The communication thread will wait for input from the agent, and act according to the agents current state and what was sent
command: "BYE"
The agent has finished processing all of the data from the relevant job. This command is follow by a return code. 0 indicates that it completed correctly, anything else can be used as an error code. Regardless of whether the agent completed, the communication thread will shutdown.
command "@@@1"
The scheduler needs the communication thread to shutdown. This will normally only happen if the agent crashes and the scheduler receives a SIGCHLD for it before it sends "BYE #".
command "@@@0"
The scheduler has updated the data that the agent should be processing. This is sent after an agent sends the "OK" command, and the scheduler has processed the resulting agent_ready_event().
command: "OK"
The agent is ready for data. This is sent it 2 situations:
command: "HEART"
Given the size of jobs that can be processed by FOSSology, agents can take an extremely long period of time to finish. To make sure that an agent is still working it must periodically update the scheduler with how much of the job it has processed.
command: "EMAIL"
Agents have the ability to set the message that will be sent with the notification email. This grabs the message and sets inside the job that the agent is running under.
command: "SPECIAL"
Agents can set special attributes that change how it is treated during execution. This grabs the command and whether it is being set to true or false. Agents use this by calling fo_scheduler_set_special() in the agent api.
command: GETSPECIAL
The agent has requested the value of a special attribute. The scheduler will respond with the value of the special attribute.
command: unknown
The agent didn't use a legal command. This will simply put what the agent printed into the log and move on.
void agent_pause | ( | agent_t * | agent | ) |
void agent_print_status | ( | agent_t * | agent, |
GOutputStream * | ostr | ||
) |
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.
scheduler | the scheduler reference to which agent is attached |
agent | the agent that is ready |
|
static |
Spawns a new agent using the command passed in using the meta agent.
This function will call the fork and exec necessary to create a new agent. As a result what this function does will change depending on if it is running in the child or the parent.
child: Will duplicate the stdin, stdout, and stderr pipes for printing to the scheduler, parse the command line options for the agent and start the agent. It will then call exec to start the new agent process
parent: This will enter the listen function, and wait for information from the child, either as a failure or as an update for the information being analyzed
pass | a pointer to scheduler_t and the new agent_t |
|
static |
GTraversalFunction that tests the current agent on every host.
This will traverse the list of hosts and start an agent that is of the type of the current meta agent on every host.
name | The name of the meta agent |
ma | The meta_agent structure needed for agent creation |
scheduler | The scheduler object to test the agents on |
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
agent | the agent to change the status for |
new_status | the new status of the agentchar* sysconfdir = NULL; // system configuration directory (SYSCONFDIR) |
void agent_unpause | ( | agent_t * | agent | ) |
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.
scheduler | the scheduler reference to inform |
unused | needed since this an event, but should be NULL |
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.
agent | the agent to send the information to |
buf | the actual data |
count | the number of bytes to write to the agent |
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.
agent | the agent to send the formated data to |
fmt | the formating string for the data |
int is_agent_special | ( | agent_t * | agent, |
int | special_type | ||
) |
int is_meta_special | ( | meta_agent_t * | ma, |
int | special_type | ||
) |
void kill_agents | ( | scheduler_t * | scheduler | ) |
void list_agents_event | ( | scheduler_t * | scheduler, |
GOutputStream * | ostr | ||
) |
Receive agent on interface.
Calls agent_list() and print evert agent attached to the scheduler.
scheduler | the scheduler to which agent is attached |
ostr | Stream to write info to |
void meta_agent_decrease_count | ( | meta_agent_t * | ma | ) |
void meta_agent_destroy | ( | meta_agent_t * | ma | ) |
void meta_agent_increase_count | ( | meta_agent_t * | ma | ) |
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.
name | the name of the agent (i.e. nomos, buckets, etc...) |
cmd | the command for starting the agent in a shell |
max | the number of these that can concurrently, -1 for no limit |
spc | any special conditions associated with the agent |
|
static |
Parses the shell command that is found in the configuration file.
confdir | The configuration directory for FOSSology | |
user_id | The id of the user that created the job | |
group_id | The id of the group that created the job | |
input | The command line that was in the agent configuration file | |
jq_cmd_args | Extra parameters required by agent (if any) | |
jobId | Job id (from db) | |
[out] | argc | Returns the number of arguments parsed |
[out] | argv | The parsed arguments |
void test_agents | ( | scheduler_t * | scheduler | ) |
|
static |
Check the status and check in time of an agent.
pid_ptr | pointer to key in g_tree, is not used in this function |
agent | the agent that needs to be updated |
unused | data that is also not used in this function |
const char* agent_status_strings[] |