forked from ydb-platform/nbs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.cpp
181 lines (148 loc) · 5.86 KB
/
config.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#include "config.h"
#include <library/cpp/monlib/service/pages/templates.h>
#include <util/generic/vector.h>
namespace NCloud::NFileStore::NServer {
namespace {
////////////////////////////////////////////////////////////////////////////////
constexpr TDuration Seconds(int s)
{
return TDuration::Seconds(s);
}
////////////////////////////////////////////////////////////////////////////////
#define FILESTORE_SERVER_CONFIG(xxx) \
xxx(Host, TString, "localhost" )\
xxx(Port, ui32, 9021 )\
xxx(MaxMessageSize, ui32, 64*1024*1024 )\
xxx(MemoryQuotaBytes, ui32, 0 )\
xxx(PreparedRequestsCount, ui32, 10 )\
xxx(ThreadsCount, ui32, 1 )\
xxx(GrpcThreadsLimit, ui32, 4 )\
xxx(KeepAliveEnabled, bool, false )\
xxx(KeepAliveIdleTimeout, TDuration, {} )\
xxx(KeepAliveProbeTimeout, TDuration, {} )\
xxx(KeepAliveProbesCount, ui32, 0 )\
xxx(ShutdownTimeout, TDuration, Seconds(30) )\
xxx(SecureHost, TString, {} )\
xxx(SecurePort, ui32, 0 )\
xxx(RootCertsFile, TString, {} )\
xxx(Certs, TVector<TCertificate>, {} )\
xxx(UnixSocketPath, TString, {} )\
xxx(UnixSocketBacklog, ui32, 16 )\
\
xxx(ActionsNoAuth, TVector<TString>, {} )\
// FILESTORE_SERVER_CONFIG
#define FILESTORE_SERVER_DECLARE_CONFIG(name, type, value) \
Y_DECLARE_UNUSED static const type Default##name = value; \
// FILESTORE_SERVER_DECLARE_CONFIG
FILESTORE_SERVER_CONFIG(FILESTORE_SERVER_DECLARE_CONFIG)
#undef FILESTORE_SERVER_DECLARE_CONFIG
////////////////////////////////////////////////////////////////////////////////
template <typename TTarget, typename TSource>
TTarget ConvertValue(const TSource& value)
{
return static_cast<TTarget>(value);
}
template <>
TDuration ConvertValue<TDuration, ui32>(const ui32& value)
{
return TDuration::MilliSeconds(value);
}
template <>
TVector<TCertificate> ConvertValue(
const google::protobuf::RepeatedPtrField<NCloud::NProto::TCertificate>& value)
{
TVector<TCertificate> v;
for (const auto& x : value) {
v.push_back({x.GetCertFile(), x.GetCertPrivateKeyFile()});
}
return v;
}
template <>
TVector<TString> ConvertValue(
const google::protobuf::RepeatedPtrField<TString>& value)
{
TVector<TString> v;
for (const auto& x : value) {
v.push_back(x);
}
return v;
}
template <typename T>
bool IsEmpty(const T& t)
{
return !t;
}
template <typename T>
bool IsEmpty(const google::protobuf::RepeatedPtrField<T>& value)
{
return value.empty();
}
template <typename T>
void DumpImpl(const T& t, IOutputStream& os)
{
os << t;
}
template <>
void DumpImpl(const TVector<TCertificate>& value, IOutputStream& os)
{
for (size_t i = 0; i < value.size(); ++i) {
if (i) {
os << ",";
}
os
<< "{ "
<< value[i].CertFile
<< ", "
<< value[i].CertPrivateKeyFile
<< " }";
}
}
template <>
void DumpImpl(const TVector<TString>& value, IOutputStream& os)
{
for (size_t i = 0; i < value.size(); ++i) {
if (i) {
os << ",";
}
os << value[i];
}
}
} // namespace
////////////////////////////////////////////////////////////////////////////////
#define FILESTORE_CONFIG_GETTER(name, type, ...) \
type TServerConfig::Get##name() const \
{ \
const auto& value = ProtoConfig.Get##name(); \
return !IsEmpty(value) ? ConvertValue<type>(value) : Default##name; \
} \
// FILESTORE_CONFIG_GETTER
FILESTORE_SERVER_CONFIG(FILESTORE_CONFIG_GETTER)
#undef FILESTORE_CONFIG_GETTER
void TServerConfig::Dump(IOutputStream& out) const
{
#define FILESTORE_CONFIG_DUMP(name, ...) \
out << #name << ": "; \
DumpImpl(Get##name(), out); \
out << Endl; \
// FILESTORE_CONFIG_DUMP
FILESTORE_SERVER_CONFIG(FILESTORE_CONFIG_DUMP);
#undef FILESTORE_CONFIG_DUMP
}
void TServerConfig::DumpHtml(IOutputStream& out) const
{
#define FILESTORE_CONFIG_DUMP(name, ...) \
TABLER() { \
TABLED() { out << #name; } \
TABLED() { DumpImpl(Get##name(), out); } \
} \
// FILESTORE_CONFIG_DUMP
HTML(out) {
TABLE_CLASS("table table-condensed") {
TABLEBODY() {
FILESTORE_SERVER_CONFIG(FILESTORE_CONFIG_DUMP);
}
}
}
#undef FILESTORE_CONFIG_DUMP
}
} // namespace NCloud::NFileStore::NServer