17 #include <scheduler.h>
48 void create_pipe(
int* int_dst,
int* int_src, FILE** file_dst, FILE** file_src)
55 if(int_dst) *int_dst = a_to_b[0];
56 if(int_src) *int_src = a_to_b[1];
58 if(file_dst) *file_dst = fdopen(a_to_b[0],
"r");
59 if(file_src) *file_src = fdopen(a_to_b[1],
"w");
78 char* name =
"copyright";
85 FO_ASSERT_PTR_NOT_NULL_FATAL(ma);
86 FO_ASSERT_STRING_EQUAL(ma->
name,
"copyright");
87 FO_ASSERT_STRING_EQUAL(ma->
raw_cmd,
"copyright --scheduler_start");
89 FO_ASSERT_EQUAL(ma->
special, spc);
90 FO_ASSERT_PTR_NULL(ma->
version);
91 FO_ASSERT_TRUE(ma->
valid);
115 ma = g_tree_lookup(scheduler->
meta_agents,
"name");
116 FO_ASSERT_EQUAL(g_tree_nnodes(scheduler->
meta_agents), 1);
117 FO_ASSERT_PTR_NOT_NULL(ma);
118 FO_ASSERT_STRING_EQUAL(ma->
name,
"name");
119 FO_ASSERT_STRING_EQUAL(ma->
raw_cmd,
"cmd --scheduler_start");
120 FO_ASSERT_EQUAL(ma->
max_run, 11);
121 FO_ASSERT_EQUAL(ma->
special, 1);
122 FO_ASSERT_PTR_NULL(ma->
version);
123 FO_ASSERT_TRUE(ma->
valid);
180 fagent.
owner = &fjob;
181 fagent.
status = AG_CREATED;
190 pid_set = g_new0(
int, 2);
191 pid_set[0] = fagent.
pid;
196 a1 = g_tree_lookup(scheduler->
agents, &fagent.
pid);
198 FO_ASSERT_EQUAL(fagent.
status, AG_CREATED);
199 FO_ASSERT_PTR_NULL(a1);
203 fclose(fagent.
write);
228 static int32_t id_gen = -1;
236 for(iter = scheduler->
host_queue; iter != NULL; iter = iter->next)
238 host = (
host_t*)iter->data;
240 host->
name, id_gen--, 0, 0, 0, 0, NULL);
244 fagent->
owner = fjob;
245 fagent->
status = AG_CREATED;
250 ag = g_tree_lookup(scheduler->
agents, &fagent->
pid);
253 FO_ASSERT_PTR_NOT_NULL(ag);
254 FO_ASSERT_PTR_NOT_NULL(gl);
255 FO_ASSERT_EQUAL(fagent->
status, AG_SPAWNED);
256 FO_ASSERT_PTR_EQUAL(ag, gl->data);
259 FO_ASSERT_EQUAL(fagent->
status, AG_PAUSED);
261 FO_ASSERT_EQUAL(fagent->
status, AG_RUNNING);
267 ag = g_tree_lookup(scheduler->
agents, &fagent->
pid);
269 FO_ASSERT_PTR_NOT_NULL(ag);
270 FO_ASSERT_EQUAL(fagent->
status, AG_PAUSED);
274 ag = g_tree_lookup(scheduler->
agents, &fagent->
pid);
276 FO_ASSERT_PTR_NOT_NULL(ag);
277 FO_ASSERT_EQUAL(fagent->
status, AG_FAILED);
281 ag = g_tree_lookup(scheduler->
agents, &fagent->
pid);
282 FO_ASSERT_PTR_NOT_NULL(ag);
283 FO_ASSERT_EQUAL(fagent->
status, AG_FAILED);
285 pid_set = g_new0(
int, 2);
286 pid_set[0] = fagent->
pid;
292 ag = g_tree_lookup(scheduler->
agents, &fagent->
pid);
294 FO_ASSERT_EQUAL(fagent->
status, AG_FAILED);
295 FO_ASSERT_PTR_NULL(ag);
311 static int32_t id_gen = -1;
319 for(iter = scheduler->
host_queue; iter != NULL; iter = iter->next)
321 host = (
host_t*)iter->data;
323 host->
name, id_gen--, 0, 0, 0, 0, NULL);
325 FO_ASSERT_PTR_NOT_NULL(fagent);
345 CU_TestInfo tests_meta_agent[] =
353 CU_TestInfo tests_agent[] =
void agent_ready_event(scheduler_t *scheduler, agent_t *agent)
Event created when an agent is ready for more data.
agent_t * agent_init(scheduler_t *scheduler, host_t *host, job_t *job)
Allocate and spawn a new agent.
void agent_update_event(scheduler_t *scheduler, void *unused)
void agent_fail_event(scheduler_t *scheduler, agent_t *agent)
Fails an agent.
meta_agent_t * meta_agent_init(char *name, char *cmd, int max, int spc)
Creates a new meta agent.
void agent_pause(agent_t *agent)
int add_meta_agent(GTree *meta_agents, char *name, char *cmd, int max, int spc)
void agent_create_event(scheduler_t *scheduler, agent_t *agent)
Event created when a new agent has been created.
void agent_unpause(agent_t *agent)
void agent_death_event(scheduler_t *scheduler, pid_t *pid)
Header file with agent related operations.
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.
FUNCTION int max(int permGroup, int permPublic)
Get the maximum group privilege.
void scheduler_config_event(scheduler_t *scheduler, void *unused)
Load both the fossology configuration and all the agent configurations.
void scheduler_agent_config(scheduler_t *scheduler)
Loads a particular agents configuration file.
void scheduler_close_event(scheduler_t *scheduler, void *killed)
Sets the closing flag and possibly kills all currently running agents.
scheduler_t * scheduler_init(gchar *sysconfigdir, log_t *log)
Create a new scheduler object.
void scheduler_foss_config(scheduler_t *scheduler)
Loads the configuration data from fossology.conf.
void scheduler_destroy(scheduler_t *scheduler)
Free any memory associated with a scheduler_t.
agent_status status
the state of execution the agent is currently in
int from_child
file identifier to read from child
FILE * write
FILE* that abstracts the use of the to_child socket.
job_t * owner
the job that this agent is assigned to
int to_parent
file identifier to print to the parent (child stdout)
uint8_t return_code
what was returned by the agent when it disconnected
pid_t pid
the pid of the process this agent is running in
char * name
The name of the host, used to store host internally to scheduler.
int32_t id
The identifier for this job.
job_status status
The current status for the job.
GList * failed_agents
The list of agents that failed while working.
GList * running_agents
The list of agents assigned to this job that are still working.
GTree * job_list
List of jobs that have been created.
GList * host_queue
Round-robin queue for choosing which host use next.
GTree * meta_agents
List of all meta agents available to the scheduler.
GTree * agents
List of any currently running agents.
GSequence * job_queue
heap of jobs that still need to be started
void create_pipe(int *int_dst, int *int_src, FILE **file_dst, FILE **file_src)
Creates 2 pipes and initialize parameters.
void test_meta_agent_init()
Test for meta_agent_init()
void test_agent_init()
Test for agent_init()
void test_agent_create_event()
Test for agent_create_event()
void test_add_meta_agent()
Test for add_meta_agent()
void test_agent_death_event()
Test for agent_death_event()