Пример #1
0
gint
chunk_id_to_string(const chunk_id_t * ci, gchar * dst, gsize dstSize)
{
	gsize offset;
	gchar str_addr[STRLEN_ADDRINFO+1];

	if (!dst || !ci)
		return 0;

	bzero(str_addr, sizeof(str_addr));
	addr_info_to_string(&(ci->addr), str_addr, sizeof(str_addr));

	/*ecrire id.id */
	offset = g_snprintf(dst, dstSize,
			"%02X%02X%02X%02X%02X%02X%02X%02X"
			"%02X%02X%02X%02X%02X%02X%02X%02X"
			"%02X%02X%02X%02X%02X%02X%02X%02X"
			"%02X%02X%02X%02X%02X%02X%02X%02X:%s:%.*s",
			ci->id[0], ci->id[1], ci->id[2], ci->id[3], ci->id[4], ci->id[5], ci->id[6], ci->id[7],
			ci->id[8], ci->id[9], ci->id[10], ci->id[11], ci->id[12], ci->id[13], ci->id[14], ci->id[15],
			ci->id[16], ci->id[17], ci->id[18], ci->id[19], ci->id[20], ci->id[21], ci->id[22], ci->id[23],
			ci->id[24], ci->id[25], ci->id[26], ci->id[27], ci->id[28], ci->id[29], ci->id[30], ci->id[31],
			str_addr,
			LIMIT_LENGTH_VOLUMENAME, ci->vol);

	return MIN(offset,dstSize);
}
static
GPtrArray*
build_meta0_cache (struct resolver_direct_s *r, GError **err)
{
	GSList *m0_list=NULL;
	GPtrArray *array=NULL;

	/*now call the meta0 reference*/
	if (!(m0_list = meta0_remote_get_meta1_all (&(r->meta0), r->timeout.m0.op, err)))
	{
		gchar str_addr[128];
		memset(str_addr, 0x00, sizeof(str_addr));
		addr_info_to_string(&(r->meta0), str_addr, sizeof(str_addr));
		GSETERROR (err,"META0 error : Cannot get the reference from %s", str_addr);
		WARN ("Cannot get the META0 reference from %s", str_addr);
		return NULL;
	}

	array = meta0_utils_list_to_array(m0_list); 

	g_slist_foreach (m0_list, meta0_info_gclean, NULL);
	g_slist_free (m0_list);

	return array;
}
Пример #3
0
size_t
gs_service_get_url(const gs_service_t * service, char *dst, size_t dst_size)
{
	if (!service || !dst || !dst_size)
		return 0;
	return addr_info_to_string(&(service->gss_si->addr), dst, dst_size);
}
Пример #4
0
static void
allservice_check_start_HT(struct namespace_data_s *ns_data, GHashTable *ht)
{
	gsize offset;
	struct taskdata_checksrv_s td_scheme;
	GHashTableIter iter_serv;
	gpointer k, v;

	TRACE_POSITION();

	g_hash_table_iter_init(&iter_serv, ht);
	while (g_hash_table_iter_next(&iter_serv, &k, &v)) {
		struct service_info_s *si = v;

		memset(&td_scheme, 0x00, sizeof(td_scheme));
		offset = g_snprintf(td_scheme.task_name, sizeof(td_scheme.task_name), "%s.", TASK_ID);
		addr_info_to_string(&(si->addr), td_scheme.task_name+offset, sizeof(td_scheme.task_name)-offset);
		g_strlcpy(td_scheme.ns_name, ns_data->name, sizeof(td_scheme.ns_name)-1);

		if (!_agent_check_enabled(si)) {
			GRID_DEBUG("Task [%s] disabled by "
					NAME_TAGNAME_AGENT_CHECK, td_scheme.task_name);
		} else if (!is_task_scheduled(td_scheme.task_name)) {
			GError *error_local = NULL;
			task_t *task = NULL;
			struct taskdata_checksrv_s *task_data;

			TRACE_POSITION();

			agent_get_service_key(si, td_scheme.srv_key, sizeof(td_scheme.srv_key));
			g_strlcpy(td_scheme.srv_key, (gchar*)k, sizeof(td_scheme.srv_key)-1);

			/* prepare the task structure */
			task_data = g_memdup(&td_scheme, sizeof(td_scheme));
			if (!task_data) {
				ERROR("Memory allocation failure");
				continue;
			}

			task = create_task(period_check_services, td_scheme.task_name);
			task = set_task_callbacks(task, _check_tcp_service_task,
					g_free, task_data);
			if (!task) {
				ERROR("Memory allocation failure");
				continue;
			}

			/* now start the task! */
			if (add_task_to_schedule(task, &error_local))
				INFO("Task started: %s", td_scheme.task_name);
			else {
				ERROR("Failed to add task to scheduler [%s] : %s", td_scheme.task_name, gerror_get_message(error_local));
				g_free(task);
			}
			if (error_local)
				g_clear_error(&error_local);
		}
	}
	TRACE_POSITION();
}
Пример #5
0
static gchar*
_chunk_to_rawxlist_element(chunk_info_t *chunk_info)
{
	GString *res = g_string_new(NULL);
	char tmpstr[65];

	// output format: ip:port/id
	addr_info_to_string(&(chunk_info->id.addr), tmpstr, sizeof(tmpstr));
	g_string_append(res, tmpstr);
	g_string_append(res, "/");
	buffer2str(chunk_info->id.id, sizeof(chunk_info->id.id), tmpstr, sizeof(tmpstr));
	g_string_append(res, tmpstr);

	return g_string_free(res, FALSE);
}
Пример #6
0
gs_error_t *
hc_create_container(gs_grid_storage_t *hc, struct hc_url_s *url,
		const char *stgpol, const char *versioning)
{
	GError *err = NULL;
	gs_error_t *e = NULL;
	gs_container_t *c = NULL;
	struct m2v2_create_params_s params = {stgpol, versioning, FALSE};

	c = gs_get_storage_container2(hc, hc_url_get(url, HCURL_REFERENCE),
			&params, 0, &e);

	if (c != NULL) {
		gchar m2[STRLEN_ADDRINFO] = {0};
		addr_info_to_string(&(c->meta2_addr), m2, STRLEN_ADDRINFO);
		err = m2v2_remote_execute_HAS(m2, NULL, url);
		if (err == NULL) {
			e = gs_error_new(CODE_CONTAINER_EXISTS,
					"Failed to create container [%s]: "
					"container already exists in namespace [%s]\n",
					hc_url_get(url, HCURL_REFERENCE), hc_url_get(url, HCURL_NS));
			goto end_label;
		} else if (err->code != CODE_CONTAINER_NOTFOUND) {
			GSERRORCAUSE(&e, err,
					"Failed to check container existence in meta2: ");
			goto end_label;
		} else {
			GRID_WARN("Container exists in meta1 but not in meta2");
		}
	}

	gs_error_free(e);
	e = NULL;
	c = gs_get_storage_container2(hc, hc_url_get(url, HCURL_REFERENCE),
			&params, 1, &e);

	if (c)
		GRID_INFO("Container [%s] created in namespace [%s].\n\n",
				hc_url_get(url, HCURL_REFERENCE), hc_url_get(url, HCURL_NS));

end_label:
	gs_container_free(c);
	g_clear_error(&err);

	return e;
}
Пример #7
0
gsize
meta0_info_to_string(const meta0_info_t * m0i, gchar * dst, gsize dstSize)
{
    gsize i = 0;
    gsize offset;

    offset = g_snprintf(dst, dstSize, "%"G_GSIZE_FORMAT":", m0i->prefixes_size);

    offset += addr_info_to_string(&(m0i->addr), dst + offset, dstSize - offset);

    offset += g_snprintf(dst + offset, dstSize - offset, ":");

    for (i = 0; i < m0i->prefixes_size; i++)
        offset += g_snprintf(dst + offset, dstSize - offset, "%02x", m0i->prefixes[i]);

    return offset;
}
Пример #8
0
GHashTable *
meta0_info_list_map_by_prefix(GSList * mL, GError ** err)
{
    GSList *l;
    GHashTable *mH;

    (void) err;

    mH = g_hash_table_new_full(func_hash_prefix, func_equal_prefix, NULL, func_free_meta0);
    for (l = mL; l; l = l->next) {
        register int i, max;
        meta0_info_t dummy, *arg, *m0i;

        if (!l->data)
            continue;
        arg = (meta0_info_t *) l->data;

        dummy.prefixes_size = 2;
        dummy.prefixes = g_try_malloc(dummy.prefixes_size);
        g_memmove(&(dummy.addr), &(arg->addr), sizeof(addr_info_t));

        for (i = 1, max = arg->prefixes_size - 1; i < max; i += 2) {
            g_memmove(dummy.prefixes, arg->prefixes + i - 1, 2);
            m0i = g_hash_table_lookup(mH, &dummy);
            if (m0i) {	/*prefix already present, we do nothing else a debug */
                if (DEBUG_ENABLED()) {
                    char str_addr[128];

                    addr_info_to_string(&(dummy.addr), str_addr, sizeof(str_addr));
                    DEBUG("double prefix found %02X%02X -> %s", dummy.prefixes[0], dummy.prefixes[1], str_addr);
                }
            }
            else {	/*prefix absent */
                m0i = meta0_info_copy(&dummy);
                g_hash_table_insert(mH, m0i, m0i);
            }
        }
        g_free(dummy.prefixes);
    }
    return mH;
}
Пример #9
0
static gs_error_t *
_get_content(struct metacnx_ctx_s *cnx, struct hc_url_s *url, struct beans_content_s **content)
{
	GSList *beans = NULL;
	char target[STRLEN_ADDRINFO];
	GError *e = NULL;
	gs_error_t *result = NULL;

	addr_info_to_string(&(cnx->addr), target, sizeof(target));

	if(!(e = m2v2_remote_execute_GET(target, url, 0, &beans))) {
		*content = _beans_to_content(beans);
		g_slist_free_full(beans, _bean_clean);
	}

	if(NULL != e) {
		GSERRORCAUSE(&result, e, "Error while retrieving content");
		g_clear_error(&e);
	}

	return result;
}
Пример #10
0
namespace_info_t *
gcluster_get_namespace_info_full(addr_info_t * addr, long timeout, GError ** error)
{
	EXTRA_ASSERT (addr != NULL);
	gchar str[STRLEN_ADDRINFO];
	addr_info_to_string(addr, str, sizeof(str));

	GByteArray *out = NULL;
	GError *err = gridd_client_exec_and_concat (str, ((gdouble)timeout)/1000.0,
			message_marshall_gba_and_clean(metautils_message_create_named(
					NAME_MSGNAME_CS_GET_NSINFO)), &out);
	if (err) {
		g_prefix_error(&err, "request: ");
		g_error_transmit(error, err);
		return NULL;
	}
	
	namespace_info_t *ns_info = namespace_info_unmarshall(out->data, out->len, error);
	if (!ns_info)
		GSETERROR(error, "Decoding error");
	return ns_info;
}
Пример #11
0
static gs_error_t* _m2_touch(struct hc_url_s *hcurl, guint32 flags)
{
	GError*            err    = NULL;
	gs_error_t*        gserr  = NULL;
	gs_container_t*    cid    = NULL;
	gs_grid_storage_t* hc     = NULL;
	GSList*            m2list = NULL;
	addr_info_t*       m2addr = NULL;
	char str_addr[STRLEN_ADDRINFO] = "";
	const char* ns             = NULL;
	const char* content        = NULL;
	const char* container_name = NULL;

	ns             = hc_url_get(hcurl, HCURL_NS);	
	container_name = hc_url_get(hcurl, HCURL_REFERENCE);
	content        = hc_url_get(hcurl, HCURL_PATH);


	/* init grid client */
	if ((ns==NULL) || (strlen(ns)==0)) {
		GSERRORCODE(&gserr, -1, "Invalid namespace");
		return gserr;
	}
	hc = gs_grid_storage_init(ns, &gserr);
	if (!hc) {
		return gserr;
	}

	/* init container_id */
    if ((container_name==NULL) || (strlen(container_name)==0)) {
        GSERRORCODE(&gserr, -1, "Invalid container_name");
        return gserr;
    }

    cid = gs_init_container(hc, container_name, FALSE, &gserr);
	if (!gserr) {		
		if (!cid) {
			gs_grid_storage_free(hc);
			GSERRORCODE(&gserr, -1, "Invalid container_name %s/%s", ns, container_name);
			return gserr;
		}
	} else return gserr;


	/* search meta2 master */
	m2list = gs_resolve_meta2(hc, C0_ID(cid), &err);		
	if (!m2list) {
        GSERRORCODE(&gserr, -1, "Meta2 Resolution error for NAME=[%s] ID=[%s]", C0_NAME(cid), C0_IDSTR(cid));
		if (cid)
	    	gs_container_free (cid);
		gs_grid_storage_free(hc);
        return gserr;
    }
	m2addr = (addr_info_t*) m2list->data;
	addr_info_to_string (m2addr, str_addr, sizeof(str_addr));

	/* execute touch command */
    if (content && strlen(content)>0) 
		err = m2v2_remote_touch_content(str_addr, NULL, hcurl);
	else 
		err = m2v2_remote_touch_container_ex(str_addr, NULL, hcurl, flags);
	
	/* an error occurs ? */
	if (err) {
		GSERRORCAUSE(&gserr, err, "Failed to execute touch command");
        g_clear_error(&err);
	}

	gs_grid_storage_free(hc);
	if (cid)
    	gs_container_free (cid);
	
	return gserr;
}
Пример #12
0
GHashTable *
rawx_client_get_statistics(rawx_session_t * session, const gchar *url, GError ** err)
{
	int rc;
	gchar str_addr[64];
	gsize str_addr_size;
	GHashTable *parsed = NULL;
	GHashTable *result = NULL;
	GByteArray *buffer = NULL;
	ne_request *request = NULL;

	if (!session || !url) {
		GSETERROR(err, "Invalid parameter");
		return NULL;
	}

	ne_set_connect_timeout(session->neon_session, session->timeout.cnx / 1000);
	ne_set_read_timeout(session->neon_session, session->timeout.req / 1000);
	request = ne_request_create(session->neon_session, "GET", url);
	if (!request) {
		GSETERROR(err, "neon request creation error");
		return NULL;
	}

	buffer = g_byte_array_new();
	ne_add_response_body_reader(request, ne_accept_2xx, body_reader, buffer);

	switch (rc = ne_request_dispatch(request)) {
	case NE_OK:
		if (ne_get_status(request)->klass != 2) {
			GSETERROR(err, "RAWX returned an error");
			goto exit;
		}
		else if (!(parsed = body_parser(buffer, err))) {
			GSETERROR(err, "No statistics from the RAWX server");
			goto exit;
		}
		break;
	case NE_ERROR:
	case NE_TIMEOUT:
	case NE_CONNECT:
	case NE_AUTH:
		str_addr_size = addr_info_to_string(&(session->addr), str_addr, sizeof(str_addr));
		GSETERROR(err, "cannot download the stats from [%.*s]' (%s)",
		    (int)str_addr_size, str_addr, ne_get_error(session->neon_session));
		goto exit;
	default:
		GSETERROR(err, "Unexpected return code from the neon library : %d", rc);
		goto exit;
	}

	result = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
	g_hash_table_foreach(parsed, _convert_string_to_double, result);

exit:
	if (buffer != NULL)
		g_byte_array_free(buffer, TRUE);
	if (request != NULL)
		ne_request_destroy(request);
	if (parsed != NULL)
		g_hash_table_destroy(parsed);

	return result;
}
Пример #13
0
gboolean
rawx_client_get_directory_data(rawx_session_t * session, hash_sha256_t chunk_id, struct content_textinfo_s *content,
    struct chunk_textinfo_s *chunk, GError ** error)
{
	int rc;
	gchar str_addr[64];
	gsize str_addr_size;
	gchar str_req[2048];
	gchar str_chunk_id[(sizeof(hash_sha256_t) * 2) + 1];
	GHashTable *result = NULL;
	GByteArray *buffer = NULL;
	ne_request *request = NULL;

	if (!session) {
		GSETERROR(error, "Invalid parameter");
		return FALSE;
	}

	memset(str_chunk_id, '\0', sizeof(str_chunk_id));
	oio_str_bin2hex(chunk_id, sizeof(hash_sha256_t), str_chunk_id, sizeof(str_chunk_id));

	memset(str_req, '\0', sizeof(str_req));
	snprintf(str_req, sizeof(str_req) - 1, "%s/%s", RAWX_REQ_GET_DIRINFO, str_chunk_id);

	ne_set_connect_timeout(session->neon_session, session->timeout.cnx / 1000);
	ne_set_read_timeout(session->neon_session, session->timeout.req / 1000);
	request = ne_request_create(session->neon_session, "HEAD", str_req);
	if (!request) {
		GSETERROR(error, "neon request creation error");
		return FALSE;
	}

	buffer = g_byte_array_new();
	ne_add_response_body_reader(request, ne_accept_2xx, body_reader, buffer);

	switch (rc = ne_request_dispatch(request)) {
		case NE_OK:
			if (ne_get_status(request)->klass != 2) {
				GSETERROR(error, "RAWX returned an error %d : %s",
						ne_get_status(request)->code, ne_get_status(request)->reason_phrase);
				goto error;
			}
			else if (!(result = header_parser(request))) {
				GSETERROR(error, "No attr from the RAWX server");
				goto error;
			}
			break;
		case NE_ERROR:
		case NE_TIMEOUT:
		case NE_CONNECT:
		case NE_AUTH:
			str_addr_size = addr_info_to_string(&(session->addr), str_addr, sizeof(str_addr));
			GSETERROR(error, "cannot download the data from [%.*s]' (%s)",
					(int)str_addr_size, str_addr, ne_get_error(session->neon_session));
			goto error;
		default:
			GSETERROR(error, "Unexpected return code from the neon library : %d", rc);
			goto error;
	}

	g_byte_array_free(buffer, TRUE);
	ne_request_destroy(request);

	/* Fill the textinfo structs */
	parse_chunkinfo_from_rawx(result, content, chunk);
	g_hash_table_destroy(result);
	return TRUE;

error:
	g_byte_array_free(buffer, TRUE);
	ne_request_destroy(request);

	return FALSE;
}
Пример #14
0
static status_t
_get_container_global_property(gs_grid_storage_t *hc, struct metacnx_ctx_s *cnx, container_id_t cid,
			GHashTable **ht, gs_error_t **gserr)
{
	GSList *prop_list = NULL, *l = NULL;
	GError *gerr = NULL;

	// get all properties with current meta2
	if (!meta2_remote_list_all_container_properties(cnx, cid, &prop_list, &gerr)) {

		GSList     *m2_list = NULL;
		addr_info_t *addr    = NULL;
		GSList      *m2      = NULL;
		gchar       str_addr[STRLEN_ADDRINFO];
		struct metacnx_ctx_s cnxOther;
		gs_error_t  *e       = NULL;
		gboolean    bResult  = FALSE;

		// search all meta2 fo current contener
		m2_list = gs_resolve_meta2(hc, cid, &gerr);
		if (!m2_list) {
			GSERRORCAUSE(gserr, gerr, "Failed to get container admin entries, Cannot find meta2(s)");
			if (gerr)
				g_error_free(gerr);
			return 0;
		}

		// test each meta2...
		for (m2=m2_list; m2 ;m2=m2->next) {
			addr = m2->data;
			if (addr) {
				addr_info_to_string(addr, str_addr, sizeof(str_addr));
				DEBUG("Failed to get container admin entries -> test with next meta2 [%s]", str_addr);

				if (!_open_meta2_connection(&cnxOther, str_addr/*ctx->loc->m2_url[0]*/, &e)) {
					GSERRORCODE(gserr, e->code,
							"Failed to open connection to meta2 (%s)\n", str_addr);
					gs_error_free(e);
					continue;
				}

				if (!meta2_remote_list_all_container_properties(&cnxOther, cid, &prop_list, &gerr)) {
					_close_meta2_connection(&cnxOther);
					GSERRORCAUSE(gserr, gerr, "Failed to get container admin entries: %s\n",str_addr);
					continue;

				} else {
					_close_meta2_connection(&cnxOther);
					// no error
					bResult = TRUE;
					break;
				}
			}
		}

		if (m2_list) { 
			g_slist_foreach(m2_list, addr_info_gclean, NULL); 
			g_slist_free(m2_list); 
		}

		if (gerr)
			g_error_free(gerr);

		if (bResult == FALSE) 
			return 0;

	}

	// here: reading properties ok

	*ht = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
	for (l = prop_list; l && l->data; l = l->next) {
		gchar *tmp = l->data;
		gchar **tok = g_strsplit(tmp, "=", 2);
		if (tok[0] && tok[1])
			g_hash_table_insert(*ht, g_strdup(tok[0]), g_strdup(tok[1]));
		g_strfreev(tok);
	}
	g_slist_free_full(prop_list, g_free);

	/* Ensure we have some mandatory properties */
	if(!g_hash_table_lookup(*ht, M2V2_ADMIN_STORAGE_POLICY))
		g_hash_table_insert(*ht, g_strdup(M2V2_ADMIN_STORAGE_POLICY), g_strdup("namespace default"));
	if(!g_hash_table_lookup(*ht, M2V2_ADMIN_VERSIONING_POLICY))
		g_hash_table_insert(*ht, g_strdup(M2V2_ADMIN_VERSIONING_POLICY), g_strdup("namespace default"));
	if(!g_hash_table_lookup(*ht, M2V2_ADMIN_QUOTA))
		g_hash_table_insert(*ht, g_strdup(M2V2_ADMIN_QUOTA), g_strdup("namespace default"));

	return 1;
}
Пример #15
0
static void
_detect_obsolete_services(struct namespace_data_s *ns_data)
{
	guint counter;
	time_t time_now, time_down, time_broken;
	GHashTableIter s_iterator;
	gpointer s_k, s_v;
	gchar *str_key;
	struct service_info_s *si;


	time_now = g_get_real_time()/1000000;
	time_down = time_now - 5;
	time_broken = time_now - 30;
	counter = 0;
	
	if (!ns_data->configured) {
		return;
	}

	/*move services from UP to DOWN */
	g_hash_table_iter_init(&s_iterator, ns_data->local_services);
	while (g_hash_table_iter_next(&s_iterator, &s_k, &s_v)) {
		str_key = s_k;
		si = s_v;
		si->score.value = -2;/*score not set*/
		if (si->score.timestamp < time_down) {
			gchar str_addr[STRLEN_ADDRINFO];

			addr_info_to_string(&(si->addr),str_addr,sizeof(str_addr));
			DEBUG("Timeout on service [%s/%s/%s] (%"G_GINT32_FORMAT" < %ld) --> DOWN",
				si->ns_name, si->type, str_addr, si->score.timestamp, time_down);

			g_hash_table_iter_steal(&s_iterator);
			g_hash_table_insert(ns_data->down_services, str_key, si);

			invalidate_conscience_service(ns_data,si);
			zero_service_stats(si->tags);
			service_tag_set_value_boolean(service_info_ensure_tag(si->tags,"tag.up"), FALSE);

			counter++;
		}
	}

	/*remove services DOWN from a long time ago */
	g_hash_table_iter_init(&s_iterator, ns_data->down_services);
	while (g_hash_table_iter_next(&s_iterator, &s_k, &s_v)) {
		str_key = s_k;
		si = s_v;
		si->score.value = -2;/*score not set*/
		if (si->score.timestamp < time_broken) {
			gchar str_addr[STRLEN_ADDRINFO];

			addr_info_to_string(&(si->addr),str_addr,sizeof(str_addr));
			DEBUG("Service obsolete [%s/%s/%s] --> DELETED", si->ns_name, si->type, str_addr);

			g_hash_table_iter_remove(&s_iterator);
			counter++;
		}
		else
			zero_service_stats(si->tags);
	}

	if (counter)
		DEBUG("[task_id=%s] %u services states have changed", TASK_ID, counter);
}
Пример #16
0
gs_status_t rawx_delete (gs_chunk_t *chunk, GError **err)
{
	char str_req_id [1024];
	char str_addr [STRLEN_ADDRINFO];
	char str_ci [STRLEN_CHUNKID];
	char cPath [CI_FULLPATHLEN];
	char str_hash[STRLEN_CHUNKHASH];

	ne_request *request=NULL;
	ne_session *session=NULL;
	
	memset(str_req_id, 0x00, sizeof(str_req_id));

	if (!chunk || !chunk->ci || !chunk->content)
	{
		GSETERROR (err,"Invalid parameter (bad chunk structure)");
		goto error_label;
	}

	addr_info_to_string (&(chunk->ci->id.addr), str_addr, sizeof(str_addr));
	chunk_id2str(chunk, str_ci, sizeof(str_ci));
	chunk_getpath (chunk, cPath, sizeof(cPath));
	DEBUG("about to delete %s on %s", str_ci, cPath);

	gscstat_tags_start(GSCSTAT_SERVICE_RAWX, GSCSTAT_TAGS_REQPROCTIME);

	session = rawx_opensession (chunk, err);
	if (!session)
	{
		GSETERROR (err, "Cannot open a webdav session");
		goto error_label;
	}

	/*Create a webdav request*/
	do {
		request = ne_request_create (session, RAWX_DELETE, cPath);
		if (!request)
		{
			GSETERROR (err, "cannot create a %s WebDAV request", RAWX_DELETE);
			goto error_label;
		}

	} while (0);

	chunk_id2str (chunk, str_ci, sizeof(str_ci));
	chunk_gethash (chunk, str_hash, sizeof(str_hash));

	/* Add request header */
	add_req_id_header(request, str_req_id, sizeof(str_req_id)-1);


	ne_add_request_header  (request, "chunkid",     str_ci);
	ne_add_request_header  (request, "chunkhash",   str_hash);
	ne_add_request_header  (request, "containerid", C1_IDSTR(chunk->content));
	ne_add_request_header  (request, "contentpath", chunk->content->info.path);
	ne_print_request_header(request, "chunkpos",    "%"G_GUINT32_FORMAT, chunk->ci->position);
	ne_print_request_header(request, "chunknb",     "%"G_GUINT32_FORMAT, chunk->ci->nb);
	ne_print_request_header(request, "chunksize",   "%"G_GINT64_FORMAT, chunk->ci->size);
	ne_print_request_header(request, "contentsize", "%"G_GINT64_FORMAT, chunk->content->info.size);

	/*now perform the request*/
	switch (ne_request_dispatch (request))
	{
		case NE_OK:
			if (ne_get_status(request)->klass != 2) {
				GSETERROR (err, "cannot delete '%s' (%s) (ReqId:%s)", cPath, ne_get_error(session), str_req_id);
				goto error_label;
			}
			DEBUG("chunk deletion finished (success) : %s", cPath);
			break;
		case NE_AUTH:
		case NE_CONNECT:
		case NE_TIMEOUT:
		case NE_ERROR:
			GSETERROR (err, "unexpected error from the WebDAV server (%s) (ReqId:%s)", ne_get_error(session), str_req_id);
			goto error_label;
	}

	ne_request_destroy (request);
	ne_session_destroy (session);
	
	TRACE("%s deleted (ReqId:%s)", cPath, str_req_id);

	gscstat_tags_end(GSCSTAT_SERVICE_RAWX, GSCSTAT_TAGS_REQPROCTIME);

	return 1;
error_label:
	TRACE("could not delete %s", cPath);
	if (request)
		ne_request_destroy (request);
	if (session)
		ne_session_destroy (session);

	gscstat_tags_end(GSCSTAT_SERVICE_RAWX, GSCSTAT_TAGS_REQPROCTIME);

	return 0;
}
Пример #17
0
static void
allservice_check_start_HT(struct namespace_data_s *ns_data, GHashTable *ht)
{
	gsize offset;
	struct taskdata_checksrv_s td_scheme;
	GHashTableIter iter_serv;
	gpointer k, v;


	g_hash_table_iter_init(&iter_serv, ht);
	while (g_hash_table_iter_next(&iter_serv, &k, &v)) {
		struct service_info_s *si = v;
		gboolean srv_check_enabled = TRUE;

		/* Services can disable TCP checks (enabled by default) */
		service_tag_t *tag = service_info_get_tag(si->tags,
				NAME_TAGNAME_AGENT_CHECK);
		if (tag) {
			GError *err = NULL;
			if (tag->type == STVT_BOOL) {
				service_tag_get_value_boolean(tag, &srv_check_enabled, &err);
			} else {
				gchar buf[64] = {0};
				service_tag_get_value_string(tag, buf, sizeof(buf), &err);
				srv_check_enabled = metautils_cfg_get_bool(buf, TRUE);
			}
			g_clear_error(&err);
		}

		memset(&td_scheme, 0x00, sizeof(td_scheme));
		offset = g_snprintf(td_scheme.task_name, sizeof(td_scheme.task_name), "%s.", TASK_ID);
		addr_info_to_string(&(si->addr), td_scheme.task_name+offset, sizeof(td_scheme.task_name)-offset);
		g_strlcpy(td_scheme.ns_name, ns_data->name, sizeof(td_scheme.ns_name)-1);

		if (!srv_check_enabled) {
			GRID_DEBUG("Task [%s] disabled by "
					NAME_TAGNAME_AGENT_CHECK, td_scheme.task_name);
		} else if (!is_task_scheduled(td_scheme.task_name)) {
			GError *error_local = NULL;
			task_t *task = NULL;
			struct taskdata_checksrv_s *task_data;


			agent_get_service_key(si, td_scheme.srv_key, sizeof(td_scheme.srv_key));
			g_strlcpy(td_scheme.srv_key, (gchar*)k, sizeof(td_scheme.srv_key)-1);

			/* prepare the task structure */
			task_data = g_memdup(&td_scheme, sizeof(td_scheme));
			if (!task_data) {
				ERROR("Memory allocation failure");
				continue;
			}

			task = create_task(period_check_services, td_scheme.task_name);
			task = set_task_callbacks(task, _check_tcp_service_task,
					g_free, task_data);
			if (!task) {
				ERROR("Memory allocation failure");
				continue;
			}
			
			/* now start the task! */
			if (add_task_to_schedule(task, &error_local))
				INFO("Task started: %s", td_scheme.task_name);
			else {
				ERROR("Failed to add task to scheduler [%s] : %s", td_scheme.task_name, gerror_get_message(error_local));
				g_free(task);
			}
			if (error_local)
				g_clear_error(&error_local);
		}
	}
}
Пример #18
0
static int
test_add_service(int argc, char ** args, int validation)
{
	GSList *really_removed=NULL, *commit_failed=NULL, *services_used=NULL;
	struct service_info_s *si;
	GSList *paths;
	GError *err;

	if (argc<1) {
		g_printerr("Failed to add anything : expecting argument\r\n");
		abort();
	}

	err = NULL;
	if (!meta2_remote_container_open(&(cnx.addr), cnx.timeout.req, &err, cid)) {
		g_printerr("Failed to open the distant container : %s\r\n", gerror_get_message(err));
		g_clear_error(&err);
		return 0;
	}

	paths = build_paths_list(argc,args);
	si = meta2_remote_service_add_contents(&cnx, cid, service_name, paths, &err);
	_display_strlist("\tAdd wanted: ", paths);
	if (si == NULL) {
		g_printerr("Failed to insert a path : %s\r\n", gerror_get_message(err));
	} else {
		gchar str_addr[128];

		addr_info_to_string(&(si->addr), str_addr, sizeof(str_addr));
		g_printerr("Service found: %s\r\n", str_addr);
	}

	if (validation) {
		status_t rc0, rc1, rc2;
		
		/* COMMIT */
		rc0 = meta2_remote_service_commit_contents(&cnx,cid,service_name,paths,&commit_failed,&err);
		_display_strlist("\tCommit wanted: ", paths);
		_display_strlist("\tCommit succeeded: ", commit_failed); _gfree_list(&commit_failed);
		g_printerr("RESULT : %s\r\n", rc0 ? "ok" : gerror_get_message(err));

		if (rc0) {
			GError *e;
			gboolean rc_local;

			/* Second-COMMIT */
			e = NULL;
			rc_local = meta2_remote_service_commit_contents(&cnx,cid,service_name,paths,&commit_failed,&e);
			_display_strlist("\tSecond Commit wanted: ", paths);
			_display_strlist("\tSecond Commit failed: ", commit_failed);
			_gfree_list(&commit_failed);
			g_printerr("Second Commit RESULT : %s\r\n", rc_local ? "ok" : gerror_get_message(e));
		}

		/* DELETE */
		rc1 = meta2_remote_service_delete_contents(&cnx, cid, service_name, paths, &really_removed, &services_used, &err);
		_display_strlist("\tDelete wanted: ", paths);
		_display_strlist("\tservices used: ", services_used);
		_display_strlist("\tcontent removed : ", really_removed);
		_gfree_list(&services_used);
		_gfree_list(&really_removed);
		g_printerr("RESULT : %s\r\n", rc1 ? "ok" : gerror_get_message(err));

		/* COMMIT */
		rc2 = meta2_remote_service_commit_contents(&cnx,cid,service_name,paths,&commit_failed,&err);
		_display_strlist("\tCommit wanted: ", paths);
		_display_strlist("\tCommit succeeded: ", commit_failed);
		_gfree_list(&commit_failed);
		g_printerr("RESULT : %s\r\n", rc2 ? "ok" : gerror_get_message(err));

		if (!rc0 || !rc1 || !rc2)
			goto error_label;
	}
	else {
		status_t rc0, rc1, rc2;

		rc0 = rc1 = rc2 = ~0;

		/* ROLLBACK */
		rc0 = meta2_remote_service_rollback_contents(&cnx,cid,service_name,paths,&commit_failed,&err);
		_display_strlist("\tRollback wanted: ", paths);
		_display_strlist("\tRollback failed: ", commit_failed); _gfree_list(&commit_failed);
		g_printerr("RESULT : %s\r\n", rc0 ? "ok" : gerror_get_message(err));
		
		if (rc0) {
			GError *e;
			gboolean rc_local;

			/* Second-COMMIT */
			e = NULL;
			rc_local = meta2_remote_service_rollback_contents(&cnx,cid,service_name,paths,&commit_failed,&e);
			_display_strlist("\tSecond Rollback wanted: ", paths);
			_display_strlist("\tSecond Rollback failed: ", commit_failed); _gfree_list(&commit_failed);
			g_printerr("Second Rollback RESULT : %s\r\n", rc_local ? "ok" : gerror_get_message(e));
		}

		/* DELETE */
		rc1 = meta2_remote_service_delete_contents(&cnx, cid, service_name, paths, &really_removed, &services_used, &err);
		_display_strlist("\tDelete wanted: ", paths);
		_display_strlist("\tservices used: ", services_used);
		_display_strlist("\tcontent removed : ", really_removed);
		g_printerr("RESULT : %s\r\n", rc1 ? "ok" : gerror_get_message(err));

		if (services_used || really_removed) {
			g_printerr("ADD+ROLLBACK content should not be found\n");
			rc2 = 0;
		}
		
		if (!rc0 || !rc1 || !rc2)
			goto error_label;
	}

	meta2_remote_container_close_in_fd(cnx.fd, cnx.timeout.req, NULL, cid);
	return 1;
error_label:
	g_slist_free(paths);
	meta2_remote_container_close_in_fd(cnx.fd, cnx.timeout.req, NULL, cid);
	g_clear_error(&err);
	return 0;
}