[LON-CAPA-cvs] cvs: loncom /configuration Configuration.pm

foxr lon-capa-cvs@mail.lon-capa.org
Wed, 09 Apr 2003 00:52:37 -0000


foxr		Tue Apr  8 20:52:37 2003 EDT

  Modified files:              
    /loncom/configuration	Configuration.pm 
  Log:
  Added ability to parse the hosts.tab file including added stuff for the
  adaptively connecting lonc.  See sub read_hosts(file).  Returns a 
  reference to a hash that is stocked with references to arrays containing
  the configuration parameters for each host... question for all?
  Should the hash contain references to hashes so the parameters can be 
  looked up by name rather than array index? What's preferred?
  
  
  
Index: loncom/configuration/Configuration.pm
diff -u loncom/configuration/Configuration.pm:1.8 loncom/configuration/Configuration.pm:1.9
--- loncom/configuration/Configuration.pm:1.8	Mon Feb  3 13:03:52 2003
+++ loncom/configuration/Configuration.pm	Tue Apr  8 20:52:37 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Configuration file reader
 #
-# $Id: Configuration.pm,v 1.8 2003/02/03 18:03:52 harris41 Exp $
+# $Id: Configuration.pm,v 1.9 2003/04/09 00:52:37 foxr Exp $
 #
 #
 # Copyright Michigan State University Board of Trustees
@@ -34,7 +34,7 @@
 
 package LONCAPA::Configuration;
 
-$VERSION = sprintf("%d.%02d", q$Revision: 1.8 $ =~ /(\d+)\.(\d+)/);
+$VERSION = sprintf("%d.%02d", q$Revision: 1.9 $ =~ /(\d+)\.(\d+)/);
 
 use strict;
 
@@ -66,6 +66,41 @@
     return ($perlvarref);
   }
 
+#---------------------- Subroutine read_hosts: Read a LON-CAPA hosts.tab
+# formatted configuration file.
+#
+my $RequiredCount = 5;		# Required item count in hosts.tab.
+my $DefaultMaxCon = 5;		# Default value for maximum connections.
+my $DefaultIdle   = 1000;       # Default connection idle time in seconds.
+my $DefaultMinCon = 0;          # Default value for minimum connections.
+sub read_hosts {
+    my $Filename = shift;
+    my %HostsTab;
+    
+    open(CONFIG,'<'.$Filename) or die("Can't read $Filename");
+    while (my $line = <CONFIG>) {
+	my @items = split(/:/, $line);
+	if (scalar @items == $RequiredCount) {	# Have only all required items:
+	    $items[$RequiredCount] = $DefaultMaxCon;
+	}
+	if(scalar @items == $RequiredCount + 1) { # Have up through maxcon.
+	    $items[$RequiredCount+1] = $DefaultIdle;
+	}
+	if(scalar @items == $RequiredCount + 2) { # Have up through idle.
+	    $items[$RequiredCount+2] = $DefaultMinCon;
+	}
+	{
+	    my @list = @items;	# probably not needed but I'm unsure of 
+				# about the scope of item so...
+	    $HostsTab{@list[0]} = \@list; 
+	}
+    }
+    close(CONFIG);
+    my $hostref = \%HostsTab;
+    return ($hostref);
+}
+
+1;
 __END__
 
 =pod
@@ -80,10 +115,11 @@
  use LONCAPA::Configuration;
 
  LONCAPA::Configuration::read_conf('loncapa.conf');
+ LONCAPA::Configuration::read_hosts(filename);
 
 =head1 DESCRIPTION
 
-Many different parts of the LON-CAPA software need to read in the
+Many different parts of the LON-CAPA software need to reads in the
 machine-specific configuration information.  These included scripts
 controlling the TCP/IP layer (e.g. F<lonc> and F<lond>), testing scripts
 (e.g. test_weblayer.pl and sqltest.pl), and utility scripts
@@ -109,6 +145,46 @@
 given toward the B<last> file name processed.
 
 =back
+
+=over 4
+=item $hostinfo = LONCAPA::Configuration::read_hosts(filename);
+
+  The parameter is the name of a file in hosts.tab form.  The file is read and
+parsed.  The return value is a reference to a hash.   The hash is indexed by
+host and each element of the has is in turn a reference to an anonymous list
+containing:
+
+=over 4
+=item host
+   The loncapa hostname of the system. (This may be different than the 
+   network hostname, see below).
+=item domain
+   The loncapa domain in which the host lives.
+=item role
+    The role of the system, currently allowed values are access for an
+    access server and library for a library server.
+=item dns
+    The DNS hostname of the system. 
+=item ip
+    The IP address corresponding to the dns hostname of the system.
+=item maxconn 
+    The maximum number of connections this system should hold to the
+    target system's lond.  If the file has no value, a default is supplied
+    here by the function.
+=item idle
+    The number of seconds the oldest idle connection can be idle before it
+    should be adaptively dropped.  If the file has no value, a default
+    is supplied by the function.
+=item mincon
+    The minimum number of connections this system should hold to the
+    target system's lond.  If the file has no value, a default is supplied by
+    the funciton.
+
+=back
+
+=back
+
+
 
 =head1 AUTHORS