Modifications in error management and correct error in Image.php
This commit is contained in:
parent
dcf0d8b2ba
commit
e9c7477ff0
5 changed files with 124 additions and 39 deletions
|
@ -89,9 +89,11 @@ class AppTest{
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getPostParam($name){
|
public function getPostParam($name){
|
||||||
|
if(isset($this->postParams[$name])){
|
||||||
return $this->postParams[$name];
|
return $this->postParams[$name];
|
||||||
|
}else{
|
||||||
|
$this->setOutput("Error", "Missing parameter ".$name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setPostParam($name, $value){
|
public function setPostParam($name, $value){
|
||||||
|
|
|
@ -6,6 +6,9 @@ include_once("../core/Compute.php");
|
||||||
$image = new Image($App);
|
$image = new Image($App);
|
||||||
$compute = new Compute($App);
|
$compute = new Compute($App);
|
||||||
|
|
||||||
|
// Création image
|
||||||
|
/*
|
||||||
|
echo "Création image :</br>";
|
||||||
$opt = Array();
|
$opt = Array();
|
||||||
$opt['name'] = "Test";
|
$opt['name'] = "Test";
|
||||||
$opt['tags'] = ['test', 'openstack'];
|
$opt['tags'] = ['test', 'openstack'];
|
||||||
|
@ -16,28 +19,86 @@ $opt['minDisk'] = 1;
|
||||||
$opt['protected'] = false;
|
$opt['protected'] = false;
|
||||||
$opt['minRam'] = 10;
|
$opt['minRam'] = 10;
|
||||||
|
|
||||||
//$App->setPostParam('id', 'sdfihlus154dfhj');
|
$App->setPostParam('opt', $opt);
|
||||||
//$err = $image->action("createImage");
|
$image->action("createImage");
|
||||||
|
$retCreate = json_decode($App->show(), true)["Images"];
|
||||||
|
$idNew = $retCreate['id'];
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
// Delete Image
|
||||||
|
$App->setPostParam('id', $idNew);
|
||||||
|
$image->action("deleteImage");
|
||||||
|
*/
|
||||||
|
|
||||||
//Liste des images
|
// Liste images
|
||||||
$image->action("listImage");
|
$image->action("listImage");
|
||||||
$im = $App->show();
|
$im = $App->show();
|
||||||
$images = json_decode($im, true)["Images"];
|
$images = json_decode($im, true)["Images"];
|
||||||
|
|
||||||
echo "Images présentes :";
|
echo "List images :</br>";
|
||||||
echo "</br>";
|
|
||||||
foreach($images as $i){
|
foreach($images as $i){
|
||||||
$recup = $i;
|
echo $i['name']."</br>"; // Nom
|
||||||
echo $recup['name'];
|
echo $i['status']."</br>"; // Status
|
||||||
|
$id = $i['id']; // Id
|
||||||
|
echo $id."</br>";
|
||||||
|
foreach ($i['tags'] as $tag) { // Tags
|
||||||
|
echo $tag."</br>";
|
||||||
|
}
|
||||||
echo "</br>";
|
echo "</br>";
|
||||||
//echo $recup['id'];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Details images
|
||||||
|
echo "Détail image :</br>";
|
||||||
|
$App->setPostParam('id', $id);
|
||||||
|
$image->action("detailsImage");
|
||||||
|
$retDetails = json_decode($App->show(), true)["Images"];
|
||||||
|
echo $retDetails['id']."</br>";
|
||||||
echo "</br>";
|
echo "</br>";
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
// Download image
|
||||||
|
$App->setPostParam('id', $id);
|
||||||
|
$image->action("downloadImage");
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
// Desactivate Images
|
||||||
|
echo "Desactivate image : </br>";
|
||||||
|
echo $id."</br>";
|
||||||
|
$App->setPostParam('id', $id);
|
||||||
|
$err = $image->action("desactivateImage");
|
||||||
|
echo "</br>";
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
// Resactivate Images
|
||||||
|
echo $id."</br>";
|
||||||
|
$App->setPostParam('id', $id);
|
||||||
|
$err = $image->action("resactivateImage");
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
// Details images
|
||||||
|
echo "Update image :</br>";
|
||||||
|
$optUpdate = Array();
|
||||||
|
$optUpdate['tags'] = ['ciros', 'testUpdate'];
|
||||||
|
$App->setPostParam('id', $id);
|
||||||
|
$App->setPostParam('opt', $optUpdate);
|
||||||
|
$image->action("updateImage");
|
||||||
|
$retDetails = json_decode($App->show(), true)["Images"];
|
||||||
|
foreach ($retDetails['tags'] as $tag) { // Tags
|
||||||
|
echo $tag."</br>";
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
echo "Flavors: ";
|
echo "Flavors: ";
|
||||||
echo "</br>";
|
echo "</br>";
|
||||||
|
|
||||||
$compute->action("listFlavors");
|
$compute->action("listFlavors");
|
||||||
$flavors = json_decode($App->show(), true)["Flavors"];
|
$flavors = json_decode($App->show(), true)["Flavors"];
|
||||||
|
|
||||||
|
@ -49,17 +110,5 @@ foreach($flavors as $f){
|
||||||
echo "vcpus=".$f['vcpus'];
|
echo "vcpus=".$f['vcpus'];
|
||||||
echo "</br>";
|
echo "</br>";
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
$App->setPostParam('id', 354);
|
|
||||||
$err = $image->action("deleteImage");
|
|
||||||
$temp = $App->show();
|
|
||||||
$ret = json_decode($temp, true)["Images"];
|
|
||||||
echo $ret['id'];
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
?>
|
?>
|
|
@ -113,13 +113,18 @@ class App{
|
||||||
|
|
||||||
public function getPostParam($name){
|
public function getPostParam($name){
|
||||||
|
|
||||||
return $this->postParams[$name];
|
if(isset($this->postParams[$name])){
|
||||||
|
return $this->postParams[$name];
|
||||||
|
}else{
|
||||||
|
$this->setOutput("Error", "Missing parameter ".$name);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setPostParam($name, $value){
|
|
||||||
|
|
||||||
$this->postParams[$name]= $value;
|
public function setPostParam($param, $value){
|
||||||
|
|
||||||
|
$this->postParams[$param] = $value;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,19 +18,48 @@ Class errorManagement{
|
||||||
}
|
}
|
||||||
|
|
||||||
public function BaseErrorHandler($error){
|
public function BaseErrorHandler($error){
|
||||||
|
$this->app->setOutput("Error", "BaseError");
|
||||||
}
|
}
|
||||||
|
|
||||||
public function BadResponseHandler($error){
|
public function BadResponseHandler($error){
|
||||||
$this->app->setOutput("Error", "Erreur Interne, Merci de contacter un administrateur!");
|
$statusCode = $error->getResponse()->getStatusCode();
|
||||||
|
switch ($statusCode) {
|
||||||
|
case 400:
|
||||||
|
$this->app->setOutput("Error", "Invalid input.");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 401:
|
||||||
|
$this->app->setOutput("Error", "Authentification failed.");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 403:
|
||||||
|
$this->app->setOutput("Error", "Operation forbidden.");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 404:
|
||||||
|
$this->app->setOutput("Error", "Ressource not found.");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 500:
|
||||||
|
$this->app->setOutput("Error", "Internal server error, please contact an administrator.");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 503:
|
||||||
|
$this->app->setOutput("Error", "Service unvailable for the moment.");
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
$this->app->setOutput("Error", "Unknow error, please contact an administrator.");
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function NotImplementedHandler($error){
|
public function NotImplementedHandler($error){
|
||||||
$this->app->setOutput("Error", "Erreur Interne, Merci de contacter un administrateur!");
|
$this->app->setOutput("Error", "Internal error (not implemented yet), please contact an administrator");
|
||||||
}
|
}
|
||||||
|
|
||||||
public function UserInputHandler($error){
|
public function UserInputHandler($error){
|
||||||
|
$this->app->setOutput("Error", "UserInputError");
|
||||||
}
|
}
|
||||||
|
|
||||||
public function OtherException($error){
|
public function OtherException($error){
|
||||||
|
|
|
@ -76,7 +76,7 @@ class image implements Core{
|
||||||
|
|
||||||
// Check the image name
|
// Check the image name
|
||||||
if(isset($opt['name'])){
|
if(isset($opt['name'])){
|
||||||
$imagesList = listImage();
|
$imagesList = $this->listImage();
|
||||||
if(isset($imagesList)){
|
if(isset($imagesList)){
|
||||||
foreach($imagesList as $image){
|
foreach($imagesList as $image){
|
||||||
if(strcmp($image->name, $opt['name']) == 0){ // if the image name already exists -> error
|
if(strcmp($image->name, $opt['name']) == 0){ // if the image name already exists -> error
|
||||||
|
@ -84,7 +84,7 @@ class image implements Core{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
$options['name'] = $opt['name'];
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
$this->app->setOutput("Error", "Missing parameter 'name' for the new image");
|
$this->app->setOutput("Error", "Missing parameter 'name' for the new image");
|
||||||
|
@ -118,7 +118,7 @@ class image implements Core{
|
||||||
if(isset($opt['protected'])){ // boolean
|
if(isset($opt['protected'])){ // boolean
|
||||||
$options['protected'] = $opt['protected'];
|
$options['protected'] = $opt['protected'];
|
||||||
}
|
}
|
||||||
if(isset($opt['properties'])){ // type dict ?
|
if(isset($opt['properties'])){ // type dict
|
||||||
$options['properties'] = $opt['properties'];
|
$options['properties'] = $opt['properties'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -187,7 +187,6 @@ class image implements Core{
|
||||||
$this->app->setOutput("Error", "Image doesn't exist");
|
$this->app->setOutput("Error", "Image doesn't exist");
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
echo 'toto';
|
|
||||||
$this->app->setOutput("Images", $image);
|
$this->app->setOutput("Images", $image);
|
||||||
}
|
}
|
||||||
}catch(BadResponseError $e){
|
}catch(BadResponseError $e){
|
||||||
|
@ -326,6 +325,7 @@ class image implements Core{
|
||||||
if($image == null){ // if the image don't exists -> error
|
if($image == null){ // if the image don't exists -> error
|
||||||
$this->app->setOutput("Error", "Image doesn't exist");
|
$this->app->setOutput("Error", "Image doesn't exist");
|
||||||
}
|
}
|
||||||
|
|
||||||
$image->reactivate();
|
$image->reactivate();
|
||||||
}catch(BadResponseError $e){
|
}catch(BadResponseError $e){
|
||||||
$this->app->getErrorInstance()->BadResponseHandler($e);
|
$this->app->getErrorInstance()->BadResponseHandler($e);
|
||||||
|
|
Loading…
Add table
Reference in a new issue