[LON-CAPA-cvs] cvs: loncom /auth lonauth.pm /lonnet/perl lonnet.pm

raeburn raeburn@source.lon-capa.org
Sun, 12 Jun 2011 14:18:12 -0000


raeburn		Sun Jun 12 14:18:12 2011 EDT

  Modified files:              
    /loncom/auth	lonauth.pm 
    /loncom/lonnet/perl	lonnet.pm 
  Log:
  - If server is configured to deny hosting of sessions for user's domain,
    attempt to switch session to least loaded server in user's domain.
  - Display message if no server available to host session.
  
  
Index: loncom/auth/lonauth.pm
diff -u loncom/auth/lonauth.pm:1.114 loncom/auth/lonauth.pm:1.115
--- loncom/auth/lonauth.pm:1.114	Sat Jun 11 17:50:35 2011
+++ loncom/auth/lonauth.pm	Sun Jun 12 14:18:09 2011
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # User Authentication Module
 #
-# $Id: lonauth.pm,v 1.114 2011/06/11 17:50:35 raeburn Exp $
+# $Id: lonauth.pm,v 1.115 2011/06/12 14:18:09 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -415,17 +415,32 @@
 	}
     }
 
-    unless (&check_can_host($r,\%form,$authhost)) {
-        return OK;
-    }
-
     if ($r->dir_config("lonBalancer") eq 'yes') {
-	&success($r,$form{'uname'},$form{'udom'},$authhost,'noredirect',undef,
-		 \%form);
         my $otherserver = &Apache::lonnet::spareserver(30000,undef,1,$form{'udom'});
-	$r->internal_redirect('/adm/switchserver?otherserver='.$otherserver.'&origurl='.$firsturl);
+        if (!$otherserver) { 
+            $otherserver = &Apache::lonnet::choose_server($form{'udom'});
+        }
+        if ($otherserver) {
+            &success($r,$form{'uname'},$form{'udom'},$authhost,'noredirect',undef,
+                     \%form);
+	    $r->internal_redirect('/adm/switchserver?otherserver='.$otherserver.'&origurl='.$firsturl);
+        } else {
+            $r->print(&noswitch());
+        }
         return OK;
     } else {
+        if (!&check_can_host($r,\%form,$authhost)) {
+            my $otherserver = &Apache::lonnet::choose_server($form{'udom'});
+            if ($otherserver) {
+                &success($r,$form{'uname'},$form{'udom'},$authhost,'noredirect',undef,
+                         \%form);
+                $r->internal_redirect('/adm/switchserver?otherserver='.$otherserver.'&origurl='.$firsturl);
+            } else {
+                $r->print(&noswitch());
+            }
+            return OK;
+        }
+
 # ------------------------------------------------------- Do the load balancing
 
 # ---------------------------------------------------------- Determine own load
@@ -442,6 +457,9 @@
 # ---------------------------------------------------------- Are we overloaded?
         if ((($userloadpercent>100.0)||($loadpercent>100.0))) {
             my $unloaded=Apache::lonnet::spareserver($loadpercent,$userloadpercent,1,$form{'udom'});
+            if (!$unloaded) {
+                $unloaded = &Apache::lonnet::choose_server($form{'udom'});
+            }
             if ($unloaded) {
                 &success($r,$form{'uname'},$form{'udom'},$authhost,'noredirect',
                          undef,\%form);
@@ -487,7 +505,9 @@
     }
     unless ($canhost) {
         if ($authhost eq 'no_account_on_host') {
-            my ($login_host,$hostname) = &Apache::lonnet::choose_server($udom);
+            my $checkloginvia = 1;
+            my ($login_host,$hostname) = 
+                &Apache::lonnet::choose_server($udom,$checkloginvia);
             &Apache::loncommon::content_type($r,'text/html');
             $r->send_http_header;
             if ($login_host ne '') {
@@ -517,6 +537,15 @@
     return $canhost;
 }
 
+sub noswitch {
+    my $result = &Apache::loncommon::start_page('Access to LON-CAPA unavailable').
+                 '<h3>'.&mt('Session unavailable').'</h3>'.
+                 &mt('This LON-CAPA server is unable to host your session.').'<br />'.
+                 '<p>'.&mt('Currently no other LON-CAPA server is available to host your session either.').'</p>'.
+                 &Apache::loncommon::end_page();
+    return $result;
+}
+
 1;
 __END__
 
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.1114 loncom/lonnet/perl/lonnet.pm:1.1115
--- loncom/lonnet/perl/lonnet.pm:1.1114	Sun Jun 12 13:48:28 2011
+++ loncom/lonnet/perl/lonnet.pm	Sun Jun 12 14:18:12 2011
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.1114 2011/06/12 13:48:28 raeburn Exp $
+# $Id: lonnet.pm,v 1.1115 2011/06/12 14:18:12 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -862,13 +862,16 @@
 # --------- determine least loaded server in a user's domain which allows login
 
 sub choose_server {
-    my ($udom) = @_;
+    my ($udom,$checkloginvia) = @_;
     my %domconfhash = &Apache::loncommon::get_domainconf($udom);
     my %servers = &get_servers($udom);
     my $lowest_load = 30000;
     my ($login_host,$hostname);
     foreach my $lonhost (keys(%servers)) {
-        my $loginvia = $domconfhash{$udom.'.login.loginvia_'.$lonhost};
+        my $loginvia;
+        if ($checkloginvia) {
+            $loginvia = $domconfhash{$udom.'.login.loginvia_'.$lonhost};
+        }
         if ($loginvia eq '') {
             ($login_host, $lowest_load) =
             &compare_server_load($lonhost, $login_host, $lowest_load);