Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions etc/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ Nodes:
# partition information list
Partitions:
- name: CPU
# Nodes in this partition. Use "ALL" for all nodes.
nodes: "cn[15-16]"
priority: 5
- name: GPU
Expand Down
48 changes: 10 additions & 38 deletions src/CraneCtld/CraneCtld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,45 +454,17 @@ void ParseConfig(int argc, char** argv) {
} else
part.priority = 0;

std::list<std::string> name_list;
auto act_nodes_str = absl::StripAsciiWhitespace(nodes);
if (act_nodes_str == "ALL") {
std::list<std::string> host_list =
g_config.Nodes | ranges::views::keys |
ranges::to<std::list<std::string>>();
part.nodelist_str = util::HostNameListToStr(host_list);
for (auto&& node : host_list) {
part.nodes.emplace(node);
nodes_without_part.erase(node);
CRANE_TRACE("Set the partition of node {} to {}", node, name);
}
} else {
part.nodelist_str = nodes;
if (!util::ParseHostList(std::string(act_nodes_str), &name_list)) {
CRANE_ERROR("Illegal node name string format.");
std::exit(1);
}
std::list<std::string> host_list =
g_config.Nodes | ranges::views::keys |
ranges::to<std::list<std::string>>();
part.nodelist_str = util::HostNameListToStr(host_list);
if (!util::PartitionNodesProcess(nodes, host_list, name, true,
part.nodes)) {
std::exit(1);
}

if (name_list.empty()) {
CRANE_WARN("No nodes in partition '{}'.", name);
} else {
for (auto&& node : name_list) {
auto node_it = g_config.Nodes.find(node);
if (node_it != g_config.Nodes.end()) {
part.nodes.emplace(node_it->first);
nodes_without_part.erase(node_it->first);
CRANE_TRACE("Set the partition of node {} to {}",
node_it->first, name);
} else {
CRANE_ERROR(
"Unknown node '{}' found in partition '{}'. It is "
"ignored "
"and should be contained in the configuration file.",
node, name);
std::exit(1);
}
}
}
for (const auto& node_name : part.nodes) {
nodes_without_part.erase(node_name);
}

if (partition["AllowedAccounts"] &&
Expand Down
36 changes: 6 additions & 30 deletions src/Craned/Core/Craned.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,36 +433,12 @@ void ParseConfig(int argc, char** argv) {
} else
std::exit(1);

std::list<std::string> name_list;
auto act_nodes_str = absl::StripAsciiWhitespace(nodes);
if (act_nodes_str == "ALL") {
for (const auto& [node, _] : g_config.CranedRes) {
part.nodes.emplace(node);
CRANE_INFO("Find node {} in partition {}", node, name);
}
} else {
if (!util::ParseHostList(std::string(act_nodes_str), &name_list)) {
CRANE_ERROR("Illegal node name string format.");
std::exit(1);
}
if (name_list.empty()) {
CRANE_WARN("No nodes in partition '{}'.", name);
} else {
for (auto&& node : name_list) {
auto node_it = g_config.CranedRes.find(node);
if (node_it != g_config.CranedRes.end()) {
part.nodes.emplace(node_it->first);
CRANE_INFO("Find node {} in partition {}", node_it->first,
name);
} else {
CRANE_ERROR(
"Unknown node '{}' found in partition '{}'. It is "
"ignored "
"and should be contained in the configuration file.",
node, name);
}
}
}
std::list<std::string> host_list =
g_config.CranedRes | std::ranges::views::keys |
std::ranges::to<std::list<std::string>>();
if (!util::PartitionNodesProcess(nodes, host_list, name, false,
part.nodes)) {
std::exit(1);
}

g_config.Partitions.emplace(std::move(name), std::move(part));
Expand Down
44 changes: 44 additions & 0 deletions src/Utilities/PublicHeader/String.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,4 +472,48 @@ std::expected<CertPair, std::string> ParseCertificate(
return CertPair{cn, formatted_serial_number};
}

bool PartitionNodesProcess(const std::string &node_str,
const std::list<std::string> &host_list,
const std::string &part_name,
bool disallow_unknown_node,
std::unordered_set<std::string> &part_node_list) {
std::list<std::string> name_list;
std::unordered_set<std::string> node_name_set_list(host_list.begin(),
host_list.end());

auto act_nodes_str = absl::StripAsciiWhitespace(node_str);
if (act_nodes_str == "ALL") {
for (const auto &node : host_list) {
part_node_list.emplace(node);
CRANE_TRACE("Find node {} in partition {}", node, part_name);
}
} else {
if (!util::ParseHostList(std::string(act_nodes_str), &name_list)) {
CRANE_ERROR("Illegal node name string format.");
return false;
}

if (name_list.empty()) {
CRANE_WARN("No nodes in partition '{}'.", part_name);
} else {
for (const auto &node : name_list) {
auto node_it = node_name_set_list.find(node);
if (node_it != node_name_set_list.end()) {
part_node_list.emplace(*node_it);
CRANE_TRACE("Find node {} in partition {}", *node_it, part_name);
} else {
CRANE_ERROR(
"Unknown node '{}' found in partition '{}'. It is "
"ignored "
"and should be contained in the configuration file.",
node, part_name);
if (disallow_unknown_node) return false;
}
}
}
}

return true;
}

} // namespace util
4 changes: 4 additions & 0 deletions src/Utilities/PublicHeader/include/crane/String.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,8 @@ std::optional<std::string> ParseCertConfig(const std::string &cert_name,
return std::nullopt;
}

bool PartitionNodesProcess(const std::string &node_str,
const std::list<std::string> &host_list,
const std::string &part_name, bool disallow_unknown_node,
std::unordered_set<std::string> &part_node_list);
} // namespace util