-
Notifications
You must be signed in to change notification settings - Fork 610
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extract ydb init to separate classes #2064
Merged
Enjection
merged 21 commits into
ydb-platform:main
from
Enjection:feature/KIKIMR-21044/extract-init-from-driver-lib-0
Feb 28, 2024
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
c968d12
WIP
Enjection 8870f03
WIP
Enjection cb51224
WIP
Enjection 686a410
WIP
Enjection 774a066
WIP
Enjection 8bb3860
WIP
Enjection b6b04b0
WIP
Enjection 7654783
WIP
Enjection 55a463b
WIP
Enjection e383d1d
WIP
Enjection c015c7d
WIP
Enjection 0fe5ba8
WIP
Enjection 2a8320a
WIP
Enjection 5974964
WIP
Enjection 4c24bd3
WIP
Enjection f1c880c
add basic tests
Enjection 1242960
fix couple issues
Enjection 5025f64
fix link issues
Enjection 327cec5
remove debug
Enjection 4995451
fix
Enjection 06b8b32
fix
Enjection File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,217 @@ | ||
#pragma once | ||
|
||
#include <ydb/core/base/event_filter.h> | ||
#include <ydb/core/cms/console/config_item_info.h> | ||
#include <ydb/core/driver_lib/run/config.h> | ||
#include <ydb/core/protos/config.pb.h> | ||
#include <ydb/library/actors/core/interconnect.h> | ||
#include <ydb/public/lib/deprecated/kicli/kicli.h> | ||
|
||
#include <library/cpp/getopt/small/last_getopt_opts.h> | ||
|
||
#include <util/generic/hash.h> | ||
#include <util/generic/vector.h> | ||
#include <util/generic/string.h> | ||
#include <util/datetime/base.h> | ||
|
||
#include <memory> | ||
|
||
namespace NKikimr::NConfig { | ||
|
||
class IEnv { | ||
public: | ||
virtual ~IEnv() {} | ||
virtual TString HostName() const = 0; | ||
virtual TString FQDNHostName() const = 0; | ||
virtual TString ReadFromFile(const TString& filePath, const TString& fileName, bool allowEmpty = true) const = 0; | ||
virtual void Sleep(const TDuration& dur) const = 0; | ||
}; | ||
|
||
class IErrorCollector { | ||
public: | ||
virtual ~IErrorCollector() {} | ||
// TODO(Enjection): CFG-UX-0 replace regular throw with just collecting | ||
virtual void Fatal(TString error) = 0; | ||
}; | ||
|
||
class IProtoConfigFileProvider { | ||
public: | ||
virtual ~IProtoConfigFileProvider() {} | ||
virtual void AddConfigFile(TString optName, TString description) = 0; | ||
virtual void RegisterCliOptions(NLastGetopt::TOpts& opts) const = 0; | ||
virtual TString GetProtoFromFile(const TString& path, IErrorCollector& errorCollector) const = 0; | ||
virtual bool Has(TString optName) = 0; | ||
virtual TString Get(TString optName) = 0; | ||
}; | ||
|
||
class IConfigUpdateTracer { | ||
public: | ||
virtual ~IConfigUpdateTracer() {} | ||
virtual void Add(ui32 kind, TConfigItemInfo::TUpdate) = 0; | ||
virtual THashMap<ui32, TConfigItemInfo> Dump() const = 0; | ||
}; | ||
|
||
// === | ||
|
||
class IMemLogInitializer { | ||
public: | ||
virtual ~IMemLogInitializer() {} | ||
virtual void Init(const NKikimrConfig::TMemoryLogConfig& mem) const = 0; | ||
}; | ||
|
||
// === | ||
|
||
struct TGrpcSslSettings { | ||
TString PathToGrpcCertFile; | ||
TString PathToGrpcCaFile; | ||
TString PathToGrpcPrivateKeyFile; | ||
}; | ||
|
||
struct TNodeRegistrationSettings { | ||
TString DomainName; | ||
TString NodeHost; | ||
TString NodeAddress; | ||
TString NodeResolveHost; | ||
TMaybe<TString> Path; | ||
bool FixedNodeID; | ||
ui32 InterconnectPort; | ||
NActors::TNodeLocation Location; | ||
}; | ||
|
||
class INodeRegistrationResult { | ||
public: | ||
virtual ~INodeRegistrationResult() {} | ||
virtual void Apply(NKikimrConfig::TAppConfig& appConfig, ui32& nodeId, TKikimrScopeId& scopeId) const = 0; | ||
}; | ||
|
||
class INodeBrokerClient { | ||
public: | ||
virtual ~INodeBrokerClient() {} | ||
virtual std::unique_ptr<INodeRegistrationResult> RegisterDynamicNode( | ||
const TGrpcSslSettings& grpcSettings, | ||
const TVector<TString>& addrs, | ||
const TNodeRegistrationSettings& regSettings, | ||
const IEnv& env) const = 0; | ||
}; | ||
|
||
// === | ||
|
||
struct TDynConfigSettings { | ||
ui32 NodeId; | ||
TString DomainName; | ||
TString TenantName; | ||
TString FQDNHostName; | ||
TString NodeType; | ||
TString StaffApiUserToken; | ||
}; | ||
|
||
class IDynConfigClient { | ||
public: | ||
virtual ~IDynConfigClient() {} | ||
virtual TMaybe<NKikimr::NClient::TConfigurationResult> GetConfig( | ||
const TGrpcSslSettings& gs, | ||
const TVector<TString>& addrs, | ||
const TDynConfigSettings& settings, | ||
const IEnv& env) const = 0; | ||
}; | ||
|
||
// === | ||
|
||
class IInitialConfigurator { | ||
public: | ||
virtual ~IInitialConfigurator() {}; | ||
virtual void RegisterCliOptions(NLastGetopt::TOpts& opts) = 0; | ||
virtual void ValidateOptions(const NLastGetopt::TOpts& opts, const NLastGetopt::TOptsParseResult& parseResult) = 0; | ||
virtual void Parse(const TVector<TString>& freeArgs) = 0; | ||
virtual void Apply( | ||
NKikimrConfig::TAppConfig& appConfig, | ||
ui32& nodeId, | ||
TKikimrScopeId& scopeId, | ||
TString& tenantName, | ||
TBasicKikimrServicesMask& servicesMask, | ||
TMap<TString, TString>& labels, | ||
TString& clusterName, | ||
NKikimrConfig::TAppConfig& initialCmsConfig, | ||
NKikimrConfig::TAppConfig& initialCmsYamlConfig, | ||
THashMap<ui32, TConfigItemInfo>& configInitInfo) const = 0; | ||
}; | ||
|
||
std::unique_ptr<IConfigUpdateTracer> MakeDefaultConfigUpdateTracer(); | ||
std::unique_ptr<IProtoConfigFileProvider> MakeDefaultProtoConfigFileProvider(); | ||
std::unique_ptr<IEnv> MakeDefaultEnv(); | ||
std::unique_ptr<IErrorCollector> MakeDefaultErrorCollector(); | ||
std::unique_ptr<IMemLogInitializer> MakeDefaultMemLogInitializer(); | ||
std::unique_ptr<INodeBrokerClient> MakeDefaultNodeBrokerClient(); | ||
std::unique_ptr<IDynConfigClient> MakeDefaultDynConfigClient(); | ||
|
||
std::unique_ptr<IInitialConfigurator> MakeDefaultInitialConfigurator( | ||
NConfig::IErrorCollector& errorCollector, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. При добавлении нового провайдера неприкольно будет добавлять новый аргумент функции. Может сразу структуру передавать? |
||
NConfig::IProtoConfigFileProvider& protoConfigFileProvider, | ||
NConfig::IConfigUpdateTracer& configUpdateTracer, | ||
NConfig::IMemLogInitializer& memLogInit, | ||
NConfig::INodeBrokerClient& nodeBrokerClient, | ||
NConfig::IDynConfigClient& DynConfigClient, | ||
NConfig::IEnv& env); | ||
|
||
class TInitialConfigurator { | ||
public: | ||
TInitialConfigurator( | ||
NConfig::IErrorCollector& errorCollector, | ||
NConfig::IProtoConfigFileProvider& protoConfigFileProvider, | ||
NConfig::IConfigUpdateTracer& configUpdateTracer, | ||
NConfig::IMemLogInitializer& memLogInit, | ||
NConfig::INodeBrokerClient& nodeBrokerClient, | ||
NConfig::IDynConfigClient& dynConfigClient, | ||
NConfig::IEnv& env) | ||
: Impl(MakeDefaultInitialConfigurator( | ||
errorCollector, | ||
protoConfigFileProvider, | ||
configUpdateTracer, | ||
memLogInit, | ||
nodeBrokerClient, | ||
dynConfigClient, | ||
env)) | ||
{} | ||
|
||
void RegisterCliOptions(NLastGetopt::TOpts& opts) { | ||
Impl->RegisterCliOptions(opts); | ||
} | ||
|
||
void ValidateOptions(const NLastGetopt::TOpts& opts, const NLastGetopt::TOptsParseResult& parseResult) { | ||
Impl->ValidateOptions(opts, parseResult); | ||
} | ||
|
||
void Parse(const TVector<TString>& freeArgs) { | ||
Impl->Parse(freeArgs); | ||
} | ||
|
||
void Apply( | ||
NKikimrConfig::TAppConfig& appConfig, | ||
ui32& nodeId, | ||
TKikimrScopeId& scopeId, | ||
TString& tenantName, | ||
TBasicKikimrServicesMask& servicesMask, | ||
TMap<TString, TString>& labels, | ||
TString& clusterName, | ||
NKikimrConfig::TAppConfig& initialCmsConfig, | ||
NKikimrConfig::TAppConfig& initialCmsYamlConfig, | ||
THashMap<ui32, TConfigItemInfo>& configInitInfo) const | ||
{ | ||
Impl->Apply( | ||
appConfig, | ||
nodeId, | ||
scopeId, | ||
tenantName, | ||
servicesMask, | ||
labels, | ||
clusterName, | ||
initialCmsConfig, | ||
initialCmsYamlConfig, | ||
configInitInfo); | ||
} | ||
|
||
private: | ||
std::unique_ptr<IInitialConfigurator> Impl; | ||
}; | ||
|
||
} // namespace NKikimr::NConfig |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Если написать
= default;
, то оно ещё и смотреться будет единообразно с= 0;
:)