This source file includes following definitions.
- pe__unpack_node_health_scores
- add_node_health_value
- pe__sum_node_health_scores
- pe__node_health
1
2
3
4
5
6
7
8
9
10 #include <crm_internal.h>
11
12 #include <crm/pengine/status.h>
13 #include <crm/pengine/internal.h>
14 #include "pe_status_private.h"
15
16
17
18
19
20
21
22 void
23 pe__unpack_node_health_scores(pe_working_set_t *data_set)
24 {
25 switch (pe__health_strategy(data_set)) {
26 case pcmk__health_strategy_none:
27 pcmk__score_red = 0;
28 pcmk__score_yellow = 0;
29 pcmk__score_green = 0;
30 break;
31
32 case pcmk__health_strategy_no_red:
33 pcmk__score_red = -INFINITY;
34 pcmk__score_yellow = 0;
35 pcmk__score_green = 0;
36 break;
37
38 case pcmk__health_strategy_only_green:
39 pcmk__score_red = -INFINITY;
40 pcmk__score_yellow = -INFINITY;
41 pcmk__score_green = 0;
42 break;
43
44 default:
45 pcmk__score_red = pe__health_score(PCMK__OPT_NODE_HEALTH_RED,
46 data_set);
47 pcmk__score_green = pe__health_score(PCMK__OPT_NODE_HEALTH_GREEN,
48 data_set);
49 pcmk__score_yellow = pe__health_score(PCMK__OPT_NODE_HEALTH_YELLOW,
50 data_set);
51 break;
52 }
53
54 if ((pcmk__score_red != 0) || (pcmk__score_yellow != 0)
55 || (pcmk__score_green != 0)) {
56 crm_debug("Values of node health scores: "
57 PCMK__VALUE_RED "=%d "
58 PCMK__VALUE_YELLOW "=%d "
59 PCMK__VALUE_GREEN "=%d",
60 pcmk__score_red, pcmk__score_yellow, pcmk__score_green);
61 }
62 }
63
64
65
66
67
68
69
70
71
72
73 static void
74 add_node_health_value(gpointer key, gpointer value, gpointer user_data)
75 {
76 if (pcmk__starts_with((const char *) key, "#health")) {
77 int score = char2score((const char *) value);
78 int *health = (int *) user_data;
79
80 *health = pcmk__add_scores(score, *health);
81 }
82 }
83
84
85
86
87
88
89
90
91
92
93 int
94 pe__sum_node_health_scores(const pe_node_t *node, int base_health)
95 {
96 CRM_ASSERT(node != NULL);
97 g_hash_table_foreach(node->details->attrs, add_node_health_value,
98 &base_health);
99 return base_health;
100 }
101
102
103
104
105
106
107
108
109
110
111 int
112 pe__node_health(pe_node_t *node)
113 {
114 GHashTableIter iter;
115 const char *name = NULL;
116 const char *value = NULL;
117 enum pcmk__health_strategy strategy;
118 int score = 0;
119 int rc = 1;
120
121 CRM_ASSERT(node != NULL);
122
123 strategy = pe__health_strategy(node->details->data_set);
124 if (strategy == pcmk__health_strategy_none) {
125 return rc;
126 }
127
128 g_hash_table_iter_init(&iter, node->details->attrs);
129 while (g_hash_table_iter_next(&iter, (gpointer *) &name,
130 (gpointer *) &value)) {
131 if (pcmk__starts_with(name, "#health")) {
132
133
134
135
136 if (pcmk__str_eq(value, PCMK__VALUE_RED, pcmk__str_casei)) {
137 return -1;
138 } else if (pcmk__str_eq(value, PCMK__VALUE_YELLOW,
139 pcmk__str_casei)) {
140 rc = 0;
141 continue;
142 }
143
144
145 score = char2score(value);
146 if (score <= pcmk__score_red) {
147 return -1;
148 } else if ((score <= pcmk__score_yellow)
149 && (pcmk__score_yellow != pcmk__score_green)) {
150 rc = 0;
151 }
152 }
153 }
154 return rc;
155 }