From 3ab70dd3e1150b2b3f66cbbee329ea95618747a5 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 16 Oct 2024 17:34:06 +0200 Subject: [PATCH] common/Formatter: move {JSON,Table,XML}Formatter to separate files Most sources only need the Formatter interface and don't need the other implementations (and their header dependencies). Signed-off-by: Max Kellermann --- src/ceph_mon.cc | 1 + src/common/AsyncReserver.h | 2 +- src/common/CMakeLists.txt | 3 + src/common/Formatter.cc | 866 +------------------ src/common/Formatter.h | 274 +----- src/common/HTMLFormatter.cc | 1 - src/common/HTMLFormatter.h | 2 +- src/common/JSONFormatter.cc | 265 ++++++ src/common/JSONFormatter.h | 128 +++ src/common/JSONFormatterFile.h | 54 ++ src/common/TableFormatter.cc | 378 ++++++++ src/common/TableFormatter.h | 67 ++ src/common/XMLFormatter.cc | 307 +++++++ src/common/XMLFormatter.h | 68 ++ src/common/admin_socket.cc | 1 + src/common/ceph_json.h | 2 +- src/crimson/CMakeLists.txt | 3 + src/crimson/os/cyanstore/cyan_store.cc | 1 + src/crimson/os/seastore/seastore.cc | 1 + src/crimson/tools/store_bench/store-bench.cc | 1 + src/global/signal_handler.cc | 2 +- src/libcephsqlite.cc | 2 +- src/mds/MDSRank.cc | 1 + src/mds/ScrubStack.cc | 2 +- src/mgr/BaseMgrModule.cc | 1 + src/mgr/ClusterState.cc | 1 + src/mgr/DaemonServer.cc | 1 + src/mgr/PyFormatter.h | 2 +- src/mgr/PyModule.cc | 1 + src/mon/ConfigMap.cc | 1 - src/mon/ConfigMonitor.cc | 2 +- src/mon/ElectionLogic.cc | 1 - src/mon/Elector.cc | 2 - src/mon/LogMonitor.cc | 1 - src/mon/MonitorDBStore.h | 2 +- src/mon/OSDMonitor.cc | 1 + src/mon/Paxos.h | 1 + src/os/bluestore/BlueFS.cc | 1 + src/os/bluestore/BlueStore.cc | 1 + src/os/bluestore/bluestore_tool.cc | 1 + src/os/kstore/KStore.cc | 2 +- src/os/memstore/MemStore.cc | 1 + src/osd/osd_types.cc | 2 +- src/rbd_replay/Replayer.cc | 1 + src/rbd_replay/actions.hpp | 2 +- src/rgw/driver/rados/rgw_bucket.cc | 1 + src/rgw/driver/rados/rgw_lc_tier.cc | 2 +- src/rgw/driver/rados/rgw_pubsub_push.cc | 1 + src/rgw/driver/rados/rgw_sync_module_aws.cc | 2 + src/rgw/driver/rados/rgw_sync_trace.cc | 1 + src/rgw/radosgw-admin/radosgw-admin.cc | 3 +- src/rgw/rgw_cors_s3.cc | 1 + src/rgw/rgw_cors_s3.h | 2 +- src/rgw/rgw_formats.cc | 2 +- src/rgw/rgw_op.cc | 1 + src/rgw/rgw_rest.cc | 2 +- src/test/admin_socket.cc | 1 + src/test/common/test_json_formatter.cc | 1 + src/test/common/test_tableformatter.cc | 2 +- src/test/common/test_xmlformatter.cc | 2 +- src/test/crush/crush.cc | 1 + src/test/formatter.cc | 3 +- src/test/libcephfs/snapdiff.cc | 1 + src/test/librados/service.cc | 1 + src/test/librados/test_common.cc | 2 +- src/test/mon/test_mon_workloadgen.cc | 1 + src/test/objectstore/store_test.cc | 1 + src/test/rgw/test_rgw_xml.cc | 2 + src/test/test_mempool.cc | 1 + src/tools/ceph-client-debug.cc | 2 +- src/tools/ceph-dencoder/ceph_dencoder.cc | 2 +- src/tools/ceph_monstore_tool.cc | 1 + src/tools/cephfs/EventOutput.cc | 1 + src/tools/cephfs/JournalTool.cc | 1 + src/tools/cephfs/TableTool.cc | 1 + src/tools/cephfs_mirror/ServiceDaemon.cc | 1 + src/tools/osdmaptool.cc | 1 + src/tools/rados/rados.cc | 2 +- src/tools/rbd/ArgumentTypes.cc | 3 +- src/tools/rbd/action/Journal.cc | 2 +- src/tools/rbd_ggate/main.cc | 3 +- src/tools/rbd_mirror/ServiceDaemon.cc | 2 +- src/tools/rbd_nbd/rbd-nbd.cc | 3 +- src/tools/rbd_wnbd/rbd_wnbd.cc | 3 +- 84 files changed, 1355 insertions(+), 1170 deletions(-) create mode 100644 src/common/JSONFormatter.cc create mode 100644 src/common/JSONFormatter.h create mode 100644 src/common/JSONFormatterFile.h create mode 100644 src/common/TableFormatter.cc create mode 100644 src/common/TableFormatter.h create mode 100644 src/common/XMLFormatter.cc create mode 100644 src/common/XMLFormatter.h diff --git a/src/ceph_mon.cc b/src/ceph_mon.cc index 28c4acff435..3c50aecb3d4 100644 --- a/src/ceph_mon.cc +++ b/src/ceph_mon.cc @@ -35,6 +35,7 @@ #include "common/ceph_argparse.h" #include "common/pick_address.h" +#include "common/JSONFormatter.h" #include "common/Throttle.h" #include "common/Timer.h" #include "common/errno.h" diff --git a/src/common/AsyncReserver.h b/src/common/AsyncReserver.h index b98e54ef767..df880844d2e 100644 --- a/src/common/AsyncReserver.h +++ b/src/common/AsyncReserver.h @@ -15,7 +15,7 @@ #ifndef ASYNC_RESERVER_H #define ASYNC_RESERVER_H -#include "common/Formatter.h" +#include "common/JSONFormatter.h" #include "common/ceph_context.h" #include "common/ceph_mutex.h" #include "include/Context.h" diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 97fb1fe7440..1f21ad4c0c5 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -29,6 +29,7 @@ set(common_srcs FixedCDC.cc Formatter.cc Graylog.cc + JSONFormatter.cc HTMLFormatter.cc HeartbeatMap.cc LogClient.cc @@ -39,12 +40,14 @@ set(common_srcs Readahead.cc RefCountedObj.cc SloppyCRCMap.cc + TableFormatter.cc Thread.cc Throttle.cc Timer.cc TracepointProvider.cc TrackedOp.cc WorkQueue.cc + XMLFormatter.cc admin_socket.cc admin_socket_client.cc assert.cc diff --git a/src/common/Formatter.cc b/src/common/Formatter.cc index 58046e1ff0e..3a47addd2b6 100644 --- a/src/common/Formatter.cc +++ b/src/common/Formatter.cc @@ -14,7 +14,11 @@ #define LARGE_SIZE 1024 +#include "Formatter.h" +#include "JSONFormatter.h" #include "HTMLFormatter.h" +#include "TableFormatter.h" +#include "XMLFormatter.h" #include "common/escape.h" #include "common/StackStringStream.h" #include "include/buffer.h" @@ -23,8 +27,6 @@ #include #include #include -#include -#include // ----------------------- namespace ceph { @@ -157,864 +159,4 @@ void Formatter::dump_format_unquoted(std::string_view name, const char *fmt, ... va_end(ap); } -// ----------------------- - -void JSONFormatter::flush(std::ostream& os) -{ - finish_pending_string(); - os << m_ss.str(); - if (m_line_break_enabled) - os << "\n"; - m_ss.clear(); - m_ss.str(""); -} - -void JSONFormatter::reset() -{ - m_stack.clear(); - m_ss.clear(); - m_ss.str(""); - m_pending_string.clear(); - m_pending_string.str(""); -} - -void JSONFormatter::print_comma(json_formatter_stack_entry_d& entry) -{ - auto& ss = get_ss(); - if (entry.size) { - if (m_pretty) { - ss << ",\n"; - for (unsigned i = 1; i < m_stack.size(); i++) - ss << " "; - } else { - ss << ","; - } - } else if (m_pretty) { - ss << "\n"; - for (unsigned i = 1; i < m_stack.size(); i++) - ss << " "; - } - if (m_pretty && entry.is_array) - ss << " "; -} - -void JSONFormatter::print_quoted_string(std::string_view s) -{ - auto& ss = get_ss(); - ss << '\"' << json_stream_escaper(s) << '\"'; -} - -void JSONFormatter::print_name(std::string_view name) -{ - auto& ss = get_ss(); - finish_pending_string(); - if (m_stack.empty()) - return; - struct json_formatter_stack_entry_d& entry = m_stack.back(); - print_comma(entry); - if (!entry.is_array) { - if (m_pretty) { - ss << " "; - } - ss << "\"" << name << "\""; - if (m_pretty) - ss << ": "; - else - ss << ':'; - } - ++entry.size; -} - -void JSONFormatter::open_section(std::string_view name, const char *ns, bool is_array) -{ - auto& ss = get_ss(); - if (handle_open_section(name, ns, is_array)) { - return; - } - if (ns) { - std::ostringstream oss; - oss << name << " " << ns; - print_name(oss.str().c_str()); - } else { - print_name(name); - } - if (is_array) - ss << '['; - else - ss << '{'; - - json_formatter_stack_entry_d n; - n.is_array = is_array; - m_stack.push_back(n); -} - -void JSONFormatter::open_array_section(std::string_view name) -{ - open_section(name, nullptr, true); -} - -void JSONFormatter::open_array_section_in_ns(std::string_view name, const char *ns) -{ - open_section(name, ns, true); -} - -void JSONFormatter::open_object_section(std::string_view name) -{ - open_section(name, nullptr, false); -} - -void JSONFormatter::open_object_section_in_ns(std::string_view name, const char *ns) -{ - open_section(name, ns, false); -} - -void JSONFormatter::close_section() -{ - auto& ss = get_ss(); - if (handle_close_section()) { - return; - } - ceph_assert(!m_stack.empty()); - finish_pending_string(); - - struct json_formatter_stack_entry_d& entry = m_stack.back(); - if (m_pretty && entry.size) { - ss << "\n"; - for (unsigned i = 1; i < m_stack.size(); i++) - ss << " "; - } - ss << (entry.is_array ? ']' : '}'); - m_stack.pop_back(); - if (m_pretty && m_stack.empty()) - ss << "\n"; -} - -void JSONFormatter::finish_pending_string() -{ - if (m_is_pending_string) { - m_is_pending_string = false; - add_value(m_pending_name.c_str(), m_pending_string.str(), true); - m_pending_string.str(""); - } -} - -void JSONFormatter::add_value(std::string_view name, double val) { - CachedStackStringStream css; - if (!std::isfinite(val) || std::isnan(val)) { - *css << "null"; - } else { - css->precision(std::numeric_limits::max_digits10); - *css << val; - } - add_value(name, css->strv(), false); -} - -template -void JSONFormatter::add_value(std::string_view name, T val) -{ - CachedStackStringStream css; - css->precision(std::numeric_limits::max_digits10); - *css << val; - add_value(name, css->strv(), false); -} - -void JSONFormatter::add_value(std::string_view name, std::string_view val, bool quoted) -{ - auto& ss = get_ss(); - if (handle_value(name, val, quoted)) { - return; - } - print_name(name); - if (!quoted) { - ss << val; - } else { - print_quoted_string(val); - } -} - -void JSONFormatter::dump_null(std::string_view name) -{ - add_value(name, "null"); -} - -void JSONFormatter::dump_unsigned(std::string_view name, uint64_t u) -{ - add_value(name, u); -} - -void JSONFormatter::dump_int(std::string_view name, int64_t s) -{ - add_value(name, s); -} - -void JSONFormatter::dump_float(std::string_view name, double d) -{ - add_value(name, d); -} - -void JSONFormatter::dump_string(std::string_view name, std::string_view s) -{ - add_value(name, s, true); -} - -std::ostream& JSONFormatter::dump_stream(std::string_view name) -{ - finish_pending_string(); - m_pending_name = name; - m_is_pending_string = true; - return m_pending_string; -} - -void JSONFormatter::dump_format_va(std::string_view name, const char *ns, bool quoted, const char *fmt, va_list ap) -{ - auto buf = boost::container::small_vector{ - LARGE_SIZE, boost::container::default_init}; - - va_list ap_copy; - va_copy(ap_copy, ap); - int len = vsnprintf(buf.data(), buf.size(), fmt, ap_copy); - va_end(ap_copy); - - if (std::cmp_greater_equal(len, buf.size())) { - // output was truncated, allocate a buffer large enough - buf.resize(len + 1, boost::container::default_init); - vsnprintf(buf.data(), buf.size(), fmt, ap); - } - - add_value(name, buf.data(), quoted); -} - -int JSONFormatter::get_len() const -{ - return m_ss.tellp(); -} - -void JSONFormatter::write_raw_data(const char *data) -{ - get_ss() << data; -} - -const char *XMLFormatter::XML_1_DTD = - ""; - -XMLFormatter::XMLFormatter(bool pretty, bool lowercased, bool underscored) -: m_pretty(pretty), - m_lowercased(lowercased), - m_underscored(underscored) -{ - reset(); -} - -void XMLFormatter::flush(std::ostream& os) -{ - finish_pending_string(); - std::string m_ss_str = m_ss.str(); - os << m_ss_str; - /* There is a small catch here. If the rest of the formatter had NO output, - * we should NOT output a newline. This primarily triggers on HTTP redirects */ - if (m_pretty && !m_ss_str.empty()) - os << "\n"; - else if (m_line_break_enabled) - os << "\n"; - m_ss.clear(); - m_ss.str(""); -} - -void XMLFormatter::reset() -{ - m_ss.clear(); - m_ss.str(""); - m_pending_string.clear(); - m_pending_string.str(""); - m_sections.clear(); - m_pending_string_name.clear(); - m_header_done = false; -} - -void XMLFormatter::output_header() -{ - if(!m_header_done) { - m_header_done = true; - write_raw_data(XMLFormatter::XML_1_DTD); - if (m_pretty) - m_ss << "\n"; - } -} - -void XMLFormatter::output_footer() -{ - while(!m_sections.empty()) { - close_section(); - } -} - -void XMLFormatter::open_object_section(std::string_view name) -{ - open_section_in_ns(name, NULL, NULL); -} - -void XMLFormatter::open_object_section_with_attrs(std::string_view name, const FormatterAttrs& attrs) -{ - open_section_in_ns(name, NULL, &attrs); -} - -void XMLFormatter::open_object_section_in_ns(std::string_view name, const char *ns) -{ - open_section_in_ns(name, ns, NULL); -} - -void XMLFormatter::open_array_section(std::string_view name) -{ - open_section_in_ns(name, NULL, NULL); -} - -void XMLFormatter::open_array_section_with_attrs(std::string_view name, const FormatterAttrs& attrs) -{ - open_section_in_ns(name, NULL, &attrs); -} - -void XMLFormatter::open_array_section_in_ns(std::string_view name, const char *ns) -{ - open_section_in_ns(name, ns, NULL); -} - -std::string XMLFormatter::get_xml_name(std::string_view name) const -{ - std::string e(name); - std::transform(e.begin(), e.end(), e.begin(), - [this](char c) { return this->to_lower_underscore(c); }); - return e; -} - -void XMLFormatter::close_section() -{ - ceph_assert(!m_sections.empty()); - finish_pending_string(); - - auto section = get_xml_name(m_sections.back()); - m_sections.pop_back(); - print_spaces(); - m_ss << ""; - if (m_pretty) - m_ss << "\n"; -} - -template -void XMLFormatter::add_value(std::string_view name, T val) -{ - auto e = get_xml_name(name); - print_spaces(); - m_ss.precision(std::numeric_limits::max_digits10); - m_ss << "<" << e << ">" << val << ""; - if (m_pretty) - m_ss << "\n"; -} - -void XMLFormatter::dump_null(std::string_view name) -{ - print_spaces(); - m_ss << "<" << get_xml_name(name) << " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:nil=\"true\" />"; - if (m_pretty) - m_ss << "\n"; -} - -void XMLFormatter::dump_unsigned(std::string_view name, uint64_t u) -{ - add_value(name, u); -} - -void XMLFormatter::dump_int(std::string_view name, int64_t s) -{ - add_value(name, s); -} - -void XMLFormatter::dump_float(std::string_view name, double d) -{ - add_value(name, d); -} - -void XMLFormatter::dump_string(std::string_view name, std::string_view s) -{ - auto e = get_xml_name(name); - print_spaces(); - m_ss << "<" << e << ">" << xml_stream_escaper(s) << ""; - if (m_pretty) - m_ss << "\n"; -} - -void XMLFormatter::dump_string_with_attrs(std::string_view name, std::string_view s, const FormatterAttrs& attrs) -{ - auto e = get_xml_name(name); - std::string attrs_str; - get_attrs_str(&attrs, attrs_str); - print_spaces(); - m_ss << "<" << e << attrs_str << ">" << xml_stream_escaper(s) << ""; - if (m_pretty) - m_ss << "\n"; -} - -std::ostream& XMLFormatter::dump_stream(std::string_view name) -{ - print_spaces(); - m_pending_string_name = name; - m_ss << "<" << m_pending_string_name << ">"; - return m_pending_string; -} - -void XMLFormatter::dump_format_va(std::string_view name, const char *ns, bool quoted, const char *fmt, va_list ap) -{ - auto buf = boost::container::small_vector{ - LARGE_SIZE, boost::container::default_init}; - - va_list ap_copy; - va_copy(ap_copy, ap); - int len = vsnprintf(buf.data(), buf.size(), fmt, ap_copy); - va_end(ap_copy); - - if (std::cmp_greater_equal(len, buf.size())) { - // output was truncated, allocate a buffer large enough - buf.resize(len + 1, boost::container::default_init); - vsnprintf(buf.data(), buf.size(), fmt, ap); - } - - auto e = get_xml_name(name); - - print_spaces(); - if (ns) { - m_ss << "<" << e << " xmlns=\"" << ns << "\">" << xml_stream_escaper(std::string_view(buf.data(), len)) << ""; - } else { - m_ss << "<" << e << ">" << xml_stream_escaper(std::string_view(buf.data(), len)) << ""; - } - - if (m_pretty) - m_ss << "\n"; -} - -int XMLFormatter::get_len() const -{ - return m_ss.str().size(); -} - -void XMLFormatter::write_raw_data(const char *data) -{ - m_ss << data; -} - -void XMLFormatter::write_bin_data(const char* buff, int buf_len) -{ - std::stringbuf *pbuf = m_ss.rdbuf(); - pbuf->sputn(buff, buf_len); - m_ss.seekg(buf_len); -} - -void XMLFormatter::get_attrs_str(const FormatterAttrs *attrs, std::string& attrs_str) const -{ - CachedStackStringStream css; - - for (const auto &p : attrs->attrs) { - *css << " " << p.first << "=" << "\"" << p.second << "\""; - } - - attrs_str = css->strv(); -} - -void XMLFormatter::open_section_in_ns(std::string_view name, const char *ns, const FormatterAttrs *attrs) -{ - print_spaces(); - std::string attrs_str; - - if (attrs) { - get_attrs_str(attrs, attrs_str); - } - - auto e = get_xml_name(name); - - if (ns) { - m_ss << "<" << e << attrs_str << " xmlns=\"" << ns << "\">"; - } else { - m_ss << "<" << e << attrs_str << ">"; - } - if (m_pretty) - m_ss << "\n"; - m_sections.push_back(std::string(name)); -} - -void XMLFormatter::finish_pending_string() -{ - if (!m_pending_string_name.empty()) { - m_ss << xml_stream_escaper(m_pending_string.str()) - << ""; - m_pending_string_name.clear(); - m_pending_string.str(std::string()); - if (m_pretty) { - m_ss << "\n"; - } - } -} - -void XMLFormatter::print_spaces() -{ - finish_pending_string(); - if (m_pretty) { - std::string spaces(m_sections.size(), ' '); - m_ss << spaces; - } -} - -char XMLFormatter::to_lower_underscore(char c) const -{ - if (m_underscored && c == ' ') { - return '_'; - } else if (m_lowercased) { - return std::tolower(c); - } - return c; -} - -TableFormatter::TableFormatter(bool keyval) : m_keyval(keyval) -{ - reset(); -} - -void TableFormatter::flush(std::ostream& os) -{ - finish_pending_string(); - std::vector column_size = m_column_size; - std::vector column_name = m_column_name; - - std::set need_header_set; - - // auto-sizing columns - for (size_t i = 0; i < m_vec.size(); i++) { - for (size_t j = 0; j < m_vec[i].size(); j++) { - column_size.resize(m_vec[i].size()); - column_name.resize(m_vec[i].size()); - if (i > 0) { - if (m_vec[i - 1][j] != m_vec[i][j]) { - // changing row labels require to show the header - need_header_set.insert(i); - column_name[i] = m_vec[i][j].first; - } - } else { - column_name[i] = m_vec[i][j].first; - } - - if (m_vec[i][j].second.length() > column_size[j]) - column_size[j] = m_vec[i][j].second.length(); - if (m_vec[i][j].first.length() > column_size[j]) - column_size[j] = m_vec[i][j].first.length(); - } - } - - bool need_header = false; - if ((column_size.size() == m_column_size.size())) { - for (size_t i = 0; i < column_size.size(); i++) { - if (column_size[i] != m_column_size[i]) { - need_header = true; - break; - } - } - } else { - need_header = true; - } - - if (need_header) { - // first row always needs a header if there wasn't one before - need_header_set.insert(0); - } - - m_column_size = column_size; - for (size_t i = 0; i < m_vec.size(); i++) { - if (i == 0) { - if (need_header_set.count(i)) { - // print the header - if (!m_keyval) { - os << "+"; - for (size_t j = 0; j < m_vec[i].size(); j++) { - for (size_t v = 0; v < m_column_size[j] + 3; v++) - os << "-"; - os << "+"; - } - os << "\n"; - os << "|"; - - for (size_t j = 0; j < m_vec[i].size(); j++) { - os << fmt::format(" {:<{}}|", - m_vec[i][j].first, m_column_size[j] + 2); - } - os << "\n"; - os << "+"; - for (size_t j = 0; j < m_vec[i].size(); j++) { - for (size_t v = 0; v < m_column_size[j] + 3; v++) - os << "-"; - os << "+"; - } - os << "\n"; - } - } - } - // print body - if (!m_keyval) - os << "|"; - for (size_t j = 0; j < m_vec[i].size(); j++) { - if (!m_keyval) - os << " "; - if (m_keyval) { - os << "key::"; - os << m_vec[i][j].first; - os << "="; - os << "\""; - os << m_vec[i][j].second; - os << "\" "; - } else { - os << fmt::format("{:<{}}|", m_vec[i][j].second, m_column_size[j] + 2); - } - } - - os << "\n"; - if (!m_keyval) { - if (i == (m_vec.size() - 1)) { - // print trailer - os << "+"; - for (size_t j = 0; j < m_vec[i].size(); j++) { - for (size_t v = 0; v < m_column_size[j] + 3; v++) - os << "-"; - os << "+"; - } - os << "\n"; - } - } - m_vec[i].clear(); - } - m_vec.clear(); -} - -void TableFormatter::reset() -{ - m_ss.clear(); - m_ss.str(""); - m_section_cnt.clear(); - m_column_size.clear(); - m_section_open = 0; -} - -void TableFormatter::open_object_section(std::string_view name) -{ - open_section_in_ns(name, NULL, NULL); -} - -void TableFormatter::open_object_section_with_attrs(std::string_view name, const FormatterAttrs& attrs) -{ - open_section_in_ns(name, NULL, NULL); -} - -void TableFormatter::open_object_section_in_ns(std::string_view name, const char *ns) -{ - open_section_in_ns(name, NULL, NULL); -} - -void TableFormatter::open_array_section(std::string_view name) -{ - open_section_in_ns(name, NULL, NULL); -} - -void TableFormatter::open_array_section_with_attrs(std::string_view name, const FormatterAttrs& attrs) -{ - open_section_in_ns(name, NULL, NULL); -} - -void TableFormatter::open_array_section_in_ns(std::string_view name, const char *ns) -{ - open_section_in_ns(name, NULL, NULL); -} - -void TableFormatter::open_section_in_ns(std::string_view name, const char *ns, const FormatterAttrs *attrs) -{ - m_section.push_back(std::string(name)); - m_section_open++; -} - -void TableFormatter::close_section() -{ - // - m_section_open--; - if (m_section.size()) { - m_section_cnt[m_section.back()] = 0; - m_section.pop_back(); - } -} - -size_t TableFormatter::m_vec_index(std::string_view name) -{ - std::string key(name); - - size_t i = m_vec.size(); - if (i) - i--; - - // make sure there are vectors to push back key/val pairs - if (!m_vec.size()) - m_vec.resize(1); - - if (m_vec.size()) { - if (m_vec[i].size()) { - if (m_vec[i][0].first == key) { - // start a new column if a key is repeated - m_vec.resize(m_vec.size() + 1); - i++; - } - } - } - - return i; -} - -std::string TableFormatter::get_section_name(std::string_view name) -{ - std::string t_name{name}; - for (const auto &i : m_section) { - t_name.insert(0, ":"); - t_name.insert(0, i); - } - if (m_section_open) { - std::stringstream lss; - lss << t_name; - lss << "["; - lss << m_section_cnt[t_name]++; - lss << "]"; - return lss.str(); - } else { - return t_name; - } -} - -template -void TableFormatter::add_value(std::string_view name, T val) { - finish_pending_string(); - size_t i = m_vec_index(name); - m_ss.precision(std::numeric_limits::max_digits10); - m_ss << val; - - m_vec[i].push_back(std::make_pair(get_section_name(name), m_ss.str())); - m_ss.clear(); - m_ss.str(""); -} - -void TableFormatter::dump_null(std::string_view name) -{ - add_value(name, "null"); -} - -void TableFormatter::dump_unsigned(std::string_view name, uint64_t u) -{ - add_value(name, u); -} - -void TableFormatter::dump_int(std::string_view name, int64_t s) -{ - add_value(name, s); -} - -void TableFormatter::dump_float(std::string_view name, double d) -{ - add_value(name, d); } - -void TableFormatter::dump_string(std::string_view name, std::string_view s) -{ - finish_pending_string(); - size_t i = m_vec_index(name); - m_ss << s; - - m_vec[i].push_back(std::make_pair(get_section_name(name), m_ss.str())); - m_ss.clear(); - m_ss.str(""); -} - -void TableFormatter::dump_string_with_attrs(std::string_view name, std::string_view s, const FormatterAttrs& attrs) -{ - finish_pending_string(); - size_t i = m_vec_index(name); - - std::string attrs_str; - get_attrs_str(&attrs, attrs_str); - m_ss << attrs_str << s; - - m_vec[i].push_back(std::make_pair(get_section_name(name), m_ss.str())); - m_ss.clear(); - m_ss.str(""); -} - -void TableFormatter::dump_format_va(std::string_view name, - const char *ns, bool quoted, - const char *fmt, va_list ap) -{ - finish_pending_string(); - auto buf = boost::container::small_vector{ - LARGE_SIZE, boost::container::default_init}; - - va_list ap_copy; - va_copy(ap_copy, ap); - int len = vsnprintf(buf.data(), buf.size(), fmt, ap_copy); - va_end(ap_copy); - - if (std::cmp_greater_equal(len, buf.size())) { - // output was truncated, allocate a buffer large enough - buf.resize(len + 1, boost::container::default_init); - vsnprintf(buf.data(), buf.size(), fmt, ap); - } - - size_t i = m_vec_index(name); - if (ns) { - m_ss << ns << "." << buf.data(); - } else { - m_ss << buf.data(); - } - - m_vec[i].push_back(std::make_pair(get_section_name(name), m_ss.str())); - m_ss.clear(); - m_ss.str(""); -} - -std::ostream& TableFormatter::dump_stream(std::string_view name) -{ - finish_pending_string(); - // we don't support this - m_pending_name = name; - return m_ss; -} - -int TableFormatter::get_len() const -{ - // we don't know the size until flush is called - return 0; -} - -void TableFormatter::write_raw_data(const char *data) { - // not supported -} - -void TableFormatter::get_attrs_str(const FormatterAttrs *attrs, std::string& attrs_str) const -{ - CachedStackStringStream css; - - for (const auto &p : attrs->attrs) { - *css << " " << p.first << "=" << "\"" << p.second << "\""; - } - - attrs_str = css->strv(); -} - -void TableFormatter::finish_pending_string() -{ - if (m_pending_name.length()) { - std::string ss = m_ss.str(); - m_ss.clear(); - m_ss.str(""); - std::string pending_name = m_pending_name; - m_pending_name = ""; - dump_string(pending_name.c_str(), ss); - } -} -} - diff --git a/src/common/Formatter.h b/src/common/Formatter.h index 05814ec66c3..0c20b61f06f 100644 --- a/src/common/Formatter.h +++ b/src/common/Formatter.h @@ -5,16 +5,12 @@ #include "include/buffer_fwd.h" -#include -#include #include #include #include -#include +#include + #include -#include -#include -#include namespace ceph { @@ -247,272 +243,6 @@ namespace ceph { virtual void write_bin_data(const char* buff, int buf_len); }; - class JSONFormatter : public Formatter { - public: - explicit JSONFormatter(bool p = false) : m_pretty(p) {} - JSONFormatter(const JSONFormatter& f) : - m_pretty(f.m_pretty), - m_pending_name(f.m_pending_name), - m_stack(f.m_stack), - m_is_pending_string(f.m_is_pending_string), - m_line_break_enabled(f.m_line_break_enabled) - { - m_ss.str(f.m_ss.str()); - m_pending_string.str(f.m_pending_string.str()); - } - JSONFormatter(JSONFormatter&& f) : - m_pretty(f.m_pretty), - m_ss(std::move(f.m_ss)), - m_pending_string(std::move(f.m_pending_string)), - m_pending_name(f.m_pending_name), - m_stack(std::move(f.m_stack)), - m_is_pending_string(f.m_is_pending_string), - m_line_break_enabled(f.m_line_break_enabled) - { - } - JSONFormatter& operator=(const JSONFormatter& f) - { - m_pretty = f.m_pretty; - m_ss.str(f.m_ss.str()); - m_pending_string.str(f.m_pending_string.str()); - m_pending_name = f.m_pending_name; - m_stack = f.m_stack; - m_is_pending_string = f.m_is_pending_string; - m_line_break_enabled = f.m_line_break_enabled; - return *this; - } - - JSONFormatter& operator=(JSONFormatter&& f) - { - m_pretty = f.m_pretty; - m_ss = std::move(f.m_ss); - m_pending_string = std::move(f.m_pending_string); - m_pending_name = f.m_pending_name; - m_stack = std::move(f.m_stack); - m_is_pending_string = f.m_is_pending_string; - m_line_break_enabled = f.m_line_break_enabled; - return *this; - } - - void set_status(int status, const char* status_name) override {}; - void output_header() override {}; - void output_footer() override {}; - void enable_line_break() override { m_line_break_enabled = true; } - void flush(std::ostream& os) override; - using Formatter::flush; // don't hide Formatter::flush(bufferlist &bl) - void reset() override; - void open_array_section(std::string_view name) override; - void open_array_section_in_ns(std::string_view name, const char *ns) override; - void open_object_section(std::string_view name) override; - void open_object_section_in_ns(std::string_view name, const char *ns) override; - void close_section() override; - void dump_null(std::string_view name) override; - void dump_unsigned(std::string_view name, uint64_t u) override; - void dump_int(std::string_view name, int64_t s) override; - void dump_float(std::string_view name, double d) override; - void dump_string(std::string_view name, std::string_view s) override; - std::ostream& dump_stream(std::string_view name) override; - void dump_format_va(std::string_view name, const char *ns, bool quoted, const char *fmt, va_list ap) override; - int get_len() const override; - void write_raw_data(const char *data) override; - -protected: - virtual bool handle_value(std::string_view name, std::string_view s, bool quoted) { - return false; /* is handling done? */ - } - - virtual bool handle_open_section(std::string_view name, const char *ns, bool is_array) { - return false; /* is handling done? */ - } - - virtual bool handle_close_section() { - return false; /* is handling done? */ - } - - int stack_size() { return m_stack.size(); } - - virtual std::ostream& get_ss() { - return m_ss; - } - - void finish_pending_string(); - -private: - struct json_formatter_stack_entry_d { - int size = 0; - bool is_array = false; - }; - - bool m_pretty = false; - void open_section(std::string_view name, const char *ns, bool is_array); - void print_quoted_string(std::string_view s); - void print_name(std::string_view name); - void print_comma(json_formatter_stack_entry_d& entry); - void add_value(std::string_view name, double val); - - template - void add_value(std::string_view name, T val); - void add_value(std::string_view name, std::string_view val, bool quoted); - - mutable std::stringstream m_ss; // mutable for get_len - std::stringstream m_pending_string; - std::string m_pending_name; - std::vector m_stack; - bool m_is_pending_string = false; - bool m_line_break_enabled = false; - }; - - class JSONFormatterFile : public JSONFormatter { -public: - JSONFormatterFile(const std::string& path, bool pretty=false) : - JSONFormatter(pretty), - path(path), - file(path, std::ios::out | std::ios::trunc) - { - } - ~JSONFormatterFile() { - flush(); - } - - void flush(std::ostream& os) override { - flush(); - } - void flush() { - JSONFormatter::finish_pending_string(); - file.flush(); - } - - void reset() override { - JSONFormatter::reset(); - file = std::ofstream(path, std::ios::out | std::ios::trunc); - } - int get_len() const override { - return file.tellp(); - } - std::ofstream const& get_ofstream() const { - return file; - } - -protected: - std::ostream& get_ss() override { - return file; - } - -private: - std::string path; - mutable std::ofstream file; // mutable for get_len - }; - - template - void add_value(std::string_view name, T val); - - class XMLFormatter : public Formatter { - public: - static const char *XML_1_DTD; - XMLFormatter(bool pretty = false, bool lowercased = false, bool underscored = true); - - void set_status(int status, const char* status_name) override {} - void output_header() override; - void output_footer() override; - - void enable_line_break() override { m_line_break_enabled = true; } - void flush(std::ostream& os) override; - using Formatter::flush; // don't hide Formatter::flush(bufferlist &bl) - void reset() override; - void open_array_section(std::string_view name) override; - void open_array_section_in_ns(std::string_view name, const char *ns) override; - void open_object_section(std::string_view name) override; - void open_object_section_in_ns(std::string_view name, const char *ns) override; - void close_section() override; - void dump_null(std::string_view name) override; - void dump_unsigned(std::string_view name, uint64_t u) override; - void dump_int(std::string_view name, int64_t s) override; - void dump_float(std::string_view name, double d) override; - void dump_string(std::string_view name, std::string_view s) override; - std::ostream& dump_stream(std::string_view name) override; - void dump_format_va(std::string_view name, const char *ns, bool quoted, const char *fmt, va_list ap) override; - int get_len() const override; - void write_raw_data(const char *data) override; - void write_bin_data(const char* buff, int len) override; - - /* with attrs */ - void open_array_section_with_attrs(std::string_view name, const FormatterAttrs& attrs) override; - void open_object_section_with_attrs(std::string_view name, const FormatterAttrs& attrs) override; - void dump_string_with_attrs(std::string_view name, std::string_view s, const FormatterAttrs& attrs) override; - - protected: - void open_section_in_ns(std::string_view name, const char *ns, const FormatterAttrs *attrs); - void finish_pending_string(); - void print_spaces(); - void get_attrs_str(const FormatterAttrs *attrs, std::string& attrs_str) const; - char to_lower_underscore(char c) const; - std::string get_xml_name(std::string_view name) const; - - std::stringstream m_ss, m_pending_string; - std::deque m_sections; - const bool m_pretty; - const bool m_lowercased; - const bool m_underscored; - std::string m_pending_string_name; - bool m_header_done; - bool m_line_break_enabled = false; - private: - template - void add_value(std::string_view name, T val); - }; - - class TableFormatter : public Formatter { - public: - explicit TableFormatter(bool keyval = false); - - void set_status(int status, const char* status_name) override {}; - void output_header() override {}; - void output_footer() override {}; - void enable_line_break() override {}; - void flush(std::ostream& os) override; - using Formatter::flush; // don't hide Formatter::flush(bufferlist &bl) - void reset() override; - void open_array_section(std::string_view name) override; - void open_array_section_in_ns(std::string_view name, const char *ns) override; - void open_object_section(std::string_view name) override; - void open_object_section_in_ns(std::string_view name, const char *ns) override; - - void open_array_section_with_attrs(std::string_view name, const FormatterAttrs& attrs) override; - void open_object_section_with_attrs(std::string_view name, const FormatterAttrs& attrs) override; - - void close_section() override; - void dump_null(std::string_view name) override; - void dump_unsigned(std::string_view name, uint64_t u) override; - void dump_int(std::string_view name, int64_t s) override; - void dump_float(std::string_view name, double d) override; - void dump_string(std::string_view name, std::string_view s) override; - void dump_format_va(std::string_view name, const char *ns, bool quoted, const char *fmt, va_list ap) override; - void dump_string_with_attrs(std::string_view name, std::string_view s, const FormatterAttrs& attrs) override; - std::ostream& dump_stream(std::string_view name) override; - - int get_len() const override; - void write_raw_data(const char *data) override; - void get_attrs_str(const FormatterAttrs *attrs, std::string& attrs_str) const; - - private: - template - void add_value(std::string_view name, T val); - void open_section_in_ns(std::string_view name, const char *ns, const FormatterAttrs *attrs); - std::vector< std::vector > > m_vec; - std::stringstream m_ss; - size_t m_vec_index(std::string_view name); - std::string get_section_name(std::string_view name); - void finish_pending_string(); - std::string m_pending_name; - bool m_keyval; - - int m_section_open; - std::vector< std::string > m_section; - std::map m_section_cnt; - std::vector m_column_size; - std::vector< std::string > m_column_name; - }; - std::string fixed_to_string(int64_t num, int scale); std::string fixed_u_to_string(uint64_t num, int scale); } diff --git a/src/common/HTMLFormatter.cc b/src/common/HTMLFormatter.cc index 1bc8d864cb6..1f452710f60 100644 --- a/src/common/HTMLFormatter.cc +++ b/src/common/HTMLFormatter.cc @@ -17,7 +17,6 @@ #include "HTMLFormatter.h" #include "Formatter.h" -#include #include #include #include diff --git a/src/common/HTMLFormatter.h b/src/common/HTMLFormatter.h index cc891824b03..d01d2d8b603 100644 --- a/src/common/HTMLFormatter.h +++ b/src/common/HTMLFormatter.h @@ -3,7 +3,7 @@ #ifndef CEPH_HTML_FORMATTER_H #define CEPH_HTML_FORMATTER_H -#include "Formatter.h" +#include "XMLFormatter.h" namespace ceph { class HTMLFormatter : public XMLFormatter { diff --git a/src/common/JSONFormatter.cc b/src/common/JSONFormatter.cc new file mode 100644 index 00000000000..7308f44b13c --- /dev/null +++ b/src/common/JSONFormatter.cc @@ -0,0 +1,265 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab +/* + * Ceph - scalable distributed file system + * + * Copyright (C) 2011 New Dream Network + * + * This is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software + * Foundation. See file COPYING. + * + */ + +#include "JSONFormatter.h" +#include "common/escape.h" +#include "common/StackStringStream.h" +#include "include/ceph_assert.h" + +#include + +#include // for std::isfinite(), std::isnan() +#include +#include + +#define LARGE_SIZE 1024 + +namespace ceph { + +void JSONFormatter::flush(std::ostream& os) +{ + finish_pending_string(); + os << m_ss.str(); + if (m_line_break_enabled) + os << "\n"; + m_ss.clear(); + m_ss.str(""); +} + +void JSONFormatter::reset() +{ + m_stack.clear(); + m_ss.clear(); + m_ss.str(""); + m_pending_string.clear(); + m_pending_string.str(""); +} + +void JSONFormatter::print_comma(json_formatter_stack_entry_d& entry) +{ + auto& ss = get_ss(); + if (entry.size) { + if (m_pretty) { + ss << ",\n"; + for (unsigned i = 1; i < m_stack.size(); i++) + ss << " "; + } else { + ss << ","; + } + } else if (m_pretty) { + ss << "\n"; + for (unsigned i = 1; i < m_stack.size(); i++) + ss << " "; + } + if (m_pretty && entry.is_array) + ss << " "; +} + +void JSONFormatter::print_quoted_string(std::string_view s) +{ + auto& ss = get_ss(); + ss << '\"' << json_stream_escaper(s) << '\"'; +} + +void JSONFormatter::print_name(std::string_view name) +{ + auto& ss = get_ss(); + finish_pending_string(); + if (m_stack.empty()) + return; + struct json_formatter_stack_entry_d& entry = m_stack.back(); + print_comma(entry); + if (!entry.is_array) { + if (m_pretty) { + ss << " "; + } + ss << "\"" << name << "\""; + if (m_pretty) + ss << ": "; + else + ss << ':'; + } + ++entry.size; +} + +void JSONFormatter::open_section(std::string_view name, const char *ns, bool is_array) +{ + auto& ss = get_ss(); + if (handle_open_section(name, ns, is_array)) { + return; + } + if (ns) { + std::ostringstream oss; + oss << name << " " << ns; + print_name(oss.str().c_str()); + } else { + print_name(name); + } + if (is_array) + ss << '['; + else + ss << '{'; + + json_formatter_stack_entry_d n; + n.is_array = is_array; + m_stack.push_back(n); +} + +void JSONFormatter::open_array_section(std::string_view name) +{ + open_section(name, nullptr, true); +} + +void JSONFormatter::open_array_section_in_ns(std::string_view name, const char *ns) +{ + open_section(name, ns, true); +} + +void JSONFormatter::open_object_section(std::string_view name) +{ + open_section(name, nullptr, false); +} + +void JSONFormatter::open_object_section_in_ns(std::string_view name, const char *ns) +{ + open_section(name, ns, false); +} + +void JSONFormatter::close_section() +{ + auto& ss = get_ss(); + if (handle_close_section()) { + return; + } + ceph_assert(!m_stack.empty()); + finish_pending_string(); + + struct json_formatter_stack_entry_d& entry = m_stack.back(); + if (m_pretty && entry.size) { + ss << "\n"; + for (unsigned i = 1; i < m_stack.size(); i++) + ss << " "; + } + ss << (entry.is_array ? ']' : '}'); + m_stack.pop_back(); + if (m_pretty && m_stack.empty()) + ss << "\n"; +} + +void JSONFormatter::finish_pending_string() +{ + if (m_is_pending_string) { + m_is_pending_string = false; + add_value(m_pending_name.c_str(), m_pending_string.str(), true); + m_pending_string.str(""); + } +} + +void JSONFormatter::add_value(std::string_view name, double val) { + CachedStackStringStream css; + if (!std::isfinite(val) || std::isnan(val)) { + *css << "null"; + } else { + css->precision(std::numeric_limits::max_digits10); + *css << val; + } + add_value(name, css->strv(), false); +} + +template +void JSONFormatter::add_value(std::string_view name, T val) +{ + CachedStackStringStream css; + css->precision(std::numeric_limits::max_digits10); + *css << val; + add_value(name, css->strv(), false); +} + +void JSONFormatter::add_value(std::string_view name, std::string_view val, bool quoted) +{ + auto& ss = get_ss(); + if (handle_value(name, val, quoted)) { + return; + } + print_name(name); + if (!quoted) { + ss << val; + } else { + print_quoted_string(val); + } +} + +void JSONFormatter::dump_null(std::string_view name) +{ + add_value(name, "null"); +} + +void JSONFormatter::dump_unsigned(std::string_view name, uint64_t u) +{ + add_value(name, u); +} + +void JSONFormatter::dump_int(std::string_view name, int64_t s) +{ + add_value(name, s); +} + +void JSONFormatter::dump_float(std::string_view name, double d) +{ + add_value(name, d); +} + +void JSONFormatter::dump_string(std::string_view name, std::string_view s) +{ + add_value(name, s, true); +} + +std::ostream& JSONFormatter::dump_stream(std::string_view name) +{ + finish_pending_string(); + m_pending_name = name; + m_is_pending_string = true; + return m_pending_string; +} + +void JSONFormatter::dump_format_va(std::string_view name, const char *ns, bool quoted, const char *fmt, va_list ap) +{ + auto buf = boost::container::small_vector{ + LARGE_SIZE, boost::container::default_init}; + + va_list ap_copy; + va_copy(ap_copy, ap); + int len = vsnprintf(buf.data(), buf.size(), fmt, ap_copy); + va_end(ap_copy); + + if (std::cmp_greater_equal(len, buf.size())) { + // output was truncated, allocate a buffer large enough + buf.resize(len + 1, boost::container::default_init); + vsnprintf(buf.data(), buf.size(), fmt, ap); + } + + add_value(name, buf.data(), quoted); +} + +int JSONFormatter::get_len() const +{ + return m_ss.tellp(); +} + +void JSONFormatter::write_raw_data(const char *data) +{ + get_ss() << data; +} + +} diff --git a/src/common/JSONFormatter.h b/src/common/JSONFormatter.h new file mode 100644 index 00000000000..4cc711d83dd --- /dev/null +++ b/src/common/JSONFormatter.h @@ -0,0 +1,128 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab + +#pragma once + +#include "common/Formatter.h" + +#include +#include + +namespace ceph { + + class JSONFormatter : public Formatter { + public: + explicit JSONFormatter(bool p = false) : m_pretty(p) {} + JSONFormatter(const JSONFormatter& f) : + m_pretty(f.m_pretty), + m_pending_name(f.m_pending_name), + m_stack(f.m_stack), + m_is_pending_string(f.m_is_pending_string), + m_line_break_enabled(f.m_line_break_enabled) + { + m_ss.str(f.m_ss.str()); + m_pending_string.str(f.m_pending_string.str()); + } + JSONFormatter(JSONFormatter&& f) : + m_pretty(f.m_pretty), + m_ss(std::move(f.m_ss)), + m_pending_string(std::move(f.m_pending_string)), + m_pending_name(f.m_pending_name), + m_stack(std::move(f.m_stack)), + m_is_pending_string(f.m_is_pending_string), + m_line_break_enabled(f.m_line_break_enabled) + { + } + JSONFormatter& operator=(const JSONFormatter& f) + { + m_pretty = f.m_pretty; + m_ss.str(f.m_ss.str()); + m_pending_string.str(f.m_pending_string.str()); + m_pending_name = f.m_pending_name; + m_stack = f.m_stack; + m_is_pending_string = f.m_is_pending_string; + m_line_break_enabled = f.m_line_break_enabled; + return *this; + } + + JSONFormatter& operator=(JSONFormatter&& f) + { + m_pretty = f.m_pretty; + m_ss = std::move(f.m_ss); + m_pending_string = std::move(f.m_pending_string); + m_pending_name = f.m_pending_name; + m_stack = std::move(f.m_stack); + m_is_pending_string = f.m_is_pending_string; + m_line_break_enabled = f.m_line_break_enabled; + return *this; + } + + void set_status(int status, const char* status_name) override {}; + void output_header() override {}; + void output_footer() override {}; + void enable_line_break() override { m_line_break_enabled = true; } + void flush(std::ostream& os) override; + using Formatter::flush; // don't hide Formatter::flush(bufferlist &bl) + void reset() override; + void open_array_section(std::string_view name) override; + void open_array_section_in_ns(std::string_view name, const char *ns) override; + void open_object_section(std::string_view name) override; + void open_object_section_in_ns(std::string_view name, const char *ns) override; + void close_section() override; + void dump_null(std::string_view name) override; + void dump_unsigned(std::string_view name, uint64_t u) override; + void dump_int(std::string_view name, int64_t s) override; + void dump_float(std::string_view name, double d) override; + void dump_string(std::string_view name, std::string_view s) override; + std::ostream& dump_stream(std::string_view name) override; + void dump_format_va(std::string_view name, const char *ns, bool quoted, const char *fmt, va_list ap) override; + int get_len() const override; + void write_raw_data(const char *data) override; + +protected: + virtual bool handle_value(std::string_view name, std::string_view s, bool quoted) { + return false; /* is handling done? */ + } + + virtual bool handle_open_section(std::string_view name, const char *ns, bool is_array) { + return false; /* is handling done? */ + } + + virtual bool handle_close_section() { + return false; /* is handling done? */ + } + + int stack_size() { return m_stack.size(); } + + virtual std::ostream& get_ss() { + return m_ss; + } + + void finish_pending_string(); + +private: + struct json_formatter_stack_entry_d { + int size = 0; + bool is_array = false; + }; + + bool m_pretty = false; + void open_section(std::string_view name, const char *ns, bool is_array); + void print_quoted_string(std::string_view s); + void print_name(std::string_view name); + void print_comma(json_formatter_stack_entry_d& entry); + void add_value(std::string_view name, double val); + + template + void add_value(std::string_view name, T val); + void add_value(std::string_view name, std::string_view val, bool quoted); + + mutable std::stringstream m_ss; // mutable for get_len + std::stringstream m_pending_string; + std::string m_pending_name; + std::vector m_stack; + bool m_is_pending_string = false; + bool m_line_break_enabled = false; + }; + +} diff --git a/src/common/JSONFormatterFile.h b/src/common/JSONFormatterFile.h new file mode 100644 index 00000000000..91a68737622 --- /dev/null +++ b/src/common/JSONFormatterFile.h @@ -0,0 +1,54 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab + +#pragma once + +#include "JSONFormatter.h" + +#include + +namespace ceph { + + class JSONFormatterFile : public JSONFormatter { +public: + JSONFormatterFile(const std::string& path, bool pretty=false) : + JSONFormatter(pretty), + path(path), + file(path, std::ios::out | std::ios::trunc) + { + } + ~JSONFormatterFile() { + flush(); + } + + void flush(std::ostream& os) override { + flush(); + } + void flush() { + JSONFormatter::finish_pending_string(); + file.flush(); + } + + void reset() override { + JSONFormatter::reset(); + file = std::ofstream(path, std::ios::out | std::ios::trunc); + } + int get_len() const override { + return file.tellp(); + } + std::ofstream const& get_ofstream() const { + return file; + } + +protected: + std::ostream& get_ss() override { + return file; + } + +private: + std::string path; + mutable std::ofstream file; // mutable for get_len + }; + +} + diff --git a/src/common/TableFormatter.cc b/src/common/TableFormatter.cc new file mode 100644 index 00000000000..8995d6c05ed --- /dev/null +++ b/src/common/TableFormatter.cc @@ -0,0 +1,378 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab +/* + * Ceph - scalable distributed file system + * + * Copyright (C) 2011 New Dream Network + * + * This is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software + * Foundation. See file COPYING. + * + */ + +#include "TableFormatter.h" +#include "common/escape.h" +#include "common/StackStringStream.h" +#include "include/buffer.h" + +#include +#include + +#include +#include +#include +#include + +#define LARGE_SIZE 1024 + +namespace ceph { + +TableFormatter::TableFormatter(bool keyval) : m_keyval(keyval) +{ + reset(); +} + +void TableFormatter::flush(std::ostream& os) +{ + finish_pending_string(); + std::vector column_size = m_column_size; + std::vector column_name = m_column_name; + + std::set need_header_set; + + // auto-sizing columns + for (size_t i = 0; i < m_vec.size(); i++) { + for (size_t j = 0; j < m_vec[i].size(); j++) { + column_size.resize(m_vec[i].size()); + column_name.resize(m_vec[i].size()); + if (i > 0) { + if (m_vec[i - 1][j] != m_vec[i][j]) { + // changing row labels require to show the header + need_header_set.insert(i); + column_name[i] = m_vec[i][j].first; + } + } else { + column_name[i] = m_vec[i][j].first; + } + + if (m_vec[i][j].second.length() > column_size[j]) + column_size[j] = m_vec[i][j].second.length(); + if (m_vec[i][j].first.length() > column_size[j]) + column_size[j] = m_vec[i][j].first.length(); + } + } + + bool need_header = false; + if ((column_size.size() == m_column_size.size())) { + for (size_t i = 0; i < column_size.size(); i++) { + if (column_size[i] != m_column_size[i]) { + need_header = true; + break; + } + } + } else { + need_header = true; + } + + if (need_header) { + // first row always needs a header if there wasn't one before + need_header_set.insert(0); + } + + m_column_size = column_size; + for (size_t i = 0; i < m_vec.size(); i++) { + if (i == 0) { + if (need_header_set.count(i)) { + // print the header + if (!m_keyval) { + os << "+"; + for (size_t j = 0; j < m_vec[i].size(); j++) { + for (size_t v = 0; v < m_column_size[j] + 3; v++) + os << "-"; + os << "+"; + } + os << "\n"; + os << "|"; + + for (size_t j = 0; j < m_vec[i].size(); j++) { + os << fmt::format(" {:<{}}|", + m_vec[i][j].first, m_column_size[j] + 2); + } + os << "\n"; + os << "+"; + for (size_t j = 0; j < m_vec[i].size(); j++) { + for (size_t v = 0; v < m_column_size[j] + 3; v++) + os << "-"; + os << "+"; + } + os << "\n"; + } + } + } + // print body + if (!m_keyval) + os << "|"; + for (size_t j = 0; j < m_vec[i].size(); j++) { + if (!m_keyval) + os << " "; + if (m_keyval) { + os << "key::"; + os << m_vec[i][j].first; + os << "="; + os << "\""; + os << m_vec[i][j].second; + os << "\" "; + } else { + os << fmt::format("{:<{}}|", m_vec[i][j].second, m_column_size[j] + 2); + } + } + + os << "\n"; + if (!m_keyval) { + if (i == (m_vec.size() - 1)) { + // print trailer + os << "+"; + for (size_t j = 0; j < m_vec[i].size(); j++) { + for (size_t v = 0; v < m_column_size[j] + 3; v++) + os << "-"; + os << "+"; + } + os << "\n"; + } + } + m_vec[i].clear(); + } + m_vec.clear(); +} + +void TableFormatter::reset() +{ + m_ss.clear(); + m_ss.str(""); + m_section_cnt.clear(); + m_column_size.clear(); + m_section_open = 0; +} + +void TableFormatter::open_object_section(std::string_view name) +{ + open_section_in_ns(name, NULL, NULL); +} + +void TableFormatter::open_object_section_with_attrs(std::string_view name, const FormatterAttrs& attrs) +{ + open_section_in_ns(name, NULL, NULL); +} + +void TableFormatter::open_object_section_in_ns(std::string_view name, const char *ns) +{ + open_section_in_ns(name, NULL, NULL); +} + +void TableFormatter::open_array_section(std::string_view name) +{ + open_section_in_ns(name, NULL, NULL); +} + +void TableFormatter::open_array_section_with_attrs(std::string_view name, const FormatterAttrs& attrs) +{ + open_section_in_ns(name, NULL, NULL); +} + +void TableFormatter::open_array_section_in_ns(std::string_view name, const char *ns) +{ + open_section_in_ns(name, NULL, NULL); +} + +void TableFormatter::open_section_in_ns(std::string_view name, const char *ns, const FormatterAttrs *attrs) +{ + m_section.push_back(std::string(name)); + m_section_open++; +} + +void TableFormatter::close_section() +{ + // + m_section_open--; + if (m_section.size()) { + m_section_cnt[m_section.back()] = 0; + m_section.pop_back(); + } +} + +size_t TableFormatter::m_vec_index(std::string_view name) +{ + std::string key(name); + + size_t i = m_vec.size(); + if (i) + i--; + + // make sure there are vectors to push back key/val pairs + if (!m_vec.size()) + m_vec.resize(1); + + if (m_vec.size()) { + if (m_vec[i].size()) { + if (m_vec[i][0].first == key) { + // start a new column if a key is repeated + m_vec.resize(m_vec.size() + 1); + i++; + } + } + } + + return i; +} + +std::string TableFormatter::get_section_name(std::string_view name) +{ + std::string t_name{name}; + for (const auto &i : m_section) { + t_name.insert(0, ":"); + t_name.insert(0, i); + } + if (m_section_open) { + std::stringstream lss; + lss << t_name; + lss << "["; + lss << m_section_cnt[t_name]++; + lss << "]"; + return lss.str(); + } else { + return t_name; + } +} + +template +void TableFormatter::add_value(std::string_view name, T val) { + finish_pending_string(); + size_t i = m_vec_index(name); + m_ss.precision(std::numeric_limits::max_digits10); + m_ss << val; + + m_vec[i].push_back(std::make_pair(get_section_name(name), m_ss.str())); + m_ss.clear(); + m_ss.str(""); +} + +void TableFormatter::dump_null(std::string_view name) +{ + add_value(name, "null"); +} + +void TableFormatter::dump_unsigned(std::string_view name, uint64_t u) +{ + add_value(name, u); +} + +void TableFormatter::dump_int(std::string_view name, int64_t s) +{ + add_value(name, s); +} + +void TableFormatter::dump_float(std::string_view name, double d) +{ + add_value(name, d); +} + +void TableFormatter::dump_string(std::string_view name, std::string_view s) +{ + finish_pending_string(); + size_t i = m_vec_index(name); + m_ss << s; + + m_vec[i].push_back(std::make_pair(get_section_name(name), m_ss.str())); + m_ss.clear(); + m_ss.str(""); +} + +void TableFormatter::dump_string_with_attrs(std::string_view name, std::string_view s, const FormatterAttrs& attrs) +{ + finish_pending_string(); + size_t i = m_vec_index(name); + + std::string attrs_str; + get_attrs_str(&attrs, attrs_str); + m_ss << attrs_str << s; + + m_vec[i].push_back(std::make_pair(get_section_name(name), m_ss.str())); + m_ss.clear(); + m_ss.str(""); +} + +void TableFormatter::dump_format_va(std::string_view name, + const char *ns, bool quoted, + const char *fmt, va_list ap) +{ + finish_pending_string(); + auto buf = boost::container::small_vector{ + LARGE_SIZE, boost::container::default_init}; + + va_list ap_copy; + va_copy(ap_copy, ap); + int len = vsnprintf(buf.data(), buf.size(), fmt, ap_copy); + va_end(ap_copy); + + if (std::cmp_greater_equal(len, buf.size())) { + // output was truncated, allocate a buffer large enough + buf.resize(len + 1, boost::container::default_init); + vsnprintf(buf.data(), buf.size(), fmt, ap); + } + + size_t i = m_vec_index(name); + if (ns) { + m_ss << ns << "." << buf.data(); + } else { + m_ss << buf.data(); + } + + m_vec[i].push_back(std::make_pair(get_section_name(name), m_ss.str())); + m_ss.clear(); + m_ss.str(""); +} + +std::ostream& TableFormatter::dump_stream(std::string_view name) +{ + finish_pending_string(); + // we don't support this + m_pending_name = name; + return m_ss; +} + +int TableFormatter::get_len() const +{ + // we don't know the size until flush is called + return 0; +} + +void TableFormatter::write_raw_data(const char *data) { + // not supported +} + +void TableFormatter::get_attrs_str(const FormatterAttrs *attrs, std::string& attrs_str) const +{ + CachedStackStringStream css; + + for (const auto &p : attrs->attrs) { + *css << " " << p.first << "=" << "\"" << p.second << "\""; + } + + attrs_str = css->strv(); +} + +void TableFormatter::finish_pending_string() +{ + if (m_pending_name.length()) { + std::string ss = m_ss.str(); + m_ss.clear(); + m_ss.str(""); + std::string pending_name = m_pending_name; + m_pending_name = ""; + dump_string(pending_name.c_str(), ss); + } +} + +} diff --git a/src/common/TableFormatter.h b/src/common/TableFormatter.h new file mode 100644 index 00000000000..31bfaa2b21c --- /dev/null +++ b/src/common/TableFormatter.h @@ -0,0 +1,67 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab + +#pragma once + +#include "common/Formatter.h" + +#include +#include +#include +#include + +namespace ceph { + + class TableFormatter : public Formatter { + public: + explicit TableFormatter(bool keyval = false); + + void set_status(int status, const char* status_name) override {}; + void output_header() override {}; + void output_footer() override {}; + void enable_line_break() override {}; + void flush(std::ostream& os) override; + using Formatter::flush; // don't hide Formatter::flush(bufferlist &bl) + void reset() override; + void open_array_section(std::string_view name) override; + void open_array_section_in_ns(std::string_view name, const char *ns) override; + void open_object_section(std::string_view name) override; + void open_object_section_in_ns(std::string_view name, const char *ns) override; + + void open_array_section_with_attrs(std::string_view name, const FormatterAttrs& attrs) override; + void open_object_section_with_attrs(std::string_view name, const FormatterAttrs& attrs) override; + + void close_section() override; + void dump_null(std::string_view name) override; + void dump_unsigned(std::string_view name, uint64_t u) override; + void dump_int(std::string_view name, int64_t s) override; + void dump_float(std::string_view name, double d) override; + void dump_string(std::string_view name, std::string_view s) override; + void dump_format_va(std::string_view name, const char *ns, bool quoted, const char *fmt, va_list ap) override; + void dump_string_with_attrs(std::string_view name, std::string_view s, const FormatterAttrs& attrs) override; + std::ostream& dump_stream(std::string_view name) override; + + int get_len() const override; + void write_raw_data(const char *data) override; + void get_attrs_str(const FormatterAttrs *attrs, std::string& attrs_str) const; + + private: + template + void add_value(std::string_view name, T val); + void open_section_in_ns(std::string_view name, const char *ns, const FormatterAttrs *attrs); + std::vector< std::vector > > m_vec; + std::stringstream m_ss; + size_t m_vec_index(std::string_view name); + std::string get_section_name(std::string_view name); + void finish_pending_string(); + std::string m_pending_name; + bool m_keyval; + + int m_section_open; + std::vector< std::string > m_section; + std::map m_section_cnt; + std::vector m_column_size; + std::vector< std::string > m_column_name; + }; + +} diff --git a/src/common/XMLFormatter.cc b/src/common/XMLFormatter.cc new file mode 100644 index 00000000000..e1baaf0f087 --- /dev/null +++ b/src/common/XMLFormatter.cc @@ -0,0 +1,307 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab +/* + * Ceph - scalable distributed file system + * + * Copyright (C) 2011 New Dream Network + * + * This is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software + * Foundation. See file COPYING. + * + */ + +#include "XMLFormatter.h" +#include "common/escape.h" +#include "common/StackStringStream.h" +#include "include/ceph_assert.h" + +#include + +#include +#include +#include + +#define LARGE_SIZE 1024 + +namespace ceph { + +const char *XMLFormatter::XML_1_DTD = + ""; + +XMLFormatter::XMLFormatter(bool pretty, bool lowercased, bool underscored) +: m_pretty(pretty), + m_lowercased(lowercased), + m_underscored(underscored) +{ + reset(); +} + +void XMLFormatter::flush(std::ostream& os) +{ + finish_pending_string(); + std::string m_ss_str = m_ss.str(); + os << m_ss_str; + /* There is a small catch here. If the rest of the formatter had NO output, + * we should NOT output a newline. This primarily triggers on HTTP redirects */ + if (m_pretty && !m_ss_str.empty()) + os << "\n"; + else if (m_line_break_enabled) + os << "\n"; + m_ss.clear(); + m_ss.str(""); +} + +void XMLFormatter::reset() +{ + m_ss.clear(); + m_ss.str(""); + m_pending_string.clear(); + m_pending_string.str(""); + m_sections.clear(); + m_pending_string_name.clear(); + m_header_done = false; +} + +void XMLFormatter::output_header() +{ + if(!m_header_done) { + m_header_done = true; + write_raw_data(XMLFormatter::XML_1_DTD); + if (m_pretty) + m_ss << "\n"; + } +} + +void XMLFormatter::output_footer() +{ + while(!m_sections.empty()) { + close_section(); + } +} + +void XMLFormatter::open_object_section(std::string_view name) +{ + open_section_in_ns(name, NULL, NULL); +} + +void XMLFormatter::open_object_section_with_attrs(std::string_view name, const FormatterAttrs& attrs) +{ + open_section_in_ns(name, NULL, &attrs); +} + +void XMLFormatter::open_object_section_in_ns(std::string_view name, const char *ns) +{ + open_section_in_ns(name, ns, NULL); +} + +void XMLFormatter::open_array_section(std::string_view name) +{ + open_section_in_ns(name, NULL, NULL); +} + +void XMLFormatter::open_array_section_with_attrs(std::string_view name, const FormatterAttrs& attrs) +{ + open_section_in_ns(name, NULL, &attrs); +} + +void XMLFormatter::open_array_section_in_ns(std::string_view name, const char *ns) +{ + open_section_in_ns(name, ns, NULL); +} + +std::string XMLFormatter::get_xml_name(std::string_view name) const +{ + std::string e(name); + std::transform(e.begin(), e.end(), e.begin(), + [this](char c) { return this->to_lower_underscore(c); }); + return e; +} + +void XMLFormatter::close_section() +{ + ceph_assert(!m_sections.empty()); + finish_pending_string(); + + auto section = get_xml_name(m_sections.back()); + m_sections.pop_back(); + print_spaces(); + m_ss << ""; + if (m_pretty) + m_ss << "\n"; +} + +template +void XMLFormatter::add_value(std::string_view name, T val) +{ + auto e = get_xml_name(name); + print_spaces(); + m_ss.precision(std::numeric_limits::max_digits10); + m_ss << "<" << e << ">" << val << ""; + if (m_pretty) + m_ss << "\n"; +} + +void XMLFormatter::dump_null(std::string_view name) +{ + print_spaces(); + m_ss << "<" << get_xml_name(name) << " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:nil=\"true\" />"; + if (m_pretty) + m_ss << "\n"; +} + +void XMLFormatter::dump_unsigned(std::string_view name, uint64_t u) +{ + add_value(name, u); +} + +void XMLFormatter::dump_int(std::string_view name, int64_t s) +{ + add_value(name, s); +} + +void XMLFormatter::dump_float(std::string_view name, double d) +{ + add_value(name, d); +} + +void XMLFormatter::dump_string(std::string_view name, std::string_view s) +{ + auto e = get_xml_name(name); + print_spaces(); + m_ss << "<" << e << ">" << xml_stream_escaper(s) << ""; + if (m_pretty) + m_ss << "\n"; +} + +void XMLFormatter::dump_string_with_attrs(std::string_view name, std::string_view s, const FormatterAttrs& attrs) +{ + auto e = get_xml_name(name); + std::string attrs_str; + get_attrs_str(&attrs, attrs_str); + print_spaces(); + m_ss << "<" << e << attrs_str << ">" << xml_stream_escaper(s) << ""; + if (m_pretty) + m_ss << "\n"; +} + +std::ostream& XMLFormatter::dump_stream(std::string_view name) +{ + print_spaces(); + m_pending_string_name = name; + m_ss << "<" << m_pending_string_name << ">"; + return m_pending_string; +} + +void XMLFormatter::dump_format_va(std::string_view name, const char *ns, bool quoted, const char *fmt, va_list ap) +{ + auto buf = boost::container::small_vector{ + LARGE_SIZE, boost::container::default_init}; + + va_list ap_copy; + va_copy(ap_copy, ap); + int len = vsnprintf(buf.data(), buf.size(), fmt, ap_copy); + va_end(ap_copy); + + if (std::cmp_greater_equal(len, buf.size())) { + // output was truncated, allocate a buffer large enough + buf.resize(len + 1, boost::container::default_init); + vsnprintf(buf.data(), buf.size(), fmt, ap); + } + + auto e = get_xml_name(name); + + print_spaces(); + if (ns) { + m_ss << "<" << e << " xmlns=\"" << ns << "\">" << xml_stream_escaper(std::string_view(buf.data(), len)) << ""; + } else { + m_ss << "<" << e << ">" << xml_stream_escaper(std::string_view(buf.data(), len)) << ""; + } + + if (m_pretty) + m_ss << "\n"; +} + +int XMLFormatter::get_len() const +{ + return m_ss.str().size(); +} + +void XMLFormatter::write_raw_data(const char *data) +{ + m_ss << data; +} + +void XMLFormatter::write_bin_data(const char* buff, int buf_len) +{ + std::stringbuf *pbuf = m_ss.rdbuf(); + pbuf->sputn(buff, buf_len); + m_ss.seekg(buf_len); +} + +void XMLFormatter::get_attrs_str(const FormatterAttrs *attrs, std::string& attrs_str) const +{ + CachedStackStringStream css; + + for (const auto &p : attrs->attrs) { + *css << " " << p.first << "=" << "\"" << p.second << "\""; + } + + attrs_str = css->strv(); +} + +void XMLFormatter::open_section_in_ns(std::string_view name, const char *ns, const FormatterAttrs *attrs) +{ + print_spaces(); + std::string attrs_str; + + if (attrs) { + get_attrs_str(attrs, attrs_str); + } + + auto e = get_xml_name(name); + + if (ns) { + m_ss << "<" << e << attrs_str << " xmlns=\"" << ns << "\">"; + } else { + m_ss << "<" << e << attrs_str << ">"; + } + if (m_pretty) + m_ss << "\n"; + m_sections.push_back(std::string(name)); +} + +void XMLFormatter::finish_pending_string() +{ + if (!m_pending_string_name.empty()) { + m_ss << xml_stream_escaper(m_pending_string.str()) + << ""; + m_pending_string_name.clear(); + m_pending_string.str(std::string()); + if (m_pretty) { + m_ss << "\n"; + } + } +} + +void XMLFormatter::print_spaces() +{ + finish_pending_string(); + if (m_pretty) { + std::string spaces(m_sections.size(), ' '); + m_ss << spaces; + } +} + +char XMLFormatter::to_lower_underscore(char c) const +{ + if (m_underscored && c == ' ') { + return '_'; + } else if (m_lowercased) { + return std::tolower(c); + } + return c; +} + +} diff --git a/src/common/XMLFormatter.h b/src/common/XMLFormatter.h new file mode 100644 index 00000000000..7beb5c10d30 --- /dev/null +++ b/src/common/XMLFormatter.h @@ -0,0 +1,68 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab + +#pragma once + +#include "common/Formatter.h" + +#include +#include + +namespace ceph { + + class XMLFormatter : public Formatter { + public: + static const char *XML_1_DTD; + XMLFormatter(bool pretty = false, bool lowercased = false, bool underscored = true); + + void set_status(int status, const char* status_name) override {} + void output_header() override; + void output_footer() override; + + void enable_line_break() override { m_line_break_enabled = true; } + void flush(std::ostream& os) override; + using Formatter::flush; // don't hide Formatter::flush(bufferlist &bl) + void reset() override; + void open_array_section(std::string_view name) override; + void open_array_section_in_ns(std::string_view name, const char *ns) override; + void open_object_section(std::string_view name) override; + void open_object_section_in_ns(std::string_view name, const char *ns) override; + void close_section() override; + void dump_null(std::string_view name) override; + void dump_unsigned(std::string_view name, uint64_t u) override; + void dump_int(std::string_view name, int64_t s) override; + void dump_float(std::string_view name, double d) override; + void dump_string(std::string_view name, std::string_view s) override; + std::ostream& dump_stream(std::string_view name) override; + void dump_format_va(std::string_view name, const char *ns, bool quoted, const char *fmt, va_list ap) override; + int get_len() const override; + void write_raw_data(const char *data) override; + void write_bin_data(const char* buff, int len) override; + + /* with attrs */ + void open_array_section_with_attrs(std::string_view name, const FormatterAttrs& attrs) override; + void open_object_section_with_attrs(std::string_view name, const FormatterAttrs& attrs) override; + void dump_string_with_attrs(std::string_view name, std::string_view s, const FormatterAttrs& attrs) override; + + protected: + void open_section_in_ns(std::string_view name, const char *ns, const FormatterAttrs *attrs); + void finish_pending_string(); + void print_spaces(); + void get_attrs_str(const FormatterAttrs *attrs, std::string& attrs_str) const; + char to_lower_underscore(char c) const; + std::string get_xml_name(std::string_view name) const; + + std::stringstream m_ss, m_pending_string; + std::deque m_sections; + const bool m_pretty; + const bool m_lowercased; + const bool m_underscored; + std::string m_pending_string_name; + bool m_header_done; + bool m_line_break_enabled = false; + private: + template + void add_value(std::string_view name, T val); + }; + +} diff --git a/src/common/admin_socket.cc b/src/common/admin_socket.cc index 957f92ad4d3..3b5152d4edb 100644 --- a/src/common/admin_socket.cc +++ b/src/common/admin_socket.cc @@ -30,6 +30,7 @@ #include "common/admin_socket_client.h" #include "common/dout.h" #include "common/errno.h" +#include "common/JSONFormatterFile.h" #include "common/safe_io.h" #include "common/Thread.h" #include "common/version.h" diff --git a/src/common/ceph_json.h b/src/common/ceph_json.h index 485c91b149d..a2e4fba5d7c 100644 --- a/src/common/ceph_json.h +++ b/src/common/ceph_json.h @@ -17,7 +17,7 @@ #include "json_spirit/json_spirit.h" -#include "Formatter.h" +#include "JSONFormatter.h" diff --git a/src/crimson/CMakeLists.txt b/src/crimson/CMakeLists.txt index 4133494039c..aeca72c5cde 100644 --- a/src/crimson/CMakeLists.txt +++ b/src/crimson/CMakeLists.txt @@ -79,6 +79,9 @@ add_library(crimson-common STATIC ${PROJECT_SOURCE_DIR}/src/common/DecayCounter.cc ${PROJECT_SOURCE_DIR}/src/common/HTMLFormatter.cc ${PROJECT_SOURCE_DIR}/src/common/Formatter.cc + ${PROJECT_SOURCE_DIR}/src/common/JSONFormatter.cc + ${PROJECT_SOURCE_DIR}/src/common/TableFormatter.cc + ${PROJECT_SOURCE_DIR}/src/common/XMLFormatter.cc ${PROJECT_SOURCE_DIR}/src/common/Graylog.cc ${PROJECT_SOURCE_DIR}/src/common/Journald.cc ${PROJECT_SOURCE_DIR}/src/common/ostream_temp.cc diff --git a/src/crimson/os/cyanstore/cyan_store.cc b/src/crimson/os/cyanstore/cyan_store.cc index 9c3f5d6551c..b7dba884c4e 100644 --- a/src/crimson/os/cyanstore/cyan_store.cc +++ b/src/crimson/os/cyanstore/cyan_store.cc @@ -7,6 +7,7 @@ #include #include +#include "common/JSONFormatter.h" #include "common/safe_io.h" #include "os/Transaction.h" diff --git a/src/crimson/os/seastore/seastore.cc b/src/crimson/os/seastore/seastore.cc index 17926425cf1..d4ad567448b 100644 --- a/src/crimson/os/seastore/seastore.cc +++ b/src/crimson/os/seastore/seastore.cc @@ -14,6 +14,7 @@ #include #include +#include "common/JSONFormatter.h" #include "common/safe_io.h" #include "include/stringify.h" #include "os/Transaction.h" diff --git a/src/crimson/tools/store_bench/store-bench.cc b/src/crimson/tools/store_bench/store-bench.cc index 1312cbcb453..d00f95e7a34 100644 --- a/src/crimson/tools/store_bench/store-bench.cc +++ b/src/crimson/tools/store_bench/store-bench.cc @@ -41,6 +41,7 @@ #include #include +#include "common/JSONFormatter.h" #include "crimson/common/config_proxy.h" #include "crimson/common/coroutine.h" #include "crimson/common/log.h" diff --git a/src/global/signal_handler.cc b/src/global/signal_handler.cc index 1a9f43ce55f..b0974efdd1a 100644 --- a/src/global/signal_handler.cc +++ b/src/global/signal_handler.cc @@ -23,7 +23,7 @@ #include "common/Clock.h" // for ceph_clock_now() #include "common/BackTrace.h" #include "common/debug.h" -#include "common/Formatter.h" +#include "common/JSONFormatter.h" #include "common/safe_io.h" #include "common/version.h" diff --git a/src/libcephsqlite.cc b/src/libcephsqlite.cc index fa3164d893b..6f12c4fa185 100644 --- a/src/libcephsqlite.cc +++ b/src/libcephsqlite.cc @@ -38,7 +38,7 @@ SQLITE_EXTENSION_INIT1 #include "include/rados/librados.hpp" #include "common/Clock.h" -#include "common/Formatter.h" +#include "common/JSONFormatter.h" #include "common/ceph_argparse.h" #include "common/ceph_mutex.h" #include "common/common_init.h" diff --git a/src/mds/MDSRank.cc b/src/mds/MDSRank.cc index c1f3960f49d..c50874e3a02 100644 --- a/src/mds/MDSRank.cc +++ b/src/mds/MDSRank.cc @@ -20,6 +20,7 @@ #include "common/debug.h" #include "common/errno.h" #include "common/fair_mutex.h" +#include "common/JSONFormatterFile.h" #include "common/likely.h" #include "common/Timer.h" #include "common/async/blocked_completion.h" diff --git a/src/mds/ScrubStack.cc b/src/mds/ScrubStack.cc index 9c401f14aab..98d5c8a8f51 100644 --- a/src/mds/ScrubStack.cc +++ b/src/mds/ScrubStack.cc @@ -17,7 +17,7 @@ #include "RetryMessage.h" #include "SnapRealm.h" #include "common/debug.h" -#include "common/Formatter.h" +#include "common/JSONFormatter.h" #include "mds/MDLog.h" #include "mds/MDSRank.h" #include "mds/MDCache.h" diff --git a/src/mgr/BaseMgrModule.cc b/src/mgr/BaseMgrModule.cc index 8ac3ef02104..b0ad9fb9432 100644 --- a/src/mgr/BaseMgrModule.cc +++ b/src/mgr/BaseMgrModule.cc @@ -24,6 +24,7 @@ #include "mon/MonClient.h" #include "common/errno.h" +#include "common/JSONFormatter.h" #include "common/version.h" #include "mgr/Types.h" diff --git a/src/mgr/ClusterState.cc b/src/mgr/ClusterState.cc index b1f9ff654d4..a18c7fd6f49 100644 --- a/src/mgr/ClusterState.cc +++ b/src/mgr/ClusterState.cc @@ -12,6 +12,7 @@ */ #include "mgr/ClusterState.h" +#include "common/JSONFormatter.h" #include "messages/MMgrDigest.h" #include "messages/MMonMgrReport.h" #include "messages/MPGStats.h" diff --git a/src/mgr/DaemonServer.cc b/src/mgr/DaemonServer.cc index a967658e2f4..85be92ea3b8 100644 --- a/src/mgr/DaemonServer.cc +++ b/src/mgr/DaemonServer.cc @@ -44,6 +44,7 @@ #include "messages/MOSDScrub2.h" #include "messages/MOSDForceRecovery.h" #include "common/errno.h" +#include "common/JSONFormatter.h" #include "common/pick_address.h" #include "common/TextTable.h" #include "crush/CrushWrapper.h" diff --git a/src/mgr/PyFormatter.h b/src/mgr/PyFormatter.h index b45fbf162e0..5608707c1dc 100644 --- a/src/mgr/PyFormatter.h +++ b/src/mgr/PyFormatter.h @@ -27,7 +27,7 @@ #include #include -#include "common/Formatter.h" +#include "common/JSONFormatter.h" #include "include/ceph_assert.h" class PyFormatter : public ceph::Formatter diff --git a/src/mgr/PyModule.cc b/src/mgr/PyModule.cc index fe33555280e..8b0629bb9ea 100644 --- a/src/mgr/PyModule.cc +++ b/src/mgr/PyModule.cc @@ -21,6 +21,7 @@ #include "include/stringify.h" #include "common/BackTrace.h" +#include "common/JSONFormatter.h" #include "global/signal_handler.h" #include "common/debug.h" diff --git a/src/mon/ConfigMap.cc b/src/mon/ConfigMap.cc index a1f3f5051e8..ce5938ffb56 100644 --- a/src/mon/ConfigMap.cc +++ b/src/mon/ConfigMap.cc @@ -37,7 +37,6 @@ using ceph::bufferlist; using ceph::decode; using ceph::encode; using ceph::Formatter; -using ceph::JSONFormatter; using ceph::mono_clock; using ceph::mono_time; using ceph::timespan_str; diff --git a/src/mon/ConfigMonitor.cc b/src/mon/ConfigMonitor.cc index 3a1526b4ed4..f124ce1c24a 100644 --- a/src/mon/ConfigMonitor.cc +++ b/src/mon/ConfigMonitor.cc @@ -9,7 +9,7 @@ #include "messages/MConfig.h" #include "messages/MGetConfig.h" #include "messages/MMonCommand.h" -#include "common/Formatter.h" +#include "common/JSONFormatter.h" #include "common/TextTable.h" #include "common/cmdparse.h" #include "include/stringify.h" diff --git a/src/mon/ElectionLogic.cc b/src/mon/ElectionLogic.cc index be0c35d06ac..0110256eca6 100644 --- a/src/mon/ElectionLogic.cc +++ b/src/mon/ElectionLogic.cc @@ -47,7 +47,6 @@ using ceph::bufferlist; using ceph::decode; using ceph::encode; using ceph::Formatter; -using ceph::JSONFormatter; using ceph::mono_clock; using ceph::mono_time; using ceph::timespan_str; diff --git a/src/mon/Elector.cc b/src/mon/Elector.cc index 3e71a69426e..bfc854d6bdc 100644 --- a/src/mon/Elector.cc +++ b/src/mon/Elector.cc @@ -48,8 +48,6 @@ using std::unique_ptr; using ceph::bufferlist; using ceph::decode; using ceph::encode; -using ceph::Formatter; -using ceph::JSONFormatter; using ceph::mono_clock; using ceph::mono_time; using ceph::timespan_str; diff --git a/src/mon/LogMonitor.cc b/src/mon/LogMonitor.cc index 82ddf9a899a..80747195751 100644 --- a/src/mon/LogMonitor.cc +++ b/src/mon/LogMonitor.cc @@ -92,7 +92,6 @@ using ceph::bufferlist; using ceph::decode; using ceph::encode; using ceph::Formatter; -using ceph::JSONFormatter; using ceph::make_message; using ceph::mono_clock; using ceph::mono_time; diff --git a/src/mon/MonitorDBStore.h b/src/mon/MonitorDBStore.h index f4c66de1812..6f1ae0543c3 100644 --- a/src/mon/MonitorDBStore.h +++ b/src/mon/MonitorDBStore.h @@ -24,7 +24,7 @@ #include "kv/KeyValueDB.h" #include "include/ceph_assert.h" -#include "common/Formatter.h" +#include "common/JSONFormatter.h" #include "common/Finisher.h" #include "common/errno.h" #include "common/debug.h" diff --git a/src/mon/OSDMonitor.cc b/src/mon/OSDMonitor.cc index 97c632cd7e9..a33464f9562 100644 --- a/src/mon/OSDMonitor.cc +++ b/src/mon/OSDMonitor.cc @@ -57,6 +57,7 @@ #include "messages/MMonGetPurgedSnaps.h" #include "messages/MMonGetPurgedSnapsReply.h" +#include "common/JSONFormatter.h" #include "common/TextTable.h" #include "common/Timer.h" #include "common/ceph_argparse.h" diff --git a/src/mon/Paxos.h b/src/mon/Paxos.h index d9b6fd228d8..a705069db86 100644 --- a/src/mon/Paxos.h +++ b/src/mon/Paxos.h @@ -114,6 +114,7 @@ e 12v #include "include/buffer.h" #include "msg/msg_types.h" #include "include/Context.h" +#include "common/JSONFormatter.h" #include "common/perf_counters.h" #include diff --git a/src/os/bluestore/BlueFS.cc b/src/os/bluestore/BlueFS.cc index de083971287..6247f372627 100644 --- a/src/os/bluestore/BlueFS.cc +++ b/src/os/bluestore/BlueFS.cc @@ -10,6 +10,7 @@ #include "common/Clock.h" // for ceph_clock_now() #include "common/debug.h" #include "common/errno.h" +#include "common/JSONFormatter.h" #include "common/perf_counters.h" #include "Allocator.h" #include "include/buffer_fwd.h" diff --git a/src/os/bluestore/BlueStore.cc b/src/os/bluestore/BlueStore.cc index 8533d676119..4d4b2acc635 100644 --- a/src/os/bluestore/BlueStore.cc +++ b/src/os/bluestore/BlueStore.cc @@ -42,6 +42,7 @@ #include "include/util.h" #include "common/debug.h" #include "common/errno.h" +#include "common/JSONFormatter.h" #include "common/safe_io.h" #include "common/PriorityCache.h" #include "common/url_escape.h" diff --git a/src/os/bluestore/bluestore_tool.cc b/src/os/bluestore/bluestore_tool.cc index ad1f8d30841..14f94494cce 100644 --- a/src/os/bluestore/bluestore_tool.cc +++ b/src/os/bluestore/bluestore_tool.cc @@ -16,6 +16,7 @@ #include "common/ceph_argparse.h" #include "include/stringify.h" #include "common/errno.h" +#include "common/JSONFormatter.h" #include "common/safe_io.h" #include "os/bluestore/BlueFS.h" diff --git a/src/os/kstore/KStore.cc b/src/os/kstore/KStore.cc index 12cf6f6aef5..2fd1c0b19a1 100644 --- a/src/os/kstore/KStore.cc +++ b/src/os/kstore/KStore.cc @@ -31,7 +31,7 @@ #include "common/debug.h" #include "common/errno.h" #include "common/safe_io.h" -#include "common/Formatter.h" +#include "common/JSONFormatter.h" #include "common/pretty_binary.h" #include // for std::shared_lock diff --git a/src/os/memstore/MemStore.cc b/src/os/memstore/MemStore.cc index f1278a0f025..bdcde2cf348 100644 --- a/src/os/memstore/MemStore.cc +++ b/src/os/memstore/MemStore.cc @@ -25,6 +25,7 @@ #include "include/stringify.h" #include "common/debug.h" #include "common/errno.h" +#include "common/JSONFormatter.h" #include "MemStore.h" #include "include/compat.h" diff --git a/src/osd/osd_types.cc b/src/osd/osd_types.cc index fc380d6ba89..143f007ab9c 100644 --- a/src/osd/osd_types.cc +++ b/src/osd/osd_types.cc @@ -42,7 +42,7 @@ extern "C" { } #include "common/ceph_context.h" -#include "common/Formatter.h" +#include "common/JSONFormatter.h" #include "common/StackStringStream.h" #include "include/utime_fmt.h" #include "OSDMap.h" diff --git a/src/rbd_replay/Replayer.cc b/src/rbd_replay/Replayer.cc index 8e7bd0c1917..a0f83a6c7b7 100644 --- a/src/rbd_replay/Replayer.cc +++ b/src/rbd_replay/Replayer.cc @@ -14,6 +14,7 @@ #include "Replayer.hpp" #include "common/errno.h" +#include "common/JSONFormatter.h" #include "include/scope_guard.h" #include "rbd_replay/ActionTypes.h" #include "rbd_replay/BufferReader.h" diff --git a/src/rbd_replay/actions.hpp b/src/rbd_replay/actions.hpp index 89e48315863..3b5dd8bd789 100644 --- a/src/rbd_replay/actions.hpp +++ b/src/rbd_replay/actions.hpp @@ -17,7 +17,7 @@ #include #include "include/rbd/librbd.hpp" -#include "common/Formatter.h" +#include "common/JSONFormatter.h" #include "rbd_replay/ActionTypes.h" #include "rbd_loc.hpp" #include diff --git a/src/rgw/driver/rados/rgw_bucket.cc b/src/rgw/driver/rados/rgw_bucket.cc index 2fd6535827b..209be5d0803 100644 --- a/src/rgw/driver/rados/rgw_bucket.cc +++ b/src/rgw/driver/rados/rgw_bucket.cc @@ -2,6 +2,7 @@ // vim: ts=8 sw=2 smarttab ft=cpp #include "common/Clock.h" // for ceph_clock_now() +#include "common/JSONFormatter.h" #include "include/function2.hpp" #include "rgw_acl_s3.h" #include "rgw_tag_s3.h" diff --git a/src/rgw/driver/rados/rgw_lc_tier.cc b/src/rgw/driver/rados/rgw_lc_tier.cc index 440ecf3d21d..4c3eb7c1fc7 100644 --- a/src/rgw/driver/rados/rgw_lc_tier.cc +++ b/src/rgw/driver/rados/rgw_lc_tier.cc @@ -5,7 +5,7 @@ #include #include -#include "common/Formatter.h" +#include "common/XMLFormatter.h" #include #include "rgw_lc.h" #include "rgw_lc_tier.h" diff --git a/src/rgw/driver/rados/rgw_pubsub_push.cc b/src/rgw/driver/rados/rgw_pubsub_push.cc index 159e2b876df..91526f8d76f 100644 --- a/src/rgw/driver/rados/rgw_pubsub_push.cc +++ b/src/rgw/driver/rados/rgw_pubsub_push.cc @@ -9,6 +9,7 @@ #include #include "common/Formatter.h" #include "common/iso_8601.h" +#include "common/JSONFormatter.h" #include "common/async/completion.h" #include "common/async/yield_waiter.h" #include "common/async/waiter.h" diff --git a/src/rgw/driver/rados/rgw_sync_module_aws.cc b/src/rgw/driver/rados/rgw_sync_module_aws.cc index fa14d056f16..a565a2fced7 100644 --- a/src/rgw/driver/rados/rgw_sync_module_aws.cc +++ b/src/rgw/driver/rados/rgw_sync_module_aws.cc @@ -2,6 +2,8 @@ // vim: ts=8 sw=2 smarttab ft=cpp #include "common/errno.h" +#include "common/JSONFormatter.h" +#include "common/XMLFormatter.h" #include "rgw_common.h" #include "rgw_coroutine.h" diff --git a/src/rgw/driver/rados/rgw_sync_trace.cc b/src/rgw/driver/rados/rgw_sync_trace.cc index b346835938d..343c4a68910 100644 --- a/src/rgw/driver/rados/rgw_sync_trace.cc +++ b/src/rgw/driver/rados/rgw_sync_trace.cc @@ -8,6 +8,7 @@ #include "common/debug.h" #include "common/ceph_json.h" +#include "common/JSONFormatter.h" #include "rgw_sync_trace.h" #include "rgw_rados.h" diff --git a/src/rgw/radosgw-admin/radosgw-admin.cc b/src/rgw/radosgw-admin/radosgw-admin.cc index 4f4bb112063..7306c60edd8 100644 --- a/src/rgw/radosgw-admin/radosgw-admin.cc +++ b/src/rgw/radosgw-admin/radosgw-admin.cc @@ -29,7 +29,8 @@ extern "C" { #include "common/ceph_json.h" #include "common/config.h" #include "common/ceph_argparse.h" -#include "common/Formatter.h" +#include "common/JSONFormatter.h" +#include "common/XMLFormatter.h" #include "common/errno.h" #include "common/safe_io.h" #include "common/fault_injector.h" diff --git a/src/rgw/rgw_cors_s3.cc b/src/rgw/rgw_cors_s3.cc index ba68487e275..f85a225e1c7 100644 --- a/src/rgw/rgw_cors_s3.cc +++ b/src/rgw/rgw_cors_s3.cc @@ -19,6 +19,7 @@ #include #include +#include "common/XMLFormatter.h" #include "include/types.h" #include "rgw_cors_s3.h" diff --git a/src/rgw/rgw_cors_s3.h b/src/rgw/rgw_cors_s3.h index 8d92a3c5fd3..8cbad453039 100644 --- a/src/rgw/rgw_cors_s3.h +++ b/src/rgw/rgw_cors_s3.h @@ -20,7 +20,7 @@ #include #include -#include +#include #include #include "rgw_xml.h" #include "rgw_cors.h" diff --git a/src/rgw/rgw_formats.cc b/src/rgw/rgw_formats.cc index a252ef73756..a49ad3f330b 100644 --- a/src/rgw/rgw_formats.cc +++ b/src/rgw/rgw_formats.cc @@ -16,7 +16,7 @@ #include #include "common/escape.h" -#include "common/Formatter.h" +#include "common/XMLFormatter.h" #include "rgw/rgw_common.h" #include "rgw/rgw_formats.h" #include "rgw/rgw_rest.h" diff --git a/src/rgw/rgw_op.cc b/src/rgw/rgw_op.cc index 75f83ea95af..815e7e35541 100644 --- a/src/rgw/rgw_op.cc +++ b/src/rgw/rgw_op.cc @@ -17,6 +17,7 @@ #include "common/dout.h" #include "include/scope_guard.h" +#include "common/XMLFormatter.h" #include "common/Clock.h" #include "common/armor.h" #include "common/async/spawn_throttle.h" diff --git a/src/rgw/rgw_rest.cc b/src/rgw/rgw_rest.cc index 4a6a2e6c576..d03e4a3a942 100644 --- a/src/rgw/rgw_rest.cc +++ b/src/rgw/rgw_rest.cc @@ -8,8 +8,8 @@ #include #include #include "ceph_ver.h" -#include "common/Formatter.h" #include "common/HTMLFormatter.h" +#include "common/XMLFormatter.h" #include "common/utf8.h" #include "include/str_list.h" #include "rgw_common.h" diff --git a/src/test/admin_socket.cc b/src/test/admin_socket.cc index dea29f96f11..db23e245ea8 100644 --- a/src/test/admin_socket.cc +++ b/src/test/admin_socket.cc @@ -17,6 +17,7 @@ #include "common/admin_socket.h" #include "common/admin_socket_client.h" #include "common/ceph_argparse.h" +#include "common/JSONFormatter.h" #include "json_spirit/json_spirit.h" #include "gtest/gtest.h" #include "fmt/format.h" diff --git a/src/test/common/test_json_formatter.cc b/src/test/common/test_json_formatter.cc index d0ddd262c0a..e67f8290659 100644 --- a/src/test/common/test_json_formatter.cc +++ b/src/test/common/test_json_formatter.cc @@ -17,6 +17,7 @@ #include "common/ceph_json.h" #include "common/Clock.h" +#include "common/JSONFormatter.h" #include "common/StackStringStream.h" #include diff --git a/src/test/common/test_tableformatter.cc b/src/test/common/test_tableformatter.cc index 90de133d315..2ab1a930bb4 100644 --- a/src/test/common/test_tableformatter.cc +++ b/src/test/common/test_tableformatter.cc @@ -1,6 +1,6 @@ #include "gtest/gtest.h" -#include "common/Formatter.h" +#include "common/TableFormatter.h" #include #include #include diff --git a/src/test/common/test_xmlformatter.cc b/src/test/common/test_xmlformatter.cc index abbe9e4e25e..fbe87966e8d 100644 --- a/src/test/common/test_xmlformatter.cc +++ b/src/test/common/test_xmlformatter.cc @@ -1,6 +1,6 @@ #include "gtest/gtest.h" -#include "common/Formatter.h" +#include "common/XMLFormatter.h" #include #include diff --git a/src/test/crush/crush.cc b/src/test/crush/crush.cc index 85806a1799d..02512d0ba23 100644 --- a/src/test/crush/crush.cc +++ b/src/test/crush/crush.cc @@ -17,6 +17,7 @@ #include "common/ceph_argparse.h" #include "common/common_init.h" +#include "common/JSONFormatter.h" #include "include/stringify.h" #include "crush/CrushWrapper.h" diff --git a/src/test/formatter.cc b/src/test/formatter.cc index 1e78a18a006..cb9b1a3f8b4 100644 --- a/src/test/formatter.cc +++ b/src/test/formatter.cc @@ -13,8 +13,9 @@ */ #include "gtest/gtest.h" -#include "common/Formatter.h" +#include "common/JSONFormatter.h" #include "common/HTMLFormatter.h" +#include "common/XMLFormatter.h" #include #include diff --git a/src/test/libcephfs/snapdiff.cc b/src/test/libcephfs/snapdiff.cc index e337716a017..a22d35cd90a 100644 --- a/src/test/libcephfs/snapdiff.cc +++ b/src/test/libcephfs/snapdiff.cc @@ -20,6 +20,7 @@ #include "include/stringify.h" #include "common/ceph_context.h" #include "common/config_proxy.h" +#include "common/JSONFormatter.h" #include "json_spirit/json_spirit.h" #include "boost/format/alt_sstream.hpp" #include diff --git a/src/test/librados/service.cc b/src/test/librados/service.cc index 6d88f0da9af..da66955251c 100644 --- a/src/test/librados/service.cc +++ b/src/test/librados/service.cc @@ -2,6 +2,7 @@ #include "include/rados/librados.hpp" #include "include/stringify.h" #include "common/config_proxy.h" +#include "common/JSONFormatter.h" #include "test/librados/test.h" #include "test/librados/TestCase.h" #ifndef _WIN32 diff --git a/src/test/librados/test_common.cc b/src/test/librados/test_common.cc index e6e6c21bdf1..4c34a9fa657 100644 --- a/src/test/librados/test_common.cc +++ b/src/test/librados/test_common.cc @@ -1,7 +1,7 @@ // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab -#include "common/Formatter.h" +#include "common/JSONFormatter.h" #include "include/ceph_assert.h" #include "include/stringify.h" #include "json_spirit/json_spirit.h" diff --git a/src/test/mon/test_mon_workloadgen.cc b/src/test/mon/test_mon_workloadgen.cc index a8c01cda8f2..22e1845b06c 100644 --- a/src/test/mon/test_mon_workloadgen.cc +++ b/src/test/mon/test_mon_workloadgen.cc @@ -48,6 +48,7 @@ #include "common/debug.h" #include "common/errno.h" #include "common/ceph_mutex.h" +#include "common/JSONFormatter.h" #include "common/strtol.h" #include "common/LogEntry.h" #include "auth/KeyRing.h" diff --git a/src/test/objectstore/store_test.cc b/src/test/objectstore/store_test.cc index eb101fd8037..9248c14862d 100644 --- a/src/test/objectstore/store_test.cc +++ b/src/test/objectstore/store_test.cc @@ -41,6 +41,7 @@ #include "common/Cond.h" #include "common/debug.h" #include "common/errno.h" +#include "common/JSONFormatter.h" #include "common/options.h" // for the size literals #include "common/pretty_binary.h" #include "include/stringify.h" diff --git a/src/test/rgw/test_rgw_xml.cc b/src/test/rgw/test_rgw_xml.cc index a31be59a3c8..e7bb3c0328a 100644 --- a/src/test/rgw/test_rgw_xml.cc +++ b/src/test/rgw/test_rgw_xml.cc @@ -2,6 +2,8 @@ // vim: ts=8 sw=2 smarttab #include "rgw_xml.h" +#include "common/XMLFormatter.h" + #include #include #include diff --git a/src/test/test_mempool.cc b/src/test/test_mempool.cc index cde8d293fdf..71a87427082 100644 --- a/src/test/test_mempool.cc +++ b/src/test/test_mempool.cc @@ -20,6 +20,7 @@ #include "global/global_init.h" #include "common/ceph_argparse.h" +#include "common/TableFormatter.h" #include "global/global_context.h" #include "gtest/gtest.h" #include "include/btree_map.h" diff --git a/src/tools/ceph-client-debug.cc b/src/tools/ceph-client-debug.cc index 229162e3bf3..87d8be497f3 100644 --- a/src/tools/ceph-client-debug.cc +++ b/src/tools/ceph-client-debug.cc @@ -15,7 +15,7 @@ #include "common/ceph_argparse.h" #include "global/global_init.h" -#include "common/Formatter.h" +#include "common/JSONFormatter.h" #include "common/debug.h" #include "common/errno.h" #include "client/Inode.h" diff --git a/src/tools/ceph-dencoder/ceph_dencoder.cc b/src/tools/ceph-dencoder/ceph_dencoder.cc index a7273622a29..1cd16b0238c 100644 --- a/src/tools/ceph-dencoder/ceph_dencoder.cc +++ b/src/tools/ceph-dencoder/ceph_dencoder.cc @@ -20,7 +20,7 @@ #include "ceph_ver.h" #include "include/types.h" -#include "common/Formatter.h" +#include "common/JSONFormatter.h" #include "common/ceph_argparse.h" #include "common/errno.h" #include "denc_plugin.h" diff --git a/src/tools/ceph_monstore_tool.cc b/src/tools/ceph_monstore_tool.cc index 8c6c9c7233b..5bb0ece595e 100644 --- a/src/tools/ceph_monstore_tool.cc +++ b/src/tools/ceph_monstore_tool.cc @@ -23,6 +23,7 @@ #include "auth/KeyRing.h" #include "auth/cephx/CephxKeyServer.h" #include "global/global_init.h" +#include "common/JSONFormatter.h" #include "include/scope_guard.h" #include "include/stringify.h" #include "mgr/mgr_commands.h" diff --git a/src/tools/cephfs/EventOutput.cc b/src/tools/cephfs/EventOutput.cc index 8cb235a82f9..bce2f524111 100644 --- a/src/tools/cephfs/EventOutput.cc +++ b/src/tools/cephfs/EventOutput.cc @@ -16,6 +16,7 @@ #include #include "common/errno.h" +#include "common/JSONFormatter.h" #include "mds/mdstypes.h" #include "mds/events/EUpdate.h" #include "mds/LogEvent.h" diff --git a/src/tools/cephfs/JournalTool.cc b/src/tools/cephfs/JournalTool.cc index 0c970bd7bae..d93f74b68cd 100644 --- a/src/tools/cephfs/JournalTool.cc +++ b/src/tools/cephfs/JournalTool.cc @@ -17,6 +17,7 @@ #include "common/ceph_argparse.h" #include "common/debug.h" #include "common/errno.h" +#include "common/JSONFormatter.h" #include "osdc/Journaler.h" #include "mds/mdstypes.h" #include "mds/LogEvent.h" diff --git a/src/tools/cephfs/TableTool.cc b/src/tools/cephfs/TableTool.cc index c07828f364e..70f7e24296b 100644 --- a/src/tools/cephfs/TableTool.cc +++ b/src/tools/cephfs/TableTool.cc @@ -15,6 +15,7 @@ #include "common/ceph_argparse.h" #include "common/debug.h" #include "common/errno.h" +#include "common/JSONFormatter.h" #include "mds/SessionMap.h" #include "mds/InoTable.h" diff --git a/src/tools/cephfs_mirror/ServiceDaemon.cc b/src/tools/cephfs_mirror/ServiceDaemon.cc index 7d8227f8845..e3489cdba53 100644 --- a/src/tools/cephfs_mirror/ServiceDaemon.cc +++ b/src/tools/cephfs_mirror/ServiceDaemon.cc @@ -4,6 +4,7 @@ #include "ServiceDaemon.h" #include "common/debug.h" #include "common/errno.h" +#include "common/JSONFormatter.h" #include "common/Timer.h" #include "include/Context.h" #include "include/stringify.h" diff --git a/src/tools/osdmaptool.cc b/src/tools/osdmaptool.cc index be75a326c82..f3ae27e8683 100644 --- a/src/tools/osdmaptool.cc +++ b/src/tools/osdmaptool.cc @@ -17,6 +17,7 @@ #include "common/ceph_argparse.h" #include "common/errno.h" +#include "common/JSONFormatter.h" #include "common/safe_io.h" #include "common/strtol.h" // for strict_strtoll() #include "crush/CrushWrapper.h" diff --git a/src/tools/rados/rados.cc b/src/tools/rados/rados.cc index 849b958152c..647a740e3b6 100644 --- a/src/tools/rados/rados.cc +++ b/src/tools/rados/rados.cc @@ -31,7 +31,7 @@ #include "common/Cond.h" #include "common/debug.h" #include "common/errno.h" -#include "common/Formatter.h" +#include "common/JSONFormatter.h" #include "common/obj_bencher.h" #include "common/strtol.h" // for strict_strtoll() #include "common/TextTable.h" diff --git a/src/tools/rbd/ArgumentTypes.cc b/src/tools/rbd/ArgumentTypes.cc index 7d60a95ca4b..d7be40342e5 100644 --- a/src/tools/rbd/ArgumentTypes.cc +++ b/src/tools/rbd/ArgumentTypes.cc @@ -7,7 +7,8 @@ #include "include/rbd/features.h" #include "common/config_proxy.h" #include "common/strtol.h" -#include "common/Formatter.h" +#include "common/JSONFormatter.h" +#include "common/XMLFormatter.h" #include "global/global_context.h" #include #include diff --git a/src/tools/rbd/action/Journal.cc b/src/tools/rbd/action/Journal.cc index a7069ab6687..44843e7600a 100644 --- a/src/tools/rbd/action/Journal.cc +++ b/src/tools/rbd/action/Journal.cc @@ -5,7 +5,7 @@ #include "tools/rbd/Shell.h" #include "tools/rbd/Utils.h" #include "common/Cond.h" -#include "common/Formatter.h" +#include "common/JSONFormatter.h" #include "common/ceph_json.h" #include "common/errno.h" #include "common/safe_io.h" diff --git a/src/tools/rbd_ggate/main.cc b/src/tools/rbd_ggate/main.cc index 0942f5689ea..705cb152f43 100644 --- a/src/tools/rbd_ggate/main.cc +++ b/src/tools/rbd_ggate/main.cc @@ -17,7 +17,8 @@ #include #include -#include "common/Formatter.h" +#include "common/JSONFormatter.h" +#include "common/XMLFormatter.h" #include "common/Preforker.h" #include "common/TextTable.h" #include "common/ceph_argparse.h" diff --git a/src/tools/rbd_mirror/ServiceDaemon.cc b/src/tools/rbd_mirror/ServiceDaemon.cc index 203be5f6134..bdfb576eb56 100644 --- a/src/tools/rbd_mirror/ServiceDaemon.cc +++ b/src/tools/rbd_mirror/ServiceDaemon.cc @@ -8,7 +8,7 @@ #include "common/config.h" #include "common/debug.h" #include "common/errno.h" -#include "common/Formatter.h" +#include "common/JSONFormatter.h" #include "common/Timer.h" #include "tools/rbd_mirror/Threads.h" #include diff --git a/src/tools/rbd_nbd/rbd-nbd.cc b/src/tools/rbd_nbd/rbd-nbd.cc index 68c6f545591..e3ae6cce55f 100644 --- a/src/tools/rbd_nbd/rbd-nbd.cc +++ b/src/tools/rbd_nbd/rbd-nbd.cc @@ -52,7 +52,8 @@ #include #include -#include "common/Formatter.h" +#include "common/JSONFormatter.h" +#include "common/XMLFormatter.h" #include "common/Preforker.h" #include "common/SubProcess.h" #include "common/TextTable.h" diff --git a/src/tools/rbd_wnbd/rbd_wnbd.cc b/src/tools/rbd_wnbd/rbd_wnbd.cc index 2ebf2c04b24..a0802895aa3 100644 --- a/src/tools/rbd_wnbd/rbd_wnbd.cc +++ b/src/tools/rbd_wnbd/rbd_wnbd.cc @@ -35,7 +35,8 @@ #include #include -#include "common/Formatter.h" +#include "common/JSONFormatter.h" +#include "common/XMLFormatter.h" #include "common/TextTable.h" #include "common/ceph_argparse.h" #include "common/config.h" -- 2.39.5