37 #include <Common/Version.h>
39 #include <boost/algorithm/string.hpp>
40 #include <boost/tokenizer.hpp>
59 #include <sys/types.h>
63 #if defined(__APPLE__)
64 extern char **environ;
75 Node(
const string &n) : name(n) {}
82 void add_role(
const string &text) {
83 const char *base = text.c_str();
85 for (ptr=base; *ptr && !isspace(*ptr); ptr++)
87 string token(base, ptr-base);
89 if (strcasecmp(token.c_str(),
"role:"))
91 while (*ptr && isspace(*ptr))
94 while (*ptr && !isspace(*ptr))
96 string name(base, ptr-base);
103 boost::char_separator<char> sep(
" \t\n\r");
104 boost::tokenizer< boost::char_separator<char> > tokens(input, sep);
105 for (
auto &t : tokens)
109 m_roles[name] = value;
111 if (!m_uber_hostspec.empty())
112 m_uber_hostspec +=
" + ";
113 m_uber_hostspec +=
"(" + value +
")";
117 map<string, Node *> node_map;
121 m_nodes.reserve(nodes.size());
122 for (
auto & node : nodes) {
123 m_nodes.push_back(make_unique<Node>(node));
124 node_map[node] = m_nodes.back().get();
133 str +=
" \"roles\": {\n";
134 for (
auto entry : m_roles) {
139 str +=
" \"" + entry.first +
"\": \"" + entry.second +
"\"";
141 for (
auto & node : nodes)
142 node_map[node]->roles.insert(entry.first);
149 str +=
" \"nodes\": [\n";
150 for (
auto & node : m_nodes) {
155 struct hostent *hent = gethostbyname(node->name.c_str());
156 str.append(
" { \"hostname\": \"");
157 str.append((
const char *)(hent->h_name));
158 str.append(
"\", \"roles\": [");
160 for (
auto & role : node->roles) {
165 str +=
"\"" + role +
"\"";
176 string m_uber_hostspec;
177 map<string, string> m_roles;
178 vector<unique_ptr<Node>> m_nodes;
187 map<string, string> environ_map;
188 for (
size_t i=0; environ[i]; i++) {
189 const char *ptr = strchr(environ[i],
'=');
191 environ_map[string(environ[i], ptr-environ[i])] = string(ptr+1);
194 stack<TokenizerPtr> definitions;
201 while (!definitions.empty()) {
202 while (definitions.top()->next(token)) {
204 def.add_role(token.
text);
209 m_str = def.to_json();
Retrieves system information (hardware, installation directory, etc)
Declarations for HostSpecification.
Converts host specification pattern to list of host names.
Po::typed_value< String > * str(String *v=0)
Cluster definition file token.
File system utility functions.
Logging routines and macros.
Compatibility Macros for C/C++.
string m_definition_file
Cluster definition file.
#define HT_THROWF(_code_, _fmt_,...)
string m_str
Output JSON string.
A String class based on std::string.
ToJson(const string &fname)
Constructor.
Declarations for Tokenizer.
Cluster definition file translation definitions.