/src/pacemaker/lib/common/health.c
Line | Count | Source |
1 | | /* |
2 | | * Copyright 2024-2025 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 <stdbool.h> |
13 | | #include <stdio.h> // NULL |
14 | | |
15 | | #include <crm/common/scheduler.h> // pcmk_scheduler_t |
16 | | |
17 | | /*! |
18 | | * \internal |
19 | | * \brief Ensure a health strategy value is allowed |
20 | | * |
21 | | * \param[in] value Configured health strategy |
22 | | * |
23 | | * \return true if \p value is an allowed health strategy value, otherwise false |
24 | | */ |
25 | | bool |
26 | | pcmk__validate_health_strategy(const char *value) |
27 | 0 | { |
28 | 0 | return pcmk__strcase_any_of(value, |
29 | 0 | PCMK_VALUE_NONE, |
30 | 0 | PCMK_VALUE_CUSTOM, |
31 | 0 | PCMK_VALUE_ONLY_GREEN, |
32 | 0 | PCMK_VALUE_PROGRESSIVE, |
33 | 0 | PCMK_VALUE_MIGRATE_ON_RED, |
34 | 0 | NULL); |
35 | 0 | } |
36 | | |
37 | | /*! |
38 | | * \internal |
39 | | * \brief Parse node health strategy from a user-provided string |
40 | | * |
41 | | * \param[in] value User-provided configuration value for node-health-strategy |
42 | | * |
43 | | * \return Node health strategy corresponding to \p value |
44 | | */ |
45 | | enum pcmk__health_strategy |
46 | | pcmk__parse_health_strategy(const char *value) |
47 | 0 | { |
48 | 0 | if (pcmk__str_eq(value, PCMK_VALUE_NONE, |
49 | 0 | pcmk__str_null_matches|pcmk__str_casei)) { |
50 | 0 | return pcmk__health_strategy_none; |
51 | 0 | } |
52 | 0 | if (pcmk__str_eq(value, PCMK_VALUE_MIGRATE_ON_RED, pcmk__str_casei)) { |
53 | 0 | return pcmk__health_strategy_no_red; |
54 | 0 | } |
55 | 0 | if (pcmk__str_eq(value, PCMK_VALUE_ONLY_GREEN, pcmk__str_casei)) { |
56 | 0 | return pcmk__health_strategy_only_green; |
57 | 0 | } |
58 | 0 | if (pcmk__str_eq(value, PCMK_VALUE_PROGRESSIVE, pcmk__str_casei)) { |
59 | 0 | return pcmk__health_strategy_progressive; |
60 | 0 | } |
61 | 0 | if (pcmk__str_eq(value, PCMK_VALUE_CUSTOM, pcmk__str_casei)) { |
62 | 0 | return pcmk__health_strategy_custom; |
63 | 0 | } else { |
64 | 0 | pcmk__config_err("Using default of \"" PCMK_VALUE_NONE "\" for " |
65 | 0 | PCMK_OPT_NODE_HEALTH_STRATEGY |
66 | 0 | " because '%s' is not a valid value", |
67 | 0 | value); |
68 | 0 | return pcmk__health_strategy_none; |
69 | 0 | } |
70 | 0 | } |
71 | | |
72 | | /*! |
73 | | * \internal |
74 | | * \brief Parse a health score from a cluster option value |
75 | | * |
76 | | * \param[in] option Name of option to parse |
77 | | * \param[in] scheduler Scheduler data |
78 | | * |
79 | | * \return Integer score parsed from \p option value (or 0 if invalid) |
80 | | */ |
81 | | int |
82 | | pcmk__health_score(const char *option, const pcmk_scheduler_t *scheduler) |
83 | 0 | { |
84 | 0 | int score = 0; |
85 | 0 | int rc = pcmk_rc_ok; |
86 | 0 | const char *value = NULL; |
87 | |
|
88 | 0 | CRM_CHECK((option != NULL) && (scheduler != NULL), return 0); |
89 | | |
90 | 0 | value = pcmk__cluster_option(scheduler->priv->options, option); |
91 | 0 | rc = pcmk_parse_score(value, &score, 0); |
92 | 0 | if (rc != pcmk_rc_ok) { |
93 | | pcmk__warn("Using 0 for %s because '%s' is invalid: %s", |
94 | 0 | option, value, pcmk_rc_str(rc)); |
95 | 0 | } |
96 | 0 | return score; |
97 | 0 | } |