1 /*
2  * Copyright (C) 2004 Andrew Beekhof <andrew@beekhof.net>
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This software is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17  */
18 #ifndef CRM_TRANSITION__H
19 #  define CRM_TRANSITION__H
20 
21 #include <crm/crm.h>
22 #include <crm/msg_xml.h>
23 #include <crm/common/xml.h>
24 
25 typedef enum {
26     action_type_pseudo,
27     action_type_rsc,
28     action_type_crm
29 } action_type_e;
30 
31 typedef struct te_timer_s crm_action_timer_t;
32 typedef struct crm_graph_s crm_graph_t;
33 
34 typedef struct synapse_s {
35     int id;
36     int priority;
37 
38     gboolean ready;
39     gboolean failed;
40     gboolean executed;
41     gboolean confirmed;
42 
43     GListPtr actions;           /* crm_action_t* */
44     GListPtr inputs;            /* crm_action_t* */
45 } synapse_t;
46 
47 typedef struct crm_action_s {
48     int id;
49     int timeout;
50     int interval;
51     GHashTable *params;
52     action_type_e type;
53 
54     crm_action_timer_t *timer;
55     synapse_t *synapse;
56 
57     gboolean sent_update;       /* sent to the CIB */
58     gboolean executed;          /* sent to the CRM */
59     gboolean confirmed;
60 
61     gboolean failed;
62     gboolean can_fail;
63 
64     xmlNode *xml;
65 
66 } crm_action_t;
67 
68 /* @COMPAT: This enum has deprecated. It has apparently never been used in a
69  * Pacemaker release, but it is kept for API backward compatibility.
70  */
71 enum timer_reason {
72     timeout_action,
73     timeout_action_warn,
74     timeout_abort,
75 };
76 
77 struct te_timer_s {
78     int source_id;
79     int timeout;
80     enum timer_reason reason; /* @COMPAT: unused, API backward compatibility */
81     crm_action_t *action;
82 };
83 
84 /* order matters here */
85 enum transition_action {
86     tg_done,
87     tg_stop,
88     tg_restart,
89     tg_shutdown,
90 };
91 
92 struct crm_graph_s {
93     int id;
94     char *source;
95     int abort_priority;
96 
97     gboolean complete;
98     const char *abort_reason;
99     enum transition_action completion_action;
100 
101     int num_actions;
102     int num_synapses;
103 
104     int batch_limit;
105     int network_delay;
106     int stonith_timeout;
107     int transition_timeout;
108 
109     int fired;
110     int pending;
111     int skipped;
112     int completed;
113     int incomplete;
114 
115     GListPtr synapses;          /* synpase_t* */
116 
117     int migration_limit;
118 };
119 
120 typedef struct crm_graph_functions_s {
121     gboolean(*pseudo) (crm_graph_t * graph, crm_action_t * action);
122     gboolean(*rsc) (crm_graph_t * graph, crm_action_t * action);
123     gboolean(*crmd) (crm_graph_t * graph, crm_action_t * action);
124     gboolean(*stonith) (crm_graph_t * graph, crm_action_t * action);
125     gboolean(*allowed) (crm_graph_t * graph, crm_action_t * action);
126 } crm_graph_functions_t;
127 
128 enum transition_status {
129     transition_active,
130     transition_pending,         /* active but no actions performed this time */
131     transition_complete,
132     transition_stopped,
133     transition_terminated,
134     transition_action_failed,
135     transition_failed,
136 };
137 
138 void set_default_graph_functions(void);
139 void set_graph_functions(crm_graph_functions_t * fns);
140 crm_graph_t *unpack_graph(xmlNode * xml_graph, const char *reference);
141 int run_graph(crm_graph_t * graph);
142 gboolean update_graph(crm_graph_t * graph, crm_action_t * action);
143 void destroy_graph(crm_graph_t * graph);
144 const char *transition_status(enum transition_status state);
145 void print_graph(unsigned int log_level, crm_graph_t * graph);
146 void print_action(int log_level, const char *prefix, crm_action_t * action);
147 bool update_abort_priority(crm_graph_t * graph, int priority,
148                            enum transition_action action, const char *abort_reason);
149 const char *actiontype2text(action_type_e type);
150 lrmd_event_data_t *convert_graph_action(xmlNode * resource, crm_action_t * action, int status,
151                                         int rc);
152 
153 #endif
154