Skip to content

Commit

Permalink
feat: When submitting a task, check whether the account is in the par…
Browse files Browse the repository at this point in the history
…tition's AllowAccounts.
  • Loading branch information
huerni committed Dec 17, 2024
1 parent 3ddf6fc commit 59671e1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/CraneCtld/CranedMetaContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,18 @@ CraneErrCodeExpected<void> CranedMetaContainer::ModifyPartitionAllowAccounts(
return result;
}

bool CranedMetaContainer::CheckIfAccountIsAllowedInPartition(
const std::string& partition_name, const std::string& account_name) {
if (!partition_metas_map_.Contains(partition_name)) return false;

auto part_meta = partition_metas_map_.GetValueExclusivePtr(partition_name);

if (!part_meta->partition_global_meta.allow_accounts.contains(account_name))
return false;

return true;
}

void CranedMetaContainer::AddDedicatedResource(
const CranedId& node_id, const DedicatedResourceInNode& resource) {
if (!craned_meta_map_.Contains(node_id)) {
Expand Down
3 changes: 3 additions & 0 deletions src/CraneCtld/CranedMetaContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ class CranedMetaContainer final {
const std::string& partition_name,
const std::unordered_set<std::string>& allow_accounts);

bool CheckIfAccountIsAllowedInPartition(const std::string& partition_name,
const std::string& account_name);

void CranedUp(const CranedId& craned_id);

void CranedDown(const CranedId& craned_id);
Expand Down
7 changes: 7 additions & 0 deletions src/CraneCtld/CtldGrpcServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1013,6 +1013,13 @@ CtldServer::SubmitTaskToScheduler(std::unique_ptr<TaskInCtld> task) {
return std::unexpected(enable_res.error());
}

if (!g_meta_container->CheckIfAccountIsAllowedInPartition(task->partition_id,
task->account))
return std::unexpected(
"The account is not in the AllowAccounts of the partition "
"specified "
"for the task, submission of the task is prohibited.");

err = g_task_scheduler->AcquireTaskAttributes(task.get());

if (err == CraneErr::kOk)
Expand Down

0 comments on commit 59671e1

Please sign in to comment.