You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by ma...@apache.org on 2017/01/10 15:21:25 UTC

[1/2] airavata-php-gateway git commit: AIRAVATA-1841 if airavata is down, log user out when they log in

Repository: airavata-php-gateway
Updated Branches:
  refs/heads/develop 6d2386250 -> f4356c5f4


AIRAVATA-1841 if airavata is down, log user out when they log in

Handles the case where user logs in but Airavata is down. We want to log
the user out so that first log in initialization can be done at a later
login when Airavata is up.


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/f4356c5f
Tree: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/tree/f4356c5f
Diff: http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/diff/f4356c5f

Branch: refs/heads/develop
Commit: f4356c5f4348a08cda9b846f715dbdb1e2318e90
Parents: e95897f
Author: Marcus Christie <ma...@apache.org>
Authored: Tue Jan 10 10:06:41 2017 -0500
Committer: Marcus Christie <ma...@apache.org>
Committed: Tue Jan 10 10:20:03 2017 -0500

----------------------------------------------------------------------
 app/controllers/AccountController.php |  8 ++++++--
 app/filters.php                       | 27 +++++++++++++++------------
 app/libraries/CommonUtilities.php     |  3 +--
 app/routes.php                        |  8 --------
 4 files changed, 22 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/f4356c5f/app/controllers/AccountController.php
----------------------------------------------------------------------
diff --git a/app/controllers/AccountController.php b/app/controllers/AccountController.php
index 4b7bfac..13022bf 100644
--- a/app/controllers/AccountController.php
+++ b/app/controllers/AccountController.php
@@ -210,9 +210,13 @@ class AccountController extends BaseController
     }
 
     private function initializeWithAiravata($username){
-        // TODO: should we log the user out if Airavata is down and they won't have a default project created?
+
+        // Log the user out if Airavata is down. If a new user we want to make
+        // sure we create the default project and setup experiment storage
+        // before they do anything else.
         if (!CommonUtilities::isAiravataUp()) {
-            return Redirect::to("home");
+            Session::forget('loggedin');
+            return Redirect::to("home")->with("airavata-down", true);
         }
 
         //creating a default project for user

http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/f4356c5f/app/filters.php
----------------------------------------------------------------------
diff --git a/app/filters.php b/app/filters.php
index 93839c8..1c63b6a 100755
--- a/app/filters.php
+++ b/app/filters.php
@@ -40,6 +40,21 @@ App::before(function ($request) {
     }
 });
 
+// Check if Airavata is up
+App::before(function ($request) {
+
+    // Exclude logout from check so that user can logout
+    if ($request->path() == "logout") {
+        return;
+    }
+    if (CommonUtilities::id_in_session()) {
+        // Use "airavata-down" flash variable as a way to prevent infinite redirect
+        if (!CommonUtilities::isAiravataUp() && !Session::has("airavata-down")) {
+            return Redirect::to("home")->with("airavata-down", true);
+        }
+    }
+});
+
 
 App::after(function ($request, $response) {
     //
@@ -137,15 +152,3 @@ 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/f4356c5f/app/libraries/CommonUtilities.php
----------------------------------------------------------------------
diff --git a/app/libraries/CommonUtilities.php b/app/libraries/CommonUtilities.php
index d9e7127..4159136 100644
--- a/app/libraries/CommonUtilities.php
+++ b/app/libraries/CommonUtilities.php
@@ -428,10 +428,9 @@ class CommonUtilities
 
         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));
+            Log::error("Airavata is down!", array("exception" => $e));
             return false;
         }
     }

http://git-wip-us.apache.org/repos/asf/airavata-php-gateway/blob/f4356c5f/app/routes.php
----------------------------------------------------------------------
diff --git a/app/routes.php b/app/routes.php
index 98d4c4a..b2e58cd 100755
--- a/app/routes.php
+++ b/app/routes.php
@@ -384,14 +384,6 @@ 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.
 */


[2/2] airavata-php-gateway git commit: AIRAVATA-1841 Redirect to home when Airavata is down

Posted by ma...@apache.org.
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 <ma...@apache.org>
Authored: Fri Jan 6 11:52:11 2017 -0500
Committer: Marcus Christie <ma...@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{