Skip to content
Merged
Show file tree
Hide file tree
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
121 changes: 121 additions & 0 deletions core/binary_protocol/src/cli/binary_cluster/get_cluster_metadata.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

use crate::Client;
use crate::cli::cli_command::{CliCommand, PRINT_TARGET};
use anyhow::Context;
use async_trait::async_trait;
use comfy_table::Table;
use tracing::{Level, event};

pub enum GetClusterMetadataOutput {
Table,
List,
}

pub struct GetClusterMetadataCmd {
output: GetClusterMetadataOutput,
}

impl GetClusterMetadataCmd {
pub fn new(output: GetClusterMetadataOutput) -> Self {
GetClusterMetadataCmd { output }
}
}

impl Default for GetClusterMetadataCmd {
fn default() -> Self {
GetClusterMetadataCmd {
output: GetClusterMetadataOutput::Table,
}
}
}

#[async_trait]
impl CliCommand for GetClusterMetadataCmd {
fn explain(&self) -> String {
let mode = match self.output {
GetClusterMetadataOutput::Table => "table",
GetClusterMetadataOutput::List => "list",
};
format!("get cluster metadata in {mode} mode")
}

async fn execute_cmd(&mut self, client: &dyn Client) -> anyhow::Result<(), anyhow::Error> {
let cluster_metadata = client
.get_cluster_metadata()
.await
.with_context(|| String::from("Problem getting cluster metadata"))?;

if cluster_metadata.nodes.is_empty() {
event!(target: PRINT_TARGET, Level::INFO, "No cluster nodes found!");
return Ok(());
}

event!(target: PRINT_TARGET, Level::INFO, "Cluster name: {}", cluster_metadata.name);

match self.output {
GetClusterMetadataOutput::Table => {
let mut table = Table::new();

table.set_header(vec![
"Name",
"IP",
"TCP",
"QUIC",
"HTTP",
"WebSocket",
"Role",
"Status",
]);

cluster_metadata.nodes.iter().for_each(|node| {
table.add_row(vec![
node.name.to_string(),
node.ip.to_string(),
node.endpoints.tcp.to_string(),
node.endpoints.quic.to_string(),
node.endpoints.http.to_string(),
node.endpoints.websocket.to_string(),
node.role.to_string(),
node.status.to_string(),
]);
});

event!(target: PRINT_TARGET, Level::INFO, "{table}");
}
GetClusterMetadataOutput::List => {
cluster_metadata.nodes.iter().for_each(|node| {
event!(target: PRINT_TARGET, Level::INFO,
"{}|{}|{}|{}|{}|{}|{}|{}",
node.name,
node.ip,
node.endpoints.tcp,
node.endpoints.quic,
node.endpoints.http,
node.endpoints.websocket,
node.role,
node.status
);
});
}
}

Ok(())
}
}
19 changes: 19 additions & 0 deletions core/binary_protocol/src/cli/binary_cluster/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

pub mod get_cluster_metadata;
1 change: 1 addition & 0 deletions core/binary_protocol/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/

pub mod binary_client;
pub mod binary_cluster;
pub mod binary_consumer_groups;
pub mod binary_consumer_offsets;
pub mod binary_context;
Expand Down
5 changes: 3 additions & 2 deletions core/binary_protocol/src/client/binary_clients/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/

use crate::{
ConsumerGroupClient, ConsumerOffsetClient, MessageClient, PartitionClient,
ClusterClient, ConsumerGroupClient, ConsumerOffsetClient, MessageClient, PartitionClient,
PersonalAccessTokenClient, SegmentClient, StreamClient, SystemClient, TopicClient, UserClient,
};
use async_broadcast::Receiver;
Expand All @@ -30,7 +30,8 @@ use std::fmt::Debug;
/// Except the ping, login and get me, all the other methods require authentication.
#[async_trait]
pub trait Client:
SystemClient
ClusterClient
+ SystemClient
+ UserClient
+ PersonalAccessTokenClient
+ StreamClient
Expand Down
33 changes: 33 additions & 0 deletions core/cli/src/args/cluster.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

use crate::args::common::ListMode;
use clap::{Args, Subcommand};

#[derive(Debug, Clone, Subcommand)]
pub(crate) enum ClusterAction {
/// Get cluster metadata
#[clap(visible_alias = "m")]
Metadata(ClusterMetadataArgs),
}

#[derive(Debug, Clone, Args)]
pub(crate) struct ClusterMetadataArgs {
#[clap(short, long, value_enum, default_value_t = ListMode::Table)]
pub(crate) list_mode: ListMode,
}
10 changes: 10 additions & 0 deletions core/cli/src/args/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

use clap::ValueEnum;
use iggy_binary_protocol::cli::binary_client::get_clients::GetClientsOutput;
use iggy_binary_protocol::cli::binary_cluster::get_cluster_metadata::GetClusterMetadataOutput;
use iggy_binary_protocol::cli::binary_consumer_groups::get_consumer_groups::GetConsumerGroupsOutput;
use iggy_binary_protocol::cli::binary_context::get_contexts::GetContextsOutput;
use iggy_binary_protocol::cli::binary_personal_access_tokens::get_personal_access_tokens::GetPersonalAccessTokensOutput;
Expand All @@ -32,6 +33,15 @@ pub(crate) enum ListMode {
List,
}

impl From<ListMode> for GetClusterMetadataOutput {
fn from(mode: ListMode) -> Self {
match mode {
ListMode::Table => GetClusterMetadataOutput::Table,
ListMode::List => GetClusterMetadataOutput::List,
}
}
}

impl From<ListMode> for GetStreamsOutput {
fn from(mode: ListMode) -> Self {
match mode {
Expand Down
5 changes: 5 additions & 0 deletions core/cli/src/args/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ use system::SnapshotArgs;

use crate::args::{
client::ClientAction,
cluster::ClusterAction,
consumer_group::ConsumerGroupAction,
consumer_offset::ConsumerOffsetAction,
context::ContextAction,
Expand All @@ -47,6 +48,7 @@ use crate::args::system::LoginArgs;
use self::user::UserAction;

pub(crate) mod client;
pub(crate) mod cluster;
pub(crate) mod common;
pub(crate) mod consumer_group;
pub(crate) mod consumer_offset;
Expand Down Expand Up @@ -173,6 +175,9 @@ pub(crate) enum Command {
/// client operations
#[command(subcommand, visible_alias = "c")]
Client(ClientAction),
/// cluster operations
#[command(subcommand, visible_alias = "cl")]
Cluster(ClusterAction),
/// consumer group operations
#[command(subcommand, visible_alias = "g")]
ConsumerGroup(ConsumerGroupAction),
Expand Down
13 changes: 10 additions & 3 deletions core/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ mod error;
mod logging;

use crate::args::{
Command, IggyConsoleArgs, client::ClientAction, consumer_group::ConsumerGroupAction,
consumer_offset::ConsumerOffsetAction, permissions::PermissionsArgs,
personal_access_token::PersonalAccessTokenAction, stream::StreamAction, topic::TopicAction,
Command, IggyConsoleArgs, client::ClientAction, cluster::ClusterAction,
consumer_group::ConsumerGroupAction, consumer_offset::ConsumerOffsetAction,
permissions::PermissionsArgs, personal_access_token::PersonalAccessTokenAction,
stream::StreamAction, topic::TopicAction,
};
use crate::credentials::IggyCredentials;
use crate::error::{CmdToolError, IggyCmdError};
Expand All @@ -46,6 +47,7 @@ use iggy_binary_protocol::cli::binary_system::snapshot::GetSnapshotCmd;
use iggy_binary_protocol::cli::cli_command::{CliCommand, PRINT_TARGET};
use iggy_binary_protocol::cli::{
binary_client::{get_client::GetClientCmd, get_clients::GetClientsCmd},
binary_cluster::get_cluster_metadata::GetClusterMetadataCmd,
binary_consumer_groups::{
create_consumer_group::CreateConsumerGroupCmd,
delete_consumer_group::DeleteConsumerGroupCmd, get_consumer_group::GetConsumerGroupCmd,
Expand Down Expand Up @@ -244,6 +246,11 @@ fn get_command(
Box::new(GetClientsCmd::new(list_args.list_mode.into()))
}
},
Command::Cluster(command) => match command {
ClusterAction::Metadata(args) => {
Box::new(GetClusterMetadataCmd::new(args.list_mode.into()))
}
},
Command::ConsumerGroup(command) => match command {
ConsumerGroupAction::Create(create_args) => Box::new(CreateConsumerGroupCmd::new(
create_args.stream_id.clone(),
Expand Down
1 change: 1 addition & 0 deletions core/integration/tests/cli/general/test_help_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Commands:
pat personal access token operations
user user operations [aliases: u]
client client operations [aliases: c]
cluster cluster operations [aliases: cl]
consumer-group consumer group operations [aliases: g]
consumer-offset consumer offset operations [aliases: o]
message message operations [aliases: m]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ Commands:
pat personal access token operations
user user operations [aliases: u]
client client operations [aliases: c]
cluster cluster operations [aliases: cl]
consumer-group consumer group operations [aliases: g]
consumer-offset consumer offset operations [aliases: o]
message message operations [aliases: m]
Expand Down
1 change: 1 addition & 0 deletions core/integration/tests/cli/system/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
// due to missing keyring support while running tests under cross
#[cfg(not(any(target_os = "macos", target_env = "musl")))]
mod test_cli_session_scenario;
mod test_cluster_metadata_command;
#[cfg(not(any(target_os = "macos", target_env = "musl")))]
mod test_login_cmd;
mod test_login_command;
Expand Down
Loading
Loading