-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(zfctl): implement
InstanceQuery::List
reply (#260)
- Loading branch information
Showing
1 changed file
with
31 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,17 +12,18 @@ | |
// ZettaScale Zenoh Team, <[email protected]> | ||
// | ||
|
||
use std::path::PathBuf; | ||
use std::{collections::HashMap, path::PathBuf, sync::Arc}; | ||
|
||
use anyhow::{anyhow, bail}; | ||
use clap::Subcommand; | ||
use comfy_table::Table; | ||
use itertools::Itertools; | ||
use uuid::Uuid; | ||
use zenoh::prelude::r#async::*; | ||
use zenoh_flow_commons::{parse_vars, Result, RuntimeId, Vars}; | ||
use zenoh_flow_commons::{parse_vars, InstanceId, Result, RuntimeId, Vars}; | ||
use zenoh_flow_daemon::queries::*; | ||
use zenoh_flow_descriptors::{DataFlowDescriptor, FlattenedDataFlowDescriptor}; | ||
use zenoh_flow_runtime::InstanceState; | ||
|
||
use super::ZENOH_FLOW_INTERNAL_ERROR; | ||
use crate::row; | ||
|
@@ -195,6 +196,34 @@ Caused by: | |
|
||
println!("{table}"); | ||
} | ||
InstancesQuery::List => { | ||
let mut table = Table::new(); | ||
table.set_width(80); | ||
table.set_header(row!("Instance Name", "Instance ID", "Instance State")); | ||
while let Ok(response) = reply.recv_async().await { | ||
match response.sample { | ||
Ok(sample) => { | ||
match serde_json::from_slice::< | ||
HashMap<InstanceId, (Arc<str>, InstanceState)>, | ||
>(&sample.value.payload.contiguous()) | ||
{ | ||
Ok(list) => { | ||
for (id, (name, state)) in list { | ||
table.add_row(row!(name, id, state)); | ||
} | ||
} | ||
Err(e) => tracing::error!( | ||
"Failed to parse 'list' reply from < {} >: {:?}", | ||
response.replier_id, | ||
e | ||
), | ||
} | ||
} | ||
Err(err) => tracing::error!("{:?}", err), | ||
} | ||
} | ||
println!("{table}"); | ||
} | ||
_ => {} | ||
} | ||
|
||
|