Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add InstanceQuery::List reply #260

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 31 additions & 2 deletions zfctl/src/instance_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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}");
}
_ => {}
}

Expand Down
Loading