| 363 | } |
| 364 | |
| 365 | gboolean |
| 366 | unpack_rsc_location(xmlNode * xml_obj, pe_working_set_t * data_set) |
| 367 | { |
| 368 | gboolean empty = TRUE; |
| 369 | rsc_to_node_t *location = NULL; |
| 370 | const char *id_lh = crm_element_value(xml_obj, "rsc"); |
| 371 | const char *id = crm_element_value(xml_obj, XML_ATTR_ID); |
| 372 | resource_t *rsc_lh = pe_find_resource(data_set->resources, id_lh); |
| 373 | const char *node = crm_element_value(xml_obj, "node"); |
| 374 | const char *score = crm_element_value(xml_obj, XML_RULE_ATTR_SCORE); |
| 375 | const char *domain = crm_element_value(xml_obj, XML_CIB_TAG_DOMAIN); |
| 376 | const char *role = crm_element_value(xml_obj, XML_RULE_ATTR_ROLE); |
| 377 | |
| 378 | if (rsc_lh == NULL) { |
| 379 | /* only a warn as BSC adds the constraint then the resource */ |
| 380 | crm_config_warn("No resource (con=%s, rsc=%s)", id, id_lh); |
| 381 | return FALSE; |
| 382 | } |
| 383 | |
| 384 | if (domain) { |
| 385 | GListPtr nodes = g_hash_table_lookup(data_set->domains, domain); |
| 386 | |
| 387 | if (domain == NULL) { |
| 388 | crm_config_err("Invalid constraint %s: Domain %s does not exist", id, domain); |
| 389 | return FALSE; |
| 390 | } |
| 391 | |
| 392 | location = rsc2node_new(id, rsc_lh, 0, NULL, data_set); |
| 393 | location->node_list_rh = node_list_dup(nodes, FALSE, FALSE); |
| 394 | |
| 395 | } else if (node != NULL && score != NULL) { |
| 396 | int score_i = char2score(score); |
| 397 | node_t *match = pe_find_node(data_set->nodes, node); |
| 398 | |
| 399 | if (!match) { |
| 400 | return FALSE; |
| 401 | } |
| 402 | location = rsc2node_new(id, rsc_lh, score_i, match, data_set); |
| 403 | |
| 404 | } else { |
| 405 | xmlNode *rule_xml = NULL; |
| 406 | |
| 407 | for (rule_xml = __xml_first_child(xml_obj); rule_xml != NULL; |
| 408 | rule_xml = __xml_next(rule_xml)) { |
| 409 | if (crm_str_eq((const char *)rule_xml->name, XML_TAG_RULE, TRUE)) { |
| 410 | empty = FALSE; |
| 411 | crm_trace("Unpacking %s/%s", id, ID(rule_xml)); |
| 412 | generate_location_rule(rsc_lh, rule_xml, data_set); |
| 413 | } |
| 414 | } |
| 415 | |
| 416 | if (empty) { |
| 417 | crm_config_err("Invalid location constraint %s:" |
| 418 | " rsc_location must contain at least one rule", ID(xml_obj)); |
| 419 | } |
| 420 | } |
| 421 | |
| 422 | if (location && role) { |
no test coverage detected