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 clean_broker_metadata_sub_command;
mod elect_master_sub_command;
mod get_controller_config_sub_command;
mod get_controller_metadata_sub_command;
mod update_controller_config_sub_command;

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

use crate::commands::CommandExecute;
use crate::commands::controller::clean_broker_metadata_sub_command::CleanBrokerMetadataSubCommand;
use crate::commands::controller::elect_master_sub_command::ElectMasterSubCommand;
use crate::commands::controller::get_controller_config_sub_command::GetControllerConfigSubCommand;
use crate::commands::controller::get_controller_metadata_sub_command::GetControllerMetadataSubCommand;
use crate::commands::controller::update_controller_config_sub_command::UpdateControllerConfigSubCommand;

#[derive(Subcommand)]
pub enum ControllerCommands {
    #[command(
        name = "cleanBrokerMetadata",
        about = "Clean metadata of broker on controller.",
        long_about = None,
    )]
    CleanBrokerMetadata(CleanBrokerMetadataSubCommand),

    #[command(
        name = "electMaster",
        about = "Re-elect the specified broker as master.",
        long_about = None,
    )]
    ElectMaster(ElectMasterSubCommand),

    #[command(
        name = "getControllerConfig",
        about = "Get configuration of controller(s)",
        long_about = None,
    )]
    GetControllerConfig(GetControllerConfigSubCommand),

    #[command(
        name = "getControllerMetaData",
        visible_alias = "getControllerMetadata",
        about = "Get meta data of controller",
        long_about = None,
    )]
    GetControllerMetadata(GetControllerMetadataSubCommand),

    #[command(
        name = "updateControllerConfig",
        about = "update controller config",
        long_about = None,
    )]
    UpdateControllerConfig(UpdateControllerConfigSubCommand),
}

impl CommandExecute for ControllerCommands {
    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 {
            ControllerCommands::CleanBrokerMetadata(cmd) => cmd.execute(credentials, client_runtime.clone()).await,
            ControllerCommands::ElectMaster(value) => value.execute(credentials, client_runtime.clone()).await,
            ControllerCommands::GetControllerConfig(value) => value.execute(credentials, client_runtime.clone()).await,
            ControllerCommands::GetControllerMetadata(value) => {
                value.execute(credentials, client_runtime.clone()).await
            }
            ControllerCommands::UpdateControllerConfig(value) => {
                value.execute(credentials, client_runtime.clone()).await
            }
        }
    }
}