Skip to content

Commit

Permalink
Make Node have as_is and to_be fields; update Node Graphql APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
sophie-cluml committed Feb 21, 2024
1 parent 57b0e98 commit 9182bec
Show file tree
Hide file tree
Showing 10 changed files with 1,561 additions and 729 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/target
/Cargo.lock
.vscode
15 changes: 12 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,19 @@ Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added
### Changed

- Add `apply_target_id` field to `Node` struct for reverting node status.
- Add `apply_in_progress` field to `Node` struct for reverting node status.
- `Node` struct now has `as_is` and `to_be` `NodeSetting`s to support 2-step
node setting save & apply. `NodeInput` accordingly has `as_is` and `to_be`.
`to_be` field means the setting is only saved to the database. Once the
setting is applied, the values in `to_be` field is moved to `as_is` field.
- `graphql::event::convert_sensors` uses `Node`'s `as_is` value, to retrieve
the hostnames of the sensors. This function is called by GraphQL APIs of
`EventQuery` and `EventGroupQuery`.
- `graphql::node::crud::get_node_settings` uses `Node`'s `as_is` value.
- `node_status_list` API uses `hostname` and `name` values from `Node`'s
`as_is` field, prioritizing their presence. If `as_is` is not present, it
resorts to using `to_be` values instead.

### Fixed

Expand Down
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ ipnet = { version = "2", features = ["serde"] }
jsonwebtoken = "9"
lazy_static = "1"
num-traits = "0.2"
oinq = { git = "https://github.com/petabi/oinq.git", tag = "0.9.1" }
# oinq = { git = "https://github.com/petabi/oinq.git", tag = "0.9.1" }
oinq = { git = "https://github.com/sophie-cluml/oinq.git", branch = "sophie/enum-configs" } # pita in discussion https://github.com/petabi/oinq/issues/58
reqwest = { version = "0.11", default-features = false, features = [
"rustls-tls-native-roots",
] }
Expand All @@ -39,6 +40,7 @@ tracing = "0.1"
vinum = { git = "https://github.com/vinesystems/vinum.git", tag = "1.0.3" }

[dev-dependencies]
assert-json-diff = "2.0.2"
config = { version = "0.13", features = ["toml"], default-features = false }
futures = "0.3"
tempfile = "3"
Expand Down
10 changes: 7 additions & 3 deletions src/graphql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ pub trait AgentManager: Send + Sync {
async fn broadcast_trusted_user_agent_list(&self, _list: &[u8]) -> Result<(), anyhow::Error>;
async fn online_apps_by_host_id(
&self,
) -> Result<HashMap<String, Vec<(String, String)>>, anyhow::Error>;
) -> Result<HashMap<String, Vec<(String, String)>>, anyhow::Error>; // (hostname, (agent_key, app_name))
async fn send_and_recv(&self, key: &str, msg: &[u8]) -> Result<Vec<u8>, anyhow::Error>;
async fn update_traffic_filter_rules(
&self,
Expand Down Expand Up @@ -554,7 +554,7 @@ impl AgentManager for MockAgentManager {
Ok(HashMap::new())
}
async fn send_and_recv(&self, _key: &str, _msg: &[u8]) -> Result<Vec<u8>, anyhow::Error> {
unimplemented!()
Ok(vec![])
}
async fn update_traffic_filter_rules(
&self,
Expand All @@ -575,14 +575,18 @@ struct TestSchema {
#[cfg(test)]
impl TestSchema {
async fn new() -> Self {
let agent_manager: BoxedAgentManager = Box::new(MockAgentManager {});
Self::new_with(agent_manager).await
}

async fn new_with(agent_manager: BoxedAgentManager) -> Self {
use self::account::set_initial_admin_password;

let db_dir = tempfile::tempdir().unwrap();
let backup_dir = tempfile::tempdir().unwrap();
let store = Store::new(db_dir.path(), backup_dir.path()).unwrap();
let _ = set_initial_admin_password(&store);
let store = Arc::new(RwLock::new(store));
let agent_manager: BoxedAgentManager = Box::new(MockAgentManager {});
let schema = Schema::build(
Query::default(),
Mutation::default(),
Expand Down
8 changes: 6 additions & 2 deletions src/graphql/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -932,11 +932,15 @@ fn convert_sensors(map: &IndexedMap, sensors: &[ID]) -> anyhow::Result<Vec<Strin
let Some(value) = map.get_by_id(i)? else {
bail!("no such sensor")
};
let value: super::node::Node = codec
let node: super::node::Node = codec
.deserialize(value.as_ref())
.context("invalid value in database")?;

converted_sensors.push(value.hostname.clone());
if let Some(as_is) = node.as_is {
converted_sensors.push(as_is.hostname.clone());
} else {
bail!("node is not yet fully configured");
}
}
Ok(converted_sensors)
}
Expand Down
Loading

0 comments on commit 9182bec

Please sign in to comment.