FOSSology  4.7.1
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 <time.h>
17 #include <event.h>
18 #include <libpq-fe.h>
19 
20 /* glib includes */
21 #include <glib.h>
22 
23 /* ************************************************************************** */
24 /* **** Data Types ********************************************************** */
25 /* ************************************************************************** */
26 
27 #define JOB_STATUS_TYPES(apply) \
28  apply(NOT_AVAILABLE) \
29  \
30  apply(CHECKEDOUT) \
31  \
32  apply(STARTED) \
33  \
34  apply(COMPLETE) \
35  \
36  apply(RESTART) \
37  \
38  apply(FAILED) \
39  \
40  apply(PAUSED)
41 
42 #define SELECT_ENUM(passed) JB_##passed,
43 typedef enum { JOB_STATUS_TYPES(SELECT_ENUM) } job_status;
44 #undef SELECT_ENUM
45 
46 extern const char* job_status_strings[];
47 
51 typedef struct
52 {
53  /* associated agent information */
54  char* agent_type;
55  char* required_host;
56  GList* running_agents;
57  GList* finished_agents;
58  GList* failed_agents;
60 
61  /* information for data manipulation */
62  job_status status;
63  gchar* data;
64  gchar *jq_cmd_args;
65  PGresult* db_result;
66  GMutex* lock;
67  uint32_t idx;
68 
69  /* information about job status */
70  gchar* message;
71  int32_t priority;
72  int32_t verbose;
73  int32_t parent_id;
74  int32_t id;
75  int32_t user_id;
76  int32_t group_id;
77  time_t checkedout_at;
78 } job_t;
79 
80 /* ************************************************************************** */
81 /* **** Constructor Destructor ********************************************** */
82 /* ************************************************************************** */
83 
84 job_t* job_init(GTree* job_list, GSequence* job_queue, char* type, char* host,
85  int id, int parent_id, int user_id, int group_id, int priority, char *jq_cmd_args);
86 void job_destroy(job_t* job);
87 
88 /* ************************************************************************** */
89 /* **** Functions and events ************************************************ */
90 /* ************************************************************************** */
91 
92 void job_verbose_event (scheduler_t* scheduler, job_t* j);
93 void job_status_event (scheduler_t* scheduler, arg_int* params);
94 void job_pause_event (scheduler_t* scheduler, arg_int* params);
95 void job_restart_event (scheduler_t* scheduler, arg_int* params);
96 void job_priority_event(scheduler_t* scheduler, arg_int* params);
97 void job_fail_event (scheduler_t* scheduler, job_t* job);
98 
99 void job_add_agent(job_t* job, void* a);
100 void job_remove_agent(job_t* job, GTree* job_list, void* a);
101 void job_finish_agent(job_t* job, void* a);
102 void job_fail_agent(job_t* job, void* a);
103 void job_set_data(scheduler_t* scheduler, job_t* job, char* data, int sql);
104 void job_update(scheduler_t* scheduler, job_t* job);
105 
106 int job_is_open(scheduler_t* scheduler, job_t* job);
107 gchar* job_next(job_t* job);
108 log_t* job_log(job_t* job);
109 
110 /* ************************************************************************** */
111 /* **** Job list Functions ************************************************** */
112 /* ************************************************************************** */
113 
114 job_t* next_job(GSequence* job_queue);
115 job_t* peek_job(GSequence* job_queue);
116 uint32_t active_jobs(GTree* job_list);
117 gint job_compare(gconstpointer a, gconstpointer b, gpointer user_data);
118 
119 #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:535
void job_fail_event(scheduler_t *scheduler, job_t *job)
Events that causes a job to be marked a failed.
Definition: job.c:437
void job_restart_event(scheduler_t *scheduler, arg_int *params)
Definition: job.c:348
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:744
void job_update(scheduler_t *scheduler, job_t *job)
Definition: job.c:574
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:624
void job_set_data(scheduler_t *scheduler, job_t *job, char *data, int sql)
Definition: job.c:553
char * job_next(job_t *job)
Definition: job.c:673
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:764
void job_remove_agent(job_t *job, GTree *job_list, void *agent)
Definition: job.c:494
void job_verbose_event(scheduler_t *scheduler, job_t *job)
Definition: job.c:250
void job_pause_event(scheduler_t *scheduler, arg_int *params)
Event to pause a job.
Definition: job.c:318
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:272
gint job_compare(gconstpointer a, gconstpointer b, gpointer user_data)
Used to compare two different jobs in the priority queue.
Definition: job.c:135
void job_destroy(job_t *job)
Definition: job.c:202
log_t * job_log(job_t *job)
Definition: job.c:700
void job_add_agent(job_t *job, void *agent)
Adds a new agent to the jobs list of agents.
Definition: job.c:479
void job_priority_event(scheduler_t *scheduler, arg_int *params)
Definition: job.c:391
void job_finish_agent(job_t *job, void *agent)
Definition: job.c:520
uint32_t active_jobs(GTree *job_list)
Gets the number of jobs that are not paused.
Definition: job.c:783
Log related operations.
Definition: event.h:46
The job structure.
Definition: job.h:52
int32_t id
The identifier for this job.
Definition: job.h:74
GMutex * lock
Lock to maintain data integrity.
Definition: job.h:66
job_status status
The current status for the job.
Definition: job.h:62
uint32_t idx
The current index into the sql results.
Definition: job.h:67
int32_t group_id
The id of the group that created the job.
Definition: job.h:76
char * required_host
If not NULL, this job must run on a specific host machine.
Definition: job.h:55
GList * finished_agents
The list of agents that have completed their tasks.
Definition: job.h:57
gchar * message
Message that will be sent with job notification email.
Definition: job.h:70
gchar * jq_cmd_args
Command line arguments for this job.
Definition: job.h:64
time_t checkedout_at
Timestamp when job entered JB_CHECKEDOUT (for stale detection grace period)
Definition: job.h:77
int32_t user_id
The id of the user that created the job.
Definition: job.h:75
GList * failed_agents
The list of agents that failed while working.
Definition: job.h:58
char * agent_type
The type of agent used to analyze the data.
Definition: job.h:54
gchar * data
The data associated with this job (jq_args)
Definition: job.h:63
int32_t priority
Importance of the job, maps directory to unix priority.
Definition: job.h:71
int32_t parent_id
The identifier for the parent of this job (its queue id)
Definition: job.h:73
GList * running_agents
The list of agents assigned to this job that are still working.
Definition: job.h:56
PGresult * db_result
Results from the sql query (if any)
Definition: job.h:65
log_t * log
The log to print any agent logging messages to.
Definition: job.h:59
int32_t verbose
The verbose level for all of the agents in this job.
Definition: job.h:72
Definition: logging.h:35