[LON-CAPA-cvs] cvs: loncom / LondConnection.pm loncnew lond /lonnet/perl lonnet.pm

albertel lon-capa-cvs@mail.lon-capa.org
Wed, 28 Mar 2007 20:28:32 -0000


This is a MIME encoded message

--albertel1175113712
Content-Type: text/plain

albertel		Wed Mar 28 16:28:32 2007 EDT

  Modified files:              
    /loncom	loncnew lond LondConnection.pm 
    /loncom/lonnet/perl	lonnet.pm 
  Log:
  - eliminate any reading of hosts.tab from loncnew
  - launch of lonc connection requires passing the lonid through the common
    launch socket
  - dealyed messages getting sent again (requires loncnew using lonnet....)
  
  
--albertel1175113712
Content-Type: text/plain
Content-Disposition: attachment; filename="albertel-20070328162832.txt"

Index: loncom/loncnew
diff -u loncom/loncnew:1.80 loncom/loncnew:1.81
--- loncom/loncnew:1.80	Tue Mar 27 20:23:46 2007
+++ loncom/loncnew	Wed Mar 28 16:28:29 2007
@@ -2,7 +2,7 @@
 # The LearningOnline Network with CAPA
 # lonc maintains the connections to remote computers
 #
-# $Id: loncnew,v 1.80 2007/03/28 00:23:46 albertel Exp $
+# $Id: loncnew,v 1.81 2007/03/28 20:28:29 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -60,7 +60,6 @@
 use LONCAPA::LondConnection;
 use LONCAPA::LondTransaction;
 use LONCAPA::Configuration;
-use LONCAPA::HashIterator;
 use Fcntl qw(:flock);
 
 
@@ -94,6 +93,7 @@
 #  The variables below are only used by the child processes.
 #
 my $RemoteHost;			# Name of host child is talking to.
+my $RemoteHostId;		# default lonid of host child is talking to.
 my $UnixSocketDir= $perlvar{'lonSockDir'};
 my $IdleConnections = Stack->new(); # Set of idle connections
 my %ActiveConnections;		# Connections to the remote lond.
@@ -112,7 +112,6 @@
 
 
 
-my $hosts_tab       = 0;        # True if we are using a static hosts.tab
 my $I_am_child      = 0;	# True if this is the child process.
 
 #
@@ -333,9 +332,7 @@
     open(LOCK,">$lock_file");
     print LOCK "Contents not important";
     close(LOCK);
-    if ($hosts_tab) {
-	unlink(&GetLoncSocketPath());
-    }
+    unlink(&GetLoncSocketPath());
 
     if ($message) {
 	die($message);
@@ -1150,10 +1147,12 @@
     }
     
 }
+
 =pod
     
 =cut
 
+
 sub QueueDelayed {
     Debug(3,"QueueDelayed called");
 
@@ -1162,15 +1161,9 @@
     Debug(4, "Delayed path: ".$path);
     opendir(DIRHANDLE, $path);
 
-    my @all_host_ids;
-    my $host_iterator =   &LondConnection::GetHostIterator();
-    while (!$host_iterator->end()) {
-	my ($host_id,$host_name) = @{$host_iterator->get()}[0,3];
-	if ($host_name eq $RemoteHost) {
-	    push(@all_host_ids, $host_id);
-	}
-	$host_iterator->next();
-    }
+    use Apache::lonnet;
+    my @all_host_ids = &Apache::lonnet::machine_ids($RemoteHost);
+
     my $host_id_re = '(?:'.join('|',@all_host_ids).')';
     my @alldelayed = grep(/\.$host_id_re$/, readdir(DIRHANDLE));
     closedir(DIRHANDLE);
@@ -1206,7 +1199,8 @@
 	  .GetServerPort());
 
     my $Connection = LondConnection->new(&GetServerHost(),
-					 &GetServerPort());
+					 &GetServerPort(),
+					 &GetHostId());
 
     if($Connection eq undef) {	# Needs to be more robust later.
 	Log("CRITICAL","Failed to make a connection with lond.");
@@ -1496,6 +1490,18 @@
 
 =pod
 
+=head2 GetServerId
+
+Returns the hostid whose lond we talk with.
+
+=cut
+
+sub GetHostId {
+    return $RemoteHostId;		# Setup by the fork.
+}
+
+=pod
+
 =head2 GetServerPort
 
 Returns the lond port number.
@@ -1749,7 +1755,7 @@
 #  Create a new child for host passed in:
 
 sub CreateChild {
-    my ($host, $socket) = @_;
+    my ($host, $hostid) = @_;
 
     my $sigset = POSIX::SigSet->new(SIGINT);
     sigprocmask(SIG_BLOCK, $sigset);
@@ -1762,14 +1768,11 @@
 	sigprocmask(SIG_UNBLOCK, $sigset);
 
     } else {			# child.
+	$RemoteHostId = $hostid;
 	ShowStatus("Connected to ".$RemoteHost);
 	$SIG{INT} = 'DEFAULT';
 	sigprocmask(SIG_UNBLOCK, $sigset);
-	if(defined $socket) {
-	    &ChildProcess($socket);
-	} else {
-	    ChildProcess;		# Does not return.
-	}
+	&ChildProcess();		# Does not return.
     }
 }
 
@@ -1797,33 +1800,11 @@
 	my ($event)   = @_;
 	my $watcher   = $event->w;
 	my $socket    = $watcher->fd;
-	if ($hosts_tab) {
-	
-	    # Lookup the host associated with this socket:
-
-	    my $host = $listening_to{$socket};
-	
-	    # Start the child:
-
-
-
-	    &Debug(9,"Creating child for $host (parent_client_connection)");
-	    &CreateChild($host, $socket);
-	    	
-	    # Clean up the listen since now the child takes over until it exits.
-	
-	    $watcher->cancel();		# Nolonger listening to this event
-	    delete($listening_to{$socket});
-	    delete($parent_dispatchers{$host});
-	    $socket->close();
-
-	} else {
-	    my $connection = $socket->accept();	# Accept the client connection.
-	    Event->io(cb      => \&get_remote_hostname,
-		      poll    => 'r',
-		      data    => "",
-		      fd      => $connection);
-	}
+	my $connection = $socket->accept();	# Accept the client connection.
+	Event->io(cb      => \&get_remote_hostname,
+		  poll    => 'r',
+		  data    => "",
+		  fd      => $connection);
     }
 }
 
@@ -1852,7 +1833,8 @@
 	}
 	
 	&Debug(5,"Creating child for $data (parent_client_connection)");
-	&CreateChild($data);
+	my ($hostname,$lonid) = split(':',$data,2);
+	&CreateChild($hostname,$lonid);
 	
 	# Clean up the listen since now the child takes over until it exits.
 	$watcher->cancel();		# Nolonger listening to this event
@@ -1973,12 +1955,8 @@
 	if($host) {		# It's for real...
 	    &Debug(9, "Caught sigchild for $host");
 	    delete($ChildHash{$pid});
-	    if ($hosts_tab) {
-		&parent_listen($host);
-	    } else {
-		&parent_clean_up($host);
-	    }
-	    
+	    &parent_clean_up($host);
+
 	} else {
 	    &Debug(5, "Caught sigchild for pid not in hosts hash: $pid");
 	}
@@ -2036,11 +2014,7 @@
 LondConnection::ReadConfig;               # Read standard config files.
 
 $RemoteHost = "[parent]";
-if ($hosts_tab) {
-    &listen_on_all_unix_sockets();
-} else {
-    &listen_on_common_socket();
-}
+&listen_on_common_socket();
 
 $RemoteHost = "Parent Server";
 
@@ -2065,15 +2039,9 @@
 $parent_handlers{TERM} = Event->signal(cb       => \&Terminate,
 				       desc     => "Parent TERM handler",
 				       signal   => "TERM");
-if ($hosts_tab) {
-    $parent_handlers{HUP}  = Event->signal(cb       => \&Restart,
-					   desc     => "Parent HUP handler.",
-					   signal   => "HUP");
-} else {
-    $parent_handlers{HUP}  = Event->signal(cb       => \&KillThemAll,
-					   desc     => "Parent HUP handler.",
-					   signal   => "HUP");
-}
+$parent_handlers{HUP}  = Event->signal(cb       => \&KillThemAll,
+				       desc     => "Parent HUP handler.",
+				       signal   => "HUP");
 $parent_handlers{USR1} = Event->signal(cb       => \&CheckKids,
 				       desc     => "Parent USR1 handler",
 				       signal   => "USR1");
@@ -2154,11 +2122,7 @@
     # The down side is transactions that are in flight will get timed out
     # (lost unless they are critical).
 
-    if ($hosts_tab) {
-	&Restart();
-    } else {
-	&KillThemAll();
-    }
+    &KillThemAll();
 }
 
 
@@ -2242,6 +2206,14 @@
     exit 0;
 
 }
+
+sub my_hostname {
+    use Sys::Hostname;
+    my $name = &hostname();
+    &Debug(9,"Name is $name");
+    return $name;
+}
+
 =pod
 
 =head1 Theory
Index: loncom/lond
diff -u loncom/lond:1.363 loncom/lond:1.364
--- loncom/lond:1.363	Tue Mar 27 20:05:38 2007
+++ loncom/lond	Wed Mar 28 16:28:29 2007
@@ -2,7 +2,7 @@
 # The LearningOnline Network
 # lond "LON Daemon" Server (port "LOND" 5663)
 #
-# $Id: lond,v 1.363 2007/03/28 00:05:38 albertel Exp $
+# $Id: lond,v 1.364 2007/03/28 20:28:29 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -59,7 +59,7 @@
 my $status='';
 my $lastlog='';
 
-my $VERSION='$Revision: 1.363 $'; #' stupid emacs
+my $VERSION='$Revision: 1.364 $'; #' stupid emacs
 my $remoteVERSION;
 my $currenthostid="default";
 my $currentdomainid;
@@ -5310,12 +5310,12 @@
 }
 
 sub create_connection {
-    my ($server) = @_;
+    my ($hostname,$lonid) = @_;
     my $client=IO::Socket::UNIX->new(Peer    => $perlvar{'lonSockCreate'},
 				     Type    => SOCK_STREAM,
 				     Timeout => 10);
     return 0 if (!$client);
-    print $client ("$server\n");
+    print $client ("$hostname:$lonid\n");
     my $result = <$client>;
     chomp($result);
     return 1 if ($result eq 'done');
@@ -5335,7 +5335,7 @@
 	if($sclient) {
 	    last;		# Connected!
 	} else {
-	    &create_connection($hostname{$server});
+	    &create_connection($hostname{$server},$server);
 	}
         sleep(1);		# Try again later if failed connection.
     }
Index: loncom/LondConnection.pm
diff -u loncom/LondConnection.pm:1.43 loncom/LondConnection.pm:1.44
--- loncom/LondConnection.pm:1.43	Fri Sep 15 16:49:24 2006
+++ loncom/LondConnection.pm	Wed Mar 28 16:28:29 2007
@@ -1,7 +1,7 @@
 #   This module defines and implements a class that represents
 #   a connection to a lond daemon.
 #
-# $Id: LondConnection.pm,v 1.43 2006/09/15 20:49:24 raeburn Exp $
+# $Id: LondConnection.pm,v 1.44 2007/03/28 20:28:29 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -43,9 +43,7 @@
 
 
 my $DebugLevel=0;
-my %hostshash;
 my %perlvar;
-my $LocalDns = "";		# Need not be defined for managers.
 my $InsecureOk;
 
 #
@@ -71,67 +69,9 @@
 
     my $perlvarref = read_conf('loncapa.conf');
     %perlvar    = %{$perlvarref};
-    my $hoststab   = read_hosts(
-				"$perlvar{lonTabDir}/hosts.tab") || 
-				die "Can't read host table!!";
-    %hostshash  = %{$hoststab};
     $ConfigRead = 1;
     
-    my $myLonCapaName = $perlvar{lonHostID};
-    Debug(8, "My loncapa name is $myLonCapaName");
-    
-    if(defined $hostshash{$myLonCapaName}) {
-	Debug(8, "My loncapa name is in hosthash");
-	my @ConfigLine = @{$hostshash{$myLonCapaName}};
-	$LocalDns = $ConfigLine[3];
-	Debug(8, "Got local name $LocalDns");
-    }
     $InsecureOk = $perlvar{loncAllowInsecure};
-    
-    Debug(3, "ReadConfig - LocalDNS = $LocalDns");
-}
-
-#
-#  Read a foreign configuration.
-#  This sub is intended for the cases where the package
-#  will be read from outside the LonCAPA environment, in that case
-#  the client will need to explicitly provide:
-#   - A file in hosts.tab format.
-#   - Some idea of the 'lonCAPA' name of the local host (for building
-#     the encryption key).
-#
-#  Parameters:
-#      MyHost   - Name of this host as far as LonCAPA is concerned.
-#      Filename - Name of a hosts.tab formatted file that will be used
-#                 to build up the hosts table.
-#
-sub ReadForeignConfig {
-
-    my ($MyHost, $Filename) = @_;
-
-    &Debug(4, "ReadForeignConfig $MyHost $Filename\n");
-
-    $perlvar{lonHostID} = $MyHost; # Rmember my host.
-    my $hosttab = read_hosts($Filename) ||
-	die "Can't read hosts table!!";
-    %hostshash = %{$hosttab};
-    if($DebugLevel > 3) {
-	foreach my $host (keys %hostshash) {
-	    print STDERR "host $host => $hostshash{$host}\n";
-	}
-    }
-    $ConfigRead = 1;
-
-    my $myLonCapaName = $perlvar{lonHostID};
-    
-    if(defined $hostshash{$myLonCapaName}) {
-	my @ConfigLine = @{$hostshash{$myLonCapaName}};
-	$LocalDns = $ConfigLine[3];
-    }
-    $InsecureOk = $perlvar{loncAllowInsecure};
-    
-    Debug(3, "ReadForeignConfig  - LocalDNS = $LocalDns");
-
 }
 
 sub Debug {
@@ -213,7 +153,7 @@
 =cut
 
 sub new {
-    my ($class, $DnsName, $Port) = @_;
+    my ($class, $DnsName, $Port, $lonid) = @_;
 
     if (!$ConfigRead) {
 	ReadConfig();
@@ -227,19 +167,12 @@
     #  negotion.  In the objec these become the Host and
     #  LoncapaHim fields of the object respectively.
     #
-    if (!exists $hostshash{$DnsName}) {
-	&Debug(8, "No Such host $DnsName");
-	return undef;		# No such host!!!
-    }
-    my @ConfigLine = @{$hostshash{$DnsName}};
-    my $Hostname    = $ConfigLine[0]; # 0'th item is the msu id of host.
-    Debug(5, "Connecting to ".$DnsName);
     # if it is me use loopback for connection
-    if ($DnsName eq $LocalDns) { $DnsName="127.0.0.1"; }
-    Debug(8, "Connecting to $DnsName I am $LocalDns");
+    if ($DnsName eq &main::my_hostname()) { $DnsName="127.0.0.1"; }
+    Debug(9, "Connecting to $DnsName");
     # Now create the object...
     my $self     = { Host               => $DnsName,
-                     LoncapaHim         => $Hostname,
+                     LoncapaHim         => $lonid,
                      Port               => $Port,
                      State              => "Initialized",
 		     AuthenticationMode => "",
@@ -251,7 +184,7 @@
                      TimeoutCallback    => undef,
                      TransitionCallback => undef,
                      Timeoutable        => 0,
-                     TimeoutValue       => 30,
+                     TimeoutValue       => 3,
                      TimeoutRemaining   => 0,
 		     LocalKeyFile       => "",
                      CipherKey          => "",
@@ -1136,31 +1069,6 @@
     }
 }
 
-=pod
-
-=head2 GetHostIterator
-
-Returns a hash iterator to the host information.  Each get from 
-this iterator returns a reference to an array that contains 
-information read from the hosts configuration file.  Array elements
-are used as follows:
-
- [0]   - LonCapa host id.
- [1]   - LonCapa domain name.
- [2]   - Loncapa role (e.g. library or access).
- [3]   - DNS name server hostname.
- [4]   - IP address (result of e.g. nslookup [3]).
- [5]   - Maximum connection count.
- [6]   - Idle timeout for reducing connection count.
- [7]   - Minimum connection count.
-
-=cut
-
-sub GetHostIterator {
-
-    return HashIterator->new(\%hostshash);    
-}
-
 ###########################################################
 #
 #  The following is an unashamed kludge that is here to
@@ -1217,45 +1125,6 @@
     return $perlvarref;
 }
 
-#---------------------- Subroutine read_hosts: Read a LON-CAPA hosts.tab
-# formatted configuration file.
-#
-my $RequiredCount = 4;		# 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>) {
-	if ($line !~ /^\s*\#/) {
-	    $line=~s/\s*$//;
-	    my @items = split(/:/, $line);
-	    if(scalar @items >= $RequiredCount) {
-		if (scalar @items == $RequiredCount) { # Only required items:
-		    $items[$RequiredCount] = $DefaultMaxCon;
-		}
-		if(scalar @items == $RequiredCount + 1) { # up through maxcon.
-		    $items[$RequiredCount+1] = $DefaultIdle;
-		}
-		if(scalar @items == $RequiredCount + 2) { # 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[3]} = \@list; 
-		}
-	    }
-	}
-    }
-    close(CONFIG);
-    my $hostref = \%HostsTab;
-    return ($hostref);
-}
 #
 #   Get the version of our peer.  Note that this is only well
 #   defined if the state machine has hit the idle state at least
@@ -1461,8 +1330,4 @@
 
 true if the current state requires timeout support.
 
-=item GetHostIterator:
-
-Returns an iterator into the host file hash.
-
 =cut
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.852 loncom/lonnet/perl/lonnet.pm:1.853
--- loncom/lonnet/perl/lonnet.pm:1.852	Tue Mar 27 20:12:58 2007
+++ loncom/lonnet/perl/lonnet.pm	Wed Mar 28 16:28:31 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.852 2007/03/28 00:12:58 albertel Exp $
+# $Id: lonnet.pm,v 1.853 2007/03/28 20:28:31 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -145,12 +145,12 @@
 }
 
 sub create_connection {
-    my ($server) = @_;
+    my ($hostname,$lonid) = @_;
     my $client=IO::Socket::UNIX->new(Peer    => $perlvar{'lonSockCreate'},
 				     Type    => SOCK_STREAM,
 				     Timeout => 10);
     return 0 if (!$client);
-    print $client ("$server\n");
+    print $client ("$hostname:$lonid\n");
     my $result = <$client>;
     chomp($result);
     return 1 if ($result eq 'done');
@@ -185,7 +185,7 @@
 	if($client) {
 	    last;		# Connected!
 	} else {
-	    &create_connection(&hostname($server));
+	    &create_connection(&hostname($server),$server);
 	}
         sleep(1);		# Try again later if failed connection.
     }
@@ -7426,7 +7426,11 @@
 }
 
 sub current_machine_domains {
-    my $hostname=&hostname($perlvar{'lonHostID'});
+    return &machine_domains(&hostname($perlvar{'lonHostID'}));
+}
+
+sub machine_domains {
+    my ($hostname) = @_;
     my @domains;
     my %hostname = &all_hostnames();
     while( my($id, $name) = each(%hostname)) {
@@ -7439,7 +7443,12 @@
 }
 
 sub current_machine_ids {
-    my $hostname=&hostname($perlvar{'lonHostID'});
+    return &machine_ids(&hostname($perlvar{'lonHostID'}));
+}
+
+sub machine_ids {
+    my ($hostname) = @_;
+    $hostname ||= &hostname($perlvar{'lonHostID'});
     my @ids;
     my %hostname = &all_hostnames();
     while( my($id, $name) = each(%hostname)) {

--albertel1175113712--