19 #include <sys/types.h> 26 static cib_t *fake_cib = NULL;
27 static GList *fake_resource_list = NULL;
28 static const GList *fake_op_fail_list = NULL;
31 const char *use_date);
46 char *action_name = NULL;
47 const char *prefix =
"";
48 const char *action_host = NULL;
49 const char *history_id = NULL;
50 const char *task =
action->task;
52 if (
action->node != NULL) {
53 action_host =
action->node->priv->name;
55 action_host =
"<none>";
60 task =
action->cancel_task;
64 history_id =
action->rsc->priv->history_id;
67 if (history_id != NULL) {
69 guint interval_ms = 0;
78 const char *n_type = g_hash_table_lookup(
action->meta,
80 const char *n_task = g_hash_table_lookup(
action->meta,
81 "notify_key_operation");
89 if (action_host != NULL) {
91 prefix, key, action_host);
99 const char *op = g_hash_table_lookup(
action->meta,
103 prefix,
action->task, op, action_host);
105 }
else if (
action->rsc && action_host) {
107 prefix,
action->uuid, action_host);
109 }
else if (action_host) {
111 prefix,
action->task, action_host);
121 action_name = with_id;
138 uint32_t section_opts,
const char *title,
149 all = g_list_prepend(all, (gpointer)
"*");
152 out->
begin_list(out, NULL, NULL,
"%s", title);
153 out->
message(out,
"cluster-status",
175 out->
begin_list(out, NULL, NULL,
"Transition Summary");
192 const char *use_date,
unsigned int flags)
196 set_effective_date(
scheduler,
true, use_date);
223 bool all_actions,
bool verbose)
226 FILE *dot_strm = fopen(dot_file,
"w");
228 if (dot_strm == NULL) {
232 fprintf(dot_strm,
" digraph \"g\" {\n");
235 const char *style =
"dashed";
236 const char *font =
"black";
237 const char *color =
"black";
238 char *action_name = create_action_name(
action, verbose);
248 }
else if ((
action->rsc != NULL)
268 fprintf(dot_strm,
"\"%s\" [ style=%s color=\"%s\" fontcolor=\"%s\"]\n",
269 action_name, style, color, font);
277 for (GList *before_iter =
action->actions_before;
278 before_iter != NULL; before_iter = before_iter->next) {
282 char *before_name = NULL;
283 char *after_name = NULL;
284 const char *style =
"dashed";
285 bool optional =
true;
299 if (all_actions || !optional) {
300 before_name = create_action_name(before->
action, verbose);
301 after_name = create_action_name(
action, verbose);
302 fprintf(dot_strm,
"\"%s\" -> \"%s\" [ style = %s]\n",
303 before_name, after_name, style);
310 fprintf(dot_strm,
"}\n");
329 profile_file(
const char *xml_file,
long long repeat,
333 xmlNode *cib_object = NULL;
364 for (
int i = 0; i < repeat; ++i) {
365 xmlNode *
input = cib_object;
371 set_effective_date(
scheduler,
false, use_date);
377 out->
message(out,
"profile", xml_file, start, end);
385 struct dirent **namelist;
387 int file_num = scandir(dir, &namelist, 0, alphasort);
393 char buffer[FILENAME_MAX];
398 if (
'.' == namelist[file_num]->d_name[0]) {
399 free(namelist[file_num]);
404 free(namelist[file_num]);
407 snprintf(buffer,
sizeof(buffer),
"%s/%s",
408 dir, namelist[file_num]->d_name);
409 if (stat(buffer, &prop) == 0 && S_ISREG(prop.st_mode)) {
410 profile_file(buffer, repeat,
scheduler, use_date);
412 free(namelist[file_num]);
435 const char *use_date)
438 time_t original_date = 0;
447 out->
info(out,
"Setting effective cluster time: %s", use_date);
451 }
else if (original_date != 0) {
454 if (print_original) {
459 out->
info(out,
"Using the original execution date of: %s", when);
481 out->
message(out,
"inject-pseudo-action", node, task);
503 const char *rtype = NULL;
504 const char *rclass = NULL;
505 const char *resource = NULL;
506 const char *rprovider = NULL;
507 const char *resource_config_name = NULL;
512 xmlNode *cib_node = NULL;
513 xmlNode *cib_resource = NULL;
524 crm_debug(
"No history injection for %s op on %s", operation, node);
528 if (action_rsc == NULL) {
540 if (resource_config_name == NULL) {
545 resource = resource_config_name;
549 if ((longname != NULL)
558 out->
message(out,
"inject-rsc-action", resource, operation, node,
575 ((router_node == NULL)? uuid: node));
581 resource_config_name,
582 rclass, rtype, rprovider);
583 if (cib_resource == NULL) {
584 crm_err(
"Could not simulate action %d history for resource %s",
593 target_outcome,
"User-injected result");
594 out->
message(out,
"inject-rsc-action", resource, op->
op_type, node,
598 for (
const GList *iter = fake_op_fail_list;
599 iter != NULL; iter = iter->next) {
600 const char *spec = (
const char *) iter->data;
602 const char *match_name = NULL;
603 const char *offset = NULL;
608 if (strncasecmp(key, spec, strlen(key)) == 0) {
609 match_name = resource;
614 if ((match_name == NULL)
615 && (strcmp(resource, resource_config_name) != 0)) {
619 if (strncasecmp(key, spec, strlen(key)) == 0) {
620 match_name = resource_config_name;
625 if (match_name == NULL) {
630 rc = sscanf(spec,
"%*[^=]=%d", (
int *) &op->
rc);
632 out->
err(out,
"Invalid failed operation '%s' " 633 "(result code must be integer)", spec);
637 out->
info(out,
"Pretending action %d failed with rc=%d",
688 out->
message(out,
"inject-cluster-action", node, task, rsc);
712 GString *xpath = g_string_sized_new(512);
729 fake_cib->
cmds->
remove(fake_cib, (
const char *) xpath->str, NULL,
732 g_string_truncate(xpath, 0);
737 fake_cib->
cmds->
remove(fake_cib, (
const char *) xpath->str, NULL,
741 g_string_free(xpath, TRUE);
752 const GList *op_fail_list)
758 simulate_pseudo_action,
759 simulate_resource_action,
760 simulate_cluster_action,
761 simulate_fencing_action,
767 fake_op_fail_list = op_fail_list;
770 out->
begin_list(out, NULL, NULL,
"Executing Cluster Transition");
781 fake_resource_list = NULL;
784 out->
err(out,
"Transition failed: %s",
787 out->
err(out,
"An invalid transition was produced");
793 xmlNode *cib_object = NULL;
794 int rc = fake_cib->
cmds->
query(fake_cib, NULL, &cib_object,
808 uint32_t section_opts,
const char *use_date,
809 const char *input_file,
const char *graph_file,
810 const char *dot_file)
814 xmlNodePtr
input = NULL;
836 printed = out->
info(out,
837 "%d of %d resource instances DISABLED and " 838 "%d BLOCKED from further action due to failure",
848 section_opts,
"Current cluster status",
856 || (injections->
node_up != NULL)
862 || (injections->
watchdog != NULL)) {
879 if (input_file != NULL) {
902 "Assignment Scores and Utilization Information");
907 out->
begin_list(out, NULL, NULL,
"Assignment Scores");
912 out->
begin_list(out, NULL, NULL,
"Utilization Information");
927 if (logger_out == NULL) {
937 if (graph_file != NULL) {
946 if (dot_file != NULL) {
947 rc = write_sim_dotfile(
scheduler, dot_file,
977 set_effective_date(
scheduler,
true, use_date);
987 print_cluster_status(
scheduler, 0, section_opts,
"Revised Cluster Status",
998 unsigned int section_opts,
const char *use_date,
999 const char *input_file,
const char *graph_file,
1000 const char *dot_file)
1014 use_date, input_file, graph_file, dot_file);
void(* end_list)(pcmk__output_t *out)
#define PCMK__XA_OPERATION_KEY
xmlNode * pcmk__xml_copy(xmlNode *parent, xmlNode *src)
xmlNode * pcmk__xe_first_child(const xmlNode *parent, const char *node_name, const char *attr_n, const char *attr_v)
Actions are ordered if on same node (or migration target for migrate_to)
enum pcmk__graph_status pcmk__simulate_transition(pcmk_scheduler_t *scheduler, cib_t *cib, const GList *op_fail_list)
G_GNUC_INTERNAL void pcmk__inject_failcount(pcmk__output_t *out, cib_t *cib_conn, xmlNode *cib_node, const char *resource, const char *task, guint interval_ms, int rc, bool infinity)
Control output from tools.
#define PCMK__XA_ROUTER_NODE
int pcmk__scan_min_int(const char *text, int *result, int minimum)
#define crm_time_log_timeofday
#define PCMK_VALUE_INFINITY
int cib__signon_query(pcmk__output_t *out, cib_t **cib, xmlNode **cib_object)
bool pcmk__strcase_any_of(const char *s,...) G_GNUC_NULL_TERMINATED
int(* message)(pcmk__output_t *out, const char *message_id,...)
crm_time_t * pcmk__copy_timet(time_t source)
#define PCMK_XE_PRIMITIVE
#define PCMK__OP_FMT
printf-style format to create operation key from resource, action, interval
int crm_element_value_epoch(const xmlNode *xml, const char *name, time_t *dest)
Retrieve the seconds-since-epoch value of an XML attribute.
pcmk_resource_t * pe_find_resource(GList *rsc_list, const char *id)
char * failed_start_offset
Failcount after one failed start action.
G_GNUC_INTERNAL xmlNode * pcmk__inject_node_state_change(cib_t *cib_conn, const char *node, bool up)
G_GNUC_INTERNAL xmlNode * pcmk__inject_action_result(xmlNode *cib_resource, lrmd_event_data_t *op, const char *node, int target_rc)
void pe_reset_working_set(pcmk_scheduler_t *scheduler)
Reset scheduler data to default state without freeing it.
#define PCMK__META_OP_TARGET_RC
bool(* is_quiet)(pcmk__output_t *out)
#define PCMK_ACTION_META_DATA
crm_exit_t pcmk_rc2exitc(int rc)
Map a function return code to the most similar exit code.
int pcmk__update_configured_schema(xmlNode **xml, bool to_logs)
Update XML from its configured schema to the latest major series.
pcmk__scheduler_private_t * priv
G_GNUC_INTERNAL xmlNode * pcmk__inject_node(cib_t *cib_conn, const char *node, const char *uuid)
#define PCMK__META_STONITH_ACTION
void pcmk__schedule_actions(xmlNode *cib, unsigned long long flags, pcmk_scheduler_t *scheduler)
enum crm_exit_e crm_exit_t
void pcmk__xml_output_finish(pcmk__output_t *out, crm_exit_t exit_status, xmlNodePtr *xml)
#define CRM_LOG_ASSERT(expr)
int(* info)(pcmk__output_t *out, const char *format,...) G_GNUC_PRINTF(2
#define PCMK__META_ON_NODE
gboolean cluster_status(pcmk_scheduler_t *scheduler)
#define PCMK_XA_OPERATION
xmlNode * pcmk__xe_create(xmlNode *parent, const char *name)
#define PCMK__XE_TRANSIENT_ATTRIBUTES
void pcmk__xml_free(xmlNode *xml)
const char * crm_xml_add(xmlNode *node, const char *name, const char *value)
Create an XML attribute with specified name and value.
#define PCMK__OUTPUT_SPACER_IF(out_obj, cond)
char * crm_time_as_string(const crm_time_t *dt, int flags)
Get a string representation of a crm_time_t object.
enum pcmk__graph_status pcmk__execute_graph(pcmk__graph_t *graph)
int pcmk__guint_from_hash(GHashTable *table, const char *key, guint default_val, guint *result)
char * failed_stop_offset
Failcount after one failed stop action.
cib_api_operations_t * cmds
#define crm_debug(fmt, args...)
int pcmk__simulate(pcmk_scheduler_t *scheduler, pcmk__output_t *out, const pcmk_injections_t *injections, unsigned int flags, uint32_t section_opts, const char *use_date, const char *input_file, const char *graph_file, const char *dot_file)
void pcmk__set_graph_functions(pcmk__graph_functions_t *fns)
xmlNode * pcmk_find_cib_element(xmlNode *cib, const char *element_name)
Find an element in the CIB.
int pcmk__xml_write_file(const xmlNode *xml, const char *filename, bool compress)
char * crm_element_value_copy(const xmlNode *data, const char *name)
Retrieve a copy of the value of an XML attribute.
const char * crm_element_value(const xmlNode *data, const char *name)
Retrieve the value of an XML attribute.
int pcmk__xml_output_new(pcmk__output_t **out, xmlNodePtr *xml)
lrmd_event_data_t * pcmk__event_from_graph_action(const xmlNode *resource, const pcmk__graph_action_t *action, int status, int rc, const char *exit_reason)
void pcmk__g_strcat(GString *buffer,...) G_GNUC_NULL_TERMINATED
bool pcmk__validate_xml(xmlNode *xml_blob, const char *validation, xmlRelaxNGValidityErrorFunc error_handler, void *error_handler_context)
#define pcmk_is_set(g, f)
Convenience alias for pcmk_all_flags_set(), to check single flag.
int(* modify)(cib_t *cib, const char *section, xmlNode *data, int call_options)
bool pcmk_str_is_infinity(const char *s)
int(*) int(*) void(* err)(pcmk__output_t *out, const char *format,...) G_GNUC_PRINTF(2
void pcmk__update_graph(pcmk__graph_t *graph, const pcmk__graph_action_t *action)
#define PCMK_ACTION_START
#define PCMK__META_ON_NODE_UUID
void pcmk__register_lib_messages(pcmk__output_t *out)
void pcmk__free_graph(pcmk__graph_t *graph)
void(* finish)(pcmk__output_t *out, crm_exit_t exit_status, bool print, void **copy_dest)
Action completed, result is known.
int(* query)(cib_t *cib, const char *section, xmlNode **output_data, int call_options)
#define PCMK_ACTION_STONITH
#define PCMK_ACTION_NOTIFIED
#define crm_time_log(level, prefix, dt, flags)
int pcmk_legacy2rc(int legacy_rc)
G_GNUC_INTERNAL void pcmk__output_actions(pcmk_scheduler_t *scheduler)
int(* replace)(cib_t *cib, const char *section, xmlNode *data, int call_options)
void pe__register_messages(pcmk__output_t *out)
#define PCMK_ACTION_DELETE
char * pcmk__op_key(const char *rsc_id, const char *op_type, guint interval_ms)
Generate an operation key (RESOURCE_ACTION_INTERVAL)
int cib__clean_up_connection(cib_t **cib)
Function and executable result codes.
pcmk__graph_t * pcmk__unpack_graph(const xmlNode *xml_graph, const char *reference)
#define PCMK_ACTION_CANCEL
void cleanup_calculations(pcmk_scheduler_t *scheduler)
Reset scheduler data to defaults without freeing it or constraints.
void pcmk__output_free(pcmk__output_t *out)
xmlNode * pcmk__xml_read(const char *filename)
int pcmk_simulate(xmlNodePtr *xml, pcmk_scheduler_t *scheduler, const pcmk_injections_t *injections, unsigned int flags, unsigned int section_opts, const char *use_date, const char *input_file, const char *graph_file, const char *dot_file)
Simulate a cluster's response to events.
#define pcmk__assert(expr)
char * pcmk__notify_key(const char *rsc_id, const char *notify_type, const char *op_type)
#define crm_log_xml_err(xml, text)
#define PCMK_META_INTERVAL
#define crm_err(fmt, args...)
pcmk_scheduler_t * scheduler
#define pcmk__set_graph_action_flags(action, flags_to_set)
crm_time_t * crm_time_new(const char *string)
Synthetic cluster events that can be injected into the cluster for running simulations.
G_GNUC_INTERNAL void pcmk__inject_scheduler_input(pcmk_scheduler_t *scheduler, cib_t *cib, const pcmk_injections_t *injections)
void lrmd_free_event(lrmd_event_data_t *event)
Free an executor event.
This structure contains everything that makes up a single output formatter.
void(* begin_list)(pcmk__output_t *out, const char *singular_noun, const char *plural_noun, const char *format,...) G_GNUC_PRINTF(4
const char * pcmk__graph_status2text(enum pcmk__graph_status state)
#define PCMK__XE_NODE_STATE
#define PCMK_XA_EXECUTION_DATE
#define pcmk__set_action_flags(action, flags_to_set)
void pcmk__profile_dir(const char *dir, long long repeat, pcmk_scheduler_t *scheduler, const char *use_date)
void pcmk__log_graph(unsigned int log_level, pcmk__graph_t *graph)
int(* remove)(cib_t *cib, const char *section, xmlNode *data, int call_options)
G_GNUC_INTERNAL xmlNode * pcmk__inject_resource_history(pcmk__output_t *out, xmlNode *cib_node, const char *resource, const char *lrm_name, const char *rclass, const char *rtype, const char *rprovider)
const char * crm_meta_value(GHashTable *hash, const char *field)
Get the value of a meta-attribute.
#define PCMK_XA_CRM_DEBUG_ORIGIN
#define pcmk__set_scheduler_flags(scheduler, flags_to_set)
#define crm_time_log_date
bool pcmk__ends_with_ext(const char *s, const char *match)
int pcmk__log_output_new(pcmk__output_t **out)
#define PCMK_ACTION_NOTIFY
No relation (compare with equality rather than bit set)
#define PCMK_SCORE_INFINITY
Integer score to use to represent "infinity".
char * crm_strdup_printf(char const *format,...) G_GNUC_PRINTF(1