src/api2/admin/datastore/backup/environment.rs: use separate file
This commit is contained in:
parent
ca60c371e2
commit
d95ced64ad
|
@ -17,6 +17,9 @@ use crate::api_schema::*;
|
||||||
use crate::server::formatter::*;
|
use crate::server::formatter::*;
|
||||||
use crate::server::WorkerTask;
|
use crate::server::WorkerTask;
|
||||||
|
|
||||||
|
mod environment;
|
||||||
|
use environment::*;
|
||||||
|
|
||||||
pub fn api_method_upgrade_backup() -> ApiAsyncMethod {
|
pub fn api_method_upgrade_backup() -> ApiAsyncMethod {
|
||||||
ApiAsyncMethod::new(
|
ApiAsyncMethod::new(
|
||||||
upgrade_h2upload,
|
upgrade_h2upload,
|
||||||
|
@ -29,53 +32,6 @@ lazy_static!{
|
||||||
static ref BACKUP_ROUTER: Router = backup_api();
|
static ref BACKUP_ROUTER: Router = backup_api();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// `RpcEnvironmet` implementation for backup service
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct BackupEnvironment {
|
|
||||||
env_type: RpcEnvironmentType,
|
|
||||||
result_attributes: HashMap<String, Value>,
|
|
||||||
user: String,
|
|
||||||
worker: Arc<WorkerTask>,
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
impl BackupEnvironment {
|
|
||||||
pub fn new(env_type: RpcEnvironmentType, user: String, worker: Arc<WorkerTask>) -> Self {
|
|
||||||
Self {
|
|
||||||
result_attributes: HashMap::new(),
|
|
||||||
env_type,
|
|
||||||
user,
|
|
||||||
worker,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn log<S: AsRef<str>>(&self, msg: S) {
|
|
||||||
self.worker.log(msg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl RpcEnvironment for BackupEnvironment {
|
|
||||||
|
|
||||||
fn set_result_attrib(&mut self, name: &str, value: Value) {
|
|
||||||
self.result_attributes.insert(name.into(), value);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_result_attrib(&self, name: &str) -> Option<&Value> {
|
|
||||||
self.result_attributes.get(name)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn env_type(&self) -> RpcEnvironmentType {
|
|
||||||
self.env_type
|
|
||||||
}
|
|
||||||
|
|
||||||
fn set_user(&mut self, _user: Option<String>) {
|
|
||||||
panic!("unable to change user");
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_user(&self) -> Option<String> {
|
|
||||||
Some(self.user.clone())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct BackupService {
|
pub struct BackupService {
|
||||||
rpcenv: BackupEnvironment,
|
rpcenv: BackupEnvironment,
|
||||||
|
|
|
@ -0,0 +1,55 @@
|
||||||
|
use std::sync::Arc;
|
||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
use serde_json::Value;
|
||||||
|
|
||||||
|
use crate::api_schema::router::{RpcEnvironment, RpcEnvironmentType};
|
||||||
|
use crate::server::WorkerTask;
|
||||||
|
|
||||||
|
/// `RpcEnvironmet` implementation for backup service
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct BackupEnvironment {
|
||||||
|
env_type: RpcEnvironmentType,
|
||||||
|
result_attributes: HashMap<String, Value>,
|
||||||
|
user: String,
|
||||||
|
worker: Arc<WorkerTask>,
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
impl BackupEnvironment {
|
||||||
|
pub fn new(env_type: RpcEnvironmentType, user: String, worker: Arc<WorkerTask>) -> Self {
|
||||||
|
Self {
|
||||||
|
result_attributes: HashMap::new(),
|
||||||
|
env_type,
|
||||||
|
user,
|
||||||
|
worker,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn log<S: AsRef<str>>(&self, msg: S) {
|
||||||
|
self.worker.log(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl RpcEnvironment for BackupEnvironment {
|
||||||
|
|
||||||
|
fn set_result_attrib(&mut self, name: &str, value: Value) {
|
||||||
|
self.result_attributes.insert(name.into(), value);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_result_attrib(&self, name: &str) -> Option<&Value> {
|
||||||
|
self.result_attributes.get(name)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn env_type(&self) -> RpcEnvironmentType {
|
||||||
|
self.env_type
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_user(&mut self, _user: Option<String>) {
|
||||||
|
panic!("unable to change user");
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_user(&self) -> Option<String> {
|
||||||
|
Some(self.user.clone())
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue