Example #1
0
mastermind::namespace_state_t::data_t::settings_t::settings_t(const std::string &name
		, const kora::config_t &state , const user_settings_factory_t &factory)
	try
	: groups_count(state.at<size_t>("groups-count"))
	, success_copies_num(state.at<std::string>("success-copies-num"))
{
	if (state.has("auth-keys")) {
		const auto &auth_keys_state = state.at("auth-keys");

		auth_keys.read = auth_keys_state.at<std::string>("read", "");
		auth_keys.read = auth_keys_state.at<std::string>("write", "");
	}

	if (state.has("static-couple")) {
		const auto &static_couple_config = state.at("static-couple");

		for (size_t index = 0, size = static_couple_config.size(); index != size; ++index) {
			static_groups.emplace_back(static_couple_config.at<group_t>(index));
		}
	}

	if (factory) {
		user_settings_ptr = factory(name, state);
	}
} catch (const std::exception &ex) {
	throw std::runtime_error(std::string("cannot create settings-state: ") + ex.what());
}
Example #2
0
mastermind::namespace_state_t::data_t::data_t(std::string name_, const kora::config_t &config
		, const user_settings_factory_t &factory)
	try
	: name(std::move(name_))
	, settings(name, config.at("settings"), factory)
	, couples(config.at("couples"))
	, weights(config.at("weights"), settings.groups_count, !settings.static_groups.empty())
	, statistics(config.at("statistics"))
{
	check_consistency();

} catch (const std::exception &ex) {
	throw std::runtime_error("cannot create ns-state " + name + ": " + ex.what());
}
Example #3
0
static size_t parse_size(const kora::config_t &value) {
	size_t ret = 0;
	if (value.underlying_object().is_uint()) {
		ret = value.to<size_t>();
	} else if (value.underlying_object().is_string()) {
		ret = parse_size(value.to<std::string>());
	} else {
		throw elliptics::config::config_error(value.path() + " must be specified");
	}

	if (ret == 0) {
		throw elliptics::config::config_error(value.path() + " must be non-zero");
	}
	return ret;
}
Example #4
0
mastermind::namespace_state_t::data_t::statistics_t::statistics_t(const kora::config_t &config)
	try
	: is_full(config.at("is_full", false))
{
	// TODO: log whether is_full is provided by mastermind
} catch (const std::exception &ex) {
	throw std::runtime_error(std::string("cannot create statistics-state: ") + ex.what());
}
Example #5
0
std::unique_ptr<cache_config> cache_config::parse(const kora::config_t &cache) {
	cache_config config;
	config.size = parse_size(cache["size"]);
	config.count = cache.at<size_t>("shards", DNET_DEFAULT_CACHES_NUMBER);
	config.sync_timeout = cache.at<unsigned>("sync_timeout", DNET_DEFAULT_CACHE_SYNC_TIMEOUT_SEC);
	config.pages_proportions =
	    cache.at("pages_proportions", std::vector<size_t>(DNET_DEFAULT_CACHE_PAGES_NUMBER, 1));
	return std::unique_ptr<cache_config>(new cache_config(config));
}
Example #6
0
	mm::namespace_state_t::user_settings_ptr_t
	user_settings_factory(const std::string &name, const kora::config_t &config) {
		gil_guard_t gil_guard;

		auto settings = detail::convert(config.underlying_object().as_object(), gil_guard);

		if (ns_filter) {
			try {
				if (!ns_filter(name, settings)) {
					return nullptr;
				}
			} catch (const std::exception &ex) {
				// ns_filter can throw python object that must be destroyed during gil is locked
				// that is during gil_guard is not out of scope.
				throw std::runtime_error(std::string{"ns_filter error: "} + ex.what());
			}
		}

		std::unique_ptr<namespace_state_t::user_settings_t> result{
			new namespace_state_t::user_settings_t{std::move(settings), gil_guard}
		};

		return mm::namespace_state_t::user_settings_ptr_t(std::move(result));
	}
Example #7
0
mastermind::namespace_state_t::data_t::couples_t::couples_t(const kora::config_t &state)
	try
{
	for (size_t index = 0, size = state.size(); index != size; ++index) {
		const auto &couple_info_state = state.at(index);

		auto couple_id = couple_info_state.at<std::string>("id");

		auto ci_insert_result = couple_info_map.insert(std::make_pair(
					couple_id, couple_info_t()));

		if (std::get<1>(ci_insert_result) == false) {
			throw std::runtime_error("reuse the same couple_id=" + couple_id);
		}

		auto &couple_info = std::get<0>(ci_insert_result)->second;

		couple_info.id = couple_id;

		{
			const auto &dynamic_tuple = couple_info_state.at("tuple")
				.underlying_object().as_array();

			for (auto it = dynamic_tuple.begin(), end = dynamic_tuple.end();
					it != end; ++it) {
				couple_info.groups.emplace_back(it->to<group_t>());
			}
		}

		{
			auto status = couple_info_state.at<std::string>("couple_status");

			if (status == "BAD") {
				couple_info.status = couple_info_t::status_tag::BAD;
			} else {
				couple_info.status = couple_info_t::status_tag::UNKNOWN;
			}
		}

		couple_info.free_effective_space = couple_info_state.at<uint64_t>("free_effective_space", 0);
		couple_info.free_reserved_space = couple_info_state.at<uint64_t>("free_reserved_space", 0);

		couple_info.hosts = couple_info_state.at("hosts").underlying_object();

		const auto &groups_info_state = couple_info_state.at("groups");

		for (size_t index = 0, size = groups_info_state.size(); index != size; ++index) {
			const auto &group_info_state = groups_info_state.at(index);

			auto group_id = group_info_state.at<group_t>("id");

			auto gi_insert_result = group_info_map.insert(std::make_pair(
						group_id, group_info_t()));

			if (std::get<1>(gi_insert_result) == false) {
				throw std::runtime_error("resuse the same group_id="
						+ boost::lexical_cast<std::string>(group_id));
			}

			auto &group_info = std::get<0>(gi_insert_result)->second;

			group_info.id = group_id;

			{
				auto status = group_info_state.at<std::string>("status");

				if (status == "COUPLED") {
					group_info.status = group_info_t::status_tag::COUPLED;
				} else {
					group_info.status = group_info_t::status_tag::UNKNOWN;
				}
			}

			group_info.couple_info_map_iterator = std::get<0>(ci_insert_result);
			couple_info.groups_info_map_iterator.emplace_back(std::get<0>(gi_insert_result));
		}
	}
} catch (const std::exception &ex) {
	throw std::runtime_error(std::string("cannot create couples-state: ") + ex.what());
}