in bistro/nodes/ManualFetcher.cpp [49:98]
void ManualFetcher::fetch(
const Config& config,
const NodeConfig& node_config,
Nodes* all_nodes) const {
ManualNodeState state;
state.allNodes_ = all_nodes;
state.maxLevel_ = config.getNumConfiguredLevels();
unordered_set<string> has_parent;
for (const auto& pair : node_config.prefs) {
auto& child_names = state.parentToChildren_[pair.first];
if (pair.second.isString()) { // A string is a single node name
child_names.emplace_back(
pair.second.asString()
);
} else if (pair.second.isObject()) {
if (auto* children = pair.second.get_ptr("children")) {
for (const auto& kid_name : *children) {
child_names.emplace_back(kid_name.asString());
}
}
if (pair.second.get_ptr("disabled")) {
state.isDisabled_.insert(pair.first);
}
} else { // Otherwise it's a list of child names
for (const auto& kid_name : pair.second) {
child_names.emplace_back(kid_name.asString());
}
}
for (const auto& child : child_names) {
has_parent.insert(child);
}
}
// Add the nodes without parents as the children of the instance node
int num_sources = 0;
for (const auto& pair : node_config.prefs) {
if (has_parent.count(pair.first) == 0) {
state.recursiveAdd(pair.first, all_nodes->getInstance(), 1);
++num_sources;
}
}
// This detects bad configs -- if you need no nodes below the instance,
// don't specify any fetchers.
if (num_sources == 0 ) {
throw BistroException("No top level nodes are defined");
}
}