From 58a936d0158e4f90596bfe88352f5a570094c436 Mon Sep 17 00:00:00 2001 From: Yoggzo Date: Wed, 17 Feb 2016 17:56:11 +0100 Subject: Add errors features for tests calsses --- server/Test/AppTestClass.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'server/Test/AppTestClass.php') diff --git a/server/Test/AppTestClass.php b/server/Test/AppTestClass.php index 311b9bf..40a5847 100755 --- a/server/Test/AppTestClass.php +++ b/server/Test/AppTestClass.php @@ -1,6 +1,12 @@ openstack = new OpenStack\OpenStack([]); $this->pluginsApi = plugin_api::getInstance(); $this->output = array(); + $this->errorClass = new errorManagement($this); } @@ -70,4 +78,9 @@ class AppTest{ echo json_encode($this->output); } + public function getErrorInstance(){ + + return $this->errorClass; + + } } \ No newline at end of file -- cgit v1.2.3 From cfce59d6dc120848624e105614575ae0f48af81b Mon Sep 17 00:00:00 2001 From: Yoggzo Date: Mon, 29 Feb 2016 14:20:13 +0100 Subject: merge --- client/images/spin/128x128/Preloader_1.gif | Bin 0 -> 71831 bytes client/images/spin/128x128/Preloader_10.gif | Bin 0 -> 19793 bytes client/images/spin/128x128/Preloader_2.gif | Bin 0 -> 7879 bytes client/images/spin/128x128/Preloader_3.gif | Bin 0 -> 22053 bytes client/images/spin/128x128/Preloader_4.gif | Bin 0 -> 19963 bytes client/images/spin/128x128/Preloader_5.gif | Bin 0 -> 84698 bytes client/images/spin/128x128/Preloader_6.gif | Bin 0 -> 19299 bytes client/images/spin/128x128/Preloader_7.gif | Bin 0 -> 12651 bytes client/images/spin/128x128/Preloader_8.gif | Bin 0 -> 81985 bytes client/images/spin/128x128/Preloader_9.gif | Bin 0 -> 48009 bytes client/images/spin/32x32/Preloader_1.gif | Bin 0 -> 17796 bytes client/images/spin/32x32/Preloader_10.gif | Bin 0 -> 5943 bytes client/images/spin/32x32/Preloader_2.gif | Bin 0 -> 3551 bytes client/images/spin/32x32/Preloader_3.gif | Bin 0 -> 7980 bytes client/images/spin/32x32/Preloader_4.gif | Bin 0 -> 6852 bytes client/images/spin/32x32/Preloader_5.gif | Bin 0 -> 22755 bytes client/images/spin/32x32/Preloader_6.gif | Bin 0 -> 5965 bytes client/images/spin/32x32/Preloader_7.gif | Bin 0 -> 4217 bytes client/images/spin/32x32/Preloader_8.gif | Bin 0 -> 13706 bytes client/images/spin/32x32/Preloader_9.gif | Bin 0 -> 13661 bytes client/images/spin/64x64/Preloader_1.gif | Bin 0 -> 35166 bytes client/images/spin/64x64/Preloader_10.gif | Bin 0 -> 10015 bytes client/images/spin/64x64/Preloader_2.gif | Bin 0 -> 4799 bytes client/images/spin/64x64/Preloader_3.gif | Bin 0 -> 12080 bytes client/images/spin/64x64/Preloader_4.gif | Bin 0 -> 10456 bytes client/images/spin/64x64/Preloader_5.gif | Bin 0 -> 41405 bytes client/images/spin/64x64/Preloader_6.gif | Bin 0 -> 9959 bytes client/images/spin/64x64/Preloader_7.gif | Bin 0 -> 6225 bytes client/images/spin/64x64/Preloader_8.gif | Bin 0 -> 25056 bytes client/images/spin/64x64/Preloader_9.gif | Bin 0 -> 23767 bytes client/index.html | 5 + client/js/controllers/home/machineDetails.js | 39 ++++++ client/js/controllers/home/main.js | 13 +- client/js/controllers/login.js | 9 +- client/js/controllers/status.js | 6 +- client/js/services/Compute.js | 25 +++- client/js/services/Identity.js | 79 ++++++++---- client/partials/home/machineDetails.html | 84 +++++++++++++ client/partials/home/main.html | 7 +- client/partials/nav.html | 2 +- server/Test/AppTestClass.php | 43 ++++++- server/Test/computeTest.php | 20 +++ server/core/App.php | 15 ++- server/core/Compute.php | 175 +++++++++++++++++++++++++++ server/core/LibOverride/genTokenOptions.php | 10 +- server/index.php | 16 ++- server/vendor/php-opencloud/openstack | 2 +- 47 files changed, 499 insertions(+), 51 deletions(-) create mode 100644 client/images/spin/128x128/Preloader_1.gif create mode 100644 client/images/spin/128x128/Preloader_10.gif create mode 100644 client/images/spin/128x128/Preloader_2.gif create mode 100644 client/images/spin/128x128/Preloader_3.gif create mode 100644 client/images/spin/128x128/Preloader_4.gif create mode 100644 client/images/spin/128x128/Preloader_5.gif create mode 100644 client/images/spin/128x128/Preloader_6.gif create mode 100644 client/images/spin/128x128/Preloader_7.gif create mode 100644 client/images/spin/128x128/Preloader_8.gif create mode 100644 client/images/spin/128x128/Preloader_9.gif create mode 100644 client/images/spin/32x32/Preloader_1.gif create mode 100644 client/images/spin/32x32/Preloader_10.gif create mode 100644 client/images/spin/32x32/Preloader_2.gif create mode 100644 client/images/spin/32x32/Preloader_3.gif create mode 100644 client/images/spin/32x32/Preloader_4.gif create mode 100644 client/images/spin/32x32/Preloader_5.gif create mode 100644 client/images/spin/32x32/Preloader_6.gif create mode 100644 client/images/spin/32x32/Preloader_7.gif create mode 100644 client/images/spin/32x32/Preloader_8.gif create mode 100644 client/images/spin/32x32/Preloader_9.gif create mode 100644 client/images/spin/64x64/Preloader_1.gif create mode 100644 client/images/spin/64x64/Preloader_10.gif create mode 100644 client/images/spin/64x64/Preloader_2.gif create mode 100644 client/images/spin/64x64/Preloader_3.gif create mode 100644 client/images/spin/64x64/Preloader_4.gif create mode 100644 client/images/spin/64x64/Preloader_5.gif create mode 100644 client/images/spin/64x64/Preloader_6.gif create mode 100644 client/images/spin/64x64/Preloader_7.gif create mode 100644 client/images/spin/64x64/Preloader_8.gif create mode 100644 client/images/spin/64x64/Preloader_9.gif create mode 100644 client/js/controllers/home/machineDetails.js create mode 100644 client/partials/home/machineDetails.html create mode 100644 server/Test/computeTest.php mode change 100644 => 100755 server/core/App.php mode change 100644 => 100755 server/core/LibOverride/genTokenOptions.php (limited to 'server/Test/AppTestClass.php') diff --git a/client/images/spin/128x128/Preloader_1.gif b/client/images/spin/128x128/Preloader_1.gif new file mode 100644 index 0000000..dafe17e Binary files /dev/null and b/client/images/spin/128x128/Preloader_1.gif differ diff --git a/client/images/spin/128x128/Preloader_10.gif b/client/images/spin/128x128/Preloader_10.gif new file mode 100644 index 0000000..cdfa680 Binary files /dev/null and b/client/images/spin/128x128/Preloader_10.gif differ diff --git a/client/images/spin/128x128/Preloader_2.gif b/client/images/spin/128x128/Preloader_2.gif new file mode 100644 index 0000000..3cb9003 Binary files /dev/null and b/client/images/spin/128x128/Preloader_2.gif differ diff --git a/client/images/spin/128x128/Preloader_3.gif b/client/images/spin/128x128/Preloader_3.gif new file mode 100644 index 0000000..7f7d415 Binary files /dev/null and b/client/images/spin/128x128/Preloader_3.gif differ diff --git a/client/images/spin/128x128/Preloader_4.gif b/client/images/spin/128x128/Preloader_4.gif new file mode 100644 index 0000000..78baff6 Binary files /dev/null and b/client/images/spin/128x128/Preloader_4.gif differ diff --git a/client/images/spin/128x128/Preloader_5.gif b/client/images/spin/128x128/Preloader_5.gif new file mode 100644 index 0000000..c9c1530 Binary files /dev/null and b/client/images/spin/128x128/Preloader_5.gif differ diff --git a/client/images/spin/128x128/Preloader_6.gif b/client/images/spin/128x128/Preloader_6.gif new file mode 100644 index 0000000..3203d7f Binary files /dev/null and b/client/images/spin/128x128/Preloader_6.gif differ diff --git a/client/images/spin/128x128/Preloader_7.gif b/client/images/spin/128x128/Preloader_7.gif new file mode 100644 index 0000000..2eb19be Binary files /dev/null and b/client/images/spin/128x128/Preloader_7.gif differ diff --git a/client/images/spin/128x128/Preloader_8.gif b/client/images/spin/128x128/Preloader_8.gif new file mode 100644 index 0000000..3ba8217 Binary files /dev/null and b/client/images/spin/128x128/Preloader_8.gif differ diff --git a/client/images/spin/128x128/Preloader_9.gif b/client/images/spin/128x128/Preloader_9.gif new file mode 100644 index 0000000..7018192 Binary files /dev/null and b/client/images/spin/128x128/Preloader_9.gif differ diff --git a/client/images/spin/32x32/Preloader_1.gif b/client/images/spin/32x32/Preloader_1.gif new file mode 100644 index 0000000..b810330 Binary files /dev/null and b/client/images/spin/32x32/Preloader_1.gif differ diff --git a/client/images/spin/32x32/Preloader_10.gif b/client/images/spin/32x32/Preloader_10.gif new file mode 100644 index 0000000..f9c462f Binary files /dev/null and b/client/images/spin/32x32/Preloader_10.gif differ diff --git a/client/images/spin/32x32/Preloader_2.gif b/client/images/spin/32x32/Preloader_2.gif new file mode 100644 index 0000000..f23998f Binary files /dev/null and b/client/images/spin/32x32/Preloader_2.gif differ diff --git a/client/images/spin/32x32/Preloader_3.gif b/client/images/spin/32x32/Preloader_3.gif new file mode 100644 index 0000000..bb7c60d Binary files /dev/null and b/client/images/spin/32x32/Preloader_3.gif differ diff --git a/client/images/spin/32x32/Preloader_4.gif b/client/images/spin/32x32/Preloader_4.gif new file mode 100644 index 0000000..117c756 Binary files /dev/null and b/client/images/spin/32x32/Preloader_4.gif differ diff --git a/client/images/spin/32x32/Preloader_5.gif b/client/images/spin/32x32/Preloader_5.gif new file mode 100644 index 0000000..7169708 Binary files /dev/null and b/client/images/spin/32x32/Preloader_5.gif differ diff --git a/client/images/spin/32x32/Preloader_6.gif b/client/images/spin/32x32/Preloader_6.gif new file mode 100644 index 0000000..9087ded Binary files /dev/null and b/client/images/spin/32x32/Preloader_6.gif differ diff --git a/client/images/spin/32x32/Preloader_7.gif b/client/images/spin/32x32/Preloader_7.gif new file mode 100644 index 0000000..0b1e633 Binary files /dev/null and b/client/images/spin/32x32/Preloader_7.gif differ diff --git a/client/images/spin/32x32/Preloader_8.gif b/client/images/spin/32x32/Preloader_8.gif new file mode 100644 index 0000000..6816be3 Binary files /dev/null and b/client/images/spin/32x32/Preloader_8.gif differ diff --git a/client/images/spin/32x32/Preloader_9.gif b/client/images/spin/32x32/Preloader_9.gif new file mode 100644 index 0000000..e38dd5a Binary files /dev/null and b/client/images/spin/32x32/Preloader_9.gif differ diff --git a/client/images/spin/64x64/Preloader_1.gif b/client/images/spin/64x64/Preloader_1.gif new file mode 100644 index 0000000..2004c5f Binary files /dev/null and b/client/images/spin/64x64/Preloader_1.gif differ diff --git a/client/images/spin/64x64/Preloader_10.gif b/client/images/spin/64x64/Preloader_10.gif new file mode 100644 index 0000000..944ec82 Binary files /dev/null and b/client/images/spin/64x64/Preloader_10.gif differ diff --git a/client/images/spin/64x64/Preloader_2.gif b/client/images/spin/64x64/Preloader_2.gif new file mode 100644 index 0000000..9821827 Binary files /dev/null and b/client/images/spin/64x64/Preloader_2.gif differ diff --git a/client/images/spin/64x64/Preloader_3.gif b/client/images/spin/64x64/Preloader_3.gif new file mode 100644 index 0000000..52b81ba Binary files /dev/null and b/client/images/spin/64x64/Preloader_3.gif differ diff --git a/client/images/spin/64x64/Preloader_4.gif b/client/images/spin/64x64/Preloader_4.gif new file mode 100644 index 0000000..3408b5d Binary files /dev/null and b/client/images/spin/64x64/Preloader_4.gif differ diff --git a/client/images/spin/64x64/Preloader_5.gif b/client/images/spin/64x64/Preloader_5.gif new file mode 100644 index 0000000..6f0585d Binary files /dev/null and b/client/images/spin/64x64/Preloader_5.gif differ diff --git a/client/images/spin/64x64/Preloader_6.gif b/client/images/spin/64x64/Preloader_6.gif new file mode 100644 index 0000000..c577f24 Binary files /dev/null and b/client/images/spin/64x64/Preloader_6.gif differ diff --git a/client/images/spin/64x64/Preloader_7.gif b/client/images/spin/64x64/Preloader_7.gif new file mode 100644 index 0000000..5f6dd5e Binary files /dev/null and b/client/images/spin/64x64/Preloader_7.gif differ diff --git a/client/images/spin/64x64/Preloader_8.gif b/client/images/spin/64x64/Preloader_8.gif new file mode 100644 index 0000000..b57e4d8 Binary files /dev/null and b/client/images/spin/64x64/Preloader_8.gif differ diff --git a/client/images/spin/64x64/Preloader_9.gif b/client/images/spin/64x64/Preloader_9.gif new file mode 100644 index 0000000..fc3ddb7 Binary files /dev/null and b/client/images/spin/64x64/Preloader_9.gif differ diff --git a/client/index.html b/client/index.html index ba183df..8d81ac3 100644 --- a/client/index.html +++ b/client/index.html @@ -26,6 +26,9 @@
+ +
+
@@ -81,7 +84,9 @@ + + diff --git a/client/js/controllers/home/machineDetails.js b/client/js/controllers/home/machineDetails.js new file mode 100644 index 0000000..f84a073 --- /dev/null +++ b/client/js/controllers/home/machineDetails.js @@ -0,0 +1,39 @@ +/** + * The home controller + * + * @param {$scope} $scope The $scope service from angular + */ +mainApp.controller('machineDetailsCtrl', [ '$scope', 'Compute', '$rootScope', '$timeout', function ($scope, Compute, $rootScope, $timeout) +{ + + $scope.machine={}; + $("#waitingForToggleMachine").hide(); + + $scope.$on('showMachineDetailsEvent', function(eventName ,machine){ + $scope.machine=machine; + $('#machineDetailsModal').modal({backdrop: false, keyboard: true}); + }); + + + $scope.toggleMachineState=function(){ + $("#waitingForToggleMachine").show(); + + // Fake timeout + $timeout(function(){ + $("#waitingForToggleMachine").hide(); + }, 3000); + $timeout(function(){ + $scope.machine.online=!$scope.machine.online; + + }, 3000); + + + }; + + $scope.applyModifications=function(){ + //Todo + } + + + +}]); diff --git a/client/js/controllers/home/main.js b/client/js/controllers/home/main.js index d25bfad..4e3bcda 100644 --- a/client/js/controllers/home/main.js +++ b/client/js/controllers/home/main.js @@ -3,15 +3,22 @@ * * @param {$scope} $scope The $scope service from angular */ -mainApp.controller('homeCtrl', [ '$scope', 'Compute', function ($scope, Compute) +mainApp.controller('homeCtrl', [ '$scope', 'Compute', '$rootScope', function ($scope, Compute, $rootScope) { - var updatePage=function(){ // TODO Update graph etc... } // Retrieve all Data Compute.pullData(updatePage); - + + Compute.getMachines(function(adzda){}); + + $scope.raiseShowMachineDetailsEvent=function(){ + var machine={name: "Machine 1", online:true}; + $rootScope.$broadcast("showMachineDetailsEvent", machine); + } + + }]); diff --git a/client/js/controllers/login.js b/client/js/controllers/login.js index 829fc1d..1a89563 100644 --- a/client/js/controllers/login.js +++ b/client/js/controllers/login.js @@ -13,14 +13,19 @@ mainApp.controller('loginCtrl', ['$scope','$sce','Identity', function ($scope,$s if(!Identity.isAlreadyLogin()){ $('#loginModal').modal({backdrop: 'static', keyboard: false}); } + + // Manager logout event $scope.$on('logoutEvent', function(){ + Identity.logout(); $('#loginModal').modal({backdrop: 'static', keyboard: false}); }); - + + // Hide loading button and message alert $('#loadingLoginButton').hide(); $('#failedToLoginAlert').hide(); - + + // Defined function for login $scope.loginAction=function(){ // Begin login state for template diff --git a/client/js/controllers/status.js b/client/js/controllers/status.js index e01df34..940d794 100644 --- a/client/js/controllers/status.js +++ b/client/js/controllers/status.js @@ -10,13 +10,11 @@ mainApp.controller('statusCtrl', ['$scope','Identity', '$rootScope', function ($ { // Give profile to model - $scope.profile=Identity.profile; + $scope.profile=Identity.getProfile(); // Function to logout - $scope.logout=function(){ - Identity.logout(); + $scope.raiseLogoutEvent=function(){ $rootScope.$broadcast('logoutEvent'); - }; }]); diff --git a/client/js/services/Compute.js b/client/js/services/Compute.js index c5c8da9..8148948 100644 --- a/client/js/services/Compute.js +++ b/client/js/services/Compute.js @@ -2,11 +2,12 @@ mainApp.factory('Compute',[ '$http', 'Identity', function($http, Identity){ - + // Create data var data={}; data.machines={}; + // Parser var parseGetMachinesAnswer=function(response, failedToSendRequest){ @@ -16,8 +17,24 @@ mainApp.factory('Compute',[ '$http', 'Identity', function($http, Identity){ // Get Machine var getMachines=function(callback){ + var params={ + "token" : Identity.getToken(), + "task" : "compute", + "action":"getServer", + "serverId":"69d5bcc4-2fab-4634-b0d2-f455fee5b7bd" + }; + var result=$http.post('../server/index.php', - $.param({"token" : Identity.profile.token, "task" : "Compute"})); + $.param(params)); + + // Wait and handle the response + result.then(function (response){ + console.log(response.data.Servers); + callback(parseGetMachinesAnswer(response, false)); + },function(response){ + alert(response.status); + callback(parseGetMachinesAnswer(response, true)); + }); }; @@ -31,8 +48,8 @@ mainApp.factory('Compute',[ '$http', 'Identity', function($http, Identity){ // Return services objects return { - getMachines: getMachines - pullData: pullData + getMachines: getMachines, + pullData: pullData, data:data }; diff --git a/client/js/services/Identity.js b/client/js/services/Identity.js index 8ee664c..b1d2a48 100644 --- a/client/js/services/Identity.js +++ b/client/js/services/Identity.js @@ -7,37 +7,47 @@ mainApp.factory('Identity',[ '$http', '$cookies', function($http, $cookies){ var profile={}; profile.username=null; profile.projectname=null; - profile.token=null; - - - /** - * Save profile in cookies - */ - var saveCookieForSession=function(){ - $cookies.putObject('profile', 5); - }; - + var token=null; + /* * @returns {boolean} Return true if a cookie is found (and load it in profile) false else */ var isAlreadyLogin=function(){ + + // Load cookies var profileInCookie=$cookies.getObject('profile'); - console.log(profileInCookie); + var tokenPart_0InCookie=$cookies.getObject('token.part_0'); + var tokenPart_1InCookie=$cookies.getObject('token.part_1'); + - if(typeof profileInCookie !== 'undefined'){ + // Check if cookie is defined + if(typeof profileInCookie !== 'undefined' + && typeof tokenPart_0InCookie !== 'undefined' + && typeof tokenPart_1InCookie !== 'undefined' + ){ + + // If yes, put it into variables angular.extend(profile, profileInCookie); + token=tokenPart_0InCookie+tokenPart_1InCookie; + + // Return I'm Login return true; } + // Return I'm not Login return false; } + + /* * Destroy profile cookies */ var logout=function(){ $cookies.remove('profile'); + $cookies.remove('token.part_0'); + $cookies.remove('token.part_1'); } @@ -49,15 +59,28 @@ mainApp.factory('Identity',[ '$http', '$cookies', function($http, $cookies){ */ var parseLoginAnswer=function(response, failedToSendRequest){ - + // Defined return object var requestParserResult={}; requestParserResult.status=1; requestParserResult.failReason=null; if (typeof response.data.token !== 'undefined') { + // Set status code requestParserResult.status=0; - profile.token=response.data.token; - saveCookieForSession(); + + // Find the middle of the token to split it + var middle=parseInt(response.data.token.length/2); + + // Create expire date (cookie expire in 55 mins) + var expireDate=new Date(); + expireDate.setMinutes(expireDate.getMinutes()+55); + + // Save profile + $cookies.putObject('profile', profile, {'expires': expireDate}); + // Save first part of token + $cookies.putObject('token.part_0', response.data.token.substring(0, middle), {'expires': expireDate}); + // Save second part of token + $cookies.putObject('token.part_1', response.data.token.substring(middle, response.data.token.length), {'expires': expireDate}); } else if(failedToSendRequest){ requestParserResult.failReason="Failed to send request"; @@ -69,7 +92,6 @@ mainApp.factory('Identity',[ '$http', '$cookies', function($http, $cookies){ return requestParserResult; }; - /** * Function to connect to OpenStack @@ -87,24 +109,39 @@ mainApp.factory('Identity',[ '$http', '$cookies', function($http, $cookies){ profile.projectname=projectname; var result=$http.post('../server/index.php', - $.param({"task" : "Authenticate", "user" : username, "password" : password, "project" : projectname})); + $.param({"task" : "Authenticate", "user" : username, "password" : password, "project" : projectname})); // Wait and handle the response result.then(function (response){ - callback(parseLoginAnswer(response), false); + callback(parseLoginAnswer(response, false)); },function(response){ - callback(parseLoginAnswer(response), true) + callback(parseLoginAnswer(response, true)); }); }; + /* + * Get the profile + */ + var getProfile=function(){ + return profile; + } + + /* + * Get the token + */ + var getToken=function(){ + return token; + } + // Return services objects return { login: login, - profile: profile, + getProfile: getProfile, isAlreadyLogin: isAlreadyLogin, - logout:logout + logout:logout, + getToken:getToken }; diff --git a/client/partials/home/machineDetails.html b/client/partials/home/machineDetails.html new file mode 100644 index 0000000..606edcf --- /dev/null +++ b/client/partials/home/machineDetails.html @@ -0,0 +1,84 @@ + diff --git a/client/partials/home/main.html b/client/partials/home/main.html index 7a5045a..37638d3 100644 --- a/client/partials/home/main.html +++ b/client/partials/home/main.html @@ -1,8 +1,11 @@ -
+
Home
Main Content + +
+
-
\ No newline at end of file +
diff --git a/client/partials/nav.html b/client/partials/nav.html index 3c72844..b3ef76a 100644 --- a/client/partials/nav.html +++ b/client/partials/nav.html @@ -32,7 +32,7 @@
  • Informations
  • Settings
  • -
  • Logout
  • +
  • Logout
  • diff --git a/server/Test/AppTestClass.php b/server/Test/AppTestClass.php index 40a5847..3ff0aea 100755 --- a/server/Test/AppTestClass.php +++ b/server/Test/AppTestClass.php @@ -12,6 +12,7 @@ class AppTest{ protected $openstack; protected $pluginsApi; + protected $postParams; protected $tokenClass; protected $tokenPost; protected $output; @@ -23,8 +24,13 @@ class AppTest{ $this->tokenClass = new genTokenOptions($args); $this->openstack = new OpenStack\OpenStack([]); $this->pluginsApi = plugin_api::getInstance(); + $this->errorClass = new errorManagement($this); $this->output = array(); +<<<<<<< HEAD $this->errorClass = new errorManagement($this); +======= + $this->postParams = $_POST; +>>>>>>> develop } @@ -48,6 +54,16 @@ class AppTest{ $opt = $this->tokenClass->getOptions($service); return $this->openstack->imagesV2($opt); break; + case "Compute": + if($this->tokenPost == NULL) $this->tokenClass->genComputeToken(); + $opt = $this->tokenClass->getOptions($service); + return $this->openstack->computeV2($opt); + break; + case "Network": + if($this->tokenPost == NULL) $this->tokenClass->genNetworkToken(); + $opt = $this->tokenClass->getOptions($service); + return $this->openstack->networkingV2($opt); + break; } } @@ -61,10 +77,21 @@ class AppTest{ $this->tokenClass->genNetworkToken(); $this->setOutput("token", $this->tokenClass->getBackup()); - }catch(Exception $e){ - echo $e; - exit(); - } + }catch(BadResponseError $e){ + $this->errorClass->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->errorClass->UserInputHandler($e); + }catch(BaseError $e){ + $this->errorClass->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->errorClass->NotImplementedHandler($e); + } + + } + + public function getPostParam($name){ + + return $this->postParams[$name]; } @@ -75,12 +102,16 @@ class AppTest{ } public function show(){ - echo json_encode($this->output); + return json_encode($this->output); } +<<<<<<< HEAD public function getErrorInstance(){ return $this->errorClass; } -} \ No newline at end of file +} +======= +} +>>>>>>> develop diff --git a/server/Test/computeTest.php b/server/Test/computeTest.php new file mode 100644 index 0000000..3ce1f2e --- /dev/null +++ b/server/Test/computeTest.php @@ -0,0 +1,20 @@ +re '../vendor/autoload.php'; +include('/istic-openstack/server/init.php'); +include_once("../core/Compute.php"); +$compute = new compute($App); + +$servers = $compute->listServers(); + +$servers= $compute->listServers(true); +foreach($servers as $server){ + //print_r($server); + echo $server->name." ".$server->id."
    "; + +//$opt = Array(); +//$opt['name'] = "Test"; +//$serverid = Array("id"=>"69d5bcc4-2fab-4634-b0d2-f455fee5b7bd"); +//$serverid["id"] = "{69d5bcc4-2fab-4634-b0d2-f455fee5b7bd}"; +//unset($server); +//$server = $compute->getServer($serverid); +//echo $server->name." ".$server->image; +//$server->update(array('name' => 'test')); diff --git a/server/core/App.php b/server/core/App.php old mode 100644 new mode 100755 index babb3d9..edb75f6 --- a/server/core/App.php +++ b/server/core/App.php @@ -33,7 +33,7 @@ class App{ public function setToken($token){ $this->tokenPost = $token; - $this->tokenClass->loadBackup($his->tokenPost); + $this->tokenClass->loadBackup($this->tokenPost); } @@ -50,6 +50,16 @@ class App{ $opt = $this->tokenClass->getOptions($service); return $this->openstack->imagesV2($opt); break; + case "Network": + if($this->tokenPost == NULL) $this->tokenClass->genNetworkToken(); + $opt = $this->tokenClass->getOptions($service); + return $this->openstack->networkingV2($opt); + break; + case "Compute": + if($this->tokenPost == NULL) $this->tokenClass->genComputeToken(); + $opt = $this->tokenClass->getOptions($service); + return $this->openstack->computeV2($opt); + break; } } @@ -95,6 +105,7 @@ class App{ public function show(){ echo json_encode($this->output); + //error_log(var_dump(json_encode($this->output), true), 0); } -} \ No newline at end of file +} diff --git a/server/core/Compute.php b/server/core/Compute.php index 8d1c8b6..94e219c 100644 --- a/server/core/Compute.php +++ b/server/core/Compute.php @@ -1 +1,176 @@ +app = $app; + $this->libClass = $app->getLibClass("Compute"); + } + /** + * Execute an action + * + * @param String $action name of another function of this class + * + * @return void + */ + public function action($action){ + + $this->{$action.""}(); + + } + /** + * List servers. + * @return array + */ + public function listServers() + { + $servers = $this->libClass->listServers(); + $this->app->setOutput("Servers", $servers); + return; + } + /** + * List flavors. + * @return array + */ + public function listFlavors() + { + $flavors = $this->libClass->listFlavors(); + $this->app->setOutput("Flavors", $flavors); + return; + } + /** + * List images. + * @return array + */ + public function listImages() + { + $images = $this->libClass->listImages(); + $this->app->setOutput("Images", $images); + return; + } + /** + * Create server. + * @return array + * + public function createServer() + { + + $server = $this->libClass->createServer(); + } + */ + /** + * Get server details. + * @return array + */ + public function getServer() + { + $serverId = $this->app->getPostParam("serverId"); + $opt = array('id' => $serverId); + $server = $this->libClass->getServer($opt); + $server->retrieve(); + $this->app->setOutput("MyServer", $server); + return; + } + /** + * Get flavor details. + * @return array + */ + public function getFlavor() + { + $flavorId = $this->app->getPostParam("flavorId"); + $opt = array('id' => $flavorId); + $flavor = $this->libClass->getFlavor($opt); + $flavor->retrieve(); + $this->app->setOutput("MyFlavor", $flavor); + return; + } + /** + * Get image details. + * @return array + */ + public function getImage() + { + $imageId = $this->app->getPostParam("imageId"); + $opt = array('id' => $imageId); + $image = $this->libClass->getImage($opt); + $image->retrieve(); + $this->app->setOutput("MyImage", $image); + return; + } + /* working on tests + + public function update() + { + $image = $this->app->getServer(array $options = []); + + } + public function delete() + { + //TODO + } + public function changePassword($newPassword) + { + //TODO + } + public function reboot($type = Enum::REBOOT_SOFT) + { + //TODO + } + public function rebuild(array $options) + { + //TODO + } + public function resize($flavorId) + { + //TODO + } + public function confirmResize() + { + //TODO + } + public function revertResize() + { + //TODO + } + public function createImage(array $options) + { + //TODO + } + public function listAddresses(array $options = []) + { + //TODO + } + public function getMetadata() + { + //TODO + } + public function resetMetadata(array $metadata) + { + //TODO + } + public function mergeMetadata(array $metadata) + { + //TODO + } + public function getMetadataItem($key) + { + //TODO + } + public function deleteMetadataItem($key) + { + //TODO + } +*/ +} diff --git a/server/core/LibOverride/genTokenOptions.php b/server/core/LibOverride/genTokenOptions.php old mode 100644 new mode 100755 index b71defa..50826ed --- a/server/core/LibOverride/genTokenOptions.php +++ b/server/core/LibOverride/genTokenOptions.php @@ -260,13 +260,14 @@ class genTokenOptions public function loadBackup($back){ $backup = unserialize($back); + $this->backup["roles"] = $backup["roles"]; $this->backup["project"] = $backup["project"]; $this->backup["user"] = $backup["user"]; - loadComputeBackup($backup["Compute"]); - loadIdentityBackup($backup["Identity"]); - loadImageBackup($backup["Image"]); - loadNetworkBackup($backup["Network"]); + $this->loadComputeBackup($backup["Compute"]); + $this->loadIdentityBackup($backup["Identity"]); + $this->loadImageBackup($backup["Image"]); + $this->loadNetworkBackup($backup["Network"]); } @@ -324,6 +325,7 @@ class genTokenOptions private function unserializeToken($tokenSerialized){ $Saved = file_get_contents("core/LibOverride/projectTokenData/".$this->backup["project"]); + $Saved = unserialize($Saved); $api = new Api(); $token = new Models\Token($this->httpClient, $api); $token->methods = unserialize($tokenSerialized["methods"]); diff --git a/server/index.php b/server/index.php index 166e82e..f888671 100644 --- a/server/index.php +++ b/server/index.php @@ -27,12 +27,26 @@ $identityObject->action($action); $App->show(); break; - + + case "network": + include_once("core/Network.php"); + $networkObject = new network($App); + $networkObject->action($action); + $App->show(); + break; + case "image": include_once("core/Image.php"); $imageObject = new image($App); $imageObject->action($action); $App->show(); break; + + case "compute": + include_once("core/Compute.php"); + $computeObject = new compute($App); + $computeObject->action($action); + $App->show(); + break; } diff --git a/server/vendor/php-opencloud/openstack b/server/vendor/php-opencloud/openstack index 1419eb2..15aca73 160000 --- a/server/vendor/php-opencloud/openstack +++ b/server/vendor/php-opencloud/openstack @@ -1 +1 @@ -Subproject commit 1419eb2e01164bb6b8b837df37724423907352d7 +Subproject commit 15aca73f423166c7ef8337ba08615c103c66e931 -- cgit v1.2.3 From ae1100c16880d4bae77513ec433ac6734da8dea4 Mon Sep 17 00:00:00 2001 From: Yoggzo Date: Mon, 29 Feb 2016 15:25:30 +0100 Subject: Error management --- server/Test/AppTestClass.php | 20 +++------- server/Test/imageTests.php | 4 +- server/core/Image.php | 92 ++++++++++++++++++++------------------------ 3 files changed, 48 insertions(+), 68 deletions(-) (limited to 'server/Test/AppTestClass.php') diff --git a/server/Test/AppTestClass.php b/server/Test/AppTestClass.php index 4d1f824..57dd422 100755 --- a/server/Test/AppTestClass.php +++ b/server/Test/AppTestClass.php @@ -26,15 +26,10 @@ class AppTest{ $this->pluginsApi = plugin_api::getInstance(); $this->errorClass = new errorManagement($this); $this->output = array(); -<<<<<<< HEAD -<<<<<<< HEAD + $this->errorClass = new errorManagement($this); -======= - $this->postParams = $_POST; ->>>>>>> develop -======= + $this->postParams = $_POST; ->>>>>>> develop } @@ -109,17 +104,12 @@ class AppTest{ return json_encode($this->output); } -<<<<<<< HEAD -<<<<<<< HEAD + public function getErrorInstance(){ return $this->errorClass; } -} -======= } ->>>>>>> develop -======= -} ->>>>>>> develop + + diff --git a/server/Test/imageTests.php b/server/Test/imageTests.php index 47a69e2..d21eefb 100644 --- a/server/Test/imageTests.php +++ b/server/Test/imageTests.php @@ -17,7 +17,7 @@ $opt['minRam'] = 10; //$new_image = $image->createImage($opt); //Liste des images -$images = $image->listImage(); +$images = $image->action("listImage"); if(isset($images)){ echo "Images présentes :"; @@ -49,7 +49,7 @@ else{ // Détails Image //$details = $image->imageDetails($id_image); -$image->deleteImage('123456'); +//$image->deleteImage('123456'); //$image->desactivateImage($id_image); //$image->reactivateImage($id_image); diff --git a/server/core/Image.php b/server/core/Image.php index 4d22443..4025595 100644 --- a/server/core/Image.php +++ b/server/core/Image.php @@ -39,7 +39,7 @@ class image implements Core{ */ public function __construct($app){ if(!isset($app)){ - // Renvoyer erreur + $this->app->setOutput("Error", "Incorrect parameter"); } try{ $this->app = $app; @@ -79,7 +79,7 @@ class image implements Core{ private function createImage(array $opt){ if(!isset($opt)){ - // Renvoyer erreur + $this->app->setOutput("Error", "Incorrect parameter"); } @@ -98,7 +98,7 @@ class image implements Core{ } else{ - //ERROR + $this->app->setOutput("Error", "Image name already exists"); } if(isset($opt['id'])){ // UUID : nnnnnnnn-nnnn-nnnn-nnnn-nnnnnnnnnnnn if($this->libClass->getImage($opt['id']) != null){ // if the id already exists -> error @@ -153,7 +153,7 @@ class image implements Core{ try{ $l = $this->libClass->listImages(); if(!isset($l)){ // if the list is empty there is no images - + $this->app->setOutput("Error", "No image"); } }catch(BadResponseError $e){ $this->app->getErrorInstance()->BadResponseHandler($e); @@ -183,7 +183,7 @@ class image implements Core{ $service = $this->libClass; $image = $service->getImage($id); if($image == null){ // if the image don't exists -> error - // Renvoyer erreur + $this->app->setOutput("Error", "Image doesn't exist"); } return $image; @@ -209,10 +209,10 @@ class image implements Core{ **/ private function updateImage($id, array $opt){ if(!isset($id)){ - // Renvoyer erreur + $this->app->setOutput("Error", "Incorrect id parameter"); } if(!isset($opt)){ - // Renvoyer erreur + $this->app->setOutput("Error", "Incorrect opt parameter"); } try{ @@ -220,7 +220,7 @@ class image implements Core{ $service = $this->libClass; $image = $service->getImage($id); if($image == null){ // if the image don't exists -> error - // Renvoyer erreur + $this->app->setOutput("Error", "Image doesn't exist"); } $options = Array(); @@ -267,14 +267,14 @@ class image implements Core{ // si protected = true, demander de le mettre a false // vérifier existence image if(!isset($id)){ - // Renvoyer erreur + $this->app->setOutput("Error", "Image doesn't exist"); } try{ $service = $this->libClass; $image = $this->libClass->getImage($id); if($image == null){ // if the image don't exists -> error - // Renvoyer erreur + $this->app->setOutput("Error", "Image doesn't exist"); } $image->delete(); }catch(BadResponseError $e){ @@ -297,14 +297,14 @@ class image implements Core{ **/ private function reactivateImage($id){ if(!isset($id)){ - // Renvoyer erreur + $this->app->setOutput("Error", "Incorrect parameter"); } try{ // vérifier existence image $service = $this->libClass; $image = $service->getImage($id); if($image == null){ // if the image don't exists -> error - // Renvoyer erreur + $this->app->setOutput("Error", "Image doesn't exist"); } $image->reactivate(); }catch(BadResponseError $e){ @@ -326,14 +326,14 @@ class image implements Core{ **/ private function desactivateImage($id){ if(!isset($id)){ - // Renvoyer erreur + $this->app->setOutput("Error", "Incorrect parameter"); } try{ // vérifier existence image $service = $this->libClass; $image = $service->getImage($id); if($image == null){ // if the image don't exists -> error - // Renvoyer erreur + $this->app->setOutput("Error", "Image doesn't exist"); } $image->deactivate(); }catch(BadResponseError $e){ @@ -358,19 +358,19 @@ class image implements Core{ **/ private function uploadImage($id, $file_name){ if(!isset($id)){ - // Renvoyer erreur + $this->app->setOutput("Error", "Incorrect id parameter"); } if(!isset($file_name)){ - // Renvoyer erreur + $this->app->setOutput("Error", "Incorrect file_name parameter"); } try{ // vérifier existence image $service = $this->libClass; $image = $service->getImage($id); if($image == null){ // if the image don't exists -> error - // Renvoyer erreur + $this->app->setOutput("Error", "Image doesn't exist"); } - $stream = \GuzzleHttp\Psr7\stream_for(fopen($file_name, 'r')); // A VOIR + $stream = \GuzzleHttp\Psr7\stream_for(fopen($file_name, 'r')); $image->uploadData($stream); }catch(BadResponseError $e){ $this->app->getErrorInstance()->BadResponseHandler($e); @@ -391,14 +391,14 @@ class image implements Core{ **/ private function downloadImage($id){ if(!isset($id)){ - // Renvoyer erreur + $this->app->setOutput("Error", "Incorrect parameter"); } try{ // vérifier existence image $service = $this->libClass; $image = $service->getImage($id); if($image == null){ // if the image don't exists -> error - // Renvoyer erreur + $this->app->setOutput("Error", "Image doesn't exist"); } $stream = $image->downloadData(); }catch(BadResponseError $e){ @@ -424,22 +424,18 @@ class image implements Core{ **/ private function addMemberImage($image_id, $member_id){ if(!isset($image_id)){ - // Renvoyer erreur + $this->app->setOutput("Error", "Incorrect parameter image_id"); } if(!isset($member_id)){ - // Renvoyer erreur + $this->app->setOutput("Error", "Incorrect parameter member_id"); } try{ - // vérifier existence image - // on doit être le proprio de l'image - // vérifier membre existe $service = $this->libClass; $image = $service->getImage($id); if($image == null){ // if the image don't exists -> error - // Renvoyer erreur + $this->app->setOutput("Error", "Image doesn't exist"); } - $member_id = $image->addMember($member_id); }catch(BadResponseError $e){ $this->app->getErrorInstance()->BadResponseHandler($e); @@ -461,21 +457,21 @@ class image implements Core{ **/ private function listMemberImage($image_id, $member_id){ if(!isset($image_id)){ - // Renvoyer erreur + $this->app->setOutput("Error", "Incorrect parameter image_id"); } if(!isset($member_id)){ - // Renvoyer erreur + $this->app->setOutput("Error", "Incorrect parameter member_id"); } try{ // vérifier existence image $service = $this->libClass; $image = $service->getImage($image_id); if($image == null){ // if the image don't exists -> error - // Renvoyer erreur + $this->app->setOutput("Error", "Image doesn't exist"); } $members = $image->listMembers(); if($member == null){ // if the image don't exists -> error - // Renvoyer erreur + $this->app->setOutput("Error", "No member"); } }catch(BadResponseError $e){ $this->app->getErrorInstance()->BadResponseHandler($e); @@ -500,10 +496,10 @@ class image implements Core{ **/ private function detailMemberImage($image_id, $member_id){ if(!isset($image_id)){ - // Renvoyer erreur + $this->app->setOutput("Error", "Incorrect parameter image_id"); } if(!isset($member_id)){ - // Renvoyer erreur + $this->app->setOutput("Error", "Incorrect parameter member_id"); } try{ // vérifier existence image @@ -513,12 +509,12 @@ class image implements Core{ $image = $service->getImage($id); if($image == null){ // if the image don't exists -> error - // Renvoyer erreur + $this->app->setOutput("Error", "Image doesn't exist"); } $member = $image->getMember($member_id); - if($member == null){ // if the image don't exists -> error - // Renvoyer erreur + if($member == null){ // if the member don't exists -> error + $this->app->setOutput("Error", "Member doesn't exist"); } }catch(BadResponseError $e){ $this->app->getErrorInstance()->BadResponseHandler($e); @@ -543,24 +539,21 @@ class image implements Core{ **/ private function removeMemberImage($image_id, $member_id){ if(!isset($image_id)){ - // Renvoyer erreur + $this->app->setOutput("Error", "Incorrect parameter image_id"); } if(!isset($member_id)){ - // Renvoyer erreur + $this->app->setOutput("Error", "Incorrect parameter member_id"); } try{ - // vérifier existence image - // on doit être le proprio de l'image - // vérifier membre existe $service = $this->libClass; $image = $service->getImage($id); if($image == null){ // if the image don't exists -> error - // Renvoyer erreur + $this->app->setOutput("Error", "Image doesn't exist"); } $member = $image->getMember($member_id); if($member == null){ // if the image don't exists -> error - // Renvoyer erreur + $this->app->setOutput("Error", "Member doesn't exist"); } $member->delete(); }catch(BadResponseError $e){ @@ -588,24 +581,21 @@ class image implements Core{ **/ private function updateMemberImage($image_id, $member_id, $status){ if(!isset($image_id)){ - // Renvoyer erreur + $this->app->setOutput("Error", "Incorrect parameter image_id"); } if(!isset($member_id)){ - // Renvoyer erreur + $this->app->setOutput("Error", "Incorrect parameter member_id"); } try{ - // vérifier existence image - // on doit être le proprio de l'image - // vérifier membre existe $service = $this->libClass; $image = $service->getImage($id); if($image == null){ // if the image don't exists -> error - // Renvoyer erreur + $this->app->setOutput("Error", "Image doesn't exist"); } $member = $image->getMember($member_id); - if($member == null){ // if the image don't exists -> error - // Renvoyer erreur + if($member == null){ // if the member don't exists -> error + $this->app->setOutput("Error", "Member doesn't exist"); } $member->updateStatus($status); }catch(BadResponseError $e){ -- cgit v1.2.3 From b7ebe1272c1127df290535af2430622b28160bb0 Mon Sep 17 00:00:00 2001 From: EoleDev Date: Wed, 9 Mar 2016 16:16:22 +0100 Subject: Library maj --- server/Test/AppTestClass.php | 9 +++++++++ server/composer.lock | 38 +++++++++++++++++++------------------- 2 files changed, 28 insertions(+), 19 deletions(-) (limited to 'server/Test/AppTestClass.php') diff --git a/server/Test/AppTestClass.php b/server/Test/AppTestClass.php index 4d7cab5..6685ec7 100755 --- a/server/Test/AppTestClass.php +++ b/server/Test/AppTestClass.php @@ -1,6 +1,15 @@ >>>>>> Stashed changes class AppTest{ diff --git a/server/composer.lock b/server/composer.lock index c6598db..198bbed 100644 --- a/server/composer.lock +++ b/server/composer.lock @@ -71,16 +71,16 @@ }, { "name": "guzzlehttp/promises", - "version": "1.0.3", + "version": "1.1.0", "source": { "type": "git", "url": "https://github.com/guzzle/promises.git", - "reference": "b1e1c0d55f8083c71eda2c28c12a228d708294ea" + "reference": "bb9024c526b22f3fe6ae55a561fd70653d470aa8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/promises/zipball/b1e1c0d55f8083c71eda2c28c12a228d708294ea", - "reference": "b1e1c0d55f8083c71eda2c28c12a228d708294ea", + "url": "https://api.github.com/repos/guzzle/promises/zipball/bb9024c526b22f3fe6ae55a561fd70653d470aa8", + "reference": "bb9024c526b22f3fe6ae55a561fd70653d470aa8", "shasum": "" }, "require": { @@ -118,20 +118,20 @@ "keywords": [ "promise" ], - "time": "2015-10-15 22:28:00" + "time": "2016-03-08 01:15:46" }, { "name": "guzzlehttp/psr7", - "version": "1.2.2", + "version": "1.2.3", "source": { "type": "git", "url": "https://github.com/guzzle/psr7.git", - "reference": "f5d04bdd2881ac89abde1fb78cc234bce24327bb" + "reference": "2e89629ff057ebb49492ba08e6995d3a6a80021b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/psr7/zipball/f5d04bdd2881ac89abde1fb78cc234bce24327bb", - "reference": "f5d04bdd2881ac89abde1fb78cc234bce24327bb", + "url": "https://api.github.com/repos/guzzle/psr7/zipball/2e89629ff057ebb49492ba08e6995d3a6a80021b", + "reference": "2e89629ff057ebb49492ba08e6995d3a6a80021b", "shasum": "" }, "require": { @@ -176,7 +176,7 @@ "stream", "uri" ], - "time": "2016-01-23 01:23:02" + "time": "2016-02-18 21:54:00" }, { "name": "justinrainbow/json-schema", @@ -250,23 +250,25 @@ "source": { "type": "git", "url": "https://github.com/php-opencloud/openstack.git", - "reference": "15aca73f423166c7ef8337ba08615c103c66e931" + "reference": "f2ee77024843659d970817a9e7055bb40a3724f9" }, "dist": { "type": "zip", +<<<<<<< Updated upstream "url": "https://api.github.com/repos/php-opencloud/openstack/zipball/15aca73f423166c7ef8337ba08615c103c66e931", "reference": "15aca73f423166c7ef8337ba08615c103c66e931", +======= + "url": "https://api.github.com/repos/php-opencloud/openstack/zipball/f2ee77024843659d970817a9e7055bb40a3724f9", + "reference": "f2ee77024843659d970817a9e7055bb40a3724f9", +>>>>>>> Stashed changes "shasum": "" }, "require": { - "guzzlehttp/guzzle": "~6.1", - "justinrainbow/json-schema": "~1.3", - "php": ">=5.6" + "php-opencloud/common": "dev-master" }, "require-dev": { "fabpot/php-cs-fixer": "~1.0", "jakub-onderka/php-parallel-lint": "0.*", - "phpspec/prophecy-phpunit": "~1.0", "phpunit/phpunit": "~4.0", "psr/log": "~1.0", "sami/sami": "dev-master", @@ -275,9 +277,7 @@ "type": "library", "autoload": { "psr-4": { - "OpenStack\\": "src/", - "OpenStack\\Test\\": "tests/unit/", - "OpenStack\\Integration\\": "tests/integration/" + "OpenStack\\": "src/" } }, "notification-url": "https://packagist.org/downloads/", @@ -288,7 +288,7 @@ "homepage": "https://github.com/jamiehannaford" } ], - "time": "2016-01-25 10:35:10" + "time": "2016-03-08 14:37:14" }, { "name": "psr/http-message", -- cgit v1.2.3 From e01936a73e75350a40fafd80995b1525a11c9da1 Mon Sep 17 00:00:00 2001 From: Yoggzo Date: Thu, 17 Mar 2016 09:46:32 +0100 Subject: add commentaries, update error management and correct some mistakes in Image.php, resolve conflict in AppTestClass.php --- server/Test/AppTestClass.php | 12 -- server/core/Image.php | 279 +++++++++++++++++++++---------------------- 2 files changed, 133 insertions(+), 158 deletions(-) (limited to 'server/Test/AppTestClass.php') diff --git a/server/Test/AppTestClass.php b/server/Test/AppTestClass.php index b398088..5e8efc7 100755 --- a/server/Test/AppTestClass.php +++ b/server/Test/AppTestClass.php @@ -1,24 +1,12 @@ >>>>>> Stashed changes -======= -include_once("../core/ErrorManagement.php"); - -use OpenStack\Common\Error\BadResponseError; -use OpenStack\Common\Error\BaseError; -use OpenStack\Common\Error\NotImplementedError; -use OpenStack\Common\Error\UserInputError; ->>>>>>> develop class AppTest{ diff --git a/server/core/Image.php b/server/core/Image.php index d37c828..f309943 100755 --- a/server/core/Image.php +++ b/server/core/Image.php @@ -9,15 +9,13 @@ * * @todo Complete the functions with errors detection and finish the descriptions */ -use OpenStack\Common\Error\BadResponseError; -use OpenStack\Common\Error\BaseError; -use OpenStack\Common\Error\NotImplementedError; -use OpenStack\Common\Error\UserInputError; - +use OpenCloud\Common\Error\BadResponseError; +use OpenCloud\Common\Error\BaseError; +use OpenCloud\Common\Error\NotImplementedError; +use OpenCloud\Common\Error\UserInputError; include("CoreInterface.php"); - /** * Image Class of the back-end application * @@ -37,13 +35,11 @@ class image implements Core{ * * @param App $app the main app object * - * @throws [Type] [] - * * @return Image */ public function __construct($app){ if(!isset($app)){ - $this->app->setOutput("Error", "Incorrect parameter"); + $this->app->setOutput("Error", "Incorrect parameter app"); } $this->app = $app; $this->libClass = $app->getLibClass("Image"); @@ -58,47 +54,46 @@ class image implements Core{ * @return void */ public function action($action){ - - $this->{$action.""}(); - + $this->{$action.""}(); } /** - * Details about an image + * Create a new image * - * @param array $opt - * options for the image creation + * @param array $opt Options for the image creation (name is required, others are optionals) * - **/ + * @return Image + */ private function createImage(){ $opt = $this->app->getPostParam("opt"); - if(!isset($opt)){ - $this->app->setOutput("Error", "Incorrect parameter"); + $this->app->setOutput("Error", "Incorrect parameter opt"); } - try{ - // VOIR SI MAUVAIS TYPE $options = Array(); - if(isset($opt['name'])){ // if the image name already exists -> error + + // Check the image name + if(isset($opt['name'])){ $imagesList = listImage(); - if(isset($images)){ + if(isset($imagesList)){ foreach($imagesList as $image){ - if(strcmp($image->name, $opt['name']) == 0){ - + if(strcmp($image->name, $opt['name']) == 0){ // if the image name already exists -> error + $this->app->setOutput("Error", "Image name already exists"); } } } } else{ - $this->app->setOutput("Error", "Image name already exists"); + $this->app->setOutput("Error", "Missing parameter 'name' for the new image"); } + + // Check optionals arguments if(isset($opt['id'])){ // UUID : nnnnnnnn-nnnn-nnnn-nnnn-nnnnnnnnnnnn if($this->libClass->getImage($opt['id']) != null){ // if the id already exists -> error - + $this->app->setOutput("Error", "Image id already exists"); } $options['id'] = $opt['id']; } @@ -131,11 +126,11 @@ class image implements Core{ }catch(BadResponseError $e){ $this->app->getErrorInstance()->BadResponseHandler($e); }catch(UserInputError $e){ - $this->app->getErrorInstance->UserInputHandler($e); + $this->app->getErrorInstance()->UserInputHandler($e); }catch(BaseError $e){ - $this->app->getErrorInstance->BaseErrorHandler($e); + $this->app->getErrorInstance()->BaseErrorHandler($e); }catch(NotImplementedError $e){ - $this->app->getErrorInstance->NotImplementedHandler($e); + $this->app->getErrorInstance()->NotImplementedHandler($e); } $this->app->setOutput("Images", $image); @@ -144,7 +139,7 @@ class image implements Core{ /** * List the images of the server * - * @return the list with all images on the server + * @return List of Image */ private function listImage(){ try{ @@ -156,11 +151,11 @@ class image implements Core{ }catch(BadResponseError $e){ $this->app->getErrorInstance()->BadResponseHandler($e); }catch(UserInputError $e){ - $this->app->getErrorInstance->UserInputHandler($e); + $this->app->getErrorInstance()->UserInputHandler($e); }catch(BaseError $e){ - $this->app->getErrorInstance->BaseErrorHandler($e); + $this->app->getErrorInstance()->BaseErrorHandler($e); }catch(NotImplementedError $e){ - $this->app->getErrorInstance->NotImplementedHandler($e); + $this->app->getErrorInstance()->NotImplementedHandler($e); } $this->app->setOutput("Images", $result); @@ -170,10 +165,10 @@ class image implements Core{ /** * Details about an image * - * @param string $id - * identifier of the image - * - **/ + * @param String $id Identifier of the image + * + * @return Image + */ private function detailsImage(){ $id = $this->app->getPostParam("id"); if(!isset($id)){ @@ -186,29 +181,26 @@ class image implements Core{ if($image == null){ // if the image don't exists -> error $this->app->setOutput("Error", "Image doesn't exist"); } - $this->app->setOutput("Images", $image); - }catch(BadResponseError $e){ $this->app->getErrorInstance()->BadResponseHandler($e); }catch(UserInputError $e){ - $this->app->getErrorInstance->UserInputHandler($e); + $this->app->getErrorInstance()->UserInputHandler($e); }catch(BaseError $e){ - $this->app->getErrorInstance->BaseErrorHandler($e); + $this->app->getErrorInstance()->BaseErrorHandler($e); }catch(NotImplementedError $e){ - $this->app->getErrorInstance->NotImplementedHandler($e); + $this->app->getErrorInstance()->NotImplementedHandler($e); } } /** - * Details about an image + * Update informations about an image * - * @param string $id - * id of the image - * - * @param array $opt - * options for the image creation - **/ + * @param String $id id of the image + * @param array $opt Options for the image creation + * + * @return Image + */ private function updateImage(){ $id = $this->app->getPostParam("id"); @@ -254,11 +246,11 @@ class image implements Core{ }catch(BadResponseError $e){ $this->app->getErrorInstance()->BadResponseHandler($e); }catch(UserInputError $e){ - $this->app->getErrorInstance->UserInputHandler($e); + $this->app->getErrorInstance()->UserInputHandler($e); }catch(BaseError $e){ - $this->app->getErrorInstance->BaseErrorHandler($e); + $this->app->getErrorInstance()->BaseErrorHandler($e); }catch(NotImplementedError $e){ - $this->app->getErrorInstance->NotImplementedHandler($e); + $this->app->getErrorInstance()->NotImplementedHandler($e); } $this->app->setOutput("Images", $image); } @@ -266,9 +258,10 @@ class image implements Core{ /** * Delete an image * - * @param string $id - * identifier of the image - **/ + * @param String $id Identifier of the image + * + * @return void + */ private function deleteImage(){ // si protected = true, demander de le mettre a false // vérifier existence image @@ -280,27 +273,28 @@ class image implements Core{ try{ $service = $this->libClass; $image = $this->libClass->getImage($id); - if($image == null){ // if the image don't exists -> error + if($image == null){ // if the image doesn't exists -> error $this->app->setOutput("Error", "Image doesn't exist"); } $image->delete(); }catch(BadResponseError $e){ $this->app->getErrorInstance()->BadResponseHandler($e); }catch(UserInputError $e){ - $this->app->getErrorInstance->UserInputHandler($e); + $this->app->getErrorInstance()->UserInputHandler($e); }catch(BaseError $e){ - $this->app->getErrorInstance->BaseErrorHandler($e); + $this->app->getErrorInstance()->BaseErrorHandler($e); }catch(NotImplementedError $e){ - $this->app->getErrorInstance->NotImplementedHandler($e); + $this->app->getErrorInstance()->NotImplementedHandler($e); } } /** * Resactive an image * - * @param string $id - * identifier of the image - **/ + * @param String $id Identifier of the image + * + * @return void + */ private function reactivateImage(){ $id = $this->app->getPostParam("id"); @@ -308,7 +302,6 @@ class image implements Core{ $this->app->setOutput("Error", "Incorrect parameter"); } try{ - // vérifier existence image $service = $this->libClass; $image = $service->getImage($id); if($image == null){ // if the image don't exists -> error @@ -318,20 +311,21 @@ class image implements Core{ }catch(BadResponseError $e){ $this->app->getErrorInstance()->BadResponseHandler($e); }catch(UserInputError $e){ - $this->app->getErrorInstance->UserInputHandler($e); + $this->app->getErrorInstance()->UserInputHandler($e); }catch(BaseError $e){ - $this->app->getErrorInstance->BaseErrorHandler($e); + $this->app->getErrorInstance()->BaseErrorHandler($e); }catch(NotImplementedError $e){ - $this->app->getErrorInstance->NotImplementedHandler($e); + $this->app->getErrorInstance()->NotImplementedHandler($e); } } /** * Desactive an image * - * @param string $id - * identifier of the image - **/ + * @param String $id Identifier of the image + * + * @return void + */ private function desactivateImage(){ $id = $this->app->getPostParam("id"); @@ -349,23 +343,22 @@ class image implements Core{ }catch(BadResponseError $e){ $this->app->getErrorInstance()->BadResponseHandler($e); }catch(UserInputError $e){ - $this->app->getErrorInstance->UserInputHandler($e); + $this->app->getErrorInstance()->UserInputHandler($e); }catch(BaseError $e){ - $this->app->getErrorInstance->BaseErrorHandler($e); + $this->app->getErrorInstance()->BaseErrorHandler($e); }catch(NotImplementedError $e){ - $this->app->getErrorInstance->NotImplementedHandler($e); + $this->app->getErrorInstance()->NotImplementedHandler($e); } } /** * Upload an image * - * @param string $id - * identifier of the image - * - * @param string $file_name - * path of the image - **/ + * @param String $id Identifier of the image + * @param String $file_name Path of the image + * + * @return void + */ private function uploadImage(){ $id = $this->app->getPostParam("id"); $file_name = $this->app->getPostParam("file_name"); @@ -375,7 +368,7 @@ class image implements Core{ $this->app->setOutput("Error", "Incorrect id parameter"); } if(!isset($file_name)){ - $this->app->setOutput("Error", "Incorrect file_name parameter"); + $this->app->setOutput("Error", "Incorrect file name parameter"); } try{ // vérifier existence image @@ -389,25 +382,26 @@ class image implements Core{ }catch(BadResponseError $e){ $this->app->getErrorInstance()->BadResponseHandler($e); }catch(UserInputError $e){ - $this->app->getErrorInstance->UserInputHandler($e); + $this->app->getErrorInstance()->UserInputHandler($e); }catch(BaseError $e){ - $this->app->getErrorInstance->BaseErrorHandler($e); + $this->app->getErrorInstance()->BaseErrorHandler($e); }catch(NotImplementedError $e){ - $this->app->getErrorInstance->NotImplementedHandler($e); + $this->app->getErrorInstance()->NotImplementedHandler($e); } } /** * Download an image * - * @param string $id - * identifier of the image - **/ + * @param String $id Identifier of the image + * + * @return Stream + */ private function downloadImage(){ $id = $this->app->getPostParam("id"); if(!isset($id)){ - $this->app->setOutput("Error", "Incorrect parameter"); + $this->app->setOutput("Error", "Incorrect id parameter"); } try{ // vérifier existence image @@ -420,11 +414,11 @@ class image implements Core{ }catch(BadResponseError $e){ $this->app->getErrorInstance()->BadResponseHandler($e); }catch(UserInputError $e){ - $this->app->getErrorInstance->UserInputHandler($e); + $this->app->getErrorInstance()->UserInputHandler($e); }catch(BaseError $e){ - $this->app->getErrorInstance->BaseErrorHandler($e); + $this->app->getErrorInstance()->BaseErrorHandler($e); }catch(NotImplementedError $e){ - $this->app->getErrorInstance->NotImplementedHandler($e); + $this->app->getErrorInstance()->NotImplementedHandler($e); } $this->app->setOutput("Images", $stream); } @@ -432,21 +426,20 @@ class image implements Core{ /** * Add a member to image * - * @param string $image_id - * identifier of the image - * - * @param string $member_id - * identifier of the member - **/ + * @param String $image_id Identifier of the image + * @param String $member_id Identifier of the member + * + * @return Member + */ private function addMemberImage(){ $image_id = $this->app->getPostParam("image_id"); $member_id = $this->app->getPostParam("member_id"); if(!isset($image_id)){ - $this->app->setOutput("Error", "Incorrect parameter image_id"); + $this->app->setOutput("Error", "Incorrect image id parameter"); } if(!isset($member_id)){ - $this->app->setOutput("Error", "Incorrect parameter member_id"); + $this->app->setOutput("Error", "Incorrect member id parameter"); } try{ $service = $this->libClass; @@ -456,14 +449,15 @@ class image implements Core{ $this->app->setOutput("Error", "Image doesn't exist"); } $member_id = $image->addMember($member_id); + $this->app->setOutput("Images", $member_id); }catch(BadResponseError $e){ $this->app->getErrorInstance()->BadResponseHandler($e); }catch(UserInputError $e){ - $this->app->getErrorInstance->UserInputHandler($e); + $this->app->getErrorInstance()->UserInputHandler($e); }catch(BaseError $e){ - $this->app->getErrorInstance->BaseErrorHandler($e); + $this->app->getErrorInstance()->BaseErrorHandler($e); }catch(NotImplementedError $e){ - $this->app->getErrorInstance->NotImplementedHandler($e); + $this->app->getErrorInstance()->NotImplementedHandler($e); } } @@ -471,18 +465,19 @@ class image implements Core{ /** * List members of an image * - * @param string $image_id - * identifier of the image - **/ + * @param String $image_id identifier of the image + * + * @return List of Member + */ private function listMemberImage(){ $image_id = $this->app->getPostParam("image_id"); $member_id = $this->app->getPostParam("member_id"); if(!isset($image_id)){ - $this->app->setOutput("Error", "Incorrect parameter image_id"); + $this->app->setOutput("Error", "Incorrect image id parameter"); } if(!isset($member_id)){ - $this->app->setOutput("Error", "Incorrect parameter member_id"); + $this->app->setOutput("Error", "Incorrect member id parameter"); } try{ // vérifier existence image @@ -492,44 +487,40 @@ class image implements Core{ $this->app->setOutput("Error", "Image doesn't exist"); } $members = $image->listMembers(); - if($member == null){ // if the image don't exists -> error + if($members == null){ // if the image don't exists -> error $this->app->setOutput("Error", "No member"); } }catch(BadResponseError $e){ $this->app->getErrorInstance()->BadResponseHandler($e); }catch(UserInputError $e){ - $this->app->getErrorInstance->UserInputHandler($e); + $this->app->getErrorInstance()->UserInputHandler($e); }catch(BaseError $e){ - $this->app->getErrorInstance->BaseErrorHandler($e); + $this->app->getErrorInstance()->BaseErrorHandler($e); }catch(NotImplementedError $e){ - $this->app->getErrorInstance->NotImplementedHandler($e); + $this->app->getErrorInstance()->NotImplementedHandler($e); } - $this->app->setOutput("Images", $member); + $this->app->setOutput("Images", $members); } /** * Show details of a member of an image * - * @param string $image_id - * identifier of the image + * @param String $image_id Identifier of the image + * @param String $member_id Identifier of the member * - * @param string $member_id - * identifier of the member - **/ + * @return Member + */ private function detailMemberImage(){ $image_id = $this->app->getPostParam("image_id"); $member_id = $this->app->getPostParam("member_id"); if(!isset($image_id)){ - $this->app->setOutput("Error", "Incorrect parameter image_id"); + $this->app->setOutput("Error", "Incorrect image id parameter"); } if(!isset($member_id)){ - $this->app->setOutput("Error", "Incorrect parameter member_id"); + $this->app->setOutput("Error", "Incorrect member id parameter"); } try{ - // vérifier existence image - // on doit être le proprio de l'image - // vérifier membre existe $service = $this->libClass; $image = $service->getImage($id); @@ -544,11 +535,11 @@ class image implements Core{ }catch(BadResponseError $e){ $this->app->getErrorInstance()->BadResponseHandler($e); }catch(UserInputError $e){ - $this->app->getErrorInstance->UserInputHandler($e); + $this->app->getErrorInstance()->UserInputHandler($e); }catch(BaseError $e){ - $this->app->getErrorInstance->BaseErrorHandler($e); + $this->app->getErrorInstance()->BaseErrorHandler($e); }catch(NotImplementedError $e){ - $this->app->getErrorInstance->NotImplementedHandler($e); + $this->app->getErrorInstance()->NotImplementedHandler($e); } $this->app->setOutput("Images", $member); } @@ -556,21 +547,20 @@ class image implements Core{ /** * Remove a member of an image * - * @param string $image_id - * identifier of the image - * - * @param string $member_id - * identifier of the member - **/ + * @param String $image_id Identifier of the image + * @param String $member_id Identifier of the member + * + * @return void + */ private function removeMemberImage(){ $image_id = $this->app->getPostParam("image_id"); $member_id = $this->app->getPostParam("member_id"); if(!isset($image_id)){ - $this->app->setOutput("Error", "Incorrect parameter image_id"); + $this->app->setOutput("Error", "Incorrect image id parameter"); } if(!isset($member_id)){ - $this->app->setOutput("Error", "Incorrect parameter member_id"); + $this->app->setOutput("Error", "Incorrect member id parameter"); } try{ $service = $this->libClass; @@ -587,25 +577,22 @@ class image implements Core{ }catch(BadResponseError $e){ $this->app->getErrorInstance()->BadResponseHandler($e); }catch(UserInputError $e){ - $this->app->getErrorInstance->UserInputHandler($e); + $this->app->getErrorInstance()->UserInputHandler($e); }catch(BaseError $e){ - $this->app->getErrorInstance->BaseErrorHandler($e); + $this->app->getErrorInstance()->BaseErrorHandler($e); }catch(NotImplementedError $e){ - $this->app->getErrorInstance->NotImplementedHandler($e); + $this->app->getErrorInstance()->NotImplementedHandler($e); } } /** * Update a member of an image * - * @param string $image_id - * identifier of the image - * - * @param string $member_id - * identifier of the member + * @param String $image_id Identifier of the image + * @param String $member_id Identifier of the member + * @param String $status New status for the member * - * @param string $status - * new status for the member + * @return void **/ private function updateMemberImage(){ $image_id = $this->app->getPostParam("image_id"); @@ -613,10 +600,10 @@ class image implements Core{ $status = $this->app->getPostParam("status"); if(!isset($image_id)){ - $this->app->setOutput("Error", "Incorrect parameter image_id"); + $this->app->setOutput("Error", "Incorrect image id parameter"); } if(!isset($member_id)){ - $this->app->setOutput("Error", "Incorrect parameter member_id"); + $this->app->setOutput("Error", "Incorrect member id parameter"); } try{ $service = $this->libClass; @@ -633,11 +620,11 @@ class image implements Core{ }catch(BadResponseError $e){ $this->app->getErrorInstance()->BadResponseHandler($e); }catch(UserInputError $e){ - $this->app->getErrorInstance->UserInputHandler($e); + $this->app->getErrorInstance()->UserInputHandler($e); }catch(BaseError $e){ - $this->app->getErrorInstance->BaseErrorHandler($e); + $this->app->getErrorInstance()->BaseErrorHandler($e); }catch(NotImplementedError $e){ - $this->app->getErrorInstance->NotImplementedHandler($e); + $this->app->getErrorInstance()->NotImplementedHandler($e); } } -- cgit v1.2.3 From fe0eb3a9e259b4fe09df364f0660ebc62185f9dd Mon Sep 17 00:00:00 2001 From: Yoggzo Date: Thu, 17 Mar 2016 11:34:56 +0100 Subject: add exception management, correct mistakes in error management in Image.php and add function to simplify parameters using in tests --- server/Test/AppTestClass.php | 8 +- server/Test/imageTests.php | 68 ++--- server/core/ErrorManagement.php | 4 + server/core/Image.php | 549 ++++++++++++++++++++++------------------ 4 files changed, 339 insertions(+), 290 deletions(-) (limited to 'server/Test/AppTestClass.php') diff --git a/server/Test/AppTestClass.php b/server/Test/AppTestClass.php index 5e8efc7..e1631c5 100755 --- a/server/Test/AppTestClass.php +++ b/server/Test/AppTestClass.php @@ -89,10 +89,16 @@ class AppTest{ } public function getPostParam($name){ - + return $this->postParams[$name]; } + + public function setPostParam($name, $value){ + + $this->postParams[$name] = $value; + + } public function setOutput($key, $out){ diff --git a/server/Test/imageTests.php b/server/Test/imageTests.php index 3af12fc..883387d 100644 --- a/server/Test/imageTests.php +++ b/server/Test/imageTests.php @@ -14,55 +14,39 @@ $opt['minDisk'] = 1; $opt['protected'] = false; $opt['minRam'] = 10; -//$new_image = $image->createImage($opt); +//$App->setPostParam('id', 'sdfihlus154dfhj'); +$err = $image->action("createImage"); + //Liste des images $image->action("listImage"); -//$images = $image->listImage(); $im = $App->show(); -$images = json_decode($im, true)["Images"]; -if(isset($images)){ - echo "Images présentes :"; - echo "
    "; - foreach($images as $i){ - echo $i['name']; - echo "
    "; - } +$images = json_decode($im, true)["Images"]; +$recup; + +echo "Images présentes :"; +echo "
    "; +foreach($images as $i){ + $recup = $i; + echo $recup['name']; echo "
    "; + //echo $recup['id']; + } +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"); - if(isset($list)){ - foreach ($list as $l) { - echo $l; - echo "
    "; - } -} -} -else{ - echo "Aucune image présente\n"; -} - - - -// Détails Image -//$details = $image->imageDetails($id_image); - -//$image->deleteImage('123456'); - -//$image->desactivateImage($id_image); -//$image->reactivateImage($id_image); - -//$file_name = "/home/yogg/Downloads/TinyCore-6.4.1.iso"; -//$image->uploadImage($id_image, $file_name); - -//$image->downloadImage($id_image); -/* -$opt_update = Array(); -$opt_update['name'] = "Test"; -$opt_update['tags'] = null; -$update = $image->updateImage($id_image, $opt_update); -echo $update->name; -*/ ?> \ No newline at end of file diff --git a/server/core/ErrorManagement.php b/server/core/ErrorManagement.php index 4ba3493..ff66339 100755 --- a/server/core/ErrorManagement.php +++ b/server/core/ErrorManagement.php @@ -32,6 +32,10 @@ Class errorManagement{ public function UserInputHandler($error){ } + + public function OtherException($error){ + $this->app->setOutput("Error", $error->getMessage); + } } diff --git a/server/core/Image.php b/server/core/Image.php index f309943..71e19ce 100755 --- a/server/core/Image.php +++ b/server/core/Image.php @@ -131,6 +131,8 @@ class image implements Core{ $this->app->getErrorInstance()->BaseErrorHandler($e); }catch(NotImplementedError $e){ $this->app->getErrorInstance()->NotImplementedHandler($e); + }catch(Exception $e){ + $this->app->getErrorInstance()->OtherException($e); } $this->app->setOutput("Images", $image); @@ -156,6 +158,8 @@ class image implements Core{ $this->app->getErrorInstance()->BaseErrorHandler($e); }catch(NotImplementedError $e){ $this->app->getErrorInstance()->NotImplementedHandler($e); + }catch(Exception $e){ + $this->app->getErrorInstance()->OtherException($e); } $this->app->setOutput("Images", $result); @@ -171,26 +175,33 @@ class image implements Core{ */ private function detailsImage(){ $id = $this->app->getPostParam("id"); + if(!isset($id)){ $this->app->setOutput("Error", "Incorrect id parameter"); - } - try{ - $service = $this->libClass; - $image = $service->getImage($id); - if($image == null){ // if the image don't exists -> error - $this->app->setOutput("Error", "Image doesn't exist"); - } - $this->app->setOutput("Images", $image); - }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); - } + else{ + try{ + $service = $this->libClass; + $image = $service->getImage($id); + if($image == null){ // if the image don't exists -> error + $this->app->setOutput("Error", "Image doesn't exist"); + } + else{ + echo 'toto'; + $this->app->setOutput("Images", $image); + } + }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); + } + } } /** @@ -209,50 +220,53 @@ class image implements Core{ if(!isset($id)){ $this->app->setOutput("Error", "Incorrect id parameter"); } - if(!isset($opt)){ + else if(!isset($opt)){ $this->app->setOutput("Error", "Incorrect opt parameter"); } + else{ + try{ + //vérifier existence image + $service = $this->libClass; + $image = $service->getImage($id); + if($image == null){ // if the image don't exists -> error + $this->app->setOutput("Error", "Image doesn't exist"); + } - try{ - //vérifier existence image - $service = $this->libClass; - $image = $service->getImage($id); - if($image == null){ // if the image don't exists -> error - $this->app->setOutput("Error", "Image doesn't exist"); - } - - $options = Array(); + $options = Array(); - // Voir vérification des types - if(isset($opt['name'])){ //string - $options['name'] = $opt['name']; - } - if(isset($opt['minDisk'])){ //int - $options['minDisk'] = $opt['minDisk']; - } - if(isset($opt['minRam'])){ // int - $options['minRam'] = $opt['minRam']; - } - if(isset($opt['protected'])){ // boolean - $options['protected'] = $opt['protected']; - } - if(isset($opt['visibility'])){ // public, private - $options['visibility'] = $opt['visibility']; - } - if(isset($opt['tags'])){ // list - $options['tags'] = $opt['tags']; - } - $image->update($options); - }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); - } - $this->app->setOutput("Images", $image); + // Voir vérification des types + if(isset($opt['name'])){ //string + $options['name'] = $opt['name']; + } + if(isset($opt['minDisk'])){ //int + $options['minDisk'] = $opt['minDisk']; + } + if(isset($opt['minRam'])){ // int + $options['minRam'] = $opt['minRam']; + } + if(isset($opt['protected'])){ // boolean + $options['protected'] = $opt['protected']; + } + if(isset($opt['visibility'])){ // public, private + $options['visibility'] = $opt['visibility']; + } + if(isset($opt['tags'])){ // list + $options['tags'] = $opt['tags']; + } + $image->update($options); + }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); + } + $this->app->setOutput("Images", $image); + } } /** @@ -269,23 +283,26 @@ class image implements Core{ if(!isset($id)){ $this->app->setOutput("Error", "Image doesn't exist"); } - - try{ - $service = $this->libClass; - $image = $this->libClass->getImage($id); - if($image == null){ // if the image doesn't exists -> error - $this->app->setOutput("Error", "Image doesn't exist"); - } - $image->delete(); - }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); - } + else{ + try{ + $service = $this->libClass; + $image = $this->libClass->getImage($id); + if($image == null){ // if the image doesn't exists -> error + $this->app->setOutput("Error", "Image doesn't exist"); + } + $image->delete(); + }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); + } + } } /** @@ -301,22 +318,27 @@ class image implements Core{ if(!isset($id)){ $this->app->setOutput("Error", "Incorrect parameter"); } - try{ - $service = $this->libClass; - $image = $service->getImage($id); - 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); - }catch(UserInputError $e){ - $this->app->getErrorInstance()->UserInputHandler($e); - }catch(BaseError $e){ - $this->app->getErrorInstance()->BaseErrorHandler($e); - }catch(NotImplementedError $e){ - $this->app->getErrorInstance()->NotImplementedHandler($e); - } + else + { + try{ + $service = $this->libClass; + $image = $service->getImage($id); + 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); + }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); + } + } } /** @@ -332,23 +354,28 @@ class image implements Core{ if(!isset($id)){ $this->app->setOutput("Error", "Incorrect parameter"); } - try{ - // vérifier existence image - $service = $this->libClass; - $image = $service->getImage($id); - if($image == null){ // if the image don't exists -> error - $this->app->setOutput("Error", "Image doesn't exist"); - } - $image->deactivate(); - }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); - } + else + { + try{ + // vérifier existence image + $service = $this->libClass; + $image = $service->getImage($id); + if($image == null){ // if the image don't exists -> error + $this->app->setOutput("Error", "Image doesn't exist"); + } + $image->deactivate(); + }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); + } + } } /** @@ -367,26 +394,30 @@ class image implements Core{ if(!isset($id)){ $this->app->setOutput("Error", "Incorrect id parameter"); } - if(!isset($file_name)){ + else if(!isset($file_name)){ $this->app->setOutput("Error", "Incorrect file name parameter"); } - try{ - // vérifier existence image - $service = $this->libClass; - $image = $service->getImage($id); - if($image == null){ // if the image don't exists -> error - $this->app->setOutput("Error", "Image doesn't exist"); - } - $stream = \GuzzleHttp\Psr7\stream_for(fopen($file_name, 'r')); - $image->uploadData($stream); - }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); + else{ + try{ + // vérifier existence image + $service = $this->libClass; + $image = $service->getImage($id); + if($image == null){ // if the image don't exists -> error + $this->app->setOutput("Error", "Image doesn't exist"); + } + $stream = \GuzzleHttp\Psr7\stream_for(fopen($file_name, 'r')); + $image->uploadData($stream); + }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); + } } } @@ -403,24 +434,28 @@ class image implements Core{ if(!isset($id)){ $this->app->setOutput("Error", "Incorrect id parameter"); } - try{ - // vérifier existence image - $service = $this->libClass; - $image = $service->getImage($id); - if($image == null){ // if the image don't exists -> error - $this->app->setOutput("Error", "Image doesn't exist"); - } - $stream = $image->downloadData(); - }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); - } - $this->app->setOutput("Images", $stream); + else{ + try{ + // vérifier existence image + $service = $this->libClass; + $image = $service->getImage($id); + if($image == null){ // if the image don't exists -> error + $this->app->setOutput("Error", "Image doesn't exist"); + } + $stream = $image->downloadData(); + }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); + } + $this->app->setOutput("Images", $stream); + } } /** @@ -438,27 +473,31 @@ class image implements Core{ if(!isset($image_id)){ $this->app->setOutput("Error", "Incorrect image id parameter"); } - if(!isset($member_id)){ + else if(!isset($member_id)){ $this->app->setOutput("Error", "Incorrect member id parameter"); } - try{ - $service = $this->libClass; + else{ + try{ + $service = $this->libClass; - $image = $service->getImage($id); - if($image == null){ // if the image don't exists -> error - $this->app->setOutput("Error", "Image doesn't exist"); - } - $member_id = $image->addMember($member_id); - $this->app->setOutput("Images", $member_id); - }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); - } + $image = $service->getImage($id); + if($image == null){ // if the image don't exists -> error + $this->app->setOutput("Error", "Image doesn't exist"); + } + $member_id = $image->addMember($member_id); + $this->app->setOutput("Images", $member_id); + }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); + } + } } @@ -476,30 +515,34 @@ class image implements Core{ if(!isset($image_id)){ $this->app->setOutput("Error", "Incorrect image id parameter"); } - if(!isset($member_id)){ + else if(!isset($member_id)){ $this->app->setOutput("Error", "Incorrect member id parameter"); } - try{ - // vérifier existence image - $service = $this->libClass; - $image = $service->getImage($image_id); - if($image == null){ // if the image don't exists -> error - $this->app->setOutput("Error", "Image doesn't exist"); - } - $members = $image->listMembers(); - if($members == null){ // if the image don't exists -> error - $this->app->setOutput("Error", "No member"); - } - }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); - } - $this->app->setOutput("Images", $members); + else{ + try{ + // vérifier existence image + $service = $this->libClass; + $image = $service->getImage($image_id); + if($image == null){ // if the image don't exists -> error + $this->app->setOutput("Error", "Image doesn't exist"); + } + $members = $image->listMembers(); + if($members == null){ // if the image don't exists -> error + $this->app->setOutput("Error", "No member"); + } + }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); + } + $this->app->setOutput("Images", $members); + } } /** @@ -517,31 +560,35 @@ class image implements Core{ if(!isset($image_id)){ $this->app->setOutput("Error", "Incorrect image id parameter"); } - if(!isset($member_id)){ + else if(!isset($member_id)){ $this->app->setOutput("Error", "Incorrect member id parameter"); } - try{ - $service = $this->libClass; + else{ + try{ + $service = $this->libClass; - $image = $service->getImage($id); - if($image == null){ // if the image don't exists -> error - $this->app->setOutput("Error", "Image doesn't exist"); - } + $image = $service->getImage($id); + if($image == null){ // if the image don't exists -> error + $this->app->setOutput("Error", "Image doesn't exist"); + } - $member = $image->getMember($member_id); - if($member == null){ // if the member don't exists -> error - $this->app->setOutput("Error", "Member doesn't exist"); - } - }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); - } - $this->app->setOutput("Images", $member); + $member = $image->getMember($member_id); + if($member == null){ // if the member don't exists -> error + $this->app->setOutput("Error", "Member doesn't exist"); + } + }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); + } + $this->app->setOutput("Images", $member); + } } /** @@ -559,30 +606,34 @@ class image implements Core{ if(!isset($image_id)){ $this->app->setOutput("Error", "Incorrect image id parameter"); } - if(!isset($member_id)){ + else if(!isset($member_id)){ $this->app->setOutput("Error", "Incorrect member id parameter"); } - try{ - $service = $this->libClass; - - $image = $service->getImage($id); - if($image == null){ // if the image don't exists -> error - $this->app->setOutput("Error", "Image doesn't exist"); - } - $member = $image->getMember($member_id); - if($member == null){ // if the image don't exists -> error - $this->app->setOutput("Error", "Member doesn't exist"); - } - $member->delete(); - }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); - } + else{ + try{ + $service = $this->libClass; + + $image = $service->getImage($id); + if($image == null){ // if the image don't exists -> error + $this->app->setOutput("Error", "Image doesn't exist"); + } + $member = $image->getMember($member_id); + if($member == null){ // if the image don't exists -> error + $this->app->setOutput("Error", "Member doesn't exist"); + } + $member->delete(); + }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); + } + } } /** @@ -602,30 +653,34 @@ class image implements Core{ if(!isset($image_id)){ $this->app->setOutput("Error", "Incorrect image id parameter"); } - if(!isset($member_id)){ + else if(!isset($member_id)){ $this->app->setOutput("Error", "Incorrect member id parameter"); } - try{ - $service = $this->libClass; + else{ + try{ + $service = $this->libClass; - $image = $service->getImage($id); - if($image == null){ // if the image don't exists -> error - $this->app->setOutput("Error", "Image doesn't exist"); - } - $member = $image->getMember($member_id); - if($member == null){ // if the member don't exists -> error - $this->app->setOutput("Error", "Member doesn't exist"); - } - $member->updateStatus($status); - }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); - } + $image = $service->getImage($id); + if($image == null){ // if the image don't exists -> error + $this->app->setOutput("Error", "Image doesn't exist"); + } + $member = $image->getMember($member_id); + if($member == null){ // if the member don't exists -> error + $this->app->setOutput("Error", "Member doesn't exist"); + } + $member->updateStatus($status); + }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); + } + } } } -- cgit v1.2.3