rocketmq_remoting/code/
response_code.rs

1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements.  See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License.  You may obtain a copy of the License at
8 *
9 *     http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17#[derive(Debug, PartialEq, Copy, Clone)]
18pub enum RemotingSysResponseCode {
19    Success = 0,
20    SystemError = 1,
21    SystemBusy = 2,
22    RequestCodeNotSupported = 3,
23    TransactionFailed = 4,
24    NoPermission = 16,
25}
26
27impl From<RemotingSysResponseCode> for i32 {
28    fn from(value: RemotingSysResponseCode) -> Self {
29        value as i32
30    }
31}
32
33impl From<i32> for RemotingSysResponseCode {
34    fn from(value: i32) -> Self {
35        match value {
36            0 => RemotingSysResponseCode::Success,
37            1 => RemotingSysResponseCode::SystemError,
38            2 => RemotingSysResponseCode::SystemBusy,
39            3 => RemotingSysResponseCode::RequestCodeNotSupported,
40            4 => RemotingSysResponseCode::TransactionFailed,
41            16 => RemotingSysResponseCode::NoPermission,
42            _ => RemotingSysResponseCode::SystemError,
43        }
44    }
45}
46
47#[derive(Debug, PartialEq, Copy, Clone)]
48pub enum ResponseCode {
49    Success = 0,
50    SystemError = 1,
51    SystemBusy = 2,
52    RequestCodeNotSupported = 3,
53    TransactionFailed = 4,
54    FlushDiskTimeout = 10,
55    SlaveNotAvailable = 11,
56    FlushSlaveTimeout = 12,
57    MessageIllegal = 13,
58    ServiceNotAvailable = 14,
59    VersionNotSupported = 15,
60    NoPermission = 16,
61    TopicNotExist = 17,
62    TopicExistAlready = 18,
63    PullNotFound = 19,
64    PullRetryImmediately = 20,
65    PullOffsetMoved = 21,
66    QueryNotFound = 22,
67    SubscriptionParseFailed = 23,
68    SubscriptionNotExist = 24,
69    SubscriptionNotLatest = 25,
70    SubscriptionGroupNotExist = 26,
71    FilterDataNotExist = 27,
72    FilterDataNotLatest = 28,
73    TransactionShouldCommit = 200,
74    TransactionShouldRollback = 201,
75    TransactionStateUnknow = 202,
76    TransactionStateGroupWrong = 203,
77    NoBuyerId = 204,
78    NotInCurrentUnit = 205,
79    ConsumerNotOnline = 206,
80    ConsumeMsgTimeout = 207,
81    NoMessage = 208,
82    /*UpdateAndCreateAclConfigFailed = 209,
83    DeleteAclConfigFailed = 210,
84    UpdateGlobalWhiteAddrsConfigFailed = 211,*/
85    PollingFull = 209,
86    PollingTimeout = 210,
87    BrokerNotExist = 211,
88    BrokerDispatchNotComplete = 212,
89    BroadcastConsumption = 213,
90    FlowControl = 215,
91    NotLeaderForQueue = 501,
92    IllegalOperation = 604,
93    RpcUnknown = -1000,
94    RpcAddrIsNull = -1002,
95    RpcSendToChannelFailed = -1004,
96    RpcTimeOut = -1006,
97    GoAway = 1500,
98    ControllerFencedMasterEpoch = 2000,
99    ControllerFencedSyncStateSetEpoch = 2001,
100    ControllerInvalidMaster = 2002,
101    ControllerInvalidReplicas = 2003,
102    ControllerMasterNotAvailable = 2004,
103    ControllerInvalidRequest = 2005,
104    ControllerBrokerNotAlive = 2006,
105    ControllerNotLeader = 2007,
106    ControllerBrokerMetadataNotExist = 2008,
107    ControllerInvalidCleanBrokerMetadata = 2009,
108    ControllerBrokerNeedToBeRegistered = 2010,
109    ControllerMasterStillExist = 2011,
110    ControllerElectMasterFailed = 2012,
111    ControllerAlterSyncStateSetFailed = 2013,
112    ControllerBrokerIdInvalid = 2014,
113}
114
115impl From<ResponseCode> for i32 {
116    fn from(value: ResponseCode) -> Self {
117        value as i32
118    }
119}
120
121impl From<i32> for ResponseCode {
122    fn from(value: i32) -> Self {
123        match value {
124            0 => ResponseCode::Success,
125            1 => ResponseCode::SystemError,
126            2 => ResponseCode::SystemBusy,
127            3 => ResponseCode::RequestCodeNotSupported,
128            4 => ResponseCode::TransactionFailed,
129            10 => ResponseCode::FlushDiskTimeout,
130            11 => ResponseCode::SlaveNotAvailable,
131            12 => ResponseCode::FlushSlaveTimeout,
132            13 => ResponseCode::MessageIllegal,
133            14 => ResponseCode::ServiceNotAvailable,
134            15 => ResponseCode::VersionNotSupported,
135            16 => ResponseCode::NoPermission,
136            17 => ResponseCode::TopicNotExist,
137            18 => ResponseCode::TopicExistAlready,
138            19 => ResponseCode::PullNotFound,
139            20 => ResponseCode::PullRetryImmediately,
140            21 => ResponseCode::PullOffsetMoved,
141            22 => ResponseCode::QueryNotFound,
142            23 => ResponseCode::SubscriptionParseFailed,
143            24 => ResponseCode::SubscriptionNotExist,
144            25 => ResponseCode::SubscriptionNotLatest,
145            26 => ResponseCode::SubscriptionGroupNotExist,
146            27 => ResponseCode::FilterDataNotExist,
147            28 => ResponseCode::FilterDataNotLatest,
148            200 => ResponseCode::TransactionShouldCommit,
149            201 => ResponseCode::TransactionShouldRollback,
150            202 => ResponseCode::TransactionStateUnknow,
151            203 => ResponseCode::TransactionStateGroupWrong,
152            204 => ResponseCode::NoBuyerId,
153            205 => ResponseCode::NotInCurrentUnit,
154            206 => ResponseCode::ConsumerNotOnline,
155            207 => ResponseCode::ConsumeMsgTimeout,
156            208 => ResponseCode::NoMessage,
157            209 => ResponseCode::PollingFull,
158            210 => ResponseCode::PollingTimeout,
159            211 => ResponseCode::BrokerNotExist,
160            212 => ResponseCode::BrokerDispatchNotComplete,
161            213 => ResponseCode::BroadcastConsumption,
162            215 => ResponseCode::FlowControl,
163            501 => ResponseCode::NotLeaderForQueue,
164            604 => ResponseCode::IllegalOperation,
165            -1000 => ResponseCode::RpcUnknown,
166            -1002 => ResponseCode::RpcAddrIsNull,
167            -1004 => ResponseCode::RpcSendToChannelFailed,
168            -1006 => ResponseCode::RpcTimeOut,
169            1500 => ResponseCode::GoAway,
170            2000 => ResponseCode::ControllerFencedMasterEpoch,
171            2001 => ResponseCode::ControllerFencedSyncStateSetEpoch,
172            2002 => ResponseCode::ControllerInvalidMaster,
173            2003 => ResponseCode::ControllerInvalidReplicas,
174            2004 => ResponseCode::ControllerMasterNotAvailable,
175            2005 => ResponseCode::ControllerInvalidRequest,
176            2006 => ResponseCode::ControllerBrokerNotAlive,
177            2007 => ResponseCode::ControllerNotLeader,
178            2008 => ResponseCode::ControllerBrokerMetadataNotExist,
179            2009 => ResponseCode::ControllerInvalidCleanBrokerMetadata,
180            2010 => ResponseCode::ControllerBrokerNeedToBeRegistered,
181            2011 => ResponseCode::ControllerMasterStillExist,
182            2012 => ResponseCode::ControllerElectMasterFailed,
183            2013 => ResponseCode::ControllerAlterSyncStateSetFailed,
184            2014 => ResponseCode::ControllerBrokerIdInvalid,
185            _ => ResponseCode::SystemError,
186        }
187    }
188}
189
190#[cfg(test)]
191mod tests {
192    use super::*;
193
194    #[test]
195    fn remoting_sys_response_code_from_i32() {
196        assert_eq!(
197            RemotingSysResponseCode::from(0),
198            RemotingSysResponseCode::Success
199        );
200        assert_eq!(
201            RemotingSysResponseCode::from(1),
202            RemotingSysResponseCode::SystemError
203        );
204        assert_eq!(
205            RemotingSysResponseCode::from(2),
206            RemotingSysResponseCode::SystemBusy
207        );
208        assert_eq!(
209            RemotingSysResponseCode::from(3),
210            RemotingSysResponseCode::RequestCodeNotSupported
211        );
212        assert_eq!(
213            RemotingSysResponseCode::from(4),
214            RemotingSysResponseCode::TransactionFailed
215        );
216        assert_eq!(
217            RemotingSysResponseCode::from(999),
218            RemotingSysResponseCode::SystemError
219        ); // Edge case
220    }
221
222    #[test]
223    fn response_code_from_i32() {
224        assert_eq!(ResponseCode::from(0), ResponseCode::Success);
225        assert_eq!(ResponseCode::from(1), ResponseCode::SystemError);
226        assert_eq!(ResponseCode::from(2), ResponseCode::SystemBusy);
227        assert_eq!(ResponseCode::from(3), ResponseCode::RequestCodeNotSupported);
228        assert_eq!(ResponseCode::from(4), ResponseCode::TransactionFailed);
229        assert_eq!(ResponseCode::from(10), ResponseCode::FlushDiskTimeout);
230        assert_eq!(ResponseCode::from(11), ResponseCode::SlaveNotAvailable);
231        assert_eq!(ResponseCode::from(12), ResponseCode::FlushSlaveTimeout);
232        assert_eq!(ResponseCode::from(13), ResponseCode::MessageIllegal);
233        assert_eq!(ResponseCode::from(14), ResponseCode::ServiceNotAvailable);
234        assert_eq!(ResponseCode::from(15), ResponseCode::VersionNotSupported);
235        assert_eq!(ResponseCode::from(16), ResponseCode::NoPermission);
236        assert_eq!(ResponseCode::from(17), ResponseCode::TopicNotExist);
237        assert_eq!(ResponseCode::from(18), ResponseCode::TopicExistAlready);
238        assert_eq!(ResponseCode::from(19), ResponseCode::PullNotFound);
239        assert_eq!(ResponseCode::from(20), ResponseCode::PullRetryImmediately);
240        assert_eq!(ResponseCode::from(21), ResponseCode::PullOffsetMoved);
241        assert_eq!(ResponseCode::from(22), ResponseCode::QueryNotFound);
242        assert_eq!(
243            ResponseCode::from(23),
244            ResponseCode::SubscriptionParseFailed
245        );
246        assert_eq!(ResponseCode::from(24), ResponseCode::SubscriptionNotExist);
247        assert_eq!(ResponseCode::from(25), ResponseCode::SubscriptionNotLatest);
248        assert_eq!(
249            ResponseCode::from(26),
250            ResponseCode::SubscriptionGroupNotExist
251        );
252        assert_eq!(ResponseCode::from(27), ResponseCode::FilterDataNotExist);
253        assert_eq!(ResponseCode::from(28), ResponseCode::FilterDataNotLatest);
254        assert_eq!(
255            ResponseCode::from(200),
256            ResponseCode::TransactionShouldCommit
257        );
258        assert_eq!(
259            ResponseCode::from(201),
260            ResponseCode::TransactionShouldRollback
261        );
262        assert_eq!(
263            ResponseCode::from(202),
264            ResponseCode::TransactionStateUnknow
265        );
266        assert_eq!(
267            ResponseCode::from(203),
268            ResponseCode::TransactionStateGroupWrong
269        );
270        assert_eq!(ResponseCode::from(204), ResponseCode::NoBuyerId);
271        assert_eq!(ResponseCode::from(205), ResponseCode::NotInCurrentUnit);
272        assert_eq!(ResponseCode::from(206), ResponseCode::ConsumerNotOnline);
273        assert_eq!(ResponseCode::from(207), ResponseCode::ConsumeMsgTimeout);
274        assert_eq!(ResponseCode::from(208), ResponseCode::NoMessage);
275        assert_eq!(ResponseCode::from(209), ResponseCode::PollingFull);
276        assert_eq!(ResponseCode::from(210), ResponseCode::PollingTimeout);
277        assert_eq!(ResponseCode::from(211), ResponseCode::BrokerNotExist);
278        assert_eq!(
279            ResponseCode::from(212),
280            ResponseCode::BrokerDispatchNotComplete
281        );
282        assert_eq!(ResponseCode::from(213), ResponseCode::BroadcastConsumption);
283        assert_eq!(ResponseCode::from(215), ResponseCode::FlowControl);
284        assert_eq!(ResponseCode::from(501), ResponseCode::NotLeaderForQueue);
285        assert_eq!(ResponseCode::from(604), ResponseCode::IllegalOperation);
286        assert_eq!(ResponseCode::from(-1000), ResponseCode::RpcUnknown);
287        assert_eq!(ResponseCode::from(-1002), ResponseCode::RpcAddrIsNull);
288        assert_eq!(
289            ResponseCode::from(-1004),
290            ResponseCode::RpcSendToChannelFailed
291        );
292        assert_eq!(ResponseCode::from(-1006), ResponseCode::RpcTimeOut);
293        assert_eq!(ResponseCode::from(1500), ResponseCode::GoAway);
294        assert_eq!(
295            ResponseCode::from(2000),
296            ResponseCode::ControllerFencedMasterEpoch
297        );
298        assert_eq!(
299            ResponseCode::from(2001),
300            ResponseCode::ControllerFencedSyncStateSetEpoch
301        );
302        assert_eq!(
303            ResponseCode::from(2002),
304            ResponseCode::ControllerInvalidMaster
305        );
306        assert_eq!(
307            ResponseCode::from(2003),
308            ResponseCode::ControllerInvalidReplicas
309        );
310        assert_eq!(
311            ResponseCode::from(2004),
312            ResponseCode::ControllerMasterNotAvailable
313        );
314        assert_eq!(
315            ResponseCode::from(2005),
316            ResponseCode::ControllerInvalidRequest
317        );
318        assert_eq!(
319            ResponseCode::from(2006),
320            ResponseCode::ControllerBrokerNotAlive
321        );
322        assert_eq!(ResponseCode::from(2007), ResponseCode::ControllerNotLeader);
323        assert_eq!(
324            ResponseCode::from(2008),
325            ResponseCode::ControllerBrokerMetadataNotExist
326        );
327        assert_eq!(
328            ResponseCode::from(2009),
329            ResponseCode::ControllerInvalidCleanBrokerMetadata
330        );
331        assert_eq!(
332            ResponseCode::from(2010),
333            ResponseCode::ControllerBrokerNeedToBeRegistered
334        );
335        assert_eq!(
336            ResponseCode::from(2011),
337            ResponseCode::ControllerMasterStillExist
338        );
339        assert_eq!(
340            ResponseCode::from(2012),
341            ResponseCode::ControllerElectMasterFailed
342        );
343        assert_eq!(
344            ResponseCode::from(2013),
345            ResponseCode::ControllerAlterSyncStateSetFailed
346        );
347        assert_eq!(
348            ResponseCode::from(2014),
349            ResponseCode::ControllerBrokerIdInvalid
350        );
351        assert_eq!(ResponseCode::from(9999), ResponseCode::SystemError); // Edge case
352    }
353}