static gboolean dump_container_properties(gs_container_t * container) { GSList *properties = NULL, *list = NULL; struct metacnx_ctx_s cnx; gchar path[1024]; int output_fd; GError *error = NULL; metacnx_clear(&cnx); if (!metacnx_init_with_addr(&cnx, &(container->meta2_addr), &error)) { PRINT_ERROR("Invalid META2 address : %s", error->message); g_clear_error(&error); return FALSE; } /* Change default timeout */ cnx.timeout.req = 10000; cnx.timeout.cnx = 10000; if (!meta2_remote_list_all_container_properties(&cnx, container->cID, &properties, &error)) { PRINT_ERROR("Failed to list container properties : %s", error->message); g_clear_error(&error); return FALSE; } metacnx_close(&cnx); metacnx_clear(&cnx); /* open container properties file */ memset(path, '\0', sizeof(path)); g_snprintf(path, sizeof(path), "%s/container.properties", base_dir); output_fd = open(path, O_EXCL | O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR); if (output_fd < 0) { PRINT_ERROR("Failed to open [%s] as the container properties target : %s\n", path, strerror(errno)); return FALSE; } /* Print container properties to file */ if (g_slist_length(properties)>0) { for (list = properties; list && list->data; list = list->next) { gchar *txt = g_strdup_printf("%s\n", (char*)list->data); write_to_fd(&output_fd, txt, strlen(txt)); g_free(txt); } } /*then adjust the file rights */ fchmod(output_fd, S_IRGRP | S_IRUSR | S_IWUSR); close(output_fd); g_slist_foreach(properties, gslist_free_element, g_free); g_slist_free(properties); return TRUE; }
GSList * gcluster_get_services2(addr_info_t * addr, long to_cnx, long to_req, const gchar * type, GError ** error) { GSList *result; struct metacnx_ctx_s cnx_ctx; (void) type; metacnx_clear(&cnx_ctx); memcpy(&(cnx_ctx.addr), addr, sizeof(addr_info_t)); cnx_ctx.timeout.cnx = to_cnx; cnx_ctx.timeout.req = to_req; result = _get_services(&cnx_ctx, type, error, FALSE); metacnx_close(&cnx_ctx); return result; }
static gboolean _open_meta2_connection(struct metacnx_ctx_s *cnx, const gchar *m2_url, gs_error_t **e) { GError *ge = NULL; gboolean ret = FALSE; metacnx_clear(cnx); if (!metacnx_init_with_url(cnx, m2_url, &ge)) { GSERRORCAUSE(e, ge, "Invalid META2 address"); goto clean; } ret = TRUE; clean: if (ge) g_error_free(ge); return ret; }
static int add_event(gs_grid_storage_t * gs, const char *cName, const char *msg) { int rc = -1; gs_error_t **gserr = NULL; gs_error_t *locerr = NULL; struct gs_container_location_s *location = NULL; container_id_t cid; struct metacnx_ctx_s cnx; gchar *hexid = NULL; gchar * meta2_url = NULL; GError *gerr = NULL; metacnx_clear(&cnx); if (!gs || !cName || !msg) { PRINT_ERROR("Invalid parameter (%p %p %p)\n", gs, cName, msg); return rc; } location = gs_locate_container_by_name(gs, cName, &locerr); if (!location) { PRINT_ERROR("cannot find %s\n", cName); goto exit_label; } if (!location->m0_url || !location->m1_url || !location->m2_url || !location->m2_url[0]) { PRINT_ERROR("cannot find %s\n", cName); goto exit_label; } PRINT_DEBUG("%s found\n", cName); hexid = location->container_hexid; meta2_url = location->m2_url[0]; if (!container_id_hex2bin(hexid, strlen(hexid), &cid, &gerr)) { GSERRORCAUSE(gserr, gerr, "Invalid container id"); goto exit_label; } if (!metacnx_init_with_url(&cnx, meta2_url, &gerr)) { GSERRORCAUSE(gserr, gerr, "Invalid META2 address"); goto exit_label; } container_event_t event; bzero(&event, sizeof(event)); event.timestamp = time(0); g_strlcpy(event.type, "test", sizeof(event.type)); g_strlcpy(event.ref, "test", sizeof(event.type)); event.message = metautils_gba_from_string(msg); PRINT_DEBUG("Adding event [%s]", msg); rc = meta2_remote_add_container_event(&cnx, cid, &event, &gerr); g_byte_array_free(event.message, TRUE); event.message = NULL; metacnx_close(&cnx); metacnx_clear(&cnx); if (!rc) { PRINT_ERROR("Failed to add event : %s\n", gerror_get_message(gerr)); g_clear_error(&gerr); } exit_label: return rc; }