Esempio n. 1
0
static void node_op_history_clear(struct assembly *assembly)
{
	qb_map_iter_t *iter;
	struct operation_history *oh;
	const char *key;
	struct resource *r;

	qb_enter();

	iter = qb_map_iter_create(op_history_map);
	while ((key = qb_map_iter_next(iter, (void **)&oh)) != NULL) {
		r = oh->resource;

		if (r->assembly == assembly) {
			/* stop the recurring monitor.
			 */
			if (qb_loop_timer_is_running(NULL, r->monitor_timer) &&
			    r->monitor_op) {
				recurring_monitor_stop(r->monitor_op);
			}

			qb_map_rm(op_history_map, key);
			free(oh->rsc_id);
			free(oh->operation);
			free(oh->op_digest);
			free(oh);
		}
	}
	qb_map_iter_free(iter);

	qb_leave();
}
Esempio n. 2
0
File: map.c Progetto: originin/libqb
void
qb_map_foreach(struct qb_map *map, qb_map_transverse_fn func, void *user_data)
{
	const char *key;
	void *value;
	qb_map_iter_t *i = qb_map_iter_create(map);

	for (key = qb_map_iter_next(i, &value);
	     key; key = qb_map_iter_next(i, &value)) {
		if (func(key, value, user_data)) {
			goto clean_up;
		}
	}
clean_up:
	qb_map_iter_free(i);
}
Esempio n. 3
0
/*
 * find all resources that have an ip or hostname parameter reference
 * and update them.
 *
 * We are looking for something like this:
 *
 * <parameter name=\"mysql_ip\" type=\"scalar\"><reference assembly=\"mysql\" parameter=\"ipaddress\"/></parameter>
 * <parameter name=\"mysql_hostname\" type=\"scalar\"><reference assembly=\"mysql\" parameter=\"hostname\"/></parameter>
 */
static void
node_update_addr_info(struct assembly *a_changed)
{
	struct assembly *a;
	struct resource *r;
	struct reference_param *p;
	const char *a_name;
	const char *r_name;
	const char *p_name;
	qb_map_iter_t *a_iter;
	qb_map_iter_t *r_iter;
	qb_map_iter_t *p_iter;

	a_iter = qb_map_iter_create(assembly_map);
	while ((a_name = qb_map_iter_next(a_iter, (void**)&a)) != NULL) {
		r_iter = qb_map_iter_create(a->resource_map);
		while ((r_name = qb_map_iter_next(r_iter, (void**)&r)) != NULL) {
			if (r->ref_params_map == NULL) {
				continue;
			}
			/* See if there is a reference parameter that references
			 * the changed node.
			 */
			p_iter = qb_map_iter_create(r->ref_params_map);
			while ((p_name = qb_map_iter_next(p_iter, (void**)&p)) != NULL) {
				if (p->xmlnode &&
				    strcmp(p->assembly, a_changed->name) == 0) {
					if (strcmp(p->parameter, "hostname") == 0) {
						/* FIXME we probably need to get
						 * the real hostname
						 */
						xmlSetProp(p->xmlnode, BAD_CAST "value",
							   BAD_CAST a_changed->name);
					} else {
						xmlSetProp(p->xmlnode, BAD_CAST "value",
							   BAD_CAST a_changed->address);
					}
				}
			}
			qb_map_iter_free(p_iter);
		}
		qb_map_iter_free(r_iter);
	}
	qb_map_iter_free(a_iter);
}
Esempio n. 4
0
int
main(void)
{
	qb_map_t *trie;
	int *i1, *i2, *i3;
	qb_map_iter_t *iter;
	const char *key;
	void *val;
	uint32_t revents = (QB_MAP_NOTIFY_DELETED |
			    QB_MAP_NOTIFY_REPLACED |
			    QB_MAP_NOTIFY_INSERTED |
			    QB_MAP_NOTIFY_RECURSIVE);

	trie = qb_trie_create();
	assert(trie != NULL);
	qb_trie_dump(trie);
	add_cs_keys(trie);

	i1 = malloc(sizeof(int));
	assert(i1 != NULL);
	*i1 = 1;

	i2 = malloc(sizeof(int));
	assert(i2 != NULL);
	*i2 = 2;

	i3 = malloc(sizeof(int));
	assert(i3 != NULL);
	*i3 = 3;

	qb_map_notify_add(trie, NULL, notify_fn, QB_MAP_NOTIFY_FREE, NULL);

	qb_map_put(trie, "test.key1", i1);
	qb_map_put(trie, "test.key2", i2);

	qb_map_notify_add(trie, "test.", notify_fn, revents, NULL);
	qb_trie_dump(trie);

	qb_map_put(trie, "test.key1", i3);

	iter = qb_map_pref_iter_create(trie, "test.");
	while ((key = qb_map_iter_next(iter, &val)) != NULL) {
		fprintf(stderr, "Iter %s [%d]\n", key, *(int *)val);
		qb_map_rm(trie, key);
	}
	qb_map_iter_free(iter);
	qb_map_notify_del_2(trie, "test.", notify_fn, revents, NULL);
	qb_map_destroy(trie);

	return (0);
}
Esempio n. 5
0
void cape_exit(void)
{
	struct assembly *assembly;
	qb_map_iter_t *iter;

	qb_enter();

	iter = qb_map_iter_create(assembly_map);
	while ((qb_map_iter_next(iter, (void **)&assembly)) != NULL) {
		transport_disconnect(assembly);
	}
	qb_map_iter_free(iter);

	qb_leave();
}
Esempio n. 6
0
static void insert_status(xmlNode *status, struct assembly *assembly)
{
	struct operation_history *oh;
	xmlNode *resource_xml;
	xmlNode *resources_xml;
	xmlNode *lrm_xml;
	struct resource *resource;
	qb_map_iter_t *iter;

	qb_enter();

	qb_log(LOG_DEBUG, "Inserting assembly %s", assembly->name);

	xmlNode *node_state = xmlNewChild(status, NULL, BAD_CAST "node_state", NULL);
        xmlNewProp(node_state, BAD_CAST "id", BAD_CAST assembly->uuid);
        xmlNewProp(node_state, BAD_CAST "uname", BAD_CAST assembly->name);
        xmlNewProp(node_state, BAD_CAST "ha", BAD_CAST "active");
        xmlNewProp(node_state, BAD_CAST "expected", BAD_CAST "member");
        xmlNewProp(node_state, BAD_CAST "in_ccm", BAD_CAST "true");
        xmlNewProp(node_state, BAD_CAST "crmd", BAD_CAST "online");

	/* check state*/
	if (assembly->recover.state == RECOVER_STATE_RUNNING) {
		xmlNewProp(node_state, BAD_CAST "join", BAD_CAST "member");
		qb_log(LOG_DEBUG, "Assembly '%s' marked as member",
			assembly->name);

	} else {
		xmlNewProp(node_state, BAD_CAST "join", BAD_CAST "pending");
		qb_log(LOG_DEBUG, "Assembly '%s' marked as pending",
			assembly->name);
	}
	lrm_xml = xmlNewChild(node_state, NULL, BAD_CAST "lrm", NULL);
	resources_xml = xmlNewChild(lrm_xml, NULL, BAD_CAST "lrm_resources", NULL);
	iter = qb_map_iter_create(op_history_map);
	while ((qb_map_iter_next(iter, (void **)&oh)) != NULL) {
		resource = oh->resource;

		if (strstr(resource->name, assembly->name) == NULL) {
			continue;
		}
		resource_xml = insert_resource(resources_xml, oh->resource);
		op_history_insert(resource_xml, oh);
	}
	qb_map_iter_free(iter);

	qb_leave();
}
Esempio n. 7
0
static void process(void)
{
	xmlNode *cur_node;
	xmlNode *status;
	int rc;
	struct assembly *assembly;
	qb_map_iter_t *iter;
	static xmlNode *pe_root;

	qb_enter();

	/*
	 * Remove status descriptor
	 */
	pe_root = xmlDocGetRootElement(_pe);
	for (cur_node = pe_root->children; cur_node; cur_node = cur_node->next) {
		if (cur_node->type == XML_ELEMENT_NODE &&
			strcmp((char*)cur_node->name, "status") == 0) {

			xmlUnlinkNode(cur_node);
			xmlFreeNode(cur_node);
			break;
		}
	}

	status = xmlNewChild(pe_root, NULL, BAD_CAST "status", NULL);
	iter = qb_map_iter_create(assembly_map);
	while ((qb_map_iter_next(iter, (void **)&assembly)) != NULL) {
		insert_status(status, assembly);
	}
	qb_map_iter_free(iter);

	rc = pe_process_state(_pe, resource_execute_cb,
			      transition_completed_cb,
			      NULL, cape_debug);

	if (rc != 0) {
		schedule_processing();
	}

	qb_leave();
}
Esempio n. 8
0
const char *icmap_iter_next(icmap_iter_t iter, size_t *value_len, icmap_value_types_t *type)
{
	struct icmap_item *item;
	const char *res;

	res = qb_map_iter_next(iter, (void **)&item);
	if (res == NULL) {
		return (res);
	}

	if (value_len != NULL) {
		*value_len = item->value_len;
	}

	if (type != NULL) {
		*type = item->type;
	}

	return (res);
}
Esempio n. 9
0
static void op_history_delete(struct pe_operation *op)
{
	struct resource *r;
	qb_map_iter_t *iter;
	const char *key;
	struct operation_history *oh;

	qb_enter();

	/*
	 * Delete this resource from any operational histories
	 */
	iter = qb_map_iter_create(op_history_map);
	while ((key = qb_map_iter_next(iter, (void **)&oh)) != NULL) {
		r = (struct resource *)oh->resource;

		if (r == op->resource) {
			/* stop the recurring monitor.
			 */
			if (qb_loop_timer_is_running(NULL, r->monitor_timer) &&
			    r->monitor_op) {
				recurring_monitor_stop(r->monitor_op);
			}

			qb_map_rm(op_history_map, key);
			free(oh->rsc_id);
			free(oh->operation);
			free(oh->op_digest);
			free(oh);
		}
	}
	qb_map_iter_free(iter);

	qb_util_stopwatch_stop(op->time_execed);
	pe_resource_completed(op, OCF_OK);
	pe_resource_unref(op);

	qb_leave();
}