Skip to content

Commit 73bf1d6

Browse files
committed
refactor
1 parent fab3268 commit 73bf1d6

File tree

5 files changed

+9
-13
lines changed

5 files changed

+9
-13
lines changed

protos/PublicDefs.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ message TaskInfo {
262262
string username = 15;
263263
string qos = 16;
264264
ResourceView res_view = 17;
265-
string licenses = 18;
265+
map<string, uint32> licenses_count = 18;
266266
repeated string req_nodes = 19;
267267
repeated string exclude_nodes = 20;
268268

src/CraneCtld/CtldPublicDefs.h

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -600,14 +600,10 @@ struct TaskInCtld {
600600
task_info->set_partition(partition_id);
601601
task_info->set_qos(qos);
602602

603-
// lic_map -> "lic1:1,lic2:3"
604-
auto license_strings =
605-
licenses_count | ranges::views::transform([](const auto& pair) {
606-
return pair.first + ":" + std::to_string(pair.second);
607-
});
608-
std::string licenses_view =
609-
license_strings | ranges::views::join(',') | ranges::to<std::string>();
610-
task_info->set_licenses(licenses_view);
603+
for (const auto& [license_name, license_count] : licenses_count) {
604+
task_info->mutable_licenses_count()->insert(
605+
{license_name, license_count});
606+
}
611607

612608
task_info->mutable_time_limit()->set_seconds(ToInt64Seconds(time_limit));
613609
task_info->mutable_submit_time()->CopyFrom(runtime_attr.submit_time());

src/CraneCtld/LicensesManager.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,13 @@ bool LicensesManager::CheckLicenseCountSufficient(
7373
return true;
7474
}
7575

76-
result::result<void, std::string> LicensesManager::CheckLicensesLegal(
76+
std::expected<void, std::string> LicensesManager::CheckLicensesLegal(
7777
const ::google::protobuf::Map<std::string, uint32_t>& lic_id_to_count_map) {
7878
util::read_lock_guard readLock(rw_mutex_);
7979
for (auto& [lic_id, count] : lic_id_to_count_map) {
8080
auto it = lic_id_to_lic_map_.find(lic_id);
8181
if (it == lic_id_to_lic_map_.end() || count > it->second.total) {
82-
return result::fail("Invalid license specification");
82+
return std::unexpected("Invalid license specification");
8383
}
8484
}
8585

src/CraneCtld/LicensesManager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class LicensesManager {
4141
bool CheckLicenseCountSufficient(
4242
const std::unordered_map<LicenseId, uint32_t> &lic_id_to_count_map);
4343

44-
result::result<void, std::string> CheckLicensesLegal(
44+
std::expected<void, std::string> CheckLicensesLegal(
4545
const ::google::protobuf::Map<std::string, uint32_t>
4646
&lic_id_to_count_map);
4747

src/CraneCtld/TaskScheduler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2561,7 +2561,7 @@ CraneErr TaskScheduler::AcquireTaskAttributes(TaskInCtld* task) {
25612561

25622562
auto check_licenses_result = g_licenses_manager->CheckLicensesLegal(
25632563
task->TaskToCtld().licenses_count());
2564-
if (check_licenses_result.has_error()) {
2564+
if (!check_licenses_result) {
25652565
CRANE_ERROR("Failed to call CheckLicensesLegal: {}",
25662566
check_licenses_result.error());
25672567

0 commit comments

Comments
 (0)