pacemaker  2.0.1-57cc9c14bf
Scalable High-Availability cluster resource manager
remote.c
Go to the documentation of this file.
1 /*
2  * Copyright 2013-2018 Andrew Beekhof <andrew@beekhof.net>
3  *
4  * This source code is licensed under the GNU Lesser General Public License
5  * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
6  */
7 
8 #include <crm_internal.h>
9 #include <crm/msg_xml.h>
10 #include <crm/common/xml.h>
11 #include <crm/pengine/internal.h>
12 #include <glib.h>
13 
14 gboolean
16 {
17  node_t *node;
18 
19  if (rsc == NULL) {
20  return FALSE;
21  } else if (rsc->is_remote_node == FALSE) {
22  return FALSE;
23  }
24 
25  node = pe_find_node(data_set->nodes, rsc->id);
26  if (node == NULL) {
27  return FALSE;
28  }
29 
30  return is_baremetal_remote_node(node);
31 }
32 
33 gboolean
35 {
36  if (is_remote_node(node) && (node->details->remote_rsc == NULL || node->details->remote_rsc->container == FALSE)) {
37  return TRUE;
38  }
39  return FALSE;
40 }
41 
42 gboolean
44 {
45  if (is_remote_node(node) && (node->details->remote_rsc && node->details->remote_rsc->container)) {
46  return TRUE;
47  }
48  return FALSE;
49 }
50 
51 gboolean
53 {
54  if (node && node->details->type == node_remote) {
55  return TRUE;
56  }
57  return FALSE;
58 }
59 
60 resource_t *
62 {
63  if (is_set(data_set->flags, pe_flag_have_remote_nodes) == FALSE) {
64  return NULL;
65  }
66 
67  if (rsc->fillers) {
68  GListPtr gIter = NULL;
69  for (gIter = rsc->fillers; gIter != NULL; gIter = gIter->next) {
70  resource_t *filler = (resource_t *) gIter->data;
71 
72  if (filler->is_remote_node) {
73  return filler;
74  }
75  }
76  }
77  return NULL;
78 }
79 
80 gboolean
82 {
83  const char *class = crm_element_value(xml, XML_AGENT_ATTR_CLASS);
84  const char *provider = crm_element_value(xml, XML_AGENT_ATTR_PROVIDER);
85  const char *agent = crm_element_value(xml, XML_ATTR_TYPE);
86 
87  if (safe_str_eq(agent, "remote") && safe_str_eq(provider, "pacemaker")
89  return TRUE;
90  }
91  return FALSE;
92 }
93 
103 void
105  void (*helper)(const node_t*, void*), void *user_data)
106 {
107  GListPtr iter;
108 
109  CRM_CHECK(data_set && host && host->details && helper, return);
110  if (!is_set(data_set->flags, pe_flag_have_remote_nodes)) {
111  return;
112  }
113  for (iter = host->details->running_rsc; iter != NULL; iter = iter->next) {
114  resource_t *rsc = (resource_t *) iter->data;
115 
116  if (rsc->is_remote_node && (rsc->container != NULL)) {
117  node_t *guest_node = pe_find_node(data_set->nodes, rsc->id);
118 
119  if (guest_node) {
120  (*helper)(guest_node, user_data);
121  }
122  }
123  }
124 }
125 
139 xmlNode *
140 pe_create_remote_xml(xmlNode *parent, const char *uname,
141  const char *container_id, const char *migrateable,
142  const char *is_managed, const char *start_timeout,
143  const char *server, const char *port)
144 {
145  xmlNode *remote;
146  xmlNode *xml_sub;
147 
148  remote = create_xml_node(parent, XML_CIB_TAG_RESOURCE);
149 
150  // Add identity
151  crm_xml_add(remote, XML_ATTR_ID, uname);
153  crm_xml_add(remote, XML_AGENT_ATTR_PROVIDER, "pacemaker");
154  crm_xml_add(remote, XML_ATTR_TYPE, "remote");
155 
156  // Add meta-attributes
157  xml_sub = create_xml_node(remote, XML_TAG_META_SETS);
158  crm_xml_set_id(xml_sub, "%s-%s", uname, XML_TAG_META_SETS);
159  crm_create_nvpair_xml(xml_sub, NULL,
161  if (container_id) {
162  crm_create_nvpair_xml(xml_sub, NULL,
163  XML_RSC_ATTR_CONTAINER, container_id);
164  }
165  if (migrateable) {
166  crm_create_nvpair_xml(xml_sub, NULL,
167  XML_OP_ATTR_ALLOW_MIGRATE, migrateable);
168  }
169  if (is_managed) {
170  crm_create_nvpair_xml(xml_sub, NULL, XML_RSC_ATTR_MANAGED, is_managed);
171  }
172 
173  // Add instance attributes
174  if (port || server) {
175  xml_sub = create_xml_node(remote, XML_TAG_ATTR_SETS);
176  crm_xml_set_id(xml_sub, "%s-%s", uname, XML_TAG_ATTR_SETS);
177  if (server) {
178  crm_create_nvpair_xml(xml_sub, NULL, "addr", server);
179  }
180  if (port) {
181  crm_create_nvpair_xml(xml_sub, NULL, "port", port);
182  }
183  }
184 
185  // Add operations
186  xml_sub = create_xml_node(remote, "operations");
187  crm_create_op_xml(xml_sub, uname, "monitor", "30s", "30s");
188  if (start_timeout) {
189  crm_create_op_xml(xml_sub, uname, "start", "0", start_timeout);
190  }
191  return remote;
192 }
193 
194 // History entry to be checked for fail count clearing
195 struct check_op {
196  xmlNode *rsc_op; // History entry XML
197  pe_resource_t *rsc; // Known resource corresponding to history entry
198  pe_node_t *node; // Known node corresponding to history entry
199  enum pe_check_parameters check_type; // What needs checking
200 };
201 
202 void
203 pe__add_param_check(xmlNode *rsc_op, pe_resource_t *rsc, pe_node_t *node,
204  enum pe_check_parameters flag, pe_working_set_t *data_set)
205 {
206  struct check_op *check_op = NULL;
207 
208  CRM_CHECK(data_set && rsc_op && rsc && node, return);
209 
210  check_op = calloc(1, sizeof(struct check_op));
211  CRM_ASSERT(check_op != NULL);
212 
213  crm_trace("Deferring checks of %s until after allocation", ID(rsc_op));
214  check_op->rsc_op = rsc_op;
215  check_op->rsc = rsc;
216  check_op->node = node;
217  check_op->check_type = flag;
218  data_set->param_check = g_list_prepend(data_set->param_check, check_op);
219 }
220 
228 void
230  void (*cb)(pe_resource_t*, pe_node_t*, xmlNode*,
232 {
233  CRM_CHECK(data_set && cb, return);
234 
235  for (GList *item = data_set->param_check; item != NULL; item = item->next) {
236  struct check_op *check_op = item->data;
237 
238  cb(check_op->rsc, check_op->node, check_op->rsc_op,
239  check_op->check_type, data_set);
240  }
241 }
242 
243 void
245 {
246  if (data_set && data_set->param_check) {
247  g_list_free_full(data_set->param_check, free);
248  data_set->param_check = NULL;
249  }
250 }
#define CRM_CHECK(expr, failure_action)
Definition: logging.h:165
char uname[MAX_NAME]
Definition: internal.h:85
GListPtr nodes
Definition: status.h:108
void pe__free_param_checks(pe_working_set_t *data_set)
Definition: remote.c:244
xmlNode * crm_create_op_xml(xmlNode *parent, const char *prefix, const char *task, const char *interval_spec, const char *timeout)
Create a CIB XML element for an operation.
Definition: operations.c:359
gboolean is_container_remote_node(node_t *node)
Definition: remote.c:43
pe_resource_t * container
Definition: status.h:318
#define XML_ATTR_TYPE
Definition: msg_xml.h:97
#define pe_flag_have_remote_nodes
Definition: status.h:81
void pe_foreach_guest_node(const pe_working_set_t *data_set, const node_t *host, void(*helper)(const node_t *, void *), void *user_data)
Definition: remote.c:104
pe_resource_t * remote_rsc
Definition: status.h:175
GListPtr fillers
Definition: status.h:319
AIS_Host host
Definition: internal.h:84
pe_node_t * pe_find_node(GListPtr node_list, const char *uname)
Definition: status.c:412
#define XML_TAG_ATTR_SETS
Definition: msg_xml.h:161
resource_t * rsc_contains_remote_node(pe_working_set_t *data_set, resource_t *rsc)
Definition: remote.c:61
#define PCMK_RESOURCE_CLASS_OCF
Definition: services.h:41
void pe__foreach_param_check(pe_working_set_t *data_set, void(*cb)(pe_resource_t *, pe_node_t *, xmlNode *, enum pe_check_parameters, pe_working_set_t *))
Definition: remote.c:229
#define XML_RSC_ATTR_CONTAINER
Definition: msg_xml.h:203
#define XML_ATTR_ID
Definition: msg_xml.h:94
#define XML_CIB_TAG_RESOURCE
Definition: msg_xml.h:172
#define XML_BOOLEAN_TRUE
Definition: msg_xml.h:105
#define crm_trace(fmt, args...)
Definition: logging.h:255
struct pe_node_shared_s * details
Definition: status.h:188
#define XML_AGENT_ATTR_PROVIDER
Definition: msg_xml.h:228
#define XML_TAG_META_SETS
Definition: msg_xml.h:162
Wrappers for and extensions to libxml2.
#define XML_RSC_ATTR_MANAGED
Definition: msg_xml.h:193
xmlNode * create_xml_node(xmlNode *parent, const char *name)
Definition: xml.c:2015
gboolean is_remote_node(node_t *node)
Definition: remote.c:52
void pe__add_param_check(xmlNode *rsc_op, pe_resource_t *rsc, pe_node_t *node, enum pe_check_parameters flag, pe_working_set_t *data_set)
Definition: remote.c:203
const char * crm_element_value(const xmlNode *data, const char *name)
Definition: xml.c:4641
const char * crm_xml_add(xmlNode *node, const char *name, const char *value)
Definition: xml.c:1907
gboolean is_baremetal_remote_node(node_t *node)
Definition: remote.c:34
GListPtr running_rsc
Definition: status.h:176
gboolean is_remote_node
Definition: status.h:289
GList * param_check
Definition: status.h:136
#define CRM_ASSERT(expr)
Definition: results.h:20
void crm_xml_set_id(xmlNode *xml, const char *format,...) __attribute__((__format__(__printf__
xmlNode * crm_create_nvpair_xml(xmlNode *parent, const char *id, const char *name, const char *value)
Create an XML name/value pair.
Definition: xml.c:4314
#define XML_RSC_ATTR_INTERNAL_RSC
Definition: msg_xml.h:204
gboolean xml_contains_remote_node(xmlNode *xml)
Definition: remote.c:81
#define ID(x)
Definition: msg_xml.h:412
unsigned long long flags
Definition: status.h:97
#define safe_str_eq(a, b)
Definition: util.h:54
xmlNode * pe_create_remote_xml(xmlNode *parent, const char *uname, const char *container_id, const char *migrateable, const char *is_managed, const char *start_timeout, const char *server, const char *port)
Definition: remote.c:140
GList * GListPtr
Definition: crm.h:190
enum node_type type
Definition: status.h:155
#define XML_OP_ATTR_ALLOW_MIGRATE
Definition: msg_xml.h:217
pe_check_parameters
Definition: status.h:140
gboolean is_rsc_baremetal_remote_node(resource_t *rsc, pe_working_set_t *data_set)
Definition: remote.c:15
#define XML_AGENT_ATTR_CLASS
Definition: msg_xml.h:227
char * id
Definition: status.h:259