diff --git a/src/client/CMakeLists.txt b/src/client/CMakeLists.txt index 174023d4..bf99d0c1 100644 --- a/src/client/CMakeLists.txt +++ b/src/client/CMakeLists.txt @@ -88,7 +88,7 @@ add_executable(test_cluster_client EXCLUDE_FROM_ALL ../test/test_cluster_client.cpp pg_states.cpp osd_ops.cpp cluster_client.cpp cluster_client_list.cpp cluster_client_wb.cpp msgr_op.cpp ../test/mock/messenger.cpp msgr_stop.cpp - etcd_state_client.cpp ../util/timerfd_manager.cpp ../util/str_util.cpp ../../json11/json11.cpp + etcd_state_client.cpp ../util/timerfd_manager.cpp ../util/str_util.cpp ../util/json_util.cpp ../../json11/json11.cpp ) target_compile_definitions(test_cluster_client PUBLIC -D__MOCK__) target_include_directories(test_cluster_client BEFORE PUBLIC ${CMAKE_SOURCE_DIR}/src/test/mock) diff --git a/src/client/cluster_client.cpp b/src/client/cluster_client.cpp index 01dd81a2..3a5533db 100644 --- a/src/client/cluster_client.cpp +++ b/src/client/cluster_client.cpp @@ -4,7 +4,7 @@ #include #include #include "cluster_client_impl.h" -#include "http_client.h" // json_is_true +#include "json_util.h" cluster_client_t::cluster_client_t(ring_loop_t *ringloop, timerfd_manager_t *tfd, json11::Json config) { diff --git a/src/client/http_client.cpp b/src/client/http_client.cpp index d0ec9a49..4b60c645 100644 --- a/src/client/http_client.cpp +++ b/src/client/http_client.cpp @@ -15,6 +15,7 @@ #include "addr_util.h" #include "str_util.h" +#include "json_util.h" #include "json11/json11.hpp" #include "http_client.h" #include "timerfd_manager.h" @@ -724,22 +725,3 @@ static bool ws_parse_frame(std::string & buf, int & type, std::string & res) buf = buf.substr(hdr+len); return true; } - -// FIXME: move to utils -bool json_is_true(const json11::Json & val) -{ - if (val.is_string()) - return val == "true" || val == "yes" || val == "1"; - return val.bool_value(); -} - -bool json_is_false(const json11::Json & val) -{ - if (val.is_string()) - return val.string_value() == "false" || val.string_value() == "no" || val.string_value() == "0"; - if (val.is_number()) - return val.number_value() == 0; - if (val.is_bool()) - return !val.bool_value(); - return false; -} diff --git a/src/client/http_client.h b/src/client/http_client.h index 29c5d8c4..b57d3a4c 100644 --- a/src/client/http_client.h +++ b/src/client/http_client.h @@ -48,9 +48,3 @@ void http_request(http_co_t *handler, const std::string & host, const std::strin const http_options_t & options, std::function response_callback); void http_post_message(http_co_t *handler, int type, const std::string & msg); void http_close(http_co_t *co); - -// Utils -std::string strtolower(const std::string & in); -// FIXME: move to json11 -bool json_is_true(const json11::Json & val); -bool json_is_false(const json11::Json & val); diff --git a/src/cmd/cli_fix.cpp b/src/cmd/cli_fix.cpp index 61cb7afc..9016fcfb 100644 --- a/src/cmd/cli_fix.cpp +++ b/src/cmd/cli_fix.cpp @@ -5,6 +5,7 @@ #include "cluster_client.h" #include "pg_states.h" #include "str_util.h" +#include "json_util.h" struct cli_fix_t { diff --git a/src/cmd/cli_fix.h b/src/cmd/cli_fix.h index 2a13f08f..9371742f 100644 --- a/src/cmd/cli_fix.h +++ b/src/cmd/cli_fix.h @@ -21,6 +21,3 @@ template void remove_duplicates(std::vector & ret) } ret.resize(j+1); } - -// from http_client.cpp... -bool json_is_false(const json11::Json & val); diff --git a/src/cmd/cli_modify_osd.cpp b/src/cmd/cli_modify_osd.cpp index 0810727c..5fc39230 100644 --- a/src/cmd/cli_modify_osd.cpp +++ b/src/cmd/cli_modify_osd.cpp @@ -4,6 +4,7 @@ #include "cli.h" #include "cluster_client.h" #include "str_util.h" +#include "json_util.h" #include "http_client.h" // Reweight OSD, change tags or set noout flag diff --git a/src/cmd/cli_status.cpp b/src/cmd/cli_status.cpp index ae32fcaa..7e12bec7 100644 --- a/src/cmd/cli_status.cpp +++ b/src/cmd/cli_status.cpp @@ -4,6 +4,7 @@ #include "cli.h" #include "cluster_client.h" #include "str_util.h" +#include "json_util.h" #include "pg_states.h" #include "http_client.h" diff --git a/src/disk_tool/disk_tool.h b/src/disk_tool/disk_tool.h index 80549054..7dc854e0 100644 --- a/src/disk_tool/disk_tool.h +++ b/src/disk_tool/disk_tool.h @@ -136,7 +136,6 @@ uint64_t sscanf_json(const char *fmt, const json11::Json & str); void fromhexstr(const std::string & from, int bytes, uint8_t *to); int disable_cache(std::string dev); std::string get_parent_device(std::string dev); -bool json_is_true(const json11::Json & val); int shell_exec(const std::vector & cmd, const std::string & in, std::string *out, std::string *err); int write_zero(int fd, uint64_t offset, uint64_t size); json11::Json read_parttable(std::string dev); diff --git a/src/disk_tool/disk_tool_prepare.cpp b/src/disk_tool/disk_tool_prepare.cpp index 2e94c319..8c9958a2 100644 --- a/src/disk_tool/disk_tool_prepare.cpp +++ b/src/disk_tool/disk_tool_prepare.cpp @@ -3,6 +3,7 @@ #include "disk_tool.h" #include "str_util.h" +#include "json_util.h" #include "osd_id.h" int disk_tool_t::prepare_one(std::map options, int is_hdd) diff --git a/src/disk_tool/disk_tool_udev.cpp b/src/disk_tool/disk_tool_udev.cpp index 7b7f1e81..f362620f 100644 --- a/src/disk_tool/disk_tool_udev.cpp +++ b/src/disk_tool/disk_tool_udev.cpp @@ -6,6 +6,7 @@ #include "disk_tool.h" #include "rw_blocking.h" #include "str_util.h" +#include "json_util.h" struct __attribute__((__packed__)) vitastor_disk_superblock_t { diff --git a/src/disk_tool/disk_tool_utils.cpp b/src/disk_tool/disk_tool_utils.cpp index ab94db85..906b4196 100644 --- a/src/disk_tool/disk_tool_utils.cpp +++ b/src/disk_tool/disk_tool_utils.cpp @@ -147,13 +147,6 @@ std::string get_parent_device(std::string dev) return dev.substr(0, i); } -bool json_is_true(const json11::Json & val) -{ - if (val.is_string()) - return val == "true" || val == "yes" || val == "1"; - return val.bool_value(); -} - int shell_exec(const std::vector & cmd, const std::string & in, std::string *out, std::string *err) { int child_stdin[2], child_stdout[2], child_stderr[2]; diff --git a/src/nfs/nfs_proxy.cpp b/src/nfs/nfs_proxy.cpp index b3340691..25d99e61 100644 --- a/src/nfs/nfs_proxy.cpp +++ b/src/nfs/nfs_proxy.cpp @@ -19,6 +19,7 @@ #include "addr_util.h" #include "str_util.h" +#include "json_util.h" #include "nfs_proxy.h" #include "nfs_kv.h" #include "nfs_block.h" diff --git a/src/test/mock/messenger.cpp b/src/test/mock/messenger.cpp index 32150cef..2d5004b5 100644 --- a/src/test/mock/messenger.cpp +++ b/src/test/mock/messenger.cpp @@ -55,10 +55,3 @@ json11::Json::object osd_messenger_t::merge_configs(const json11::Json::object & { return cli_config; } - -bool json_is_true(const json11::Json & val) -{ - if (val.is_string()) - return val == "true" || val == "yes" || val == "1"; - return val.bool_value(); -} diff --git a/src/util/json_util.cpp b/src/util/json_util.cpp index 2ba87bd6..f329a23e 100644 --- a/src/util/json_util.cpp +++ b/src/util/json_util.cpp @@ -15,3 +15,21 @@ std::map json_to_string_map(const json11::Json::object } return bs; } + +bool json_is_true(const json11::Json & val) +{ + if (val.is_string()) + return val == "true" || val == "yes" || val == "1"; + return val.bool_value(); +} + +bool json_is_false(const json11::Json & val) +{ + if (val.is_string()) + return val.string_value() == "false" || val.string_value() == "no" || val.string_value() == "0"; + if (val.is_number()) + return val.number_value() == 0; + if (val.is_bool()) + return !val.bool_value(); + return false; +} diff --git a/src/util/json_util.h b/src/util/json_util.h index 0fbe25b3..cd958d95 100644 --- a/src/util/json_util.h +++ b/src/util/json_util.h @@ -9,3 +9,5 @@ #include "json11/json11.hpp" std::map json_to_string_map(const json11::Json::object & config); +bool json_is_true(const json11::Json & val); +bool json_is_false(const json11::Json & val);