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
23 void
24 pe__unpack_node_health_scores(pcmk_scheduler_t *scheduler)
25 {
26 switch (pe__health_strategy(scheduler)) {
27 case pcmk__health_strategy_none:
28 pcmk__score_red = 0;
29 pcmk__score_yellow = 0;
30 pcmk__score_green = 0;
31 break;
32
33 case pcmk__health_strategy_no_red:
34 pcmk__score_red = -PCMK_SCORE_INFINITY;
35 pcmk__score_yellow = 0;
36 pcmk__score_green = 0;
37 break;
38
39 case pcmk__health_strategy_only_green:
40 pcmk__score_red = -PCMK_SCORE_INFINITY;
41 pcmk__score_yellow = -PCMK_SCORE_INFINITY;
42 pcmk__score_green = 0;
43 break;
44
45 default:
46 pcmk__score_red = pe__health_score(PCMK_OPT_NODE_HEALTH_RED,
47 scheduler);
48 pcmk__score_green = pe__health_score(PCMK_OPT_NODE_HEALTH_GREEN,
49 scheduler);
50 pcmk__score_yellow = pe__health_score(PCMK_OPT_NODE_HEALTH_YELLOW,
51 scheduler);
52 break;
53 }
54
55 if ((pcmk__score_red != 0) || (pcmk__score_yellow != 0)
56 || (pcmk__score_green != 0)) {
57 crm_debug("Values of node health scores: "
58 PCMK_VALUE_RED "=%d "
59 PCMK_VALUE_YELLOW "=%d "
60 PCMK_VALUE_GREEN "=%d",
61 pcmk__score_red, pcmk__score_yellow, pcmk__score_green);
62 }
63 }
64
65
66
67
68
69
70
71
72
73
74 static void
75 add_node_health_value(gpointer key, gpointer value, gpointer user_data)
76 {
77 if (pcmk__starts_with((const char *) key, "#health")) {
78 int score = char2score((const char *) value);
79 int *health = (int *) user_data;
80
81 *health = pcmk__add_scores(score, *health);
82 crm_trace("Combined '%s' into node health score (now %s)",
83 (const char *) value, pcmk_readable_score(*health));
84 }
85 }
86
87
88
89
90
91
92
93
94
95
96 int
97 pe__sum_node_health_scores(const pcmk_node_t *node, int base_health)
98 {
99 CRM_ASSERT(node != NULL);
100 g_hash_table_foreach(node->details->attrs, add_node_health_value,
101 &base_health);
102 return base_health;
103 }
104
105
106
107
108
109
110
111
112
113
114 int
115 pe__node_health(pcmk_node_t *node)
116 {
117 GHashTableIter iter;
118 const char *name = NULL;
119 const char *value = NULL;
120 enum pcmk__health_strategy strategy;
121 int score = 0;
122 int rc = 1;
123
124 CRM_ASSERT(node != NULL);
125
126 strategy = pe__health_strategy(node->details->data_set);
127 if (strategy == pcmk__health_strategy_none) {
128 return rc;
129 }
130
131 g_hash_table_iter_init(&iter, node->details->attrs);
132 while (g_hash_table_iter_next(&iter, (gpointer *) &name,
133 (gpointer *) &value)) {
134 if (pcmk__starts_with(name, "#health")) {
135
136
137
138
139 if (pcmk__str_eq(value, PCMK_VALUE_RED, pcmk__str_casei)) {
140 return -1;
141 } else if (pcmk__str_eq(value, PCMK_VALUE_YELLOW,
142 pcmk__str_casei)) {
143 rc = 0;
144 continue;
145 }
146
147
148 score = char2score(value);
149 if (score <= pcmk__score_red) {
150 return -1;
151 } else if ((score <= pcmk__score_yellow)
152 && (pcmk__score_yellow != pcmk__score_green)) {
153 rc = 0;
154 }
155 }
156 }
157 return rc;
158 }