AIRAVATA-1841 Redirect to home when Airavata is down
Project: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/repo Commit: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/commit/e95897f5 Tree: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/tree/e95897f5 Diff: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/diff/e95897f5 Branch: refs/heads/develop Commit: e95897f585f81d62fb1adefbb10fbfe4bb22e9a6 Parents: 6d23862 Author: Marcus Christie <machris...@apache.org> Authored: Fri Jan 6 11:52:11 2017 -0500 Committer: Marcus Christie <machris...@apache.org> Committed: Tue Jan 10 10:20:03 2017 -0500 ---------------------------------------------------------------------- app/controllers/AccountController.php | 31 +++++++++++++++--------------- app/filters.php | 12 ++++++++++++ app/libraries/CommonUtilities.php | 25 +++++++++++++++++++++++- app/routes.php | 9 +++++++++ app/views/layout/basic.blade.php | 5 +++++ 5 files changed, 65 insertions(+), 17 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/e95897f5/app/controllers/AccountController.php ---------------------------------------------------------------------- diff --git a/app/controllers/AccountController.php b/app/controllers/AccountController.php index 3b3c771..4b7bfac 100644 --- a/app/controllers/AccountController.php +++ b/app/controllers/AccountController.php @@ -210,24 +210,23 @@ class AccountController extends BaseController } private function initializeWithAiravata($username){ - //Check Airavata Server is up - try{ + // TODO: should we log the user out if Airavata is down and they won't have a default project created? + if (!CommonUtilities::isAiravataUp()) { + return Redirect::to("home"); + } + + //creating a default project for user + $projects = ProjectUtilities::get_all_user_projects(Config::get('pga_config.airavata')['gateway-id'], $username); + if($projects == null || count($projects) == 0){ //creating a default project for user - $projects = ProjectUtilities::get_all_user_projects(Config::get('pga_config.airavata')['gateway-id'], $username); - if($projects == null || count($projects) == 0){ - //creating a default project for user - ProjectUtilities::create_default_project($username); - } + ProjectUtilities::create_default_project($username); + } - $dirPath = Config::get('pga_config.airavata')['experiment-data-absolute-path'] . "/" . Session::get('username'); - if(!file_exists($dirPath)){ - $old_umask = umask(0); - mkdir($dirPath, 0777, true); - umask($old_umask); - } - }catch (Exception $ex){ - CommonUtilities::print_error_message("Unable to Connect to the Airavata Server Instance!"); - return View::make('home'); + $dirPath = Config::get('pga_config.airavata')['experiment-data-absolute-path'] . "/" . Session::get('username'); + if(!file_exists($dirPath)){ + $old_umask = umask(0); + mkdir($dirPath, 0777, true); + umask($old_umask); } if(Session::has("admin") || Session::has("admin-read-only")){ http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/e95897f5/app/filters.php ---------------------------------------------------------------------- diff --git a/app/filters.php b/app/filters.php index e28b25b..93839c8 100755 --- a/app/filters.php +++ b/app/filters.php @@ -136,4 +136,16 @@ Route::filter('verifyeditadmin', function () { } } else return Redirect::to("home")->with("login-alert", true); +}); + +Route::filter('checkIfAiravataIsUp', function() { + if (Request::path() == "logout") { + return; + } + if (CommonUtilities::id_in_session()) { + if (!CommonUtilities::isAiravataUp() && !Session::has("airavata-down")) { + // TODO: just use request variable instead of additional flash variable? + return Redirect::to("home")->with("airavata-down", true); + } + } }); \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/e95897f5/app/libraries/CommonUtilities.php ---------------------------------------------------------------------- diff --git a/app/libraries/CommonUtilities.php b/app/libraries/CommonUtilities.php index 27b3828..d9e7127 100644 --- a/app/libraries/CommonUtilities.php +++ b/app/libraries/CommonUtilities.php @@ -211,7 +211,9 @@ class CommonUtilities if( Session::has('authorized-user') || Session::has('admin') || Session::has('admin-read-only')){ //notification bell $notices = array(); - $notices = CommonUtilities::get_all_notices(); + if (CommonUtilities::isAiravataUp()) { + $notices = CommonUtilities::get_all_notices(); + } $navbar .= CommonUtilities::get_notices_ui( $notices); } @@ -412,5 +414,26 @@ class CommonUtilities return strtotime( $addOrSubtract . " " . abs($timeDifference) . " hours", $localTime); } + + public static function isAiravataUp() { + // Cache whether Airavata is up in the REQUEST scope + if (array_key_exists("isAiravataUp", $_REQUEST)) { + return $_REQUEST["isAiravataUp"]; + } + $_REQUEST["isAiravataUp"] = CommonUtilities::checkIfAiravataIsUp(); + return $_REQUEST["isAiravataUp"]; + } + + private static function checkIfAiravataIsUp() { + + try { + $version = Airavata::getAPIVersion(Session::get('authz-token')); + Log::debug("Airavata is up!", array("version" => $version)); + return true; + } catch (Exception $e) { + Log::error("Airavata is down!", array("exception", $e)); + return false; + } + } } http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/e95897f5/app/routes.php ---------------------------------------------------------------------- diff --git a/app/routes.php b/app/routes.php index 7418ab6..98d4c4a 100755 --- a/app/routes.php +++ b/app/routes.php @@ -383,6 +383,15 @@ Route::get( "pages/{theme_view}", function( $theme_view){ Route::get("airavata/down", function () { return View::make("server-down"); }); + +// the filter excludes the 'logout' route +Route::when("*", 'checkIfAiravataIsUp'); + +Route::get("is-airavata-up", function() { + + return Response::json(array("is-airavata-up" => CommonUtilities::isAiravataUp())); +}); + /* * Test Routes. */ http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/e95897f5/app/views/layout/basic.blade.php ---------------------------------------------------------------------- diff --git a/app/views/layout/basic.blade.php b/app/views/layout/basic.blade.php index 2cb74cf..b621ecd 100755 --- a/app/views/layout/basic.blade.php +++ b/app/views/layout/basic.blade.php @@ -48,6 +48,11 @@ var fullName = "{{Session::get("user-profile")["firstname"] . " " . Session::get {{ Session::forget("admin-alert") }} @endif +@if (Session::has("airavata-down")) + {{ CommonUtilities::print_error_message("The Airavata servers are currently down. We apologize for any inconvenience. Please try again after some time.") }} + {{ Session::forget("airavata-down") }} +@endif + <!-- PGA UI lies here. Do not touch. --> <style> .content-area{