FOSSology  4.4.0
Open Source License Compliance by Open Source Software
job.h
1 /*
2  SPDX-FileCopyrightText: © 2010-2013 Hewlett-Packard Development Company, L.P.
3  SPDX-FileCopyrightText: © 2015 Siemens AG
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
7 
8 #ifndef JOB_H_INCLUDE
9 #define JOB_H_INCLUDE
10 
11 /* local includes */
12 #include <logging.h>
13 
14 /* std library includes */
15 #include <stdio.h>
16 #include <event.h>
17 #include <libpq-fe.h>
18 
19 /* glib includes */
20 #include <glib.h>
21 
22 /* ************************************************************************** */
23 /* **** Data Types ********************************************************** */
24 /* ************************************************************************** */
25 
26 #define JOB_STATUS_TYPES(apply) \
27  apply(NOT_AVAILABLE) \
28  \
29  apply(CHECKEDOUT) \
30  \
31  apply(STARTED) \
32  \
33  apply(COMPLETE) \
34  \
35  apply(RESTART) \
36  \
37  apply(FAILED) \
38  \
39  apply(PAUSED)
40 
41 #define SELECT_ENUM(passed) JB_##passed,
42 typedef enum { JOB_STATUS_TYPES(SELECT_ENUM) } job_status;
43 #undef SELECT_ENUM
44 
45 extern const char* job_status_strings[];
46 
50 typedef struct
51 {
52  /* associated agent information */
53  char* agent_type;
54  char* required_host;
55  GList* running_agents;
56  GList* finished_agents;
57  GList* failed_agents;
59 
60  /* information for data manipulation */
61  job_status status;
62  gchar* data;
63  gchar *jq_cmd_args;
64  PGresult* db_result;
65  GMutex* lock;
66  uint32_t idx;
67 
68  /* information about job status */
69  gchar* message;
70  int32_t priority;
71  int32_t verbose;
72  int32_t parent_id;
73  int32_t id;
74  int32_t user_id;
75  int32_t group_id;
76 } job_t;
77 
78 /* ************************************************************************** */
79 /* **** Constructor Destructor ********************************************** */
80 /* ************************************************************************** */
81 
82 job_t* job_init(GTree* job_list, GSequence* job_queue, char* type, char* host,
83  int id, int parent_id, int user_id, int group_id, int priority, char *jq_cmd_args);
84 void job_destroy(job_t* job);
85 
86 /* ************************************************************************** */
87 /* **** Functions and events ************************************************ */
88 /* ************************************************************************** */
89 
90 void job_verbose_event (scheduler_t* scheduler, job_t* j);
91 void job_status_event (scheduler_t* scheduler, arg_int* params);
92 void job_pause_event (scheduler_t* scheduler, arg_int* params);
93 void job_restart_event (scheduler_t* scheduler, arg_int* params);
94 void job_priority_event(scheduler_t* scheduler, arg_int* params);
95 void job_fail_event (scheduler_t* scheduler, job_t* job);
96 
97 void job_add_agent(job_t* job, void* a);
98 void job_remove_agent(job_t* job, GTree* job_list, void* a);
99 void job_finish_agent(job_t* job, void* a);
100 void job_fail_agent(job_t* job, void* a);
101 void job_set_data(scheduler_t* scheduler, job_t* job, char* data, int sql);
102 void job_update(scheduler_t* scheduler, job_t* job);
103 
104 gboolean job_is_open(scheduler_t* scheduler, job_t* job);
105 gchar* job_next(job_t* job);
106 log_t* job_log(job_t* job);
107 
108 /* ************************************************************************** */
109 /* **** Job list Functions ************************************************** */
110 /* ************************************************************************** */
111 
112 job_t* next_job(GSequence* job_queue);
113 job_t* peek_job(GSequence* job_queue);
114 uint32_t active_jobs(GTree* job_list);
115 
116 #endif /* JOB_H_INCLUDE */
#define SELECT_ENUM(passed)
Definition: agent.h:65
Event handling operations.
void job_fail_agent(job_t *job, void *agent)
Definition: job.c:493
void job_fail_event(scheduler_t *scheduler, job_t *job)
Events that causes a job to be marked a failed.
Definition: job.c:406
void job_restart_event(scheduler_t *scheduler, arg_int *params)
Definition: job.c:342
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.
Definition: job.c:164
job_t * next_job(GSequence *job_queue)
Gets the next job from the job queue.
Definition: job.c:681
void job_update(scheduler_t *scheduler, job_t *job)
Definition: job.c:531
int job_is_open(scheduler_t *scheduler, job_t *job)
Tests to see if there is still data available for this job.
Definition: job.c:570
void job_set_data(scheduler_t *scheduler, job_t *job, char *data, int sql)
Definition: job.c:511
char * job_next(job_t *job)
Definition: job.c:610
job_t * peek_job(GSequence *job_queue)
Gets the job that is at the top of the queue if there is one.
Definition: job.c:701
void job_remove_agent(job_t *job, GTree *job_list, void *agent)
Definition: job.c:449
void job_verbose_event(scheduler_t *scheduler, job_t *job)
Definition: job.c:244
void job_pause_event(scheduler_t *scheduler, arg_int *params)
Event to pause a job.
Definition: job.c:312
void job_status_event(scheduler_t *scheduler, arg_int *params)
Event to get the status of the scheduler or a specific job.
Definition: job.c:266
void job_destroy(job_t *job)
Definition: job.c:201
log_t * job_log(job_t *job)
Definition: job.c:637
void job_add_agent(job_t *job, void *agent)
Adds a new agent to the jobs list of agents.
Definition: job.c:434
void job_priority_event(scheduler_t *scheduler, arg_int *params)
Definition: job.c:385
void job_finish_agent(job_t *job, void *agent)
Definition: job.c:478
uint32_t active_jobs(GTree *job_list)
Gets the number of jobs that are not paused.
Definition: job.c:720
Log related operations.
Definition: event.h:46
The job structure.
Definition: job.h:51
int32_t id
The identifier for this job.
Definition: job.h:73
GMutex * lock
Lock to maintain data integrity.
Definition: job.h:65
job_status status
The current status for the job.
Definition: job.h:61
uint32_t idx
The current index into the sql results.
Definition: job.h:66
int32_t group_id
The id of the group that created the job.
Definition: job.h:75
char * required_host
If not NULL, this job must run on a specific host machine.
Definition: job.h:54
GList * finished_agents
The list of agents that have completed their tasks.
Definition: job.h:56
gchar * message
Message that will be sent with job notification email.
Definition: job.h:69
gchar * jq_cmd_args
Command line arguments for this job.
Definition: job.h:63
int32_t user_id
The id of the user that created the job.
Definition: job.h:74
GList * failed_agents
The list of agents that failed while working.
Definition: job.h:57
char * agent_type
The type of agent used to analyze the data.
Definition: job.h:53
gchar * data
The data associated with this job (jq_args)
Definition: job.h:62
int32_t priority
Importance of the job, maps directory to unix priority.
Definition: job.h:70
int32_t parent_id
The identifier for the parent of this job (its queue id)
Definition: job.h:72
GList * running_agents
The list of agents assigned to this job that are still working.
Definition: job.h:55
PGresult * db_result
Results from the sql query (if any)
Definition: job.h:64
log_t * log
The log to print any agent logging messages to.
Definition: job.h:58
int32_t verbose
The verbose level for all of the agents in this job.
Definition: job.h:71
Definition: logging.h:35