root/lib/common/health.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. pcmk__validate_health_strategy
  2. pcmk__parse_health_strategy
  3. pcmk__health_score

   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 
  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)
     /* [previous][next][first][last][top][bottom][index][help] */
  27 {
  28     return pcmk__strcase_any_of(value,
  29                                 PCMK_VALUE_NONE,
  30                                 PCMK_VALUE_CUSTOM,
  31                                 PCMK_VALUE_ONLY_GREEN,
  32                                 PCMK_VALUE_PROGRESSIVE,
  33                                 PCMK_VALUE_MIGRATE_ON_RED,
  34                                 NULL);
  35 }
  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)
     /* [previous][next][first][last][top][bottom][index][help] */
  47 {
  48     if (pcmk__str_eq(value, PCMK_VALUE_NONE,
  49                      pcmk__str_null_matches|pcmk__str_casei)) {
  50         return pcmk__health_strategy_none;
  51     }
  52     if (pcmk__str_eq(value, PCMK_VALUE_MIGRATE_ON_RED, pcmk__str_casei)) {
  53         return pcmk__health_strategy_no_red;
  54     }
  55     if (pcmk__str_eq(value, PCMK_VALUE_ONLY_GREEN, pcmk__str_casei)) {
  56         return pcmk__health_strategy_only_green;
  57     }
  58     if (pcmk__str_eq(value, PCMK_VALUE_PROGRESSIVE, pcmk__str_casei)) {
  59         return pcmk__health_strategy_progressive;
  60     }
  61     if (pcmk__str_eq(value, PCMK_VALUE_CUSTOM, pcmk__str_casei)) {
  62         return pcmk__health_strategy_custom;
  63     } else {
  64         pcmk__config_err("Using default of \"" PCMK_VALUE_NONE "\" for "
  65                          PCMK_OPT_NODE_HEALTH_STRATEGY
  66                          " because '%s' is not a valid value",
  67                          value);
  68         return pcmk__health_strategy_none;
  69     }
  70 }
  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)
     /* [previous][next][first][last][top][bottom][index][help] */
  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 }

/* [previous][next][first][last][top][bottom][index][help] */