35 #include <boost/algorithm/string.hpp>
36 #include <boost/tokenizer.hpp>
42 #include <sys/types.h>
53 vector<string> &members,
55 lock_guard<mutex> lock(m_mutex);
57 auto iter = m_roles.find(role);
58 if (iter == m_roles.end()) {
64 members = iter->second;
66 *generation = (int64_t)m_last_mtime;
72 if (stat(m_fname.c_str(), &stats)) {
73 if (errno == ENOENT) {
78 HT_FATALF(
"Unable to access file %s - %s",
79 m_fname.c_str(), strerror(errno));
82 if (stats.st_mtime > m_last_mtime) {
85 while (tokenizer->next(token)) {
89 m_last_mtime = stats.st_mtime;
95 const char *base = text.c_str();
97 for (ptr=base; *ptr && !isspace(*ptr); ptr++)
99 string token(base, ptr-base);
101 if (strcasecmp(token.c_str(),
"role:"))
103 while (*ptr && isspace(*ptr))
106 while (*ptr && !isspace(*ptr))
108 string name(base, ptr-base);
115 boost::char_separator<char> sep(
" \t\n\r");
116 boost::tokenizer< boost::char_separator<char> > tokens(input, sep);
117 for (
auto &t : tokens)
Declarations for HostSpecification.
void add_role(const std::string &text)
Parses a role definition statement Parses the role definition statement contained in text and adds th...
Converts host specification pattern to list of host names.
Cluster definition file token.
shared_ptr< Tokenizer > TokenizerPtr
Smart pointer to Tokenizer.
Logging routines and macros.
void load_file()
Load cluster definition from file Loads the cluster definition from the file m_fname, if the file was modified since the last time it was loaded.
Compatibility Macros for C/C++.
Splits cluster definition file into tokens.
Declarations for ClusterDefinition.
#define HT_FATALF(msg,...)
#define HT_THROWF(_code_, _fmt_,...)
void get_role_members(const std::string &role, std::vector< std::string > &members, int64_t *generation=nullptr)
Get list of members of a role This method first refreshes its view of the cluster definition by reloa...
Declarations for Tokenizer.
Cluster definition file translation definitions.