19 #include <sys/types.h> 26 static cib_t *fake_cib = NULL;
27 static GList *fake_resource_list = NULL;
28 static GList *fake_op_fail_list = NULL;
46 char *action_name = NULL;
47 const char *prefix =
"";
48 const char *action_host = NULL;
49 const char *clone_name = NULL;
50 const char *task =
action->task;
52 if (
action->node != NULL) {
53 action_host =
action->node->details->uname;
55 action_host =
"<none>";
60 task =
action->cancel_task;
64 clone_name =
action->rsc->clone_name;
67 if (clone_name != NULL) {
69 guint interval_ms = 0;
79 const char *n_type = g_hash_table_lookup(
action->meta,
81 const char *n_task = g_hash_table_lookup(
action->meta,
82 "notify_key_operation");
91 if (action_host != NULL) {
93 prefix, key, action_host);
100 const char *op = g_hash_table_lookup(
action->meta,
"stonith_action");
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,
bool print_spacer)
147 all = g_list_prepend(all, (gpointer)
"*");
150 out->
begin_list(out, NULL, NULL,
"%s", title);
152 section_opts, show_opts, NULL, all, all);
171 out->
begin_list(out, NULL, NULL,
"Transition Summary");
188 char *use_date,
unsigned int flags)
192 set_effective_date(
data_set,
true, use_date);
219 bool all_actions,
bool verbose)
222 FILE *dot_strm = fopen(dot_file,
"w");
224 if (dot_strm == NULL) {
228 fprintf(dot_strm,
" digraph \"g\" {\n");
231 const char *style =
"dashed";
232 const char *font =
"black";
233 const char *color =
"black";
234 char *action_name = create_action_name(
action, verbose);
244 }
else if ((
action->rsc != NULL)
264 fprintf(dot_strm,
"\"%s\" [ style=%s color=\"%s\" fontcolor=\"%s\"]\n",
265 action_name, style, color, font);
273 GList *gIter2 = NULL;
275 for (gIter2 =
action->actions_before; gIter2 != NULL; gIter2 = gIter2->next) {
278 char *before_name = NULL;
279 char *after_name = NULL;
280 const char *style =
"dashed";
281 bool optional =
true;
294 if (all_actions || !optional) {
295 before_name = create_action_name(before->
action, verbose);
296 after_name = create_action_name(
action, verbose);
297 fprintf(dot_strm,
"\"%s\" -> \"%s\" [ style = %s]\n",
298 before_name, after_name, style);
305 fprintf(dot_strm,
"}\n");
328 xmlNode *cib_object = NULL;
359 for (
int i = 0; i < repeat; ++i) {
360 xmlNode *
input = (repeat == 1)? cib_object :
copy_xml(cib_object);
363 set_effective_date(
data_set,
false, use_date);
369 out->
message(out,
"profile", xml_file, start, end);
376 struct dirent **namelist;
378 int file_num = scandir(dir, &namelist, 0,
alphasort);
384 char buffer[FILENAME_MAX];
389 if (
'.' == namelist[file_num]->d_name[0]) {
390 free(namelist[file_num]);
395 free(namelist[file_num]);
398 snprintf(buffer,
sizeof(buffer),
"%s/%s", dir, namelist[file_num]->d_name);
399 if (stat(buffer, &prop) == 0 && S_ISREG(prop.st_mode)) {
400 profile_file(buffer, repeat,
data_set, use_date);
402 free(namelist[file_num]);
428 time_t original_date = 0;
436 out->
info(out,
"Setting effective cluster time: %s", use_date);
440 }
else if (original_date) {
445 if (print_original) {
449 out->
info(out,
"Using the original execution date of: %s", when);
471 out->
message(out,
"inject-pseudo-action", node, task);
493 const char *rtype = NULL;
494 const char *rclass = NULL;
495 const char *resource = NULL;
496 const char *rprovider = NULL;
497 const char *resource_config_name = NULL;
502 xmlNode *cib_node = NULL;
503 xmlNode *cib_resource = NULL;
513 crm_debug(
"No history injection for %s op on %s", operation, node);
517 if (action_rsc == NULL) {
529 if (resource_config_name == NULL) {
534 resource = resource_config_name;
538 if ((longname != NULL)
546 out->
message(out,
"inject-rsc-action", resource, operation, node,
563 ((router_node == NULL)? uuid: node));
569 resource_config_name,
570 rclass, rtype, rprovider);
571 if (cib_resource == NULL) {
572 crm_err(
"Could not simulate action %d history for resource %s",
581 target_outcome,
"User-injected result");
582 out->
message(out,
"inject-rsc-action", resource, op->
op_type, node,
586 for (GList *iter = fake_op_fail_list; iter != NULL; iter = iter->next) {
587 char *spec = (
char *) iter->data;
589 const char *match_name = NULL;
594 if (strncasecmp(key, spec, strlen(key)) == 0) {
595 match_name = resource;
600 if ((match_name == NULL)
601 && (strcmp(resource, resource_config_name) != 0)) {
605 if (strncasecmp(key, spec, strlen(key)) == 0) {
606 match_name = resource_config_name;
611 if (match_name == NULL) {
616 rc = sscanf(spec,
"%*[^=]=%d", (
int *) &op->
rc);
618 out->
err(out,
"Invalid failed operation '%s' " 619 "(result code must be integer)", spec);
623 out->
info(out,
"Pretending action %d failed with rc=%d",
663 out->
message(out,
"inject-cluster-action", node, task, rsc);
687 GString *xpath = g_string_sized_new(512);
704 fake_cib->
cmds->
remove(fake_cib, (
const char *) xpath->str, NULL,
707 g_string_truncate(xpath, 0);
712 fake_cib->
cmds->
remove(fake_cib, (
const char *) xpath->str, NULL,
716 g_string_free(xpath, TRUE);
733 simulate_pseudo_action,
734 simulate_resource_action,
735 simulate_cluster_action,
736 simulate_fencing_action,
742 fake_op_fail_list = op_fail_list;
745 out->
begin_list(out, NULL, NULL,
"Executing Cluster Transition");
756 fake_resource_list = NULL;
759 out->
err(out,
"Transition failed: %s",
762 out->
err(out,
"An invalid transition was produced");
768 xmlNode *cib_object = NULL;
769 int rc = fake_cib->
cmds->
query(fake_cib, NULL, &cib_object,
783 uint32_t section_opts,
char *use_date,
char *input_file,
784 char *graph_file,
char *dot_file)
788 xmlNodePtr
input = NULL;
806 printed = out->
info(out,
807 "%d of %d resource instances DISABLED and " 808 "%d BLOCKED from further action due to failure",
819 section_opts,
"Current cluster status",
827 || (injections->
node_up != NULL)
833 || (injections->
watchdog != NULL)) {
850 if (input_file != NULL) {
873 "Allocation Scores and Utilization Information");
878 out->
begin_list(out, NULL, NULL,
"Allocation Scores");
883 out->
begin_list(out, NULL, NULL,
"Utilization Information");
898 if (logger_out == NULL) {
908 if (graph_file != NULL) {
916 if (dot_file != NULL) {
917 rc = write_sim_dotfile(
data_set, dot_file,
947 set_effective_date(
data_set,
true, use_date);
957 print_cluster_status(
data_set, 0, section_opts,
"Revised Cluster Status",
968 unsigned int section_opts,
char *use_date,
char *input_file,
969 char *graph_file,
char *dot_file)
983 use_date, input_file, graph_file, dot_file);
void(* end_list)(pcmk__output_t *out)
#define pe__set_action_flags(action, flags_to_set)
void pcmk__inject_scheduler_input(pe_working_set_t *data_set, cib_t *cib, pcmk_injections_t *injections)
Control output from tools.
int pcmk__scan_min_int(const char *text, int *result, int minimum)
#define crm_time_log_timeofday
bool pcmk__strcase_any_of(const char *s,...) G_GNUC_NULL_TERMINATED
int(* message)(pcmk__output_t *out, const char *message_id,...)
Internal tracking for transition graph creation.
#define pe_flag_no_compat
xmlNode * first_named_child(const xmlNode *parent, const char *name)
G_GNUC_INTERNAL xmlNode * pcmk__inject_node_state_change(cib_t *cib_conn, const char *node, bool up)
#define pe_flag_maintenance_mode
bool(* is_quiet)(pcmk__output_t *out)
G_GNUC_INTERNAL void pcmk__inject_failcount(pcmk__output_t *out, xmlNode *cib_node, const char *resource, const char *task, guint interval_ms, int rc)
#define XML_TAG_TRANSIENT_NODEATTRS
int alphasort(const void *dirent1, const void *dirent2)
const char * crm_meta_value(GHashTable *hash, const char *field)
const char * crm_xml_add(xmlNode *node, const char *name, const char *value)
Create an XML attribute with specified name and value.
void lrmd_free_event(lrmd_event_data_t *event)
Free an executor event.
int write_xml_file(xmlNode *xml_node, const char *filename, gboolean compress)
Write XML to a file.
G_GNUC_INTERNAL xmlNode * pcmk__inject_node(cib_t *cib_conn, const char *node, const char *uuid)
enum crm_exit_e crm_exit_t
pe_resource_t * pe_find_resource(GList *rsc_list, const char *id_rh)
#define CRM_LOG_ASSERT(expr)
int(* info)(pcmk__output_t *out, const char *format,...) G_GNUC_PRINTF(2
xmlNode * filename2xml(const char *filename)
gboolean validate_xml(xmlNode *xml_blob, const char *validation, gboolean to_logs)
#define PCMK__OUTPUT_SPACER_IF(out_obj, cond)
#define XML_LRM_ATTR_TASK_KEY
xmlNode * copy_xml(xmlNode *src_node)
int cib__signon_query(cib_t **cib, xmlNode **cib_object)
#define XML_LRM_ATTR_TASK
char * crm_time_as_string(const crm_time_t *dt, int flags)
void pe_reset_working_set(pe_working_set_t *data_set)
Reset a working set to default state without freeing it.
void cleanup_calculations(pe_working_set_t *data_set)
Reset working set to default state without freeing it or constraints.
char * pcmk__notify_key(const char *rsc_id, const char *notify_type, const char *op_type)
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)
cib_api_operations_t * cmds
#define crm_debug(fmt, args...)
void crm_time_set_timet(crm_time_t *target, const time_t *source)
#define pe_flag_sanitized
int pcmk_simulate(xmlNodePtr *xml, pe_working_set_t *data_set, pcmk_injections_t *injections, unsigned int flags, unsigned int section_opts, char *use_date, char *input_file, char *graph_file, char *dot_file)
Simulate a cluster's response to events.
enum pcmk__graph_status pcmk__simulate_transition(pe_working_set_t *data_set, cib_t *cib, GList *op_fail_list)
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.
#define XML_CIB_TAG_RESOURCE
void pcmk__set_graph_functions(pcmk__graph_functions_t *fns)
#define XML_CIB_TAG_STATE
xmlNode * pcmk_find_cib_element(xmlNode *cib, const char *element_name)
Find an element in the CIB.
void pcmk__profile_dir(const char *dir, long long repeat, pe_working_set_t *data_set, char *use_date)
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
char * crm_strdup_printf(char const *format,...) G_GNUC_PRINTF(1
#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)
#define XML_AGENT_ATTR_PROVIDER
int(*) void(* err)(pcmk__output_t *out, const char *format,...) G_GNUC_PRINTF(2
void pcmk__register_lib_messages(pcmk__output_t *out)
void pcmk__free_graph(pcmk__graph_t *graph)
pe_working_set_t * data_set
void(* finish)(pcmk__output_t *out, crm_exit_t exit_status, bool print, void **copy_dest)
xmlNode * create_xml_node(xmlNode *parent, const char *name)
Action completed, result is known.
int(* query)(cib_t *cib, const char *section, xmlNode **output_data, int call_options)
int crm_element_value_epoch(const xmlNode *xml, const char *name, time_t *dest)
Retrieve the seconds-since-epoch value of an XML attribute.
#define crm_time_log(level, prefix, dt, flags)
int pcmk_legacy2rc(int legacy_rc)
int pcmk__simulate(pe_working_set_t *data_set, pcmk__output_t *out, pcmk_injections_t *injections, unsigned int flags, uint32_t section_opts, char *use_date, char *input_file, char *graph_file, char *dot_file)
G_GNUC_INTERNAL void pcmk__output_actions(pe_working_set_t *data_set)
int(* replace)(cib_t *cib, const char *section, xmlNode *data, int call_options)
void pe__register_messages(pcmk__output_t *out)
#define XML_LRM_ATTR_ROUTER_NODE
void free_xml(xmlNode *child)
int cib__clean_up_connection(cib_t **cib)
Function and executable result codes.
char * pcmk__op_key(const char *rsc_id, const char *op_type, guint interval_ms)
Generate an operation key (RESOURCE_ACTION_INTERVAL)
pcmk__graph_t * pcmk__unpack_graph(xmlNode *xml_graph, const char *reference)
#define XML_LRM_ATTR_TARGET_UUID
void pcmk__output_free(pcmk__output_t *out)
void pcmk__update_graph(pcmk__graph_t *graph, pcmk__graph_action_t *action)
#define crm_log_xml_err(xml, text)
#define pe_flag_show_utilization
#define crm_err(fmt, args...)
#define pcmk__set_graph_action_flags(action, flags_to_set)
gboolean cluster_status(pe_working_set_t *data_set)
crm_time_t * crm_time_new(const char *string)
Synthetic cluster events that can be injected into the cluster for running simulations.
This structure contains everything that makes up a single output formatter.
#define XML_LRM_ATTR_INTERVAL_MS
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 pe__set_working_set_flags(working_set, flags_to_set)
enum pe_action_flags flags
void pcmk__xml_output_finish(pcmk__output_t *out, xmlNodePtr *xml)
void pcmk__log_graph(unsigned int log_level, pcmk__graph_t *graph)
#define XML_CIB_TAG_STATUS
G_GNUC_INTERNAL xmlNode * pcmk__inject_action_result(xmlNode *cib_resource, lrmd_event_data_t *op, int target_rc)
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)
Data types for cluster status.
#define XML_LRM_ATTR_TARGET
gboolean cli_config_update(xmlNode **xml, int *best_version, gboolean to_logs)
#define pe_flag_show_scores
void pcmk__schedule_actions(xmlNode *cib, unsigned long long flags, pe_working_set_t *data_set)
#define crm_time_log_date
bool pcmk__ends_with_ext(const char *s, const char *match)
#define XML_ATTR_TE_TARGET_RC
int pcmk__log_output_new(pcmk__output_t **out)
#define XML_AGENT_ATTR_CLASS