static GError * _get_peers(struct sqlx_service_s *ss, struct sqlx_name_s *n, gboolean nocache, gchar ***result) { EXTRA_ASSERT(ss != NULL); EXTRA_ASSERT(result != NULL); gint retries = 1; gchar **peers = NULL; GError *err = NULL; gint64 seq = 1; struct oio_url_s *u = oio_url_empty (); oio_url_set(u, OIOURL_NS, ss->ns_name); if (!sqlx_name_extract (n, u, NAME_SRVTYPE_META2, &seq)) { oio_url_pclean (&u); return BADREQ("Invalid type name: '%s'", n->type); } retry: if (nocache) { hc_decache_reference_service(ss->resolver, u, n->type); if (!result) { oio_url_pclean (&u); return NULL; } } peers = NULL; err = hc_resolve_reference_service(ss->resolver, u, n->type, &peers); if (NULL != err) { g_prefix_error(&err, "Peer resolution error: "); oio_url_clean(u); return err; } gchar **out = filter_services_and_clean(ss, peers, seq, n->type); if (!out) { if (retries-- > 0) { nocache = TRUE; goto retry; } err = NEWERROR(CODE_CONTAINER_NOTFOUND, "Base not managed"); } if (err) { if (out) g_strfreev (out); *result = NULL; } else { *result = out; } oio_url_clean(u); return err; }
static void cli_action(void) { /* Use the client to get a sqlx service */ GRID_DEBUG("Locating [%s] CID[%s]", oio_url_get(url, OIOURL_WHOLE), oio_url_get(url, OIOURL_HEXID)); gchar **srvurlv = NULL; GError *err = hc_resolve_reference_service(resolver, url, type, &srvurlv); if (err != NULL) { GRID_ERROR("Services resolution error: (%d) %s", err->code, err->message); grid_main_set_status(1); return; } if (!srvurlv || !*srvurlv) { GRID_ERROR("Services resolution error: (%d) %s", 0, "No service found"); grid_main_set_status(1); return; } for (gchar **s=srvurlv; *s ;s++) GRID_DEBUG("Located [%s]", *s); gint rc = 0; for (gchar **s=srvurlv; !rc && *s ;s++) { struct meta1_service_url_s *surl; if (!(surl = meta1_unpack_url(*s))) g_printerr("Invalid service URL from meta1 [%s]\n", *s); else { if (!g_ascii_strcasecmp("destroy", query[0])) { rc = do_destroy2(surl); } else { rc = do_queryv(surl); } g_free(surl); } } g_strfreev(srvurlv); }
enum http_rc_e action_dir_srv_list (struct req_args_s *args) { const gchar *type = TYPE(); if (!type) return _reply_format_error (args, NEWERROR( CODE_BAD_REQUEST, "No service type provided")); gchar **urlv = NULL; GError *err = hc_resolve_reference_service (resolver, args->url, type, &urlv); EXTRA_ASSERT ((err != NULL) ^ (urlv != NULL)); if (!err) { if ((args->flags & FLAG_NOEMPTY) && !*urlv) { g_strfreev (urlv); urlv = NULL; return _reply_notfound_error (args, NEWERROR (CODE_NOT_FOUND, "No service linked")); } return _reply_success_json (args, _pack_and_freev_m1url_list (NULL, urlv)); } return _reply_common_error (args, err); }