-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ISSUE #74] 🚩 Namesrv support wipe write perm of boker(request code 205)
- Loading branch information
Showing
5 changed files
with
141 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
rocketmq-remoting/src/protocol/header/namesrv/perm_broker_header.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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. | ||
*/ | ||
use std::collections::HashMap; | ||
|
||
use serde::{Deserialize, Serialize}; | ||
|
||
use crate::protocol::command_custom_header::{CommandCustomHeader, FromMap}; | ||
|
||
#[derive(Debug, Clone, Deserialize, Serialize, Default)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct WipeWritePermOfBrokerRequestHeader { | ||
pub broker_name: String, | ||
} | ||
|
||
impl WipeWritePermOfBrokerRequestHeader { | ||
const BROKER_NAME: &'static str = "brokerName"; | ||
pub fn new(broker_name: impl Into<String>) -> Self { | ||
Self { | ||
broker_name: broker_name.into(), | ||
} | ||
} | ||
} | ||
|
||
impl CommandCustomHeader for WipeWritePermOfBrokerRequestHeader { | ||
fn to_map(&self) -> Option<HashMap<String, String>> { | ||
Some(HashMap::from([( | ||
Self::BROKER_NAME.to_string(), | ||
self.broker_name.clone(), | ||
)])) | ||
} | ||
} | ||
|
||
impl FromMap for WipeWritePermOfBrokerRequestHeader { | ||
type Target = Self; | ||
|
||
fn from(map: &HashMap<String, String>) -> Option<Self::Target> { | ||
Some(WipeWritePermOfBrokerRequestHeader { | ||
broker_name: map | ||
.get(WipeWritePermOfBrokerRequestHeader::BROKER_NAME) | ||
.cloned() | ||
.unwrap_or_default(), | ||
}) | ||
} | ||
} | ||
|
||
#[derive(Debug, Clone, Deserialize, Serialize, Default)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct WipeWritePermOfBrokerResponseHeader { | ||
pub wipe_topic_count: i32, | ||
} | ||
|
||
impl WipeWritePermOfBrokerResponseHeader { | ||
const WIPE_TOPIC_COUNT: &'static str = "wipeTopicCount"; | ||
|
||
pub fn new(wipe_topic_count: i32) -> Self { | ||
Self { wipe_topic_count } | ||
} | ||
} | ||
|
||
impl CommandCustomHeader for WipeWritePermOfBrokerResponseHeader { | ||
fn to_map(&self) -> Option<HashMap<String, String>> { | ||
Some(HashMap::from([( | ||
Self::WIPE_TOPIC_COUNT.to_string(), | ||
self.wipe_topic_count.to_string(), | ||
)])) | ||
} | ||
} | ||
|
||
impl FromMap for WipeWritePermOfBrokerResponseHeader { | ||
type Target = Self; | ||
|
||
fn from(map: &HashMap<String, String>) -> Option<Self::Target> { | ||
Some(WipeWritePermOfBrokerResponseHeader { | ||
wipe_topic_count: map | ||
.get(WipeWritePermOfBrokerResponseHeader::WIPE_TOPIC_COUNT) | ||
.and_then(|s| s.parse::<i32>().ok()) | ||
.unwrap_or(0), | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters