Skip to content

Commit

Permalink
fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
MCKZX-llx committed Jun 24, 2024
1 parent 1255ade commit e5b012a
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 26 deletions.
2 changes: 1 addition & 1 deletion protos/Crane.proto
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,7 @@ service CraneCtld {
rpc QueryCranedInfo(QueryCranedInfoRequest) returns (QueryCranedInfoReply);
rpc QueryPartitionInfo(QueryPartitionInfoRequest) returns (QueryPartitionInfoReply);
rpc ModifyTask(ModifyTaskRequest) returns (ModifyTaskReply);
rpc ModifyNode(ModifyCranedStateRequest) returns (ModifyCranedStateReply);
rpc ModifyNodeState(ModifyCranedStateRequest) returns (ModifyCranedStateReply);

rpc AddPartition(AddPartitionRequest) returns (AddPartitionReply);
rpc AddNode(AddNodeRequest) returns (AddNodeReply);
Expand Down
2 changes: 1 addition & 1 deletion protos/PublicDefs.proto
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ message PartitionInfo {
uint64 avail_mem = 10;
uint64 alloc_mem = 11;

uint32 priority = 12;
int64 priority = 12;
repeated string allow_list = 13;
repeated string deny_list = 14;
}
Expand Down
12 changes: 12 additions & 0 deletions src/CraneCtld/AccountManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,18 @@ AccountManager::Result AccountManager::BlockUser(const std::string& name,
bool AccountManager::CheckUserPermissionToPartition(
const std::string& name, const std::string& account,
const std::string& partition) {
{
auto part_meta = g_meta_container->GetPartitionMetasPtr(partition);

if (part_meta->partition_global_meta.deny_accounts.contains(account)) {
return false;
} else if (!part_meta->partition_global_meta.allow_accounts.empty() &&
!part_meta->partition_global_meta.allow_accounts.contains(
account)) {
return false;
}
}

UserMutexSharedPtr user_share_ptr = GetExistedUserInfo(name);
if (!user_share_ptr) {
return false;
Expand Down
9 changes: 9 additions & 0 deletions src/CraneCtld/CranedMetaContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,11 +402,13 @@ CranedMetaContainerSimpleImpl::UpdatePartition(PartitionMeta&& new_partition) {
if (!new_partition.partition_global_meta.allow_accounts.empty()) {
part_global_meta.allow_accounts =
new_partition.partition_global_meta.allow_accounts;
part_global_meta.deny_accounts.clear();
}

if (!new_partition.partition_global_meta.deny_accounts.empty()) {
part_global_meta.deny_accounts =
new_partition.partition_global_meta.deny_accounts;
part_global_meta.allow_accounts.clear();
}

if (new_partition.partition_global_meta.priority >= 0) {
Expand Down Expand Up @@ -505,6 +507,13 @@ void CranedMetaContainerSimpleImpl::RegisterPhysicalResource(
cpu_t(cpu);
craned_ptr->static_meta.res_physical.allocatable_resource.memory_bytes =
memory_bytes;

if (cpu_t(cpu) < craned_ptr->res_total.allocatable_resource.cpu_count ||
memory_bytes < craned_ptr->res_total.allocatable_resource.memory_bytes) {
craned_ptr->drain = true;
craned_ptr->status = crane::grpc::CRANE_DRAIN;
craned_ptr->state_reason = "Invalid resource num";
}
}

void CranedMetaContainerSimpleImpl::WaitJobsTerminatedCb_() {
Expand Down
53 changes: 31 additions & 22 deletions src/CraneCtld/CtldGrpcServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ grpc::Status CraneCtldServiceImpl::ModifyTask(
return grpc::Status::OK;
}

grpc::Status CraneCtldServiceImpl::ModifyNode(
grpc::Status CraneCtldServiceImpl::ModifyNodeState(
grpc::ServerContext *context,
const crane::grpc::ModifyCranedStateRequest *request,
crane::grpc::ModifyCranedStateReply *response) {
Expand Down Expand Up @@ -583,14 +583,21 @@ grpc::Status CraneCtldServiceImpl::UpdatePartition(
part_global_meta.name = new_partition.name();
part_global_meta.priority = new_partition.priority();

std::list<std::string> nodes;
util::ParseHostList(new_partition.hostlist(), &nodes);
for (const auto &node : nodes) {
partition.craned_ids.emplace(node);
}
if (!new_partition.hostlist().empty()) {
std::list<std::string> nodes;
if (!util::ParseHostList(new_partition.hostlist(), &nodes)) {
response->set_ok(false);
response->set_reason("Illegal node name string format.");
return grpc::Status::OK;
}
for (const auto &node : nodes) {
partition.craned_ids.emplace(node);
}

part_global_meta.node_cnt = nodes.size();
part_global_meta.nodelist_str = util::HostNameListToStr(partition.craned_ids);
part_global_meta.node_cnt = nodes.size();
part_global_meta.nodelist_str =
util::HostNameListToStr(partition.craned_ids);
}

if (new_partition.allow_list_size() > 0 &&
new_partition.deny_list_size() > 0) {
Expand Down Expand Up @@ -640,7 +647,7 @@ grpc::Status CraneCtldServiceImpl::UpdateNode(
}

if (!request->has_node() || request->node().hostname().empty() ||
request->node().cpu() == 0.0 || request->node().real_mem() == 0) {
request->node().cpu() == 0.0 && request->node().real_mem() == 0) {
response->set_ok(false);
response->set_reason("The parameter is empty.");
return grpc::Status::OK;
Expand Down Expand Up @@ -1465,21 +1472,23 @@ CtldServer::SubmitTaskToScheduler(std::unique_ptr<TaskInCtld> task) {
}
}

if (!g_account_manager->CheckUserPermissionToPartition(
task->Username(), task->account, task->partition_id)) {
return result::fail(
fmt::format("User '{}' doesn't have permission to use partition '{}' "
"when using account '{}'",
task->Username(), task->partition_id, task->account));
}
err = g_task_scheduler->AcquireTaskAttributes(task.get());

auto enable_res =
g_account_manager->CheckEnableState(task->account, task->Username());
if (enable_res.has_error()) {
return result::fail(enable_res.error());
}
if (err == CraneErr::kOk) {
if (!g_account_manager->CheckUserPermissionToPartition(
task->Username(), task->account, task->partition_id)) {
return result::fail(
fmt::format("User '{}' doesn't have permission to use partition '{}' "
"when using account '{}'",
task->Username(), task->partition_id, task->account));
}

err = g_task_scheduler->AcquireTaskAttributes(task.get());
auto enable_res =
g_account_manager->CheckEnableState(task->account, task->Username());
if (enable_res.has_error()) {
return result::fail(enable_res.error());
}
}

if (err == CraneErr::kOk)
err = g_task_scheduler->CheckTaskValidity(task.get());
Expand Down
2 changes: 1 addition & 1 deletion src/CraneCtld/CtldGrpcServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ class CraneCtldServiceImpl final : public crane::grpc::CraneCtld::Service {
const crane::grpc::ModifyTaskRequest *request,
crane::grpc::ModifyTaskReply *response) override;

grpc::Status ModifyNode(
grpc::Status ModifyNodeState(
grpc::ServerContext *context,
const crane::grpc::ModifyCranedStateRequest *request,
crane::grpc::ModifyCranedStateReply *response) override;
Expand Down
2 changes: 1 addition & 1 deletion src/CraneCtld/CtldPublicDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ struct PartitionGlobalMeta {
uint32_t alive_craned_cnt = 0;
uint32_t priority;

std::unordered_set<std::string> allow_accounts; // TODO
std::unordered_set<std::string> allow_accounts;
std::unordered_set<std::string> deny_accounts;
};

Expand Down

0 comments on commit e5b012a

Please sign in to comment.