forked from mxsm/rocketmq-rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdefault_mq_admin_ext_impl.rs
More file actions
2135 lines (1933 loc) · 73.9 KB
/
default_mq_admin_ext_impl.rs
File metadata and controls
2135 lines (1933 loc) · 73.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// 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.
#![allow(dead_code)]
use std::collections::HashMap;
use std::collections::HashSet;
use std::env;
use std::sync::Arc;
use std::sync::OnceLock;
use std::time::Duration;
use crate::admin::mq_admin_ext_async::MQAdminExt;
use crate::admin::mq_admin_ext_async_inner::MQAdminExtInnerImpl;
use crate::base::client_config::ClientConfig;
use crate::common::admin_tool_result::AdminToolResult;
use crate::consumer::consumer_impl::pull_request_ext::PullResultExt;
use crate::consumer::pull_callback::PullCallback;
use crate::consumer::pull_status::PullStatus;
use crate::factory::mq_client_instance::MQClientInstance;
use crate::implementation::communication_mode::CommunicationMode;
use crate::implementation::mq_client_api_impl::MQClientAPIImpl;
use crate::implementation::mq_client_manager::MQClientManager;
use cheetah_string::CheetahString;
use rand::seq::IndexedRandom;
use rocketmq_common::common::base::plain_access_config::PlainAccessConfig;
use rocketmq_common::common::base::service_state::ServiceState;
use rocketmq_common::common::config::TopicConfig;
use rocketmq_common::common::constant::PermName;
use rocketmq_common::common::message::message_decoder;
use rocketmq_common::common::message::message_enum::MessageRequestMode;
use rocketmq_common::common::message::message_ext::MessageExt;
use rocketmq_common::common::message::message_queue::MessageQueue;
use rocketmq_common::common::mix_all;
use rocketmq_common::common::mix_all::DLQ_GROUP_TOPIC_PREFIX;
use rocketmq_common::common::mix_all::RETRY_GROUP_TOPIC_PREFIX;
use rocketmq_common::common::sys_flag::pull_sys_flag::PullSysFlag;
#[allow(deprecated)]
use rocketmq_common::common::tools::broker_operator_result::BrokerOperatorResult;
#[allow(deprecated)]
use rocketmq_common::common::tools::message_track::MessageTrack;
use rocketmq_common::common::topic::TopicValidator;
use rocketmq_common::common::FAQUrl;
use rocketmq_remoting::protocol::admin::consume_stats::ConsumeStats;
use rocketmq_remoting::protocol::admin::consume_stats_list::ConsumeStatsList;
use rocketmq_remoting::protocol::admin::rollback_stats::RollbackStats;
use rocketmq_remoting::protocol::admin::topic_stats_table::TopicStatsTable;
use rocketmq_remoting::protocol::body::acl_info::AclInfo;
use rocketmq_remoting::protocol::body::broker_body::broker_member_group::BrokerMemberGroup;
use rocketmq_remoting::protocol::body::broker_body::cluster_info::ClusterInfo;
use rocketmq_remoting::protocol::body::broker_replicas_info::BrokerReplicasInfo;
use rocketmq_remoting::protocol::body::check_rocksdb_cqwrite_progress_response_body::CheckRocksdbCqWriteResult;
use rocketmq_remoting::protocol::body::consume_message_directly_result::ConsumeMessageDirectlyResult;
use rocketmq_remoting::protocol::body::consumer_connection::ConsumerConnection;
use rocketmq_remoting::protocol::body::consumer_running_info::ConsumerRunningInfo;
use rocketmq_remoting::protocol::body::epoch_entry_cache::EpochEntryCache;
use rocketmq_remoting::protocol::body::get_broker_lite_info_response_body::GetBrokerLiteInfoResponseBody;
use rocketmq_remoting::protocol::body::get_lite_client_info_response_body::GetLiteClientInfoResponseBody;
use rocketmq_remoting::protocol::body::get_lite_group_info_response_body::GetLiteGroupInfoResponseBody;
use rocketmq_remoting::protocol::body::get_lite_topic_info_response_body::GetLiteTopicInfoResponseBody;
use rocketmq_remoting::protocol::body::get_parent_topic_info_response_body::GetParentTopicInfoResponseBody;
use rocketmq_remoting::protocol::body::group_list::GroupList;
use rocketmq_remoting::protocol::body::ha_runtime_info::HARuntimeInfo;
use rocketmq_remoting::protocol::body::kv_table::KVTable;
use rocketmq_remoting::protocol::body::producer_connection::ProducerConnection;
use rocketmq_remoting::protocol::body::producer_table_info::ProducerTableInfo;
use rocketmq_remoting::protocol::body::query_consume_queue_response_body::QueryConsumeQueueResponseBody;
use rocketmq_remoting::protocol::body::queue_time_span::QueueTimeSpan;
use rocketmq_remoting::protocol::body::subscription_group_wrapper::SubscriptionGroupWrapper;
use rocketmq_remoting::protocol::body::topic::topic_list::TopicList;
use rocketmq_remoting::protocol::body::topic_info_wrapper::TopicConfigSerializeWrapper;
use rocketmq_remoting::protocol::body::user_info::UserInfo;
use rocketmq_remoting::protocol::header::elect_master_response_header::ElectMasterResponseHeader;
use rocketmq_remoting::protocol::header::get_consume_stats_request_header::GetConsumeStatsRequestHeader;
use rocketmq_remoting::protocol::header::get_meta_data_response_header::GetMetaDataResponseHeader;
use rocketmq_remoting::protocol::header::pull_message_request_header::PullMessageRequestHeader;
use rocketmq_remoting::protocol::header::query_topic_consume_by_who_request_header::QueryTopicConsumeByWhoRequestHeader;
use rocketmq_remoting::protocol::header::view_broker_stats_data_request_header::ViewBrokerStatsDataRequestHeader;
use rocketmq_remoting::protocol::header::view_message_request_header::ViewMessageRequestHeader;
use rocketmq_remoting::protocol::heartbeat::subscription_data::SubscriptionData;
use rocketmq_remoting::protocol::route::topic_route_data::TopicRouteData;
use rocketmq_remoting::protocol::static_topic::topic_queue_mapping_detail::TopicQueueMappingDetail;
use rocketmq_remoting::protocol::subscription::broker_stats_data::BrokerStatsData;
use rocketmq_remoting::protocol::subscription::group_forbidden::GroupForbidden;
use rocketmq_remoting::protocol::subscription::subscription_group_config::SubscriptionGroupConfig;
use rocketmq_remoting::runtime::RPCHook;
use rocketmq_rust::ArcMut;
use tracing::info;
static SYSTEM_GROUP_SET: OnceLock<HashSet<CheetahString>> = OnceLock::new();
fn get_system_group_set() -> &'static HashSet<CheetahString> {
SYSTEM_GROUP_SET.get_or_init(|| {
let mut set = HashSet::new();
set.insert(CheetahString::from(mix_all::DEFAULT_CONSUMER_GROUP));
set.insert(CheetahString::from(mix_all::DEFAULT_PRODUCER_GROUP));
set.insert(CheetahString::from(mix_all::TOOLS_CONSUMER_GROUP));
set.insert(CheetahString::from(mix_all::SCHEDULE_CONSUMER_GROUP));
set.insert(CheetahString::from(mix_all::FILTERSRV_CONSUMER_GROUP));
set.insert(CheetahString::from(mix_all::MONITOR_CONSUMER_GROUP));
set.insert(CheetahString::from(mix_all::CLIENT_INNER_PRODUCER_GROUP));
set.insert(CheetahString::from(mix_all::SELF_TEST_PRODUCER_GROUP));
set.insert(CheetahString::from(mix_all::SELF_TEST_CONSUMER_GROUP));
set.insert(CheetahString::from(mix_all::ONS_HTTP_PROXY_GROUP));
set.insert(CheetahString::from(mix_all::CID_ONSAPI_PERMISSION_GROUP));
set.insert(CheetahString::from(mix_all::CID_ONSAPI_OWNER_GROUP));
set.insert(CheetahString::from(mix_all::CID_ONSAPI_PULL_GROUP));
set.insert(CheetahString::from(mix_all::CID_SYS_RMQ_TRANS));
set
})
}
const SOCKS_PROXY_JSON: &str = "socksProxyJson";
const NAMESPACE_ORDER_TOPIC_CONFIG: &str = "ORDER_TOPIC_CONFIG";
pub struct DefaultMQAdminExtImpl {
service_state: ServiceState,
client_instance: Option<ArcMut<MQClientInstance>>,
rpc_hook: Option<Arc<dyn RPCHook>>,
timeout_millis: Duration,
kv_namespace_to_delete_list: Vec<CheetahString>,
client_config: ArcMut<ClientConfig>,
admin_ext_group: CheetahString,
inner: Option<ArcMut<DefaultMQAdminExtImpl>>,
}
impl DefaultMQAdminExtImpl {
pub fn new(
rpc_hook: Option<Arc<dyn RPCHook>>,
timeout_millis: Duration,
client_config: ArcMut<ClientConfig>,
admin_ext_group: CheetahString,
) -> Self {
DefaultMQAdminExtImpl {
service_state: ServiceState::CreateJust,
client_instance: None,
rpc_hook,
timeout_millis,
kv_namespace_to_delete_list: vec![CheetahString::from_static_str(NAMESPACE_ORDER_TOPIC_CONFIG)],
client_config,
admin_ext_group,
inner: None,
}
}
pub fn set_inner(&mut self, inner: ArcMut<DefaultMQAdminExtImpl>) {
self.inner = Some(inner);
}
pub async fn create_acl_with_acl_info(
&self,
broker_addr: CheetahString,
acl_info: AclInfo,
) -> rocketmq_error::RocketMQResult<()> {
let subject = acl_info
.subject
.clone()
.ok_or_else(|| rocketmq_error::RocketMQError::IllegalArgument("ACL subject is required".into()))?;
if let Some(ref policies) = acl_info.policies {
for policy in policies {
if let Some(ref entries) = policy.entries {
for entry in entries {
let resources: Vec<CheetahString> =
entry.resource.as_ref().map(|r| vec![r.clone()]).unwrap_or_default();
let actions: Vec<CheetahString> = entry
.actions
.as_ref()
.map(|a| a.split(',').map(|s| CheetahString::from(s.trim())).collect())
.unwrap_or_default();
let source_ips: Vec<CheetahString> = entry.source_ips.clone().unwrap_or_default();
let decision: CheetahString = entry.decision.clone().unwrap_or_default();
self.create_acl(
broker_addr.clone(),
subject.clone(),
resources,
actions,
source_ips,
decision,
)
.await?;
}
}
}
}
Ok(())
}
pub async fn update_acl_with_acl_info(
&self,
broker_addr: CheetahString,
acl_info: AclInfo,
) -> rocketmq_error::RocketMQResult<()> {
let subject = acl_info
.subject
.clone()
.ok_or_else(|| rocketmq_error::RocketMQError::IllegalArgument("ACL subject is required".into()))?;
if let Some(ref policies) = acl_info.policies {
for policy in policies {
if let Some(ref entries) = policy.entries {
for entry in entries {
let resources: Vec<CheetahString> =
entry.resource.as_ref().map(|r| vec![r.clone()]).unwrap_or_default();
let actions: Vec<CheetahString> = entry
.actions
.as_ref()
.map(|a| a.split(',').map(|s| CheetahString::from(s.trim())).collect())
.unwrap_or_default();
let source_ips: Vec<CheetahString> = entry.source_ips.clone().unwrap_or_default();
let decision: CheetahString = entry.decision.clone().unwrap_or_default();
self.update_acl(
broker_addr.clone(),
subject.clone(),
resources,
actions,
source_ips,
decision,
)
.await?;
}
}
}
}
Ok(())
}
pub async fn create_user_with_user_info(
&self,
broker_addr: CheetahString,
user_info: UserInfo,
) -> rocketmq_error::RocketMQResult<()> {
let username = user_info
.username
.clone()
.ok_or_else(|| rocketmq_error::RocketMQError::IllegalArgument("User username is required".into()))?;
let password = user_info.password.clone().unwrap_or_default();
let user_type = user_info.user_type.clone().unwrap_or_default();
self.create_user(broker_addr, username, password, user_type).await
}
pub async fn update_user_with_user_info(
&self,
broker_addr: CheetahString,
user_info: UserInfo,
) -> rocketmq_error::RocketMQResult<()> {
let username = user_info
.username
.clone()
.ok_or_else(|| rocketmq_error::RocketMQError::IllegalArgument("User username is required".into()))?;
let password = user_info.password.clone().unwrap_or_default();
let user_type = user_info.user_type.clone().unwrap_or_default();
let user_status = user_info.user_status.clone().unwrap_or_default();
self.update_user(broker_addr, username, password, user_type, user_status)
.await
}
pub async fn pull_message_from_queue(
&self,
broker_addr: &str,
mq: &MessageQueue,
sub_expression: &str,
offset: i64,
max_nums: i32,
timeout_millis: u64,
) -> rocketmq_error::RocketMQResult<crate::consumer::pull_result::PullResult> {
let sys_flag = PullSysFlag::build_sys_flag(false, false, true, false);
let request_header = PullMessageRequestHeader {
consumer_group: CheetahString::from_static_str(mix_all::TOOLS_CONSUMER_GROUP),
topic: mq.topic().clone(),
queue_id: mq.queue_id(),
queue_offset: offset,
max_msg_nums: max_nums,
sys_flag: sys_flag as i32,
commit_offset: 0,
suspend_timeout_millis: 0,
sub_version: 0,
subscription: Some(CheetahString::from(sub_expression)),
expression_type: None,
max_msg_bytes: None,
request_source: None,
proxy_forward_client_id: None,
topic_request: None,
};
struct NoopPullCallback;
impl PullCallback for NoopPullCallback {
async fn on_success(&mut self, _pull_result: PullResultExt) {}
fn on_exception(&mut self, _e: Box<dyn std::error::Error + Send>) {}
}
let api_impl = self.client_instance.as_ref().unwrap().get_mq_client_api_impl();
let mut result = MQClientAPIImpl::pull_message(
api_impl,
CheetahString::from(broker_addr),
request_header,
timeout_millis,
CommunicationMode::Sync,
NoopPullCallback,
)
.await?
.ok_or_else(|| rocketmq_error::RocketMQError::Internal("pull_message returned None in sync mode".into()))?;
if result.pull_result.pull_status == PullStatus::Found {
if let Some(mut message_binary) = result.message_binary.take() {
let msg_vec = message_decoder::decodes_batch(&mut message_binary, true, true);
result.pull_result.msg_found_list = Some(msg_vec.into_iter().map(ArcMut::new).collect());
}
}
Ok(result.pull_result)
}
pub async fn query_message_by_key(
&self,
cluster_name: Option<CheetahString>,
topic: CheetahString,
key: CheetahString,
max_num: i32,
begin_timestamp: i64,
end_timestamp: i64,
_key_type: CheetahString,
_last_key: Option<CheetahString>,
) -> rocketmq_error::RocketMQResult<crate::base::query_result::QueryResult> {
let route_topic = cluster_name.unwrap_or_else(|| topic.clone());
let topic_route_data = self
.examine_topic_route_info(route_topic.clone())
.await?
.ok_or_else(|| {
rocketmq_error::RocketMQError::Internal(format!("Topic route not found for: {}", route_topic))
})?;
let mut message_list: Vec<MessageExt> = Vec::new();
let mut index_last_update_timestamp: u64 = 0;
let api_impl = self.client_instance.as_ref().unwrap().get_mq_client_api_impl();
let timeout = self.timeout_millis.as_millis() as u64;
for broker_data in &topic_route_data.broker_datas {
let broker_addr = match broker_data.select_broker_addr() {
Some(addr) => addr,
None => continue,
};
let request_header =
rocketmq_remoting::protocol::header::query_message_request_header::QueryMessageRequestHeader {
topic: topic.clone(),
key: key.clone(),
max_num,
begin_timestamp,
end_timestamp,
topic_request_header: None,
};
match MQClientAPIImpl::query_message(&api_impl, &broker_addr, request_header, timeout).await {
Ok(Some((response_header, body))) => {
if let Some(mut body_bytes) = body {
let msgs = message_decoder::decodes_batch(&mut body_bytes, true, true);
message_list.extend(msgs);
}
if response_header.index_last_update_timestamp as u64 > index_last_update_timestamp {
index_last_update_timestamp = response_header.index_last_update_timestamp as u64;
}
}
Ok(None) => {
// No messages found on this broker, continue
}
Err(e) => {
tracing::warn!("Failed to query message by key from broker {}: {}", broker_addr, e);
}
}
}
Ok(crate::base::query_result::QueryResult::new(
index_last_update_timestamp,
message_list,
))
}
}
#[allow(unused_variables)]
#[allow(unused_mut)]
impl MQAdminExt for DefaultMQAdminExtImpl {
async fn start(&mut self) -> rocketmq_error::RocketMQResult<()> {
match self.service_state {
ServiceState::CreateJust => {
self.service_state = ServiceState::StartFailed;
self.client_config.change_instance_name_to_pid();
if "{}".eq(&self.client_config.socks_proxy_config) {
self.client_config.socks_proxy_config =
env::var(SOCKS_PROXY_JSON).unwrap_or_else(|_| "{}".to_string()).into();
}
self.client_instance = Some(
MQClientManager::get_instance()
.get_or_create_mq_client_instance(self.client_config.as_ref().clone(), self.rpc_hook.clone()),
);
let group = &self.admin_ext_group.clone();
let register_ok = self
.client_instance
.as_mut()
.unwrap()
.register_admin_ext(
group,
MQAdminExtInnerImpl {
inner: self.inner.as_ref().unwrap().clone(),
},
)
.await;
if !register_ok {
self.service_state = ServiceState::StartFailed;
return Err(rocketmq_error::RocketMQError::illegal_argument(format!(
"The adminExt group[{}] has created already, specified another name please.{}",
self.admin_ext_group,
FAQUrl::suggest_todo(FAQUrl::GROUP_NAME_DUPLICATE_URL)
)));
}
let arc_mut = self.client_instance.clone().unwrap();
self.client_instance.as_mut().unwrap().start(arc_mut).await?;
self.service_state = ServiceState::Running;
info!("the adminExt [{}] start OK", self.admin_ext_group);
Ok(())
}
ServiceState::Running | ServiceState::ShutdownAlready | ServiceState::StartFailed => {
unimplemented!()
}
}
}
async fn shutdown(&mut self) {
match self.service_state {
ServiceState::CreateJust | ServiceState::ShutdownAlready | ServiceState::StartFailed => {
// do nothing
}
ServiceState::Running => {
let instance = self.client_instance.as_mut().unwrap();
instance.unregister_admin_ext(&self.admin_ext_group).await;
instance.shutdown().await;
self.service_state = ServiceState::ShutdownAlready;
}
}
}
async fn add_broker_to_container(
&self,
broker_container_addr: CheetahString,
broker_config: CheetahString,
) -> rocketmq_error::RocketMQResult<()> {
todo!()
}
async fn remove_broker_from_container(
&self,
broker_container_addr: CheetahString,
cluster_name: CheetahString,
broker_name: CheetahString,
broker_id: u64,
) -> rocketmq_error::RocketMQResult<()> {
todo!()
}
async fn update_broker_config(
&self,
broker_addr: CheetahString,
properties: HashMap<CheetahString, CheetahString>,
) -> rocketmq_error::RocketMQResult<()> {
todo!()
}
async fn get_broker_config(
&self,
broker_addr: CheetahString,
) -> rocketmq_error::RocketMQResult<HashMap<CheetahString, CheetahString>> {
todo!()
}
async fn create_and_update_topic_config(
&self,
addr: CheetahString,
config: TopicConfig,
) -> rocketmq_error::RocketMQResult<()> {
todo!()
}
async fn create_and_update_topic_config_list(
&self,
addr: CheetahString,
topic_config_list: Vec<TopicConfig>,
) -> rocketmq_error::RocketMQResult<()> {
todo!()
}
async fn create_and_update_plain_access_config(
&self,
addr: CheetahString,
config: PlainAccessConfig,
) -> rocketmq_error::RocketMQResult<()> {
todo!()
}
async fn delete_plain_access_config(
&self,
addr: CheetahString,
access_key: CheetahString,
) -> rocketmq_error::RocketMQResult<()> {
todo!()
}
async fn update_global_white_addr_config(
&self,
addr: CheetahString,
global_white_addrs: CheetahString,
acl_file_full_path: Option<CheetahString>,
) -> rocketmq_error::RocketMQResult<()> {
todo!()
}
async fn examine_broker_cluster_acl_version_info(
&self,
addr: CheetahString,
) -> rocketmq_error::RocketMQResult<CheetahString> {
todo!()
}
async fn create_and_update_subscription_group_config(
&self,
addr: CheetahString,
config: SubscriptionGroupConfig,
) -> rocketmq_error::RocketMQResult<()> {
todo!()
}
async fn create_and_update_subscription_group_config_list(
&self,
broker_addr: CheetahString,
configs: Vec<SubscriptionGroupConfig>,
) -> rocketmq_error::RocketMQResult<()> {
todo!()
}
async fn examine_subscription_group_config(
&self,
addr: CheetahString,
group: CheetahString,
) -> rocketmq_error::RocketMQResult<SubscriptionGroupConfig> {
self.client_instance
.as_ref()
.unwrap()
.get_mq_client_api_impl()
.get_subscription_group_config(&addr, group, self.timeout_millis.as_millis() as u64)
.await
}
async fn examine_topic_stats(
&self,
topic: CheetahString,
broker_addr: Option<CheetahString>,
) -> rocketmq_error::RocketMQResult<TopicStatsTable> {
todo!()
}
async fn examine_topic_stats_concurrent(&self, topic: CheetahString) -> AdminToolResult<TopicStatsTable> {
todo!()
}
async fn fetch_all_topic_list(&self) -> rocketmq_error::RocketMQResult<TopicList> {
self.client_instance
.as_ref()
.unwrap()
.get_mq_client_api_impl()
.get_all_topic_list_from_name_server(self.timeout_millis.as_millis() as u64)
.await
}
async fn fetch_topics_by_cluster(&self, cluster_name: CheetahString) -> rocketmq_error::RocketMQResult<TopicList> {
todo!()
}
async fn fetch_broker_runtime_stats(&self, broker_addr: CheetahString) -> rocketmq_error::RocketMQResult<KVTable> {
self.client_instance
.as_ref()
.unwrap()
.get_mq_client_api_impl()
.get_broker_runtime_info(&broker_addr, self.timeout_millis.as_millis() as u64)
.await
}
async fn examine_consume_stats(
&self,
consumer_group: CheetahString,
topic: Option<CheetahString>,
cluster_name: Option<CheetahString>,
broker_addr: Option<CheetahString>,
timeout_millis: Option<u64>,
) -> rocketmq_error::RocketMQResult<ConsumeStats> {
let timeout = timeout_millis.unwrap_or(self.timeout_millis.as_millis() as u64);
let topic_str = topic.clone().unwrap_or_default();
if let Some(addr) = broker_addr {
let request_header = GetConsumeStatsRequestHeader {
consumer_group,
topic: topic_str,
topic_request_header: None,
};
return self
.client_instance
.as_ref()
.unwrap()
.get_mq_client_api_impl()
.get_consume_stats(&addr, request_header, timeout)
.await;
}
let retry_topic: CheetahString = rocketmq_common::common::mix_all::get_retry_topic(&consumer_group).into();
let topic_route = self
.client_instance
.as_ref()
.unwrap()
.mq_client_api_impl
.as_ref()
.unwrap()
.get_topic_route_info_from_name_server(&retry_topic, timeout)
.await?;
let mut result = ConsumeStats::new();
if let Some(route_data) = topic_route {
for bd in &route_data.broker_datas {
if let Some(master_addr) = bd.broker_addrs().get(&rocketmq_common::common::mix_all::MASTER_ID) {
let request_header = GetConsumeStatsRequestHeader {
consumer_group: consumer_group.clone(),
topic: topic_str.clone(),
topic_request_header: None,
};
let cs = self
.client_instance
.as_ref()
.unwrap()
.get_mq_client_api_impl()
.get_consume_stats(master_addr, request_header, timeout)
.await?;
result.get_offset_table_mut().extend(cs.offset_table);
let new_tps = result.get_consume_tps() + cs.consume_tps;
result.set_consume_tps(new_tps);
}
}
}
Ok(result)
}
async fn check_rocksdb_cq_write_progress(
&self,
broker_addr: CheetahString,
topic: CheetahString,
check_store_time: i64,
) -> rocketmq_error::RocketMQResult<CheckRocksdbCqWriteResult> {
self.client_instance
.as_ref()
.unwrap()
.get_mq_client_api_impl()
.check_rocksdb_cq_write_progress(
&broker_addr,
topic,
check_store_time,
self.timeout_millis.as_millis() as u64,
)
.await
}
async fn examine_broker_cluster_info(&self) -> rocketmq_error::RocketMQResult<ClusterInfo> {
self.client_instance
.as_ref()
.unwrap()
.get_mq_client_api_impl()
.get_broker_cluster_info(self.timeout_millis.as_millis() as u64)
.await
}
async fn examine_topic_route_info(
&self,
topic: CheetahString,
) -> rocketmq_error::RocketMQResult<Option<TopicRouteData>> {
self.client_instance
.as_ref()
.unwrap()
.mq_client_api_impl
.as_ref()
.unwrap()
.get_topic_route_info_from_name_server(&topic, self.timeout_millis.as_millis() as u64)
.await
}
async fn examine_consumer_connection_info(
&self,
consumer_group: CheetahString,
broker_addr: Option<CheetahString>,
) -> rocketmq_error::RocketMQResult<ConsumerConnection> {
let mut result = ConsumerConnection::new();
let timeout = self.timeout_millis.as_millis() as u64;
if let Some(broker_addr) = broker_addr {
result = self
.client_instance
.as_ref()
.unwrap()
.get_mq_client_api_impl()
.get_consumer_connection_list(broker_addr.as_str(), consumer_group.clone(), timeout)
.await?;
} else {
let topic = CheetahString::from_string(mix_all::get_retry_topic(consumer_group.as_str()));
let topic_route_data = self
.client_instance
.as_ref()
.unwrap()
.get_mq_client_api_impl()
.get_topic_route_info_from_name_server(&topic, timeout)
.await?;
if let Some(topic_route_data) = topic_route_data {
let brokers = &topic_route_data.broker_datas;
if !brokers.is_empty() {
if let Some(broker_data) = brokers.choose(&mut rand::rng()) {
if let Some(addr) = broker_data.select_broker_addr() {
result = self
.client_instance
.as_ref()
.unwrap()
.get_mq_client_api_impl()
.get_consumer_connection_list(addr.as_str(), consumer_group.clone(), timeout)
.await?;
}
}
}
}
}
if result.get_connection_set().is_empty() {
return Err(mq_client_err!(
rocketmq_remoting::code::response_code::ResponseCode::ConsumerNotOnline,
"Not found the consumer group connection"
));
}
Ok(result)
}
async fn examine_producer_connection_info(
&self,
producer_group: CheetahString,
topic: CheetahString,
) -> rocketmq_error::RocketMQResult<ProducerConnection> {
todo!()
}
async fn get_all_producer_info(
&self,
broker_addr: CheetahString,
) -> rocketmq_error::RocketMQResult<ProducerTableInfo> {
self.client_instance
.as_ref()
.unwrap()
.get_mq_client_api_impl()
.get_all_producer_info(broker_addr.as_str(), self.timeout_millis.as_millis() as u64)
.await
}
async fn get_name_server_address_list(&self) -> Vec<CheetahString> {
self.client_instance
.as_ref()
.unwrap()
.get_mq_client_api_impl()
.get_name_server_address_list()
.to_vec()
}
async fn wipe_write_perm_of_broker(
&self,
namesrv_addr: CheetahString,
broker_name: CheetahString,
) -> rocketmq_error::RocketMQResult<i32> {
self.client_instance
.as_ref()
.unwrap()
.get_mq_client_api_impl()
.wipe_write_perm_of_broker(namesrv_addr, broker_name, self.timeout_millis.as_millis() as u64)
.await
}
async fn add_write_perm_of_broker(
&self,
namesrv_addr: CheetahString,
broker_name: CheetahString,
) -> rocketmq_error::RocketMQResult<i32> {
self.client_instance
.as_ref()
.unwrap()
.get_mq_client_api_impl()
.add_write_perm_of_broker(namesrv_addr, broker_name, self.timeout_millis.as_millis() as u64)
.await
}
async fn put_kv_config(&self, namespace: CheetahString, key: CheetahString, value: CheetahString) {
todo!()
}
async fn get_kv_config(
&self,
namespace: CheetahString,
key: CheetahString,
) -> rocketmq_error::RocketMQResult<CheetahString> {
todo!()
}
async fn get_kv_list_by_namespace(&self, namespace: CheetahString) -> rocketmq_error::RocketMQResult<KVTable> {
todo!()
}
async fn delete_topic(
&self,
topic_name: CheetahString,
cluster_name: CheetahString,
) -> rocketmq_error::RocketMQResult<()> {
todo!()
}
async fn delete_topic_in_broker(
&self,
addrs: HashSet<CheetahString>,
topic: CheetahString,
) -> rocketmq_error::RocketMQResult<()> {
todo!()
}
async fn delete_topic_in_name_server(
&self,
addrs: HashSet<CheetahString>,
cluster_name: Option<CheetahString>,
topic: CheetahString,
) -> rocketmq_error::RocketMQResult<()> {
todo!()
}
async fn delete_subscription_group(
&self,
addr: CheetahString,
group_name: CheetahString,
remove_offset: Option<bool>,
) -> rocketmq_error::RocketMQResult<()> {
self.client_instance
.as_ref()
.unwrap()
.get_mq_client_api_impl()
.delete_subscription_group(
&addr,
group_name,
remove_offset.unwrap_or(false),
self.timeout_millis.as_millis() as u64,
)
.await
}
async fn create_and_update_kv_config(
&self,
namespace: CheetahString,
key: CheetahString,
value: CheetahString,
) -> rocketmq_error::RocketMQResult<()> {
self.client_instance
.as_ref()
.unwrap()
.get_mq_client_api_impl()
.put_kvconfig_value(namespace, key, value, self.timeout_millis.as_millis() as u64)
.await
}
async fn delete_kv_config(
&self,
namespace: CheetahString,
key: CheetahString,
) -> rocketmq_error::RocketMQResult<()> {
self.client_instance
.as_ref()
.unwrap()
.get_mq_client_api_impl()
.delete_kvconfig_value(namespace, key, self.timeout_millis.as_millis() as u64)
.await
}
async fn reset_offset_by_timestamp(
&self,
cluster_name: Option<CheetahString>,
topic: CheetahString,
group: CheetahString,
timestamp: u64,
is_force: bool,
) -> rocketmq_error::RocketMQResult<HashMap<MessageQueue, u64>> {
todo!()
}
async fn reset_offset_new(
&self,
consumer_group: CheetahString,
topic: CheetahString,
timestamp: u64,
) -> rocketmq_error::RocketMQResult<()> {
todo!()
}
async fn get_consume_status(
&self,
topic: CheetahString,
group: CheetahString,
client_addr: CheetahString,
) -> rocketmq_error::RocketMQResult<HashMap<CheetahString, HashMap<MessageQueue, u64>>> {
let topic_route_data = self.examine_topic_route_info(topic.clone()).await?;
if let Some(route_data) = topic_route_data {
if !route_data.broker_datas.is_empty() {
if let Some(addr) = route_data.broker_datas[0].select_broker_addr() {
let result = self
.client_instance
.as_ref()
.unwrap()
.get_mq_client_api_impl()
.invoke_broker_to_get_consumer_status(
addr.as_str(),
topic,
group,
client_addr,
self.timeout_millis.as_millis() as u64,
)
.await?;
let converted: HashMap<CheetahString, HashMap<MessageQueue, u64>> = result
.into_iter()
.map(|(k, v)| {
let inner: HashMap<MessageQueue, u64> =
v.into_iter().map(|(mq, off)| (mq, off as u64)).collect();
(k, inner)
})
.collect();
return Ok(converted);
}
}
}
Ok(HashMap::new())
}
async fn create_or_update_order_conf(
&self,
key: CheetahString,
value: CheetahString,
is_cluster: bool,
) -> rocketmq_error::RocketMQResult<()> {
todo!()
}
async fn query_topic_consume_by_who(&self, topic: CheetahString) -> rocketmq_error::RocketMQResult<GroupList> {
let topic_route = self
.client_instance
.as_ref()
.unwrap()
.mq_client_api_impl
.as_ref()
.unwrap()
.get_topic_route_info_from_name_server(&topic, self.timeout_millis.as_millis() as u64)
.await?;
if let Some(route_data) = topic_route {
for bd in &route_data.broker_datas {
if let Some(master_addr) = bd.broker_addrs().get(&rocketmq_common::common::mix_all::MASTER_ID) {
let request_header = QueryTopicConsumeByWhoRequestHeader {
topic: topic.clone(),
topic_request_header: None,
};