rocketmq-admin-cli 1.0.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 broker_consume_stats_sub_command;
mod broker_status_sub_command;
mod clean_expired_cq_sub_command;
mod clean_unused_topic_sub_command;
mod commit_log_set_read_ahead_sub_command;
mod delete_expired_commit_log_sub_command;
mod get_broker_config_sub_command;
mod get_broker_epoch_sub_command;
mod get_cold_data_flow_ctr_info_sub_command;
mod remove_cold_data_flow_ctr_group_config_sub_command;
mod reset_master_flush_offset_sub_command;
mod send_msg_status_sub_command;
mod switch_timer_engine_sub_command;
mod update_broker_config_sub_command;
mod update_cold_data_flow_ctr_group_config_sub_command;

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

use crate::commands::CommandExecute;
use crate::commands::broker::broker_consume_stats_sub_command::BrokerConsumeStatsSubCommand;
use crate::commands::broker::broker_status_sub_command::BrokerStatusSubCommand;
use crate::commands::broker::clean_expired_cq_sub_command::CleanExpiredCQSubCommand;
use crate::commands::broker::clean_unused_topic_sub_command::CleanUnusedTopicSubCommand;
use crate::commands::broker::commit_log_set_read_ahead_sub_command::CommitLogSetReadAheadSubCommand;
use crate::commands::broker::delete_expired_commit_log_sub_command::DeleteExpiredCommitLogSubCommand;
use crate::commands::broker::get_broker_config_sub_command::GetBrokerConfigSubCommand;
use crate::commands::broker::get_broker_epoch_sub_command::GetBrokerEpochSubCommand;
use crate::commands::broker::get_cold_data_flow_ctr_info_sub_command::GetColdDataFlowCtrInfoSubCommand;
use crate::commands::broker::remove_cold_data_flow_ctr_group_config_sub_command::RemoveColdDataFlowCtrGroupConfigSubCommand;
use crate::commands::broker::reset_master_flush_offset_sub_command::ResetMasterFlushOffsetSubCommand;
use crate::commands::broker::send_msg_status_sub_command::SendMsgStatusSubCommand;
use crate::commands::broker::switch_timer_engine_sub_command::SwitchTimerEngineSubCommand;
use crate::commands::broker::update_broker_config_sub_command::UpdateBrokerConfigSubCommand;
use crate::commands::broker::update_cold_data_flow_ctr_group_config_sub_command::UpdateColdDataFlowCtrGroupConfigSubCommand;

#[derive(Subcommand)]
pub enum BrokerCommands {
    #[command(
        name = "brokerConsumeStats",
        about = "Fetch broker consume stats data.",
        long_about = None,
    )]
    BrokerConsumeStats(BrokerConsumeStatsSubCommand),

    #[command(
        name = "brokerStatus",
        about = "Fetch broker runtime status data.",
        long_about = None,
    )]
    BrokerStatus(BrokerStatusSubCommand),

    #[command(
        name = "cleanExpiredCQ",
        about = "Clean expired ConsumeQueue on broker.",
        long_about = None,
    )]
    CleanExpiredCQ(CleanExpiredCQSubCommand),

    #[command(
        name = "cleanUnusedTopic",
        about = "Clean unused topic on broker.",
        long_about = None,
    )]
    CleanUnusedTopic(CleanUnusedTopicSubCommand),

    #[command(
        name = "deleteExpiredCommitLog",
        about = "Delete expired CommitLog files.",
        long_about = None,
    )]
    DeleteExpiredCommitLog(DeleteExpiredCommitLogSubCommand),

    #[command(
        name = "getBrokerConfig",
        about = "Get broker config by cluster or special broker.",
        long_about = None,
    )]
    GetBrokerConfig(GetBrokerConfigSubCommand),

    #[command(
        name = "getBrokerEpoch",
        about = "Fetch broker epoch entries.",
        long_about = None,
    )]
    GetBrokerEpoch(GetBrokerEpochSubCommand),

    #[command(
        name = "getColdDataFlowCtrInfo",
        about = "Get cold data flow ctr info.",
        long_about = None,
    )]
    GetColdDataFlowCtrInfo(GetColdDataFlowCtrInfoSubCommand),

    #[command(
        name = "removeColdDataFlowCtrGroupConfig",
        about = "Remove consumer from cold ctr config.",
        long_about = None,
    )]
    RemoveColdDataFlowCtrGroupConfig(RemoveColdDataFlowCtrGroupConfigSubCommand),

    #[command(
        name = "resetMasterFlushOffset",
        about = "Reset master flush offset in slave.",
        long_about = None,
    )]
    ResetMasterFlushOffset(ResetMasterFlushOffsetSubCommand),

    #[command(
        name = "sendMsgStatus",
        about = "Send msg to broker.",
        long_about = None,
    )]
    SendMsgStatus(SendMsgStatusSubCommand),

    #[command(
        name = "switchTimerEngine",
        about = "Switch the engine of timer message in broker.",
        long_about = None,
    )]
    SwitchTimerEngine(SwitchTimerEngineSubCommand),

    #[command(
        name = "updateColdDataFlowCtrGroupConfig",
        about = "Add or update cold data flow ctr group config.",
        long_about = None,
    )]
    UpdateColdDataFlowCtrGroupConfig(UpdateColdDataFlowCtrGroupConfigSubCommand),

    #[command(
        name = "updateBrokerConfig",
        about = "Update broker config by special broker or all brokers in cluster.",
        long_about = None,
    )]
    UpdateBrokerConfigSubCommand(UpdateBrokerConfigSubCommand),

    #[command(
        name = "setCommitLogReadAheadMode",
        about = "Set read ahead mode for all commitlog files.",
        long_about = None,
    )]
    CommitLogSetReadAheadSubCommand(CommitLogSetReadAheadSubCommand),
}

impl CommandExecute for BrokerCommands {
    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 {
            BrokerCommands::BrokerConsumeStats(value) => value.execute(credentials, client_runtime.clone()).await,
            BrokerCommands::BrokerStatus(cmd) => cmd.execute(credentials, client_runtime.clone()).await,
            BrokerCommands::CleanExpiredCQ(value) => value.execute(credentials, client_runtime.clone()).await,
            BrokerCommands::CleanUnusedTopic(value) => value.execute(credentials, client_runtime.clone()).await,
            BrokerCommands::DeleteExpiredCommitLog(value) => value.execute(credentials, client_runtime.clone()).await,
            BrokerCommands::GetBrokerConfig(cmd) => cmd.execute(credentials, client_runtime.clone()).await,
            BrokerCommands::GetBrokerEpoch(cmd) => cmd.execute(credentials, client_runtime.clone()).await,
            BrokerCommands::GetColdDataFlowCtrInfo(value) => value.execute(credentials, client_runtime.clone()).await,
            BrokerCommands::RemoveColdDataFlowCtrGroupConfig(value) => {
                value.execute(credentials, client_runtime.clone()).await
            }
            BrokerCommands::ResetMasterFlushOffset(value) => value.execute(credentials, client_runtime.clone()).await,
            BrokerCommands::SendMsgStatus(value) => value.execute(credentials, client_runtime.clone()).await,
            BrokerCommands::SwitchTimerEngine(value) => value.execute(credentials, client_runtime.clone()).await,
            BrokerCommands::UpdateColdDataFlowCtrGroupConfig(value) => {
                value.execute(credentials, client_runtime.clone()).await
            }
            BrokerCommands::UpdateBrokerConfigSubCommand(cmd) => cmd.execute(credentials, client_runtime.clone()).await,
            BrokerCommands::CommitLogSetReadAheadSubCommand(cmd) => {
                cmd.execute(credentials, client_runtime.clone()).await
            }
        }
    }
}