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 *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);
101 const char *op = g_hash_table_lookup(
action->meta,
"stonith_action");
104 prefix,
action->task, op, action_host);
106 }
else if (
action->rsc && action_host) {
108 prefix,
action->uuid, action_host);
110 }
else if (action_host) {
112 prefix,
action->task, action_host);
122 action_name = with_id;
139 uint32_t section_opts,
const char *title,
150 all = g_list_prepend(all, (gpointer)
"*");
153 out->
begin_list(out, NULL, NULL,
"%s", title);
154 out->
message(out,
"cluster-status",
156 false, section_opts, show_opts, NULL, all, all);
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 = (repeat == 1)? cib_object :
copy_xml(cib_object);
368 set_effective_date(
scheduler,
false, use_date);
374 out->
message(out,
"profile", xml_file, start, end);
382 struct dirent **namelist;
384 int file_num = scandir(dir, &namelist, 0, alphasort);
390 char buffer[FILENAME_MAX];
395 if (
'.' == namelist[file_num]->d_name[0]) {
396 free(namelist[file_num]);
401 free(namelist[file_num]);
404 snprintf(buffer,
sizeof(buffer),
"%s/%s",
405 dir, namelist[file_num]->d_name);
406 if (stat(buffer, &prop) == 0 && S_ISREG(prop.st_mode)) {
407 profile_file(buffer, repeat,
scheduler, use_date);
409 free(namelist[file_num]);
432 const char *use_date)
435 time_t original_date = 0;
443 out->
info(out,
"Setting effective cluster time: %s", use_date);
447 }
else if (original_date != 0) {
450 if (print_original) {
454 out->
info(out,
"Using the original execution date of: %s", when);
476 out->
message(out,
"inject-pseudo-action", node, task);
498 const char *rtype = NULL;
499 const char *rclass = NULL;
500 const char *resource = NULL;
501 const char *rprovider = NULL;
502 const char *resource_config_name = NULL;
507 xmlNode *cib_node = NULL;
508 xmlNode *cib_resource = NULL;
518 crm_debug(
"No history injection for %s op on %s", operation, node);
522 if (action_rsc == NULL) {
534 if (resource_config_name == NULL) {
539 resource = resource_config_name;
543 if ((longname != NULL)
552 out->
message(out,
"inject-rsc-action", resource, operation, node,
569 ((router_node == NULL)? uuid: node));
575 resource_config_name,
576 rclass, rtype, rprovider);
577 if (cib_resource == NULL) {
578 crm_err(
"Could not simulate action %d history for resource %s",
587 target_outcome,
"User-injected result");
588 out->
message(out,
"inject-rsc-action", resource, op->
op_type, node,
592 for (
const GList *iter = fake_op_fail_list;
593 iter != NULL; iter = iter->next) {
594 const char *spec = (
const char *) iter->data;
596 const char *match_name = NULL;
601 if (strncasecmp(key, spec, strlen(key)) == 0) {
602 match_name = resource;
607 if ((match_name == NULL)
608 && (strcmp(resource, resource_config_name) != 0)) {
612 if (strncasecmp(key, spec, strlen(key)) == 0) {
613 match_name = resource_config_name;
618 if (match_name == NULL) {
623 rc = sscanf(spec,
"%*[^=]=%d", (
int *) &op->
rc);
625 out->
err(out,
"Invalid failed operation '%s' " 626 "(result code must be integer)", spec);
630 out->
info(out,
"Pretending action %d failed with rc=%d",
670 out->
message(out,
"inject-cluster-action", node, task, rsc);
694 GString *xpath = g_string_sized_new(512);
711 fake_cib->
cmds->
remove(fake_cib, (
const char *) xpath->str, NULL,
714 g_string_truncate(xpath, 0);
719 fake_cib->
cmds->
remove(fake_cib, (
const char *) xpath->str, NULL,
723 g_string_free(xpath, TRUE);
734 const GList *op_fail_list)
740 simulate_pseudo_action,
741 simulate_resource_action,
742 simulate_cluster_action,
743 simulate_fencing_action,
749 fake_op_fail_list = op_fail_list;
752 out->
begin_list(out, NULL, NULL,
"Executing Cluster Transition");
763 fake_resource_list = NULL;
766 out->
err(out,
"Transition failed: %s",
769 out->
err(out,
"An invalid transition was produced");
775 xmlNode *cib_object = NULL;
776 int rc = fake_cib->
cmds->
query(fake_cib, NULL, &cib_object,
790 uint32_t section_opts,
const char *use_date,
791 const char *input_file,
const char *graph_file,
792 const char *dot_file)
796 xmlNodePtr
input = NULL;
825 printed = out->
info(out,
826 "%d of %d resource instances DISABLED and " 827 "%d BLOCKED from further action due to failure",
837 section_opts,
"Current cluster status",
845 || (injections->
node_up != NULL)
851 || (injections->
watchdog != NULL)) {
868 if (input_file != NULL) {
892 "Assignment Scores and Utilization Information");
897 out->
begin_list(out, NULL, NULL,
"Assignment Scores");
902 out->
begin_list(out, NULL, NULL,
"Utilization Information");
917 if (logger_out == NULL) {
927 if (graph_file != NULL) {
935 if (dot_file != NULL) {
936 rc = write_sim_dotfile(
scheduler, dot_file,
966 set_effective_date(
scheduler,
true, use_date);
976 print_cluster_status(
scheduler, 0, section_opts,
"Revised Cluster Status",
987 unsigned int section_opts,
const char *use_date,
988 const char *input_file,
const char *graph_file,
989 const char *dot_file)
1003 use_date, input_file, graph_file, dot_file);
void(* end_list)(pcmk__output_t *out)
Actions are ordered if on same node (or migration target for migrate_to)
Whether action should not be executed.
enum pcmk__graph_status pcmk__simulate_transition(pcmk_scheduler_t *scheduler, cib_t *cib, const GList *op_fail_list)
#define pe__set_action_flags(action, flags_to_set)
Control output from tools.
int pcmk__scan_min_int(const char *text, int *result, int minimum)
#define crm_time_log_timeofday
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__OP_FMT
printf-style format to create operation key from resource, action, interval
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)
void pe_reset_working_set(pcmk_scheduler_t *scheduler)
Reset scheduler data to default state without freeing it.
bool(* is_quiet)(pcmk__output_t *out)
Implementation of pcmk_action_t.
#define PCMK_ACTION_META_DATA
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
Whether node scores should be output instead of logged.
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.
#define pe__set_working_set_flags(scheduler, flags_to_set)
int write_xml_file(const xmlNode *xml, 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)
void pcmk__schedule_actions(xmlNode *cib, unsigned long long flags, pcmk_scheduler_t *scheduler)
enum crm_exit_e crm_exit_t
GList * actions
Scheduled actions.
#define CRM_LOG_ASSERT(expr)
int(* info)(pcmk__output_t *out, const char *format,...) G_GNUC_PRINTF(2
xmlNode * filename2xml(const char *filename)
Implementation of pcmk_scheduler_t.
gboolean cluster_status(pcmk_scheduler_t *scheduler)
int ninstances
Total number of resource instances.
gboolean validate_xml(xmlNode *xml_blob, const char *validation, gboolean to_logs)
GList * resources
Resources in cluster.
#define PCMK__OUTPUT_SPACER_IF(out_obj, cond)
#define XML_LRM_ATTR_TASK_KEY
xmlNode * copy_xml(xmlNode *src_node)
#define XML_LRM_ATTR_TASK
Whether to show node and resource utilization (in log or output)
char * crm_time_as_string(const crm_time_t *dt, int flags)
Get a string representation of a crm_time_t object.
pcmk_resource_t * pe_find_resource(GList *rsc_list, const char *id_rh)
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...)
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__inject_scheduler_input(pcmk_scheduler_t *scheduler, cib_t *cib, const pcmk_injections_t *injections)
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.
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
void * priv
For Pacemaker use only.
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 blocked_resources
Number of blocked resources in cluster.
int(* modify)(cib_t *cib, const char *section, xmlNode *data, int call_options)
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 XML_AGENT_ATTR_PROVIDER
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)
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 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 XML_LRM_ATTR_ROUTER_NODE
#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)
void free_xml(xmlNode *child)
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
Whether sensitive resource attributes have been masked.
void cleanup_calculations(pcmk_scheduler_t *scheduler)
Reset scheduler data to defaults without freeing it or constraints.
#define XML_LRM_ATTR_TARGET_UUID
void pcmk__output_free(pcmk__output_t *out)
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.
char * pcmk__notify_key(const char *rsc_id, const char *notify_type, const char *op_type)
#define crm_log_xml_err(xml, text)
Whether action is runnable.
#define crm_err(fmt, args...)
pcmk_scheduler_t * scheduler
Whether action does not require invoking an agent.
char * pcmk__our_nodename
Node name of the local node.
#define pcmk__set_graph_action_flags(action, flags_to_set)
int disabled_resources
Number of disabled resources in cluster.
crm_time_t * crm_time_new(const char *string)
Synthetic cluster events that can be injected into the cluster for running simulations.
void lrmd_free_event(lrmd_event_data_t *event)
Free an executor event.
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)
enum pe_action_flags flags
Group of enum pe_action_flags.
void pcmk__xml_output_finish(pcmk__output_t *out, xmlNodePtr *xml)
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)
#define XML_CIB_TAG_STATUS
Whether action has been added to transition graph.
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)
#define XML_LRM_ATTR_TARGET
unsigned long long flags
Group of enum pcmk_scheduler_flags.
gboolean cli_config_update(xmlNode **xml, int *best_version, gboolean to_logs)
Whether resource is managed.
Whether cluster is in maintenance mode (via maintenance-mode property)
crm_time_t * now
Current time for evaluation purposes.
#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 PCMK_ACTION_NOTIFY
No relation (compare with equality rather than bit set)
#define XML_AGENT_ATTR_CLASS
xmlNode * graph
Transition graph.