Skip to content

Commit e48d9c8

Browse files
authored
Merge pull request #285 from akshaylg0314/main
feat(api)-Define more REST APIs DELETE POST on SettingsService for Dashboard[#264]
2 parents 4ef0da5 + 5aa726b commit e48d9c8

File tree

24 files changed

+1202
-309
lines changed

24 files changed

+1202
-309
lines changed

src/Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ clean:
1212
cargo clean --manifest-path=player/Cargo.toml
1313
cargo clean --manifest-path=server/Cargo.toml
1414
cargo clean --manifest-path=tools/Cargo.toml
15+
cargo clean --manifest-path=agent/Cargo.toml
1516

1617
.PHONY: tool
1718
tool:
@@ -23,10 +24,12 @@ fmt:
2324
cd player && cargo fmt
2425
cd server && cargo fmt
2526
cd tools && cargo fmt
27+
cd agent && cargo fmt
2628

2729
.PHONY: clippy
2830
clippy:
2931
cd common && cargo clippy
3032
cd player && cargo clippy
3133
cd server && cargo clippy
32-
cd tools && cargo clippy
34+
cd tools && cargo clippy
35+
cd agent && cargo clippy

src/agent/nodeagent/src/bluechi/filemaker.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,18 @@ pub async fn make_symlink(node_name: &str, model_name: &str) -> common::Result<(
4343
crate::config::Config::get().get_yaml_storage(),
4444
model_name
4545
);
46-
46+
4747
// Make sure original file exists
4848
if !std::path::Path::new(&original).exists() {
4949
return Err(format!("Original file '{}' does not exist", original).into());
5050
}
51-
51+
5252
// Make sure SYSTEMD_PATH exists
5353
if !std::path::Path::new(SYSTEMD_PATH).exists() {
5454
println!("Creating directory: {}", SYSTEMD_PATH);
5555
std::fs::create_dir_all(SYSTEMD_PATH)?;
5656
}
57-
57+
5858
let link = format!("{}{}.kube", SYSTEMD_PATH, model_name);
5959

6060
// Remove existing symlink if it exists

src/agent/nodeagent/src/config.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1+
use if_addrs::{get_if_addrs, Interface};
12
use serde::Deserialize;
23
use std::fs::File;
34
use std::io::Read;
45
use std::path::Path;
56
use std::sync::OnceLock;
6-
use if_addrs::{Interface, get_if_addrs};
77
use thiserror::Error;
88

9-
109
// Global config instance
1110
static NODEAGENT_CONFIG: OnceLock<Config> = OnceLock::new();
1211

@@ -90,7 +89,7 @@ impl Config {
9089
if !self.nodeagent.node_ip.is_empty() {
9190
return self.nodeagent.node_ip.clone();
9291
}
93-
92+
9493
// Otherwise try to get the first non-loopback IPv4 address
9594
if let Ok(interfaces) = get_network_interfaces() {
9695
for iface in interfaces {
@@ -101,7 +100,7 @@ impl Config {
101100
}
102101
}
103102
}
104-
103+
105104
// Fallback to master_ip if we couldn't determine the host IP
106105
self.nodeagent.master_ip.clone()
107106
}

src/agent/nodeagent/src/grpc/receiver.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ impl NodeAgentConnection for NodeAgentReceiver {
6868
// This is typically called by the master node, not the node itself
6969
let config = crate::config::Config::get();
7070
let master_ip = config.nodeagent.master_ip.clone();
71-
71+
7272
let response = NodeRegistrationResponse {
7373
success: true,
7474
message: "Node registration processed".to_string(),
@@ -115,7 +115,7 @@ impl NodeAgentConnection for NodeAgentReceiver {
115115

116116
let config = crate::config::Config::get();
117117
let master_ip = config.nodeagent.master_ip.clone();
118-
118+
119119
let response = HeartbeatResponse {
120120
ack: true,
121121
updated_config: Some(common::nodeagent::ClusterConfig {

src/agent/nodeagent/src/grpc/sender.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ impl NodeAgentSender {
7676
let config = crate::config::Config::get();
7777
let master_ip = config.nodeagent.master_ip.clone();
7878
let addr = format!("http://{}:47003", master_ip);
79-
79+
8080
let client = MonitoringServerConnectionClient::connect(addr).await;
8181

8282
match client {
@@ -115,7 +115,7 @@ impl NodeAgentSender {
115115
let config = crate::config::Config::get();
116116
let master_ip = config.nodeagent.master_ip.clone();
117117
let addr = format!("http://{}:47098", master_ip);
118-
118+
119119
let client = ApiServerConnectionClient::connect(addr).await;
120120

121121
match client {
@@ -147,7 +147,7 @@ impl NodeAgentSender {
147147
let config = crate::config::Config::get();
148148
let master_ip = config.nodeagent.master_ip.clone();
149149
let master_endpoint = format!("http://{}:47098", master_ip);
150-
150+
151151
Ok(tonic::Response::new(HeartbeatResponse {
152152
ack: true,
153153
updated_config: Some(common::nodeagent::ClusterConfig {

src/agent/nodeagent/src/main.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
//! This file sets up the asynchronous runtime, initializes the manager and gRPC server,
44
//! and launches both concurrently. It also provides unit tests for initialization.
55
6+
use clap::Parser;
67
use common::nodeagent::HandleYamlRequest;
78
use common::nodeagent::NodeRegistrationRequest;
8-
use clap::Parser;
99
use std::path::PathBuf;
1010
mod bluechi;
1111
pub mod config;
@@ -46,15 +46,15 @@ async fn launch_manager(
4646
metadata: std::collections::HashMap::new(),
4747
resources: None,
4848
node_type: match config.nodeagent.node_type.as_str() {
49-
"cloud" => 1, // NodeType::Cloud as i32
49+
"cloud" => 1, // NodeType::Cloud as i32
5050
"vehicle" => 2, // NodeType::Vehicle as i32
51-
_ => 0, // NodeType::Unspecified as i32
51+
_ => 0, // NodeType::Unspecified as i32
5252
},
5353
node_role: match config.nodeagent.node_role.as_str() {
54-
"master" => 1, // NodeRole::Master as i32
54+
"master" => 1, // NodeRole::Master as i32
5555
"nodeagent" => 2, // NodeRole::Nodeagent as i32
56-
"bluechi" => 3, // NodeRole::Bluechi as i32
57-
_ => 0, // NodeRole::Unspecified as i32
56+
"bluechi" => 3, // NodeRole::Bluechi as i32
57+
_ => 0, // NodeRole::Unspecified as i32
5858
},
5959
};
6060

@@ -128,7 +128,10 @@ async fn initialize(tx_grpc: Sender<HandleYamlRequest>, hostname: String, config
128128
.parse()
129129
.expect("nodeagent address parsing error");
130130
println!("NodeAgent listening on {}", addr);
131-
println!("NodeAgent config - master_ip: {}, grpc_port: {}", config.nodeagent.master_ip, config.nodeagent.grpc_port);
131+
println!(
132+
"NodeAgent config - master_ip: {}, grpc_port: {}",
133+
config.nodeagent.master_ip, config.nodeagent.grpc_port
134+
);
132135

133136
let _ = Server::builder()
134137
.add_service(NodeAgentConnectionServer::new(server))

src/common/src/lib.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -84,21 +84,21 @@ pub mod monitoringserver {
8484
pub mod nodeagent {
8585
tonic::include_proto!("nodeagent");
8686

87-
// pub fn open_server() -> String {
88-
// super::open_server(47004)
89-
// }
87+
// pub fn open_server() -> String {
88+
// super::open_server(47004)
89+
// }
9090

91-
// pub fn open_guest_server() -> String {
92-
// super::open_guest_server(47004)
93-
// }
91+
// pub fn open_guest_server() -> String {
92+
// super::open_guest_server(47004)
93+
// }
9494

95-
// pub fn connect_server() -> String {
96-
// super::connect_server(47004)
97-
// }
95+
// pub fn connect_server() -> String {
96+
// super::connect_server(47004)
97+
// }
9898

99-
// pub fn connect_guest_server() -> String {
100-
// super::connect_guest_server(47004)
101-
// }
99+
// pub fn connect_guest_server() -> String {
100+
// super::connect_guest_server(47004)
101+
// }
102102
}
103103

104104
pub mod policymanager {

src/common/src/setting.rs

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -89,21 +89,6 @@ mod tests {
8989
assert!(std::ptr::eq(config1, config2));
9090
}
9191

92-
// Test handling of multiple guests in the settings
93-
#[tokio::test]
94-
async fn test_parse_settings_yaml_multiple_guests() {
95-
// Verify that multiple guests are correctly parsed
96-
let settings = parse_settings_yaml();
97-
if let Some(guests) = settings.guest {
98-
assert!(guests.len() > 1);
99-
for guest in guests {
100-
assert_ne!(guest.name, "");
101-
assert_ne!(guest.ip, "");
102-
assert_ne!(guest.r#type, "");
103-
}
104-
}
105-
}
106-
10792
// Test concurrent access to `get_config`
10893
#[tokio::test]
10994
async fn test_get_config_concurrent_access() {
@@ -158,44 +143,6 @@ mod tests {
158143
assert!(valid_types.contains(&settings.host.r#type.as_str()));
159144
}
160145

161-
// Test handling of a settings file with guests having invalid types
162-
#[tokio::test]
163-
async fn test_parse_settings_yaml_invalid_guest_types() {
164-
// Verify that guest types are valid
165-
let settings = parse_settings_yaml();
166-
if let Some(guests) = settings.guest {
167-
let valid_types = vec!["nodeagent", "zoneagent", "cloudagent"];
168-
for guest in guests {
169-
assert!(valid_types.contains(&guest.r#type.as_str()));
170-
}
171-
}
172-
}
173-
174-
// Test handling of a settings file with guests having missing names
175-
#[tokio::test]
176-
async fn test_parse_settings_yaml_guest_missing_names() {
177-
// Verify that guest names are not missing
178-
let settings = parse_settings_yaml();
179-
if let Some(guests) = settings.guest {
180-
for guest in guests {
181-
assert_ne!(guest.name, "");
182-
}
183-
}
184-
}
185-
186-
// Test handling of a settings file with guests having duplicate IPs
187-
#[tokio::test]
188-
async fn test_parse_settings_yaml_guest_duplicate_ips() {
189-
// Verify that guest IPs are unique
190-
let settings = parse_settings_yaml();
191-
if let Some(guests) = settings.guest {
192-
let mut ips: Vec<String> = guests.iter().map(|guest| guest.ip.clone()).collect();
193-
ips.sort();
194-
ips.dedup();
195-
assert_eq!(ips.len(), guests.len());
196-
}
197-
}
198-
199146
// Test handling of invalid YAML file path
200147
#[tokio::test]
201148
async fn test_parse_settings_yaml_invalid_file_path() {

src/player/actioncontroller/src/grpc/sender/policymanager.rs

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ pub async fn check_policy(scenario_name: String) -> Result<()> {
6868
}
6969
}
7070

71-
7271
// ===========================
7372
// UNIT TESTS
7473
// ===========================
@@ -98,31 +97,4 @@ mod tests {
9897
let result = check_policy(scenario_name).await;
9998
assert!(result.is_err());
10099
}
101-
102-
#[tokio::test]
103-
async fn test_handle_workload_success() {
104-
let workload_name = "test-workload".to_string();
105-
let action = 1;
106-
let description = "example description".to_string();
107-
108-
let result = handle_yaml(workload_name).await;
109-
if let Err(ref e) = result {
110-
println!("Error in test_handle_workload_success: {:?}", e);
111-
} else {
112-
println!("test_handle_workload_success successful");
113-
}
114-
assert!(result.is_ok());
115-
}
116-
117-
#[tokio::test]
118-
async fn test_handle_workload_failure_invalid_workload() {
119-
// Sending invalid workload_name and invalid action to trigger failure
120-
let workload_name = "".to_string(); // Invalid empty workload
121-
let action = -999; // Invalid action code
122-
let description = "".to_string(); // Empty description
123-
124-
let result = handle_yaml(workload_name).await;
125-
126-
assert!(result.is_err());
127-
}
128100
}

src/player/actioncontroller/src/main.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,19 @@ async fn initialize(skip_grpc: bool) -> Result<(), Box<dyn Error>> {
2020
// 기본 설정 정보에서 노드 역할 확인
2121
let config = common::setting::get_config();
2222
let mut manager = manager::ActionControllerManager::new();
23-
23+
2424
// 설정 파일의 호스트 정보 확인 (노드 역할 사전 설정)
2525
let hostname = &config.host.name;
2626
let node_type = &config.host.r#type;
27-
27+
2828
if node_type == "bluechi" {
2929
println!("Adding {} to bluechi_nodes from settings.yaml", hostname);
3030
manager.bluechi_nodes.push(hostname.clone());
3131
} else {
3232
println!("Adding {} to nodeagent_nodes from settings.yaml", hostname);
3333
manager.nodeagent_nodes.push(hostname.clone());
3434
}
35-
35+
3636
// gRPC 서버 초기화 (테스트 모드가 아닌 경우)
3737
if !skip_grpc {
3838
grpc::init(manager).await?;

0 commit comments

Comments
 (0)