[LON-CAPA-cvs] cvs: loncom /auth lonacc.pm lonauth.pm migrateuser.pm /interface domainprefs.pm /lonnet/perl lonnet.pm

raeburn raeburn at source.lon-capa.org
Sun Dec 4 19:52:03 EST 2016


raeburn		Mon Dec  5 00:52:03 2016 EDT

  Modified files:              
    /loncom/auth	lonacc.pm lonauth.pm migrateuser.pm 
    /loncom/interface	domainprefs.pm 
    /loncom/lonnet/perl	lonnet.pm 
  Log:
  - Domain Configuration for dedicated load balancer includes option to
    permit "Hosting on balancer itself".
  - If balancer has lowest load, it will host the user session for a user
    logging in.  
  
  
-------------- next part --------------
Index: loncom/auth/lonacc.pm
diff -u loncom/auth/lonacc.pm:1.164 loncom/auth/lonacc.pm:1.165
--- loncom/auth/lonacc.pm:1.164	Tue Aug 16 20:17:49 2016
+++ loncom/auth/lonacc.pm	Mon Dec  5 00:51:43 2016
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Cookie Based Access Handler
 #
-# $Id: lonacc.pm,v 1.164 2016/08/16 20:17:49 raeburn Exp $
+# $Id: lonacc.pm,v 1.165 2016/12/05 00:51:43 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -339,10 +339,24 @@
         }
         unless ($hosthere) {
             ($is_balancer,$otherserver) =
-                &Apache::lonnet::check_loadbalancing($user,$domain);
+                &Apache::lonnet::check_loadbalancing($user,$domain,'login');
+            if ($is_balancer) {
+                if ($otherserver eq '') {
+                    my $lowest_load;
+                    ($otherserver,undef,undef,undef,$lowest_load) = &Apache::lonnet::choose_server($domain);
+                    if ($lowest_load > 100) {
+                        $otherserver = &Apache::lonnet::spareserver($lowest_load,$lowest_load,1,$domain);
+                    }
+                }
+                if ($otherserver ne '') {
+                    my @hosts = &Apache::lonnet::current_machine_ids();
+                    if (grep(/^\Q$otherserver\E$/, at hosts)) {
+                        $hosthere = $otherserver;
+                    }
+                }
+            }
         }
-
-	if ($is_balancer) {
+	if (($is_balancer) && (!$hosthere)) {
 	    # login but immediately go to switch server to find us a new 
 	    # machine
 	    &Apache::lonauth::success($r,$user,$domain,$home,'noredirect');
@@ -384,6 +398,9 @@
                 $info{'sso.reloginserver'} = 
                     $r->dir_config('lonSSOReloginServer'); 
             }
+            if (($is_balancer) && ($hosthere)) {
+                $info{'noloadbalance'} = $hosthere;
+            }
 	    my $token = 
 		&Apache::lonnet::tmpput(\%info,
 					$r->dir_config('lonHostID'));
Index: loncom/auth/lonauth.pm
diff -u loncom/auth/lonauth.pm:1.140 loncom/auth/lonauth.pm:1.141
--- loncom/auth/lonauth.pm:1.140	Sat Apr  2 04:31:33 2016
+++ loncom/auth/lonauth.pm	Mon Dec  5 00:51:43 2016
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # User Authentication Module
 #
-# $Id: lonauth.pm,v 1.140 2016/04/02 04:31:33 raeburn Exp $
+# $Id: lonauth.pm,v 1.141 2016/12/05 00:51:43 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -249,7 +249,6 @@
 sub handler {
     my $r = shift;
     my $londocroot = $r->dir_config('lonDocRoot');
-    my $form;
 # Are we re-routing?
     if (-e "$londocroot/lon-status/reroute.txt") {
 	&reroute($r);
@@ -466,13 +465,25 @@
 
     unless ($hosthere) {
         ($is_balancer,$otherserver) =
-            &Apache::lonnet::check_loadbalancing($form{'uname'},$form{'udom'});
+            &Apache::lonnet::check_loadbalancing($form{'uname'},$form{'udom'},'login');
+        if ($is_balancer) {
+            if ($otherserver eq '') {
+                my $lowest_load;
+                ($otherserver,undef,undef,undef,$lowest_load) = &Apache::lonnet::choose_server($form{'udom'});
+                if ($lowest_load > 100) {
+                    $otherserver = &Apache::lonnet::spareserver($lowest_load,$lowest_load,1,$form{'udom'});
+                }
+            }
+            if ($otherserver ne '') {
+                my @hosts = &Apache::lonnet::current_machine_ids();
+                if (grep(/^\Q$otherserver\E$/, at hosts)) {
+                    $hosthere = $otherserver;
+                }
+            }
+        }
     }
 
-    if ($is_balancer) {
-        if (!$otherserver) { 
-            ($otherserver) = &Apache::lonnet::choose_server($form{'udom'});
-        }
+    if (($is_balancer) && (!$hosthere)) {
         if ($otherserver) {
             &success($r,$form{'uname'},$form{'udom'},$authhost,'noredirect',undef,
                      \%form);
@@ -540,6 +551,9 @@
                 return OK;
             }
         }
+        if (($is_balancer) && ($hosthere)) {
+            $form{'noloadbalance'} = $hosthere;
+        }
         &success($r,$form{'uname'},$form{'udom'},$authhost,$firsturl,undef,
                  \%form);
         return OK;
Index: loncom/auth/migrateuser.pm
diff -u loncom/auth/migrateuser.pm:1.24 loncom/auth/migrateuser.pm:1.25
--- loncom/auth/migrateuser.pm:1.24	Tue Oct  7 03:13:34 2014
+++ loncom/auth/migrateuser.pm	Mon Dec  5 00:51:43 2016
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Starts a user off based of an existing token.
 #
-# $Id: migrateuser.pm,v 1.24 2014/10/07 03:13:34 raeburn Exp $
+# $Id: migrateuser.pm,v 1.25 2016/12/05 00:51:43 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -252,6 +252,9 @@
     if ($data{'iptoken'} ne '') {
         $form{'iptoken'} = $data{'iptoken'};
     }
+    if ($data{'noloadbalance'} ne '') {
+        $form{'noloadbalance'} = $data{'noloadbalance'};
+    }
 
     if (!$data{'role'}) {
 	my $handle = &Apache::lonnet::check_for_valid_session($r);
Index: loncom/interface/domainprefs.pm
diff -u loncom/interface/domainprefs.pm:1.283 loncom/interface/domainprefs.pm:1.284
--- loncom/interface/domainprefs.pm:1.283	Tue Oct 25 12:45:33 2016
+++ loncom/interface/domainprefs.pm	Mon Dec  5 00:51:53 2016
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to set domain-wide configuration settings
 #
-# $Id: domainprefs.pm,v 1.283 2016/10/25 12:45:33 raeburn Exp $
+# $Id: domainprefs.pm,v 1.284 2016/12/05 00:51:53 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -4690,6 +4690,9 @@
         my ($numspares, at spares) = &count_servers($lonhost,%servers);
         my @sparestypes = ('primary','default');
         my %typetitles = &sparestype_titles();
+        my %hostherechecked = (
+                                  no => ' checked="checked"',
+                              );
         foreach my $sparetype (@sparestypes) {
             my $targettable;
             for (my $i=0; $i<$numspares; $i++) {
@@ -4735,6 +4738,23 @@
                 $datatable .=  '<i>'.$typetitles{$sparetype}.'</i><br />'.
                                '<table><tr>'.$targettable.'</tr></table><br />';
             }
+            $hostherechecked{$sparetype} = '';
+            if (ref($currtargets{$lonhost}) eq 'HASH') {
+                if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
+                    if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
+                        $hostherechecked{$sparetype} = ' checked="checked"';
+                        $hostherechecked{'no'} = '';
+                    }
+                }
+            }
+        }
+        $datatable .= &mt('Hosting on balancer itself').'<br />'.
+                      '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
+                      $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
+        foreach my $sparetype (@sparestypes) {
+            $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
+                          'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
+                          '</i></label><br />';
         }
         $datatable .= '</div></td></tr>'.
                       &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
@@ -13194,8 +13214,13 @@
                         push(@offloadto,$target);
                     }
                 }
-                $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
             }
+            if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
+                unless(grep(/^\Q$balancer\E$/, at offloadto)) {
+                    push(@offloadto,$balancer);
+                }
+            }
+            $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
         }
         if (ref($currtargets{$balancer}) eq 'HASH') {
             foreach my $sparetype (@sparestypes) {
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.1330 loncom/lonnet/perl/lonnet.pm:1.1331
--- loncom/lonnet/perl/lonnet.pm:1.1330	Tue Nov 15 20:46:35 2016
+++ loncom/lonnet/perl/lonnet.pm	Mon Dec  5 00:52:02 2016
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.1330 2016/11/15 20:46:35 raeburn Exp $
+# $Id: lonnet.pm,v 1.1331 2016/12/05 00:52:02 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1049,7 +1049,7 @@
     if ($login_host ne '') {
         $hostname = &hostname($login_host);
     }
-    return ($login_host,$hostname,$portal_path,$isredirect);
+    return ($login_host,$hostname,$portal_path,$isredirect,$lowest_load);
 }
 
 # --------------------------------------------- Try to change a user's password
@@ -1321,7 +1321,7 @@
 }
 
 sub check_loadbalancing {
-    my ($uname,$udom) = @_;
+    my ($uname,$udom,$caller) = @_;
     my ($is_balancer,$currtargets,$currrules,$dom_in_use,$homeintdom,
         $rule_in_effect,$offloadto,$otherserver);
     my $lonhost = $perlvar{'lonHostID'};
@@ -1472,13 +1472,15 @@
                 }
             }
         }
-        if (($otherserver ne '') && (grep(/^\Q$otherserver\E$/, at hosts))) {
-            $is_balancer = 0;
-            if ($uname ne '' && $udom ne '') {
-                if (($env{'user.name'} eq $uname) && ($env{'user.domain'} eq $udom)) {
+        unless ($caller eq 'login') {
+            if (($otherserver ne '') && (grep(/^\Q$otherserver\E$/, at hosts))) {
+                $is_balancer = 0;
+                if ($uname ne '' && $udom ne '') {
+                    if (($env{'user.name'} eq $uname) && ($env{'user.domain'} eq $udom)) {
                     
-                    &appenv({'user.loadbalexempt'     => $lonhost,  
-                             'user.loadbalcheck.time' => time});
+                        &appenv({'user.loadbalexempt'     => $lonhost,  
+                                 'user.loadbalcheck.time' => time});
+                    }
                 }
             }
         }


More information about the LON-CAPA-cvs mailing list