Skip to content

Commit

Permalink
feat: expose io-engine version via rest
Browse files Browse the repository at this point in the history
Signed-off-by: Tiago Castro <tiagolobocastro@gmail.com>
  • Loading branch information
tiagolobocastro committed Jun 12, 2024
1 parent 08e25af commit 9dfb153
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ mod tests {
NodeStatus::Online,
None,
None,
None,
);
NodeWrapper::new_stub(&state)
}
Expand Down
28 changes: 22 additions & 6 deletions control-plane/agents/src/bin/core/tests/node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ fn new_node(
status: NodeStatus,
api_versions: Option<Vec<ApiVersion>>,
node_nqn: Option<HostNqn>,
version: &Option<String>,
) -> Node {
let endpoint = std::str::FromStr::from_str(&endpoint).unwrap();
Node::new(
Expand All @@ -25,9 +26,16 @@ fn new_node(
node_nqn.clone(),
None,
None,
None,
version.clone(),
)),
Some(NodeState::new(
id,
endpoint,
status,
api_versions,
node_nqn,
version.clone(),
)),
Some(NodeState::new(id, endpoint, status, api_versions, node_nqn)),
)
}

Expand All @@ -54,14 +62,19 @@ async fn node() {
let nodes = node_client.get(Filter::None, false, None).await.unwrap();
tracing::info!("Nodes: {:?}", nodes);
assert_eq!(nodes.0.len(), 1);
let version = nodes
.0
.first()
.and_then(|n| n.state().and_then(|n| n.version.clone()));
assert_eq!(
nodes.0.first().unwrap(),
&new_node(
maya_name.clone(),
grpc.clone(),
NodeStatus::Online,
None,
Some(HostNqn::from_nodename(&maya_name.to_string()))
Some(HostNqn::from_nodename(&maya_name.to_string())),
&version
)
);
tokio::time::sleep(std::time::Duration::from_secs(2)).await;
Expand All @@ -76,7 +89,8 @@ async fn node() {
grpc.clone(),
NodeStatus::Online,
None,
Some(HostNqn::from_nodename(&maya_name.to_string()))
Some(HostNqn::from_nodename(&maya_name.to_string())),
&version
)
);

Expand All @@ -92,7 +106,8 @@ async fn node() {
grpc.clone(),
NodeStatus::Offline,
None,
Some(HostNqn::from_nodename(&maya_name.to_string()))
Some(HostNqn::from_nodename(&maya_name.to_string())),
&version
)
);
cluster.composer().start(maya_name.as_str()).await.unwrap();
Expand All @@ -114,7 +129,8 @@ async fn node() {
grpc.clone(),
NodeStatus::Online,
None,
Some(HostNqn::from_nodename(&maya_name.to_string()))
Some(HostNqn::from_nodename(&maya_name.to_string())),
&version
)
);

Expand Down
2 changes: 0 additions & 2 deletions control-plane/agents/src/bin/core/tests/volume/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -604,8 +604,6 @@ async fn snapshot_upgrade() {
b.with_io_engines(2)
.with_idle_io_engines(2)
.with_io_engine_tag("v2.6.1")
// testing: remove me
.with_idle_io_engine_bin("~/git/mayastor/io-engine/target/debug/io-engine-fix")
})
.build()
.await
Expand Down
14 changes: 9 additions & 5 deletions control-plane/grpc/proto/v1/node/target_node.proto
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ message NodeSpec {
optional CordonDrainState cordon_drain_state = 4;
// the host nqn
optional string node_nqn = 5;
// the io-engine version
optional string version = 6;
}

message NodeState {
Expand All @@ -39,6 +41,8 @@ message NodeState {
NodeStatus status = 3;
// the host nqn
optional string node_nqn = 4;
// the io-engine version
optional string version = 5;
}

// Multiple nodes
Expand Down Expand Up @@ -127,11 +131,11 @@ message DrainNodeReply {
}

message CordonDrainState {
oneof cordondrainstate {
CordonedState cordoned = 1;
DrainState draining = 2;
DrainState drained = 3;
}
oneof cordondrainstate {
CordonedState cordoned = 1;
DrainState draining = 2;
DrainState drained = 3;
}
}

message CordonedState {
Expand Down
5 changes: 4 additions & 1 deletion control-plane/grpc/src/operations/node/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl TryFrom<node::Node> for Node {
spec.node_nqn.try_into_opt()?,
None,
None,
None,
spec.version,
)),
None => None,
};
Expand All @@ -123,6 +123,7 @@ impl TryFrom<node::Node> for Node {
status,
None,
state.node_nqn.try_into_opt()?,
state.version,
))
}
None => None,
Expand Down Expand Up @@ -180,6 +181,7 @@ impl From<Node> for node::Node {
None => None,
},
node_nqn: types_v0_spec.node_nqn().as_ref().map(|nqn| nqn.to_string()),
version: types_v0_spec.version().clone(),
});
let grpc_node_state = match types_v0_node.state() {
None => None,
Expand All @@ -190,6 +192,7 @@ impl From<Node> for node::Node {
endpoint: types_v0_state.grpc_endpoint.to_string(),
status: grpc_node_status as i32,
node_nqn: types_v0_state.node_nqn.as_ref().map(|nqn| nqn.to_string()),
version: types_v0_state.version.clone(),
})
}
};
Expand Down
12 changes: 10 additions & 2 deletions control-plane/plugin/src/resources/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ use crate::{
operations::{Cordoning, Drain, GetWithArgs, Label, ListWithArgs, PluginResult},
resources::{
error::Error,
utils::{self, print_table, CreateRow, CreateRows, GetHeaderRow, OutputFormat},
utils::{
self, optional_cell, print_table, CreateRow, CreateRows, GetHeaderRow, OutputFormat,
},
NodeId,
},
rest_wrapper::RestClient,
Expand Down Expand Up @@ -75,6 +77,7 @@ impl CreateRow for openapi::models::Node {
grpc_endpoint: spec.grpc_endpoint,
status: openapi::models::NodeStatus::Unknown,
node_nqn: spec.node_nqn,
version: spec.version,
});
let statuses = match spec.cordondrainstate {
None => format!("{:?}", state.status),
Expand All @@ -98,7 +101,12 @@ impl CreateRow for openapi::models::Node {
)
}
};
row![self.id, state.grpc_endpoint, statuses]
row![
self.id,
state.grpc_endpoint,
statuses,
optional_cell(state.version)
]
}
}

Expand Down
2 changes: 1 addition & 1 deletion control-plane/plugin/src/resources/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ lazy_static! {
"AVAILABLE",
"COMMITTED"
];
pub static ref NODE_HEADERS: Row = row!["ID", "GRPC ENDPOINT", "STATUS"];
pub static ref NODE_HEADERS: Row = row!["ID", "GRPC ENDPOINT", "STATUS", "VERSION"];
pub static ref REPLICA_TOPOLOGIES_PREFIX: Row = row!["VOLUME-ID"];
pub static ref REPLICA_TOPOLOGY_HEADERS: Row = row![
"ID",
Expand Down
6 changes: 6 additions & 0 deletions control-plane/rest/openapi-specs/v0_api_spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2912,6 +2912,9 @@ components:
- $ref: '#/components/schemas/CordonDrainState'
node_nqn:
$ref: '#/components/schemas/HostNqn'
version:
description: Version of the io-engine instance
type: string
additionalProperties: false
required:
- grpcEndpoint
Expand All @@ -2933,6 +2936,9 @@ components:
$ref: '#/components/schemas/NodeStatus'
node_nqn:
$ref: '#/components/schemas/HostNqn'
version:
description: Version of the io-engine instance
type: string
required:
- grpcEndpoint
- id
Expand Down
6 changes: 5 additions & 1 deletion control-plane/rest/tests/v0_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ async fn client_test(cluster: &Cluster, auth: &bool) {
let io_engine2 = cluster.node(1);

let listed_node = client.nodes_api().get_node(io_engine1.as_str()).await;
let listed_node = listed_node.unwrap();
let version = listed_node.spec.as_ref().unwrap().version.clone();
let mut node = models::Node {
id: io_engine1.to_string(),
spec: Some(models::NodeSpec {
Expand All @@ -109,6 +111,7 @@ async fn client_test(cluster: &Cluster, auth: &bool) {
labels: None,
cordondrainstate: None,
node_nqn: Some(HostNqn::from_nodename(&io_engine1.to_string()).to_string()),
version: version.clone(),
}),
state: Some(models::NodeState {
id: io_engine1.to_string(),
Expand All @@ -118,9 +121,10 @@ async fn client_test(cluster: &Cluster, auth: &bool) {
),
status: models::NodeStatus::Online,
node_nqn: Some(HostNqn::from_nodename(&io_engine1.to_string()).to_string()),
version,
}),
};
assert_eq!(listed_node.unwrap(), node);
assert_eq!(listed_node, node);

let _ = client.pools_api().get_pools(None).await.unwrap();
let pool = client
Expand Down
1 change: 1 addition & 0 deletions control-plane/stor-port/src/types/v0/store/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,7 @@ impl From<NodeSpec> for models::NodeSpec {
labels,
src.cordon_drain_state.into_opt(),
src.node_nqn.into_opt(),
src.version,
)
}
}
Expand Down
4 changes: 3 additions & 1 deletion control-plane/stor-port/src/types/v0/transport/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ impl NodeState {
status: NodeStatus,
api_versions: Option<Vec<ApiVersion>>,
node_nqn: Option<HostNqn>,
version: Option<String>,
) -> Self {
Self {
id,
Expand All @@ -203,7 +204,7 @@ impl NodeState {
node_nqn,
features: None,
bugfixes: None,
version: None,
version,
}
}
/// Get the node identification.
Expand Down Expand Up @@ -256,6 +257,7 @@ impl From<NodeState> for models::NodeState {
src.id,
src.status,
src.node_nqn.into_opt(),
src.version,
)
}
}
Expand Down
2 changes: 1 addition & 1 deletion utils/dependencies
Submodule dependencies updated 0 files

0 comments on commit 9dfb153

Please sign in to comment.