Skip to content

Commit

Permalink
add enum type error
Browse files Browse the repository at this point in the history
  • Loading branch information
1daidai1 committed Dec 6, 2024
1 parent b72a2a9 commit b382e40
Show file tree
Hide file tree
Showing 7 changed files with 178 additions and 82 deletions.
74 changes: 41 additions & 33 deletions protos/PublicDefs.proto
Original file line number Diff line number Diff line change
Expand Up @@ -340,44 +340,52 @@ enum ErrCode {
ERR_PARENT_ALLOWED_PARTITION = 10017;
ERR_USER_EMPTY_PARTITION = 10018;
ERR_CHILD_HAS_PARTITION = 10019;

ERR_INVALID_QOS = 10020;
ERR_DB_DUPLICATE_QOS = 10021;
ERR_DELETE_QOS = 10022;
ERR_CONVERT_TO_INTERGER = 10023;
ERR_TIME_LIMIT = 10024;
ERR_ALLOWED_QOS = 10025;
ERR_DUPLICATE_QOS = 10026;
ERR_PARENT_ALLOWED_QOS = 10027;
ERR_SET_ALLOWED_QOS = 10028;
ERR_ALLOWED_DEFAULT_QOS = 10029;
ERR_DUPLICATE_DEFAULT_QOS = 10030;
ERR_CHILD_HAS_DEFAULT_QOS = 10031;
ERR_SET_ACCOUNT_QOS = 10032;
ERR_SET_DEFAULT_QOS = 10033;
ERR_IS_DEFAULT_QOS = 10034;

ERR_UPDATE_DATABASE = 10035;
ERR_HAS_NO_QOS_IN_PARTITION = 10020;
ERR_HAS_ALLOWED_QOS_IN_PARTITION = 10021;

ERR_INVALID_QOS = 10022;
ERR_DB_DUPLICATE_QOS = 10023;
ERR_DELETE_QOS = 10024;
ERR_CONVERT_TO_INTERGER = 10025;
ERR_TIME_LIMIT = 10026;
ERR_ALLOWED_QOS = 10027;
ERR_DUPLICATE_QOS = 10028;
ERR_PARENT_ALLOWED_QOS = 10029;
ERR_SET_ALLOWED_QOS = 10030;
ERR_ALLOWED_DEFAULT_QOS = 10031;
ERR_DUPLICATE_DEFAULT_QOS = 10032;
ERR_CHILD_HAS_DEFAULT_QOS = 10033;
ERR_SET_ACCOUNT_QOS = 10034;
ERR_SET_DEFAULT_QOS = 10035;
ERR_IS_DEFAULT_QOS = 10036;

ERR_UPDATE_DATABASE = 10037;

ERR_GENERIC_FAILURE = 10100;
ERR_NO_RESOURCE = 10101;
ERR_NON_EXISTENT = 10102;
ERR_INVALID_NODE_NUM = 10103;
ERR_SYSTEM_ERR = 10104;
ERR_EXISTING_TASK = 10105;
ERR_INVALID_PARAM = 10106;
ERR_STOP = 10107;
ERR_PERMISSION_DENIED = 10108;
ERR_CONNECTION_TIMEOUT = 10109;
ERR_CONNECTION_ABORTED = 10110;
ERR_RPC_FAILURE = 10111;
ERR_TOKEN_REQUEST_FAILURE = 10112;
ERR_STREAM_BROKEN = 10113;
ERR_INVALID_STUB = 10114;
ERR_CGROUP = 10115;
ERR_PROTOBUF = 10116;
ERR_LIB_EVENT = 10117;
ERR_NO_AVAIL_NODE = 10118;
ERR_INVAILD_NODE_LIST = 10104;
ERR_INVAILD_EX_NODE_LIST = 10105;
ERR_TIME_TIMIT_BEYOND = 10106;
ERR_CPUS_PER_TASK_BEYOND = 10107;
ERR_NO_ENOUGH_NODE = 10108;

ERR_SYSTEM_ERR = 10109;
ERR_EXISTING_TASK = 10110;
ERR_INVALID_PARAM = 10111;
ERR_STOP = 10112;
ERR_PERMISSION_DENIED = 10113;
ERR_CONNECTION_TIMEOUT = 10114;
ERR_CONNECTION_ABORTED = 10115;
ERR_RPC_FAILURE = 10116;
ERR_TOKEN_REQUEST_FAILURE = 10117;
ERR_STREAM_BROKEN = 10118;
ERR_INVALID_STUB = 10119;
ERR_CGROUP = 10120;
ERR_PROTOBUF = 10121;
ERR_LIB_EVENT = 10122;
ERR_NO_AVAIL_NODE = 10123;
}

enum EntityType {
Expand Down
18 changes: 9 additions & 9 deletions src/CraneCtld/AccountManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -921,7 +921,7 @@ result::result<void, std::string> AccountManager::CheckIfUserOfAccountIsEnabled(
return {};
}

CraneErr AccountManager::CheckAndApplyQosLimitOnTask(const std::string& user,
AccountManager::CraneExpected<void> AccountManager::CheckAndApplyQosLimitOnTask(const std::string& user,
const std::string& account,
TaskInCtld* task) {
util::read_lock_guard user_guard(m_rw_user_mutex_);
Expand All @@ -930,7 +930,7 @@ CraneErr AccountManager::CheckAndApplyQosLimitOnTask(const std::string& user,
const User* user_share_ptr = GetExistedUserInfoNoLock_(user);
if (!user_share_ptr) {
CRANE_ERROR("CheckAndApplyQosLimitOnTask error: Unknown user {}", user);
return CraneErr::kInvalidUser;
return std::unexpected(CraneErrCode::ERR_INVALID_OP_USER);
}

if (task->uid != 0) {
Expand All @@ -941,7 +941,7 @@ CraneErr AccountManager::CheckAndApplyQosLimitOnTask(const std::string& user,
CRANE_ERROR(
"CheckAndApplyQosLimitOnTask error: Partition is not allowed for "
"this user");
return CraneErr::kNonExistent;
return std::unexpected(CraneErrCode::ERR_ALLOWED_PARTITION);

if (task->qos.empty()) {
// Default qos
Expand All @@ -951,7 +951,7 @@ CraneErr AccountManager::CheckAndApplyQosLimitOnTask(const std::string& user,
"CheckAndApplyQosLimitOnTask error: The user '{}' has no QOS "
"available for this partition '{}' to be used",
task->Username(), task->partition_id);
return CraneErr::kInvalidQos;
return std::unexpected(CraneErrCode::ERR_HAS_NO_QOS_IN_PARTITION);
}
} else {
// Check whether task.qos in the qos list
Expand All @@ -960,7 +960,7 @@ CraneErr AccountManager::CheckAndApplyQosLimitOnTask(const std::string& user,
"CheckAndApplyQosLimitOnTask error: The qos '{}'"
" you set is not in partition's allowed qos list",
task->qos);
return CraneErr::kInvalidQos;
return std::unexpected(CraneErrCode::ERR_HAS_ALLOWED_QOS_IN_PARTITION);
}
}
} else {
Expand All @@ -972,7 +972,7 @@ CraneErr AccountManager::CheckAndApplyQosLimitOnTask(const std::string& user,
const Qos* qos_share_ptr = GetExistedQosInfoNoLock_(task->qos);
if (!qos_share_ptr) {
CRANE_ERROR("Unknown QOS '{}'", task->qos);
return CraneErr::kInvalidQos;
return std::unexpected(CraneErrCode::ERR_INVALID_QOS);
}

task->qos_priority = qos_share_ptr->priority;
Expand All @@ -981,16 +981,16 @@ CraneErr AccountManager::CheckAndApplyQosLimitOnTask(const std::string& user,
task->time_limit = qos_share_ptr->max_time_limit_per_task;
} else if (task->time_limit > qos_share_ptr->max_time_limit_per_task) {
CRANE_ERROR("time-limit reached the user's limit");
return CraneErr::kInvalidTimeLimit;
return std::unexpected(CraneErrCode::ERR_TIME_TIMIT_BEYOND);
}

if (static_cast<double>(task->cpus_per_task) >
qos_share_ptr->max_cpus_per_user) {
CRANE_ERROR("cpus-per-task reached the user's limit");
return CraneErr::kInvaildCpusperTask;
return std::unexpected(CraneErrCode::ERR_CPUS_PER_TASK_BEYOND);
}

return CraneErr::kOk;
return {};
}

result::result<void, std::string> AccountManager::CheckUidIsAdmin(
Expand Down
2 changes: 1 addition & 1 deletion src/CraneCtld/AccountManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class AccountManager {
result::result<void, std::string> CheckIfUserOfAccountIsEnabled(
const std::string& user, const std::string& account);

CraneErr CheckAndApplyQosLimitOnTask(const std::string& user,
CraneExpected<void> CheckAndApplyQosLimitOnTask(const std::string& user,
const std::string& account,
TaskInCtld* task);

Expand Down
47 changes: 28 additions & 19 deletions src/CraneCtld/CtldGrpcServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,6 @@ CtldServer::CtldServer(const Config::CraneCtldListenConf &listen_conf) {

result::result<std::future<task_id_t>, std::string>
CtldServer::SubmitTaskToScheduler(std::unique_ptr<TaskInCtld> task) {
CraneErr err;

if (!task->password_entry->Valid()) {
return result::fail(
Expand Down Expand Up @@ -968,75 +967,85 @@ CtldServer::SubmitTaskToScheduler(std::unique_ptr<TaskInCtld> task) {
return result::fail(enable_res.error());
}

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

if (err == CraneErr::kOk)
err = g_task_scheduler->CheckTaskValidity(task.get());
if (result)
result = g_task_scheduler->CheckTaskValidity(task.get());

if (err == CraneErr::kOk) {
if (result) {
task->SetSubmitTime(absl::Now());
std::future<task_id_t> future =
g_task_scheduler->SubmitTaskAsync(std::move(task));
return {std::move(future)};
}

switch (err) {
case CraneErr::kNonExistent:
switch (result.error()) {
case crane::grpc::ErrCode::ERR_INVALID_PARTITION:
case crane::grpc::ErrCode::ERR_ALLOWED_PARTITION:
CRANE_DEBUG("Task submission failed. Reason: Partition doesn't exist!");
return result::fail("Partition doesn't exist");

case CraneErr::kInvalidNodeNum:
case crane::grpc::ErrCode::ERR_INVALID_NODE_NUM:
CRANE_DEBUG(
"Task submission failed. Reason: --node is either invalid or greater "
"than the number of nodes in its partition.");
return result::fail(
"--node is either invalid or greater than the number of nodes in its "
"partition");

case CraneErr::kNoResource:
case crane::grpc::ErrCode::ERR_NO_RESOURCE:
CRANE_DEBUG(
"Task submission failed. "
"Reason: The resources of the partition are insufficient.");
return result::fail("The resources of the partition are insufficient");

case CraneErr::kNoAvailNode:
case crane::grpc::ErrCode::ERR_NO_ENOUGH_NODE:
CRANE_DEBUG(
"Task submission failed. "
"Reason: Nodes satisfying the requirements of task are insufficient");
return result::fail(
"Nodes satisfying the requirements of task are insufficient");

case CraneErr::kInvalidUser:
case crane::grpc::ErrCode::ERR_INVALID_OP_USER:
CRANE_DEBUG("Task submission failed. Reason: Unknown user");
return result::fail("Unknown user");

case CraneErr::kInvalidQos:
case crane::grpc::ErrCode::ERR_INVALID_QOS:
CRANE_DEBUG(
"Task submission failed. Reason: Unknown Qos");
return result::fail("Unkown Qos");
case crane::grpc::ErrCode::ERR_HAS_ALLOWED_QOS_IN_PARTITION:
CRANE_DEBUG(
"Task submission failed. Reason: "
"The qos you set is not in partition's allowed qos list");
return result::fail("the qos you set is not in partition's allowed qos list");
case crane::grpc::ErrCode::ERR_HAS_NO_QOS_IN_PARTITION:
CRANE_DEBUG(
"Task submission failed. Reason: "
"Unknown Qos or not in partition's allowed qos list");
return result::fail("Unkown Qos or not in partition's allowed qos list");
"The user has no QOS available for this partition to be used");
return result::fail("The user has no QOS available for this partition to be used");

case CraneErr::kInvalidTimeLimit:
case crane::grpc::ErrCode::ERR_TIME_TIMIT_BEYOND:
CRANE_DEBUG(
"Task submission failed. Reason: time-limit reached the user's limit");
return result::fail("time-limit reached the user's limit");

case CraneErr::kInvaildCpusperTask:
case crane::grpc::ErrCode::ERR_CPUS_PER_TASK_BEYOND:
CRANE_DEBUG(
"Task submission failed. Reason: cpus-per-task reached the user's "
"limit");
return result::fail("cpus-per-task reached the user's limit");

case CraneErr::kInvaildNodeList:
case crane::grpc::ErrCode::ERR_INVAILD_NODE_LIST:
CRANE_DEBUG("Task submission failed. Reason: Invalid nodelist");
return result::fail("Invalid nodelist");

case CraneErr::kInvalidExNodeList:
case crane::grpc::ErrCode::ERR_INVAILD_EX_NODE_LIST:
CRANE_DEBUG("Task submission failed. Reason: Invalid excluded nodelist");
return result::fail("Invalid excluded nodelist");

default:
return result::fail(CraneErrStr(err));
return result::fail(CraneErrCodeStr(result.error()));
}
}

Expand Down
Loading

0 comments on commit b382e40

Please sign in to comment.