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

raeburn raeburn@source.lon-capa.org
Sat, 24 Jul 2010 17:42:52 -0000


raeburn		Sat Jul 24 17:42:52 2010 EDT

  Modified files:              
    /loncom/auth	lonauth.pm 
    /loncom/lonnet/perl	lonnet.pm 
  Log:
   &choose_server() moved from lonauth.pm to lonnet.pm to facilitate reuse.
  
  
Index: loncom/auth/lonauth.pm
diff -u loncom/auth/lonauth.pm:1.106 loncom/auth/lonauth.pm:1.107
--- loncom/auth/lonauth.pm:1.106	Tue Jul 20 02:42:33 2010
+++ loncom/auth/lonauth.pm	Sat Jul 24 17:42:46 2010
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # User Authentication Module
 #
-# $Id: lonauth.pm,v 1.106 2010/07/20 02:42:33 raeburn Exp $
+# $Id: lonauth.pm,v 1.107 2010/07/24 17:42:46 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -408,7 +408,7 @@
     if ($r->dir_config("lonBalancer") eq 'yes') {
 	&success($r,$form{'uname'},$form{'udom'},$authhost,'noredirect',undef,
 		 \%form);
-        my ($otherserver) = &choose_server($form{'udom'});
+        my ($otherserver) = &Apache::lonnet::choose_server($form{'udom'});
 	$r->internal_redirect('/adm/switchserver?otherserver='.$otherserver);
     } else {
 	&success($r,$form{'uname'},$form{'udom'},$authhost,$firsturl,undef,
@@ -445,7 +445,7 @@
     }
     unless ($canhost) {
         if ($authhost eq 'no_account_on_host') {
-            my ($login_host,$hostname) = &choose_server($udom);
+            my ($login_host,$hostname) = &Apache::lonnet::choose_server($udom);
             &Apache::loncommon::content_type($r,'text/html');
             $r->send_http_header;
             if ($login_host ne '') {
@@ -469,31 +469,12 @@
         } else {
             &success($r,$form->{'uname'},$udom,$authhost,'noredirect',undef,
                      $form);
-            my ($otherserver) = &choose_server($udom);
+            my ($otherserver) = &Apache::lonnet::choose_server($udom);
             $r->internal_redirect('/adm/switchserver?otherserver='.$otherserver);
         }
     }
 }
 
-sub choose_server {
-    my ($udom) = @_;
-    my %domconfhash = &Apache::loncommon::get_domainconf($udom);
-    my %servers = &Apache::lonnet::get_servers($udom);
-    my $lowest_load = 30000;
-    my ($login_host,$hostname);
-    foreach my $lonhost (keys(%servers)) {
-        my $loginvia = $domconfhash{$udom.'.login.loginvia_'.$lonhost};
-        if ($loginvia eq '') {
-            ($login_host, $lowest_load) =
-            &Apache::lonnet::compare_server_load($lonhost, $login_host, $lowest_load);
-        }
-    }
-    if ($login_host ne '') {
-        $hostname = $servers{$login_host};
-    }
-    return ($login_host,$hostname);
-}
-
 1;
 __END__
 
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.1075 loncom/lonnet/perl/lonnet.pm:1.1076
--- loncom/lonnet/perl/lonnet.pm:1.1075	Fri Jul 23 14:59:24 2010
+++ loncom/lonnet/perl/lonnet.pm	Sat Jul 24 17:42:51 2010
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.1075 2010/07/23 14:59:24 raeburn Exp $
+# $Id: lonnet.pm,v 1.1076 2010/07/24 17:42:51 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -812,6 +812,27 @@
     return 0;
 }
 
+# --------- determine least loaded server in a user's domain which allows login
+
+sub choose_server {
+    my ($udom) = @_;
+    my %domconfhash = &Apache::loncommon::get_domainconf($udom);
+    my %servers = &servers($udom);
+    my $lowest_load = 30000;
+    my ($login_host,$hostname);
+    foreach my $lonhost (keys(%servers)) {
+        my $loginvia = $domconfhash{$udom.'.login.loginvia_'.$lonhost};
+        if ($loginvia eq '') {
+            ($login_host, $lowest_load) =
+            &compare_server_load($lonhost, $login_host, $lowest_load);
+        }
+    }
+    if ($login_host ne '') {
+        $hostname = $servers{$login_host};
+    }
+    return ($login_host,$hostname);
+}
+
 # --------------------------------------------- Try to change a user's password
 
 sub changepass {