-
Notifications
You must be signed in to change notification settings - Fork 333
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
xifyang
committed
Sep 4, 2023
1 parent
a12ee5c
commit f064ef0
Showing
7 changed files
with
164 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
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
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,61 @@ | ||
// Copyright 2023 Greptime Team | ||
// | ||
// 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. | ||
|
||
use std::collections::HashMap; | ||
|
||
use common_meta::key::MAINTENANCE_KEY; | ||
use common_meta::rpc::store::PutRequest; | ||
use snafu::{OptionExt, ResultExt}; | ||
use tonic::codegen::http; | ||
|
||
use crate::error::{self, Result}; | ||
use crate::service::admin::HttpHandler; | ||
use crate::service::store::kv::KvStoreRef; | ||
pub struct MaintenanceHandler { | ||
pub kv_store: KvStoreRef, | ||
} | ||
|
||
#[async_trait::async_trait] | ||
impl HttpHandler for MaintenanceHandler { | ||
async fn handle( | ||
&self, | ||
_: &str, | ||
params: &HashMap<String, String>, | ||
) -> Result<http::Response<String>> { | ||
let switch_on = params | ||
.get("switch_on") | ||
.map(|on| on.parse::<bool>()) | ||
.context(error::MissingRequiredParameterSnafu { param: "switch-on" })? | ||
.context(error::ParseBoolSnafu { | ||
err_msg: "`switch_on` is not a valid bool", | ||
})?; | ||
|
||
let req = PutRequest { | ||
key: MAINTENANCE_KEY.to_string().into_bytes(), | ||
value: vec![], | ||
prev_kv: false, | ||
}; | ||
|
||
if switch_on { | ||
self.kv_store.put(req).await?; | ||
} else { | ||
self.kv_store.delete(req.key.as_slice(), false).await?; | ||
} | ||
|
||
http::Response::builder() | ||
.status(http::StatusCode::OK) | ||
.body(format!("metasvc is succeed to be set maintenance mode",)) | ||
.context(error::InvalidHttpBodySnafu) | ||
} | ||
} |