Skip to content
This repository has been archived by the owner on Jun 23, 2022. It is now read-only.

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
qinzuoyan authored Aug 1, 2018
2 parents 79f8e76 + 54770a2 commit 3ebfdb8
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 7 deletions.
5 changes: 5 additions & 0 deletions bin/dsn.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
include(${CMAKE_CURRENT_LIST_DIR}/compiler_info.cmake)

# Always generate the compilation database file (compile_commands.json) for use
# with various development tools, such as IWYU and Vim's YouCompleteMe plugin.
# See http://clang.llvm.org/docs/JSONCompilationDatabase.html
set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE)

function(ms_add_project PROJ_LANG PROJ_TYPE PROJ_NAME PROJ_SRC PROJ_INC_PATH PROJ_LIBS PROJ_LIB_PATH PROJ_BINPLACES PROJ_BINDIRS DO_INSTALL)
if(DEFINED DSN_DEBUG_CMAKE)
message(STATUS "PROJ_LANG = ${PROJ_LANG}")
Expand Down
2 changes: 2 additions & 0 deletions include/dsn/dist/replication/replication_ddl_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ class replication_ddl_client
list_nodes(const dsn::replication::node_status::type status,
std::map<dsn::rpc_address, dsn::replication::node_status::type> &nodes);

dsn::error_code cluster_name(int64_t timeout_ms, std::string &cluster_name);

dsn::error_code cluster_info(const std::string &file_name, bool resolve_ip = false);

dsn::error_code list_app(const std::string &app_name,
Expand Down
14 changes: 7 additions & 7 deletions src/core/tests/string_conv_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

TEST(string_conv, buf2bool)
{
bool result;
bool result = false;

ASSERT_TRUE(dsn::buf2bool("true", result));
ASSERT_EQ(result, true);
Expand Down Expand Up @@ -60,7 +60,7 @@ TEST(string_conv, buf2bool)

TEST(string_conv, buf2int32)
{
int32_t result;
int32_t result = -1;

ASSERT_TRUE(dsn::buf2int32(std::to_string(0), result));
ASSERT_EQ(result, 0);
Expand Down Expand Up @@ -98,7 +98,7 @@ TEST(string_conv, buf2int32)

TEST(string_conv, buf2int64)
{
int64_t result;
int64_t result = -1;

ASSERT_TRUE(dsn::buf2int64(std::to_string(0), result));
ASSERT_EQ(result, 0);
Expand Down Expand Up @@ -143,7 +143,7 @@ TEST(string_conv, buf2int64)

TEST(string_conv, buf2uint64)
{
uint64_t result;
uint64_t result = 1;

ASSERT_TRUE(dsn::buf2uint64(std::to_string(0), result));
ASSERT_EQ(result, 0);
Expand Down Expand Up @@ -185,7 +185,7 @@ TEST(string_conv, buf2uint64)

TEST(string_conv, int64_partial)
{
int64_t result;
int64_t result = 0;
ASSERT_FALSE(dsn::buf2int64("", result));
ASSERT_FALSE(dsn::buf2int64(" ", result)) << result;
ASSERT_FALSE(dsn::buf2int64("-", result)) << result;
Expand All @@ -201,7 +201,7 @@ TEST(string_conv, int64_partial)

TEST(string_conv, uint64_partial)
{
uint64_t result;
uint64_t result = 0;
ASSERT_FALSE(dsn::buf2uint64("", result));
ASSERT_FALSE(dsn::buf2uint64(" ", result)) << result;
ASSERT_FALSE(dsn::buf2uint64("-", result)) << result;
Expand All @@ -216,7 +216,7 @@ TEST(string_conv, uint64_partial)

TEST(string_conv, buf2double)
{
double result;
double result = 0;

ASSERT_TRUE(dsn::buf2double("1.1", result));
ASSERT_DOUBLE_EQ(result, 1.1);
Expand Down
32 changes: 32 additions & 0 deletions src/dist/replication/ddl_lib/replication_ddl_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,38 @@ dsn::error_code replication_ddl_client::list_nodes(const dsn::replication::node_
#undef RESOLVE
}

dsn::error_code replication_ddl_client::cluster_name(int64_t timeout_ms, std::string &cluster_name)
{
std::shared_ptr<configuration_cluster_info_request> req(
new configuration_cluster_info_request());

auto resp_task = request_meta<configuration_cluster_info_request>(RPC_CM_CLUSTER_INFO, req, timeout_ms);
resp_task->wait();
if (resp_task->error() != dsn::ERR_OK) {
return resp_task->error();
}

configuration_cluster_info_response resp;
::dsn::unmarshall(resp_task->get_response(), resp);
if (resp.err != dsn::ERR_OK) {
return resp.err;
}

std::string zk_root;
for (int i = 0; i < resp.keys.size(); ++i) {
if (resp.keys[i] == "zookeeper_root") {
zk_root = resp.values[i];
}
}

cluster_name.clear();
if (!zk_root.empty() && zk_root.find("/pegasus/") == 0) {
cluster_name = zk_root.substr(9);
}

return cluster_name.empty() ? dsn::ERR_UNKNOWN : dsn::ERR_OK;
}

dsn::error_code replication_ddl_client::cluster_info(const std::string &file_name, bool resolve_ip)
{
std::shared_ptr<configuration_cluster_info_request> req(
Expand Down

0 comments on commit 3ebfdb8

Please sign in to comment.