pacemaker  2.1.9-49aab99839
Scalable High-Availability cluster resource manager
health.c
Go to the documentation of this file.
1 /*
2  * Copyright 2024 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 <stdio.h> // NULL
13 
14 #include <crm/common/scheduler.h> // pcmk_scheduler_t
15 #include <crm/common/scheduler_internal.h> // pcmk_scheduler_t private data
16 
25 bool
27 {
28  return pcmk__strcase_any_of(value,
34  NULL);
35 }
36 
46 pcmk__parse_health_strategy(const char *value)
47 {
48  if (pcmk__str_eq(value, PCMK_VALUE_NONE,
51  }
52  if (pcmk__str_eq(value, PCMK_VALUE_MIGRATE_ON_RED, pcmk__str_casei)) {
54  }
55  if (pcmk__str_eq(value, PCMK_VALUE_ONLY_GREEN, pcmk__str_casei)) {
57  }
58  if (pcmk__str_eq(value, PCMK_VALUE_PROGRESSIVE, pcmk__str_casei)) {
60  }
61  if (pcmk__str_eq(value, PCMK_VALUE_CUSTOM, pcmk__str_casei)) {
63  } else {
64  pcmk__config_err("Using default of \"" PCMK_VALUE_NONE "\" for "
66  " because '%s' is not a valid value",
67  value);
69  }
70 }
71 
81 int
82 pcmk__health_score(const char *option, const pcmk_scheduler_t *scheduler)
83 {
84  int score = 0;
85  int rc = pcmk_rc_ok;
86  const char *value = NULL;
87 
88  CRM_CHECK((option != NULL) && (scheduler != NULL), return 0);
89 
90  value = pcmk__cluster_option(scheduler->config_hash, option);
91  rc = pcmk_parse_score(value, &score, 0);
92  if (rc != pcmk_rc_ok) {
93  crm_warn("Using 0 for %s because '%s' is invalid: %s",
94  option, value, pcmk_rc_str(rc));
95  }
96  return score;
97 }
#define CRM_CHECK(expr, failure_action)
Definition: logging.h:245
bool pcmk__strcase_any_of(const char *s,...) G_GNUC_NULL_TERMINATED
Definition: strings.c:1038
#define pcmk__config_err(fmt...)
const char * pcmk__cluster_option(GHashTable *options, const char *name)
Definition: options.c:1419
const char * pcmk_rc_str(int rc)
Get a user-friendly description of a return code.
Definition: results.c:503
Scheduler API.
#define crm_warn(fmt, args...)
Definition: logging.h:394
int pcmk__health_score(const char *option, const pcmk_scheduler_t *scheduler)
Definition: health.c:82
#define PCMK_VALUE_NONE
Definition: options.h:178
#define PCMK_VALUE_ONLY_GREEN
Definition: options.h:185
enum pcmk__health_strategy pcmk__parse_health_strategy(const char *value)
Definition: health.c:46
GHashTable * config_hash
Definition: scheduler.h:219
#define PCMK_VALUE_CUSTOM
Definition: options.h:140
#define PCMK_OPT_NODE_HEALTH_STRATEGY
Definition: options.h:51
pcmk_scheduler_t * scheduler
pcmk__health_strategy
int pcmk_parse_score(const char *score_s, int *score, int default_score)
Parse an integer score from a string.
Definition: scores.c:39
#define PCMK_VALUE_PROGRESSIVE
Definition: options.h:194
#define PCMK_VALUE_MIGRATE_ON_RED
Definition: options.h:171
bool pcmk__validate_health_strategy(const char *value)
Definition: health.c:26