Skip to content

Commit 1f8ec58

Browse files
[ISSUE #6343]✨Organize and standardize the SubCommands and Commands in rocketmq-admin-core (#6345)
1 parent 511417d commit 1f8ec58

15 files changed

+179
-235
lines changed

rocketmq-tools/rocketmq-admin/rocketmq-admin-core/src/commands/auth_commands.rs

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,18 @@ mod update_user_sub_command;
2727

2828
use std::sync::Arc;
2929

30+
use crate::commands::auth_commands::copy_acl_sub_command::CopyAclSubCommand;
31+
use crate::commands::auth_commands::copy_users_sub_command::CopyUsersSubCommand;
32+
use crate::commands::auth_commands::create_acl_sub_command::CreateAclSubCommand;
33+
use crate::commands::auth_commands::create_user_sub_command::CreateUserSubCommand;
34+
use crate::commands::auth_commands::delete_acl_sub_command::DeleteAclSubCommand;
35+
use crate::commands::auth_commands::delete_user_sub_command::DeleteUserSubCommand;
36+
use crate::commands::auth_commands::get_acl_sub_command::GetAclSubCommand;
37+
use crate::commands::auth_commands::get_user_sub_command::GetUserSubCommand;
38+
use crate::commands::auth_commands::list_acl_sub_command::ListAclSubCommand;
39+
use crate::commands::auth_commands::list_users_sub_command::ListUsersSubCommand;
40+
use crate::commands::auth_commands::update_acl_sub_command::UpdateAclSubCommand;
41+
use crate::commands::auth_commands::update_user_sub_command::UpdateUserSubCommand;
3042
use crate::commands::CommandExecute;
3143
use clap::Subcommand;
3244
use rocketmq_error::RocketMQResult;
@@ -39,84 +51,84 @@ pub enum AuthCommands {
3951
about = "Copy acl to cluster",
4052
long_about = None,
4153
)]
42-
CopyAcl(copy_acl_sub_command::CopyAclSubCommand),
54+
CopyAcl(CopyAclSubCommand),
4355

4456
#[command(
4557
name = "copyUser",
4658
about = "Copy user to cluster",
4759
long_about = None,
4860
)]
49-
CopyUsers(copy_users_sub_command::CopyUsersSubCommand),
61+
CopyUsers(CopyUsersSubCommand),
5062

5163
#[command(
5264
name = "createAcl",
5365
about = "Create acl to cluster",
5466
long_about = None,
5567
)]
56-
CreateAcl(create_acl_sub_command::CreateAclSubCommand),
68+
CreateAcl(CreateAclSubCommand),
5769

5870
#[command(
5971
name = "createUser",
6072
about = "Create user to cluster.",
6173
long_about = None,
6274
)]
63-
CreateUser(create_user_sub_command::CreateUserSubCommand),
75+
CreateUser(CreateUserSubCommand),
6476

6577
#[command(
6678
name = "deleteAcl",
6779
about = "Delete acl from cluster.",
6880
long_about = None,
6981
)]
70-
DeleteAcl(delete_acl_sub_command::DeleteAclSubCommand),
82+
DeleteAcl(DeleteAclSubCommand),
7183

7284
#[command(
7385
name = "deleteUser",
7486
about = "Delete user from cluster.",
7587
long_about = None,
7688
)]
77-
DeleteUser(delete_user_sub_command::DeleteUserSubCommand),
78-
79-
#[command(
80-
name = "getUser",
81-
about = "Get user from cluster.",
82-
long_about = None,
83-
)]
84-
GetUser(get_user_sub_command::GetUserSubCommand),
89+
DeleteUser(DeleteUserSubCommand),
8590

8691
#[command(
8792
name = "getAcl",
8893
about = "Get acl from cluster.",
8994
long_about = None,
9095
)]
91-
GetAcl(get_acl_sub_command::GetAclSubCommand),
96+
GetAcl(GetAclSubCommand),
9297

9398
#[command(
94-
name = "listUsers",
95-
about = "List users from cluster.",
99+
name = "getUser",
100+
about = "Get user from cluster.",
96101
long_about = None,
97102
)]
98-
ListUsers(list_users_sub_command::ListUsersSubCommand),
103+
GetUser(GetUserSubCommand),
99104

100105
#[command(
101106
name = "listAcl",
102107
about = "List acl from cluster",
103108
long_about = None,
104109
)]
105-
ListAcl(list_acl_sub_command::ListAclSubCommand),
110+
ListAcl(ListAclSubCommand),
111+
112+
#[command(
113+
name = "listUsers",
114+
about = "List users from cluster.",
115+
long_about = None,
116+
)]
117+
ListUsers(ListUsersSubCommand),
106118

107119
#[command(
108120
name = "updateAcl",
109121
about = "Update Access Control List (ACL)",
110122
long_about = None,
111123
)]
112-
UpdateAcl(update_acl_sub_command::UpdateAclSubCommand),
124+
UpdateAcl(UpdateAclSubCommand),
113125

114126
#[command(
115127
name = "updateUser",
116128
about = "Update user to cluster.",
117129
long_about = None,
118130
)]
119-
UpdateUser(update_user_sub_command::UpdateUserSubCommand),
131+
UpdateUser(UpdateUserSubCommand),
120132
}
121133

122134
impl CommandExecute for AuthCommands {
@@ -128,8 +140,8 @@ impl CommandExecute for AuthCommands {
128140
AuthCommands::CreateUser(value) => value.execute(rpc_hook).await,
129141
AuthCommands::DeleteAcl(value) => value.execute(rpc_hook).await,
130142
AuthCommands::DeleteUser(value) => value.execute(rpc_hook).await,
131-
AuthCommands::GetUser(value) => value.execute(rpc_hook).await,
132143
AuthCommands::GetAcl(value) => value.execute(rpc_hook).await,
144+
AuthCommands::GetUser(value) => value.execute(rpc_hook).await,
133145
AuthCommands::ListAcl(value) => value.execute(rpc_hook).await,
134146
AuthCommands::ListUsers(value) => value.execute(rpc_hook).await,
135147
AuthCommands::UpdateAcl(value) => value.execute(rpc_hook).await,

rocketmq-tools/rocketmq-admin/rocketmq-admin-core/src/commands/broker_commands.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
// limitations under the License.
1414

1515
mod clean_expired_cq_sub_command;
16-
mod clean_unused_topic_command;
17-
mod delete_expired_commit_log_command;
16+
mod clean_unused_topic_sub_command;
17+
mod delete_expired_commit_log_sub_command;
1818
mod get_broker_config_sub_command;
1919
mod reset_master_flush_offset_sub_command;
20-
mod send_msg_status_command;
20+
mod send_msg_status_sub_command;
2121
mod switch_timer_engine_sub_command;
2222
mod update_cold_data_flow_ctr_group_config_sub_command;
2323

@@ -28,11 +28,11 @@ use rocketmq_error::RocketMQResult;
2828
use rocketmq_remoting::runtime::RPCHook;
2929

3030
use crate::commands::broker_commands::clean_expired_cq_sub_command::CleanExpiredCQSubCommand;
31-
use crate::commands::broker_commands::clean_unused_topic_command::CleanUnusedTopicCommand;
32-
use crate::commands::broker_commands::delete_expired_commit_log_command::DeleteExpiredCommitLogCommand;
31+
use crate::commands::broker_commands::clean_unused_topic_sub_command::CleanUnusedTopicSubCommand;
32+
use crate::commands::broker_commands::delete_expired_commit_log_sub_command::DeleteExpiredCommitLogSubCommand;
3333
use crate::commands::broker_commands::get_broker_config_sub_command::GetBrokerConfigSubCommand;
3434
use crate::commands::broker_commands::reset_master_flush_offset_sub_command::ResetMasterFlushOffsetSubCommand;
35-
use crate::commands::broker_commands::send_msg_status_command::SendMsgStatusCommand;
35+
use crate::commands::broker_commands::send_msg_status_sub_command::SendMsgStatusSubCommand;
3636
use crate::commands::broker_commands::switch_timer_engine_sub_command::SwitchTimerEngineSubCommand;
3737
use crate::commands::broker_commands::update_cold_data_flow_ctr_group_config_sub_command::UpdateColdDataFlowCtrGroupConfigSubCommand;
3838
use crate::commands::CommandExecute;
@@ -51,21 +51,21 @@ pub enum BrokerCommands {
5151
about = "Clean unused topic on broker.",
5252
long_about = None,
5353
)]
54-
CleanUnusedTopic(CleanUnusedTopicCommand),
54+
CleanUnusedTopic(CleanUnusedTopicSubCommand),
5555

5656
#[command(
5757
name = "deleteExpiredCommitLog",
5858
about = "Delete expired CommitLog files.",
5959
long_about = None,
6060
)]
61-
DeleteExpiredCommitLog(DeleteExpiredCommitLogCommand),
61+
DeleteExpiredCommitLog(DeleteExpiredCommitLogSubCommand),
6262

6363
#[command(
6464
name = "getBrokerConfig",
6565
about = "Get broker config by cluster or special broker.",
6666
long_about = None,
6767
)]
68-
GetBrokerConfigSubCommand(GetBrokerConfigSubCommand),
68+
GetBrokerConfig(GetBrokerConfigSubCommand),
6969

7070
#[command(
7171
name = "resetMasterFlushOffset",
@@ -79,7 +79,7 @@ pub enum BrokerCommands {
7979
about = "Send msg to broker.",
8080
long_about = None,
8181
)]
82-
SendMsgStatus(SendMsgStatusCommand),
82+
SendMsgStatus(SendMsgStatusSubCommand),
8383

8484
#[command(
8585
name = "switchTimerEngine",
@@ -102,7 +102,7 @@ impl CommandExecute for BrokerCommands {
102102
BrokerCommands::CleanExpiredCQ(value) => value.execute(rpc_hook).await,
103103
BrokerCommands::CleanUnusedTopic(value) => value.execute(rpc_hook).await,
104104
BrokerCommands::DeleteExpiredCommitLog(value) => value.execute(rpc_hook).await,
105-
BrokerCommands::GetBrokerConfigSubCommand(cmd) => cmd.execute(rpc_hook).await,
105+
BrokerCommands::GetBrokerConfig(cmd) => cmd.execute(rpc_hook).await,
106106
BrokerCommands::ResetMasterFlushOffset(value) => value.execute(rpc_hook).await,
107107
BrokerCommands::SendMsgStatus(value) => value.execute(rpc_hook).await,
108108
BrokerCommands::SwitchTimerEngine(value) => value.execute(rpc_hook).await,

rocketmq-tools/rocketmq-admin/rocketmq-admin-core/src/commands/broker_commands/clean_unused_topic_command.rs renamed to rocketmq-tools/rocketmq-admin/rocketmq-admin-core/src/commands/broker_commands/clean_unused_topic_sub_command.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ use crate::commands::CommandExecute;
3131
.required(false)
3232
.args(&["broker_addr", "cluster_name"]))
3333
)]
34-
pub struct CleanUnusedTopicCommand {
34+
pub struct CleanUnusedTopicSubCommand {
3535
#[arg(short = 'b', long = "brokerAddr", required = false, help = "Broker address")]
3636
broker_addr: Option<String>,
3737

3838
#[arg(short = 'c', long = "cluster", required = false, help = "Cluster name")]
3939
cluster_name: Option<String>,
4040
}
4141

42-
impl CommandExecute for CleanUnusedTopicCommand {
42+
impl CommandExecute for CleanUnusedTopicSubCommand {
4343
async fn execute(&self, rpc_hook: Option<Arc<dyn RPCHook>>) -> RocketMQResult<()> {
4444
let mut default_mqadmin_ext = if let Some(rpc_hook) = rpc_hook {
4545
DefaultMQAdminExt::with_rpc_hook(rpc_hook)
@@ -51,7 +51,7 @@ impl CommandExecute for CleanUnusedTopicCommand {
5151
.set_instance_name(get_current_millis().to_string().into());
5252

5353
MQAdminExt::start(&mut default_mqadmin_ext).await.map_err(|e| {
54-
RocketMQError::Internal(format!("CleanUnusedTopicCommand: Failed to start MQAdminExt: {}", e))
54+
RocketMQError::Internal(format!("CleanUnusedTopicSubCommand: Failed to start MQAdminExt: {}", e))
5555
})?;
5656

5757
let operation_result = clean_unused_topic(&default_mqadmin_ext, self).await;
@@ -63,7 +63,7 @@ impl CommandExecute for CleanUnusedTopicCommand {
6363

6464
async fn clean_unused_topic(
6565
default_mqadmin_ext: &DefaultMQAdminExt,
66-
command: &CleanUnusedTopicCommand,
66+
command: &CleanUnusedTopicSubCommand,
6767
) -> RocketMQResult<()> {
6868
let addr = command
6969
.broker_addr

rocketmq-tools/rocketmq-admin/rocketmq-admin-core/src/commands/broker_commands/delete_expired_commit_log_command.rs renamed to rocketmq-tools/rocketmq-admin/rocketmq-admin-core/src/commands/broker_commands/delete_expired_commit_log_sub_command.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ use crate::commands::CommandExecute;
3131
.required(false)
3232
.args(&["broker_addr", "cluster_name"]))
3333
)]
34-
pub struct DeleteExpiredCommitLogCommand {
34+
pub struct DeleteExpiredCommitLogSubCommand {
3535
#[arg(short = 'b', long = "brokerAddr", required = false, help = "Broker address")]
3636
broker_addr: Option<String>,
3737

3838
#[arg(short = 'c', long = "cluster", required = false, help = "Cluster name")]
3939
cluster_name: Option<String>,
4040
}
4141

42-
impl CommandExecute for DeleteExpiredCommitLogCommand {
42+
impl CommandExecute for DeleteExpiredCommitLogSubCommand {
4343
async fn execute(&self, rpc_hook: Option<Arc<dyn RPCHook>>) -> RocketMQResult<()> {
4444
let mut default_mqadmin_ext = if let Some(rpc_hook) = rpc_hook {
4545
DefaultMQAdminExt::with_rpc_hook(rpc_hook)
@@ -52,7 +52,7 @@ impl CommandExecute for DeleteExpiredCommitLogCommand {
5252

5353
MQAdminExt::start(&mut default_mqadmin_ext).await.map_err(|e| {
5454
RocketMQError::Internal(format!(
55-
"DeleteExpiredCommitLogCommand: Failed to start MQAdminExt: {}",
55+
"DeleteExpiredCommitLogSubCommand: Failed to start MQAdminExt: {}",
5656
e
5757
))
5858
})?;
@@ -66,7 +66,7 @@ impl CommandExecute for DeleteExpiredCommitLogCommand {
6666

6767
async fn delete_expired_commit_log(
6868
default_mqadmin_ext: &DefaultMQAdminExt,
69-
command: &DeleteExpiredCommitLogCommand,
69+
command: &DeleteExpiredCommitLogSubCommand,
7070
) -> RocketMQResult<()> {
7171
let addr = command
7272
.broker_addr

rocketmq-tools/rocketmq-admin/rocketmq-admin-core/src/commands/broker_commands/send_msg_status_command.rs renamed to rocketmq-tools/rocketmq-admin/rocketmq-admin-core/src/commands/broker_commands/send_msg_status_sub_command.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ fn build_message(topic: &str, message_size: usize) -> Message {
4343
}
4444

4545
#[derive(Debug, Clone, Parser)]
46-
pub struct SendMsgStatusCommand {
46+
pub struct SendMsgStatusSubCommand {
4747
#[arg(
4848
short = 'b',
4949
long = "brokerName",
@@ -71,7 +71,7 @@ pub struct SendMsgStatusCommand {
7171
count: u32,
7272
}
7373

74-
impl CommandExecute for SendMsgStatusCommand {
74+
impl CommandExecute for SendMsgStatusSubCommand {
7575
async fn execute(&self, rpc_hook: Option<Arc<dyn RPCHook>>) -> RocketMQResult<()> {
7676
let instance_name = format!("PID_SMSC_{}", get_current_millis());
7777
let mut client_config = ClientConfig::default();
@@ -96,7 +96,7 @@ impl CommandExecute for SendMsgStatusCommand {
9696
if let Err(e) = warmup_result {
9797
producer.shutdown().await;
9898
return Err(RocketMQError::Internal(format!(
99-
"SendMsgStatusCommand command failed: {}",
99+
"SendMsgStatusSubCommand command failed: {}",
100100
e
101101
)));
102102
}
@@ -115,7 +115,7 @@ impl CommandExecute for SendMsgStatusCommand {
115115
Err(e) => {
116116
producer.shutdown().await;
117117
return Err(RocketMQError::Internal(format!(
118-
"SendMsgStatusCommand command failed: {}",
118+
"SendMsgStatusSubCommand command failed: {}",
119119
e
120120
)));
121121
}

0 commit comments

Comments
 (0)