aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormihanix-it <mihanix-it@yandex-team.ru>2022-02-10 16:52:21 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:52:21 +0300
commit57d878af942e78206675efc83be53348b9834168 (patch)
treeab7fbbf3253d4c0e2793218f09378908beb025fb
parent63b1c9b4f595ab94506ad595b112afd161d3811e (diff)
downloadydb-57d878af942e78206675efc83be53348b9834168.tar.gz
Restoring authorship annotation for <mihanix-it@yandex-team.ru>. Commit 2 of 2.
-rw-r--r--ydb/core/cms/console/log_settings_configurator.cpp112
-rw-r--r--ydb/core/cms/console/log_settings_configurator.h4
-rw-r--r--ydb/core/cms/console/validators/validator_nameservice.cpp4
-rw-r--r--ydb/core/cms/console/validators/validator_nameservice_ut.cpp12
-rw-r--r--ydb/core/driver_lib/cli_utils/cli_cmds_server.cpp178
-rw-r--r--ydb/core/driver_lib/run/config.h4
-rw-r--r--ydb/core/driver_lib/run/kikimr_services_initializers.cpp14
-rw-r--r--ydb/core/driver_lib/run/kikimr_services_initializers.h2
-rw-r--r--ydb/public/sdk/python/examples/basic_example_v1/basic_example.py14
-rw-r--r--ydb/public/sdk/python/examples/basic_example_v1/basic_example_data.py10
-rw-r--r--ydb/public/sdk/python/examples/reservations-bot-demo/cloud_function/config.py42
-rw-r--r--ydb/public/sdk/python/examples/reservations-bot-demo/cloud_function/controller.py76
-rw-r--r--ydb/public/sdk/python/examples/reservations-bot-demo/cloud_function/models.py74
-rw-r--r--ydb/public/sdk/python/examples/reservations-bot-demo/cloud_function/requirements.txt30
-rw-r--r--ydb/public/sdk/python/examples/reservations-bot-demo/cloud_function/storage.py176
-rw-r--r--ydb/public/sdk/python/examples/reservations-bot-demo/cloud_function/utils.py46
-rw-r--r--ydb/public/sdk/python/examples/reservations-bot-demo/readme.md96
-rw-r--r--ydb/public/sdk/python/examples/reservations-bot-demo/voximplant/scenario.js280
-rw-r--r--ydb/public/sdk/python/examples/reservations-bot-demo/ydb/ddl.yql38
-rw-r--r--ydb/public/sdk/python/examples/reservations-bot-demo/ydb/dml.yql10
-rw-r--r--ydb/public/sdk/python/ydb/_session_impl.py20
-rw-r--r--ydb/public/sdk/python/ydb/table.py42
-rw-r--r--ydb/public/sdk/python/ydb/types.py50
-rw-r--r--ydb/tests/functional/api/test_public_api.py100
-rw-r--r--ydb/tests/functional/cms_config_cache/main.py156
-rw-r--r--ydb/tests/functional/cms_config_cache/ya.make42
-rw-r--r--ydb/tests/library/harness/kikimr_cluster.py2
-rw-r--r--ydb/tests/library/harness/kikimr_runner.py20
-rw-r--r--ydb/tests/library/harness/param_constants.py2
29 files changed, 828 insertions, 828 deletions
diff --git a/ydb/core/cms/console/log_settings_configurator.cpp b/ydb/core/cms/console/log_settings_configurator.cpp
index 16c45fa99bd..11d41e245e4 100644
--- a/ydb/core/cms/console/log_settings_configurator.cpp
+++ b/ydb/core/cms/console/log_settings_configurator.cpp
@@ -3,9 +3,9 @@
#include "log_settings_configurator.h"
#include <library/cpp/actors/core/actor_bootstrapped.h>
-#include <util/system/file.h>
-#include <util/system/fs.h>
-#include <util/stream/file.h>
+#include <util/system/file.h>
+#include <util/system/fs.h>
+#include <util/stream/file.h>
#include <google/protobuf/text_format.h>
namespace NKikimr {
@@ -19,11 +19,11 @@ public:
}
TLogSettingsConfigurator();
- TLogSettingsConfigurator(const TString &pathToConfigCacheFile);
+ TLogSettingsConfigurator(const TString &pathToConfigCacheFile);
+
+ void SaveLogSettingsConfigToCache(const NKikimrConfig::TLogConfig &logConfig,
+ const TActorContext &ctx);
- void SaveLogSettingsConfigToCache(const NKikimrConfig::TLogConfig &logConfig,
- const TActorContext &ctx);
-
void Bootstrap(const TActorContext &ctx);
void Handle(TEvConsole::TEvConfigNotificationRequest::TPtr &ev,
@@ -48,19 +48,19 @@ public:
break;
}
}
-private:
- TString PathToConfigCacheFile;
+private:
+ TString PathToConfigCacheFile;
};
TLogSettingsConfigurator::TLogSettingsConfigurator()
{
}
-TLogSettingsConfigurator::TLogSettingsConfigurator(const TString &pathToConfigCacheFile)
-{
- PathToConfigCacheFile = pathToConfigCacheFile;
-}
-
+TLogSettingsConfigurator::TLogSettingsConfigurator(const TString &pathToConfigCacheFile)
+{
+ PathToConfigCacheFile = pathToConfigCacheFile;
+}
+
void TLogSettingsConfigurator::Bootstrap(const TActorContext &ctx)
{
LOG_DEBUG_S(ctx, NKikimrServices::CMS_CONFIGS,
@@ -85,14 +85,14 @@ void TLogSettingsConfigurator::Handle(TEvConsole::TEvConfigNotificationRequest::
"TLogSettingsConfigurator: got new config: "
<< rec.GetConfig().ShortDebugString());
- const auto& logConfig = rec.GetConfig().GetLogConfig();
+ const auto& logConfig = rec.GetConfig().GetLogConfig();
+
+ ApplyLogConfig(logConfig, ctx);
+
+ // Save config to cache file
+ if (PathToConfigCacheFile)
+ SaveLogSettingsConfigToCache(logConfig, ctx);
- ApplyLogConfig(logConfig, ctx);
-
- // Save config to cache file
- if (PathToConfigCacheFile)
- SaveLogSettingsConfigToCache(logConfig, ctx);
-
auto resp = MakeHolder<TEvConsole::TEvConfigNotificationResponse>(rec);
LOG_TRACE_S(ctx, NKikimrServices::CMS_CONFIGS,
@@ -102,36 +102,36 @@ void TLogSettingsConfigurator::Handle(TEvConsole::TEvConfigNotificationRequest::
ctx.Send(ev->Sender, resp.Release(), 0, ev->Cookie);
}
-void TLogSettingsConfigurator::SaveLogSettingsConfigToCache(const NKikimrConfig::TLogConfig &logConfig,
- const TActorContext &ctx) {
- try {
- NKikimrConfig::TAppConfig appConfig;
- TFileInput cacheFile(PathToConfigCacheFile);
-
- if (!google::protobuf::TextFormat::ParseFromString(cacheFile.ReadAll(), &appConfig))
- ythrow yexception() << "Failed to parse config from cache file " << LastSystemError() << " " << LastSystemErrorText();
-
- appConfig.MutableLogConfig()->CopyFrom(logConfig);
-
- TString proto;
- const TString pathToTempFile = PathToConfigCacheFile + ".tmp";
-
- if (!google::protobuf::TextFormat::PrintToString(appConfig, &proto))
- ythrow yexception() << "Failed to print app config to string " << LastSystemError() << " " << LastSystemErrorText();
-
- TFileOutput tempFile(pathToTempFile);
- tempFile << proto;
-
- if (!NFs::Rename(pathToTempFile, PathToConfigCacheFile))
- ythrow yexception() << "Failed to rename temporary file " << LastSystemError() << " " << LastSystemErrorText();
-
- } catch (const yexception& ex) {
- LOG_ERROR_S(ctx, NKikimrServices::CMS_CONFIGS,
- "TLogSettingsConfigurator: failed to save log settings config to cache file '"
- << ex.what() << "'");
- }
-}
-
+void TLogSettingsConfigurator::SaveLogSettingsConfigToCache(const NKikimrConfig::TLogConfig &logConfig,
+ const TActorContext &ctx) {
+ try {
+ NKikimrConfig::TAppConfig appConfig;
+ TFileInput cacheFile(PathToConfigCacheFile);
+
+ if (!google::protobuf::TextFormat::ParseFromString(cacheFile.ReadAll(), &appConfig))
+ ythrow yexception() << "Failed to parse config from cache file " << LastSystemError() << " " << LastSystemErrorText();
+
+ appConfig.MutableLogConfig()->CopyFrom(logConfig);
+
+ TString proto;
+ const TString pathToTempFile = PathToConfigCacheFile + ".tmp";
+
+ if (!google::protobuf::TextFormat::PrintToString(appConfig, &proto))
+ ythrow yexception() << "Failed to print app config to string " << LastSystemError() << " " << LastSystemErrorText();
+
+ TFileOutput tempFile(pathToTempFile);
+ tempFile << proto;
+
+ if (!NFs::Rename(pathToTempFile, PathToConfigCacheFile))
+ ythrow yexception() << "Failed to rename temporary file " << LastSystemError() << " " << LastSystemErrorText();
+
+ } catch (const yexception& ex) {
+ LOG_ERROR_S(ctx, NKikimrServices::CMS_CONFIGS,
+ "TLogSettingsConfigurator: failed to save log settings config to cache file '"
+ << ex.what() << "'");
+ }
+}
+
void TLogSettingsConfigurator::ApplyLogConfig(const NKikimrConfig::TLogConfig &config,
const TActorContext &ctx)
{
@@ -212,10 +212,10 @@ IActor *CreateLogSettingsConfigurator()
return new TLogSettingsConfigurator();
}
-IActor *CreateLogSettingsConfigurator(const TString &pathToConfigCacheFile)
-{
- return new TLogSettingsConfigurator(pathToConfigCacheFile);
-}
-
+IActor *CreateLogSettingsConfigurator(const TString &pathToConfigCacheFile)
+{
+ return new TLogSettingsConfigurator(pathToConfigCacheFile);
+}
+
} // namespace NConsole
} // namespace NKikimr
diff --git a/ydb/core/cms/console/log_settings_configurator.h b/ydb/core/cms/console/log_settings_configurator.h
index 47ce2520278..e46a92d5650 100644
--- a/ydb/core/cms/console/log_settings_configurator.h
+++ b/ydb/core/cms/console/log_settings_configurator.h
@@ -10,7 +10,7 @@ namespace NConsole {
*/
IActor *CreateLogSettingsConfigurator();
-IActor *CreateLogSettingsConfigurator(const TString &pathToConfigCacheFile);
-
+IActor *CreateLogSettingsConfigurator(const TString &pathToConfigCacheFile);
+
} // namespace NConsole
} // namespace NKikimr
diff --git a/ydb/core/cms/console/validators/validator_nameservice.cpp b/ydb/core/cms/console/validators/validator_nameservice.cpp
index 830a3387919..0867be38132 100644
--- a/ydb/core/cms/console/validators/validator_nameservice.cpp
+++ b/ydb/core/cms/console/validators/validator_nameservice.cpp
@@ -67,8 +67,8 @@ bool TNameserviceConfigValidator::CheckConfig(const NKikimrConfig::TAppConfig &o
}
auto addrPort = std::make_pair(addr, port);
- // do not validate for duplicates if addr is empty
- if (addr && addrMap.contains(addrPort)) {
+ // do not validate for duplicates if addr is empty
+ if (addr && addrMap.contains(addrPort)) {
AddError(issues,
TStringBuilder() << "duplicating " << addr << ":" << port
<< " for nodes " << addrMap.at(addrPort) << " and " << id);
diff --git a/ydb/core/cms/console/validators/validator_nameservice_ut.cpp b/ydb/core/cms/console/validators/validator_nameservice_ut.cpp
index 29c5a703467..939e3fe7f34 100644
--- a/ydb/core/cms/console/validators/validator_nameservice_ut.cpp
+++ b/ydb/core/cms/console/validators/validator_nameservice_ut.cpp
@@ -148,18 +148,18 @@ Y_UNIT_TEST_SUITE(NameserviceConfigValidatorTests) {
RemoveNode(2, oldCfg);
CheckConfig(oldCfg, newCfg, true);
}
-
- Y_UNIT_TEST(TestEmptyAddresses) {
- NKikimrConfig::TStaticNameserviceConfig oldCfg = MakeDefaultNameserviceConfig();
- NKikimrConfig::TStaticNameserviceConfig newCfg = MakeDefaultNameserviceConfig();
+
+ Y_UNIT_TEST(TestEmptyAddresses) {
+ NKikimrConfig::TStaticNameserviceConfig oldCfg = MakeDefaultNameserviceConfig();
+ NKikimrConfig::TStaticNameserviceConfig newCfg = MakeDefaultNameserviceConfig();
AddNode(5, "host1", 102, "rhost3", "", "dc1", newCfg);
AddNode(6, "host6", 19001, "rhost6", "", "dc1", newCfg);
AddNode(7, "host7", 19001, "rhost7", "", "dc1", newCfg);
- CheckConfig(oldCfg, newCfg, true);
+ CheckConfig(oldCfg, newCfg, true);
NKikimrConfig::TStaticNameserviceConfig midCfg = newCfg;
AddNode(8, "host8", 19001, "rhost8", "", "dc1", newCfg);
CheckConfig(midCfg, newCfg, true);
- }
+ }
}
} // namespace NConsole
diff --git a/ydb/core/driver_lib/cli_utils/cli_cmds_server.cpp b/ydb/core/driver_lib/cli_utils/cli_cmds_server.cpp
index 36653bdfc75..6766dd31719 100644
--- a/ydb/core/driver_lib/cli_utils/cli_cmds_server.cpp
+++ b/ydb/core/driver_lib/cli_utils/cli_cmds_server.cpp
@@ -6,10 +6,10 @@
#include <ydb/library/yaml_config/yaml_config_parser.h>
#include <ydb/public/lib/deprecated/kicli/kicli.h>
#include <util/digest/city.h>
-#include <util/random/random.h>
+#include <util/random/random.h>
#include <util/string/cast.h>
-#include <util/system/file.h>
-#include <util/system/fs.h>
+#include <util/system/file.h>
+#include <util/system/fs.h>
#include <util/system/hostname.h>
#include <google/protobuf/text_format.h>
@@ -244,8 +244,8 @@ protected:
config.Opts->AddLongOption("body", "body name (used to describe dynamic node location)")
.RequiredArgument("NUM").StoreResult(&Body);
config.Opts->AddLongOption("yaml-config", "Yaml config").OptionalArgument("PATH").AppendTo(&YamlConfigFiles);
- config.Opts->AddLongOption("cms-config-cache-file", "Path to CMS cache config file").OptionalArgument("PATH")
- .StoreResult(&RunConfig.PathToConfigCacheFile);
+ config.Opts->AddLongOption("cms-config-cache-file", "Path to CMS cache config file").OptionalArgument("PATH")
+ .StoreResult(&RunConfig.PathToConfigCacheFile);
config.Opts->AddHelpOption('h');
// add messagebus proxy options
@@ -816,29 +816,29 @@ protected:
return "";
}
- bool GetCachedConfig(NKikimrConfig::TAppConfig &appConfig) {
+ bool GetCachedConfig(NKikimrConfig::TAppConfig &appConfig) {
Y_VERIFY_DEBUG(RunConfig.PathToConfigCacheFile, "GetCachedConfig called with a cms config cache file set");
- try {
- auto cacheFile = TFileInput(RunConfig.PathToConfigCacheFile);
- if (!google::protobuf::TextFormat::ParseFromString(cacheFile.ReadAll(), &appConfig))
- ythrow yexception() << "Failed to parse config protobuf from string";
- return true;
- } catch (const yexception &ex) {
- Cerr << "WARNING: an exception occurred while getting config from cache file: " << ex.what() << Endl;
- }
- return false;
- }
-
- void LoadCachedConfigsForStaticNode() {
- NKikimrConfig::TAppConfig appConfig;
-
- // log config
- if (GetCachedConfig(appConfig) && appConfig.HasLogConfig()) {
- AppConfig.MutableLogConfig()->CopyFrom(appConfig.GetLogConfig());
- }
- }
-
+ try {
+ auto cacheFile = TFileInput(RunConfig.PathToConfigCacheFile);
+ if (!google::protobuf::TextFormat::ParseFromString(cacheFile.ReadAll(), &appConfig))
+ ythrow yexception() << "Failed to parse config protobuf from string";
+ return true;
+ } catch (const yexception &ex) {
+ Cerr << "WARNING: an exception occurred while getting config from cache file: " << ex.what() << Endl;
+ }
+ return false;
+ }
+
+ void LoadCachedConfigsForStaticNode() {
+ NKikimrConfig::TAppConfig appConfig;
+
+ // log config
+ if (GetCachedConfig(appConfig) && appConfig.HasLogConfig()) {
+ AppConfig.MutableLogConfig()->CopyFrom(appConfig.GetLogConfig());
+ }
+ }
+
void MaybeRegisterAndLoadConfigs()
{
// static node
@@ -847,13 +847,13 @@ protected:
ythrow yexception() << "Either --node [NUM|'static'] or --node-broker[-port] should be specified";
if (!HierarchicalCfg && RunConfig.PathToConfigCacheFile)
- LoadCachedConfigsForStaticNode();
+ LoadCachedConfigsForStaticNode();
return;
}
RegisterDynamicNode();
if (!HierarchicalCfg && !IgnoreCmsConfigs)
- LoadConfigForDynamicNode();
+ LoadConfigForDynamicNode();
}
THolder<NClient::TRegistrationResult> TryToRegisterDynamicNode(
@@ -981,42 +981,42 @@ protected:
}
}
- void ApplyConfigForNode(NKikimrConfig::TAppConfig &appConfig) {
- AppConfig.Swap(&appConfig);
- // Dynamic node config is defined by options and Node Broker response.
- AppConfig.MutableDynamicNodeConfig()->Swap(appConfig.MutableDynamicNodeConfig());
- // By now naming config should be loaded and probably replaced with
- // info from registration response. Don't lose it in case CMS has no
- // config for naming service.
- if (!AppConfig.HasNameserviceConfig())
- AppConfig.MutableNameserviceConfig()->Swap(appConfig.MutableNameserviceConfig());
- }
-
- bool SaveConfigForNodeToCache(const NKikimrConfig::TAppConfig &appConfig) {
+ void ApplyConfigForNode(NKikimrConfig::TAppConfig &appConfig) {
+ AppConfig.Swap(&appConfig);
+ // Dynamic node config is defined by options and Node Broker response.
+ AppConfig.MutableDynamicNodeConfig()->Swap(appConfig.MutableDynamicNodeConfig());
+ // By now naming config should be loaded and probably replaced with
+ // info from registration response. Don't lose it in case CMS has no
+ // config for naming service.
+ if (!AppConfig.HasNameserviceConfig())
+ AppConfig.MutableNameserviceConfig()->Swap(appConfig.MutableNameserviceConfig());
+ }
+
+ bool SaveConfigForNodeToCache(const NKikimrConfig::TAppConfig &appConfig) {
Y_VERIFY_DEBUG(RunConfig.PathToConfigCacheFile, "SaveConfigForNodeToCache called without a cms config cache file set");
- // Ensure "atomicity" by writing to temp file and renaming it
- const TString pathToTempFile = RunConfig.PathToConfigCacheFile + ".tmp";
- TString proto;
- bool status;
- try {
- TFileOutput tempFile(pathToTempFile);
- status = google::protobuf::TextFormat::PrintToString(appConfig, &proto);
- if (status) {
- tempFile << proto;
- if (!NFs::Rename(pathToTempFile, RunConfig.PathToConfigCacheFile)) {
- ythrow yexception() << "Failed to rename temporary file " << LastSystemError() << " " << LastSystemErrorText();
- }
- }
- } catch (const yexception& ex) {
- Cerr << "WARNING: an exception occured while saving config to cache file: " << ex.what() << Endl;
- status = false;
- }
-
- return status;
- }
-
- bool TryToLoadConfigForDynamicNodeFromCMS(const TString &addr, TString &error) {
+ // Ensure "atomicity" by writing to temp file and renaming it
+ const TString pathToTempFile = RunConfig.PathToConfigCacheFile + ".tmp";
+ TString proto;
+ bool status;
+ try {
+ TFileOutput tempFile(pathToTempFile);
+ status = google::protobuf::TextFormat::PrintToString(appConfig, &proto);
+ if (status) {
+ tempFile << proto;
+ if (!NFs::Rename(pathToTempFile, RunConfig.PathToConfigCacheFile)) {
+ ythrow yexception() << "Failed to rename temporary file " << LastSystemError() << " " << LastSystemErrorText();
+ }
+ }
+ } catch (const yexception& ex) {
+ Cerr << "WARNING: an exception occured while saving config to cache file: " << ex.what() << Endl;
+ status = false;
+ }
+
+ return status;
+ }
+
+ bool TryToLoadConfigForDynamicNodeFromCMS(const TString &addr, TString &error) {
NClient::TKikimr kikimr(GetKikimr(addr));
auto configurator = kikimr.GetNodeConfigurator();
@@ -1045,53 +1045,53 @@ protected:
Cout << "Failed to save config to cache file" << Endl;
}
}
-
- ApplyConfigForNode(appConfig);
-
+
+ ApplyConfigForNode(appConfig);
+
return true;
}
- bool LoadConfigForDynamicNodeFromCache() {
- NKikimrConfig::TAppConfig config;
- if (GetCachedConfig(config)) {
- ApplyConfigForNode(config);
- return true;
- }
- return false;
- }
-
- void LoadConfigForDynamicNode() {
+ bool LoadConfigForDynamicNodeFromCache() {
+ NKikimrConfig::TAppConfig config;
+ if (GetCachedConfig(config)) {
+ ApplyConfigForNode(config);
+ return true;
+ }
+ return false;
+ }
+
+ void LoadConfigForDynamicNode() {
auto res = false;
TString error;
TVector<TString> addrs;
FillClusterEndpoints(addrs);
- SetRandomSeed(TInstant::Now().MicroSeconds());
+ SetRandomSeed(TInstant::Now().MicroSeconds());
int minAttempts = 10;
int attempts = 0;
while (!res && attempts < minAttempts) {
for (auto addr : addrs) {
- res = TryToLoadConfigForDynamicNodeFromCMS(addr, error);
+ res = TryToLoadConfigForDynamicNodeFromCMS(addr, error);
++attempts;
if (res)
break;
}
- // Randomized backoff
+ // Randomized backoff
if (!res)
- Sleep(TDuration::MilliSeconds(500 + RandomNumber<ui64>(1000)));
+ Sleep(TDuration::MilliSeconds(500 + RandomNumber<ui64>(1000)));
}
- if (!res) {
- Cerr << "WARNING: couldn't load config from CMS: " << error << Endl;
- if (RunConfig.PathToConfigCacheFile) {
- Cout << "Loading config from cache file " << RunConfig.PathToConfigCacheFile << Endl;
- if (!LoadConfigForDynamicNodeFromCache())
- Cerr << "WARNING: couldn't load config from cache file" << Endl;
- } else {
- Cerr << "WARNING: option --cms-config-cache-file was not set, ";
- Cerr << "couldn't load config from cache file" << Endl;
- }
+ if (!res) {
+ Cerr << "WARNING: couldn't load config from CMS: " << error << Endl;
+ if (RunConfig.PathToConfigCacheFile) {
+ Cout << "Loading config from cache file " << RunConfig.PathToConfigCacheFile << Endl;
+ if (!LoadConfigForDynamicNodeFromCache())
+ Cerr << "WARNING: couldn't load config from cache file" << Endl;
+ } else {
+ Cerr << "WARNING: option --cms-config-cache-file was not set, ";
+ Cerr << "couldn't load config from cache file" << Endl;
+ }
}
}
diff --git a/ydb/core/driver_lib/run/config.h b/ydb/core/driver_lib/run/config.h
index 60f998dffae..faf1797413e 100644
--- a/ydb/core/driver_lib/run/config.h
+++ b/ydb/core/driver_lib/run/config.h
@@ -89,8 +89,8 @@ struct TKikimrRunConfig {
ui32 NodeId;
TKikimrScopeId ScopeId;
- TString PathToConfigCacheFile;
-
+ TString PathToConfigCacheFile;
+
TKikimrRunConfig(NKikimrConfig::TAppConfig& appConfig,
ui32 nodeId = 0, const TKikimrScopeId& scopeId = {});
};
diff --git a/ydb/core/driver_lib/run/kikimr_services_initializers.cpp b/ydb/core/driver_lib/run/kikimr_services_initializers.cpp
index f810cc10db7..819c1478d19 100644
--- a/ydb/core/driver_lib/run/kikimr_services_initializers.cpp
+++ b/ydb/core/driver_lib/run/kikimr_services_initializers.cpp
@@ -1021,7 +1021,7 @@ TLoggerInitializer::TLoggerInitializer(const TKikimrRunConfig& runConfig,
: IKikimrServicesInitializer(runConfig)
, LogSettings(logSettings)
, LogBackend(logBackend)
- , PathToConfigCacheFile(runConfig.PathToConfigCacheFile)
+ , PathToConfigCacheFile(runConfig.PathToConfigCacheFile)
{
}
@@ -1036,13 +1036,13 @@ void TLoggerInitializer::InitializeServices(
std::pair<NActors::TActorId, NActors::TActorSetupCmd> loggerActorPair(LogSettings->LoggerActorId, loggerActorCmd);
setup->LocalServices.push_back(loggerActorPair);
- IActor *configurator;
+ IActor *configurator;
if (PathToConfigCacheFile && !appData->FeatureFlags.GetEnableConfigurationCache()) {
- configurator = NConsole::CreateLogSettingsConfigurator(PathToConfigCacheFile);
- } else {
- configurator = NConsole::CreateLogSettingsConfigurator();
- }
-
+ configurator = NConsole::CreateLogSettingsConfigurator(PathToConfigCacheFile);
+ } else {
+ configurator = NConsole::CreateLogSettingsConfigurator();
+ }
+
setup->LocalServices.emplace_back(TActorId(),
TActorSetupCmd(configurator, TMailboxType::HTSwap, appData->UserPoolId));
}
diff --git a/ydb/core/driver_lib/run/kikimr_services_initializers.h b/ydb/core/driver_lib/run/kikimr_services_initializers.h
index ad270add635..407ce1bb7ba 100644
--- a/ydb/core/driver_lib/run/kikimr_services_initializers.h
+++ b/ydb/core/driver_lib/run/kikimr_services_initializers.h
@@ -101,7 +101,7 @@ public:
class TLoggerInitializer : public IKikimrServicesInitializer {
TIntrusivePtr<NActors::NLog::TSettings> LogSettings;
std::shared_ptr<TLogBackend> LogBackend;
- TString PathToConfigCacheFile;
+ TString PathToConfigCacheFile;
public:
TLoggerInitializer(const TKikimrRunConfig& runConfig,
diff --git a/ydb/public/sdk/python/examples/basic_example_v1/basic_example.py b/ydb/public/sdk/python/examples/basic_example_v1/basic_example.py
index a9a47c7887c..5845a18a2e0 100644
--- a/ydb/public/sdk/python/examples/basic_example_v1/basic_example.py
+++ b/ydb/public/sdk/python/examples/basic_example_v1/basic_example.py
@@ -266,8 +266,8 @@ def describe_table(pool, path, name):
return pool.retry_operation_sync(callee)
-def bulk_upsert(table_client, path):
- print("\n> bulk upsert: episodes")
+def bulk_upsert(table_client, path):
+ print("\n> bulk upsert: episodes")
column_types = (
ydb.BulkUpsertColumns()
.add_column("series_id", ydb.OptionalType(ydb.PrimitiveType.Uint64))
@@ -276,10 +276,10 @@ def bulk_upsert(table_client, path):
.add_column("title", ydb.OptionalType(ydb.PrimitiveType.Utf8))
.add_column("air_date", ydb.OptionalType(ydb.PrimitiveType.Uint64))
)
- rows = basic_example_data.get_episodes_data_for_bulk_upsert()
- table_client.bulk_upsert(os.path.join(path, "episodes"), rows, column_types)
-
-
+ rows = basic_example_data.get_episodes_data_for_bulk_upsert()
+ table_client.bulk_upsert(os.path.join(path, "episodes"), rows, column_types)
+
+
def is_directory_exists(driver, path):
try:
return driver.scheme_client.describe_path(path).is_directory()
@@ -321,7 +321,7 @@ def run(endpoint, database, path):
select_simple(pool, full_path)
upsert_simple(pool, full_path)
-
+
bulk_upsert(driver.table_client, full_path)
select_prepared(pool, full_path, 2, 3, 7)
diff --git a/ydb/public/sdk/python/examples/basic_example_v1/basic_example_data.py b/ydb/public/sdk/python/examples/basic_example_v1/basic_example_data.py
index ea7f2674ccd..967c78ead72 100644
--- a/ydb/public/sdk/python/examples/basic_example_v1/basic_example_data.py
+++ b/ydb/public/sdk/python/examples/basic_example_v1/basic_example_data.py
@@ -98,11 +98,11 @@ def get_episodes_data():
Episode(1, 4, 4, "Italian For Beginners", "2010-07-16"),
Episode(1, 4, 5, "Bad Boys", "2010-07-23"),
Episode(1, 4, 6, "Reynholm vs Reynholm", "2010-07-30"),
- ]
-
-
-def get_episodes_data_for_bulk_upsert():
- return [
+ ]
+
+
+def get_episodes_data_for_bulk_upsert():
+ return [
Episode(2, 1, 1, "Minimum Viable Product", "2014-04-06"),
Episode(2, 1, 2, "The Cap Table", "2014-04-13"),
Episode(2, 1, 3, "Articles of Incorporation", "2014-04-20"),
diff --git a/ydb/public/sdk/python/examples/reservations-bot-demo/cloud_function/config.py b/ydb/public/sdk/python/examples/reservations-bot-demo/cloud_function/config.py
index 67e193132ed..7c4cbd558a1 100644
--- a/ydb/public/sdk/python/examples/reservations-bot-demo/cloud_function/config.py
+++ b/ydb/public/sdk/python/examples/reservations-bot-demo/cloud_function/config.py
@@ -1,25 +1,25 @@
-import os
-
-
-class Config(object):
+import os
+
+
+class Config(object):
_ydb_endpoint = os.getenv("YDB_ENDPOINT")
_ydb_database = os.getenv("YDB_DATABASE")
_ydb_path = os.getenv("YDB_PATH", "")
-
+
_reservation_period_minutes = int(os.getenv("RESERVATION_PERIOD_MINUTES", "60"))
-
- @classmethod
- def ydb_endpoint(cls):
- return cls._ydb_endpoint
-
- @classmethod
- def ydb_database(cls):
- return cls._ydb_database
-
- @classmethod
- def ydb_path(cls):
- return cls._ydb_path
-
- @classmethod
- def reservation_period_minutes(cls):
- return cls._reservation_period_minutes
+
+ @classmethod
+ def ydb_endpoint(cls):
+ return cls._ydb_endpoint
+
+ @classmethod
+ def ydb_database(cls):
+ return cls._ydb_database
+
+ @classmethod
+ def ydb_path(cls):
+ return cls._ydb_path
+
+ @classmethod
+ def reservation_period_minutes(cls):
+ return cls._reservation_period_minutes
diff --git a/ydb/public/sdk/python/examples/reservations-bot-demo/cloud_function/controller.py b/ydb/public/sdk/python/examples/reservations-bot-demo/cloud_function/controller.py
index 0b9934a30b2..31d2ba68149 100644
--- a/ydb/public/sdk/python/examples/reservations-bot-demo/cloud_function/controller.py
+++ b/ydb/public/sdk/python/examples/reservations-bot-demo/cloud_function/controller.py
@@ -1,62 +1,62 @@
-import typing
-import logging
-from storage import Storage
-from models import (
- ReservationCreateResponse,
- ReservationCreateRequest,
- ReservationCancelRequest,
- ReservationCancelResponse,
-)
-
-
-class Controller(object):
-
+import typing
+import logging
+from storage import Storage
+from models import (
+ ReservationCreateResponse,
+ ReservationCreateRequest,
+ ReservationCancelRequest,
+ ReservationCancelResponse,
+)
+
+
+class Controller(object):
+
__slots__ = ("_storage",)
-
- def __init__(self, storage: Storage):
- self._storage = storage
-
- def _find_available_table_id(
- self, request: ReservationCreateRequest
- ) -> typing.Optional[int]:
- table_ids = set(self._storage.list_table_ids(cnt=request.cnt))
+
+ def __init__(self, storage: Storage):
+ self._storage = storage
+
+ def _find_available_table_id(
+ self, request: ReservationCreateRequest
+ ) -> typing.Optional[int]:
+ table_ids = set(self._storage.list_table_ids(cnt=request.cnt))
reserved_table_ids = set(
self._storage.find_reserved_table_ids(cnt=request.cnt, dt=request.dt)
)
- for table_id in table_ids.difference(reserved_table_ids):
- return table_id
-
+ for table_id in table_ids.difference(reserved_table_ids):
+ return table_id
+
def maybe_create_reservation(
self, request: ReservationCreateRequest
) -> ReservationCreateResponse:
- table_id = self._find_available_table_id(request)
- if table_id is None:
+ table_id = self._find_available_table_id(request)
+ if table_id is None:
logging.warning("reservation failed")
- return ReservationCreateResponse(success=False)
- try:
- self._storage.save_reservation(
+ return ReservationCreateResponse(success=False)
+ try:
+ self._storage.save_reservation(
dt=request.dt,
table_id=table_id,
cnt=request.cnt,
description=request.description,
phone=request.phone,
- )
+ )
logging.warning(f"reservation {request.phone} {request.dt} succeeded")
return ReservationCreateResponse(success=True, table_id=table_id)
- except Exception as e:
+ except Exception as e:
logging.warning(f"failed to reserve a table due to {repr(e)}")
- return ReservationCreateResponse(success=False)
-
+ return ReservationCreateResponse(success=False)
+
def maybe_cancel_reservation(
self, request: ReservationCancelRequest
) -> ReservationCancelResponse:
- try:
- self._storage.delete_reservation(phone=request.phone, dt=request.dt)
+ try:
+ self._storage.delete_reservation(phone=request.phone, dt=request.dt)
logging.warning(f"reservation {request.phone} {request.dt} cancelled")
- return ReservationCancelResponse(success=True)
- except Exception as e:
+ return ReservationCancelResponse(success=True)
+ except Exception as e:
logging.warning(
f"failed to cancel reservation for {request.phone} "
f"{request.dt} due to {repr(e)}"
)
- return ReservationCancelResponse(success=False)
+ return ReservationCancelResponse(success=False)
diff --git a/ydb/public/sdk/python/examples/reservations-bot-demo/cloud_function/models.py b/ydb/public/sdk/python/examples/reservations-bot-demo/cloud_function/models.py
index 498cb8fba81..bce3622a810 100644
--- a/ydb/public/sdk/python/examples/reservations-bot-demo/cloud_function/models.py
+++ b/ydb/public/sdk/python/examples/reservations-bot-demo/cloud_function/models.py
@@ -1,37 +1,37 @@
-import typing
-import datetime
-from pydantic import BaseModel
-
-
-class Reservation(BaseModel):
- phone: typing.Optional[typing.Union[str, str]] = None
- description: typing.Optional[typing.Union[bytes, str]] = None
- table_id: int
- dt: datetime.datetime
-
-
-class Table(BaseModel):
- table_id: int = None
- description: typing.Optional[typing.Union[bytes, str]] = None
- cnt: int
-
-
-class ReservationCreateRequest(BaseModel):
- dt: datetime.datetime
- cnt: int
- description: typing.Optional[typing.Union[bytes, str]] = None
- phone: typing.Optional[typing.Union[bytes, str]]
-
-
-class ReservationCreateResponse(BaseModel):
- success: bool
- table_id: typing.Optional[int] = None
-
-
-class ReservationCancelRequest(BaseModel):
- phone: typing.Optional[typing.Union[bytes, str]]
- dt: datetime.datetime
-
-
-class ReservationCancelResponse(BaseModel):
- success: bool
+import typing
+import datetime
+from pydantic import BaseModel
+
+
+class Reservation(BaseModel):
+ phone: typing.Optional[typing.Union[str, str]] = None
+ description: typing.Optional[typing.Union[bytes, str]] = None
+ table_id: int
+ dt: datetime.datetime
+
+
+class Table(BaseModel):
+ table_id: int = None
+ description: typing.Optional[typing.Union[bytes, str]] = None
+ cnt: int
+
+
+class ReservationCreateRequest(BaseModel):
+ dt: datetime.datetime
+ cnt: int
+ description: typing.Optional[typing.Union[bytes, str]] = None
+ phone: typing.Optional[typing.Union[bytes, str]]
+
+
+class ReservationCreateResponse(BaseModel):
+ success: bool
+ table_id: typing.Optional[int] = None
+
+
+class ReservationCancelRequest(BaseModel):
+ phone: typing.Optional[typing.Union[bytes, str]]
+ dt: datetime.datetime
+
+
+class ReservationCancelResponse(BaseModel):
+ success: bool
diff --git a/ydb/public/sdk/python/examples/reservations-bot-demo/cloud_function/requirements.txt b/ydb/public/sdk/python/examples/reservations-bot-demo/cloud_function/requirements.txt
index 483f98615e9..8a4d06a346e 100644
--- a/ydb/public/sdk/python/examples/reservations-bot-demo/cloud_function/requirements.txt
+++ b/ydb/public/sdk/python/examples/reservations-bot-demo/cloud_function/requirements.txt
@@ -1,18 +1,18 @@
-certifi==2020.6.20
-cffi==1.14.2
-chardet==3.0.4
+certifi==2020.6.20
+cffi==1.14.2
+chardet==3.0.4
cryptography==3.3.2
-enum-compat==0.0.3
-googleapis-common-protos==1.52.0
-grpcio==1.31.0
-idna==2.10
-protobuf==3.13.0
-pycparser==2.20
+enum-compat==0.0.3
+googleapis-common-protos==1.52.0
+grpcio==1.31.0
+idna==2.10
+protobuf==3.13.0
+pycparser==2.20
pydantic==1.6.2
-PyJWT==1.7.1
-requests==2.24.0
-six==1.15.0
+PyJWT==1.7.1
+requests==2.24.0
+six==1.15.0
urllib3==1.26.5
-yandexcloud==0.48.0
-ydb==0.0.41
-
+yandexcloud==0.48.0
+ydb==0.0.41
+
diff --git a/ydb/public/sdk/python/examples/reservations-bot-demo/cloud_function/storage.py b/ydb/public/sdk/python/examples/reservations-bot-demo/cloud_function/storage.py
index b8427d13030..a8806899f4f 100644
--- a/ydb/public/sdk/python/examples/reservations-bot-demo/cloud_function/storage.py
+++ b/ydb/public/sdk/python/examples/reservations-bot-demo/cloud_function/storage.py
@@ -1,64 +1,64 @@
-import datetime
-import typing
+import datetime
+import typing
import ydb
-from utils import session_pool_context, make_driver_config
-from config import Config
-
-
-class Storage(object):
- def __init__(self, *, endpoint: str, database: str, path: str):
- self._database = database
- self._driver_config = make_driver_config(endpoint, database, path)
-
- def list_table_ids(self, *, cnt: int = 0) -> typing.List[int]:
- query = f"""PRAGMA TablePathPrefix("{self._database}");
- DECLARE $cnt as Uint64;
- SELECT table_id FROM tables WHERE cnt >= $cnt;
- """
-
- def transaction(session):
- tx = session.transaction(ydb.SerializableReadWrite()).begin()
- prepared_query = session.prepare(query)
+from utils import session_pool_context, make_driver_config
+from config import Config
+
+
+class Storage(object):
+ def __init__(self, *, endpoint: str, database: str, path: str):
+ self._database = database
+ self._driver_config = make_driver_config(endpoint, database, path)
+
+ def list_table_ids(self, *, cnt: int = 0) -> typing.List[int]:
+ query = f"""PRAGMA TablePathPrefix("{self._database}");
+ DECLARE $cnt as Uint64;
+ SELECT table_id FROM tables WHERE cnt >= $cnt;
+ """
+
+ def transaction(session):
+ tx = session.transaction(ydb.SerializableReadWrite()).begin()
+ prepared_query = session.prepare(query)
rs = tx.execute(prepared_query, parameters={"$cnt": cnt}, commit_tx=True)
- return rs[0].rows
-
- with session_pool_context(self._driver_config) as session_pool:
- tables = session_pool.retry_operation_sync(transaction)
+ return rs[0].rows
+
+ with session_pool_context(self._driver_config) as session_pool:
+ tables = session_pool.retry_operation_sync(transaction)
return list(map(lambda x: getattr(x, "table_id"), tables))
-
+
def find_reserved_table_ids(
self, *, cnt: int, dt: datetime.datetime
) -> typing.List[int]:
- query = f"""PRAGMA TablePathPrefix("{self._database}");
- DECLARE $dt AS DateTime;
- DECLARE $reservation_period_minutes AS Int32;
- DECLARE $cnt AS Uint64;
- SELECT DISTINCT(table_id) FROM reservations
- WHERE dt <= $dt
- AND dt >= $dt - DateTime::IntervalFromMinutes($reservation_period_minutes)
- AND cnt >= $cnt;
- """
-
- def transaction(session):
- tx = session.transaction(ydb.SerializableReadWrite()).begin()
- prepared_query = session.prepare(query)
- rs = tx.execute(
- prepared_query,
- parameters={
+ query = f"""PRAGMA TablePathPrefix("{self._database}");
+ DECLARE $dt AS DateTime;
+ DECLARE $reservation_period_minutes AS Int32;
+ DECLARE $cnt AS Uint64;
+ SELECT DISTINCT(table_id) FROM reservations
+ WHERE dt <= $dt
+ AND dt >= $dt - DateTime::IntervalFromMinutes($reservation_period_minutes)
+ AND cnt >= $cnt;
+ """
+
+ def transaction(session):
+ tx = session.transaction(ydb.SerializableReadWrite()).begin()
+ prepared_query = session.prepare(query)
+ rs = tx.execute(
+ prepared_query,
+ parameters={
"$cnt": cnt,
"$dt": int(dt.timestamp()),
"$reservation_period_minutes": Config.reservation_period_minutes(),
- },
+ },
commit_tx=True,
- )
- if len(rs[0].rows) > 0:
- return rs[0].rows
- return []
-
- with session_pool_context(self._driver_config) as session_pool:
- tables = session_pool.retry_operation_sync(transaction)
+ )
+ if len(rs[0].rows) > 0:
+ return rs[0].rows
+ return []
+
+ with session_pool_context(self._driver_config) as session_pool:
+ tables = session_pool.retry_operation_sync(transaction)
return list(map(lambda x: getattr(x, "table_id"), tables))
-
+
def save_reservation(
self,
*,
@@ -68,49 +68,49 @@ class Storage(object):
description: str = "",
phone: str,
) -> None:
- query = f"""PRAGMA TablePathPrefix("{self._database}");
- DECLARE $dt AS DateTime;
- DECLARE $cnt AS Uint64;
- DECLARE $phone AS String;
- DECLARE $description AS Utf8;
- DECLARE $table_id AS Uint64;
- INSERT INTO reservations (table_id, dt, phone, cnt, description)
- VALUES ($table_id, $dt, $phone, $cnt, $description);
- """
-
- def transaction(session):
- tx = session.transaction(ydb.SerializableReadWrite()).begin()
- prepared_query = session.prepare(query)
- tx.execute(
- prepared_query,
- parameters={
+ query = f"""PRAGMA TablePathPrefix("{self._database}");
+ DECLARE $dt AS DateTime;
+ DECLARE $cnt AS Uint64;
+ DECLARE $phone AS String;
+ DECLARE $description AS Utf8;
+ DECLARE $table_id AS Uint64;
+ INSERT INTO reservations (table_id, dt, phone, cnt, description)
+ VALUES ($table_id, $dt, $phone, $cnt, $description);
+ """
+
+ def transaction(session):
+ tx = session.transaction(ydb.SerializableReadWrite()).begin()
+ prepared_query = session.prepare(query)
+ tx.execute(
+ prepared_query,
+ parameters={
"$dt": int(dt.timestamp()),
"$cnt": cnt,
"$table_id": table_id,
"$description": "" if description is None else description,
"$phone": phone.encode(),
- },
+ },
commit_tx=True,
- )
-
- with session_pool_context(self._driver_config) as session_pool:
- session_pool.retry_operation_sync(transaction)
-
- def delete_reservation(self, *, phone: str, dt: datetime.datetime) -> None:
- query = f"""PRAGMA TablePathPrefix("{self._database}");
- DECLARE $dt AS DateTime;
- DECLARE $phone AS String;
- DELETE FROM reservations WHERE dt = $dt AND phone = $phone;
- """
-
- def transaction(session):
- tx = session.transaction(ydb.SerializableReadWrite()).begin()
- prepared_query = session.prepare(query)
- tx.execute(
- prepared_query,
+ )
+
+ with session_pool_context(self._driver_config) as session_pool:
+ session_pool.retry_operation_sync(transaction)
+
+ def delete_reservation(self, *, phone: str, dt: datetime.datetime) -> None:
+ query = f"""PRAGMA TablePathPrefix("{self._database}");
+ DECLARE $dt AS DateTime;
+ DECLARE $phone AS String;
+ DELETE FROM reservations WHERE dt = $dt AND phone = $phone;
+ """
+
+ def transaction(session):
+ tx = session.transaction(ydb.SerializableReadWrite()).begin()
+ prepared_query = session.prepare(query)
+ tx.execute(
+ prepared_query,
parameters={"$dt": dt, "$phone": phone.encode()},
commit_tx=True,
- )
-
- with session_pool_context(self._driver_config) as session_pool:
- session_pool.retry_operation_sync(transaction)
+ )
+
+ with session_pool_context(self._driver_config) as session_pool:
+ session_pool.retry_operation_sync(transaction)
diff --git a/ydb/public/sdk/python/examples/reservations-bot-demo/cloud_function/utils.py b/ydb/public/sdk/python/examples/reservations-bot-demo/cloud_function/utils.py
index 5e442a1a851..52aa56f9f70 100644
--- a/ydb/public/sdk/python/examples/reservations-bot-demo/cloud_function/utils.py
+++ b/ydb/public/sdk/python/examples/reservations-bot-demo/cloud_function/utils.py
@@ -1,35 +1,35 @@
-import logging
-import contextlib
+import logging
+import contextlib
import ydb
-
-
-def make_driver_config(endpoint, database, path):
- return ydb.DriverConfig(
+
+
+def make_driver_config(endpoint, database, path):
+ return ydb.DriverConfig(
endpoint,
database,
credentials=ydb.construct_credentials_from_environ(),
- root_certificates=ydb.load_ydb_root_certificate(),
- )
-
-
-@contextlib.contextmanager
-def session_pool_context(
+ root_certificates=ydb.load_ydb_root_certificate(),
+ )
+
+
+@contextlib.contextmanager
+def session_pool_context(
driver_config: ydb.DriverConfig, size=1, workers_threads_count=1
-):
- with ydb.Driver(driver_config) as driver:
- try:
- logging.info("connecting to the database")
- driver.wait(timeout=15)
- except TimeoutError:
+):
+ with ydb.Driver(driver_config) as driver:
+ try:
+ logging.info("connecting to the database")
+ driver.wait(timeout=15)
+ except TimeoutError:
logging.critical(
f"connection failed\n"
f"last reported errors by discovery: {driver.discovery_debug_details()}"
)
- raise
+ raise
with ydb.SessionPool(
driver, size=size, workers_threads_count=workers_threads_count
) as session_pool:
- try:
- yield session_pool
- except Exception as e:
- logging.critical(f"failed to create session pool due to {repr(e)}")
+ try:
+ yield session_pool
+ except Exception as e:
+ logging.critical(f"failed to create session pool due to {repr(e)}")
diff --git a/ydb/public/sdk/python/examples/reservations-bot-demo/readme.md b/ydb/public/sdk/python/examples/reservations-bot-demo/readme.md
index 3b8885c47d4..9b0fdfd7c15 100644
--- a/ydb/public/sdk/python/examples/reservations-bot-demo/readme.md
+++ b/ydb/public/sdk/python/examples/reservations-bot-demo/readme.md
@@ -1,48 +1,48 @@
-# Voximplant + YDB Reservations Bot Demo
-
-## Что это?
-
-Это голосовой чат-бот, реализованный в партнерстве с облаком Voximplant.
-- В качестве стораджа используется Yandex Database
-- Системная логика реализована на Yandex Functions
-- Телефония в Voximplant
-- Распознавание речи и построение диалога в Google Dialogflow
-
-## Как развернуть
-
-### Yandex Cloud
-
-Сперва нужно создать сервисный аккаунт c правами`ydb.admin` и `serverless.function.invoker`, который будет использоваться облачной функцией.
-
-#### Yandex Database
-
-Нужно создать базу YDB и убедиться, что у нее доступен белый ip адрес.
-
-Завести необходимые таблицы можно в UI облака скриптом `ydb/ddl.sql`, а залить начальные данные можно с помощью `ydb/dml.sql`.
-
-#### Yandex Function
-
-Функцию создаем с сервисным аккаунтом, созданным ранее.
-
-В `./cloud_function` лежат файлы, которые необходимо загрузить в UI функции.
-
-В той же директории лежит `./cloud_function/config.py` в котором описаны ENV-перменные.
-
-А для секретов есть папка `./cloud_function/secrets`, в которую необходимо положить json сервисного аккаунта и SSL-сертификаты. Они нужны для доступа к YDB. Подробнее про получение доступа к YDB можно почитать в [примере запуска тестового приложения на YDB](https://cloud.yandex.ru/docs/ydb/quickstart/launch-test-app).
-
-#### Google Dialogflow
-
-Необходимо создать учетную запись в Google Cloud и импортровать `./dialogflow/agent.zip`.
-
-Сохраните сервисный аккаунт Google Cloud для следующего шага.
-
-#### Voximplant
-
-- Создаем аккаунт на voximplant
-- Создаем приложение
-- Добавляем сценарий, куда вписываем `./voximplant/scenario.js`
-- Покупаем телефонный номер (можно недорого купить тестовый)
-- Создаем правило роутинга, в которое прикрепляем сценарий и номер
-
-Более подробно все описано в статье ["ИИ продает пиццу"](https://habr.com/ru/company/Voximplant/blog/412663/)
-
+# Voximplant + YDB Reservations Bot Demo
+
+## Что это?
+
+Это голосовой чат-бот, реализованный в партнерстве с облаком Voximplant.
+- В качестве стораджа используется Yandex Database
+- Системная логика реализована на Yandex Functions
+- Телефония в Voximplant
+- Распознавание речи и построение диалога в Google Dialogflow
+
+## Как развернуть
+
+### Yandex Cloud
+
+Сперва нужно создать сервисный аккаунт c правами`ydb.admin` и `serverless.function.invoker`, который будет использоваться облачной функцией.
+
+#### Yandex Database
+
+Нужно создать базу YDB и убедиться, что у нее доступен белый ip адрес.
+
+Завести необходимые таблицы можно в UI облака скриптом `ydb/ddl.sql`, а залить начальные данные можно с помощью `ydb/dml.sql`.
+
+#### Yandex Function
+
+Функцию создаем с сервисным аккаунтом, созданным ранее.
+
+В `./cloud_function` лежат файлы, которые необходимо загрузить в UI функции.
+
+В той же директории лежит `./cloud_function/config.py` в котором описаны ENV-перменные.
+
+А для секретов есть папка `./cloud_function/secrets`, в которую необходимо положить json сервисного аккаунта и SSL-сертификаты. Они нужны для доступа к YDB. Подробнее про получение доступа к YDB можно почитать в [примере запуска тестового приложения на YDB](https://cloud.yandex.ru/docs/ydb/quickstart/launch-test-app).
+
+#### Google Dialogflow
+
+Необходимо создать учетную запись в Google Cloud и импортровать `./dialogflow/agent.zip`.
+
+Сохраните сервисный аккаунт Google Cloud для следующего шага.
+
+#### Voximplant
+
+- Создаем аккаунт на voximplant
+- Создаем приложение
+- Добавляем сценарий, куда вписываем `./voximplant/scenario.js`
+- Покупаем телефонный номер (можно недорого купить тестовый)
+- Создаем правило роутинга, в которое прикрепляем сценарий и номер
+
+Более подробно все описано в статье ["ИИ продает пиццу"](https://habr.com/ru/company/Voximplant/blog/412663/)
+
diff --git a/ydb/public/sdk/python/examples/reservations-bot-demo/voximplant/scenario.js b/ydb/public/sdk/python/examples/reservations-bot-demo/voximplant/scenario.js
index b9e9117158e..179a2cd4e09 100644
--- a/ydb/public/sdk/python/examples/reservations-bot-demo/voximplant/scenario.js
+++ b/ydb/public/sdk/python/examples/reservations-bot-demo/voximplant/scenario.js
@@ -1,140 +1,140 @@
-require(Modules.AI);
-require(Modules.ASR);
-require(Modules.Player);
-
-let mycall = null,
- voice = Language.Premium.RU_RUSSIAN_YA_FEMALE,
- account_name = "",
- dialed_number = "",
- caller_id = "",
- flow,
- lastText = '',
- player
-
-VoxEngine.addEventListener(AppEvents.CallAlerting, (e) => {
-
- mycall = e.call;
- mycall.addEventListener(CallEvents.Connected, handleCallConnected);
-
- account_name = e.toURI.substring(e.toURI.indexOf('.') + 1);
- account_name = account_name.substring(0, account_name.indexOf('.'));
- dialed_number = e.destination;
- caller_id = e.callerid;
-
- mycall.answer();
-
-});
-
-function startASR() {
- mycall.removeEventListener(CallEvents.PlaybackFinished, startASR);
- mycall.sendMediaTo(flow);
-}
-
-
-// TODO: separate into different functions,
-// state machine instead of nested if statements
-function handleCallConnected(e) {
-
-
- flow = AI.createDialogflow({
- lang: "ru"
- });
-
- if (AI.Events.DialogflowResponse !== undefined)
- flow.addEventListener(AI.Events.DialogflowResponse, (event) => {
- if (event.response.queryResult !== undefined) {
- let result = event.response.queryResult
-
- if (result.queryText === undefined) {
- if (result.languageCode !== undefined) startASR();
- return
- }
-
-
- if (result.fulfillmentText !== undefined || result.allRequiredParamsPresent == true) {
- try {
- player = VoxEngine.createTTSPlayer(result.fulfillmentText, voice)
- player.addMarker(-500)
- player.addEventListener(PlayerEvents.PlaybackMarkerReached, startASR)
- player.sendMediaTo(mycall)
- } catch (err) {
-
- }
-
- Logger.write(result.allRequiredParamsPresent);
-
- if (result.allRequiredParamsPresent == true) {
- let msg = "";
- let base_url = 'https://functions.yandexcloud.net/d4erurocvcpt8dc20mfb';
- base_url += '?dt=' + result.parameters['date'].toString().split("T")[0];
- base_url += 'T' + result.parameters['time'].toString().split("T")[1];
- base_url += '&phone=' + caller_id;
- Logger.write(base_url);
- if (result.intent['displayName'] === 'restaurants.reservations.cancel') {
- base_url += '&action=cancel';
- } else {
- base_url += '&action=create';
- base_url += '&cnt=' + result.parameters['number'].toString();
- }
- Net.httpRequest(base_url,
- (result) => {
- if (result.code != 200) {
- Logger.write("Failed");
- Logger.write("code: " + result.code);
- Logger.write("data: " + result.data);
- Logger.write("error: " + result.error);
- Logger.write("headers: " + JSON.stringify(result.headers));
- Logger.write("raw_headers: " + result.raw_headers);
- Logger.write("text: " + result.text);
- msg += " К сожалению не нашлось подходящих столиков. Простите! ";
- } else {
- Logger.write('OK');
- Logger.write("data: " + result.data);
- Logger.write("text: " + result.text);
- Logger.write("result: " + result.result);
- msg += " Хорошо, спасибо. Бронирование привязано к вашему номеру телефона. ";
-
- }
- Logger.write('msg' + msg)
- player.stop()
- player = VoxEngine.createTTSPlayer(msg, voice)
- player.addEventListener(PlayerEvents.PlaybackFinished, () => mycall.hangup())
- player.sendMediaTo(e.call)
- },
- Net.HttpRequestOptions({
- method: 'GET',
- }
- )
- )
-
- player.stop()
- player = VoxEngine.createTTSPlayer(msg, voice)
- player.addMarker(-500)
- player.addEventListener(PlayerEvents.PlaybackMarkerReached, startASR)
- player.sendMediaTo(e.call)
-
- } else {
-
- player.stop()
- lastText = result.fulfillmentText
- player = VoxEngine.createTTSPlayer(result.fulfillmentText, voice)
- player.addMarker(-500)
- player.addEventListener(PlayerEvents.PlaybackMarkerReached, startASR)
- player.sendMediaTo(e.call)
-
- }
- }
- }
- })
-
- player = VoxEngine.createTTSPlayer(" Здравствуйте! Это ресторан Облачко. Желаете забронировать столик? ", voice);
- player.addMarker(-500);
- player.addEventListener(PlayerEvents.PlaybackMarkerReached, startASR);
- player.sendMediaTo(e.call);
-
- mycall.record();
- mycall.addEventListener(CallEvents.Disconnected, (event) => {
- VoxEngine.terminate();
- })
-}
-
+require(Modules.AI);
+require(Modules.ASR);
+require(Modules.Player);
+
+let mycall = null,
+ voice = Language.Premium.RU_RUSSIAN_YA_FEMALE,
+ account_name = "",
+ dialed_number = "",
+ caller_id = "",
+ flow,
+ lastText = '',
+ player
+
+VoxEngine.addEventListener(AppEvents.CallAlerting, (e) => {
+
+ mycall = e.call;
+ mycall.addEventListener(CallEvents.Connected, handleCallConnected);
+
+ account_name = e.toURI.substring(e.toURI.indexOf('.') + 1);
+ account_name = account_name.substring(0, account_name.indexOf('.'));
+ dialed_number = e.destination;
+ caller_id = e.callerid;
+
+ mycall.answer();
+
+});
+
+function startASR() {
+ mycall.removeEventListener(CallEvents.PlaybackFinished, startASR);
+ mycall.sendMediaTo(flow);
+}
+
+
+// TODO: separate into different functions,
+// state machine instead of nested if statements
+function handleCallConnected(e) {
+
+
+ flow = AI.createDialogflow({
+ lang: "ru"
+ });
+
+ if (AI.Events.DialogflowResponse !== undefined)
+ flow.addEventListener(AI.Events.DialogflowResponse, (event) => {
+ if (event.response.queryResult !== undefined) {
+ let result = event.response.queryResult
+
+ if (result.queryText === undefined) {
+ if (result.languageCode !== undefined) startASR();
+ return
+ }
+
+
+ if (result.fulfillmentText !== undefined || result.allRequiredParamsPresent == true) {
+ try {
+ player = VoxEngine.createTTSPlayer(result.fulfillmentText, voice)
+ player.addMarker(-500)
+ player.addEventListener(PlayerEvents.PlaybackMarkerReached, startASR)
+ player.sendMediaTo(mycall)
+ } catch (err) {
+
+ }
+
+ Logger.write(result.allRequiredParamsPresent);
+
+ if (result.allRequiredParamsPresent == true) {
+ let msg = "";
+ let base_url = 'https://functions.yandexcloud.net/d4erurocvcpt8dc20mfb';
+ base_url += '?dt=' + result.parameters['date'].toString().split("T")[0];
+ base_url += 'T' + result.parameters['time'].toString().split("T")[1];
+ base_url += '&phone=' + caller_id;
+ Logger.write(base_url);
+ if (result.intent['displayName'] === 'restaurants.reservations.cancel') {
+ base_url += '&action=cancel';
+ } else {
+ base_url += '&action=create';
+ base_url += '&cnt=' + result.parameters['number'].toString();
+ }
+ Net.httpRequest(base_url,
+ (result) => {
+ if (result.code != 200) {
+ Logger.write("Failed");
+ Logger.write("code: " + result.code);
+ Logger.write("data: " + result.data);
+ Logger.write("error: " + result.error);
+ Logger.write("headers: " + JSON.stringify(result.headers));
+ Logger.write("raw_headers: " + result.raw_headers);
+ Logger.write("text: " + result.text);
+ msg += " К сожалению не нашлось подходящих столиков. Простите! ";
+ } else {
+ Logger.write('OK');
+ Logger.write("data: " + result.data);
+ Logger.write("text: " + result.text);
+ Logger.write("result: " + result.result);
+ msg += " Хорошо, спасибо. Бронирование привязано к вашему номеру телефона. ";
+
+ }
+ Logger.write('msg' + msg)
+ player.stop()
+ player = VoxEngine.createTTSPlayer(msg, voice)
+ player.addEventListener(PlayerEvents.PlaybackFinished, () => mycall.hangup())
+ player.sendMediaTo(e.call)
+ },
+ Net.HttpRequestOptions({
+ method: 'GET',
+ }
+ )
+ )
+
+ player.stop()
+ player = VoxEngine.createTTSPlayer(msg, voice)
+ player.addMarker(-500)
+ player.addEventListener(PlayerEvents.PlaybackMarkerReached, startASR)
+ player.sendMediaTo(e.call)
+
+ } else {
+
+ player.stop()
+ lastText = result.fulfillmentText
+ player = VoxEngine.createTTSPlayer(result.fulfillmentText, voice)
+ player.addMarker(-500)
+ player.addEventListener(PlayerEvents.PlaybackMarkerReached, startASR)
+ player.sendMediaTo(e.call)
+
+ }
+ }
+ }
+ })
+
+ player = VoxEngine.createTTSPlayer(" Здравствуйте! Это ресторан Облачко. Желаете забронировать столик? ", voice);
+ player.addMarker(-500);
+ player.addEventListener(PlayerEvents.PlaybackMarkerReached, startASR);
+ player.sendMediaTo(e.call);
+
+ mycall.record();
+ mycall.addEventListener(CallEvents.Disconnected, (event) => {
+ VoxEngine.terminate();
+ })
+}
+
diff --git a/ydb/public/sdk/python/examples/reservations-bot-demo/ydb/ddl.yql b/ydb/public/sdk/python/examples/reservations-bot-demo/ydb/ddl.yql
index 5463318fdc5..c944febbf6c 100644
--- a/ydb/public/sdk/python/examples/reservations-bot-demo/ydb/ddl.yql
+++ b/ydb/public/sdk/python/examples/reservations-bot-demo/ydb/ddl.yql
@@ -1,20 +1,20 @@
CREATE TABLE tables
-(
- table_id Uint64,
- description Utf8,
- cnt Uint64,
- PRIMARY KEY (table_id)
-);
-
-CREATE TABLE reservations
-(
- phone String,
- description Utf8,
- table_id Uint64,
- cnt Uint64,
- dt DateTime,
- PRIMARY KEY (dt, phone)
-);
-
-COMMIT;
-
+(
+ table_id Uint64,
+ description Utf8,
+ cnt Uint64,
+ PRIMARY KEY (table_id)
+);
+
+CREATE TABLE reservations
+(
+ phone String,
+ description Utf8,
+ table_id Uint64,
+ cnt Uint64,
+ dt DateTime,
+ PRIMARY KEY (dt, phone)
+);
+
+COMMIT;
+
diff --git a/ydb/public/sdk/python/examples/reservations-bot-demo/ydb/dml.yql b/ydb/public/sdk/python/examples/reservations-bot-demo/ydb/dml.yql
index 7bdc9bcc998..d42a4509929 100644
--- a/ydb/public/sdk/python/examples/reservations-bot-demo/ydb/dml.yql
+++ b/ydb/public/sdk/python/examples/reservations-bot-demo/ydb/dml.yql
@@ -1,5 +1,5 @@
-INSERT INTO tables (table_id, description, cnt)
-VALUES (1, 'a', 10), (2, 'b', 1), (3, 'c', 5), (4, 'd', 2), (5, 'e', 3);
-
-COMMIT;
-
+INSERT INTO tables (table_id, description, cnt)
+VALUES (1, 'a', 10), (2, 'b', 1), (3, 'c', 5), (4, 'd', 2), (5, 'e', 3);
+
+COMMIT;
+
diff --git a/ydb/public/sdk/python/ydb/_session_impl.py b/ydb/public/sdk/python/ydb/_session_impl.py
index 198ab4f3ab6..e1906299ecd 100644
--- a/ydb/public/sdk/python/ydb/_session_impl.py
+++ b/ydb/public/sdk/python/ydb/_session_impl.py
@@ -246,10 +246,10 @@ def wrap_operation(rpc_state, response_pb, session_state, driver=None):
return operation.Operation(rpc_state, response_pb, driver)
-def wrap_operation_bulk_upsert(rpc_state, response_pb, driver=None):
- return operation.Operation(rpc_state, response_pb, driver)
-
-
+def wrap_operation_bulk_upsert(rpc_state, response_pb, driver=None):
+ return operation.Operation(rpc_state, response_pb, driver)
+
+
@bad_session_handler
def wrap_keep_alive_response(rpc_state, response_pb, session_state, session):
issues._process_response(response_pb.operation)
@@ -396,15 +396,15 @@ def read_table_request_factory(
return session_state.attach_request(request)
-def bulk_upsert_request_factory(table, rows, column_types):
- request = _apis.ydb_table.BulkUpsertRequest()
- request.table = table
+def bulk_upsert_request_factory(table, rows, column_types):
+ request = _apis.ydb_table.BulkUpsertRequest()
+ request.table = table
request.rows.MergeFrom(
convert.to_typed_value_from_native(types.ListType(column_types).proto, rows)
)
- return request
-
-
+ return request
+
+
def wrap_read_table_response(response):
issues._process_response(response)
return convert.ResultSet.from_message(response.result.result_set)
diff --git a/ydb/public/sdk/python/ydb/table.py b/ydb/public/sdk/python/ydb/table.py
index 78bf946335d..c49c4660c7c 100644
--- a/ydb/public/sdk/python/ydb/table.py
+++ b/ydb/public/sdk/python/ydb/table.py
@@ -211,15 +211,15 @@ class CompactionPolicy(object):
return self._pb
-class SplitPoint(object):
- def __init__(self, *args):
- self._value = tuple(args)
-
- @property
- def value(self):
- return self._value
-
-
+class SplitPoint(object):
+ def __init__(self, *args):
+ self._value = tuple(args)
+
+ @property
+ def value(self):
+ return self._value
+
+
class ExplicitPartitions(object):
def __init__(self, split_points):
self.split_points = split_points
@@ -1306,19 +1306,19 @@ class TableClient(BaseTableClient):
lambda resp: _wrap_scan_query_response(resp, self._table_client_settings),
)
- @_utilities.wrap_async_call_exceptions
- def async_bulk_upsert(self, table_path, rows, column_types, settings=None):
+ @_utilities.wrap_async_call_exceptions
+ def async_bulk_upsert(self, table_path, rows, column_types, settings=None):
# type: (str, list, ydb.AbstractTypeBuilder | ydb.PrimitiveType, ydb.BaseRequestSettings) -> None
- return self._driver.future(
- _session_impl.bulk_upsert_request_factory(table_path, rows, column_types),
- _apis.TableService.Stub,
- _apis.TableService.BulkUpsert,
- _session_impl.wrap_operation_bulk_upsert,
- settings,
- (),
- )
-
-
+ return self._driver.future(
+ _session_impl.bulk_upsert_request_factory(table_path, rows, column_types),
+ _apis.TableService.Stub,
+ _apis.TableService.BulkUpsert,
+ _session_impl.wrap_operation_bulk_upsert,
+ settings,
+ (),
+ )
+
+
def _make_index_description(index):
result = TableIndex(index.name).with_index_columns(
*tuple(col for col in index.index_columns)
diff --git a/ydb/public/sdk/python/ydb/types.py b/ydb/public/sdk/python/ydb/types.py
index 23bfa6e5534..6ae09a5b421 100644
--- a/ydb/public/sdk/python/ydb/types.py
+++ b/ydb/public/sdk/python/ydb/types.py
@@ -346,29 +346,29 @@ class StructType(AbstractTypeBuilder):
def __str__(self):
return "Struct<%s>" % ",".join(self.__members_repr)
-
-
-class BulkUpsertColumns(AbstractTypeBuilder):
+
+
+class BulkUpsertColumns(AbstractTypeBuilder):
__slots__ = ("__columns_repr", "__proto")
-
- def __init__(self):
- self.__columns_repr = []
- self.__proto = _apis.ydb_value.Type(struct_type=_apis.ydb_value.StructType())
-
- def add_column(self, name, column_type):
- """
- :param name: A column name
- :param column_type: A column type
- """
- self.__columns_repr.append("%s:%s" % (name, column_type))
- column = self.__proto.struct_type.members.add()
- column.name = name
- column.type.MergeFrom(column_type.proto)
- return self
-
- @property
- def proto(self):
- return self.__proto
-
- def __str__(self):
- return "BulkUpsertColumns<%s>" % ",".join(self.__columns_repr)
+
+ def __init__(self):
+ self.__columns_repr = []
+ self.__proto = _apis.ydb_value.Type(struct_type=_apis.ydb_value.StructType())
+
+ def add_column(self, name, column_type):
+ """
+ :param name: A column name
+ :param column_type: A column type
+ """
+ self.__columns_repr.append("%s:%s" % (name, column_type))
+ column = self.__proto.struct_type.members.add()
+ column.name = name
+ column.type.MergeFrom(column_type.proto)
+ return self
+
+ @property
+ def proto(self):
+ return self.__proto
+
+ def __str__(self):
+ return "BulkUpsertColumns<%s>" % ",".join(self.__columns_repr)
diff --git a/ydb/tests/functional/api/test_public_api.py b/ydb/tests/functional/api/test_public_api.py
index a0ff46da15f..072ee35de38 100644
--- a/ydb/tests/functional/api/test_public_api.py
+++ b/ydb/tests/functional/api/test_public_api.py
@@ -467,59 +467,59 @@ SELECT * FROM $InputSource;
)
)
- def test_bulk_upsert(self):
- session = ydb.retry_operation_sync(lambda: self.driver.table_client.session().create())
-
- session.execute_scheme(
+ def test_bulk_upsert(self):
+ session = ydb.retry_operation_sync(lambda: self.driver.table_client.session().create())
+
+ session.execute_scheme(
' create table `test_bulk_upsert` '
- ' (k Uint64, a Utf8, b Utf8, primary key(k)); '
- )
-
- class Rec(object):
- __slots__ = ('k', 'a', 'b')
-
- def __init__(self, k, a, b=None):
- self.k = k
- self.a = a
- self.b = b
-
- table_client = self.driver.table_client
- table_path = os.path.join(self.database_name, 'test_bulk_upsert')
- rows = [Rec(i, str(i), 'b') for i in range(10)]
- column_types = ydb.BulkUpsertColumns()\
- .add_column('k', ydb.PrimitiveType.Uint64)\
- .add_column('a', ydb.PrimitiveType.Utf8)\
- .add_column('b', ydb.PrimitiveType.Utf8)
- table_client.bulk_upsert(table_path, rows, column_types)
-
- result_sets = session.transaction().execute(
+ ' (k Uint64, a Utf8, b Utf8, primary key(k)); '
+ )
+
+ class Rec(object):
+ __slots__ = ('k', 'a', 'b')
+
+ def __init__(self, k, a, b=None):
+ self.k = k
+ self.a = a
+ self.b = b
+
+ table_client = self.driver.table_client
+ table_path = os.path.join(self.database_name, 'test_bulk_upsert')
+ rows = [Rec(i, str(i), 'b') for i in range(10)]
+ column_types = ydb.BulkUpsertColumns()\
+ .add_column('k', ydb.PrimitiveType.Uint64)\
+ .add_column('a', ydb.PrimitiveType.Utf8)\
+ .add_column('b', ydb.PrimitiveType.Utf8)
+ table_client.bulk_upsert(table_path, rows, column_types)
+
+ result_sets = session.transaction().execute(
'SELECT COUNT(*) as cnt FROM test_bulk_upsert;', commit_tx=True
- )
-
- assert_that(
- result_sets[0].rows[0].cnt, is_(
- 10
- )
- )
-
- # performing bulk upsert on 2 out of 3 columns
- column_types = ydb.BulkUpsertColumns()\
- .add_column('k', ydb.PrimitiveType.Uint64)\
- .add_column('a', ydb.PrimitiveType.Utf8)
- rows = [Rec(i, str(i)) for i in range(10)]
- table_client.bulk_upsert(table_path, rows, column_types)
-
- result_sets = session.transaction().execute(
+ )
+
+ assert_that(
+ result_sets[0].rows[0].cnt, is_(
+ 10
+ )
+ )
+
+ # performing bulk upsert on 2 out of 3 columns
+ column_types = ydb.BulkUpsertColumns()\
+ .add_column('k', ydb.PrimitiveType.Uint64)\
+ .add_column('a', ydb.PrimitiveType.Utf8)
+ rows = [Rec(i, str(i)) for i in range(10)]
+ table_client.bulk_upsert(table_path, rows, column_types)
+
+ result_sets = session.transaction().execute(
'SELECT * FROM test_bulk_upsert LIMIT 1;', commit_tx=True
- )
-
- # check that column b wasn't updated
- assert_that(
- result_sets[0].rows[0].b, is_(
- 'b'
- )
- )
-
+ )
+
+ # check that column b wasn't updated
+ assert_that(
+ result_sets[0].rows[0].b, is_(
+ 'b'
+ )
+ )
+
def test_all_enums_are_presented_as_exceptions(self):
status_ids = ydb_status_codes_pb2.StatusIds
for name, value in status_ids.StatusCode.items():
diff --git a/ydb/tests/functional/cms_config_cache/main.py b/ydb/tests/functional/cms_config_cache/main.py
index a496f6a71c4..8df6cd3ad2c 100644
--- a/ydb/tests/functional/cms_config_cache/main.py
+++ b/ydb/tests/functional/cms_config_cache/main.py
@@ -1,88 +1,88 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-import logging
-import os
-import time
-
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+import logging
+import os
+import time
+
from ydb.tests.library.harness.kikimr_cluster import kikimr_cluster_factory
from ydb.tests.library.harness.kikimr_config import KikimrConfigGenerator
-
-logger = logging.getLogger(__name__)
-
-
-class TestCmsConfigCacheMain(object):
-
- sample_log_config = """
-LogConfig {
- Entry {
- Component: "FLAT_TX_SCHEMESHARD"
- Level: 7
- }
- Entry {
- Component: "TENANT_SLOT_BROKER"
- Level: 7
- }
- Entry {
- Component: "TX_DATASHARD"
- Level: 5
- }
- Entry {
- Component: "LOCAL"
- Level: 7
- }
- Entry {
- Component: "TX_PROXY"
- Level: 5
- }
- Entry {
- Component: "HIVE"
- Level: 7
- }
- Entry {
- Component: "BS_CONTROLLER"
- Level: 7
- }
- SysLog: true
-}
-"""
-
- @classmethod
- def setup_class(cls):
+
+logger = logging.getLogger(__name__)
+
+
+class TestCmsConfigCacheMain(object):
+
+ sample_log_config = """
+LogConfig {
+ Entry {
+ Component: "FLAT_TX_SCHEMESHARD"
+ Level: 7
+ }
+ Entry {
+ Component: "TENANT_SLOT_BROKER"
+ Level: 7
+ }
+ Entry {
+ Component: "TX_DATASHARD"
+ Level: 5
+ }
+ Entry {
+ Component: "LOCAL"
+ Level: 7
+ }
+ Entry {
+ Component: "TX_PROXY"
+ Level: 5
+ }
+ Entry {
+ Component: "HIVE"
+ Level: 7
+ }
+ Entry {
+ Component: "BS_CONTROLLER"
+ Level: 7
+ }
+ SysLog: true
+}
+"""
+
+ @classmethod
+ def setup_class(cls):
configurator = KikimrConfigGenerator()
- cls.cluster = kikimr_cluster_factory(configurator=configurator)
- cls.cluster.start()
+ cls.cluster = kikimr_cluster_factory(configurator=configurator)
+ cls.cluster.start()
cls.cluster.create_database(
'/Root/database',
storage_pool_units_count={'hdd': 1}
)
cls.cluster.register_and_start_slots('/Root/database', count=1)
cls.cluster.wait_tenant_up('/Root/database')
-
- @classmethod
- def teardown_class(cls):
+
+ @classmethod
+ def teardown_class(cls):
cls.cluster.stop()
-
- def _cms_config_cache_file_path(self):
- slot = self.cluster.slots[1]
- path = os.path.join(slot.cwd, slot.cms_config_cache_file_name)
- return path
-
- def test_cache_log_settings(self):
- with open(self._cms_config_cache_file_path(), 'r') as file:
- assert 'LogConfig' not in file.read(), "initial node config should not contain LogConfig items"
- self.cluster.client.add_config_item(self.sample_log_config)
- timeout = 60
- step = 1
- cur = 0
- config_updated = False
- while not config_updated and cur < timeout:
- time.sleep(step)
- cur += step
- with open(self._cms_config_cache_file_path(), 'r') as file:
- config_updated = 'LogConfig' in file.read()
- assert config_updated, "log config wasn't updated"
-
- def test_cms_config_cache(self):
- with open(self._cms_config_cache_file_path(), 'r') as file:
- cfg = file.read()
- assert len(cfg) > 0
+
+ def _cms_config_cache_file_path(self):
+ slot = self.cluster.slots[1]
+ path = os.path.join(slot.cwd, slot.cms_config_cache_file_name)
+ return path
+
+ def test_cache_log_settings(self):
+ with open(self._cms_config_cache_file_path(), 'r') as file:
+ assert 'LogConfig' not in file.read(), "initial node config should not contain LogConfig items"
+ self.cluster.client.add_config_item(self.sample_log_config)
+ timeout = 60
+ step = 1
+ cur = 0
+ config_updated = False
+ while not config_updated and cur < timeout:
+ time.sleep(step)
+ cur += step
+ with open(self._cms_config_cache_file_path(), 'r') as file:
+ config_updated = 'LogConfig' in file.read()
+ assert config_updated, "log config wasn't updated"
+
+ def test_cms_config_cache(self):
+ with open(self._cms_config_cache_file_path(), 'r') as file:
+ cfg = file.read()
+ assert len(cfg) > 0
diff --git a/ydb/tests/functional/cms_config_cache/ya.make b/ydb/tests/functional/cms_config_cache/ya.make
index 3f871bf684f..d69aa6e12cc 100644
--- a/ydb/tests/functional/cms_config_cache/ya.make
+++ b/ydb/tests/functional/cms_config_cache/ya.make
@@ -1,26 +1,26 @@
-OWNER(g:kikimr)
-
+OWNER(g:kikimr)
+
PY3TEST()
ENV(YDB_DRIVER_BINARY="ydb/apps/ydbd/ydbd")
-TEST_SRCS(
- main.py
-)
-
-TIMEOUT(600)
-
-SIZE(MEDIUM)
-
-DEPENDS(
+TEST_SRCS(
+ main.py
+)
+
+TIMEOUT(600)
+
+SIZE(MEDIUM)
+
+DEPENDS(
ydb/apps/ydbd
-)
-
-PEERDIR(
+)
+
+PEERDIR(
ydb/tests/library
ydb/public/sdk/python/ydb
-)
-
-FORK_SUBTESTS()
-
-FORK_TEST_FILES()
-
-END()
+)
+
+FORK_SUBTESTS()
+
+FORK_TEST_FILES()
+
+END()
diff --git a/ydb/tests/library/harness/kikimr_cluster.py b/ydb/tests/library/harness/kikimr_cluster.py
index f726b05f8a5..942e1588ca4 100644
--- a/ydb/tests/library/harness/kikimr_cluster.py
+++ b/ydb/tests/library/harness/kikimr_cluster.py
@@ -135,7 +135,7 @@ class ExternalKiKiMRCluster(KiKiMRClusterInterface):
self._run_on(
self.nodes,
lambda x: x.ssh_command(
- "sudo ln -f /Berkanavt/kikimr/secrets/auth.txt /Berkanavt/kikimr/cfg/auth.txt"
+ "sudo ln -f /Berkanavt/kikimr/secrets/auth.txt /Berkanavt/kikimr/cfg/auth.txt"
)
)
diff --git a/ydb/tests/library/harness/kikimr_runner.py b/ydb/tests/library/harness/kikimr_runner.py
index 7230e9de3e5..251f485b5db 100644
--- a/ydb/tests/library/harness/kikimr_runner.py
+++ b/ydb/tests/library/harness/kikimr_runner.py
@@ -70,12 +70,12 @@ class KiKiMRNode(daemon.Daemon, kikimr_node_interface.NodeInterface):
self.__role = role
self.__node_broker_port = node_broker_port
self.__log_file = tempfile.NamedTemporaryFile(dir=self.cwd, prefix="logfile_", suffix=".log", delete=False)
- self.__cms_config_cache_file = tempfile.NamedTemporaryFile(
+ self.__cms_config_cache_file = tempfile.NamedTemporaryFile(
dir=self.cwd,
- prefix="cms_config_cache_",
- delete=False
- )
- self.__cms_config_cache_file_name = self.__cms_config_cache_file.name
+ prefix="cms_config_cache_",
+ delete=False
+ )
+ self.__cms_config_cache_file_name = self.__cms_config_cache_file.name
daemon.Daemon.__init__(self, self.command, cwd=self.cwd, timeout=180, stderr_on_error_lines=240)
@property
@@ -95,10 +95,10 @@ class KiKiMRNode(daemon.Daemon, kikimr_node_interface.NodeInterface):
return self.__cwd
@property
- def cms_config_cache_file_name(self):
- return self.__cms_config_cache_file_name
-
- @property
+ def cms_config_cache_file_name(self):
+ return self.__cms_config_cache_file_name
+
+ @property
def command(self):
return self.__make_run_command()
@@ -160,7 +160,7 @@ class KiKiMRNode(daemon.Daemon, kikimr_node_interface.NodeInterface):
if self.sqs_port is not None:
command.extend(["--sqs-port=%d" % self.sqs_port])
-
+
logger.info('CFG_DIR_PATH="%s"', self.__config_path)
logger.info("Final command: %s", ' '.join(command).replace(self.__config_path, '$CFG_DIR_PATH'))
return command
diff --git a/ydb/tests/library/harness/param_constants.py b/ydb/tests/library/harness/param_constants.py
index 972826e5291..c478696a589 100644
--- a/ydb/tests/library/harness/param_constants.py
+++ b/ydb/tests/library/harness/param_constants.py
@@ -17,7 +17,7 @@ kikimr_cluster_yaml_deploy_path = '/Berkanavt/kikimr/cfg/cluster.yaml'
blockstore_configs_deploy_path = '/Berkanavt/nbs-server/cfg'
kikimr_next_version_deploy_path = '/Berkanavt/kikimr/bin/kikimr_next'
kikimr_last_version_deploy_path = '/Berkanavt/kikimr/bin/kikimr_last'
-kikimr_home = '/Berkanavt/kikimr'
+kikimr_home = '/Berkanavt/kikimr'
def generate_configs_cmd(configs_type="", deploy_path=None):