pacemaker 3.0.1-16e74fc4da
Scalable High-Availability cluster resource manager
Loading...
Searching...
No Matches
rules_compat.c
Go to the documentation of this file.
1/*
2 * Copyright 2004-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#include <glib.h> // gboolean, GList, GHashTable
14#include <libxml/tree.h> // xmlNode
15
16#include <crm/crm.h>
17#include <crm/common/iso8601.h> // crm_time_t
18#include <crm/common/roles.h> // enum rsc_role_e
19
20#include <crm/common/xml.h>
21#include <crm/common/rules.h> // pcmk_rule_input_t, etc.
22#include <crm/common/nvpair_internal.h> // pcmk__nvpair_unpack_t, etc.
23
25
26// Deprecated functions kept only for backward API compatibility
27// LCOV_EXCL_START
28
31
32gboolean
33test_rule(xmlNode * rule, GHashTable * node_hash, enum rsc_role_e role, crm_time_t * now)
34{
35 pcmk_rule_input_t rule_input = {
36 .node_attrs = node_hash,
37 .now = now,
38 };
39
40 return pcmk_evaluate_rule(rule, &rule_input, NULL) == pcmk_rc_ok;
41}
42
50static void
51map_rule_input(pcmk_rule_input_t *new, const pe_rule_eval_data_t *old)
52{
53 if (old == NULL) {
54 return;
55 }
56 new->now = old->now;
57 new->node_attrs = old->node_hash;
58 if (old->rsc_data != NULL) {
59 new->rsc_standard = old->rsc_data->standard;
60 new->rsc_provider = old->rsc_data->provider;
61 new->rsc_agent = old->rsc_data->agent;
62 }
63 if (old->match_data != NULL) {
64 new->rsc_params = old->match_data->params;
65 new->rsc_meta = old->match_data->meta;
66 if (old->match_data->re != NULL) {
67 new->rsc_id = old->match_data->re->string;
68 new->rsc_id_submatches = old->match_data->re->pmatch;
69 new->rsc_id_nmatches = old->match_data->re->nregs;
70 }
71 }
72 if (old->op_data != NULL) {
73 new->op_name = old->op_data->op_name;
74 new->op_interval_ms = old->op_data->interval;
75 }
76}
77
78void
79pe_eval_nvpairs(xmlNode *top, const xmlNode *xml_obj, const char *set_name,
80 const pe_rule_eval_data_t *rule_data, GHashTable *hash,
81 const char *always_first, gboolean overwrite,
82 crm_time_t *next_change)
83{
84 GList *pairs = pcmk__xe_dereference_children(xml_obj, set_name);
85
86 if (pairs) {
88 .values = hash,
89 .first_id = always_first,
90 .overwrite = overwrite,
91 .next_change = next_change,
92 };
93
94 map_rule_input(&(data.rule_input), rule_data);
95
96 pairs = g_list_sort_with_data(pairs, pcmk__cmp_nvpair_blocks, &data);
97 g_list_foreach(pairs, pcmk__unpack_nvpair_block, &data);
98 g_list_free(pairs);
99 }
100}
101
102void
103pe_unpack_nvpairs(xmlNode *top, const xmlNode *xml_obj, const char *set_name,
104 GHashTable *node_hash, GHashTable *hash,
105 const char *always_first, gboolean overwrite,
106 crm_time_t *now, crm_time_t *next_change)
107{
108 pe_rule_eval_data_t rule_data = {
109 .node_hash = node_hash,
110 .now = now,
111 .match_data = NULL,
112 .rsc_data = NULL,
113 .op_data = NULL
114 };
115
116 pe_eval_nvpairs(NULL, xml_obj, set_name, &rule_data, hash,
117 always_first, overwrite, next_change);
118}
119
120// LCOV_EXCL_STOP
121// End deprecated API
Scheduler API for rules.
int pcmk_evaluate_rule(xmlNode *rule, const pcmk_rule_input_t *rule_input, crm_time_t *next_change)
Evaluate a single rule, including all its conditions.
Definition rules.c:1304
Deprecated Pacemaker shared API for scheduler and rules.
char data[0]
Definition cpg.c:10
A dumping ground.
ISO_8601 Date handling.
struct crm_time_s crm_time_t
Definition iso8601.h:32
#define CRM_TRACE_INIT_DATA(name)
Definition logging.h:111
void pcmk__unpack_nvpair_block(gpointer data, gpointer user_data)
Definition nvpair.c:445
gint pcmk__cmp_nvpair_blocks(gconstpointer a, gconstpointer b, gpointer user_data)
Definition nvpair.c:582
@ pcmk_rc_ok
Definition results.h:159
Scheduler API for resource roles.
rsc_role_e
Definition roles.h:34
gboolean test_rule(xmlNode *rule, GHashTable *node_hash, enum rsc_role_e role, crm_time_t *now)
void pe_unpack_nvpairs(xmlNode *top, const xmlNode *xml_obj, const char *set_name, GHashTable *node_hash, GHashTable *hash, const char *always_first, gboolean overwrite, crm_time_t *now, crm_time_t *next_change)
void pe_eval_nvpairs(xmlNode *top, const xmlNode *xml_obj, const char *set_name, const pe_rule_eval_data_t *rule_data, GHashTable *hash, const char *always_first, gboolean overwrite, crm_time_t *next_change)
Deprecated Pacemaker rule API.
Data used to evaluate a rule (any NULL items are ignored)
Definition rules.h:57
GHashTable * meta
pe_re_match_data_t * re
GHashTable * params
const char * op_name
regmatch_t * pmatch
const char * agent
const char * provider
const char * standard
pe_rsc_eval_data_t * rsc_data
GHashTable * node_hash
crm_time_t * now
pe_match_data_t * match_data
pe_op_eval_data_t * op_data
Wrappers for and extensions to libxml2.
GList * pcmk__xe_dereference_children(const xmlNode *xml, const char *element_name)
Definition xml_idref.c:128