From 128140d02be3d4f07762d57b3d0f775cce705ba6 Mon Sep 17 00:00:00 2001 From: Yingchun Lai Date: Thu, 21 Dec 2023 00:11:18 +0800 Subject: [PATCH] refactor(ranger): Move ranger out of runtime --- src/CMakeLists.txt | 1 + src/aio/test/CMakeLists.txt | 26 +++-------- src/common/json_helper.h | 2 +- src/failure_detector/test/CMakeLists.txt | 26 +++-------- src/meta/CMakeLists.txt | 15 +------ src/meta/meta_options.cpp | 13 ------ src/meta/meta_options.h | 4 -- src/meta/meta_service.cpp | 11 ++--- src/meta/test/CMakeLists.txt | 23 ++++------ .../test/balancer_simulator/CMakeLists.txt | 22 +++------- src/meta/test/meta_bulk_load_service_test.cpp | 4 +- .../test/meta_partition_guardian_test.cpp | 5 ++- src/meta/test/meta_state/CMakeLists.txt | 37 +++++----------- src/meta/test/meta_test_base.cpp | 4 +- src/meta/test/update_configuration_test.cpp | 8 ++-- src/perf_counter/test/CMakeLists.txt | 24 +++------- src/{runtime => }/ranger/CMakeLists.txt | 6 +-- src/{runtime => }/ranger/access_type.h | 12 +++-- .../ranger/ranger_resource_policy.cpp | 2 +- .../ranger/ranger_resource_policy.h | 0 .../ranger/ranger_resource_policy_manager.cpp | 8 ++-- .../ranger/ranger_resource_policy_manager.h | 2 +- src/ranger/test/CMakeLists.txt | 30 +++++++++++++ .../access_type.cpp => ranger/test/main.cpp} | 20 ++------- .../ranger_resource_policy_manager_test.cpp | 6 +-- .../test/ranger_resource_policy_test.cpp | 4 +- src/ranger/test/run.sh | 25 +++++++++++ src/replica/backup/test/CMakeLists.txt | 13 ++---- src/replica/bulk_load/test/CMakeLists.txt | 13 ++---- src/replica/duplication/test/CMakeLists.txt | 13 ++---- src/replica/replica.h | 2 +- src/replica/replica_2pc.cpp | 2 +- src/replica/replica_stub.cpp | 2 +- src/replica/replica_stub.h | 2 +- src/replica/split/test/CMakeLists.txt | 16 +++---- src/replica/storage/simple_kv/CMakeLists.txt | 22 ++-------- .../storage/simple_kv/test/CMakeLists.txt | 21 +++------ src/replica/test/CMakeLists.txt | 17 +++---- src/runtime/CMakeLists.txt | 5 +-- src/runtime/security/access_controller.h | 2 +- .../security/meta_access_controller.cpp | 4 +- .../security/replica_access_controller.h | 4 +- src/runtime/test/CMakeLists.txt | 32 +++++--------- src/runtime/test/async_call.cpp | 5 ++- src/runtime/test/corrupt_message.cpp | 2 +- src/runtime/test/host_port_test.cpp | 2 +- src/runtime/test/lpc.cpp | 2 +- src/runtime/test/main.cpp | 2 +- src/runtime/test/netprovider.cpp | 2 +- .../test/replica_access_controller_test.cpp | 2 +- src/runtime/test/rpc.cpp | 2 +- src/runtime/test/task_engine.cpp | 2 +- src/runtime/{test => }/test_utils.h | 0 src/server/CMakeLists.txt | 19 ++------ src/server/test/CMakeLists.txt | 44 +++++++++---------- src/shell/CMakeLists.txt | 23 +++------- src/utils/filesystem.cpp | 11 +++++ src/utils/filesystem.h | 2 + 58 files changed, 258 insertions(+), 372 deletions(-) rename src/{runtime => }/ranger/CMakeLists.txt (92%) rename src/{runtime => }/ranger/access_type.h (83%) rename src/{runtime => }/ranger/ranger_resource_policy.cpp (99%) rename src/{runtime => }/ranger/ranger_resource_policy.h (100%) rename src/{runtime => }/ranger/ranger_resource_policy_manager.cpp (99%) rename src/{runtime => }/ranger/ranger_resource_policy_manager.h (99%) create mode 100644 src/ranger/test/CMakeLists.txt rename src/{runtime/ranger/access_type.cpp => ranger/test/main.cpp} (64%) rename src/{runtime => ranger}/test/ranger_resource_policy_manager_test.cpp (99%) rename src/{runtime => ranger}/test/ranger_resource_policy_test.cpp (99%) create mode 100755 src/ranger/test/run.sh rename src/runtime/{test => }/test_utils.h (100%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 00b8a0914d..253cb6cf64 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -45,6 +45,7 @@ add_subdirectory(http) add_subdirectory(meta) add_subdirectory(nfs) add_subdirectory(perf_counter) +add_subdirectory(ranger) add_subdirectory(redis_protocol) add_subdirectory(remote_cmd) add_subdirectory(replica) diff --git a/src/aio/test/CMakeLists.txt b/src/aio/test/CMakeLists.txt index 2eb4371467..cbc853d834 100644 --- a/src/aio/test/CMakeLists.txt +++ b/src/aio/test/CMakeLists.txt @@ -23,36 +23,24 @@ # THE SOFTWARE. set(MY_PROJ_NAME dsn_aio_test) - -# Source files under CURRENT project directory will be automatically included. -# You can manually set MY_PROJ_SRC to include source files under other directories. set(MY_PROJ_SRC "") - -# Search mode for source files under CURRENT project directory? -# "GLOB_RECURSE" for recursive search -# "GLOB" for non-recursive search set(MY_SRC_SEARCH_MODE "GLOB") - set(MY_PROJ_LIBS + dsn_runtime dsn_meta_server + dsn_ranger dsn_replication_common - gtest - dsn_runtime dsn_aio test_utils + gtest rocksdb lz4 zstd snappy) - set(MY_BOOST_LIBS Boost::system Boost::filesystem) - -# Extra files that will be installed set(MY_BINPLACES - "${CMAKE_CURRENT_SOURCE_DIR}/config.ini" - "${CMAKE_CURRENT_SOURCE_DIR}/clear.sh" - "${CMAKE_CURRENT_SOURCE_DIR}/run.sh" - "${CMAKE_CURRENT_SOURCE_DIR}/copy_source.txt" -) - + config.ini + clear.sh + run.sh + copy_source.txt) dsn_add_test() diff --git a/src/common/json_helper.h b/src/common/json_helper.h index 3c5bed8eab..5953826f4a 100644 --- a/src/common/json_helper.h +++ b/src/common/json_helper.h @@ -59,7 +59,7 @@ #include "consensus_types.h" #include "replica_admin_types.h" #include "common/replication_enums.h" -#include "runtime/ranger/access_type.h" +#include "ranger/access_type.h" #define JSON_ENCODE_ENTRY(out, prefix, T) \ out.Key(#T); \ diff --git a/src/failure_detector/test/CMakeLists.txt b/src/failure_detector/test/CMakeLists.txt index 5b5a6832a9..54907d6ee8 100644 --- a/src/failure_detector/test/CMakeLists.txt +++ b/src/failure_detector/test/CMakeLists.txt @@ -23,19 +23,12 @@ # THE SOFTWARE. set(MY_PROJ_NAME dsn.failure_detector.tests) - -# Source files under CURRENT project directory will be automatically included. -# You can manually set MY_PROJ_SRC to include source files under other directories. set(MY_PROJ_SRC "") - -# Search mode for source files under CURRENT project directory? -# "GLOB_RECURSE" for recursive search -# "GLOB" for non-recursive search set(MY_SRC_SEARCH_MODE "GLOB") - set(MY_PROJ_LIBS dsn_runtime dsn_meta_server + dsn_ranger dsn_replica_server dsn_replication_common dsn.failure_detector @@ -45,17 +38,12 @@ set(MY_PROJ_LIBS lz4 zstd snappy) - set(MY_BOOST_LIBS Boost::system Boost::filesystem) - -# Extra files that will be installed set(MY_BINPLACES - "${CMAKE_CURRENT_SOURCE_DIR}/run.sh" - "${CMAKE_CURRENT_SOURCE_DIR}/clear.sh" - "${CMAKE_CURRENT_SOURCE_DIR}/config-test.ini" - "${CMAKE_CURRENT_SOURCE_DIR}/config-whitelist-test.ini" - "${CMAKE_CURRENT_SOURCE_DIR}/config-whitelist-test-failed.ini" - "${CMAKE_CURRENT_SOURCE_DIR}/gtest.filter" -) - + run.sh + clear.sh + config-test.ini + config-whitelist-test.ini + config-whitelist-test-failed.ini + gtest.filter) dsn_add_test() diff --git a/src/meta/CMakeLists.txt b/src/meta/CMakeLists.txt index fcc3a12329..f3e9733c95 100644 --- a/src/meta/CMakeLists.txt +++ b/src/meta/CMakeLists.txt @@ -23,17 +23,12 @@ # THE SOFTWARE. set(MY_PROJ_NAME dsn_meta_server) - set(DUPLICATION_SRC duplication/duplication_info.cpp - duplication/meta_duplication_service.cpp - ) - -# Source files under CURRENT project directory will be automatically included. -# You can manually set MY_PROJ_SRC to include source files under other directories. + duplication/meta_duplication_service.cpp) set(MY_PROJ_SRC "${DUPLICATION_SRC}") - set(MY_PROJ_LIBS + dsn_ranger dsn_replication_common dsn.block_service dsn.block_service.local @@ -51,14 +46,8 @@ set(MY_PROJ_LIBS lz4 zstd snappy) - set(MY_BOOST_LIBS Boost::system Boost::filesystem) - -# Extra files that will be installed set(MY_BINPLACES "") - add_definitions(-DDSN_MOCK_TEST) - dsn_add_shared_library() - add_subdirectory(test) diff --git a/src/meta/meta_options.cpp b/src/meta/meta_options.cpp index 7956ff35e2..cb1e770beb 100644 --- a/src/meta/meta_options.cpp +++ b/src/meta/meta_options.cpp @@ -26,7 +26,6 @@ #include "meta_options.h" -#include #include #include @@ -55,18 +54,6 @@ DSN_DEFINE_string(meta_server, "", "white list of replica-servers in meta-server"); -std::string meta_options::concat_path_unix_style(const std::string &prefix, - const std::string &postfix) -{ - size_t pos1 = prefix.size(); // last_valid_pos + 1 - while (pos1 > 0 && prefix[pos1 - 1] == '/') - pos1--; - size_t pos2 = 0; // first non '/' position - while (pos2 < postfix.size() && postfix[pos2] == '/') - pos2++; - return prefix.substr(0, pos1) + "/" + postfix.substr(pos2); -} - void meta_options::initialize() { utils::split_args(FLAGS_meta_state_service_parameters, meta_state_service_args); diff --git a/src/meta/meta_options.h b/src/meta/meta_options.h index f33d83174e..ffda22eae5 100644 --- a/src/meta/meta_options.h +++ b/src/meta/meta_options.h @@ -54,10 +54,6 @@ class meta_options public: void initialize(); - -public: - static std::string concat_path_unix_style(const std::string &prefix, - const std::string &postfix); }; } // namespace replication } // namespace dsn diff --git a/src/meta/meta_service.cpp b/src/meta/meta_service.cpp index c35e3be99f..0acd4890ae 100644 --- a/src/meta/meta_service.cpp +++ b/src/meta/meta_service.cpp @@ -56,7 +56,7 @@ #include "meta_split_service.h" #include "partition_split_types.h" #include "remote_cmd/remote_command.h" -#include "runtime/ranger/ranger_resource_policy_manager.h" +#include "ranger/ranger_resource_policy_manager.h" #include "runtime/rpc/rpc_holder.h" #include "runtime/task/async_calls.h" #include "server_load_balancer.h" @@ -64,6 +64,7 @@ #include "utils/autoref_ptr.h" #include "utils/command_manager.h" #include "utils/factory_store.h" +#include "utils/filesystem.h" #include "utils/flags.h" #include "utils/fmt_logging.h" #include "utils/string_conv.h" @@ -224,7 +225,7 @@ error_code meta_service::remote_storage_initialize() utils::split_args(FLAGS_cluster_root, slices, '/'); std::string current = ""; for (unsigned int i = 0; i != slices.size(); ++i) { - current = meta_options::concat_path_unix_style(current, slices[i]); + current = utils::filesystem::concat_path_unix_style(current, slices[i]); task_ptr tsk = _storage->create_node(current, LPC_META_CALLBACK, [&err](error_code ec) { err = ec; }); tsk->wait(); @@ -445,16 +446,16 @@ error_code meta_service::start() LOG_INFO("initialize backup handler"); _backup_handler = std::make_shared( this, - meta_options::concat_path_unix_style(_cluster_root, "backup"), + utils::filesystem::concat_path_unix_style(_cluster_root, "backup"), FLAGS_cold_backup_root, [](backup_service *bs) { return std::make_shared(bs); }); } _bulk_load_svc = std::make_unique( - this, meta_options::concat_path_unix_style(_cluster_root, "bulk_load")); + this, utils::filesystem::concat_path_unix_style(_cluster_root, "bulk_load")); // initialize the server_state - _state->initialize(this, meta_options::concat_path_unix_style(_cluster_root, "apps")); + _state->initialize(this, utils::filesystem::concat_path_unix_style(_cluster_root, "apps")); while ((err = _state->initialize_data_structure()) != ERR_OK) { if (err == ERR_OBJECT_NOT_FOUND && FLAGS_recover_from_replica_server) { LOG_INFO("can't find apps from remote storage, and " diff --git a/src/meta/test/CMakeLists.txt b/src/meta/test/CMakeLists.txt index 49c9e4994d..13a1efe9d1 100644 --- a/src/meta/test/CMakeLists.txt +++ b/src/meta/test/CMakeLists.txt @@ -23,20 +23,11 @@ # THE SOFTWARE. set(MY_PROJ_NAME dsn.meta.test) - -# Source files under CURRENT project directory will be automatically included. -# You can manually set MY_PROJ_SRC to include source files under other directories. file(GLOB MY_PROJ_SRC ${PROJECT_SOURCE_DIR}/src/meta/*.cpp - ${PROJECT_SOURCE_DIR}/src/meta/duplication/*.cpp - ) + ${PROJECT_SOURCE_DIR}/src/meta/duplication/*.cpp) set(MY_PROJ_SRC ${MY_PROJ_SRC} misc/misc.cpp) - -# Search mode for source files under CURRENT project directory? -# "GLOB_RECURSE" for recursive search -# "GLOB" for non-recursive search set(MY_SRC_SEARCH_MODE "GLOB") - set(MY_PROJ_LIBS dsn.replication.zookeeper_provider dsn_replication_common @@ -47,18 +38,20 @@ set(MY_PROJ_LIBS dsn_dist_cmd dsn_http dsn_meta_server + dsn_ranger dsn_runtime dsn_aio zookeeper hashtable gtest hdfs) - set(MY_BOOST_LIBS Boost::system Boost::filesystem) - -# Extra files that will be installed -set(MY_BINPLACES clear.sh run.sh config-test.ini suite1 suite2) - +set(MY_BINPLACES + clear.sh + run.sh + config-test.ini + suite1 + suite2) dsn_add_test() add_subdirectory(balancer_simulator) diff --git a/src/meta/test/balancer_simulator/CMakeLists.txt b/src/meta/test/balancer_simulator/CMakeLists.txt index 7fe9925dac..69ddfc4a44 100644 --- a/src/meta/test/balancer_simulator/CMakeLists.txt +++ b/src/meta/test/balancer_simulator/CMakeLists.txt @@ -23,26 +23,14 @@ # THE SOFTWARE. set(MY_PROJ_NAME sim_lb) - -# Source files under CURRENT project directory will be automatically included. -# You can manually set MY_PROJ_SRC to include source files under other directories. set(MY_PROJ_SRC ../misc/misc.cpp) - -# Search mode for source files under CURRENT project directory? -# "GLOB_RECURSE" for recursive search -# "GLOB" for non-recursive search set(MY_SRC_SEARCH_MODE "GLOB") - set(MY_PROJ_LIBS - dsn_meta_server - dsn_replication_common - dsn_runtime - hashtable - gtest) - + dsn_runtime + dsn_meta_server + dsn_ranger + dsn_replication_common + gtest) set(MY_BOOST_LIBS Boost::system Boost::filesystem) - -# Extra files that will be installed set(MY_BINPLACES "") - dsn_add_test() diff --git a/src/meta/test/meta_bulk_load_service_test.cpp b/src/meta/test/meta_bulk_load_service_test.cpp index c83f8cbbb4..d3ae38a1e8 100644 --- a/src/meta/test/meta_bulk_load_service_test.cpp +++ b/src/meta/test/meta_bulk_load_service_test.cpp @@ -41,7 +41,6 @@ #include "gtest/gtest.h" #include "meta/meta_bulk_load_service.h" #include "meta/meta_data.h" -#include "meta/meta_options.h" #include "meta/meta_server_failure_detector.h" #include "meta/meta_service.h" #include "meta/meta_state_service_utils.h" @@ -54,6 +53,7 @@ #include "utils/blob.h" #include "utils/error_code.h" #include "utils/fail_point.h" +#include "utils/filesystem.h" #include "utils/fmt_logging.h" namespace dsn { @@ -344,7 +344,7 @@ class bulk_load_service_test : public meta_test_base // initialize bulk load service _ms->_bulk_load_svc = std::make_unique( - _ms.get(), meta_options::concat_path_unix_style(_ms->_cluster_root, "bulk_load")); + _ms.get(), utils::filesystem::concat_path_unix_style(_ms->_cluster_root, "bulk_load")); mock_bulk_load_on_remote_storage( app_id_set, app_bulk_load_info_map, partition_bulk_load_info_map); diff --git a/src/meta/test/meta_partition_guardian_test.cpp b/src/meta/test/meta_partition_guardian_test.cpp index 403dcb3fe2..e4f62f1fb5 100644 --- a/src/meta/test/meta_partition_guardian_test.cpp +++ b/src/meta/test/meta_partition_guardian_test.cpp @@ -45,7 +45,6 @@ #include "gtest/gtest.h" #include "meta/greedy_load_balancer.h" #include "meta/meta_data.h" -#include "meta/meta_options.h" #include "meta/meta_server_failure_detector.h" #include "meta/meta_service.h" #include "meta/partition_guardian.h" @@ -62,6 +61,7 @@ #include "runtime/task/task.h" #include "utils/autoref_ptr.h" #include "utils/error_code.h" +#include "utils/filesystem.h" namespace dsn { namespace replication { @@ -179,7 +179,8 @@ void meta_partition_guardian_test::cure_test() svc->_balancer.reset(new dummy_balancer(svc.get())); server_state *state = svc->_state.get(); - state->initialize(svc.get(), meta_options::concat_path_unix_style(svc->_cluster_root, "apps")); + state->initialize(svc.get(), + utils::filesystem::concat_path_unix_style(svc->_cluster_root, "apps")); dsn::app_info info; info.is_stateful = true; info.status = dsn::app_status::AS_CREATING; diff --git a/src/meta/test/meta_state/CMakeLists.txt b/src/meta/test/meta_state/CMakeLists.txt index 9f480e7808..dbb7be2ebb 100644 --- a/src/meta/test/meta_state/CMakeLists.txt +++ b/src/meta/test/meta_state/CMakeLists.txt @@ -23,33 +23,20 @@ # THE SOFTWARE. set(MY_PROJ_NAME dsn_meta_state_tests) - -# Source files under CURRENT project directory will be automatically included. -# You can manually set MY_PROJ_SRC to include source files under other directories. set(MY_PROJ_SRC "") - -# Search mode for source files under CURRENT project directory? -# "GLOB_RECURSE" for recursive search -# "GLOB" for non-recursive search set(MY_SRC_SEARCH_MODE "GLOB") - -set(MY_PROJ_LIBS - dsn_meta_server - dsn_replica_server - dsn_replication_common - dsn_runtime - hashtable - gtest - ) - +set(MY_PROJ_LIBS + dsn_meta_server + dsn_ranger + dsn_replica_server + dsn_replication_common + dsn_runtime + hashtable + gtest) set(MY_BOOST_LIBS Boost::system Boost::filesystem) - -# Extra files that will be installed set(MY_BINPLACES - "run.sh" - "clear.sh" - "config-test.ini" - "gtest.filter" -) - + run.sh + clear.sh + config-test.ini + gtest.filter) dsn_add_test() diff --git a/src/meta/test/meta_test_base.cpp b/src/meta/test/meta_test_base.cpp index d05d8a1452..9b0a865454 100644 --- a/src/meta/test/meta_test_base.cpp +++ b/src/meta/test/meta_test_base.cpp @@ -28,7 +28,6 @@ #include "gtest/gtest.h" #include "meta/meta_bulk_load_service.h" #include "meta/meta_data.h" -#include "meta/meta_options.h" #include "meta/meta_rpc_types.h" #include "meta/meta_server_failure_detector.h" #include "meta/meta_service.h" @@ -44,6 +43,7 @@ #include "runtime/task/task_tracker.h" #include "utils/error_code.h" #include "utils/factory_store.h" +#include "utils/filesystem.h" #include "utils/flags.h" #include "utils/fmt_logging.h" #include "utils/zlocks.h" @@ -71,7 +71,7 @@ void meta_test_base::SetUp() _ms->_split_svc = std::make_unique(_ms.get()); ASSERT_TRUE(_ms->_split_svc); _ms->_bulk_load_svc = std::make_unique( - _ms.get(), meta_options::concat_path_unix_style(_ms->_cluster_root, "bulk_load")); + _ms.get(), utils::filesystem::concat_path_unix_style(_ms->_cluster_root, "bulk_load")); ASSERT_TRUE(_ms->_bulk_load_svc); _ms->_bulk_load_svc->initialize_bulk_load_service(); diff --git a/src/meta/test/update_configuration_test.cpp b/src/meta/test/update_configuration_test.cpp index d80b32a3e2..2c23d231c2 100644 --- a/src/meta/test/update_configuration_test.cpp +++ b/src/meta/test/update_configuration_test.cpp @@ -45,7 +45,6 @@ #include "gtest/gtest.h" #include "meta/greedy_load_balancer.h" #include "meta/meta_data.h" -#include "meta/meta_options.h" #include "meta/meta_server_failure_detector.h" #include "meta/meta_service.h" #include "meta/partition_guardian.h" @@ -63,6 +62,7 @@ #include "runtime/task/task.h" #include "utils/autoref_ptr.h" #include "utils/error_code.h" +#include "utils/filesystem.h" #include "utils/flags.h" #include "utils/fmt_logging.h" #include "utils/zlocks.h" @@ -224,7 +224,8 @@ void meta_service_test_app::update_configuration_test() svc->_balancer.reset(new dummy_balancer(svc.get())); server_state *ss = svc->_state.get(); - ss->initialize(svc.get(), meta_options::concat_path_unix_style(svc->_cluster_root, "apps")); + ss->initialize(svc.get(), + utils::filesystem::concat_path_unix_style(svc->_cluster_root, "apps")); dsn::app_info info; info.is_stateful = true; info.status = dsn::app_status::AS_CREATING; @@ -303,7 +304,8 @@ void meta_service_test_app::adjust_dropped_size() svc->_balancer.reset(new dummy_balancer(svc.get())); server_state *ss = svc->_state.get(); - ss->initialize(svc.get(), meta_options::concat_path_unix_style(svc->_cluster_root, "apps")); + ss->initialize(svc.get(), + utils::filesystem::concat_path_unix_style(svc->_cluster_root, "apps")); dsn::app_info info; info.is_stateful = true; info.status = dsn::app_status::AS_CREATING; diff --git a/src/perf_counter/test/CMakeLists.txt b/src/perf_counter/test/CMakeLists.txt index f924437dec..1b1a8d2292 100644 --- a/src/perf_counter/test/CMakeLists.txt +++ b/src/perf_counter/test/CMakeLists.txt @@ -23,32 +23,20 @@ # THE SOFTWARE. set(MY_PROJ_NAME dsn_perf_counter_test) - -# Source files under CURRENT project directory will be automatically included. -# You can manually set MY_PROJ_SRC to include source files under other directories. set(MY_PROJ_SRC "") - -# Search mode for source files under CURRENT project directory? -# "GLOB_RECURSE" for recursive search -# "GLOB" for non-recursive search set(MY_SRC_SEARCH_MODE "GLOB") - set(MY_PROJ_LIBS + dsn_runtime dsn_meta_server + dsn_ranger dsn_replication_common - gtest - dsn_runtime rocksdb lz4 zstd - snappy) - + snappy + gtest) set(MY_BOOST_LIBS Boost::system Boost::filesystem) - -# Extra files that will be installed set(MY_BINPLACES - "${CMAKE_CURRENT_SOURCE_DIR}/clear.sh" - "${CMAKE_CURRENT_SOURCE_DIR}/run.sh" -) - + clear.sh + run.sh) dsn_add_test() diff --git a/src/runtime/ranger/CMakeLists.txt b/src/ranger/CMakeLists.txt similarity index 92% rename from src/runtime/ranger/CMakeLists.txt rename to src/ranger/CMakeLists.txt index fbbceb570a..79b4896091 100644 --- a/src/runtime/ranger/CMakeLists.txt +++ b/src/ranger/CMakeLists.txt @@ -16,11 +16,11 @@ # under the License. set(MY_PROJ_NAME dsn_ranger) - set(MY_PROJ_SRC "") set(MY_SRC_SEARCH_MODE "GLOB") set(MY_PROJ_LIBS dsn_meta_server - dsn_replication_common) - + dsn_replication_common + dsn_utils) dsn_add_static_library() +add_subdirectory(test) diff --git a/src/runtime/ranger/access_type.h b/src/ranger/access_type.h similarity index 83% rename from src/runtime/ranger/access_type.h rename to src/ranger/access_type.h index b28795b65d..74dae6a1f0 100644 --- a/src/runtime/ranger/access_type.h +++ b/src/ranger/access_type.h @@ -49,11 +49,17 @@ ENUM_END(access_type) using act = std::underlying_type::type; -access_type operator|(access_type lhs, access_type rhs); +inline access_type operator|(access_type lhs, access_type rhs) +{ + return access_type(static_cast(lhs) | static_cast(rhs)); +} -access_type operator&(access_type lhs, access_type rhs); +inline access_type operator&(access_type lhs, access_type rhs) +{ + return access_type(static_cast(lhs) & static_cast(rhs)); +} -access_type &operator|=(access_type &lhs, access_type rhs); +inline access_type &operator|=(access_type &lhs, access_type rhs) { return lhs = lhs | rhs; } const access_type kAccessTypeNone = access_type::kInvalid; const access_type kAccessTypeAll = access_type::kRead | access_type::kWrite | access_type::kCreate | diff --git a/src/runtime/ranger/ranger_resource_policy.cpp b/src/ranger/ranger_resource_policy.cpp similarity index 99% rename from src/runtime/ranger/ranger_resource_policy.cpp rename to src/ranger/ranger_resource_policy.cpp index 2342da7541..ae6262be0d 100644 --- a/src/runtime/ranger/ranger_resource_policy.cpp +++ b/src/ranger/ranger_resource_policy.cpp @@ -17,7 +17,7 @@ #include "ranger_resource_policy.h" -#include "runtime/ranger/access_type.h" +#include "ranger/access_type.h" #include "utils/fmt_logging.h" namespace dsn { diff --git a/src/runtime/ranger/ranger_resource_policy.h b/src/ranger/ranger_resource_policy.h similarity index 100% rename from src/runtime/ranger/ranger_resource_policy.h rename to src/ranger/ranger_resource_policy.h diff --git a/src/runtime/ranger/ranger_resource_policy_manager.cpp b/src/ranger/ranger_resource_policy_manager.cpp similarity index 99% rename from src/runtime/ranger/ranger_resource_policy_manager.cpp rename to src/ranger/ranger_resource_policy_manager.cpp index 4bc5ee54ff..d9fb6c30dd 100644 --- a/src/runtime/ranger/ranger_resource_policy_manager.cpp +++ b/src/ranger/ranger_resource_policy_manager.cpp @@ -38,19 +38,19 @@ #include "common/replication_common.h" #include "dsn.layer2_types.h" #include "fmt/core.h" -#include "meta/meta_options.h" #include "meta/meta_service.h" #include "meta/meta_state_service.h" #include "meta/server_state.h" #include "meta_admin_types.h" +#include "ranger/ranger_resource_policy.h" +#include "ranger/ranger_resource_policy_manager.h" #include "ranger_resource_policy_manager.h" #include "rapidjson/allocators.h" -#include "runtime/ranger/ranger_resource_policy.h" -#include "runtime/ranger/ranger_resource_policy_manager.h" #include "runtime/task/async_calls.h" #include "runtime/task/task.h" #include "runtime/task/task_code.h" #include "utils/blob.h" +#include "utils/filesystem.h" #include "utils/flags.h" #include "utils/fmt_logging.h" #include "utils/process_utils.h" @@ -205,7 +205,7 @@ ranger_resource_policy_manager::ranger_resource_policy_manager( void ranger_resource_policy_manager::start() { CHECK_NOTNULL(_meta_svc, ""); - _ranger_policy_meta_root = dsn::replication::meta_options::concat_path_unix_style( + _ranger_policy_meta_root = dsn::utils::filesystem::concat_path_unix_style( _meta_svc->cluster_root(), "ranger_policy_meta_root"); tasking::enqueue_timer(LPC_USE_RANGER_ACCESS_CONTROL, &_tracker, diff --git a/src/runtime/ranger/ranger_resource_policy_manager.h b/src/ranger/ranger_resource_policy_manager.h similarity index 99% rename from src/runtime/ranger/ranger_resource_policy_manager.h rename to src/ranger/ranger_resource_policy_manager.h index 52aeb2c727..974c0fe84d 100644 --- a/src/runtime/ranger/ranger_resource_policy_manager.h +++ b/src/ranger/ranger_resource_policy_manager.h @@ -27,7 +27,7 @@ #include "gtest/gtest_prod.h" #include "ranger_resource_policy.h" #include "rapidjson/document.h" -#include "runtime/ranger/access_type.h" +#include "ranger/access_type.h" #include "runtime/task/task_tracker.h" #include "utils/enum_helper.h" #include "utils/error_code.h" diff --git a/src/ranger/test/CMakeLists.txt b/src/ranger/test/CMakeLists.txt new file mode 100644 index 0000000000..443791ff28 --- /dev/null +++ b/src/ranger/test/CMakeLists.txt @@ -0,0 +1,30 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +set(MY_PROJ_NAME dsn_ranger_tests) +set(MY_PROJ_SRC "") +set(MY_SRC_SEARCH_MODE "GLOB") +set(MY_PROJ_LIBS + dsn_ranger + dsn_runtime + dsn_meta_server + dsn_replication_common + dsn_utils + gtest) +set(MY_BINPLACES + run.sh) +dsn_add_test() diff --git a/src/runtime/ranger/access_type.cpp b/src/ranger/test/main.cpp similarity index 64% rename from src/runtime/ranger/access_type.cpp rename to src/ranger/test/main.cpp index c26ddb71ba..ce7419113a 100644 --- a/src/runtime/ranger/access_type.cpp +++ b/src/ranger/test/main.cpp @@ -15,22 +15,10 @@ // specific language governing permissions and limitations // under the License. -#include "access_type.h" +#include -namespace dsn { -namespace ranger { - -access_type operator|(access_type lhs, access_type rhs) -{ - return access_type(static_cast(lhs) | static_cast(rhs)); -} - -access_type operator&(access_type lhs, access_type rhs) +GTEST_API_ int main(int argc, char **argv) { - return access_type(static_cast(lhs) & static_cast(rhs)); + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); } - -access_type &operator|=(access_type &lhs, access_type rhs) { return lhs = lhs | rhs; } - -} // namespace ranger -} // namespace dsn diff --git a/src/runtime/test/ranger_resource_policy_manager_test.cpp b/src/ranger/test/ranger_resource_policy_manager_test.cpp similarity index 99% rename from src/runtime/test/ranger_resource_policy_manager_test.cpp rename to src/ranger/test/ranger_resource_policy_manager_test.cpp index c17c51dfc9..ba355970a4 100644 --- a/src/runtime/test/ranger_resource_policy_manager_test.cpp +++ b/src/ranger/test/ranger_resource_policy_manager_test.cpp @@ -27,9 +27,9 @@ #include "common/json_helper.h" #include "gtest/gtest.h" -#include "runtime/ranger/access_type.h" -#include "runtime/ranger/ranger_resource_policy.h" -#include "runtime/ranger/ranger_resource_policy_manager.h" +#include "ranger/access_type.h" +#include "ranger/ranger_resource_policy.h" +#include "ranger/ranger_resource_policy_manager.h" #include "runtime/task/task_code.h" #include "utils/blob.h" #include "utils/flags.h" diff --git a/src/runtime/test/ranger_resource_policy_test.cpp b/src/ranger/test/ranger_resource_policy_test.cpp similarity index 99% rename from src/runtime/test/ranger_resource_policy_test.cpp rename to src/ranger/test/ranger_resource_policy_test.cpp index a9025d9bb5..ff6199d829 100644 --- a/src/runtime/test/ranger_resource_policy_test.cpp +++ b/src/ranger/test/ranger_resource_policy_test.cpp @@ -20,8 +20,8 @@ #include #include "gtest/gtest.h" -#include "runtime/ranger/access_type.h" -#include "runtime/ranger/ranger_resource_policy.h" +#include "ranger/access_type.h" +#include "ranger/ranger_resource_policy.h" namespace dsn { namespace ranger { diff --git a/src/ranger/test/run.sh b/src/ranger/test/run.sh new file mode 100755 index 0000000000..c518a6d6d6 --- /dev/null +++ b/src/ranger/test/run.sh @@ -0,0 +1,25 @@ +#!/bin/sh +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +if [ -z "${REPORT_DIR}" ]; then + REPORT_DIR="." +fi + +rm -rf data dsn_ranger_tests.xml +output_xml="${REPORT_DIR}/dsn_ranger_tests.xml" +GTEST_OUTPUT="xml:${output_xml}" ./dsn_ranger_tests diff --git a/src/replica/backup/test/CMakeLists.txt b/src/replica/backup/test/CMakeLists.txt index fed60e3120..bacb77adad 100644 --- a/src/replica/backup/test/CMakeLists.txt +++ b/src/replica/backup/test/CMakeLists.txt @@ -16,12 +16,11 @@ # under the License. set(MY_PROJ_NAME dsn_replica_backup_test) - set(MY_PROJ_SRC "") - set(MY_SRC_SEARCH_MODE "GLOB") - -set(MY_PROJ_LIBS dsn_meta_server +set(MY_PROJ_LIBS + dsn_meta_server + dsn_ranger dsn_replica_server dsn_replication_common dsn.block_service @@ -33,12 +32,8 @@ set(MY_PROJ_LIBS dsn_meta_server lz4 zstd snappy) - set(MY_BOOST_LIBS Boost::system Boost::filesystem) - set(MY_BINPLACES config-test.ini - run.sh -) - + run.sh) dsn_add_test() diff --git a/src/replica/bulk_load/test/CMakeLists.txt b/src/replica/bulk_load/test/CMakeLists.txt index bda1a89819..08abb8f9a7 100644 --- a/src/replica/bulk_load/test/CMakeLists.txt +++ b/src/replica/bulk_load/test/CMakeLists.txt @@ -16,12 +16,11 @@ # under the License. set(MY_PROJ_NAME dsn_replica_bulk_load_test) - set(MY_PROJ_SRC "") - set(MY_SRC_SEARCH_MODE "GLOB") - -set(MY_PROJ_LIBS dsn_meta_server +set(MY_PROJ_LIBS + dsn_meta_server + dsn_ranger dsn_replica_server dsn_replication_common dsn_runtime @@ -32,12 +31,8 @@ set(MY_PROJ_LIBS dsn_meta_server lz4 zstd snappy) - set(MY_BOOST_LIBS Boost::system Boost::filesystem) - set(MY_BINPLACES config-test.ini - run.sh -) - + run.sh) dsn_add_test() diff --git a/src/replica/duplication/test/CMakeLists.txt b/src/replica/duplication/test/CMakeLists.txt index 26e461bd75..57915bbe0e 100644 --- a/src/replica/duplication/test/CMakeLists.txt +++ b/src/replica/duplication/test/CMakeLists.txt @@ -16,12 +16,11 @@ # under the License. set(MY_PROJ_NAME dsn_replica_dup_test) - set(MY_PROJ_SRC "") - set(MY_SRC_SEARCH_MODE "GLOB") - -set(MY_PROJ_LIBS dsn_meta_server +set(MY_PROJ_LIBS + dsn_meta_server + dsn_ranger dsn_replica_server dsn.replication.zookeeper_provider dsn_replication_common @@ -35,15 +34,11 @@ set(MY_PROJ_LIBS dsn_meta_server lz4 zstd snappy) - set(MY_BOOST_LIBS Boost::system Boost::filesystem) - set(MY_BINPLACES config-test.ini log.1.0.handle_real_private_log log.1.0.all_loaded_are_write_empties log.1.0.handle_real_private_log2 - run.sh -) - + run.sh) dsn_add_test() diff --git a/src/replica/replica.h b/src/replica/replica.h index c4f3d2ff49..e552a33b0b 100644 --- a/src/replica/replica.h +++ b/src/replica/replica.h @@ -46,7 +46,7 @@ #include "replica/replica_base.h" #include "replica_context.h" #include "runtime/api_layer1.h" -#include "runtime/ranger/access_type.h" +#include "ranger/access_type.h" #include "runtime/rpc/rpc_message.h" #include "runtime/serverlet.h" #include "runtime/task/task.h" diff --git a/src/replica/replica_2pc.cpp b/src/replica/replica_2pc.cpp index 3acb42a19a..840353e266 100644 --- a/src/replica/replica_2pc.cpp +++ b/src/replica/replica_2pc.cpp @@ -55,7 +55,7 @@ #include "replica/replication_app_base.h" #include "replica_stub.h" #include "runtime/api_layer1.h" -#include "runtime/ranger/access_type.h" +#include "ranger/access_type.h" #include "runtime/rpc/network.h" #include "runtime/rpc/rpc_address.h" #include "runtime/rpc/rpc_message.h" diff --git a/src/replica/replica_stub.cpp b/src/replica/replica_stub.cpp index cc0c46cd57..44c6e6bf41 100644 --- a/src/replica/replica_stub.cpp +++ b/src/replica/replica_stub.cpp @@ -62,7 +62,7 @@ #include "replica_disk_migrator.h" #include "replica_stub.h" #include "runtime/api_layer1.h" -#include "runtime/ranger/access_type.h" +#include "ranger/access_type.h" #include "runtime/rpc/rpc_message.h" #include "runtime/rpc/serialization.h" #include "runtime/security/access_controller.h" diff --git a/src/replica/replica_stub.h b/src/replica/replica_stub.h index e702f70485..de158f992b 100644 --- a/src/replica/replica_stub.h +++ b/src/replica/replica_stub.h @@ -53,7 +53,7 @@ #include "replica.h" #include "replica/mutation_log.h" #include "replica_admin_types.h" -#include "runtime/ranger/access_type.h" +#include "ranger/access_type.h" #include "runtime/rpc/rpc_address.h" #include "runtime/rpc/rpc_holder.h" #include "runtime/security/access_controller.h" diff --git a/src/replica/split/test/CMakeLists.txt b/src/replica/split/test/CMakeLists.txt index 7e77ba7302..6bacdf05c5 100644 --- a/src/replica/split/test/CMakeLists.txt +++ b/src/replica/split/test/CMakeLists.txt @@ -16,24 +16,18 @@ # under the License. set(MY_PROJ_NAME dsn_replica_split_test) - set(MY_PROJ_SRC "") - set(MY_SRC_SEARCH_MODE "GLOB") - -set(MY_PROJ_LIBS dsn_meta_server +set(MY_PROJ_LIBS + dsn_meta_server + dsn_ranger dsn_replica_server dsn_replication_common dsn_runtime hashtable - gtest -) - + gtest) set(MY_BOOST_LIBS Boost::system Boost::filesystem) - set(MY_BINPLACES config-test.ini - run.sh -) - + run.sh) dsn_add_test() diff --git a/src/replica/storage/simple_kv/CMakeLists.txt b/src/replica/storage/simple_kv/CMakeLists.txt index a2f8506770..f8595297e2 100644 --- a/src/replica/storage/simple_kv/CMakeLists.txt +++ b/src/replica/storage/simple_kv/CMakeLists.txt @@ -23,23 +23,17 @@ # THE SOFTWARE. set(MY_PROJ_NAME dsn.replication.simple_kv) - thrift_generate_cpp( SIMPLE_KV_THRIFT_SRCS SIMPLE_KV_THRIFT_HDRS ${CMAKE_CURRENT_SOURCE_DIR}/simple_kv.thrift ) - set(MY_PROJ_SRC ${SIMPLE_KV_THRIFT_SRCS}) - -# Search mode for source files under CURRENT project directory? -# "GLOB_RECURSE" for recursive search -# "GLOB" for non-recursive search set(MY_SRC_SEARCH_MODE "GLOB") - set(MY_PROJ_LIBS dsn_replica_server dsn_meta_server + dsn_ranger dsn_client dsn_runtime hashtable @@ -47,19 +41,11 @@ set(MY_PROJ_LIBS lz4 zstd snappy) - set(MY_BOOST_LIBS Boost::system Boost::filesystem) - -set(INI_FILES "") -file(GLOB - RES_FILES - "${CMAKE_CURRENT_SOURCE_DIR}/*.ini" - "${CMAKE_CURRENT_SOURCE_DIR}/*.sh" - ) - -# Extra files that will be installed +file(GLOB RES_FILES + *.ini + *.sh) set(MY_BINPLACES ${RES_FILES}) - dsn_add_test() add_subdirectory(test) diff --git a/src/replica/storage/simple_kv/test/CMakeLists.txt b/src/replica/storage/simple_kv/test/CMakeLists.txt index 0bce41b712..1aa7dbaa15 100644 --- a/src/replica/storage/simple_kv/test/CMakeLists.txt +++ b/src/replica/storage/simple_kv/test/CMakeLists.txt @@ -23,15 +23,11 @@ # THE SOFTWARE. set(MY_PROJ_NAME dsn.rep_tests.simple_kv) - -# Search mode for source files under CURRENT project directory? -# "GLOB_RECURSE" for recursive search -# "GLOB" for non-recursive search set(MY_SRC_SEARCH_MODE "GLOB") - set(MY_PROJ_LIBS - dsn_replica_server dsn_meta_server + dsn_ranger + dsn_replica_server dsn_replication_common dsn_client dsn.failure_detector @@ -45,16 +41,11 @@ set(MY_PROJ_LIBS lz4 zstd snappy) - set(MY_BOOST_LIBS Boost::system Boost::filesystem) - -# Extra files that will be installed FILE(GLOB CASE_FILES "case-*") set(MY_BINPLACES - "run.sh" - "clear.sh" - "addcase.sh" - "${CASE_FILES}" -) - + run.sh + clear.sh + addcase.sh + ${CASE_FILES}) dsn_add_test() diff --git a/src/replica/test/CMakeLists.txt b/src/replica/test/CMakeLists.txt index 94b5c89348..ef30c7d031 100644 --- a/src/replica/test/CMakeLists.txt +++ b/src/replica/test/CMakeLists.txt @@ -23,18 +23,11 @@ # THE SOFTWARE. set(MY_PROJ_NAME dsn.replica.test) - -#Source files under CURRENT project directory will be automatically included. -#You can manually set MY_PROJ_SRC to include source files under other directories. set(MY_PROJ_SRC "") - -#Search mode for source files under CURRENT project directory ? -#"GLOB_RECURSE" for recursive search -#"GLOB" for non - recursive search set(MY_SRC_SEARCH_MODE "GLOB") - set(MY_PROJ_LIBS dsn_meta_server + dsn_ranger dsn_replica_server dsn.replication.zookeeper_provider dsn_replication_common @@ -52,9 +45,9 @@ set(MY_PROJ_LIBS lz4 zstd snappy) - set(MY_BOOST_LIBS Boost::system Boost::filesystem) - -#Extra files that will be installed -set(MY_BINPLACES clear.sh run.sh config-test.ini) +set(MY_BINPLACES + clear.sh + run.sh + config-test.ini) dsn_add_test() diff --git a/src/runtime/CMakeLists.txt b/src/runtime/CMakeLists.txt index d5757717ac..ac98bfc5d7 100644 --- a/src/runtime/CMakeLists.txt +++ b/src/runtime/CMakeLists.txt @@ -26,11 +26,9 @@ add_subdirectory(test) add_subdirectory(rpc) add_subdirectory(task) add_subdirectory(security) -add_subdirectory(ranger) # TODO(zlw) remove perf_counter from dsn_runtime after the refactor by WuTao add_library(dsn_runtime STATIC - $ $ $ $ @@ -51,8 +49,7 @@ add_library(dsn_runtime STATIC threadpool_code.cpp tool_api.cpp tracer.cpp - zlocks.cpp - ) + zlocks.cpp) target_link_libraries(dsn_runtime PRIVATE dsn_utils sasl2 gssapi_krb5 krb5) define_file_basename_for_sources(dsn_runtime) install(TARGETS dsn_runtime DESTINATION "lib") diff --git a/src/runtime/security/access_controller.h b/src/runtime/security/access_controller.h index 863779deb3..7770cdc160 100644 --- a/src/runtime/security/access_controller.h +++ b/src/runtime/security/access_controller.h @@ -21,7 +21,7 @@ #include #include -#include "runtime/ranger/access_type.h" +#include "ranger/access_type.h" namespace dsn { class message_ex; diff --git a/src/runtime/security/meta_access_controller.cpp b/src/runtime/security/meta_access_controller.cpp index 8334815955..8133d7533d 100644 --- a/src/runtime/security/meta_access_controller.cpp +++ b/src/runtime/security/meta_access_controller.cpp @@ -19,8 +19,8 @@ #include -#include "runtime/ranger/ranger_resource_policy_manager.h" -#include "runtime/ranger/ranger_resource_policy.h" +#include "ranger/ranger_resource_policy_manager.h" +#include "ranger/ranger_resource_policy.h" #include "runtime/rpc/network.h" #include "runtime/rpc/rpc_message.h" #include "runtime/task/task_code.h" diff --git a/src/runtime/security/replica_access_controller.h b/src/runtime/security/replica_access_controller.h index dcaeaa7586..834bdc614c 100644 --- a/src/runtime/security/replica_access_controller.h +++ b/src/runtime/security/replica_access_controller.h @@ -23,8 +23,8 @@ #include "access_controller.h" #include "common/json_helper.h" -#include "runtime/ranger/access_type.h" -#include "runtime/ranger/ranger_resource_policy.h" +#include "ranger/access_type.h" +#include "ranger/ranger_resource_policy.h" #include "utils/synchronize.h" namespace dsn { diff --git a/src/runtime/test/CMakeLists.txt b/src/runtime/test/CMakeLists.txt index 38e52a4f5b..83e355c449 100644 --- a/src/runtime/test/CMakeLists.txt +++ b/src/runtime/test/CMakeLists.txt @@ -23,32 +23,24 @@ # THE SOFTWARE. set(MY_PROJ_NAME dsn_runtime_tests) - -# Search mode for source files under CURRENT project directory? -# "GLOB_RECURSE" for recursive search -# "GLOB" for non-recursive search set(MY_SRC_SEARCH_MODE "GLOB") - set(MY_PROJ_LIBS - gtest + dsn_meta_server + dsn_ranger dsn_runtime dsn_aio - dsn_meta_server rocksdb lz4 zstd - snappy) - + snappy + gtest) set(MY_BOOST_LIBS Boost::system Boost::filesystem) - -# Extra files that will be installed -set(MY_BINPLACES "${CMAKE_CURRENT_SOURCE_DIR}/config-test-corrupt-message.ini" - "${CMAKE_CURRENT_SOURCE_DIR}/config-test.ini" - "${CMAKE_CURRENT_SOURCE_DIR}/config-test-sim.ini" - "${CMAKE_CURRENT_SOURCE_DIR}/command.txt" - "${CMAKE_CURRENT_SOURCE_DIR}/run.sh" - "${CMAKE_CURRENT_SOURCE_DIR}/clear.sh" - "${CMAKE_CURRENT_SOURCE_DIR}/gtest.filter" -) -add_definitions(-Wno-dangling-else) +set(MY_BINPLACES + config-test-corrupt-message.ini + config-test.ini + config-test-sim.ini + command.txt + run.sh + clear.sh + gtest.filter) dsn_add_test() diff --git a/src/runtime/test/async_call.cpp b/src/runtime/test/async_call.cpp index 0b55f2e788..0a266cbcf6 100644 --- a/src/runtime/test/async_call.cpp +++ b/src/runtime/test/async_call.cpp @@ -42,7 +42,7 @@ #include "runtime/task/task.h" #include "runtime/task/task_code.h" #include "runtime/task/task_tracker.h" -#include "test_utils.h" +#include "runtime/test_utils.h" #include "utils/autoref_ptr.h" #include "utils/error_code.h" #include "utils/fmt_logging.h" @@ -137,8 +137,9 @@ TEST(async_call, rpc_call) *str_command, &tc->_tracker, [str_command](error_code ec, std::string &&resp) { - if (ERR_OK == ec) + if (ERR_OK == ec) { EXPECT_TRUE(str_command->substr(5) == resp); + } }); task_vec.push_back(t); t = rpc::call(addr2, diff --git a/src/runtime/test/corrupt_message.cpp b/src/runtime/test/corrupt_message.cpp index 88a07cfc68..1db983b252 100644 --- a/src/runtime/test/corrupt_message.cpp +++ b/src/runtime/test/corrupt_message.cpp @@ -32,7 +32,7 @@ #include "gtest/gtest.h" #include "runtime/rpc/rpc_address.h" #include "runtime/task/async_calls.h" -#include "test_utils.h" +#include "runtime/test_utils.h" #include "utils/error_code.h" // this only works with the fault injector diff --git a/src/runtime/test/host_port_test.cpp b/src/runtime/test/host_port_test.cpp index 728bef6539..85324abfc0 100644 --- a/src/runtime/test/host_port_test.cpp +++ b/src/runtime/test/host_port_test.cpp @@ -34,7 +34,7 @@ #include "runtime/task/task.h" #include "runtime/task/task_spec.h" #include "runtime/task/task_tracker.h" -#include "test_utils.h" +#include "runtime/test_utils.h" #include "utils/autoref_ptr.h" #include "utils/error_code.h" #include "utils/errors.h" diff --git a/src/runtime/test/lpc.cpp b/src/runtime/test/lpc.cpp index 286cf1c487..c0d63b3a8d 100644 --- a/src/runtime/test/lpc.cpp +++ b/src/runtime/test/lpc.cpp @@ -32,7 +32,7 @@ #include "runtime/task/task.h" #include "runtime/task/task_code.h" #include "runtime/task/task_worker.h" -#include "test_utils.h" +#include "runtime/test_utils.h" #include "utils/autoref_ptr.h" DEFINE_TASK_CODE(LPC_TEST_HASH, TASK_PRIORITY_COMMON, THREAD_POOL_TEST_SERVER) diff --git a/src/runtime/test/main.cpp b/src/runtime/test/main.cpp index 0e0400eb6c..23b64deb6d 100644 --- a/src/runtime/test/main.cpp +++ b/src/runtime/test/main.cpp @@ -31,7 +31,7 @@ #include #include "runtime/app_model.h" #include "runtime/service_app.h" -#include "test_utils.h" +#include "runtime/test_utils.h" #include "utils/flags.h" #include "utils/strings.h" diff --git a/src/runtime/test/netprovider.cpp b/src/runtime/test/netprovider.cpp index f0b568300c..cef7f40ec9 100644 --- a/src/runtime/test/netprovider.cpp +++ b/src/runtime/test/netprovider.cpp @@ -46,7 +46,7 @@ #include "runtime/task/task.h" #include "runtime/task/task_code.h" #include "runtime/task/task_spec.h" -#include "test_utils.h" +#include "runtime/test_utils.h" #include "utils/autoref_ptr.h" #include "utils/error_code.h" #include "utils/flags.h" diff --git a/src/runtime/test/replica_access_controller_test.cpp b/src/runtime/test/replica_access_controller_test.cpp index d801d77558..b0d17da755 100644 --- a/src/runtime/test/replica_access_controller_test.cpp +++ b/src/runtime/test/replica_access_controller_test.cpp @@ -22,7 +22,7 @@ #include "common/replication.codes.h" #include "gtest/gtest.h" -#include "runtime/ranger/access_type.h" +#include "ranger/access_type.h" #include "runtime/rpc/network.h" #include "runtime/rpc/network.sim.h" #include "runtime/rpc/rpc_address.h" diff --git a/src/runtime/test/rpc.cpp b/src/runtime/test/rpc.cpp index 0acebc16fe..17c95fb5fe 100644 --- a/src/runtime/test/rpc.cpp +++ b/src/runtime/test/rpc.cpp @@ -41,7 +41,7 @@ #include "runtime/rpc/serialization.h" #include "runtime/task/async_calls.h" #include "runtime/task/task.h" -#include "test_utils.h" +#include "runtime/test_utils.h" #include "utils/autoref_ptr.h" #include "utils/error_code.h" #include "utils/fmt_logging.h" diff --git a/src/runtime/test/task_engine.cpp b/src/runtime/test/task_engine.cpp index 573e931ec1..38374f4558 100644 --- a/src/runtime/test/task_engine.cpp +++ b/src/runtime/test/task_engine.cpp @@ -32,7 +32,7 @@ #include "runtime/global_config.h" #include "runtime/service_engine.h" #include "runtime/task/task.h" -#include "test_utils.h" +#include "runtime/test_utils.h" #include "utils/enum_helper.h" #include "utils/threadpool_code.h" diff --git a/src/runtime/test/test_utils.h b/src/runtime/test_utils.h similarity index 100% rename from src/runtime/test/test_utils.h rename to src/runtime/test_utils.h diff --git a/src/server/CMakeLists.txt b/src/server/CMakeLists.txt index 8c8daa4d12..e37eeeff09 100644 --- a/src/server/CMakeLists.txt +++ b/src/server/CMakeLists.txt @@ -15,20 +15,13 @@ # specific language governing permissions and limitations # under the License. -set(MY_PROJ_NAME "pegasus_server") - -# Source files under CURRENT project directory will be automatically included. -# You can manually set MY_PROJ_SRC to include source files under other directories. +set(MY_PROJ_NAME pegasus_server) set(MY_PROJ_SRC "") - -# Search mode for source files under CURRENT project directory? -# "GLOB_RECURSE" for recursive search -# "GLOB" for non-recursive search set(MY_SRC_SEARCH_MODE "GLOB") - set(MY_PROJ_LIBS dsn_replica_server dsn_meta_server + dsn_ranger dsn_replication_common dsn_client dsn.block_service.local @@ -44,15 +37,11 @@ set(MY_PROJ_LIBS pegasus_client_static event hashtable) - set(MY_BOOST_LIBS Boost::system Boost::filesystem) - -set(MY_BINPLACES "${CMAKE_CURRENT_SOURCE_DIR}/config.ini") - +set(MY_BINPLACES + ${CMAKE_CURRENT_SOURCE_DIR}/config.ini) add_definitions(-Wno-attributes) - SET(CMAKE_INSTALL_RPATH ".") SET(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) - dsn_add_executable() dsn_install_executable() diff --git a/src/server/test/CMakeLists.txt b/src/server/test/CMakeLists.txt index 2b4c96ac1f..5907476d30 100644 --- a/src/server/test/CMakeLists.txt +++ b/src/server/test/CMakeLists.txt @@ -16,28 +16,26 @@ # under the License. set(MY_PROJ_NAME pegasus_unit_test) - -set(MY_PROJ_SRC "../pegasus_server_impl.cpp" - "../pegasus_server_impl_init.cpp" - "../pegasus_manual_compact_service.cpp" - "../pegasus_event_listener.cpp" - "../pegasus_write_service.cpp" - "../pegasus_server_write.cpp" - "../capacity_unit_calculator.cpp" - "../pegasus_mutation_duplicator.cpp" - "../hotspot_partition_calculator.cpp" - "../meta_store.cpp" - "../hotkey_collector.cpp" - "../rocksdb_wrapper.cpp" - "../compaction_filter_rule.cpp" - "../compaction_operation.cpp" - ) - +set(MY_PROJ_SRC + "../pegasus_server_impl.cpp" + "../pegasus_server_impl_init.cpp" + "../pegasus_manual_compact_service.cpp" + "../pegasus_event_listener.cpp" + "../pegasus_write_service.cpp" + "../pegasus_server_write.cpp" + "../capacity_unit_calculator.cpp" + "../pegasus_mutation_duplicator.cpp" + "../hotspot_partition_calculator.cpp" + "../meta_store.cpp" + "../hotkey_collector.cpp" + "../rocksdb_wrapper.cpp" + "../compaction_filter_rule.cpp" + "../compaction_operation.cpp") set(MY_SRC_SEARCH_MODE "GLOB") - set(MY_PROJ_LIBS dsn_replica_server dsn_meta_server + dsn_ranger dsn_replication_common dsn_client dsn.block_service.local @@ -54,13 +52,11 @@ set(MY_PROJ_LIBS pegasus_base gtest gmock - hashtable -) + hashtable) add_definitions(-DPEGASUS_UNIT_TEST) add_definitions(-DENABLE_FAIL) - set(MY_BOOST_LIBS Boost::system Boost::filesystem) - -set(MY_BINPLACES config.ini run.sh) - +set(MY_BINPLACES + config.ini + run.sh) dsn_add_test() diff --git a/src/shell/CMakeLists.txt b/src/shell/CMakeLists.txt index 81271006e1..121f1b04cb 100644 --- a/src/shell/CMakeLists.txt +++ b/src/shell/CMakeLists.txt @@ -15,23 +15,18 @@ # specific language governing permissions and limitations # under the License. -set(MY_PROJ_NAME "pegasus_shell") +set(MY_PROJ_NAME pegasus_shell) project(${MY_PROJ_NAME} C CXX) - -# Source files under CURRENT project directory will be automatically included. -# You can manually set MY_PROJ_SRC to include source files under other directories. -set(MY_PROJ_SRC "linenoise/linenoise.c" "sds/sds.c") - -# Search mode for source files under CURRENT project directory? -# "GLOB_RECURSE" for recursive search -# "GLOB" for non-recursive search +set(MY_PROJ_SRC + linenoise/linenoise.c + sds/sds.c) set(MY_SRC_SEARCH_MODE "GLOB_RECURSE") - set(MY_PROJ_LIBS pegasus_base dsn.replication.tool dsn_replica_server dsn_meta_server + dsn_ranger dsn_replication_common dsn_client dsn_utils @@ -49,15 +44,11 @@ set(MY_PROJ_LIBS absl::strings s2 hdfs) - -set(MY_BINPLACES "${CMAKE_CURRENT_SOURCE_DIR}/config.ini") - +set(MY_BINPLACES + ${CMAKE_CURRENT_SOURCE_DIR}/config.ini) set(MY_BOOST_LIBS Boost::system Boost::filesystem) - SET(CMAKE_INSTALL_RPATH ".") SET(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) - add_definitions(-Wno-attributes) - dsn_add_executable() dsn_install_executable() diff --git a/src/utils/filesystem.cpp b/src/utils/filesystem.cpp index 0ebe07ef77..d0d4396640 100644 --- a/src/utils/filesystem.cpp +++ b/src/utils/filesystem.cpp @@ -569,6 +569,17 @@ std::string path_combine(const std::string &path1, const std::string &path2) return npath; } +std::string concat_path_unix_style(const std::string &prefix, const std::string &postfix) +{ + size_t pos1 = prefix.size(); // last_valid_pos + 1 + while (pos1 > 0 && prefix[pos1 - 1] == '/') + pos1--; + size_t pos2 = 0; // first non '/' position + while (pos2 < postfix.size() && postfix[pos2] == '/') + pos2++; + return prefix.substr(0, pos1) + "/" + postfix.substr(pos2); +} + bool get_current_directory(std::string &path) { bool succ; diff --git a/src/utils/filesystem.h b/src/utils/filesystem.h index 2142d1be1a..29524c9c3c 100644 --- a/src/utils/filesystem.h +++ b/src/utils/filesystem.h @@ -75,7 +75,9 @@ std::string remove_file_name(const std::string &path); std::string get_file_name(const std::string &path); +// TODO(yingchun): The 2 functions are similar, remove concat_path_unix_style. std::string path_combine(const std::string &path1, const std::string &path2); +std::string concat_path_unix_style(const std::string &prefix, const std::string &postfix); typedef std::function ftw_handler; bool file_tree_walk(const std::string &dirpath, ftw_handler handler, bool recursive = true);