예제 #1
0
	static
	groups_map_t
	create_groups_map(const kora::dynamic_t &dynamic) {
		try {
			const auto &dynamic_keys = dynamic.as_object();

			auto groups_map = groups_map_t{};
			for (auto key_it = dynamic_keys.begin(), key_end = dynamic_keys.end()
					; key_it != key_end; ++key_it) {
				const auto &dynamic_couple_ids = key_it->second.as_object();

				auto couple_id_map = std::map<std::string, groups_t>{};
				for (auto couple_id_it = dynamic_couple_ids.begin()
						, couple_id_end = dynamic_couple_ids.end()
						; couple_id_it != couple_id_end; ++couple_id_it) {
					const auto &dynamic_info = couple_id_it->second.as_object();
					const auto &dynamic_cache_groups = dynamic_info.at("cache_groups").as_array();

					auto groups = groups_t{};
					for (auto cache_groups_it = dynamic_cache_groups.begin()
							, cache_groups_end = dynamic_cache_groups.end()
							; cache_groups_it != cache_groups_end; ++cache_groups_it) {
						groups.emplace_back(cache_groups_it->to<group_t>());
					}
					couple_id_map.insert(std::make_pair(couple_id_it->first, groups));
				}

				groups_map.insert(std::make_pair(key_it->first, couple_id_map));
			}

			return groups_map;
		} catch (const std::exception &ex) {
			throw std::runtime_error(std::string("cached_keys parse error: ") + ex.what());
		}
	}
예제 #2
0
std::map<std::string, groups_t>
mastermind_t::data::create_cache_groups(const std::string &name
		, const kora::dynamic_t &raw_value) {
	(void) name;

	std::map<std::string, groups_t> result;

	const auto &raw_value_array = raw_value.as_array();

	for (auto p_it = raw_value_array.begin(), p_end = raw_value_array.end();
			p_it != p_end; ++p_it) {
		const auto &pair = p_it->as_array();
		const auto &name = pair[0].to<std::string>();
		const auto &raw_groups = pair[1].as_array();
		groups_t groups;

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

		result.insert(std::make_pair(name, groups));
	}

	if (result.empty()) {
		throw std::runtime_error("cache-groups list is empty");
	}

	return result;
}
예제 #3
0
std::vector<std::string>
mastermind_t::data::create_elliptics_remotes(const std::string &name
		, const kora::dynamic_t &raw_value) {
	(void) name;

	std::vector<std::string> result;

	const auto &raw_value_array = raw_value.as_array();

	for (auto p_it = raw_value_array.begin(), p_end = raw_value_array.end();
			p_it != p_end; ++p_it) {
		const auto &tuple = p_it->as_array();
		const auto &name = tuple[0].to<std::string>();
		const auto &port = tuple[1].to<int>();
		const auto &family = tuple[2].to<int>();

		std::ostringstream oss;
		oss << name << ':' << port << ':' << family;

		result.emplace_back(oss.str());
	}

	if (result.empty()) {
		throw std::runtime_error("elliptics-remotes list is empty");
	}

	return result;
}
예제 #4
0
bool
mastermind_t::data::namespace_state_is_deleted(const kora::dynamic_t &raw_value) {
	const auto &state_object = raw_value.as_object();
	auto it_settings = state_object.find("settings");

	if (it_settings == state_object.end()) {
		return false;
	}

	const auto &settings_object = it_settings->second.as_object();
	auto it_service = settings_object.find("__service");

	if (it_service == settings_object.end()) {
		return false;
	}

	const auto &service_object = it_service->second.as_object();
	auto it_is_deleted = service_object.find("is_deleted");

	if (it_is_deleted == service_object.end()) {
		return false;
	}

	const auto &is_deleted_object = it_is_deleted->second;
	return is_deleted_object.to<bool>();
}
예제 #5
0
bp::object
convert(const kora::dynamic_t &d, const gil_guard_t &gil_guard) {
	if (d.is_null()) {
		return bp::object{};
	} else if (d.is_bool()) {
		return bp::object{d.as_bool()};
	} else if (d.is_int()) {
		return bp::object{d.as_int()};
	} else if (d.is_uint()) {
		return bp::object{d.as_uint()};
	} else if (d.is_double()) {
		return bp::object{d.as_double()};
	} else if (d.is_string()) {
		return bp::object{d.as_string()};
	} else if (d.is_array()) {
		return convert(d.as_array(), gil_guard);
	} else if (d.is_object()) {
		return convert(d.as_object(), gil_guard);
	}

	return bp::object{};
}