int
meta2_filter_action_deduplicate_container(struct gridd_filter_ctx_s *ctx,
		struct gridd_reply_ctx_s *reply)
{
	GString *status_message = NULL;

	// M2V2_MODE_DRYRUN, ...
	guint32 flags = 0;
	const char *fstr = meta2_filter_ctx_get_param(ctx, M2_KEY_GET_FLAGS);
	if (NULL != fstr)
		flags = (guint32) g_ascii_strtoull(fstr, NULL, 10);
	
	GError *err = meta2_backend_deduplicate_contents(
			meta2_filter_ctx_get_backend(ctx),
			meta2_filter_ctx_get_url(ctx),
			flags,
			&status_message);
	reply->did_write = TRUE;

	if (!err) {
		if (status_message != NULL)
			reply->add_body(metautils_gba_from_string(status_message->str));
		return FILTER_OK;
	} else {
		meta2_filter_ctx_set_error(ctx, err);
		return FILTER_KO;
	}
}
Esempio n. 2
0
gboolean
convert_chunk_text_to_raw(const struct chunk_textinfo_s* text_chunk, struct meta2_raw_chunk_s* raw_chunk, GError** error)
{
	if (text_chunk == NULL) {
		GSETERROR(error, "text_chunk is null");
		return FALSE;
	}

	memset(raw_chunk, 0, sizeof(struct meta2_raw_chunk_s));

	if (text_chunk->id != NULL
		&& !oio_str_hex2bin(text_chunk->id, raw_chunk->id.id, sizeof(hash_sha256_t))) {
			GSETERROR(error, "Failed to convert chunk id from hex to bin");
			return FALSE;
	}

	if (text_chunk->hash != NULL
		&& !oio_str_hex2bin(text_chunk->hash, raw_chunk->hash, sizeof(chunk_hash_t))) {
			GSETERROR(error, "Failed to convert chunk hash from hex to bin");
			return FALSE;
	}

	if (text_chunk->size != NULL)
		raw_chunk->size = g_ascii_strtoll(text_chunk->size, NULL, 10);

	if (text_chunk->position != NULL)
		raw_chunk->position = g_ascii_strtoull(text_chunk->position, NULL, 10);

	if (text_chunk->metadata != NULL)
		raw_chunk->metadata = metautils_gba_from_string(text_chunk->metadata);

	return TRUE;
}
Esempio n. 3
0
static void
_init_nsinfo(struct namespace_info_s *nsinfo, const gchar *ns)
{
	memset(nsinfo, 0, sizeof(*nsinfo));
	metautils_strlcpy_physical_ns(nsinfo->name, ns, sizeof(nsinfo->name));
	nsinfo->chunk_size = chunk_size;

	nsinfo->writable_vns = g_slist_prepend(nsinfo->writable_vns, g_strdup("NS.VNS0"));
	nsinfo->writable_vns = g_slist_prepend(nsinfo->writable_vns, g_strdup("NS.VNS1"));

	nsinfo->storage_policy = g_hash_table_new_full(g_str_hash, g_str_equal,
			g_free, metautils_gba_unref);
	nsinfo->data_security = g_hash_table_new_full(g_str_hash, g_str_equal,
			g_free, metautils_gba_unref);
	nsinfo->data_treatments = g_hash_table_new_full(g_str_hash, g_str_equal,
			g_free, metautils_gba_unref);

	g_hash_table_insert(nsinfo->storage_policy, g_strdup("classic"),
			metautils_gba_from_string("DUMMY:DUPONETWO:NONE"));
	g_hash_table_insert(nsinfo->storage_policy, g_strdup("polcheck"),
			metautils_gba_from_string("DUMMY:DUPONETHREE:SIMCOMP"));
	g_hash_table_insert(nsinfo->storage_policy, g_strdup("secure"),
			metautils_gba_from_string("DUMMY:DUP_SECURE:NONE"));

	g_hash_table_insert(nsinfo->data_security, g_strdup("DUPONETWO"),
			metautils_gba_from_string("DUP:distance=1|nb_copy=2"));
	g_hash_table_insert(nsinfo->data_security, g_strdup("DUPONETHREE"),
			metautils_gba_from_string("DUP:distance=1|nb_copy=3"));
	g_hash_table_insert(nsinfo->data_security, g_strdup("DUP_SECURE"),
			metautils_gba_from_string("DUP:distance=4|nb_copy=2"));

	g_hash_table_insert(nsinfo->data_treatments, g_strdup("SIMCOMP"),
			metautils_gba_from_string("COMP:algo=ZLIB|blocksize=262144"));
}
Esempio n. 4
0
static GSList *
_get_services(struct metacnx_ctx_s *ctx, const gchar * type,
		GError ** error, gboolean full)
{
	GByteArray *gba0 = NULL, *gba1 = NULL;
	GSList *result;

	gba0 = metautils_gba_from_string(type);
	if (full)
		gba1 = metautils_gba_from_string("1");
	result = service_info_sequence_request(ctx, error,
			NAME_MSGNAME_CS_GET_SRV, NULL, "TYPENAME", gba0,
			"FULL", gba1,
			NULL);

	g_byte_array_free(gba0, TRUE);
	if (gba1)
		g_byte_array_free(gba1, TRUE);

	return result;
}
Esempio n. 5
0
static MESSAGE
_m2v2_build_request(const gchar *name, GByteArray *sid,
		struct hc_url_s *url, GByteArray *body)
{
	struct message_s *msg;
	GSList *pool = NULL;

	EXTRA_ASSERT(url != NULL);
	msg = message_create_request(NULL, sid, name,
			body ? gba_poolify(&pool, body) : NULL,
			"HC_URL", gba_poolify(&pool,
				metautils_gba_from_string(hc_url_get(url, HCURL_WHOLE))),
			"NAMESPACE", gba_poolify(&pool,
				metautils_gba_from_string(hc_url_get(url, HCURL_NS))),
			"CONTAINER_ID", gba_poolify(&pool,
				_url_2_gba(url)),
			"CONTENT_PATH", gba_poolify(&pool, metautils_gba_from_string(
					hc_url_get(url, HCURL_PATH))),
			NULL);
	GBA_POOL_CLEAN(pool);

	return msg;
}
Esempio n. 6
0
static GError *
_load_hash (struct json_object *obj, const gchar *k, GHashTable *dst)
{
	struct json_object *sub = NULL;

	if (!json_object_object_get_ex(obj, k, &sub))
		return NULL;
	if (!json_object_is_type(sub, json_type_object))
		return NEWERROR(CODE_BAD_REQUEST, "Invalid '%s' field", k);

	json_object_object_foreach(sub,key,val) {
		if (!json_object_is_type(val, json_type_string))
			continue;
		g_hash_table_insert(dst, g_strdup(key), metautils_gba_from_string(
					json_object_get_string(val)));
	}
	return NULL;
}
Esempio n. 7
0
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;
}