GSList * gcluster_get_service_types(addr_info_t *addr, long timeout, GError ** error) { static struct code_handler_s codes[] = { {206, REPSEQ_BODYMANDATORY, &container_list_content_handler, NULL}, {200, REPSEQ_FINAL, &container_list_content_handler, NULL}, {0, 0, NULL, NULL}}; GSList *srvtypes = NULL; struct reply_sequence_data_s data = { &srvtypes, 0, codes }; MESSAGE req = NULL; req = build_request(NAME_MSGNAME_CS_GET_SRVNAMES, NULL, 0, error); if (req == NULL) { GSETERROR(error, "Failed to build request %s", NAME_MSGNAME_CS_GET_SRVNAMES); goto error_buildreq; } /*reads the answers */ if (!metaXClient_reply_sequence_run_from_addrinfo(error, req, addr, timeout, &data)) { GSETERROR(error, "Cannot execute the query %s and receive all the responses", NAME_MSGNAME_CS_GET_SRVNAMES); goto error_reply; } message_destroy(req, NULL); return (srvtypes); error_reply: message_destroy(req, NULL); error_buildreq: return (NULL); }
gint gcluster_push_virtual_ns_space_used(addr_info_t * addr, long timeout, GHashTable *space_used, GError ** error) { static struct code_handler_s codes[] = { {200, REPSEQ_FINAL, NULL, NULL}, {0, 0, NULL, NULL} }; struct reply_sequence_data_s data = { NULL, 0, codes }; MESSAGE req = NULL; GByteArray *buf = NULL; GSList *kv_list = NULL; /* send the hashtable in the body */ kv_list = key_value_pairs_convert_from_map(space_used, FALSE, error); if (!kv_list) { GSETERROR(error, "Conversion HashTable->List failure"); return (0); } /*encode the list */ buf = key_value_pairs_marshall_gba(kv_list, error); if (!buf) { GSETERROR(error, "Failed to marshall kv list"); goto error_marshall; } req = build_request(NAME_MSGNAME_CS_PUSH_VNS_SPACE_USED, buf->data, buf->len, error); if (req == NULL) { GSETERROR(error, "Failed to build request %s", NAME_MSGNAME_CS_PUSH_VNS_SPACE_USED); goto error_buildreq; } /*reads the answers */ if (!metaXClient_reply_sequence_run_from_addrinfo(error, req, addr, timeout, &data)) { GSETERROR(error, "Cannot execute the query %s and receive all the responses", NAME_MSGNAME_CS_PUSH_BROKEN_CONT); goto error_reply; } message_destroy(req, NULL); g_byte_array_free(buf, TRUE); if(kv_list) { g_slist_foreach(kv_list, g_free1, NULL); g_slist_free(kv_list); } return (1); error_reply: message_destroy(req, NULL); error_buildreq: g_byte_array_free(buf, TRUE); error_marshall: if(kv_list) { g_slist_foreach(kv_list, g_free1, NULL); g_slist_free(kv_list); } return (0); }
namespace_info_t * gcluster_get_namespace_info(addr_info_t * addr, long timeout, GError ** error) { static struct code_handler_s codes[] = { {200, REPSEQ_FINAL, &namespace_info_handler, NULL}, {0, 0, NULL, NULL} }; namespace_info_t *ns_info = NULL; struct reply_sequence_data_s data = { &ns_info, 0, codes }; MESSAGE req = NULL; req = build_request(NAME_MSGNAME_CS_GETNS, NULL, 0, error); if (req == NULL) { GSETERROR(error, "Failed to build request %s", NAME_MSGNAME_CS_GETNS); goto error_buildreq; } /*reads the answers */ if (!metaXClient_reply_sequence_run_from_addrinfo(error, req, addr, timeout, &data)) { GSETERROR(error, "Cannot execute the query %s and receive all the responses", NAME_MSGNAME_CS_GETNS); goto error_reply; } message_destroy(req, NULL); return (ns_info); error_reply: message_destroy(req, NULL); error_buildreq: return (NULL); }
GHashTable* gridd_stats_remote (addr_info_t *ai, gint ms, GError **err, const gchar *pattern) { GHashTable *ht=NULL; struct code_handler_s codes [] = { { CODE_FINAL_OK, REPSEQ_FINAL, NULL, field_extractor }, { CODE_PARTIAL_CONTENT, 0, NULL, field_extractor }, { 0, 0, NULL, NULL }, }; struct reply_sequence_data_s data = { &ht , 0 , codes }; /*create the result hash table*/ ht = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); if (!ht) { GSETERROR(err, "cannot create a hashtable"); return NULL; } /*create and fill the request*/ GByteArray *gba_pattern = g_byte_array_append(g_byte_array_new(), (guint8*)pattern, strlen(pattern)); MESSAGE request = metautils_message_create_named("REQ_STATS"); metautils_message_add_fields_gba (request, MSGKEY_PATTERN, gba_pattern, NULL); g_byte_array_free(gba_pattern, TRUE); if (!request) { GSETERROR(err, "Cannot create a message"); goto errorLabel; } /*run the reply sequence*/ if (!metaXClient_reply_sequence_run_from_addrinfo(err, request, ai, ms, &data)) { GSETERROR(err, "Cannot execute the request and parse the answers"); goto errorLabel; } metautils_message_destroy (request); return ht; errorLabel: if (ht) g_hash_table_destroy (ht); metautils_message_destroy (request); return NULL; }
gint gcluster_push_services(addr_info_t * addr, long timeout, GSList * services_list, gboolean lock_action, GError ** error) { static struct code_handler_s codes[] = { {200, REPSEQ_FINAL, NULL, NULL}, {0, 0, NULL, NULL} }; struct reply_sequence_data_s data = { NULL, 0, codes }; MESSAGE req = NULL; GByteArray *buf = NULL; buf = service_info_marshall_gba(services_list, error); if (!buf) { GSETERROR(error, "Failed to marshall services list"); goto error_marshall; } req = build_request(NAME_MSGNAME_CS_PUSH_SRV, buf->data, buf->len, error); if (req == NULL) { GSETERROR(error, "Failed to build request %s", NAME_MSGNAME_CS_PUSH_SRV); goto error_buildreq; } if (lock_action) message_add_field(req, "LOCK", sizeof("LOCK") - 1, "true", sizeof("true") - 1, NULL); /*reads the answers */ if (!metaXClient_reply_sequence_run_from_addrinfo(error, req, addr, timeout, &data)) { GSETERROR(error, "Cannot execute the query %s and receive all the responses", NAME_MSGNAME_CS_PUSH_SRV); goto error_reply; } message_destroy(req, NULL); g_byte_array_free(buf, TRUE); return (1); error_reply: message_destroy(req, NULL); error_buildreq: g_byte_array_free(buf, TRUE); error_marshall: return (0); }
gint gcluster_rm_broken_container(addr_info_t * addr, long timeout, GSList * container_list, GError ** error) { static struct code_handler_s codes[] = { {200, REPSEQ_FINAL, NULL, NULL}, {0, 0, NULL, NULL} }; struct reply_sequence_data_s data = { NULL, 0, codes }; MESSAGE req = NULL; GByteArray *buf = NULL; buf = meta2_maintenance_names_marshall(container_list, error); if (!buf) { GSETERROR(error, "Failed to marshall container list"); goto error_marshall; } req = build_request(NAME_MSGNAME_CS_RM_BROKEN_CONT, buf->data, buf->len, error); if (req == NULL) { GSETERROR(error, "Failed to build request %s", NAME_MSGNAME_CS_RM_BROKEN_CONT); goto error_buildreq; } /*reads the answers */ if (!metaXClient_reply_sequence_run_from_addrinfo(error, req, addr, timeout, &data)) { GSETERROR(error, "Cannot execute the query %s and receive all the responses", NAME_MSGNAME_CS_RM_BROKEN_CONT); goto error_reply; } message_destroy(req, NULL); g_byte_array_free(buf, TRUE); return (1); error_reply: message_destroy(req, NULL); error_buildreq: g_byte_array_free(buf, TRUE); error_marshall: return (0); }
void gcluster_update_conf(addr_info_t * addr, long timeout, const gchar *srv_type, GHashTable *options, gboolean no_overwrite, GError **error) { static struct code_handler_s codes[] = { {200, REPSEQ_FINAL, NULL, NULL}, {0, 0, NULL, NULL} }; struct reply_sequence_data_s data = { NULL, 0, codes }; MESSAGE req = NULL; GString *body = g_string_sized_new(64); GHashTableIter iter; gpointer key, value; g_hash_table_iter_init(&iter, options); while (g_hash_table_iter_next(&iter, &key, &value)) { if (!value) value = ""; if (srv_type) g_string_append_printf(body, "%s_%s=%s\n", srv_type, (gchar*)key, (gchar*)value); else g_string_append_printf(body, "%s=%s\n", (gchar*)key, (gchar*)value); } req = build_request(NAME_MSGNAME_OCTO_CONF_UPDATE, body->str, body->len, error); g_string_free(body, TRUE); if (!req) return; if (no_overwrite) message_add_fields_str(req, NAME_HEADER_NO_OVERWRITE, "True", NULL); metaXClient_reply_sequence_run_from_addrinfo(error, req, addr, timeout, &data); message_destroy(req, NULL); }
GByteArray * gcluster_get_srvtype_event_config(addr_info_t * addr, long to, gchar * name, GError ** error) { static struct code_handler_s codes[] = { {200, REPSEQ_FINAL, &body_to_gba_handler, NULL}, {0, 0, NULL, NULL} }; GByteArray *result = NULL; struct reply_sequence_data_s data = { &result, 0, codes }; MESSAGE req = NULL; if (!addr || !name || to<0L) { GSETERROR(error,"Invalid parameter (%p %p)", addr, name); return NULL; } req = build_request(NAME_MSGNAME_CS_GET_EVENT_CONFIG, NULL, 0, error); if (req == NULL) { GSETERROR(error, "Failed to build request "NAME_MSGNAME_CS_GET_EVENT_CONFIG); return NULL; } if (!message_add_field(req, "TYPENAME", sizeof("TYPENAME") - 1, name, strlen(name), NULL)) { GSETERROR(error, "Failed to add the service typ name in the request headers"); message_destroy(req, NULL); return NULL; } result = g_byte_array_new(); if (!metaXClient_reply_sequence_run_from_addrinfo(error, req, addr, to, &data)) { GSETERROR(error, "Cannot execute the query "NAME_MSGNAME_CS_GET_EVENT_CONFIG" and receive all the responses"); g_byte_array_free(result, TRUE); message_destroy(req, NULL); return NULL; } message_destroy(req, NULL); return result; }