mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 23:21:59 +00:00
implemented clickhouse --extract-from-config tool [#CLICKHOUSE-2876]
This commit is contained in:
parent
f19b82e4ea
commit
3f9eb5f0f9
@ -405,7 +405,7 @@ public:
|
||||
}
|
||||
|
||||
|
||||
int mainEntryClickhouseBenchmark(int argc, char ** argv)
|
||||
int mainEntryClickHouseBenchmark(int argc, char ** argv)
|
||||
{
|
||||
using namespace DB;
|
||||
bool print_stacktrace = true;
|
||||
|
@ -1352,7 +1352,7 @@ public:
|
||||
}
|
||||
|
||||
|
||||
int mainEntryClickhouseClient(int argc, char ** argv)
|
||||
int mainEntryClickHouseClient(int argc, char ** argv)
|
||||
{
|
||||
DB::Client client;
|
||||
|
||||
|
@ -13,8 +13,16 @@ target_link_libraries(clickhouse-server daemon storages_system)
|
||||
add_library(clickhouse-local LocalServer.cpp)
|
||||
target_link_libraries(clickhouse-local dbms)
|
||||
|
||||
add_library(clickhouse-extract-from-config ExtractFromConfig.cpp)
|
||||
target_link_libraries(clickhouse-extract-from-config dbms)
|
||||
|
||||
add_executable(clickhouse main.cpp)
|
||||
target_link_libraries(clickhouse clickhouse-server clickhouse-client clickhouse-local clickhouse-benchmark)
|
||||
target_link_libraries(clickhouse
|
||||
clickhouse-server
|
||||
clickhouse-client
|
||||
clickhouse-local
|
||||
clickhouse-benchmark
|
||||
clickhouse-extract-from-config)
|
||||
INSTALL(TARGETS clickhouse RUNTIME DESTINATION bin COMPONENT clickhouse)
|
||||
|
||||
# make symbolic links to concrete clickhouse applications
|
||||
|
77
dbms/src/Server/ExtractFromConfig.cpp
Normal file
77
dbms/src/Server/ExtractFromConfig.cpp
Normal file
@ -0,0 +1,77 @@
|
||||
#include <iostream>
|
||||
|
||||
#include <boost/program_options.hpp>
|
||||
#include <Poco/Util/XMLConfiguration.h>
|
||||
|
||||
#include <zkutil/ZooKeeperNodeCache.h>
|
||||
#include <DB/Common/ConfigProcessor.h>
|
||||
#include <DB/Common/Exception.h>
|
||||
|
||||
|
||||
static std::string extractFromConfig(
|
||||
const std::string & config_path, const std::string & key, bool process_zk_includes)
|
||||
{
|
||||
ConfigProcessor processor(/* throw_on_bad_incl = */ false, /* log_to_console = */ true);
|
||||
bool has_zk_includes;
|
||||
XMLDocumentPtr config_xml = processor.processConfig(config_path, &has_zk_includes);
|
||||
if (has_zk_includes && process_zk_includes)
|
||||
{
|
||||
ConfigurationPtr bootstrap_configuration(new Poco::Util::XMLConfiguration(config_xml));
|
||||
zkutil::ZooKeeperPtr zookeeper = std::make_shared<zkutil::ZooKeeper>(
|
||||
*bootstrap_configuration, "zookeeper");
|
||||
zkutil::ZooKeeperNodeCache zk_node_cache([&] { return zookeeper; });
|
||||
config_xml = processor.processConfig(config_path, &has_zk_includes, &zk_node_cache);
|
||||
}
|
||||
ConfigurationPtr configuration(new Poco::Util::XMLConfiguration(config_xml));
|
||||
return configuration->getString(key);
|
||||
}
|
||||
|
||||
int mainEntryClickHouseExtractFromConfig(int argc, char ** argv)
|
||||
{
|
||||
bool print_stacktrace = false;
|
||||
bool process_zk_includes = false;
|
||||
std::string config_path;
|
||||
std::string key;
|
||||
|
||||
namespace po = boost::program_options;
|
||||
|
||||
po::options_description options_desc("Allowed options");
|
||||
options_desc.add_options()
|
||||
("help", "produce this help message")
|
||||
("stacktrace", po::bool_switch(&print_stacktrace), "print stack traces of exceptions")
|
||||
("process-zk-includes", po::bool_switch(&process_zk_includes),
|
||||
"if there are from_zk elements in config, connect to ZooKeeper and process them")
|
||||
("config-file,c", po::value<std::string>(&config_path)->required(), "path to config file")
|
||||
("key,k", po::value<std::string>(&key)->required(), "key to get value for");
|
||||
|
||||
po::positional_options_description positional_desc;
|
||||
positional_desc.add("config-file", 1);
|
||||
positional_desc.add("key", 1);
|
||||
|
||||
try
|
||||
{
|
||||
po::variables_map options;
|
||||
po::store(po::command_line_parser(argc, argv).options(options_desc).positional(positional_desc).run(), options);
|
||||
|
||||
if (options.count("help"))
|
||||
{
|
||||
std::cerr << "Preprocess config file and extract value of the given key." << std::endl
|
||||
<< std::endl;
|
||||
std::cerr << "Usage: clickhouse --extract-from-config [options]" << std::endl
|
||||
<< std::endl;
|
||||
std::cerr << options_desc << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
po::notify(options);
|
||||
|
||||
std::cout << extractFromConfig(config_path, key, process_zk_includes) << std::endl;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
std::cerr << DB::getCurrentExceptionMessage(print_stacktrace, true) << std::endl;
|
||||
return DB::getCurrentExceptionCode();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@ -461,4 +461,4 @@ void LocalServer::setupUsers()
|
||||
|
||||
}
|
||||
|
||||
YANDEX_APP_MAIN_FUNC(DB::LocalServer, mainEntryClickhouseLocal);
|
||||
YANDEX_APP_MAIN_FUNC(DB::LocalServer, mainEntryClickHouseLocal);
|
||||
|
@ -8,9 +8,10 @@
|
||||
|
||||
/// Universal executable for various clickhouse applications
|
||||
int mainEntryClickHouseServer(int argc, char ** argv);
|
||||
int mainEntryClickhouseClient(int argc, char ** argv);
|
||||
int mainEntryClickhouseLocal(int argc, char ** argv);
|
||||
int mainEntryClickhouseBenchmark(int argc, char ** argv);
|
||||
int mainEntryClickHouseClient(int argc, char ** argv);
|
||||
int mainEntryClickHouseLocal(int argc, char ** argv);
|
||||
int mainEntryClickHouseBenchmark(int argc, char ** argv);
|
||||
int mainEntryClickHouseExtractFromConfig(int argc, char ** argv);
|
||||
|
||||
|
||||
static bool isClickhouseApp(const std::string & app_suffix, std::vector<char *> & argv)
|
||||
@ -46,13 +47,15 @@ int main(int argc_, char ** argv_)
|
||||
auto main_func = mainEntryClickHouseServer;
|
||||
|
||||
if (isClickhouseApp("local", argv))
|
||||
main_func = mainEntryClickhouseLocal;
|
||||
main_func = mainEntryClickHouseLocal;
|
||||
else if (isClickhouseApp("client", argv))
|
||||
main_func = mainEntryClickhouseClient;
|
||||
main_func = mainEntryClickHouseClient;
|
||||
else if (isClickhouseApp("benchmark", argv))
|
||||
main_func = mainEntryClickhouseBenchmark;
|
||||
main_func = mainEntryClickHouseBenchmark;
|
||||
else if (isClickhouseApp("server", argv)) /// --server arg should be cut
|
||||
main_func = mainEntryClickHouseServer;
|
||||
else if (isClickhouseApp("extract-from-config", argv))
|
||||
main_func = mainEntryClickHouseExtractFromConfig;
|
||||
|
||||
return main_func(static_cast<int>(argv.size()), argv.data());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user