/* * _hostrange_output * * Output metric data in hostrange format. The algorithm involves * using the metric_value as a hash key. Each hash item will then * store the hosts with the same metric_value/key. */ static void _hostrange_output(List l) { #if CEREBRO_DEBUG const char *func = __FUNCTION__; #endif /* CEREBRO_DEBUG */ struct node_metric_data *data = NULL; ListIterator litr = NULL; unsigned int count; hash_t h; assert(l); count = List_count(l); #if CEREBRO_DEBUG if (!count) err_exit("%s: invalid count", func); #endif /* CEREBRO_DEBUG */ h = Hash_create(count, (hash_key_f)hash_key_string, (hash_cmp_f)strcmp, (hash_del_f)_hostrange_data_destroy); litr = List_iterator_create(l); while ((data = list_next(litr))) { char buf[CEREBRO_STAT_BUFLEN]; struct hostrange_data *hd; _metric_value_str(data->metric_value_type, data->metric_value_len, data->metric_value, buf, CEREBRO_STAT_BUFLEN); if (!(hd = Hash_find(h, buf))) { hd = Malloc(sizeof(struct hostrange_data)); hd->hl = Hostlist_create(NULL); hd->key = Strdup(buf); Hash_insert(h, hd->key, hd); } Hostlist_push(hd->hl, data->nodename); } Hash_for_each(h, _hostrange_output_data, NULL); /* No need to destroy list iterator, caller will destroy List */ Hash_destroy(h); }
/* * _forwarding_setup * * 'index' is the index of the message config and forwarding info. * * Returns 0 success, -1 on error */ static int _forwarding_setup(int index) { hostlist_iterator_t itr = NULL; char *node; int rv = -1; assert(index >= 0 && index < conf.forward_message_config_len); /* We require a separate hostlist here b/c the hosts input by the * user and/or received by the remote hosts need to be mapped to a * single hostname. */ if ((forwarding_info[index].fd = _forwarding_setup_socket(index)) < 0) goto cleanup; if (conf.forward_message_config[index].hosts) { forwarding_info[index].hosts = Hostlist_create(NULL); itr = Hostlist_iterator_create(conf.forward_message_config[index].hosts); while ((node = Hostlist_next(itr))) { char nodebuf[CEREBRO_MAX_NODENAME_LEN+1]; char *nodeptr; if (found_clusterlist_module) { if (clusterlist_module_get_nodename(clusterlist_handle, node, nodebuf, CEREBRO_MAX_NODENAME_LEN+1) < 0) { CEREBROD_DBG(("clusterlist_module_get_nodename: %s", nodebuf)); Hostlist_destroy(forwarding_info[index].hosts); goto cleanup; } nodeptr = nodebuf; } else nodeptr = node; Hostlist_push(forwarding_info[index].hosts, nodeptr); free(node); } } else forwarding_info[index].hosts = NULL; Pthread_mutex_init(&(forwarding_info[index].lock), NULL); rv = 0; cleanup: if (itr) Hostlist_iterator_destroy(itr); return rv; }
/* * _cluster_nodes_output * * Output cluster nodes */ static void _cluster_nodes_output(List l) { struct node_metric_data *data = NULL; hostlist_t hl = NULL; ListIterator litr = NULL; assert(l); litr = List_iterator_create(l); if (output_type == CEREBRO_STAT_HOSTRANGE) hl = Hostlist_create(NULL); while ((data = list_next(litr))) { if (output_type == CEREBRO_STAT_NEWLINE) fprintf(stdout, "%s\n", data->nodename); if (output_type == CEREBRO_STAT_HOSTRANGE) Hostlist_push(hl, data->nodename); } if (output_type == CEREBRO_STAT_HOSTRANGE) { char hstr[CEREBRO_STAT_BUFLEN]; Hostlist_sort(hl); Hostlist_uniq(hl); memset(hstr, '\0', CEREBRO_STAT_BUFLEN); Hostlist_ranged_string(hl, CEREBRO_STAT_BUFLEN, hstr); fprintf(stdout, "%s\n", hstr); } /* No need to destroy list iterator, caller will destroy List */ if (hl) Hostlist_destroy(hl); }