pacemaker 2.1.5-a3f44794f94
Scalable High-Availability cluster resource manager
pe_health.c
Go to the documentation of this file.
1/*
2 * Copyright 2004-2022 the Pacemaker project contributors
3 *
4 * The version control history for this file may have further details.
5 *
6 * This source code is licensed under the GNU Lesser General Public License
7 * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
8 */
9
10#include <crm_internal.h>
11
12#include <crm/pengine/status.h>
14#include "pe_status_private.h"
15
22void
24{
25 switch (pe__health_strategy(data_set)) {
30 break;
31
36 break;
37
42 break;
43
44 default: // progressive or custom
46 data_set);
48 data_set);
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 "
61 }
62}
63
73static void
74add_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
93int
94pe__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
111int
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 /* It's possible that pcmk__score_red equals pcmk__score_yellow,
133 * or pcmk__score_yellow equals pcmk__score_green, so check the
134 * textual value first to be able to distinguish those.
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,
140 rc = 0;
141 continue;
142 }
143
144 // The value is an integer, so compare numerically
145 score = char2score(value);
146 if (score <= pcmk__score_red) {
147 return -1;
148 } else if ((score <= pcmk__score_yellow)
150 rc = 0;
151 }
152 }
153 }
154 return rc;
155}
const char * name
Definition: cib.c:24
int pcmk__score_yellow
Definition: scores.c:22
int pcmk__score_green
Definition: scores.c:21
int pcmk__score_red
Definition: scores.c:20
int pcmk__add_scores(int score1, int score2)
Definition: scores.c:113
int char2score(const char *score)
Get the integer value of a score string.
Definition: scores.c:36
#define INFINITY
Definition: crm.h:99
pcmk__health_strategy
@ pcmk__health_strategy_only_green
@ pcmk__health_strategy_none
@ pcmk__health_strategy_no_red
#define crm_debug(fmt, args...)
Definition: logging.h:364
pe_working_set_t * data_set
#define PCMK__VALUE_RED
#define PCMK__VALUE_GREEN
#define PCMK__OPT_NODE_HEALTH_RED
#define PCMK__OPT_NODE_HEALTH_GREEN
#define PCMK__VALUE_YELLOW
#define PCMK__OPT_NODE_HEALTH_YELLOW
void pe__unpack_node_health_scores(pe_working_set_t *data_set)
Definition: pe_health.c:23
int pe__sum_node_health_scores(const pe_node_t *node, int base_health)
Definition: pe_health.c:94
int pe__node_health(pe_node_t *node)
Definition: pe_health.c:112
#define CRM_ASSERT(expr)
Definition: results.h:42
Cluster status and scheduling.
bool pcmk__starts_with(const char *str, const char *prefix)
Check whether a string starts with a certain sequence.
Definition: strings.c:484
@ pcmk__str_casei
struct pe_node_shared_s * details
Definition: pe_types.h:252
GHashTable * attrs
Definition: pe_types.h:241
pe_working_set_t * data_set
Cluster that this node is part of.
Definition: pe_types.h:245