enum ocf_exitcode pe_resource_ocf_exitcode_get(struct pe_operation *op, int lsb_exitcode) { qb_enter(); if (strcmp(op->rclass, "lsb") == 0 && strcmp("monitor", op->method) == 0) { switch(lsb_exitcode) { case LSB_STATUS_OK: return OCF_OK; case LSB_STATUS_VAR_PID: return OCF_NOT_RUNNING; case LSB_STATUS_VAR_LOCK: return OCF_NOT_RUNNING; case LSB_STATUS_NOT_RUNNING: return OCF_NOT_RUNNING; case LSB_STATUS_NOT_INSTALLED: return OCF_UNKNOWN_ERROR; default: return OCF_UNKNOWN_ERROR; } } else if (lsb_exitcode > LSB_NOT_RUNNING) { qb_leave(); return OCF_UNKNOWN_ERROR; } /* For non-status operations, the LSB and OCF share error code meaning * for rc <= 7 */ qb_leave(); return (enum ocf_exitcode)lsb_exitcode; }
void instance_create_from_image_id(char *image_id, void (*completion_func)(char *instance_id, void *data), void *data) { struct deltacloud_api api; char *instance_id; int rc; rc = deltacloud_initialize(&api, "http://localhost:3001/api", "dep-wp", ""); if (rc < 0) { qb_log(LOG_ERR, "Failed to initialize libdeltacloud: %s", deltacloud_get_last_error_string()); qb_leave(); return; } rc = deltacloud_create_instance(&api, image_id, NULL, 0, &instance_id); if (rc < 0) { qb_log(LOG_ERR, "Failed to initialize libdeltacloud: %s", deltacloud_get_last_error_string()); qb_leave(); return; } completion_func(instance_id, data); deltacloud_free(&api); }
int32_t pe_process_state(xmlDocPtr doc, pe_resource_execute_t exec_fn, pe_transition_completed_t done_fn, void *user_data, int debug) { crm_graph_t *transition = NULL; xmlNode *xml_input = xmlDocGetRootElement(doc); qb_enter(); if (working_set) { qb_log(LOG_ERR, "Transition already in progress"); qb_leave(); return -EEXIST; } transition_count++; if (debug) { char filename[PATH_MAX]; assert(validate_xml(xml_input, "pacemaker-1.2", FALSE) == TRUE); snprintf(filename, PATH_MAX, "/tmp/pe-%d-%d.xml", getpid(), transition_count); xmlSaveFormatFileEnc(filename, doc, "UTF-8", 1); qb_log(LOG_INFO, "Executing deployable transition [%s]", filename); } else { qb_log(LOG_INFO, "Executing deployable transition [%d]", transition_count); } working_set = calloc(1, sizeof(pe_working_set_t)); run_fn = exec_fn; completed_fn = done_fn; run_user_data = user_data; set_graph_functions(&graph_exec_fns); set_working_set_defaults(working_set); /* calculate output */ do_calculations(working_set, xml_input, NULL); transition = unpack_graph(working_set->graph, __func__); //print_graph(LOG_INFO, transition); graph_updated = TRUE; qb_loop_job_add(NULL, QB_LOOP_HIGH, transition, process_next_job); qb_leave(); return 0; }
int32_t pe_is_busy_processing(void) { qb_enter(); if (working_set != NULL) { qb_leave(); return TRUE; } qb_leave(); return FALSE; }
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(); }
void pe_resource_unref(struct pe_operation *op) { qb_enter(); op->refcount--; qb_log(LOG_TRACE, "unref %s_%s_%d refcount:%d", op->rname, op->method, op->interval, op->refcount); if (op->refcount == 0) { crm_free(op->hostname); crm_free(op->rprovider); crm_free(op->rtype); crm_free(op->rclass); crm_free(op->node_uuid); crm_free(op->op_digest); free(op->method); free(op->rname); qb_map_foreach(op->params, qb_map_transverse_rm, op->params); qb_map_destroy(op->params); qb_util_stopwatch_free(op->time_execed); free(op); } qb_leave(); }
const char* pe_resource_reason_get(enum ocf_exitcode exitcode) { qb_enter(); if (exitcode == OCF_PENDING) { qb_leave(); return "Operation pending"; } if (exitcode < OCF_OK || exitcode > OCF_FAILED_MASTER) { qb_leave(); return "Unknown Error"; } else { qb_leave(); return ocf_reasons[exitcode]; } }
static void configure_resource_create(xmlNode *rsc_node, xmlNode *params_node, struct assembly *assembly) { struct resource *resource; char *name; /* 6 = rsc__ and terminator */ char resource_name[ASSEMBLY_NAME_MAX + RESOURCE_NAME_MAX + 6]; qb_enter(); resource = calloc(1, sizeof (struct resource)); name = (char*)xmlGetProp(rsc_node, BAD_CAST "name"); snprintf(resource_name, ASSEMBLY_NAME_MAX + RESOURCE_NAME_MAX + 6, "cfg_%s_%s", assembly->name, name); resource->name = strdup(resource_name); resource->type = strdup("script_runner"); resource->rclass = strdup("ocf"); resource->rprovider = strdup("pacemaker-cloud"); recover_init(&resource->recover, "-1", "-1", resource_recover_restart, resource_recover_escalate, resource_state_change_event); resource->recover.instance = resource; resource->assembly = assembly; qb_map_put(assembly->resource_map, resource->name, resource); resource_add_ref_params(params_node, resource); qb_leave(); }
static void schedule_processing(void) { qb_enter(); qb_loop_job_add(NULL, QB_LOOP_LOW, NULL, process_job); qb_leave(); }
void pe_resource_ref(struct pe_operation *op) { qb_enter(); op->refcount++; qb_leave(); }
static void dup_attr(gpointer key, gpointer value, gpointer user_data) { qb_enter(); qb_map_put(user_data, strdup(key), strdup(value)); qb_leave(); }
static void resource_recover_restart(void * inst) { struct resource *resource = (struct resource *)inst; qb_enter(); qb_loop_timer_del(NULL, resource->monitor_timer); qb_leave(); }
void cape_load_from_buffer(const char *buffer) { qb_enter(); _config = xmlParseMemory(buffer, strlen(buffer)); parse_and_load(); qb_leave(); }
static void node_recover_escalate(void * inst) { // struct assembly *a = (struct assembly *)inst; qb_enter(); qb_leave(); }
static void func_two(void) { qb_enter(); qb_logt(LOG_DEBUG, 0, "arf arf?"); qb_logt(LOG_CRIT, MY_TAG_ONE, "arrrg!"); qb_log(LOG_ERR, "oops, I did it again"); qb_logt(LOG_INFO, MY_TAG_THREE, "are you aware ..."); qb_leave(); }
static void process_next_job(void* data) { crm_graph_t *transition = (crm_graph_t *)data; enum transition_status graph_rc; qb_enter(); if (!graph_updated) { qb_loop_job_add(NULL, QB_LOOP_MED, transition, process_next_job); qb_leave(); return; } graph_updated = FALSE; graph_rc = run_graph(transition); qb_log(LOG_DEBUG, "run_graph returned: %s", transition_status(graph_rc)); if (graph_rc == transition_active || graph_rc == transition_pending) { qb_loop_job_add(NULL, QB_LOOP_MED, transition, process_next_job); qb_leave(); return; } if (graph_rc != transition_complete) { qb_log(LOG_ERR, "Transition failed: %s", transition_status(graph_rc)); } destroy_graph(transition); // we don't want to free the input xml working_set->input = NULL; cleanup_alloc_calculations(working_set); free(working_set); working_set = NULL; completed_fn(run_user_data, graph_rc); qb_leave(); return; }
int pe_resource_is_hard_error(enum ocf_exitcode ec) { qb_enter(); qb_leave(); return (ec == OCF_INVALID_PARAM || ec == OCF_UNIMPLEMENT_FEATURE || ec == OCF_INSUFFICIENT_PRIV || ec == OCF_NOT_INSTALLED || ec == OCF_NOT_CONFIGURED); }
int instance_destroy(struct assembly *a) { qb_enter(); instance_destroy_by_instance_id(a->instance_id, instance_destroy_completion, a); qb_leave(); return 0; }
static void xml_new_time_prop(xmlNode *n, const char *name, time_t val) { char int_str[36]; qb_enter(); snprintf(int_str, 36, "%d", (int)val); xmlNewProp(n, BAD_CAST name, BAD_CAST int_str); qb_leave(); }
static void process_job(void *data) { qb_enter(); if (pe_is_busy_processing()) { schedule_processing(); } else { process(); } qb_leave(); }
static gboolean exec_crmd_action(crm_graph_t *graph, crm_action_t *action) { qb_enter(); action->confirmed = TRUE; update_graph(graph, action); graph_updated = TRUE; qb_leave(); return TRUE; }
void image_id_get(char *image_name, void (*completion_func)(char *image_id, void *data), void *data) { static struct deltacloud_api api; struct deltacloud_image *images_head; struct deltacloud_image *images; int rc; qb_enter(); if (deltacloud_initialize(&api, "http://localhost:3001/api", "dep-wp", "") < 0) { qb_log(LOG_ERR, "Failed to initialize libdeltacloud: %s", deltacloud_get_last_error_string()); qb_leave(); return; } rc = deltacloud_get_images(&api, &images); if (rc < 0) { qb_log(LOG_ERR, "Failed to initialize libdeltacloud: %s", deltacloud_get_last_error_string()); qb_leave(); return; } for (images_head = images; images; images = images->next) { if (strcmp(images->name, image_name) == 0) { completion_func(images->id, data); break; } } deltacloud_free_image_list(&images_head); deltacloud_free(&api); qb_leave(); }
/* * External API */ int32_t instance_create(struct assembly *assembly) { qb_enter(); qb_util_stopwatch_start(assembly->sw_instance_create); image_id_get(assembly->name, image_id_get_completion, assembly); instance_create_from_image_id(assembly->image_id, instance_create_completion, assembly); qb_loop_job_add(NULL, QB_LOOP_LOW, assembly, my_instance_state_get); qb_leave(); return 0; }
static void resources_create(xmlNode *cur_node, struct assembly *assembly) { qb_enter(); for (; cur_node; cur_node = cur_node->next) { if (cur_node->type != XML_ELEMENT_NODE) { continue; } resource_create(cur_node, assembly); } qb_leave(); }
static void resource_execute_cb(struct pe_operation *op) { struct resource *resource; struct assembly *assembly; qb_enter(); assembly = qb_map_get(assembly_map, op->hostname); resource = qb_map_get(assembly->resource_map, op->rname); if (assembly->recover.state != RECOVER_STATE_RUNNING) { qb_log(LOG_DEBUG, "can't execute resource in offline state"); resource_action_completed(op, OCF_UNKNOWN_ERROR); return; } qb_log(LOG_TRACE, "%s_%s_%d [%s] on %s target_rc:%d", op->rname, op->method, op->interval, op->rclass, op->hostname, op->target_outcome); qb_util_stopwatch_start(op->time_execed); op->resource = resource; if (strcmp(op->method, "monitor") == 0) { if (strstr(op->rname, op->hostname) != NULL) { assert(op->resource); if (op->interval > 0) { recurring_monitor_start(op); } else { resource_monitor_execute(op); } } else { qb_util_stopwatch_stop(op->time_execed); pe_resource_completed(op, OCF_NOT_RUNNING); pe_resource_unref(op); } } else if (strcmp (op->method, "start") == 0) { transport_resource_action(assembly, resource, op); } else if (strcmp(op->method, "stop") == 0) { if (resource->monitor_op) { recurring_monitor_stop(resource->monitor_op); } transport_resource_action(assembly, resource, op); } else if (strcmp(op->method, "delete") == 0) { op_history_delete(op); } else { assert(0); } qb_leave(); }
static void log_it_please(void) { qb_enter(); qb_log(LOG_TRACE, "A:%d B:%d C:%d", 1, 2, 3); qb_log(LOG_DEBUG, "A:%d B:%d C:%d", 1, 2, 3); errno = EEXIST; qb_perror(LOG_WARNING, "bogus error"); errno = 0; qb_log(LOG_INFO, "A:%d B:%d C:%d", 1, 2, 3); qb_log(LOG_NOTICE, "A:%d B:%d C:%d", 1, 2, 3); qb_log(LOG_WARNING, "A:%d B:%d C:%d", 1, 2, 3); qb_log(LOG_ERR, "A:%d B:%d C:%d", 1, 2, 3); qb_leave(); }
void pe_resource_completed(struct pe_operation *op, uint32_t return_code) { crm_graph_t *graph = op->graph; crm_action_t *action = op->action; qb_enter(); if (working_set == NULL) { qb_leave(); return; } if (return_code != op->target_outcome) { action->failed = TRUE; graph->abort_priority = INFINITY; } action->confirmed = TRUE; update_graph(graph, action); graph_updated = TRUE; qb_leave(); }
void resource_action_completed(struct pe_operation *op, enum ocf_exitcode pe_exitcode) { uint64_t el; struct assembly *a = qb_map_get(assembly_map, op->hostname);; struct resource *r = qb_map_get(a->resource_map, op->rname); qb_enter(); op->times_executed++; qb_util_stopwatch_stop(op->time_execed); el = qb_util_stopwatch_us_elapsed_get(op->time_execed); qb_log(LOG_INFO, "%s_%s_%d [%s] on %s rc:[%d/%d] time:[%"PRIu64"/%ums]", op->rname, op->method, op->interval, op->rclass, op->hostname, pe_exitcode, op->target_outcome, el / QB_TIME_US_IN_MSEC, op->timeout); if (strstr(op->rname, op->hostname) != NULL) { op_history_save(r, op, pe_exitcode); } if (op->times_executed <= 1) { pe_resource_completed(op, pe_exitcode); } resource_state_set(r, op, pe_exitcode); if (pe_exitcode != op->target_outcome) { schedule_processing(); } if (op->interval > 0) { if (pe_exitcode != op->target_outcome) { /* unreference as not used by the timer anymore. */ pe_resource_unref(op); } else { qb_loop_timer_add(NULL, QB_LOOP_LOW, op->interval * QB_TIME_NS_IN_MSEC, op, resource_monitor_execute, &r->monitor_timer); } } else { pe_resource_unref(op); } qb_leave(); }
static void resource_recover_escalate(void * inst) { struct resource *r = (struct resource *)inst; qb_enter(); qb_log(LOG_NOTICE, "Escalating failure of service %s to node %s:%s", r->name, r->assembly->uuid, r->assembly->name); qb_loop_timer_del(NULL, r->monitor_timer); instance_destroy(r->assembly); qb_leave(); }
static void node_recover_restart(void * inst) { struct assembly *a = (struct assembly *)inst; qb_enter(); transport_disconnect(a); node_op_history_clear(a); instance_create(a); qb_leave(); }