-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
ClientBasedGflagsManager.cpp
77 lines (66 loc) · 2.9 KB
/
ClientBasedGflagsManager.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/* Copyright (c) 2019 vesoft inc. All rights reserved.
*
* This source code is licensed under Apache 2.0 License,
* attached with Common Clause Condition 1.0, found in the LICENSES directory.
*/
#include "meta/ClientBasedGflagsManager.h"
namespace nebula {
namespace meta {
ClientBasedGflagsManager::ClientBasedGflagsManager(MetaClient *client) {
metaClient_ = client;
CHECK_NOTNULL(metaClient_);
}
ClientBasedGflagsManager::~ClientBasedGflagsManager() {
metaClient_ = nullptr;
}
template<typename ValueType>
folly::Future<StatusOr<bool>> ClientBasedGflagsManager::set(const cpp2::ConfigModule& module,
const std::string& name,
const cpp2::ConfigType& type,
const ValueType& value) {
std::string valueStr;
valueStr.append(reinterpret_cast<const char*>(&value), sizeof(value));
return metaClient_->setConfig(module, name, type, std::move(valueStr));
}
template<>
folly::Future<StatusOr<bool>>
ClientBasedGflagsManager::set<std::string>(const cpp2::ConfigModule& module,
const std::string& name,
const cpp2::ConfigType& type,
const std::string& value) {
return metaClient_->setConfig(module, name, type, value);
}
folly::Future<StatusOr<bool>>
ClientBasedGflagsManager::setConfig(const cpp2::ConfigModule& module, const std::string& name,
const cpp2::ConfigType& type, const VariantType &value) {
switch (type) {
case cpp2::ConfigType::INT64:
return set(module, name, type, boost::get<int64_t>(value));
case cpp2::ConfigType::DOUBLE:
return set(module, name, type, boost::get<double>(value));
case cpp2::ConfigType::BOOL:
return set(module, name, type, boost::get<bool>(value));
case cpp2::ConfigType::STRING:
return set(module, name, type, boost::get<std::string>(value));
default:
return Status::Error("parse value type error");
}
}
folly::Future<StatusOr<std::vector<cpp2::ConfigItem>>>
ClientBasedGflagsManager::getConfig(const cpp2::ConfigModule& module, const std::string& name) {
return metaClient_->getConfig(module, name);
}
folly::Future<StatusOr<std::vector<cpp2::ConfigItem>>>
ClientBasedGflagsManager::listConfigs(const cpp2::ConfigModule& module) {
return metaClient_->listConfigs(module);
}
Status ClientBasedGflagsManager::registerGflags(const std::vector<cpp2::ConfigItem>& items) {
auto status = metaClient_->regConfig(items).get();
if (status.ok()) {
LOG(INFO) << "Register gflags ok " << items.size();
return Status::OK();
}
return Status::Error("Register gflags failed");
}
} // namespace meta
} // namespace nebula