Skip to content

Commit

Permalink
fix: Bug when reading database.yaml and update config examples (#246)
Browse files Browse the repository at this point in the history
* fix: Bug when reading database.yaml and update config examples

* Refactor.

Signed-off-by: RileyW <wrllrwwrllrw@gmail.com>

---------

Signed-off-by: RileyW <wrllrwwrllrw@gmail.com>
Co-authored-by: RileyW <wrllrwwrllrw@gmail.com>
  • Loading branch information
Nativu5 and RileyWen authored Mar 26, 2024
1 parent e8008d9 commit 59c30b3
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 24 deletions.
31 changes: 21 additions & 10 deletions etc/config.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Cluster settings (This must be identical across all nodes)
# the hostname of node which is running cranectld
ControlMachine: cn15
# the name of this cluster
Expand All @@ -14,23 +15,33 @@ ServerKeyFilePath: /etc/crane/server.key
CaCertFilePath: /etc/crane/ca.crt
DomainSuffix: riley.local

# Other configurations to be used
DbConfigPath: /etc/crane/database.yaml

# Craned Options
# Data storage settings
CraneBaseDir: /var/crane

# Ctld settings
# debug level of cranectld
CraneCtldDebugLevel: trace
# file path of cranectld log file
CraneCtldLogFile: /tmp/cranectld/cranectld.log
# Determines whether the cranectld is running in the background
# file path of cranectld log file (relative to CraneBaseDir)
CraneCtldLogFile: cranectld/cranectld.log
# file path of cranectld lock file (relative to CraneBaseDir)
CraneCtldMutexFilePath: cranectld/cranectld.lock
# whether the cranectld is running in the background
CraneCtldForeground: true

# Craned settings
# debug level of craned
CranedDebugLevel: trace
# file path of craned log file
CranedLogFile: /tmp/craned/craned.log
# Determines whether the craned is running in the background
# file path of craned log file (relative to CraneBaseDir)
CranedLogFile: craned/craned.log
# file path of craned lock file (relative to CraneBaseDir)
CranedMutexFilePath: craned/craned.lock
# whether the craned is running in the background
CranedForeground: true

# Scheduling settings
PriorityType: priority/multifactor

# Default value is true
Expand All @@ -46,8 +57,8 @@ PriorityWeightJobSize: 0
PriorityWeightPartition: 1000
PriorityWeightQ0S: 1000000


# list of configuration information of the computing machine
# Nodes and partitions settings
# node information list
Nodes:
- name: "cn[15-18]"
cpu: 2
Expand All @@ -62,4 +73,4 @@ Partitions:
nodes: "cn[17-18]"
priority: 3

DefaultPartition: CPU
DefaultPartition: CPU
6 changes: 4 additions & 2 deletions etc/database.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# EmbeddedDb settings
CraneEmbeddedDbBackend: Unqlite # BerkeleyDB or Unqlite(default)
CraneCtldDbPath: /tmp/cranectld/embedded.db
# BerkeleyDB or Unqlite(default)
CraneEmbeddedDbBackend: Unqlite
# File path of CraneCtld embeded DB (Relative to CraneBaseDir)
CraneCtldDbPath: cranectld/embedded.db

# Mongodb settings
DbUser: admin
Expand Down
15 changes: 8 additions & 7 deletions src/CraneCtld/CraneCtld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void ParseConfig(int argc, char** argv) {
config["CraneCtldLogFile"].as<std::string>();
else
g_config.CraneCtldLogFile =
g_config.CraneBaseDir + kCraneCtldDefaultLogPath;
g_config.CraneBaseDir + kDefaultCraneCtldLogPath;

if (config["CraneCtldDebugLevel"])
g_config.CraneCtldDebugLevel =
Expand Down Expand Up @@ -104,12 +104,6 @@ void ParseConfig(int argc, char** argv) {
g_config.CraneCtldMutexFilePath =
g_config.CraneBaseDir + kDefaultCraneCtldMutexFile;

if (config["CraneCtldDbPath"] && !config["CraneCtldDbPath"].IsNull())
g_config.CraneCtldDbPath =
g_config.CraneBaseDir + config["CraneCtldDbPath"].as<std::string>();
else
g_config.CraneCtldDbPath = g_config.CraneBaseDir + kDefaultDbPath;

if (config["CraneCtldListenAddr"])
g_config.ListenConf.CraneCtldListenAddr =
config["CraneCtldListenAddr"].as<std::string>();
Expand Down Expand Up @@ -409,6 +403,13 @@ void ParseConfig(int argc, char** argv) {
else
g_config.CraneEmbeddedDbBackend = "Unqlite";

if (config["CraneCtldDbPath"] && !config["CraneCtldDbPath"].IsNull())
g_config.CraneCtldDbPath =
g_config.CraneBaseDir + config["CraneCtldDbPath"].as<std::string>();
else
g_config.CraneCtldDbPath =
g_config.CraneBaseDir + kDefaultCraneCtldDbPath;

if (config["DbUser"] && !config["DbUser"].IsNull()) {
g_config.DbUser = config["DbUser"].as<std::string>();
if (config["DbPassword"] && !config["DbPassword"].IsNull())
Expand Down
4 changes: 2 additions & 2 deletions src/Craned/Craned.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void ParseConfig(int argc, char** argv) {
("s,server-address", "CraneCtld address format: <IP>:<port>",
cxxopts::value<std::string>())
("L,log-file", "File path of craned log file",
cxxopts::value<std::string>()->default_value(kCranedDefaultLogPath))
cxxopts::value<std::string>()->default_value(kDefaultCranedLogPath))
("D,debug-level", "<trace|debug|info|warn|error>", cxxopts::value<std::string>()->default_value("info"))
("h,help", "Show help")
;
Expand Down Expand Up @@ -80,7 +80,7 @@ void ParseConfig(int argc, char** argv) {
g_config.CranedLogFile =
g_config.CraneBaseDir + config["CranedLogFile"].as<std::string>();
else
g_config.CranedLogFile = g_config.CraneBaseDir + kCranedDefaultLogPath;
g_config.CranedLogFile = g_config.CraneBaseDir + kDefaultCranedLogPath;

if (config["CranedDebugLevel"])
g_config.CranedDebugLevel =
Expand Down
6 changes: 3 additions & 3 deletions src/Utilities/PublicHeader/include/crane/PublicHeader.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ inline constexpr uint64_t kPriorityDefaultMaxAge = 7 * 24 * 3600; // 7 days

inline const char* kDefaultCraneBaseDir = "/var/crane/";
inline const char* kDefaultCraneCtldMutexFile = "cranectld/cranectld.lock";
inline const char* kCraneCtldDefaultLogPath = "cranectld/cranectld.log";
inline const char* kDefaultDbPath = "cranectld/embedded.db";
inline const char* kDefaultCraneCtldLogPath = "cranectld/cranectld.log";
inline const char* kDefaultCraneCtldDbPath = "cranectld/embedded.db";

inline const char* kDefaultCranedScriptDir = "craned/scripts";
inline const char* kDefaultCranedUnixSockPath = "craned/craned.sock";
inline const char* kDefaultCranedMutexFile = "craned/craned.lock";
inline const char* kCranedDefaultLogPath = "craned/craned.log";
inline const char* kDefaultCranedLogPath = "craned/craned.log";

constexpr int64_t kMaxTimeLimitSecond =
google::protobuf::util::TimeUtil::kDurationMaxSeconds;
Expand Down

0 comments on commit 59c30b3

Please sign in to comment.