From 6df31645bcfb98efbe49828400bac108d0d96737 Mon Sep 17 00:00:00 2001 From: Marcin Haba Date: Sat, 3 Jun 2017 19:35:40 +0200 Subject: [PATCH] baculum: Improve errors handling in API restore pages --- .../protected/API/Pages/API/BVFSRestore.php | 18 ++++--- .../protected/API/Pages/API/JobEstimate.php | 8 +-- .../protected/API/Pages/API/JobRun.php | 16 +++--- .../protected/API/Pages/API/RestoreRun.php | 51 +++++++++++++++---- gui/baculum/protected/Common/Class/Errors.php | 16 +++--- 5 files changed, 71 insertions(+), 38 deletions(-) diff --git a/gui/baculum/protected/API/Pages/API/BVFSRestore.php b/gui/baculum/protected/API/Pages/API/BVFSRestore.php index 02b2298aa9..0d16ce1d19 100644 --- a/gui/baculum/protected/API/Pages/API/BVFSRestore.php +++ b/gui/baculum/protected/API/Pages/API/BVFSRestore.php @@ -30,14 +30,18 @@ class BVFSRestore extends BaculumAPIServer { $path = property_exists($params, 'path') ? $params->path : null; $is_valid = true; - $jobidsList = explode(',', $jobids); - if(is_array($jobidsList)) { - for($i = 0; $i < count($jobidsList); $i++) { - $job = $this->getModule('job')->getJobById($jobidsList[$i]); - if(is_null($job)) { - $is_valid = false; - break; + if (!is_null($jobids)) { + $jobidsList = explode(',', $jobids); + if(is_array($jobidsList)) { + for($i = 0; $i < count($jobidsList); $i++) { + $job = $this->getModule('job')->getJobById($jobidsList[$i]); + if(is_null($job)) { + $is_valid = false; + break; + } } + } else { + $is_valid = false; } } else { $is_valid = false; diff --git a/gui/baculum/protected/API/Pages/API/JobEstimate.php b/gui/baculum/protected/API/Pages/API/JobEstimate.php index 5ffb976fc2..f42caada9e 100644 --- a/gui/baculum/protected/API/Pages/API/JobEstimate.php +++ b/gui/baculum/protected/API/Pages/API/JobEstimate.php @@ -71,12 +71,12 @@ class JobEstimate extends BaculumAPIServer { $this->output = $estimation->output; $this->error = (integer)$estimation->exitcode; } else { - $this->output = JobError::MSG_ERROR_CLIENTID_DOES_NOT_EXISTS; - $this->error = JobError::ERROR_CLIENTID_DOES_NOT_EXISTS; + $this->output = JobError::MSG_ERROR_CLIENT_DOES_NOT_EXISTS; + $this->error = JobError::ERROR_CLIENT_DOES_NOT_EXISTS; } } else { - $this->output = JobError::MSG_ERROR_FILESETID_DOES_NOT_EXISTS; - $this->error = JobError::ERROR_FILESETID_DOES_NOT_EXISTS; + $this->output = JobError::MSG_ERROR_FILESET_DOES_NOT_EXISTS; + $this->error = JobError::ERROR_FILESET_DOES_NOT_EXISTS; } } else { $this->output = JobError::MSG_ERROR_INVALID_JOBLEVEL; diff --git a/gui/baculum/protected/API/Pages/API/JobRun.php b/gui/baculum/protected/API/Pages/API/JobRun.php index ed4e230564..36d9436bc2 100644 --- a/gui/baculum/protected/API/Pages/API/JobRun.php +++ b/gui/baculum/protected/API/Pages/API/JobRun.php @@ -96,20 +96,20 @@ class JobRun extends BaculumAPIServer { $this->output = $run->output; $this->error = (integer)$run->exitcode; } else { - $this->output = JobError::MSG_ERROR_POOLID_DOES_NOT_EXISTS; - $this->error = JobError::ERROR_POOLID_DOES_NOT_EXISTS; + $this->output = JobError::MSG_ERROR_POOL_DOES_NOT_EXISTS; + $this->error = JobError::ERROR_POOL_DOES_NOT_EXISTS; } } else { - $this->output = JobError::MSG_ERROR_STORAGEID_DOES_NOT_EXISTS; - $this->error = JobError::ERROR_STORAGEID_DOES_NOT_EXISTS; + $this->output = JobError::MSG_ERROR_STORAGE_DOES_NOT_EXISTS; + $this->error = JobError::ERROR_STORAGE_DOES_NOT_EXISTS; } } else { - $this->output = JobError::MSG_ERROR_CLIENTID_DOES_NOT_EXISTS; - $this->error = JobError::ERROR_CLIENTID_DOES_NOT_EXISTS; + $this->output = JobError::MSG_ERROR_CLIENT_DOES_NOT_EXISTS; + $this->error = JobError::ERROR_CLIENT_DOES_NOT_EXISTS; } } else { - $this->output = JobError::MSG_ERROR_FILESETID_DOES_NOT_EXISTS; - $this->error = JobError::ERROR_FILESETID_DOES_NOT_EXISTS; + $this->output = JobError::MSG_ERROR_FILESET_DOES_NOT_EXISTS; + $this->error = JobError::ERROR_FILESET_DOES_NOT_EXISTS; } } else { $this->output = JobError::MSG_ERROR_INVALID_JOBLEVEL; diff --git a/gui/baculum/protected/API/Pages/API/RestoreRun.php b/gui/baculum/protected/API/Pages/API/RestoreRun.php index 431f4ece97..f7ed970515 100644 --- a/gui/baculum/protected/API/Pages/API/RestoreRun.php +++ b/gui/baculum/protected/API/Pages/API/RestoreRun.php @@ -28,13 +28,22 @@ class RestoreRun extends BaculumAPIServer { public function create($params) { $rfile = property_exists($params, 'rpath') ? $params->rpath : null; - $clientid = property_exists($params, 'clientid') ? intval($params->clientid) : null; - $fileset = property_exists($params, 'fileset') ? $params->fileset : null; - $priority = property_exists($params, 'priority') ? intval($params->priority) : null; + + $fileset = null; + if (property_exists($params, 'fileset') && $this->getModule('misc')->isValidName($params->fileset)) { + $fileset = $params->fileset; + } + $client = null; + if (property_exists($params, 'clientid')) { + $clientid = intval($params->clientid); + $client_row = $this->getModule('client')->getClientById($clientid); + $client = is_object($client_row) ? $client_row->name : null; + } elseif (property_exists($params, 'client') && $this->getModule('misc')->isValidName($params->client)) { + $client = $params->client; + } + $priority = property_exists($params, 'priority') ? intval($params->priority) : 10; // default priority is set to 10 $where = property_exists($params, 'where') ? $params->where : null; $replace = property_exists($params, 'replace') ? $params->replace : null; - - $client = $this->getModule('client')->getClientById($clientid); $misc = $this->getModule('misc'); if(!is_null($fileset)) { @@ -42,7 +51,16 @@ class RestoreRun extends BaculumAPIServer { if(preg_match($misc::RPATH_PATTERN, $rfile) === 1) { if(!is_null($where)) { if(!is_null($replace)) { - $restore = $this->getModule('bconsole')->bconsoleCommand($this->director, array('restore', 'file="?' . $rfile . '"', 'client="' . $client->name . '"', 'where="' . $where . '"', 'replace="' . $replace . '"', 'fileset="' . $fileset . '"', 'priority="' . $priority . '"', 'yes'), $this->user); + $command = array('restore', + 'file="?' . $rfile . '"', + 'client="' . $client . '"', + 'where="' . $where . '"', + 'replace="' . $replace . '"', + 'fileset="' . $fileset . '"', + 'priority="' . $priority . '"', + 'yes' + ); + $restore = $this->getModule('bconsole')->bconsoleCommand($this->director, $command, $this->user); $this->removeTmpRestoreTable($rfile); $this->output = $restore->output; $this->error = (integer)$restore->exitcode; @@ -59,12 +77,12 @@ class RestoreRun extends BaculumAPIServer { $this->error = JobError::ERROR_INVALID_RPATH; } } else { - $this->output = JobError::MSG_ERROR_CLIENTID_DOES_NOT_EXISTS; - $this->error = JobError::ERROR_CLIENTID_DOES_NOT_EXISTS; + $this->output = JobError::MSG_ERROR_CLIENT_DOES_NOT_EXISTS; + $this->error = JobError::ERROR_CLIENT_DOES_NOT_EXISTS; } } else { - $this->output = JobError::MSG_ERROR_FILESETID_DOES_NOT_EXISTS; - $this->error = JobError::ERROR_FILESETID_DOES_NOT_EXISTS; + $this->output = JobError::MSG_ERROR_FILESET_DOES_NOT_EXISTS; + $this->error = JobError::ERROR_FILESET_DOES_NOT_EXISTS; } } @@ -77,7 +95,18 @@ class RestoreRun extends BaculumAPIServer { $connection->setActive(true); $sql = "DROP TABLE $tableName"; $pdo = $connection->getPdoInstance(); - $pdo->exec($sql); + try { + $pdo->exec($sql); + } catch(PDOException $e) { + $emsg = 'Problem during delete temporary Bvfs table. ' . $e->getMessage(); + $this->getModule('logging')->log( + __FUNCTION__, + $emsg, + Logging::CATEGORY_APPLICATION, + __FILE__, + __LINE__ + ); + } $pdo = null; } } diff --git a/gui/baculum/protected/Common/Class/Errors.php b/gui/baculum/protected/Common/Class/Errors.php index e4f5cff573..8a308d5fb3 100644 --- a/gui/baculum/protected/Common/Class/Errors.php +++ b/gui/baculum/protected/Common/Class/Errors.php @@ -85,20 +85,20 @@ class PoolError extends GenericError { class JobError extends GenericError { const ERROR_JOB_DOES_NOT_EXISTS = 50; const ERROR_INVALID_JOBLEVEL = 51; - const ERROR_FILESETID_DOES_NOT_EXISTS = 52; - const ERROR_CLIENTID_DOES_NOT_EXISTS = 53; - const ERROR_STORAGEID_DOES_NOT_EXISTS = 54; - const ERROR_POOLID_DOES_NOT_EXISTS = 55; + const ERROR_FILESET_DOES_NOT_EXISTS = 52; + const ERROR_CLIENT_DOES_NOT_EXISTS = 53; + const ERROR_STORAGE_DOES_NOT_EXISTS = 54; + const ERROR_POOL_DOES_NOT_EXISTS = 55; const ERROR_INVALID_RPATH = 56; const ERROR_INVALID_WHERE_OPTION = 57; const ERROR_INVALID_REPLACE_OPTION = 58; const MSG_ERROR_JOB_DOES_NOT_EXISTS = 'Job with inputted jobid does not exist.'; const MSG_ERROR_INVALID_JOBLEVEL = 'Inputted job level is invalid.'; - const MSG_ERROR_FILESETID_DOES_NOT_EXISTS = 'FileSet resource with inputted filesetid does not exist.'; - const MSG_ERROR_CLIENTID_DOES_NOT_EXISTS = 'Client with inputted clientid does not exist.'; - const MSG_ERROR_STORAGEID_DOES_NOT_EXISTS = 'Storage with inputted storageid does not exist.'; - const MSG_ERROR_POOLID_DOES_NOT_EXISTS = 'Pool with inputted poolid does not exist.'; + const MSG_ERROR_FILESET_DOES_NOT_EXISTS = 'FileSet resource does not exist.'; + const MSG_ERROR_CLIENT_DOES_NOT_EXISTS = 'Client does not exist.'; + const MSG_ERROR_STORAGE_DOES_NOT_EXISTS = 'Storage does not exist.'; + const MSG_ERROR_POOL_DOES_NOT_EXISTS = 'Pool does not exist.'; const MSG_ERROR_INVALID_RPATH = 'Inputted rpath for restore is invalid. Proper format is b2[0-9]+.'; const MSG_ERROR_INVALID_WHERE_OPTION = 'Inputted "where" option is invalid.'; const MSG_ERROR_INVALID_REPLACE_OPTION = 'Inputted "replace" option is invalid.'; -- 2.39.2