src/api2/admin/datastore/backup.rs: add debug flag

This commit is contained in:
Dietmar Maurer 2019-05-29 09:35:21 +02:00
parent 976595e1a9
commit a42d1f55c3
3 changed files with 21 additions and 7 deletions

View File

@ -35,6 +35,7 @@ pub fn api_method_upgrade_backup() -> ApiAsyncMethod {
.required("backup-type", StringSchema::new("Backup type.") .required("backup-type", StringSchema::new("Backup type.")
.format(Arc::new(ApiStringFormat::Enum(&["vm", "ct", "host"])))) .format(Arc::new(ApiStringFormat::Enum(&["vm", "ct", "host"]))))
.required("backup-id", StringSchema::new("Backup ID.")) .required("backup-id", StringSchema::new("Backup ID."))
.optional("debug", BooleanSchema::new("Enable verbose debug logging."))
) )
} }
@ -48,6 +49,8 @@ fn upgrade_to_backup_protocol(
static PROXMOX_BACKUP_PROTOCOL_ID: &str = "proxmox-backup-protocol-h2"; static PROXMOX_BACKUP_PROTOCOL_ID: &str = "proxmox-backup-protocol-h2";
let debug = param["debug"].as_bool().unwrap_or(false);
let store = tools::required_string_param(&param, "store")?.to_owned(); let store = tools::required_string_param(&param, "store")?.to_owned();
let datastore = DataStore::lookup_datastore(&store)?; let datastore = DataStore::lookup_datastore(&store)?;
@ -85,21 +88,23 @@ fn upgrade_to_backup_protocol(
let mut env = BackupEnvironment::new( let mut env = BackupEnvironment::new(
env_type, username.clone(), worker.clone(), datastore, backup_dir); env_type, username.clone(), worker.clone(), datastore, backup_dir);
env.debug = debug;
env.last_backup = last_backup; env.last_backup = last_backup;
env.log(format!("starting new backup on datastore '{}': {:?}", store, path)); env.log(format!("starting new backup on datastore '{}': {:?}", store, path));
let service = BackupService::new(env.clone(), worker.clone()); let service = BackupService::new(env.clone(), worker.clone(), debug);
let abort_future = worker.abort_future(); let abort_future = worker.abort_future();
let env2 = env.clone(); let env2 = env.clone();
let env3 = env.clone();
req_body req_body
.on_upgrade() .on_upgrade()
.map_err(Error::from) .map_err(Error::from)
.and_then(move |conn| { .and_then(move |conn| {
worker.log("upgrade done"); env3.debug("protocol upgrade done");
let mut http = hyper::server::conn::Http::new(); let mut http = hyper::server::conn::Http::new();
http.http2_only(true); http.http2_only(true);

View File

@ -58,6 +58,7 @@ pub struct BackupEnvironment {
env_type: RpcEnvironmentType, env_type: RpcEnvironmentType,
result_attributes: HashMap<String, Value>, result_attributes: HashMap<String, Value>,
user: String, user: String,
pub debug: bool,
pub formatter: &'static OutputFormatter, pub formatter: &'static OutputFormatter,
pub worker: Arc<WorkerTask>, pub worker: Arc<WorkerTask>,
pub datastore: Arc<DataStore>, pub datastore: Arc<DataStore>,
@ -89,6 +90,7 @@ impl BackupEnvironment {
user, user,
worker, worker,
datastore, datastore,
debug: false,
formatter: &JSON_FORMATTER, formatter: &JSON_FORMATTER,
backup_dir, backup_dir,
last_backup: None, last_backup: None,
@ -269,6 +271,10 @@ impl BackupEnvironment {
self.worker.log(msg); self.worker.log(msg);
} }
pub fn debug<S: AsRef<str>>(&self, msg: S) {
if self.debug { self.worker.log(msg); }
}
pub fn format_response(&self, result: Result<Value, Error>) -> Response<Body> { pub fn format_response(&self, result: Result<Value, Error>) -> Response<Body> {
match result { match result {
Ok(data) => (self.formatter.format_data)(data, self), Ok(data) => (self.formatter.format_data)(data, self),

View File

@ -18,16 +18,20 @@ lazy_static!{
static ref BACKUP_ROUTER: Router = super::backup_api(); static ref BACKUP_ROUTER: Router = super::backup_api();
} }
pub struct BackupService { pub struct BackupService {
rpcenv: BackupEnvironment, rpcenv: BackupEnvironment,
worker: Arc<WorkerTask>, worker: Arc<WorkerTask>,
debug: bool,
} }
impl BackupService { impl BackupService {
pub fn new(rpcenv: BackupEnvironment, worker: Arc<WorkerTask>) -> Self { pub fn new(rpcenv: BackupEnvironment, worker: Arc<WorkerTask>, debug: bool) -> Self {
Self { rpcenv, worker } Self { rpcenv, worker, debug }
}
pub fn debug<S: AsRef<str>>(&self, msg: S) {
if self.debug { self.worker.log(msg); }
} }
fn handle_request(&self, req: Request<Body>) -> BoxFut { fn handle_request(&self, req: Request<Body>) -> BoxFut {
@ -41,8 +45,7 @@ impl BackupService {
Err(err) => return Box::new(future::err(http_err!(BAD_REQUEST, err.to_string()))), Err(err) => return Box::new(future::err(http_err!(BAD_REQUEST, err.to_string()))),
}; };
self.worker.log(format!("H2 REQUEST {} {}", method, path)); self.debug(format!("REQUEST: {} {}", method, path));
self.worker.log(format!("H2 COMPO {:?}", components));
let mut uri_param = HashMap::new(); let mut uri_param = HashMap::new();