rocketmq-admin-cli 1.1.0

Command-line interface for managing RocketMQ-Rust and Apache RocketMQ clusters
// Copyright 2023 The RocketMQ Rust Authors
//
// Licensed 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.

mod allocate_mq_sub_command;
mod delete_topic_sub_command;
mod remapping_static_topic_sub_command;
mod static_topic_file;
mod topic_cluster_sub_command;
mod topic_list_sub_command;
mod topic_route_sub_command;
mod topic_status_sub_command;
mod update_order_conf_sub_command;
mod update_static_topic_sub_command;
mod update_topic_list_sub_command;
mod update_topic_perm_sub_command;
mod update_topic_sub_command;

use clap::Subcommand;
use rocketmq_error::Result as CanonicalResult;

use crate::commands::CommandExecute;
use crate::commands::topic::allocate_mq_sub_command::AllocateMQSubCommand;
use crate::commands::topic::delete_topic_sub_command::DeleteTopicSubCommand;
use crate::commands::topic::remapping_static_topic_sub_command::RemappingStaticTopicSubCommand;
use crate::commands::topic::topic_cluster_sub_command::TopicClusterSubCommand;
use crate::commands::topic::topic_list_sub_command::TopicListSubCommand;
use crate::commands::topic::topic_route_sub_command::TopicRouteSubCommand;
use crate::commands::topic::topic_status_sub_command::TopicStatusSubCommand;
use crate::commands::topic::update_order_conf_sub_command::UpdateOrderConfSubCommand;
use crate::commands::topic::update_static_topic_sub_command::UpdateStaticTopicSubCommand;
use crate::commands::topic::update_topic_list_sub_command::UpdateTopicListSubCommand;
use crate::commands::topic::update_topic_perm_sub_command::UpdateTopicPermSubCommand;
use crate::commands::topic::update_topic_sub_command::UpdateTopicSubCommand;
#[derive(Subcommand)]
pub enum TopicCommands {
    #[command(
        name = "allocateMQ",
        about = "Allocate memory space for each topic",
        long_about = r#"Allocate memory space for each topic, which is used to allocate the memory
space of the topic when the topic is created. The default value is 1. If you want to allocate
more memory space, you can use this command to allocate it."#
    )]
    AllocateMQ(AllocateMQSubCommand),

    #[command(
        name = "deleteTopic",
        about = "Delete topic",
        long_about = r#"Delete topic from broker and NameServer."#
    )]
    DeleteTopic(DeleteTopicSubCommand),

    #[command(
        name = "remappingStaticTopic",
        about = "Remapping static topic",
        long_about = r#"Remapping static topic to different brokers or clusters."#
    )]
    RemappingStaticTopic(RemappingStaticTopicSubCommand),

    #[command(
        name = "topicClusterList",
        about = "Get cluster info for topic",
        long_about = r#"Get cluster info for a given topic. This command queries which clusters contain the specified topic."#
    )]
    TopicCluster(TopicClusterSubCommand),

    #[command(
        name = "topicList",
        about = "Get topic list",
        long_about = r#"Fetch all topic list from name server."#
    )]
    TopicList(TopicListSubCommand),

    #[command(
        name = "topicRoute",
        about = "Examine topic route info",
        long_about = r#"Examine topic route info."#
    )]
    TopicRoute(TopicRouteSubCommand),

    #[command(
        name = "topicStatus",
        about = "Examine topic status info",
        long_about = r#"Examine topic status info."#
    )]
    TopicStatus(TopicStatusSubCommand),

    #[command(
        name = "updateOrderConf",
        about = "Create or update order conf",
        long_about = r#"Create, update, or delete order topic configuration."#
    )]
    UpdateOrderConf(UpdateOrderConfSubCommand),

    #[command(
        name = "updateStaticTopic",
        about = "Update static topic",
        long_about = r#"Update or create static topic with queue mapping."#
    )]
    UpdateStaticTopic(UpdateStaticTopicSubCommand),

    #[command(
        name = "updateTopicList",
        about = "Update topic list",
        long_about = "Update topic list with specified configuration."
    )]
    UpdateTopicList(UpdateTopicListSubCommand),

    #[command(
        name = "updateTopicPerm",
        about = "Update topic perm.",
        long_about = r#"Update topic perm."#
    )]
    UpdateTopicPerm(UpdateTopicPermSubCommand),

    #[command(
        name = "updateTopic",
        about = "Update or create topic",
        long_about = r#"Update or create topic with specified configuration."#
    )]
    UpdateTopic(UpdateTopicSubCommand),
}

impl CommandExecute for TopicCommands {
    async fn execute(
        &self,
        credentials: Option<rocketmq_admin_core::core::security::AdminCredentials>,
        client_runtime: std::sync::Arc<rocketmq_admin_core::client_adapter::ClientRuntime>,
    ) -> CanonicalResult<()> {
        match self {
            TopicCommands::AllocateMQ(cmd) => cmd.execute(credentials, client_runtime.clone()).await,
            TopicCommands::DeleteTopic(cmd) => cmd.execute(credentials, client_runtime.clone()).await,
            TopicCommands::RemappingStaticTopic(cmd) => cmd.execute(credentials, client_runtime.clone()).await,
            TopicCommands::TopicCluster(cmd) => cmd.execute(credentials, client_runtime.clone()).await,
            TopicCommands::TopicList(cmd) => cmd.execute(credentials, client_runtime.clone()).await,
            TopicCommands::TopicRoute(cmd) => cmd.execute(credentials, client_runtime.clone()).await,
            TopicCommands::TopicStatus(cmd) => cmd.execute(credentials, client_runtime.clone()).await,
            TopicCommands::UpdateOrderConf(cmd) => cmd.execute(credentials, client_runtime.clone()).await,
            TopicCommands::UpdateStaticTopic(cmd) => cmd.execute(credentials, client_runtime.clone()).await,
            TopicCommands::UpdateTopicList(cmd) => cmd.execute(credentials, client_runtime.clone()).await,
            TopicCommands::UpdateTopicPerm(cmd) => cmd.execute(credentials, client_runtime.clone()).await,
            TopicCommands::UpdateTopic(cmd) => cmd.execute(credentials, client_runtime.clone()).await,
        }
    }
}