Skip to content

Commit e7e214a

Browse files
authored
Merge pull request #23 from dmitryro/devel-0.0.1
Devel 0.0.1
2 parents 724f33e + 5458cef commit e7e214a

File tree

9 files changed

+5895
-1231
lines changed

9 files changed

+5895
-1231
lines changed

server/src/cli/cli.rs

Lines changed: 220 additions & 50 deletions
Large diffs are not rendered by default.

server/src/cli/commands.rs

Lines changed: 356 additions & 159 deletions
Large diffs are not rendered by default.

server/src/cli/config.rs

Lines changed: 34 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,33 @@
11
// server/src/cli/config.rs
22

33
// This file handles loading CLI and Storage daemon configurations.
4-
54
use serde::{Deserialize, Serialize};
65
use std::fs;
76
use std::path::PathBuf;
87
use anyhow::{Context, Result};
9-
use std::str::FromStr; // Required for FromStr trait implementation
10-
use serde_yaml2; // <--- Add this import
11-
use daemon_api::StorageEngineType as DaemonApiStorageEngineType; // Added: Import daemon_api's StorageEngineType
8+
use std::str::FromStr;
9+
use serde_yaml2;
10+
use daemon_api::StorageEngineType as DaemonApiStorageEngineType;
11+
12+
/// Define the StorageConfig struct to mirror the content under 'storage:' in storage_config.yaml.
13+
#[derive(Debug, Deserialize, Serialize, Clone)]
14+
pub struct StorageConfig {
15+
pub data_directory: String,
16+
pub log_directory: String,
17+
pub default_port: u16,
18+
pub cluster_range: String,
19+
pub max_disk_space_gb: u64,
20+
pub min_disk_space_gb: u64,
21+
pub use_raft_for_scale: bool,
22+
pub storage_engine_type: String,
23+
}
1224

25+
#[derive(Debug, Deserialize)]
26+
pub struct ConfigWrapper {
27+
pub storage: StorageConfig,
28+
}
1329

1430
// CLI's assumed default storage port. This is used for consistency in stop/status commands.
15-
// The actual daemon port is determined by the daemon itself based on CLI arguments or its own config file.
1631
pub const CLI_ASSUMED_DEFAULT_STORAGE_PORT_FOR_STATUS: u16 = 8085;
1732

1833
/// Represents the top-level structure of the CLI configuration file (e.g., config.toml).
@@ -43,45 +58,26 @@ pub fn load_cli_config() -> Result<CliConfig> {
4358
Ok(config)
4459
}
4560

46-
/// Define the StorageConfig struct to mirror the content under 'storage:' in storage_config.yaml.
47-
#[derive(Debug, Deserialize, Serialize, Clone)] // Added Clone for passing to daemonized process
48-
pub struct StorageConfig {
49-
pub data_directory: String,
50-
pub log_directory: String,
51-
pub default_port: u16,
52-
pub cluster_range: String,
53-
pub max_disk_space_gb: u64,
54-
pub min_disk_space_gb: u64,
55-
pub use_raft_for_scale: bool,
56-
pub storage_engine_type: String,
57-
}
58-
59-
// Added: Default implementation for StorageConfig
61+
// Default implementation for StorageConfig
6062
impl Default for StorageConfig {
6163
fn default() -> Self {
6264
StorageConfig {
6365
data_directory: "/tmp/graphdb_data".to_string(),
6466
log_directory: "/tmp/graphdb_logs".to_string(),
65-
default_port: 8090, // A common default port for storage
66-
cluster_range: "8090-8100".to_string(), // Example default cluster range
67-
max_disk_space_gb: 100, // 100 GB default
68-
min_disk_space_gb: 10, // 10 GB default
69-
use_raft_for_scale: false, // Default to not using Raft
70-
storage_engine_type: "sled".to_string(), // Default to Sled
67+
default_port: 8090,
68+
cluster_range: "8090-8100".to_string(),
69+
max_disk_space_gb: 100,
70+
min_disk_space_gb: 10,
71+
use_raft_for_scale: false,
72+
storage_engine_type: "sled".to_string(),
7173
}
7274
}
7375
}
7476

75-
// Define a wrapper struct to match the 'storage:' key in the YAML config.
76-
#[derive(Debug, Deserialize)]
77-
struct StorageConfigWrapper {
78-
storage: StorageConfig,
79-
}
80-
8177
/// Loads the Storage daemon configuration from `storage_daemon_server/storage_config.yaml`.
8278
pub fn load_storage_config(config_file_path: Option<PathBuf>) -> Result<StorageConfig, anyhow::Error> {
8379
let default_config_path = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
84-
.parent() // Go up to the workspace root of the server crate
80+
.parent()
8581
.ok_or_else(|| anyhow::anyhow!("Failed to get parent directory of server crate"))?
8682
.join("storage_daemon_server")
8783
.join("storage_config.yaml");
@@ -91,25 +87,23 @@ pub fn load_storage_config(config_file_path: Option<PathBuf>) -> Result<StorageC
9187
let config_content = fs::read_to_string(&path_to_use)
9288
.map_err(|e| anyhow::anyhow!("Failed to read storage config file {}: {}", path_to_use.display(), e))?;
9389

94-
// Change from serde_yaml::from_str to serde_yaml2::from_str
95-
let wrapper: StorageConfigWrapper = serde_yaml2::from_str(&config_content) // <--- Changed here
90+
let wrapper: ConfigWrapper = serde_yaml2::from_str(&config_content)
9691
.map_err(|e| anyhow::anyhow!("Failed to parse storage config file {}: {}", path_to_use.display(), e))?;
9792

9893
Ok(wrapper.storage)
9994
}
10095

10196
/// Function to get default REST API port from config
10297
pub fn get_default_rest_port_from_config() -> u16 {
103-
8082 // Default REST API port
98+
8082
10499
}
105100

106101
/// Enum for different storage engine types.
107102
#[derive(Debug, Clone, PartialEq, Eq)]
108103
pub enum StorageEngineType {
109104
Sled,
110105
RocksDB,
111-
InMemory, // Added InMemory option to align with lib and daemon_api
112-
// Add other storage engine types here
106+
InMemory,
113107
}
114108

115109
impl FromStr for StorageEngineType {
@@ -119,7 +113,7 @@ impl FromStr for StorageEngineType {
119113
match s.to_lowercase().as_str() {
120114
"sled" => Ok(StorageEngineType::Sled),
121115
"rocksdb" => Ok(StorageEngineType::RocksDB),
122-
"inmemory" => Ok(StorageEngineType::InMemory), // Added InMemory
116+
"inmemory" => Ok(StorageEngineType::InMemory),
123117
_ => Err(anyhow::anyhow!("Unknown storage engine type: {}", s)),
124118
}
125119
}
@@ -130,13 +124,11 @@ impl ToString for StorageEngineType {
130124
match self {
131125
StorageEngineType::Sled => "sled".to_string(),
132126
StorageEngineType::RocksDB => "rocksdb".to_string(),
133-
StorageEngineType::InMemory => "inmemory".to_string(), // Added InMemory
127+
StorageEngineType::InMemory => "inmemory".to_string(),
134128
}
135129
}
136130
}
137131

138-
// Added: From implementation to convert from cli::config::StorageEngineType
139-
// to daemon_api::StorageEngineType
140132
impl From<StorageEngineType> for DaemonApiStorageEngineType {
141133
fn from(cli_type: StorageEngineType) -> Self {
142134
match cli_type {
@@ -145,5 +137,4 @@ impl From<StorageEngineType> for DaemonApiStorageEngineType {
145137
StorageEngineType::InMemory => DaemonApiStorageEngineType::InMemory,
146138
}
147139
}
148-
}
149-
140+
}

0 commit comments

Comments
 (0)