2019-09-30 16:12:08 +00:00
|
|
|
#include <Interpreters/ExternalLoaderXMLConfigRepository.h>
|
|
|
|
|
2021-09-29 12:52:58 +00:00
|
|
|
#include <filesystem>
|
|
|
|
|
2019-09-30 16:12:08 +00:00
|
|
|
#include <Common/StringUtils/StringUtils.h>
|
|
|
|
#include <Common/Config/ConfigProcessor.h>
|
|
|
|
#include <Common/getMultipleKeysFromConfig.h>
|
|
|
|
#include <Poco/Glob.h>
|
2021-05-28 21:57:53 +00:00
|
|
|
#include <Common/filesystemHelpers.h>
|
2019-09-30 16:12:08 +00:00
|
|
|
|
2021-05-28 18:17:16 +00:00
|
|
|
|
2021-04-28 10:42:07 +00:00
|
|
|
namespace fs = std::filesystem;
|
2019-09-30 16:12:08 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
2021-09-29 12:52:58 +00:00
|
|
|
|
2019-12-30 23:30:06 +00:00
|
|
|
ExternalLoaderXMLConfigRepository::ExternalLoaderXMLConfigRepository(
|
2021-09-29 12:52:58 +00:00
|
|
|
const std::string & app_path_,
|
|
|
|
const std::string & main_config_path_,
|
|
|
|
const std::unordered_set<std::string> & patterns_)
|
|
|
|
: app_path(app_path_)
|
|
|
|
, main_config_path(main_config_path_)
|
|
|
|
, patterns(patterns_)
|
2019-12-30 23:30:06 +00:00
|
|
|
{
|
|
|
|
}
|
2019-09-30 16:12:08 +00:00
|
|
|
|
2019-10-01 08:58:47 +00:00
|
|
|
Poco::Timestamp ExternalLoaderXMLConfigRepository::getUpdateTime(const std::string & definition_entity_name)
|
2019-09-30 16:12:08 +00:00
|
|
|
{
|
2021-05-28 18:17:16 +00:00
|
|
|
return FS::getModificationTimestamp(definition_entity_name);
|
2019-09-30 16:12:08 +00:00
|
|
|
}
|
|
|
|
|
2019-12-30 23:30:06 +00:00
|
|
|
std::set<std::string> ExternalLoaderXMLConfigRepository::getAllLoadablesDefinitionNames()
|
2019-09-30 16:12:08 +00:00
|
|
|
{
|
2021-09-29 12:52:58 +00:00
|
|
|
std::unordered_set<std::string> patterns_copy;
|
2019-09-30 16:12:08 +00:00
|
|
|
|
2021-09-29 12:52:58 +00:00
|
|
|
{
|
|
|
|
std::lock_guard<std::mutex> lock(patterns_mutex);
|
|
|
|
patterns_copy = patterns;
|
|
|
|
}
|
2019-09-30 16:12:08 +00:00
|
|
|
|
2021-09-29 12:52:58 +00:00
|
|
|
const String config_dir = fs::path(main_config_path).parent_path();
|
|
|
|
std::set<std::string> files;
|
|
|
|
|
|
|
|
for (const auto & pattern : patterns_copy)
|
2019-09-30 16:12:08 +00:00
|
|
|
{
|
|
|
|
if (pattern.empty())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (pattern[0] != '/')
|
|
|
|
{
|
2021-05-14 07:06:38 +00:00
|
|
|
const String absolute_path = fs::path(config_dir) / pattern;
|
2021-09-29 12:52:58 +00:00
|
|
|
|
2019-09-30 16:12:08 +00:00
|
|
|
Poco::Glob::glob(absolute_path, files, 0);
|
|
|
|
if (!files.empty())
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
Poco::Glob::glob(pattern, files, 0);
|
|
|
|
}
|
|
|
|
|
2021-09-29 12:52:58 +00:00
|
|
|
for (auto it = files.begin(); it != files.end();)
|
2019-09-30 16:12:08 +00:00
|
|
|
{
|
|
|
|
if (ConfigProcessor::isPreprocessedFile(*it))
|
2021-09-29 12:52:58 +00:00
|
|
|
it = files.erase(it);
|
2019-09-30 16:12:08 +00:00
|
|
|
else
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
|
|
|
|
return files;
|
|
|
|
}
|
|
|
|
|
2021-09-29 12:52:58 +00:00
|
|
|
void ExternalLoaderXMLConfigRepository::updatePatterns(const std::unordered_set<std::string> & patterns_)
|
|
|
|
{
|
|
|
|
std::lock_guard<std::mutex> lock(patterns_mutex);
|
|
|
|
|
|
|
|
if (patterns == patterns_)
|
|
|
|
return;
|
|
|
|
|
|
|
|
patterns = patterns_;
|
|
|
|
}
|
|
|
|
|
2019-12-30 23:30:06 +00:00
|
|
|
bool ExternalLoaderXMLConfigRepository::exists(const std::string & definition_entity_name)
|
2019-09-30 16:12:08 +00:00
|
|
|
{
|
2021-04-28 10:42:07 +00:00
|
|
|
return fs::exists(fs::path(definition_entity_name));
|
2019-09-30 16:12:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Poco::AutoPtr<Poco::Util::AbstractConfiguration> ExternalLoaderXMLConfigRepository::load(
|
2019-12-30 23:30:06 +00:00
|
|
|
const std::string & config_file)
|
2019-09-30 16:12:08 +00:00
|
|
|
{
|
|
|
|
ConfigProcessor config_processor{config_file};
|
|
|
|
ConfigProcessor::LoadedConfig preprocessed = config_processor.loadConfig();
|
2021-09-29 12:52:58 +00:00
|
|
|
config_processor.savePreprocessedConfig(preprocessed, app_path);
|
2019-09-30 16:12:08 +00:00
|
|
|
return preprocessed.configuration;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|