[LON-CAPA-cvs] cvs: loncom /auth lonauth.pm lonlogin.pm /lonnet/perl lonnet.pm
raeburn
raeburn@source.lon-capa.org
Wed, 25 Aug 2010 16:34:36 -0000
raeburn Wed Aug 25 16:34:36 2010 EDT
Modified files:
/loncom/auth lonlogin.pm lonauth.pm
/loncom/lonnet/perl lonnet.pm
Log:
- Offloading from a busy server delayed until after authentication so
user's domain is available when determining which less loaded server
will host (check that hosting is allowed).
Index: loncom/auth/lonlogin.pm
diff -u loncom/auth/lonlogin.pm:1.139 loncom/auth/lonlogin.pm:1.140
--- loncom/auth/lonlogin.pm:1.139 Sun Aug 22 21:51:11 2010
+++ loncom/auth/lonlogin.pm Wed Aug 25 16:34:32 2010
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Login Screen
#
-# $Id: lonlogin.pm,v 1.139 2010/08/22 21:51:11 raeburn Exp $
+# $Id: lonlogin.pm,v 1.140 2010/08/25 16:34:32 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -152,16 +152,8 @@
my $loadpercent=sprintf("%.1f",100*$loadavg/$loadlim);
my $userloadpercent=&Apache::lonnet::userload();
-# ------------------------------------------------------- Do the load balancing
- my $otherserver= &Apache::lonnet::absolute_url($host_name);
my $firsturl=
($env{'request.firsturl'}?$env{'request.firsturl'}:$env{'form.firsturl'});
-# ---------------------------------------------------------- Are we overloaded?
- if ((($userloadpercent>100.0)||($loadpercent>100.0))) {
- my $unloaded=Apache::lonnet::spareserver($loadpercent,$userloadpercent);
- if ($unloaded) { $otherserver=$unloaded; }
- }
-
# ----------------------------------------------------------- Get announcements
my $announcements=&Apache::lonnet::getannounce();
# -------------------------------------------------------- Set login parameters
@@ -384,7 +376,7 @@
#
$r->print(<<ENDSERVERFORM);
-<form name="server" action="$otherserver/adm/authenticate" method="post" target="_top">
+<form name="server" action="/adm/authenticate" method="post" target="_top">
<input type="hidden" name="logtoken" value="$logtoken" />
<input type="hidden" name="serverid" value="$lonhost" />
<input type="hidden" name="uname" value="" />
Index: loncom/auth/lonauth.pm
diff -u loncom/auth/lonauth.pm:1.108 loncom/auth/lonauth.pm:1.109
--- loncom/auth/lonauth.pm:1.108 Wed Aug 18 19:25:12 2010
+++ loncom/auth/lonauth.pm Wed Aug 25 16:34:32 2010
@@ -1,7 +1,7 @@
# The LearningOnline Network
# User Authentication Module
#
-# $Id: lonauth.pm,v 1.108 2010/08/18 19:25:12 raeburn Exp $
+# $Id: lonauth.pm,v 1.109 2010/08/25 16:34:32 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -40,6 +40,7 @@
use Apache::createaccount;
use Fcntl qw(:flock);
use Apache::lonlocal;
+use Apache::File ();
use HTML::Entities;
# ------------------------------------------------------------ Successful login
@@ -409,10 +410,32 @@
&success($r,$form{'uname'},$form{'udom'},$authhost,'noredirect',undef,
\%form);
my ($otherserver) = &Apache::lonnet::choose_server($form{'udom'});
- $r->internal_redirect('/adm/switchserver?otherserver='.$otherserver);
+ $r->internal_redirect('/adm/switchserver?otherserver='.$otherserver.'&origurl='.$firsturl);
} else {
- &success($r,$form{'uname'},$form{'udom'},$authhost,$firsturl,undef,
- \%form);
+# ------------------------------------------------------- Do the load balancing
+
+# ---------------------------------------------------------- Determine own load
+ my $loadlim = $r->dir_config('lonLoadLim');
+ my $loadavg;
+ {
+ my $loadfile=Apache::File->new('/proc/loadavg');
+ $loadavg=<$loadfile>;
+ }
+ $loadavg =~ s/\s.*//g;
+ my $loadpercent=sprintf("%.1f",100*$loadavg/$loadlim);
+ my $userloadpercent=&Apache::lonnet::userload();
+
+# ---------------------------------------------------------- Are we overloaded?
+ if ((($userloadpercent>100.0)||($loadpercent>100.0))) {
+ my $unloaded=Apache::lonnet::spareserver($loadpercent,$userloadpercent,1,$form{'udom'});
+ if ($unloaded) {
+ &success($r,$form{'uname'},$form{'udom'},$authhost,'noredirect',
+ undef,\%form);
+ $r->internal_redirect('/adm/switchserver?otherserver='.$unloaded.'&origurl='.$firsturl);
+ }
+ }
+ &success($r,$form{'uname'},$form{'udom'},$authhost,$firsturl,undef,
+ \%form);
}
return OK;
}
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.1082 loncom/lonnet/perl/lonnet.pm:1.1083
--- loncom/lonnet/perl/lonnet.pm:1.1082 Fri Aug 20 18:17:04 2010
+++ loncom/lonnet/perl/lonnet.pm Wed Aug 25 16:34:36 2010
@@ -1,7 +1,7 @@
# The LearningOnline Network
# TCP networking package
#
-# $Id: lonnet.pm,v 1.1082 2010/08/20 18:17:04 raeburn Exp $
+# $Id: lonnet.pm,v 1.1083 2010/08/25 16:34:36 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -727,13 +727,23 @@
# ------------------------------ Find server with least workload from spare.tab
sub spareserver {
- my ($loadpercent,$userloadpercent,$want_server_name) = @_;
+ my ($loadpercent,$userloadpercent,$want_server_name,$udom) = @_;
my $spare_server;
if ($userloadpercent !~ /\d/) { $userloadpercent=0; }
my $lowest_load=($loadpercent > $userloadpercent) ? $loadpercent
: $userloadpercent;
-
+ my ($uint_dom,$remotesessions);
+ if (($udom ne '') && (&domain($udom) ne '')) {
+ my $uprimary_id = &Apache::lonnet::domain($udom,'primary');
+ $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
+ my %udomdefaults = &Apache::lonnet::get_domain_defaults($udom);
+ $remotesessions = $udomdefaults{'remotesessions'};
+ }
foreach my $try_server (@{ $spareid{'primary'} }) {
+ if ($uint_dom) {
+ next unless (&spare_can_host($udom,$uint_dom,$remotesessions,
+ $try_server));
+ }
($spare_server, $lowest_load) =
&compare_server_load($try_server, $spare_server, $lowest_load);
}
@@ -742,6 +752,10 @@
if (!$found_server) {
foreach my $try_server (@{ $spareid{'default'} }) {
+ if ($uint_dom) {
+ next unless (&spare_can_host($udom,$uint_dom,$remotesessions,
+ $try_server));
+ }
($spare_server, $lowest_load) =
&compare_server_load($try_server, $spare_server, $lowest_load);
}
@@ -754,7 +768,7 @@
}
if (defined($spare_server)) {
my $hostname = &hostname($spare_server);
- if (defined($hostname)) {
+ if (defined($hostname)) {
$spare_server = $protocol.'://'.$hostname;
}
}
@@ -990,6 +1004,26 @@
return $canhost;
}
+sub spare_can_host {
+ my ($udom,$uint_dom,$remotesessions,$try_server)=@_;
+ my $canhost=1;
+ my @intdoms;
+ my $internet_names = &Apache::lonnet::get_internet_names($try_server);
+ if (ref($internet_names) eq 'ARRAY') {
+ @intdoms = @{$internet_names};
+ }
+ unless (grep(/^\Q$uint_dom\E$/,@intdoms)) {
+ my $serverhomeID = &Apache::lonnet::get_server_homeID($try_server);
+ my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
+ my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
+ my $remoterev = &Apache::lonnet::get_server_loncaparev(undef,$try_server);
+ $canhost = &can_host_session($udom,$try_server,$remoterev,
+ $remotesessions,
+ $defdomdefaults{'hostedsessions'});
+ }
+ return $canhost;
+}
+
# ---------------------- Find the homebase for a user from domain's lib servers
my %homecache;