From 1fa4dcbab660a7185165b106b178a12de0917f59 Mon Sep 17 00:00:00 2001 From: Yoggzo Date: Mon, 21 Mar 2016 10:19:26 +0100 Subject: correct error in error management ! --- server/Test/imageTests.php | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'server/Test/imageTests.php') diff --git a/server/Test/imageTests.php b/server/Test/imageTests.php index 883387d..d184d44 100644 --- a/server/Test/imageTests.php +++ b/server/Test/imageTests.php @@ -15,7 +15,7 @@ $opt['protected'] = false; $opt['minRam'] = 10; //$App->setPostParam('id', 'sdfihlus154dfhj'); -$err = $image->action("createImage"); +//$err = $image->action("createImage"); //Liste des images @@ -35,16 +35,15 @@ foreach($images as $i){ echo "
"; echo "Erreur capturée: "; echo "
"; - - /* - //$App->setPostParam('id', $recup['id']); - $App->setPostParam('id', 'sdfihlus154dfhj'); - $err = $image->action("detailsImage"); - $temp = $App->show(); - $ret = json_decode($temp, true)["Images"]; - echo $ret['id']; - */ - //$App->getPostParam("id"); + +/* +$App->setPostParam('id', 354); +$err = $image->action("deleteImage"); +$temp = $App->show(); +$ret = json_decode($temp, true)["Images"]; +echo $ret['id']; +*/ + -- cgit v1.2.3 From dcf0d8b2ba2547720215f7de55a747bf7ec47a0b Mon Sep 17 00:00:00 2001 From: Yoggzo Date: Wed, 23 Mar 2016 15:46:57 +0100 Subject: begining of automating tasks --- server/Test/imageTests.php | 18 ++++++++- server/core/App.php | 6 +++ server/core/Automating.php | 95 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 117 insertions(+), 2 deletions(-) create mode 100644 server/core/Automating.php (limited to 'server/Test/imageTests.php') diff --git a/server/Test/imageTests.php b/server/Test/imageTests.php index d184d44..d86c664 100644 --- a/server/Test/imageTests.php +++ b/server/Test/imageTests.php @@ -1,8 +1,10 @@ action("listImage"); $im = $App->show(); $images = json_decode($im, true)["Images"]; -$recup; echo "Images présentes :"; echo "
"; @@ -33,9 +34,22 @@ foreach($images as $i){ //echo $recup['id']; } echo "
"; -echo "Erreur capturée: "; + +echo "Flavors: "; echo "
"; +$compute->action("listFlavors"); +$flavors = json_decode($App->show(), true)["Flavors"]; + +foreach($flavors as $f){ + echo "Id=".$f['id'].", "; + echo "name=".$f['name'].", "; + echo "ram=".$f['ram'].", "; + echo "disk=".$f['disk'].", "; + echo "vcpus=".$f['vcpus']; + echo "
"; + } + /* $App->setPostParam('id', 354); $err = $image->action("deleteImage"); diff --git a/server/core/App.php b/server/core/App.php index 6970e5f..10813bd 100755 --- a/server/core/App.php +++ b/server/core/App.php @@ -116,6 +116,12 @@ class App{ return $this->postParams[$name]; } + + public function setPostParam($name, $value){ + + $this->postParams[$name]= $value; + + } public function setOutput($key, $out){ diff --git a/server/core/Automating.php b/server/core/Automating.php new file mode 100644 index 0000000..2665541 --- /dev/null +++ b/server/core/Automating.php @@ -0,0 +1,95 @@ +app->setOutput("Error", "Incorrect parameter app"); + } + $this->app = $app; + $this->libClass = $app->getLibClass("Automating"); + } + + /** + * Execute an action + * + * @param String $action name of another function of this class + * + * @return void + */ + public function action($action){ + $this->{$action.""}(); + } + + + private function createImageOnNewServer(){ + try{ + $image = new Image($this->app); + $compute = new Compute($this->app); + + $name = $this->app->getPostParam("name"); + $falvor_id = $this->app->getPostParam("falvor_id"); // Compris entre 1 et 5 (1=petit serveur, 5=gros serveur) + + $opt = Array(); + $opt['name'] = $name; + $opt['visibility'] = 'public'; + $opt['minDisk'] = 100; // A VOIR + $opt['minRam'] = 128; // A VOIR + $opt['protected'] = false; + + $this->app->setPostParam("opt", $opt); + + $image->action("createImage"); + $res = json_decode($this->app->show(), true)["Images"]; + + + $this->app->setPostParam("name", $name); + $this->app->setPostParam("imageId", $res['id']); + $this->app->setPostParam("flavorId", $falvor_id); + + $compute->action("createServer"); + + }catch(BadResponseError $e){ + $this->app->getErrorInstance()->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance()->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance()->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance()->NotImplementedHandler($e); + }catch(Exception $e){ + $this->app->getErrorInstance()->OtherException($e); + } + } + + +} + +?> \ No newline at end of file -- cgit v1.2.3 From e9c7477ff0acedf9b49e508e1543395bbcbf7533 Mon Sep 17 00:00:00 2001 From: Yoggzo Date: Sun, 27 Mar 2016 19:24:03 +0200 Subject: Modifications in error management and correct error in Image.php --- server/Test/AppTestClass.php | 8 ++-- server/Test/imageTests.php | 95 +++++++++++++++++++++++++++++++---------- server/core/App.php | 15 ++++--- server/core/ErrorManagement.php | 37 ++++++++++++++-- server/core/Image.php | 8 ++-- 5 files changed, 124 insertions(+), 39 deletions(-) (limited to 'server/Test/imageTests.php') diff --git a/server/Test/AppTestClass.php b/server/Test/AppTestClass.php index 3f8abbe..a663514 100755 --- a/server/Test/AppTestClass.php +++ b/server/Test/AppTestClass.php @@ -89,9 +89,11 @@ class AppTest{ } 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){ diff --git a/server/Test/imageTests.php b/server/Test/imageTests.php index d86c664..4adec08 100644 --- a/server/Test/imageTests.php +++ b/server/Test/imageTests.php @@ -6,6 +6,9 @@ include_once("../core/Compute.php"); $image = new Image($App); $compute = new Compute($App); +// Création image +/* +echo "Création image :
"; $opt = Array(); $opt['name'] = "Test"; $opt['tags'] = ['test', 'openstack']; @@ -16,28 +19,86 @@ $opt['minDisk'] = 1; $opt['protected'] = false; $opt['minRam'] = 10; -//$App->setPostParam('id', 'sdfihlus154dfhj'); -//$err = $image->action("createImage"); +$App->setPostParam('opt', $opt); +$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"); $im = $App->show(); $images = json_decode($im, true)["Images"]; -echo "Images présentes :"; -echo "
"; +echo "List images :
"; foreach($images as $i){ - $recup = $i; - echo $recup['name']; + echo $i['name']."
"; // Nom + echo $i['status']."
"; // Status + $id = $i['id']; // Id + echo $id."
"; + foreach ($i['tags'] as $tag) { // Tags + echo $tag."
"; + } echo "
"; - //echo $recup['id']; - } + } + + +// Details images +echo "Détail image :
"; +$App->setPostParam('id', $id); +$image->action("detailsImage"); +$retDetails = json_decode($App->show(), true)["Images"]; +echo $retDetails['id']."
"; +echo "
"; + + +/* +// Download image +$App->setPostParam('id', $id); +$image->action("downloadImage"); +*/ + + +// Desactivate Images +echo "Desactivate image :
"; +echo $id."
"; +$App->setPostParam('id', $id); +$err = $image->action("desactivateImage"); echo "
"; + +/* +// Resactivate Images +echo $id."
"; +$App->setPostParam('id', $id); +$err = $image->action("resactivateImage"); +*/ + + +/* +// Details images +echo "Update image :
"; +$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."
"; +} +*/ + + +/* echo "Flavors: "; echo "
"; - $compute->action("listFlavors"); $flavors = json_decode($App->show(), true)["Flavors"]; @@ -49,17 +110,5 @@ foreach($flavors as $f){ echo "vcpus=".$f['vcpus']; echo "
"; } - -/* -$App->setPostParam('id', 354); -$err = $image->action("deleteImage"); -$temp = $App->show(); -$ret = json_decode($temp, true)["Images"]; -echo $ret['id']; -*/ - - - - - +*/ ?> \ No newline at end of file diff --git a/server/core/App.php b/server/core/App.php index 10813bd..48bb9ab 100755 --- a/server/core/App.php +++ b/server/core/App.php @@ -112,15 +112,20 @@ class App{ } 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; + } public function setOutput($key, $out){ diff --git a/server/core/ErrorManagement.php b/server/core/ErrorManagement.php index 3257dd3..e7cb83e 100755 --- a/server/core/ErrorManagement.php +++ b/server/core/ErrorManagement.php @@ -18,19 +18,48 @@ Class errorManagement{ } public function BaseErrorHandler($error){ - + $this->app->setOutput("Error", "BaseError"); } 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){ - $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){ - + $this->app->setOutput("Error", "UserInputError"); } public function OtherException($error){ diff --git a/server/core/Image.php b/server/core/Image.php index 71e19ce..e9736a2 100755 --- a/server/core/Image.php +++ b/server/core/Image.php @@ -76,7 +76,7 @@ class image implements Core{ // Check the image name if(isset($opt['name'])){ - $imagesList = listImage(); + $imagesList = $this->listImage(); if(isset($imagesList)){ foreach($imagesList as $image){ 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{ $this->app->setOutput("Error", "Missing parameter 'name' for the new image"); @@ -118,7 +118,7 @@ class image implements Core{ if(isset($opt['protected'])){ // boolean $options['protected'] = $opt['protected']; } - if(isset($opt['properties'])){ // type dict ? + if(isset($opt['properties'])){ // type dict $options['properties'] = $opt['properties']; } @@ -187,7 +187,6 @@ class image implements Core{ $this->app->setOutput("Error", "Image doesn't exist"); } else{ - echo 'toto'; $this->app->setOutput("Images", $image); } }catch(BadResponseError $e){ @@ -326,6 +325,7 @@ class image implements Core{ if($image == null){ // if the image don't exists -> error $this->app->setOutput("Error", "Image doesn't exist"); } + $image->reactivate(); }catch(BadResponseError $e){ $this->app->getErrorInstance()->BadResponseHandler($e); -- cgit v1.2.3